[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)

2024-03-02 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -3616,6 +3617,12 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
   if (!ConsiderWrapperFunctions && getStorageClass() == SC_Static)
 return 0;
 
+  // AMDGCN implementation supports printf as a builtin
+  // for OpenCL
+  if (Context.getTargetInfo().getTriple().isAMDGCN() &&
+  Context.getLangOpts().OpenCL && BuiltinID == AMDGPU::BIprintf)
+return BuiltinID;

ssahasra wrote:

I thought this had been clarified earlier too. It's quite imprecise to just say 
that "signatures differ". Perhaps the following detailed explanation might move 
the conversatino forward. The problem is that the OpenCL printf expects a 
format string in the constant address space, which has no representation in 
Clang builtin. What we do have is the ability to specify an address-space 
number in the builtin declaration. But this number is target-specific, which 
makes the whole builtin target-specific. Is there a way around that magic 
number 4?


https://github.com/llvm/llvm-project/pull/72556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wreturn-mismatch (PR #82872)

2024-03-02 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Its a Humble Ping!

https://github.com/llvm/llvm-project/pull/82872
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][RISCV] Reorder sema check for RVV type (PR #83553)

2024-03-02 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/83553

>From 8ad3a883d29155dc26c79abdd57ea0f72d046dfc Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Fri, 1 Mar 2024 00:40:21 -0800
Subject: [PATCH 1/3] [clang][RISCV] Reorder sema check for RVV type

Currently using the command `clang -cc1 -triple riscv64` to compile the
code below:
```
#include 
void foo() {
  vfloat64m1_t f64m1;
}
```
would get the error message "RISC-V type 'vfloat64m1_t' ... requires the 
'zve64x' extension"
which is supposed to be "RISC-V type 'vfloat64m1_t' ... requires the 'zve64d' 
extension".
---
 clang/lib/Sema/SemaChecking.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 979b63884359fc..27ed6f2da05254 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6332,9 +6332,12 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   unsigned EltSize = Context.getTypeSize(Info.ElementType);
   unsigned MinElts = Info.EC.getKnownMinValue();
 
+  if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
+   !TI.hasFeature("zve64d"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
   // (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
   // least zve64x
-  if (((EltSize == 64 && Info.ElementType->isIntegerType()) || MinElts == 1) &&
+  else if (((EltSize == 64 && Info.ElementType->isIntegerType()) || MinElts == 
1) &&
   !TI.hasFeature("zve64x"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
   else if (Info.ElementType->isFloat16Type() && !TI.hasFeature("zvfh") &&
@@ -6347,9 +6350,6 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   else if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Float) &&
!TI.hasFeature("zve32f"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32f";
-  else if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
-   !TI.hasFeature("zve64d"))
-Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
   // Given that caller already checked isRVVType() before calling this 
function,
   // if we don't have at least zve32x supported, then we need to emit error.
   else if (!TI.hasFeature("zve32x"))

>From 779aebac10d2128d4507f74c2c929ab0924a80b6 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Fri, 1 Mar 2024 02:57:00 -0800
Subject: [PATCH 2/3] fixup! [clang][RISCV] Reorder sema check for RVV type

---
 clang/lib/Sema/SemaChecking.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 27ed6f2da05254..ae011806eec629 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6333,12 +6333,13 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   unsigned MinElts = Info.EC.getKnownMinValue();
 
   if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
-   !TI.hasFeature("zve64d"))
+  !TI.hasFeature("zve64d"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
   // (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
   // least zve64x
-  else if (((EltSize == 64 && Info.ElementType->isIntegerType()) || MinElts == 
1) &&
-  !TI.hasFeature("zve64x"))
+  else if (((EltSize == 64 && Info.ElementType->isIntegerType()) ||
+MinElts == 1) &&
+   !TI.hasFeature("zve64x"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
   else if (Info.ElementType->isFloat16Type() && !TI.hasFeature("zvfh") &&
!TI.hasFeature("zvfhmin"))

>From ee33c7d12c307835b5f999eef9f3db6f0d0071f7 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Sat, 2 Mar 2024 02:58:12 -0800
Subject: [PATCH 3/3] fixup! [clang][RISCV] Reorder sema check for RVV type

---
 clang/test/Sema/riscv-vector-float64-check.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/test/Sema/riscv-vector-float64-check.c 
b/clang/test/Sema/riscv-vector-float64-check.c
index ee7db32663959e..f21ae5c0c70405 100644
--- a/clang/test/Sema/riscv-vector-float64-check.c
+++ b/clang/test/Sema/riscv-vector-float64-check.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
-// RUN:   -target-feature +zve64f -target-feature +zfh \
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x \
 // RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
 // REQUIRES: riscv-registered-target
 #include 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][RISCV] Reorder sema check for RVV type (PR #83553)

2024-03-02 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Maybe we can modify the current test case, it would get the error message 
"RISC-V type 'vfloat64m1_t' ... requires the 'zve64x' extension", but should be 
'zve64d' instead.

https://github.com/llvm/llvm-project/pull/83553
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Improve some comments in ArrayBoundCheckerV2 (NFC) (PR #83545)

2024-03-02 Thread Gábor Spaits via cfe-commits


@@ -301,21 +301,27 @@ compareValueToThreshold(ProgramStateRef State, NonLoc 
Value, NonLoc Threshold,
   // calling `evalBinOpNN`:
   if (isNegative(SVB, State, Value) && isUnsigned(SVB, Threshold)) {
 if (CheckEquality) {
-  // negative_value == unsigned_value is always false
+  // negative_value == unsigned_threshold is always false
   return {nullptr, State};
 }
-// negative_value < unsigned_value is always false
+// negative_value < unsigned_threshold is always true
 return {State, nullptr};
   }
   if (isUnsigned(SVB, Value) && isNegative(SVB, State, Threshold)) {
-// unsigned_value == negative_value and unsigned_value < negative_value are
-// both always false
+// unsigned_value == negative_threshold and
+// unsigned_value < negative_threshold are both always false

spaits wrote:

Oh. I understand.

https://github.com/llvm/llvm-project/pull/83545
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Add specific results to comparisons (PR #83316)

2024-03-02 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@pogo This doesn't match what we did for the various cmp intrinsics in 
emmintrin.h - should it?
```cpp
/// Compares each of the corresponding signed 32-bit values of the
///128-bit integer vectors to determine if the values in the first operand
///are greater than those in the second operand.
///
///Each comparison yields 0x0 for false, 0x for true.
///
/// \headerfile 
///
/// This intrinsic corresponds to the  VPCMPGTD / PCMPGTD  instruction.
```

https://github.com/llvm/llvm-project/pull/83316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-02 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/3] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_pa

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-02 Thread Krzysztof Parzyszek via cfe-commits

kparzysz wrote:

The failing test on Windows is unrelated.  I've seen it fail in other builds 
before.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-02 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/83674

It is currently not possible to use "RVV type" and "RVV intrinsics" if
the "zve32x" is not enabled globally. However in some cases we may want
to use them only in some functions, for instance:
```
#include 

__attribute__((target("+zve32x")))
vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}

int other_add(int i1, int i2) {
  return i1 + i2;
}
```
, it is supposed to be compilable even the vector is not specified, e.g.
`clang -target riscv64 -march=rv64gc -S test.c`.


>From 51c523397008dd307bfbc190fd8966fbc4fa4331 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Fri, 1 Mar 2024 09:52:35 -0800
Subject: [PATCH] [clang][RISCV] Support function attribute
 __attribute__((target("+attr")))

It is currently not possible to use "RVV type" and "RVV intrinsics" if
the "zve32x" is not enabled globally. However in some cases we may want
to use them only in some functions, for instance:
```
#include 

__attribute__((target("+zve32x")))
vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}

int other_add(int i1, int i2) {
  return i1 + i2;
}
```
, it is supposed to be compilable even the vector is not specified, e.g.
`clang -target riscv64 -march=rv64gc -S test.c`.
---
 clang/include/clang/Sema/Sema.h   |  3 +-
 clang/lib/Basic/Targets/RISCV.cpp |  3 +-
 clang/lib/Sema/Sema.cpp   |  7 +-
 clang/lib/Sema/SemaChecking.cpp   | 70 +++
 clang/lib/Sema/SemaDecl.cpp   |  9 ++-
 .../RISCV/rvb-intrinsics/riscv32-zbb-error.c  |  4 +-
 .../RISCV/rvb-intrinsics/riscv64-zbkb-error.c | 12 ++--
 .../rvv-intrinsics-handcrafted/rvv-error.c|  2 +-
 clang/test/Sema/riscv-function-target-attr.c  | 41 +++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 --
 10 files changed, 73 insertions(+), 82 deletions(-)
 create mode 100644 clang/test/Sema/riscv-function-target-attr.c

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..932b76c82af0ee 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14067,7 +14067,8 @@ class Sema final {
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
-  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D);
+  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
+   const llvm::StringMap &FeatureMap);
   bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID, CallExpr 
*TheCall);
   bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..6991caa21d23b4 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))
+  Ret.Features.push_back(Feature.str());
   }
   return Ret;
 }
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..41c7bfb25a7921 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2077,8 +2077,11 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
-if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType())
-  checkRVVTypeSupport(Ty, Loc, D);
+if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
+  llvm::StringMap CallerFeatureMap;
+  Context.getFunctionFeatureMap(CallerFeatureMap, FD);
+  checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
+}
 
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..50afb56ae09eac 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5415,57 +5415,6 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo 
&TI, CallExpr *TheCall,
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
-  // CodeGenFunction can also detect this, but this gives a better error
-  // message.
-  bool FeatureMissing = false;
-  SmallVector ReqFeatures;
-  StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
-  Features.split(ReqFeatures, ',', -1, false);
-
-  // Ch

[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Brandon Wu (4vtomat)


Changes

It is currently not possible to use "RVV type" and "RVV intrinsics" if
the "zve32x" is not enabled globally. However in some cases we may want
to use them only in some functions, for instance:
```
#include 

__attribute__((target("+zve32x")))
vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}

int other_add(int i1, int i2) {
  return i1 + i2;
}
```
, it is supposed to be compilable even the vector is not specified, e.g.
`clang -target riscv64 -march=rv64gc -S test.c`.


---
Full diff: https://github.com/llvm/llvm-project/pull/83674.diff


10 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+2-1) 
- (modified) clang/lib/Sema/Sema.cpp (+5-2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+9-61) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+7-2) 
- (modified) clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c (+2-2) 
- (modified) clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb-error.c 
(+4-8) 
- (modified) clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-error.c 
(+1-1) 
- (added) clang/test/Sema/riscv-function-target-attr.c (+41) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (-4) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..932b76c82af0ee 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14067,7 +14067,8 @@ class Sema final {
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
-  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D);
+  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
+   const llvm::StringMap &FeatureMap);
   bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID, CallExpr 
*TheCall);
   bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..6991caa21d23b4 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))
+  Ret.Features.push_back(Feature.str());
   }
   return Ret;
 }
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..41c7bfb25a7921 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2077,8 +2077,11 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
-if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType())
-  checkRVVTypeSupport(Ty, Loc, D);
+if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
+  llvm::StringMap CallerFeatureMap;
+  Context.getFunctionFeatureMap(CallerFeatureMap, FD);
+  checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
+}
 
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..50afb56ae09eac 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5415,57 +5415,6 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo 
&TI, CallExpr *TheCall,
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
-  // CodeGenFunction can also detect this, but this gives a better error
-  // message.
-  bool FeatureMissing = false;
-  SmallVector ReqFeatures;
-  StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
-  Features.split(ReqFeatures, ',', -1, false);
-
-  // Check if each required feature is included
-  for (StringRef F : ReqFeatures) {
-SmallVector ReqOpFeatures;
-F.split(ReqOpFeatures, '|');
-
-if (llvm::none_of(ReqOpFeatures,
-  [&TI](StringRef OF) { return TI.hasFeature(OF); })) {
-  std::string FeatureStrs;
-  bool IsExtension = true;
-  for (StringRef OF : ReqOpFeatures) {
-// If the feature is 64bit, alter the string so it will print better in
-// the diagnostic.
-if (OF == "64bit") {
-  assert(ReqOpFeatures.size() == 1 && "Expected '64bit' to be alone");
-  OF = "RV64";
-  IsExtension = false;
-}
- 

[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-02 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Related request: https://github.com/riscv-non-isa/riscv-c-api-doc/issues/69

https://github.com/llvm/llvm-project/pull/83674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-02 Thread David CARLIER via cfe-commits

https://github.com/devnexen created 
https://github.com/llvm/llvm-project/pull/83675

since it went way beyond just openbsd, adding basic check for possible misusage.

>From f9e571bfa3e64d9fb54e965f3c363aef40fa3b80 Mon Sep 17 00:00:00 2001
From: David Carlier 
Date: Sat, 2 Mar 2024 14:56:15 +
Subject: [PATCH] [clang][StaticAnalyzer] Adding getentropy to CStringChecker.

since it went way beyond just openbsd, adding basic check for possible
misusage.
---
 .../Checkers/CStringChecker.cpp   | 42 +++
 1 file changed, 42 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b7b64c3da4f6c8..b6b0878459f0c2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -166,6 +166,7 @@ class CStringChecker : public Checker< eval::Call,
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, &CStringChecker::evalBzero},
   {{CDF_MaybeBuiltin, {"sprintf"}, 2}, &CStringChecker::evalSprintf},
   {{CDF_MaybeBuiltin, {"snprintf"}, 2}, &CStringChecker::evalSnprintf},
+  {{CDF_MaybeBuiltin, {"getentropy"}, 2}, &CStringChecker::evalGetentropy},
   };
 
   // These require a bit of special handling.
@@ -220,6 +221,7 @@ class CStringChecker : public Checker< eval::Call,
   void evalSnprintf(CheckerContext &C, const CallEvent &Call) const;
   void evalSprintfCommon(CheckerContext &C, const CallEvent &Call,
  bool IsBounded, bool IsBuiltin) const;
+  void evalGetentropy(CheckerContext &C, const CallEvent &Call) const;
 
   // Utility methods
   std::pair
@@ -2516,6 +2518,46 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  constexpr int BufferMaxSize = 256;
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);
+  if (!State)
+return;
+
+  auto SizeLoc = SizeVal.getAs();
+  auto size = SizeLoc->getValue().getExtValue();
+
+  if (size > BufferMaxSize) {
+ErrorMessage Message;
+llvm::raw_svector_ostream Os(Message);
+Os << " destination buffer size is greater than " << BufferMaxSize;
+emitOutOfBoundsBug(C, StateNonZeroSize, Buffer.Expression, Message);
+return;
+  }
+
+  State = invalidateDestinationBufferBySize(
+  C, State, Buffer.Expression, C.getSVal(Buffer.Expression), SizeVal,
+  SizeTy);
+
+  C.addTransition(State);
+}
+
 
//===--===//
 // The driver method, and other Checker callbacks.
 
//===--===//

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David CARLIER (devnexen)


Changes

since it went way beyond just openbsd, adding basic check for possible misusage.

---
Full diff: https://github.com/llvm/llvm-project/pull/83675.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (+42) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b7b64c3da4f6c8..b6b0878459f0c2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -166,6 +166,7 @@ class CStringChecker : public Checker< eval::Call,
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, &CStringChecker::evalBzero},
   {{CDF_MaybeBuiltin, {"sprintf"}, 2}, &CStringChecker::evalSprintf},
   {{CDF_MaybeBuiltin, {"snprintf"}, 2}, &CStringChecker::evalSnprintf},
+  {{CDF_MaybeBuiltin, {"getentropy"}, 2}, &CStringChecker::evalGetentropy},
   };
 
   // These require a bit of special handling.
@@ -220,6 +221,7 @@ class CStringChecker : public Checker< eval::Call,
   void evalSnprintf(CheckerContext &C, const CallEvent &Call) const;
   void evalSprintfCommon(CheckerContext &C, const CallEvent &Call,
  bool IsBounded, bool IsBuiltin) const;
+  void evalGetentropy(CheckerContext &C, const CallEvent &Call) const;
 
   // Utility methods
   std::pair
@@ -2516,6 +2518,46 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  constexpr int BufferMaxSize = 256;
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);
+  if (!State)
+return;
+
+  auto SizeLoc = SizeVal.getAs();
+  auto size = SizeLoc->getValue().getExtValue();
+
+  if (size > BufferMaxSize) {
+ErrorMessage Message;
+llvm::raw_svector_ostream Os(Message);
+Os << " destination buffer size is greater than " << BufferMaxSize;
+emitOutOfBoundsBug(C, StateNonZeroSize, Buffer.Expression, Message);
+return;
+  }
+
+  State = invalidateDestinationBufferBySize(
+  C, State, Buffer.Expression, C.getSVal(Buffer.Expression), SizeVal,
+  SizeTy);
+
+  C.addTransition(State);
+}
+
 
//===--===//
 // The driver method, and other Checker callbacks.
 
//===--===//

``




https://github.com/llvm/llvm-project/pull/83675
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-02 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff ca827d53c5524409dcca5ade3949b25f38a60fef 
f9e571bfa3e64d9fb54e965f3c363aef40fa3b80 -- 
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b6b0878459..5b4c3912f1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -2518,7 +2518,8 @@ void CStringChecker::evalSprintfCommon(CheckerContext &C, 
const CallEvent &Call,
   C.addTransition(State);
 }
 
-void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+void CStringChecker::evalGetentropy(CheckerContext &C,
+const CallEvent &Call) const {
   DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
   SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
   ProgramStateRef State = C.getState();
@@ -2529,7 +2530,7 @@ void CStringChecker::evalGetentropy(CheckerContext &C, 
const CallEvent &Call) co
 
   ProgramStateRef StateZeroSize, StateNonZeroSize;
   std::tie(StateZeroSize, StateNonZeroSize) =
-assumeZero(C, State, SizeVal, SizeTy);
+  assumeZero(C, State, SizeVal, SizeTy);
 
   SVal Buff = C.getSVal(Buffer.Expression);
   State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
@@ -2551,9 +2552,9 @@ void CStringChecker::evalGetentropy(CheckerContext &C, 
const CallEvent &Call) co
 return;
   }
 
-  State = invalidateDestinationBufferBySize(
-  C, State, Buffer.Expression, C.getSVal(Buffer.Expression), SizeVal,
-  SizeTy);
+  State = invalidateDestinationBufferBySize(C, State, Buffer.Expression,
+C.getSVal(Buffer.Expression),
+SizeVal, SizeTy);
 
   C.addTransition(State);
 }

``




https://github.com/llvm/llvm-project/pull/83675
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-02 Thread David CARLIER via cfe-commits

https://github.com/devnexen updated 
https://github.com/llvm/llvm-project/pull/83675

>From 685c7e56c1ce8d2e11c0f9a97f6c4d24f63a05b8 Mon Sep 17 00:00:00 2001
From: David Carlier 
Date: Sat, 2 Mar 2024 14:56:15 +
Subject: [PATCH] [clang][StaticAnalyzer] Adding getentropy to CStringChecker.

since it went way beyond just openbsd, adding basic check for possible
misusage.
---
 .../Checkers/CStringChecker.cpp   | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b7b64c3da4f6c8..5b4c3912f13006 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -166,6 +166,7 @@ class CStringChecker : public Checker< eval::Call,
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, &CStringChecker::evalBzero},
   {{CDF_MaybeBuiltin, {"sprintf"}, 2}, &CStringChecker::evalSprintf},
   {{CDF_MaybeBuiltin, {"snprintf"}, 2}, &CStringChecker::evalSnprintf},
+  {{CDF_MaybeBuiltin, {"getentropy"}, 2}, &CStringChecker::evalGetentropy},
   };
 
   // These require a bit of special handling.
@@ -220,6 +221,7 @@ class CStringChecker : public Checker< eval::Call,
   void evalSnprintf(CheckerContext &C, const CallEvent &Call) const;
   void evalSprintfCommon(CheckerContext &C, const CallEvent &Call,
  bool IsBounded, bool IsBuiltin) const;
+  void evalGetentropy(CheckerContext &C, const CallEvent &Call) const;
 
   // Utility methods
   std::pair
@@ -2516,6 +2518,47 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C,
+const CallEvent &Call) const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  constexpr int BufferMaxSize = 256;
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);
+  if (!State)
+return;
+
+  auto SizeLoc = SizeVal.getAs();
+  auto size = SizeLoc->getValue().getExtValue();
+
+  if (size > BufferMaxSize) {
+ErrorMessage Message;
+llvm::raw_svector_ostream Os(Message);
+Os << " destination buffer size is greater than " << BufferMaxSize;
+emitOutOfBoundsBug(C, StateNonZeroSize, Buffer.Expression, Message);
+return;
+  }
+
+  State = invalidateDestinationBufferBySize(C, State, Buffer.Expression,
+C.getSVal(Buffer.Expression),
+SizeVal, SizeTy);
+
+  C.addTransition(State);
+}
+
 
//===--===//
 // The driver method, and other Checker callbacks.
 
//===--===//

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-02 Thread via cfe-commits

https://github.com/mzyKi created https://github.com/llvm/llvm-project/pull/83677

```bool evalCall(const CallEvent &Call, CheckerContext &C)``` is corret form.

>From 9779c43a8e603efdf93344780702de1ff343a676 Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Sat, 2 Mar 2024 23:16:58 +0800
Subject: [PATCH] [clang][StaticAnalyzer] fix function evalCall() typo in
 CheckerDocumentation

---
 clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 3e5e2b9139149d..0ca0c487b64550 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -226,7 +226,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// first one wins.
   ///
   /// eval::Call
-  bool evalCall(const CallExpr *CE, CheckerContext &C) const { return true; }
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const { return true; 
}
 
   /// Handles assumptions on symbolic values.
   ///

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Exile (mzyKi)


Changes

```bool evalCall(const CallEvent &Call, CheckerContext &C)``` is corret 
form.

---
Full diff: https://github.com/llvm/llvm-project/pull/83677.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp (+1-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 3e5e2b9139149d..0ca0c487b64550 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -226,7 +226,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// first one wins.
   ///
   /// eval::Call
-  bool evalCall(const CallExpr *CE, CheckerContext &C) const { return true; }
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const { return true; 
}
 
   /// Handles assumptions on symbolic values.
   ///

``




https://github.com/llvm/llvm-project/pull/83677
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Exile (mzyKi)


Changes

```bool evalCall(const CallEvent &Call, CheckerContext &C)``` is corret 
form.

---
Full diff: https://github.com/llvm/llvm-project/pull/83677.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp (+1-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 3e5e2b9139149d..0ca0c487b64550 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -226,7 +226,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// first one wins.
   ///
   /// eval::Call
-  bool evalCall(const CallExpr *CE, CheckerContext &C) const { return true; }
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const { return true; 
}
 
   /// Handles assumptions on symbolic values.
   ///

``




https://github.com/llvm/llvm-project/pull/83677
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-03-02 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> I tried compiling it and then got two warnings.
> 
> ```
> llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:1408:11: warning: enumeration 
> value 'CC_RISCVVectorCall' not handled in switch [-Wswitch]
>  1408 |   switch (CC) {
>   |   ^~
> 1 warning generated.
> [3629/3776] Building CXX object 
> tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o
> llvm-project/clang/tools/libclang/CXType.cpp:662:13: warning: enumeration 
> value 'CC_RISCVVectorCall' not handled in switch [-Wswitch]
>   662 | switch (FD->getCallConv()) {
>   | ^
> 1 warning generated.
> ```

I forgot to add these cases for `CC_RISCVVectorCall` lol, thanks~

https://github.com/llvm/llvm-project/pull/77560
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AMDGPU] Don't define feature macros on host code (PR #83558)

2024-03-02 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

When clang does host compilation, it essentially makes an assumption that the 
generated IR for host does not depend on the assumed GPU arch, or, the 
generated IR may be affected by assumed GPU arch, but it won't affect the 
program output. This is true in most cases. For example, in the case of 
rocprim, it needs to see __AMDGCN_WAVEFRONT_SIZE  to be able to parse device 
functions in host compilation, but that does not affect what host IR is 
generated. That is the reason why we can assume a default GPU arch in host 
compilation.

I think a more practical approach to void __AMDGCN_WAVEFRONT_SIZE  being used 
in host functions is to define it as a clang constexpr builtin that is 
evaluated to an integer constant in device functions or variables, but will be 
diagnosed when used in host functions or variables. warpSize should also be 
defined as a device constexpr variable to avoid it being used in host code.

https://github.com/llvm/llvm-project/pull/83558
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix null-deref thanks to an attribute on a global declarator chunk (PR #83611)

2024-03-02 Thread Erich Keane via cfe-commits


@@ -100,6 +100,12 @@ void AttributePool::takePool(AttributePool &pool) {
   pool.Attrs.clear();
 }
 
+void AttributePool::takeFrom(ParsedAttributesView &List, AttributePool &Pool) {
+  assert(&Pool != this && "AttributePool can't take attributes from itself");
+  llvm::for_each(List.AttrList, [&Pool](ParsedAttr *A) { Pool.remove(A); });

erichkeane wrote:

You mean reverse the order of the remove/add?  Based on `takeAllFrom` and 
`takeOneFrom` 
(https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Sema/ParsedAttr.h#L953),
 we are consistently inconsistent :)

In this case, I was working from `takeOneFrom` so I ended up in this order, but 
if there is a good reason to prefer one over the other, I can switch.

https://github.com/llvm/llvm-project/pull/83611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix null-deref thanks to an attribute on a global declarator chunk (PR #83611)

2024-03-02 Thread Erich Keane via cfe-commits

erichkeane wrote:

Note to self when I get back to work:
1- Update commit message with bug #[ 
83611](https://github.com/llvm/llvm-project/pull/83611)
2- Add bug # to release note.

https://github.com/llvm/llvm-project/pull/83611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)

2024-03-02 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

When implementing support for `StmtExpr`, I ran  into a problem: there is no 
way for `ByteCodeExprGen` to visit a statement. Previously, `ByteCodeStmtGen` 
inherited from `ByteCodeExprGen`, so the former could visit expressions, but 
the latter couldn't visit statements.

This branch merges the two, renames the result to `Compiler` and uses it to 
implement `StmtExpr` support.

Apart from implementing `StmtExpr` support, this entire branch is NFC of 
course, but I was wondering if this makes sense for everyone involved.

---

Patch is 91.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/83683.diff


9 Files Affected:

- (modified) clang/lib/AST/CMakeLists.txt (+1-2) 
- (removed) clang/lib/AST/Interp/ByteCodeStmtGen.cpp (-684) 
- (removed) clang/lib/AST/Interp/ByteCodeStmtGen.h (-91) 
- (renamed) clang/lib/AST/Interp/Compiler.cpp (+785-136) 
- (renamed) clang/lib/AST/Interp/Compiler.h (+64-23) 
- (modified) clang/lib/AST/Interp/Context.cpp (+6-7) 
- (modified) clang/lib/AST/Interp/EvalEmitter.h (+1) 
- (modified) clang/lib/AST/Interp/Program.cpp (-1) 
- (modified) clang/test/AST/Interp/literals.cpp (+14) 


``diff
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 6ea1ca3e76cf33..9a17e6b6a3b462 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -65,9 +65,8 @@ add_clang_library(clangAST
   FormatString.cpp
   InheritViz.cpp
   Interp/ByteCodeEmitter.cpp
-  Interp/ByteCodeExprGen.cpp
+  Interp/Compiler.cpp
   Interp/ByteCodeGenError.cpp
-  Interp/ByteCodeStmtGen.cpp
   Interp/Context.cpp
   Interp/Descriptor.cpp
   Interp/Disasm.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
deleted file mode 100644
index d9213b12cbd08b..00
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ /dev/null
@@ -1,684 +0,0 @@
-//===--- ByteCodeStmtGen.cpp - Code generator for expressions ---*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "ByteCodeStmtGen.h"
-#include "ByteCodeEmitter.h"
-#include "ByteCodeGenError.h"
-#include "Context.h"
-#include "Function.h"
-#include "PrimType.h"
-
-using namespace clang;
-using namespace clang::interp;
-
-namespace clang {
-namespace interp {
-
-/// Scope managing label targets.
-template  class LabelScope {
-public:
-  virtual ~LabelScope() {  }
-
-protected:
-  LabelScope(ByteCodeStmtGen *Ctx) : Ctx(Ctx) {}
-  /// ByteCodeStmtGen instance.
-  ByteCodeStmtGen *Ctx;
-};
-
-/// Sets the context for break/continue statements.
-template  class LoopScope final : public LabelScope {
-public:
-  using LabelTy = typename ByteCodeStmtGen::LabelTy;
-  using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy;
-
-  LoopScope(ByteCodeStmtGen *Ctx, LabelTy BreakLabel,
-LabelTy ContinueLabel)
-  : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldContinueLabel(Ctx->ContinueLabel) {
-this->Ctx->BreakLabel = BreakLabel;
-this->Ctx->ContinueLabel = ContinueLabel;
-  }
-
-  ~LoopScope() {
-this->Ctx->BreakLabel = OldBreakLabel;
-this->Ctx->ContinueLabel = OldContinueLabel;
-  }
-
-private:
-  OptLabelTy OldBreakLabel;
-  OptLabelTy OldContinueLabel;
-};
-
-// Sets the context for a switch scope, mapping labels.
-template  class SwitchScope final : public LabelScope {
-public:
-  using LabelTy = typename ByteCodeStmtGen::LabelTy;
-  using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy;
-  using CaseMap = typename ByteCodeStmtGen::CaseMap;
-
-  SwitchScope(ByteCodeStmtGen *Ctx, CaseMap &&CaseLabels,
-  LabelTy BreakLabel, OptLabelTy DefaultLabel)
-  : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel),
-OldDefaultLabel(this->Ctx->DefaultLabel),
-OldCaseLabels(std::move(this->Ctx->CaseLabels)) {
-this->Ctx->BreakLabel = BreakLabel;
-this->Ctx->DefaultLabel = DefaultLabel;
-this->Ctx->CaseLabels = std::move(CaseLabels);
-  }
-
-  ~SwitchScope() {
-this->Ctx->BreakLabel = OldBreakLabel;
-this->Ctx->DefaultLabel = OldDefaultLabel;
-this->Ctx->CaseLabels = std::move(OldCaseLabels);
-  }
-
-private:
-  OptLabelTy OldBreakLabel;
-  OptLabelTy OldDefaultLabel;
-  CaseMap OldCaseLabels;
-};
-
-} // namespace interp
-} // namespace clang
-
-template 
-bool ByteCodeStmtGen::emitLambdaStaticInvokerBody(
-const CXXMethodDecl *MD) {
-  assert(MD->isLambdaStaticInvoker());
-  assert(MD->hasBody());
-  assert(cast(MD->getBody())->body_empty());
-
-  const CXXRecordDecl *ClosureClass = MD->getParent();
-  const CXXMethodDec

[clang] [llvm] [X86] Use generic CPU tuning when tune-cpu is empty (PR #83631)

2024-03-02 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

Please check the CI - these failures look relevant
```
Failed Tests (4):
  lld :: COFF/lto-cpu-string.ll
  lld :: COFF/lto.ll
  lld :: ELF/lto/cpu-string.ll
  lld :: MachO/lto-cpu-string.ll
```

https://github.com/llvm/llvm-project/pull/83631
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-02 Thread Balazs Benics via cfe-commits

steakhal wrote:

Makes sense, but how did it build before the fix?
I thought by inheriting from `Checker` it would take the address of the member 
function with the expected signature to store them inside vectors. How could it 
take the address of a nonexisting member function?

https://github.com/llvm/llvm-project/pull/83677
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-02 Thread Balazs Benics via cfe-commits

https://github.com/steakhal approved this pull request.


https://github.com/llvm/llvm-project/pull/83677
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits

https://github.com/steakhal edited 
https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 57f599d - [clang][Interp] Improve handling of external variables

2024-03-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-02T17:40:16+01:00
New Revision: 57f599d6443a910a213094646e7e26837a1d4417

URL: 
https://github.com/llvm/llvm-project/commit/57f599d6443a910a213094646e7e26837a1d4417
DIFF: 
https://github.com/llvm/llvm-project/commit/57f599d6443a910a213094646e7e26837a1d4417.diff

LOG: [clang][Interp] Improve handling of external variables

Further down in this function, we assert that the variable has
an initializer, which didn't work for external declarations.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 63ab80f59dac46..b4110d5856d512 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2663,6 +2663,11 @@ bool ByteCodeExprGen::visitVarDecl(const 
VarDecl *VD) {
 if (P.getGlobal(VD))
   return true;
 
+// Ignore external declarations. We will instead emit a dummy
+// pointer when we see a DeclRefExpr for them.
+if (VD->hasExternalStorage())
+  return true;
+
 std::optional GlobalIndex = P.createGlobal(VD, Init);
 
 if (!GlobalIndex)

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 10b687c1408ac3..d86609108ca446 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1168,3 +1168,10 @@ namespace incdecbool {
 
 
 }
+
+#if __cplusplus >= 201402L
+constexpr int externvar1() { // both-error {{never produces a constant 
expression}}
+  extern char arr[]; // both-note {{declared here}}
+  return arr[0]; // both-note {{read of non-constexpr variable 'arr'}}
+}
+#endif



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a30ba2c - [clang][Interp][NFC] Emit diagnostic for unknown builtins

2024-03-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-02T18:28:12+01:00
New Revision: a30ba2ca21b0da49631c6d0c52108e4a080a451e

URL: 
https://github.com/llvm/llvm-project/commit/a30ba2ca21b0da49631c6d0c52108e4a080a451e
DIFF: 
https://github.com/llvm/llvm-project/commit/a30ba2ca21b0da49631c6d0c52108e4a080a451e.diff

LOG: [clang][Interp][NFC] Emit diagnostic for unknown builtins

Instead of just returning false.

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 4ba518e5f0619c..371240065179e3 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1207,6 +1207,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
 break;
 
   default:
+S.FFDiag(S.Current->getLocation(OpPC),
+ diag::note_invalid_subexpr_in_const_expr)
+<< S.Current->getRange(OpPC);
+
 return false;
   }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits

https://github.com/steakhal edited 
https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++23 
-verify %s
+// expected-no-diagnostics
+
+struct S
+{
+constexpr auto operator==(this auto, S)
+{
+return true;
+}
+};
+
+int main()
+{
+return S {} == S {};
+}

steakhal wrote:

```suggestion
struct S {
  bool operator==(this auto, S) {
return true;
  }
};

int use_deducing_this() {
  return S{} == S{};
}
```

https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

I feel like it's better than crashing, but I suspect it only resolves that, 
right?

https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++23 
-verify %s

steakhal wrote:

```suggestion
// RUN: %clang_analyze_cc1 -analyzer-checker=core -std=c++23 -verify %s
```

https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-02 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++23 
-verify %s
+// expected-no-diagnostics
+
+struct S
+{
+constexpr auto operator==(this auto, S)
+{
+return true;
+}
+};
+
+int main()
+{
+return S {} == S {};
+}

steakhal wrote:

Speaking of this test, it might be better to dedicate a file for "deducing 
this".

https://github.com/llvm/llvm-project/pull/83585
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b901b0d - [clang][Interp] Reject dummy pointers from __builtin_strcmp()

2024-03-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-02T18:28:51+01:00
New Revision: b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf

URL: 
https://github.com/llvm/llvm-project/commit/b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf
DIFF: 
https://github.com/llvm/llvm-project/commit/b901b0d3edeaa30e363af4cb9dc76d6a7072e6cf.diff

LOG: [clang][Interp] Reject dummy pointers from __builtin_strcmp()

We can't load anything from them, so reject them here.

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 371240065179e3..de3d72169432fd 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -132,6 +132,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
 return false;
 
+  if (A.isDummy() || B.isDummy())
+return false;
+
   assert(A.getFieldDesc()->isPrimitiveArray());
   assert(B.getFieldDesc()->isPrimitiveArray());
 

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 3701106e02f05b..ab8abac4b36e34 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -34,6 +34,14 @@ namespace strcmp {
   static_assert(__builtin_strcmp(kFoobar, kFoobazfoobar + 6) == 0, ""); // 
both-error {{not an integral constant}} \
 // 
both-note {{dereferenced one-past-the-end}} \
 // 
expected-note {{in call to}}
+
+  /// Used to assert because we're passing a dummy pointer to
+  /// __builtin_strcmp() when evaluating the return statement.
+  constexpr bool char_memchr_mutable() {
+char buffer[] = "mutable";
+return __builtin_strcmp(buffer, "mutable") == 0;
+  }
+  static_assert(char_memchr_mutable(), "");
 }
 
 /// Copied from constant-expression-cxx11.cpp



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-02 Thread David CARLIER via cfe-commits

https://github.com/devnexen created 
https://github.com/llvm/llvm-project/pull/83686

close #83671.

>From 49c888993ee4ce566db8f5b8d4932cee81b8f701 Mon Sep 17 00:00:00 2001
From: David Carlier 
Date: Sat, 2 Mar 2024 18:00:10 +
Subject: [PATCH] [clang][AST] fix dereference on class/struct layouts check.

close #83671.
---
 clang/lib/AST/RecordLayoutBuilder.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index a3b7431f7ffd6d..195f17d2e5a42f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -205,15 +205,15 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
 
   // Check the fields.
   for (const FieldDecl *FD : Class->fields()) {
+const CXXRecordDecl *MemberDecl;
 const RecordType *RT =
 Context.getBaseElementType(FD->getType())->getAs();
 
-// We only care about record types.
-if (!RT)
+// We only care about members layout.
+if (!RT || !(MemberDecl = RT->getAsCXXRecordDecl()))
   continue;
 
 CharUnits EmptySize;
-const CXXRecordDecl *MemberDecl = RT->getAsCXXRecordDecl();
 const ASTRecordLayout &Layout = Context.getASTRecordLayout(MemberDecl);
 if (MemberDecl->isEmpty()) {
   // If the class decl is empty, get its size.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David CARLIER (devnexen)


Changes

close #83671.

---
Full diff: https://github.com/llvm/llvm-project/pull/83686.diff


1 Files Affected:

- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3) 


``diff
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index a3b7431f7ffd6d..195f17d2e5a42f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -205,15 +205,15 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
 
   // Check the fields.
   for (const FieldDecl *FD : Class->fields()) {
+const CXXRecordDecl *MemberDecl;
 const RecordType *RT =
 Context.getBaseElementType(FD->getType())->getAs();
 
-// We only care about record types.
-if (!RT)
+// We only care about members layout.
+if (!RT || !(MemberDecl = RT->getAsCXXRecordDecl()))
   continue;
 
 CharUnits EmptySize;
-const CXXRecordDecl *MemberDecl = RT->getAsCXXRecordDecl();
 const ASTRecordLayout &Layout = Context.getASTRecordLayout(MemberDecl);
 if (MemberDecl->isEmpty()) {
   // If the class decl is empty, get its size.

``




https://github.com/llvm/llvm-project/pull/83686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dfb8a15 - [clang][Interp][NFC] Make a local variable const

2024-03-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-02T18:56:35+01:00
New Revision: dfb8a1531c962238a63db199dff973deec47e4ff

URL: 
https://github.com/llvm/llvm-project/commit/dfb8a1531c962238a63db199dff973deec47e4ff
DIFF: 
https://github.com/llvm/llvm-project/commit/dfb8a1531c962238a63db199dff973deec47e4ff.diff

LOG: [clang][Interp][NFC] Make a local variable const

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index de3d72169432fd..6550a07650c887 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1237,7 +1237,7 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, 
const OffsetOfExpr *E,
   const RecordType *RT = CurrentType->getAs();
   if (!RT)
 return false;
-  RecordDecl *RD = RT->getDecl();
+  const RecordDecl *RD = RT->getDecl();
   if (RD->isInvalidDecl())
 return false;
   const ASTRecordLayout &RL = S.getCtx().getASTRecordLayout(RD);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f25debe - [clang][Interp][NFC] Remove some leftover debug output

2024-03-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-02T18:56:43+01:00
New Revision: f25debe58b61a6d66e662d60fd4c060adcd74630

URL: 
https://github.com/llvm/llvm-project/commit/f25debe58b61a6d66e662d60fd4c060adcd74630
DIFF: 
https://github.com/llvm/llvm-project/commit/f25debe58b61a6d66e662d60fd4c060adcd74630.diff

LOG: [clang][Interp][NFC] Remove some leftover debug output

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 6550a07650c887..cc457ce41af595 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -463,9 +463,6 @@ static bool interp__builtin_popcount(InterpState &S, 
CodePtr OpPC,
  const InterpFrame *Frame,
  const Function *Func,
  const CallExpr *Call) {
-
-  Func->getDecl()->dump();
-
   PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
   APSInt Val = peekToAPSInt(S.Stk, ArgT);
   pushInteger(S, Val.popcount(), Call->getType());



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-02 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/83688

We were crashing on trying to print the layout of an uninstantiated template, 
which obviously doesn’t make sense.

This fixes #83684.

>From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:41:22 +0100
Subject: [PATCH 1/2] [Clang] [Sema] Do not attempt to dump the layout of
 dependent types

---
 clang/lib/AST/Decl.cpp  |  2 +-
 clang/test/Layout/dump-complete.cpp | 29 -
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

>From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 2 Mar 2024 20:45:24 +0100
Subject: [PATCH 2/2] [Clang] Add release note

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

We were crashing on trying to print the layout of an uninstantiated template, 
which obviously doesn’t make sense.

This fixes #83684.

---
Full diff: https://github.com/llvm/llvm-project/pull/83688.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/AST/Decl.cpp (+1-1) 
- (modified) clang/test/Layout/dump-complete.cpp (+28-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..69cf0cb643e6aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types when 
``-fdump-record-layouts-complete``
+  is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..d069cd65732310 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())
 (void)Ctx.getASTRecordLayout(this);
 }
 
diff --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..0a91d3329e6921 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,34 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+void f() {
+  ts a;
+  ts b;
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult

``




https://github.com/llvm/llvm-project/pull/83688
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)

2024-03-02 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/83533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)

2024-03-02 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/83533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 051e910 - [clang-format][NFC] Replace Style.isCpp() with IsCpp (#83533)

2024-03-02 Thread via cfe-commits

Author: Owen Pan
Date: 2024-03-02T12:57:24-08:00
New Revision: 051e910b8b6c59fc94d019fa01ae4507b1c81498

URL: 
https://github.com/llvm/llvm-project/commit/051e910b8b6c59fc94d019fa01ae4507b1c81498
DIFF: 
https://github.com/llvm/llvm-project/commit/051e910b8b6c59fc94d019fa01ae4507b1c81498.diff

LOG: [clang-format][NFC] Replace Style.isCpp() with IsCpp (#83533)

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 0c1dce7a294082..31245495041960 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -821,8 +821,8 @@ struct FormatToken {
 
   /// Returns whether the token is the left square bracket of a C++
   /// structured binding declaration.
-  bool isCppStructuredBinding(const FormatStyle &Style) const {
-if (!Style.isCpp() || isNot(tok::l_square))
+  bool isCppStructuredBinding(bool IsCpp) const {
+if (!IsCpp || isNot(tok::l_square))
   return false;
 const FormatToken *T = this;
 do {

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a60d6ae197a24e..04f0374b674e53 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -126,7 +126,7 @@ class AnnotatingParser {
const AdditionalKeywords &Keywords,
SmallVector &Scopes)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
-Keywords(Keywords), Scopes(Scopes) {
+IsCpp(Style.isCpp()), Keywords(Keywords), Scopes(Scopes) {
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata();
   }
@@ -676,13 +676,13 @@ class AnnotatingParser {
 // In C++, this can happen either in array of templates (foo[10])
 // or when array is a nested template type (unique_ptr[]>).
 bool CppArrayTemplates =
-Style.isCpp() && Parent && Parent->is(TT_TemplateCloser) &&
+IsCpp && Parent && Parent->is(TT_TemplateCloser) &&
 (Contexts.back().CanBeExpression || Contexts.back().IsExpression ||
  Contexts.back().ContextType == Context::TemplateArgument);
 
 const bool IsInnerSquare = Contexts.back().InCpp11AttributeSpecifier;
 const bool IsCpp11AttributeSpecifier =
-isCppAttribute(Style.isCpp(), *Left) || IsInnerSquare;
+isCppAttribute(IsCpp, *Left) || IsInnerSquare;
 
 // Treat C# Attributes [STAThread] much like C++ attributes [[...]].
 bool IsCSharpAttributeSpecifier =
@@ -690,12 +690,11 @@ class AnnotatingParser {
 Contexts.back().InCSharpAttributeSpecifier;
 
 bool InsideInlineASM = Line.startsWith(tok::kw_asm);
-bool IsCppStructuredBinding = Left->isCppStructuredBinding(Style);
+bool IsCppStructuredBinding = Left->isCppStructuredBinding(IsCpp);
 bool StartsObjCMethodExpr =
 !IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
-Style.isCpp() && !IsCpp11AttributeSpecifier &&
-!IsCSharpAttributeSpecifier && Contexts.back().CanBeExpression &&
-Left->isNot(TT_LambdaLSquare) &&
+IsCpp && !IsCpp11AttributeSpecifier && !IsCSharpAttributeSpecifier &&
+Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
 !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
 (!Parent ||
  Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
@@ -723,7 +722,7 @@ class AnnotatingParser {
  Contexts.back().ContextKind == tok::l_brace &&
  Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->setType(TT_JsComputedPropertyName);
-  } else if (Style.isCpp() && Contexts.back().ContextKind == tok::l_brace 
&&
+  } else if (IsCpp && Contexts.back().ContextKind == tok::l_brace &&
  Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->setType(TT_DesignatedInitializerLSquare);
   } else if (IsCSharpAttributeSpecifier) {
@@ -1161,7 +1160,7 @@ class AnnotatingParser {
 if (Previous->is(TT_JsTypeOptionalQuestion))
   Previous = Previous->getPreviousNonComment();
 if ((CurrentToken->is(tok::colon) && !Style.isTableGen() &&
- (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
+ (!Contexts.back().ColonIsDictLiteral || !IsCpp)) ||
 Style.isProto()) {
   OpeningBrace.setType(TT_DictLiteral);
   if (Previous->Tok.getIdentifierInfo() ||
@@ -1230,7 +1229,7 @@ class AnnotatingParser {
   }
 
   bool consumeToken() {
-if (Style.isCpp()) {
+if (IsCpp) {
   const auto *Prev = CurrentToken->getPreviousNonComment();
   if (Prev && Prev->is(tok::r_square) &&

[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

https://github.com/MagentaTreehouse created 
https://github.com/llvm/llvm-project/pull/83693

None

>From 7c5498a5844cd5000c31ebef7d9295c98d94f75e Mon Sep 17 00:00:00 2001
From: Mingyi Chen 
Date: Sat, 2 Mar 2024 16:06:39 -0500
Subject: [PATCH] [NFC] Use fold expressions to replace discarded
 initializer_lists

---
 clang/lib/AST/Interp/ByteCodeEmitter.cpp| 5 +
 llvm/lib/Target/AArch64/AArch64SLSHardening.cpp | 9 ++---
 llvm/lib/Target/ARM/ARMSLSHardening.cpp | 9 ++---
 llvm/lib/Target/X86/X86IndirectThunks.cpp   | 9 ++---
 4 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index e1b954fcc68486..4fbfc0930fbaa1 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -302,10 +302,7 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... 
Args, const SourceInfo &S
   if (SI)
 SrcMap.emplace_back(Code.size(), SI);
 
-  // The initializer list forces the expression to be evaluated
-  // for each argument in the variadic template, in order.
-  (void)std::initializer_list{(emit(P, Code, Args, Success), 0)...};
-
+  (..., emit(P, Code, Args, Success));
   return Success;
 }
 
diff --git a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp 
b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
index 76dd5a2d713ebb..ce3bc0b1837558 100644
--- a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
@@ -412,20 +412,15 @@ class AArch64IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 
diff --git a/llvm/lib/Target/ARM/ARMSLSHardening.cpp 
b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
index 23d72b34902d0e..d9ff14ead60e27 100644
--- a/llvm/lib/Target/ARM/ARMSLSHardening.cpp
+++ b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
@@ -404,20 +404,15 @@ class ARMIndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 
diff --git a/llvm/lib/Target/X86/X86IndirectThunks.cpp 
b/llvm/lib/Target/X86/X86IndirectThunks.cpp
index 9db667900bffb3..ecc52600f75933 100644
--- a/llvm/lib/Target/X86/X86IndirectThunks.cpp
+++ b/llvm/lib/Target/X86/X86IndirectThunks.cpp
@@ -118,20 +118,15 @@ class X86IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64
@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: None (MagentaTreehouse)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/83693.diff


4 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeEmitter.cpp (+1-4) 
- (modified) llvm/lib/Target/AArch64/AArch64SLSHardening.cpp (+2-7) 
- (modified) llvm/lib/Target/ARM/ARMSLSHardening.cpp (+2-7) 
- (modified) llvm/lib/Target/X86/X86IndirectThunks.cpp (+2-7) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index e1b954fcc68486..4fbfc0930fbaa1 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -302,10 +302,7 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... 
Args, const SourceInfo &S
   if (SI)
 SrcMap.emplace_back(Code.size(), SI);
 
-  // The initializer list forces the expression to be evaluated
-  // for each argument in the variadic template, in order.
-  (void)std::initializer_list{(emit(P, Code, Args, Success), 0)...};
-
+  (..., emit(P, Code, Args, Success));
   return Success;
 }
 
diff --git a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp 
b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
index 76dd5a2d713ebb..ce3bc0b1837558 100644
--- a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
@@ -412,20 +412,15 @@ class AArch64IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 
diff --git a/llvm/lib/Target/ARM/ARMSLSHardening.cpp 
b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
index 23d72b34902d0e..d9ff14ead60e27 100644
--- a/llvm/lib/Target/ARM/ARMSLSHardening.cpp
+++ b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
@@ -404,20 +404,15 @@ class ARMIndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 
diff --git a/llvm/lib/Target/X86/X86IndirectThunks.cpp 
b/llvm/lib/Target/X86/X86IndirectThunks.cpp
index 9db667900bffb3..ecc52600f75933 100644
--- a/llvm/lib/Target/X86/X86IndirectThunks.cpp
+++ b/llvm/lib/Target/X86/X86IndirectThunks.cpp
@@ -118,20 +118,15 @@ class X86IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 

``




https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-03-02 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

```
error: 'expected-error' diagnostics seen but not expected:
  File 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-6mhbj-1/llvm-project/clang-ci/clang/test/Modules/explicit-build-overlap.cpp
 Line 11: module use does not directly depend on a module exporting 'a.h', 
which is part of indirectly-used module b
1 error generated.
```

https://github.com/llvm/llvm-project/pull/83660
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86] Use generic CPU tuning when tune-cpu is empty (PR #83631)

2024-03-02 Thread via cfe-commits

AtariDreams wrote:

> Please check the CI - these failures look relevant
> 
> ```
> Failed Tests (4):
>   lld :: COFF/lto-cpu-string.ll
>   lld :: COFF/lto.ll
>   lld :: ELF/lto/cpu-string.ll
>   lld :: MachO/lto-cpu-string.ll
> ```

they are and I am getting to them.

https://github.com/llvm/llvm-project/pull/83631
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

Sirraide wrote:

LGTM. This seems like a straight-forward change, so I don’t see anything that 
could really go wrong here.

https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

https://github.com/Sirraide approved this pull request.


https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Add noinline check for __builtin_frame_address and __builtin_return_address (PR #82966)

2024-03-02 Thread via cfe-commits

https://github.com/Sirraide edited 
https://github.com/llvm/llvm-project/pull/82966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Add noinline check for __builtin_frame_address and __builtin_return_address (PR #82966)

2024-03-02 Thread via cfe-commits

https://github.com/Sirraide requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/82966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Add noinline check for __builtin_frame_address and __builtin_return_address (PR #82966)

2024-03-02 Thread via cfe-commits


@@ -2029,6 +2029,10 @@ def warn_frame_address : Warning<
   "calling '%0' with a nonzero argument is unsafe">,
   InGroup, DefaultIgnore;
 
+def warn_frame_address_missing_noinline: Warning<
+  "calling '%0' in function not marked __attribute__((noinline)) may return a 
caller's %1 address">,

Sirraide wrote:

This is a minor thing, but you should probably use `%select` for `%1` here 
instead of passing in e.g. `"frame"` as a string. The `%0` is fine imo because 
it’s the name of a builtin function.

https://github.com/llvm/llvm-project/pull/82966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Add noinline check for __builtin_frame_address and __builtin_return_address (PR #82966)

2024-03-02 Thread via cfe-commits

Sirraide wrote:

> In my opinion, it's confusing for the behavior to change depending on 
> optimization levels

I will say, if you’re calling `__builtin_frame_address` when optimisations are 
enabled then I’m not quite sure what you’re expecting, candidly; I’m not 
convinced we should warn on this, but I’m also not that familiar w/ how people 
typically use this builtin.

https://github.com/llvm/llvm-project/pull/82966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

Sirraide wrote:

Hmm, CI seems to be failing on some flang tests, but other prs seem to be 
experiencing similar issues, so I don’t think this pr broke anything.

https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

Sirraide wrote:

Just saw that another pr was merged earlier that also ran into this issue, so 
I’m just going to assume that this is fine; it’s just Flang on Windows that 
seems to be a bit broken atm.

https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f505a92 - [NFC] Use fold expressions to replace discarded initializer_lists (#83693)

2024-03-02 Thread via cfe-commits

Author: MagentaTreehouse
Date: 2024-03-02T23:44:17+01:00
New Revision: f505a92fc2e965f1fe2e6a25d1ff4f0d9d1297c6

URL: 
https://github.com/llvm/llvm-project/commit/f505a92fc2e965f1fe2e6a25d1ff4f0d9d1297c6
DIFF: 
https://github.com/llvm/llvm-project/commit/f505a92fc2e965f1fe2e6a25d1ff4f0d9d1297c6.diff

LOG: [NFC] Use fold expressions to replace discarded initializer_lists (#83693)

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
llvm/lib/Target/ARM/ARMSLSHardening.cpp
llvm/lib/Target/X86/X86IndirectThunks.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index e1b954fcc68486..4fbfc0930fbaa1 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -302,10 +302,7 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... 
Args, const SourceInfo &S
   if (SI)
 SrcMap.emplace_back(Code.size(), SI);
 
-  // The initializer list forces the expression to be evaluated
-  // for each argument in the variadic template, in order.
-  (void)std::initializer_list{(emit(P, Code, Args, Success), 0)...};
-
+  (..., emit(P, Code, Args, Success));
   return Success;
 }
 

diff  --git a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp 
b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
index 76dd5a2d713ebb..ce3bc0b1837558 100644
--- a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
@@ -412,20 +412,15 @@ class AArch64IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 

diff  --git a/llvm/lib/Target/ARM/ARMSLSHardening.cpp 
b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
index 23d72b34902d0e..d9ff14ead60e27 100644
--- a/llvm/lib/Target/ARM/ARMSLSHardening.cpp
+++ b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
@@ -404,20 +404,15 @@ class ARMIndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 

diff  --git a/llvm/lib/Target/X86/X86IndirectThunks.cpp 
b/llvm/lib/Target/X86/X86IndirectThunks.cpp
index 9db667900bffb3..ecc52600f75933 100644
--- a/llvm/lib/Target/X86/X86IndirectThunks.cpp
+++ b/llvm/lib/Target/X86/X86IndirectThunks.cpp
@@ -118,20 +118,15 @@ class X86IndirectThunks : public MachineFunctionPass {
 private:
   std::tuple TIs;
 
-  // FIXME: When LLVM moves to C++17, these can become folds
   template 
   static void initTIs(Module &M,
   std::tuple &ThunkInserters) {
-(void)std::initializer_list{
-(std::get(ThunkInserters).init(M), 0)...};
+(..., std::get(ThunkInserters).init(M));
   }
   template 
   static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
  std::tuple &ThunkInserters) {
-bool Modified = false;
-(void)std::initializer_list{
-Modified |= std::get(ThunkInserters).run(MMI, MF)...};
-return Modified;
+return (0 | ... | std::get(ThunkInserters).run(MMI, MF));
   }
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

https://github.com/Sirraide closed 
https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NFC] Use fold expressions to replace discarded initializer_lists (PR #83693)

2024-03-02 Thread via cfe-commits

github-actions[bot] wrote:



@MagentaTreehouse Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/83693
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

2024-03-02 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


https://github.com/llvm/llvm-project/pull/82689
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

2024-03-02 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


https://github.com/llvm/llvm-project/pull/82689
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Test?

https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-02 Thread Fangrui Song via cfe-commits


@@ -942,20 +942,28 @@ CompressedOffloadBundle::compress(const 
llvm::MemoryBuffer &Input,
   Input.getBuffer().size());
 
   llvm::compression::Format CompressionFormat;
+  int Level;
 
-  if (llvm::compression::zstd::isAvailable())
+  if (llvm::compression::zstd::isAvailable()) {
 CompressionFormat = llvm::compression::Format::Zstd;
-  else if (llvm::compression::zlib::isAvailable())
+// Use a high zstd compress level by default for better size reduction.
+const int DefaultZstdLevel = 20;

MaskRay wrote:

High levels decrease compression speed substantially. Have you checked that 20 
hits a good sweet spot between 9 to 22 (max)?

Is OffloadBundler used more like a linker than a compile action where 
parallelism helps? If yes, lld/ELF/OutputSections.cpp has some code, which can 
be copied here. (Please don't share the code, I think some duplication in 
lld/ELF makes lld code easier to change)

https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-02 Thread Fangrui Song via cfe-commits


@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib && !zstd

MaskRay wrote:

Since zstd configurations become more prevalence, `zlib && !zstd` would 
essentially disable the test for increasingly more bots. But I guess this 
cannot be improved.

https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-02 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-02 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Remove duplicate -r flag usage when linking (PR #82715)

2024-03-02 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Gnu.cpp used by Linux doesn't have the problem. Thanks for fixing other targets.

https://github.com/llvm/llvm-project/pull/82715
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Remove duplicate -r flag usage when linking (PR #82715)

2024-03-02 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/82715
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Remove duplicate -r flag usage when linking (PR #82715)

2024-03-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/82715
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d5f77e1 - [Driver] Remove duplicate -r flag usage when linking (#82715)

2024-03-02 Thread via cfe-commits

Author: Brad Smith
Date: 2024-03-02T21:33:59-05:00
New Revision: d5f77e112e6352d933afa22920a4a0d3bf8d26e5

URL: 
https://github.com/llvm/llvm-project/commit/d5f77e112e6352d933afa22920a4a0d3bf8d26e5
DIFF: 
https://github.com/llvm/llvm-project/commit/d5f77e112e6352d933afa22920a4a0d3bf8d26e5.diff

LOG: [Driver] Remove duplicate -r flag usage when linking (#82715)

Bug #82010

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index cc1219d69d9910..fff538d2e5d735 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -643,9 +643,8 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as 
expected.
-  Args.addAllArgs(CmdArgs,
-  {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
-   options::OPT_Z_Flag, options::OPT_u_Group, options::OPT_r});
+  Args.addAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, 
options::OPT_t,
+options::OPT_Z_Flag, options::OPT_u_Group});
 
   // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
   // members of static archive libraries which implement Objective-C classes or

diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 9942fc632e0a91..89e0600277c44c 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -122,7 +122,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
-options::OPT_s, options::OPT_t, options::OPT_r});
+options::OPT_s, options::OPT_t});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index b7c9e0e51cdb66..9d698f77583950 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -261,8 +261,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
-options::OPT_t, options::OPT_r});
+  Args.addAllArgs(CmdArgs,
+  {options::OPT_T_Group, options::OPT_s, options::OPT_t});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");

diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index e0d94035823fd3..ca7faa68765abf 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -80,7 +80,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
-options::OPT_s, options::OPT_t, options::OPT_r});
+options::OPT_s, options::OPT_t});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   if (D.isUsingLTO()) {

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 240bf5764b9cce..645d0311641f34 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -268,7 +268,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
-options::OPT_s, options::OPT_t, options::OPT_r});
+options::OPT_s, options::OPT_t});
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index fd6aa4d7e68447..97f88b7b79dfbe 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -192,8 +192,8 @@ void openbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From ad96ce2633c62efa2de6b4925e8c3c11e98ba8bb Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 97f88b7b79dfbe..6da6728585df93 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
@@ -160,8 +161,11 @@ void openbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (Nopie || Profiling)
 CmdArgs.push_back("-nopi

[clang] [lld] [llvm] [X86] Use generic CPU tuning when tune-cpu is empty (PR #83631)

2024-03-02 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

This is a turbulent change to both upstream and downstream tests without any 
profit as far as I can tell.

I did a similar change for 64-bit a few years ago: 
https://reviews.llvm.org/D129647

In comparison, this patch is not to solve a specific problem. It should not 
show any value because we don't care about 32-bit performance. Not to mention, 
we need to keep the test not changed as many as possible. The way we used in 
D129647 is to add an explicit "tune-cpu". We cannot blindly update tests in 
case distort the original intention.

https://github.com/llvm/llvm-project/pull/83631
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [X86] Use generic CPU tuning when tune-cpu is empty (PR #83631)

2024-03-02 Thread Craig Topper via cfe-commits

topperc wrote:

> This is a turbulent change to both upstream and downstream tests without any 
> profit as far as I can tell.
> 
> I did a similar change for 64-bit a few years ago: 
> https://reviews.llvm.org/D129647
> 
> In comparison, this patch is not to solve a specific problem. It should not 
> show any value because we don't care about 32-bit performance. Not to 
> mention, we need to keep the test not changed as many as possible. The way we 
> used in D129647 is to add an explicit "tune-cpu". We cannot blindly update 
> tests in case distort the original intention.

I think I probaby wrote the FIXME and I agree with @phoebewang 

https://github.com/llvm/llvm-project/pull/83631
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c462160 - More fix BUILD_SHARED_LIBS=ON build for platforms which require explicit link of -lpthread (NFC)

2024-03-02 Thread Mehdi Amini via cfe-commits

Author: Mehdi Amini
Date: 2024-03-02T19:54:35-08:00
New Revision: c4621607245a5feed42cf9f748ff796728ef579a

URL: 
https://github.com/llvm/llvm-project/commit/c4621607245a5feed42cf9f748ff796728ef579a
DIFF: 
https://github.com/llvm/llvm-project/commit/c4621607245a5feed42cf9f748ff796728ef579a.diff

LOG: More fix BUILD_SHARED_LIBS=ON build for platforms which require explicit 
link of -lpthread (NFC)

Some systems requires explictly providing -lpthread when linking, I don't
have such system so it is hard to find all the missing cases.

Added: 


Modified: 
clang/lib/Tooling/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Tooling/CMakeLists.txt 
b/clang/lib/Tooling/CMakeLists.txt
index aff39e4de13c0b..91e6cbdcbc44f7 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -135,4 +135,5 @@ add_clang_library(clangTooling
   clangRewrite
   clangSerialization
   clangToolingCore
+  ${LLVM_PTHREAD_LIB}
   )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 706bf652f2dec8a4c9341641e53bf57647bf49e3 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  9 +
 clang/test/Driver/haiku.c   | 10 ++
 clang/test/Driver/netbsd.c  | 14 ++
 clang/test/Driver/openbsd.c |  9 +++--
 8 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 97f88b7b79dfbe..6da6728585df93 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool Static = Args.hasArg

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 35cd96b70bb616bbca68371e374655d0508fc7a8 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  9 +
 clang/test/Driver/fuchsia.c | 10 ++
 clang/test/Driver/haiku.c   | 10 ++
 clang/test/Driver/netbsd.c  | 14 ++
 clang/test/Driver/openbsd.c |  9 +++--
 10 files changed, 76 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 edited https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Remove duplicate -r flag usage when linking (PR #82715)

2024-03-02 Thread Brad Smith via cfe-commits

brad0 wrote:

Fuchsia I think has the same issue, but the Driver code is a bit different.

https://github.com/llvm/llvm-project/pull/82715
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-02 Thread Yaxun Liu via cfe-commits


@@ -942,20 +942,28 @@ CompressedOffloadBundle::compress(const 
llvm::MemoryBuffer &Input,
   Input.getBuffer().size());
 
   llvm::compression::Format CompressionFormat;
+  int Level;
 
-  if (llvm::compression::zstd::isAvailable())
+  if (llvm::compression::zstd::isAvailable()) {
 CompressionFormat = llvm::compression::Format::Zstd;
-  else if (llvm::compression::zlib::isAvailable())
+// Use a high zstd compress level by default for better size reduction.
+const int DefaultZstdLevel = 20;

yxsamliu wrote:

level 20 is a sweet spot for both compression rate and compression time, as 
shown in the following table for Blender 4.1 bundled bitcode for 6 GPU archs:

| Zstd Level | Size Before (bytes) | Size After (bytes) | Compression Rate | 
Compression Time (s) | Decompression Time (s) |
||-||--|--||
| 6  | 68,459,756  | 32,612,291 | 2.10 | 
0.8891   | 0.1809 |
| 9  | 68,459,756  | 31,445,373 | 2.18 | 
1.4200   | 0.1742 |
| 15 | 68,459,756  | 28,063,493 | 2.44 | 
9.7994   | 0.1712 |
| 18 | 68,459,756  | 24,952,891 | 2.74 | 
11.4201  | 0.1796 |
| 19 | 68,459,756  | 24,690,733 | 2.77 | 
13.4060  | 0.1820 |
| 20 | 68,459,756  | 4,394,993  | 15.58| 
2.0946   | 0.1320 |
| 21 | 68,459,756  | 4,394,399  | 15.59| 
2.1500   | 0.1318 |
| 22 | 68,459,756  | 4,394,429  | 15.59| 
2.6635   | 0.1309 |

Level 20 and level 19 has some compression parameter differences 
(https://github.com/facebook/zstd/blob/a58b48ef0e543980888a4d9d16c9072ff22135ca/lib/compress/clevels.h#L48
 ) the meaning of these parameters are defined at 
https://github.com/facebook/zstd/blob/a58b48ef0e543980888a4d9d16c9072ff22135ca/lib/zstd.h#L1299.
 It seems either the largest match distance or fully searched segment makes the 
difference.

clang-offload-bundler just concatenates the binaries for different GPU arch's 
together. Parallelization does not help much, unless zstd can be parallelized.


https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-02 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/83709

Fixes #83400.

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH] [clang-format] Handle common C++ non-keyword types as such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return 

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #83400.

---
Full diff: https://github.com/llvm/llvm-project/pull/83709.diff


7 Files Affected:

- (modified) clang/lib/Format/FormatToken.cpp (+13-3) 
- (modified) clang/lib/Format/FormatToken.h (+2-2) 
- (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+15-10) 
- (modified) clang/lib/Format/QualifierAlignmentFixer.h (+3-2) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+16-13) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+6-6) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6) 


``diff
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -408,11 +412,12 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
   // The case `volatile long long const int` -> `const volatile long long i

[clang] [llvm] [AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (PR #65996)

2024-03-02 Thread Anton Korobeynikov via cfe-commits

https://github.com/asl milestoned 
https://github.com/llvm/llvm-project/pull/65996
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #67454)

2024-03-02 Thread Anton Korobeynikov via cfe-commits

https://github.com/asl milestoned 
https://github.com/llvm/llvm-project/pull/67454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik requested changes to this pull request.

We need a minimal reproducer here. Looking at the bug report it is not clear to 
me if this is the correct fix or not. After we have a reproducer we would need 
a test added to the PR and a release note.

https://github.com/llvm/llvm-project/pull/83686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/83686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AST] fix dereference on class/struct layouts check. (PR #83686)

2024-03-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/83686
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/83688
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-02 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I think this makes sense but I would like another set of eyes.

https://github.com/llvm/llvm-project/pull/83688
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-02 Thread Shafik Yaghmour via cfe-commits


@@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType())

shafik wrote:

Can you update the comment above to reflect this change.

https://github.com/llvm/llvm-project/pull/83688
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-02 Thread Owen Pan via cfe-commits

owenca wrote:

> So I did added a simple search and replace to the generating script so now 
> every time [[[NAME]]] is reference it will use the members name.

Nice! Though why `[[[NAME]]]` in particular? Can we use `` instead?

https://github.com/llvm/llvm-project/pull/83415
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-02 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/83415
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Fangrui Song via cfe-commits


@@ -203,3 +203,12 @@
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 
+// Check that the -X flag is passed to the linker on riscv64

MaskRay wrote:

The CHECK is self-explanatory and renders the comment redundant. The RUN line 
may test additional options in the future.

https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-02 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-02 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> here is my analysis:
> 
> (Let's use the example from your test case)
> 
> ```c++
> template 
> struct waldo {
>   using type = waldo::type::next;
> };
> ```
> 
> So, we're somehow attempting to resolve the type/decl for `next`, which is of 
> `DependentNameType`. To achieve that, we want to inspect the type of its 
> prefix i.e. the `waldo::type`, which is another `NestedNameSpecifier` 
> and thus we shall find out the type of `waldo` first - which is of 
> `ClassTemplateSpecializationType`. Then, we would perform a name lookup for 
> `type` within the context thereof, which results in the solely `TypedefType` 
> we're currently in.
> 
> Then we move on and try to find out what the `next` is with the `TypedefType` 
> as its prefix. This would happen in `resolveDependentMember`, with `T` as 
> `TypedefType` and `Name` as `next`. We expect that prefix to be of a 
> `RecordType` so that we can perform a name lookup. That is 
> `resolveTypeToRecordDecl`, and the type alias would get unwrapped and become 
> a `DependentNameType` in the end.
> 
> And now we're successfully getting into an infinite loop: we want to know the 
> type of `type`, which ends up a type alias `type` that would boil down to 
> itself!

Thanks for the detailed writeup of how the issue arises! This matches my 
understanding.

Another way to think about it is that `waldo` is like a recursive compile-time 
function (`waldo::type` is a function of `waldo::type`). In a 
real-world scenario, the recursion would be terminated by a base case expressed 
as a template specialization (for example `waldo<0>`). However, 
`HeuristicResolver` always looks at the primary template (that is the 
[heuristic 
aspect](https://searchfox.org/llvm/rev/bf08d0286825eb3e482bcfdc1cc7c19a28441ae7/clang-tools-extra/clangd/HeuristicResolver.h#43-45)
 of it), it will never look at a specialization, so its analysis of such a 
recursive construct would never terminate even if the code does in fact contain 
a base case.

> The PR resolves it by tracking every seen DependentNameType with a set. And 
> since we don't want to turn the stateless `HeuristicResolver` to something 
> stateful (e.g. adding extra data members), we have to add another layer to 
> hide our implementation - this is what you've done.
> 
> However, I think we could track these `DependentNameType`s by adding some 
> extra parameters. Specifically, we can pass through the `DNT` from 
> `resolveDependentNameType` to `resolveDependentMember` and 
> `resolveTypeToRecordDecl`, then inside `resolveTypeToRecordDecl`, we bail out 
> with null if the unwrapped `DependentNameType` from `T` is the same as the 
> `DNT` - I did an experiment and it turns out to be working.

Thanks for the alternative suggestion!

I've considered this, but it's slightly less general than my fix. It handles 
the case where the we arrive back to the same DependentNameType in a **single** 
level of recursion, but we can also construct cases where it takes two or more 
levels.

Here is an example with two levels:

```c++
template 
struct odd;

template 
struct even {
  using type = typename odd::type::next;
};

template 
struct odd {
  using type = typename even::type::next;
};
```

To handle such cases, we need to keep track of a set of seen DependentNameTypes 
(hence the `llvm::SmallSet`), rather than just one.

We could also consider a variation of your approach where we have a 
`SmallSet`, but we pass it as an argument to 
`resolveDependentMember` etc., rather than storing it as a member variable.

On the whole, I prefer the member variable approach for a couple of reasons:
 * The call chain `resolveDependentNameType --> resolveDependentMember --> 
resolveTypeToRecordDecl --> resolveDependentNameType` is just one way that 
`resolveDependentNameType` can call itself recursively. Another possible call 
chain is `resolveDependentNameType --> resolveNestedNameSpecifierToType --> 
resolveDependentMember --> resolveTypeToRecordDecl --> 
resolveDependentNameType`, which would require propagating the 
`SmallSet` parameter to additional functions. By making it 
a member variable, we handle all call chains, including ones potentially 
introduced in the future.
 * In the future we may run into scenarios where we get into a recursion on 
some other AST node type (e.g. a `Decl` or some such). The refactoring in this 
patch makes it easy to add protection for that by e.g. adding a 
`SmallSet SeenDecls` member as well (vs. having to add that as an 
additional parameter to various methods).

https://github.com/llvm/llvm-project/pull/83542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits