[clang] [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (PR #112887)

2024-10-18 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/112887

This patch should not introduce much overhead as it only does one more 
constraint map lookup, which is really quick.

Depends on #112583

>From e380dd4572c8914fbd87a812e74addba1f24304d Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 16 Oct 2024 15:53:20 +0200
Subject: [PATCH] [analyzer][Solver] Teach SymbolicRangeInferrer about
 commutativity (2/2)

This patch should not introduce much overhead as it only does one more
constraint map lookup, which is really quick.
---
 .../Core/RangeConstraintManager.cpp   | 17 ++
 clang/test/Analysis/unary-sym-expr.c  | 33 +--
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ecf7974c838650..f0311b7028f56d 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
 // calculate the effective range set by intersecting the range set
 // for A - B and the negated range set of B - A.
 getRangeForNegatedSymSym(SSE),
+// If commutative, we may have constaints for the commuted variant.
+getRangeCommutativeSymSym(SSE),
 // If Sym is a comparison expression (except <=>),
 // find any other comparisons with the same operands.
 // See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
 Sym->getType());
   }
 
+  std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) {
+auto Op = SSE->getOpcode();
+bool IsCommutative = llvm::is_contained(
+// ==, !=, |, &, +, *, ^
+{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
+if (!IsCommutative)
+  return std::nullopt;
+
+SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
+if (const RangeSet *Range = getConstraint(State, Commuted))
+  return *Range;
+return std::nullopt;
+  }
+
   // Returns ranges only for binary comparison operators (except <=>)
   // when left and right operands are symbolic values.
   // Finds any other comparisons with the same operands.
diff --git a/clang/test/Analysis/unary-sym-expr.c 
b/clang/test/Analysis/unary-sym-expr.c
index 7c4774f3cca82f..92e11b295bee7c 100644
--- a/clang/test/Analysis/unary-sym-expr.c
+++ b/clang/test/Analysis/unary-sym-expr.c
@@ -29,12 +29,39 @@ int test(int x, int y) {
   return 42;
 }
 
-void test_svalbuilder_simplification(int x, int y) {
+void test_svalbuilder_simplification_add(int x, int y) {
   if (x + y != 3)
 return;
   clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
-  // FIXME Commutativity is not supported yet.
-  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_mul(int x, int y) {
+  if (x * y != 3)
+return;
+  clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_and(int x, int y) {
+  if ((x & y) != 3)
+return;
+  clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_or(int x, int y) {
+  if ((x | y) != 3)
+return;
+  clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_xor(int x, int y) {
+  if ((x ^ y) != 3)
+return;
+  clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
 }
 
 int test_fp(int flag) {

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


[clang] [Clang] [PGO] Provide default value for -fprofile-sample-use (PR #112750)

2024-10-18 Thread Mikołaj Piróg via cfe-commits

https://github.com/mikolaj-pirog updated 
https://github.com/llvm/llvm-project/pull/112750

From 642f7ac9b1e999d8adb690b67c6303139794379d Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" 
Date: Thu, 17 Oct 2024 10:17:09 -0700
Subject: [PATCH 1/2] Provide default value for -fprofile-sample-use

---
 clang/lib/Driver/ToolChains/Clang.cpp | 21 +
 1 file changed, 21 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fc39296f44281..2da8b604ebff62 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -594,6 +594,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 << PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
 
   auto *ProfileUseArg = getLastProfileUseArg(Args);
+  auto *ProfileSampleUseArg = Args.getLastArg(
+  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
 
   if (PGOGenerateArg && ProfileUseArg)
 D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -677,6 +679,25 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 }
   }
 
+  if (ProfileSampleUseArg) {
+if ((ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use) ||
+ ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use_EQ))) {
+  SmallString<128> Path(ProfileSampleUseArg->getNumValues() == 0
+? ""
+: ProfileSampleUseArg->getValue());
+  if (Path.empty() || llvm::sys::fs::is_directory(Path))
+llvm::sys::path::append(Path, "default.profdata");
+
+  if (!llvm::sys::fs::exists(Path))
+D.Diag(diag::err_drv_no_such_file) << Path;
+
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-fprofile-sample-use=") + Path));
+}
+  }
+
   bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
options::OPT_fno_test_coverage, false) ||
   Args.hasArg(options::OPT_coverage);

From 571b9ddef3dcffdea76681fd2b3608a26dc3f1ef Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" 
Date: Fri, 18 Oct 2024 04:51:11 -0700
Subject: [PATCH 2/2] Fix tests and correct behaviour on -fno.. options

---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 +-
 clang/test/Driver/clang_f_opts.c  |  5 +++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2da8b604ebff62..d588badcc03b14 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -595,7 +595,15 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 
   auto *ProfileUseArg = getLastProfileUseArg(Args);
   auto *ProfileSampleUseArg = Args.getLastArg(
-  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
+  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
+  options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
+  options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
+
+  if (ProfileSampleUseArg &&
+  (ProfileSampleUseArg->getOption().matches(
+   options::OPT_fno_profile_sample_use) ||
+   
ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
+ProfileSampleUseArg = nullptr;
 
   if (PGOGenerateArg && ProfileUseArg)
 D.Diag(diag::err_drv_argument_not_allowed_with)
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index fd15552715cb35..4d6f13038763ed 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -71,8 +71,9 @@
 // RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile %s 
2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s
 // CHECK-NO-AUTO-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof"
 
-// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE %s
-// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile 
-fprofile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s
+// RUN: not %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE-NO-DEFAULT %s
+// RUN: not %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-auto-profile -fprofile-sample-use %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE-NO-DEFAULT %s
+// CHECK-AUTO-PROFILE-NO-DEFAULT: error: no such file or directory: 
'default.profdata'
 
 // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE-LLVM %s
 // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE %s

___

[clang] [Clang] Provide default value for -fprofile-sample-use, -fprofile-auto (PR #112750)

2024-10-18 Thread Mikołaj Piróg via cfe-commits

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


[clang] [clang] LazyOffsetPtr: Use native pointer width (PR #111995)

2024-10-18 Thread Richard Smith via cfe-commits

zygoloid wrote:

> How about:
> [...]

Yeah, I think that fixes it. For me that looks a lot less simple than using a 
union, but it is nice to have only a single implementation. I'd be fine with 
going in that direction.

For CHERI, can we assume that the least-significant byte of the pointer 
representation is even when the alignment of the type is > 1?

> The std::launder may be unnecessary

Formally I think it's correct and necessary for the pointer and integer case 
because an array element and an object for which the array provides storage are 
not pointer-interconvertible, but it's incorrect for the `unsigned char` case 
because there's no in-lifetime `unsigned char` object at the provided address.

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


[clang] [Clang] Provide default value for -fprofile-sample-use, -fprofile-auto (PR #112750)

2024-10-18 Thread Mikołaj Piróg via cfe-commits

https://github.com/mikolaj-pirog updated 
https://github.com/llvm/llvm-project/pull/112750

From 642f7ac9b1e999d8adb690b67c6303139794379d Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" 
Date: Thu, 17 Oct 2024 10:17:09 -0700
Subject: [PATCH 1/3] Provide default value for -fprofile-sample-use

---
 clang/lib/Driver/ToolChains/Clang.cpp | 21 +
 1 file changed, 21 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fc39296f44281..2da8b604ebff62 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -594,6 +594,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 << PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
 
   auto *ProfileUseArg = getLastProfileUseArg(Args);
+  auto *ProfileSampleUseArg = Args.getLastArg(
+  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
 
   if (PGOGenerateArg && ProfileUseArg)
 D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -677,6 +679,25 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 }
   }
 
+  if (ProfileSampleUseArg) {
+if ((ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use) ||
+ ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use_EQ))) {
+  SmallString<128> Path(ProfileSampleUseArg->getNumValues() == 0
+? ""
+: ProfileSampleUseArg->getValue());
+  if (Path.empty() || llvm::sys::fs::is_directory(Path))
+llvm::sys::path::append(Path, "default.profdata");
+
+  if (!llvm::sys::fs::exists(Path))
+D.Diag(diag::err_drv_no_such_file) << Path;
+
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-fprofile-sample-use=") + Path));
+}
+  }
+
   bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
options::OPT_fno_test_coverage, false) ||
   Args.hasArg(options::OPT_coverage);

From 571b9ddef3dcffdea76681fd2b3608a26dc3f1ef Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" 
Date: Fri, 18 Oct 2024 04:51:11 -0700
Subject: [PATCH 2/3] Fix tests and correct behaviour on -fno.. options

---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 +-
 clang/test/Driver/clang_f_opts.c  |  5 +++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2da8b604ebff62..d588badcc03b14 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -595,7 +595,15 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 
   auto *ProfileUseArg = getLastProfileUseArg(Args);
   auto *ProfileSampleUseArg = Args.getLastArg(
-  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
+  options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
+  options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
+  options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
+
+  if (ProfileSampleUseArg &&
+  (ProfileSampleUseArg->getOption().matches(
+   options::OPT_fno_profile_sample_use) ||
+   
ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
+ProfileSampleUseArg = nullptr;
 
   if (PGOGenerateArg && ProfileUseArg)
 D.Diag(diag::err_drv_argument_not_allowed_with)
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index fd15552715cb35..4d6f13038763ed 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -71,8 +71,9 @@
 // RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile %s 
2>&1 | FileCheck -check-prefix=CHECK-NO-AUTO-PROFILE %s
 // CHECK-NO-AUTO-PROFILE-NOT: "-fprofile-sample-use={{.*}}/file.prof"
 
-// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE %s
-// RUN: %clang -### -S -fauto-profile=%S/Inputs/file.prof -fno-auto-profile 
-fprofile-sample-use %s 2>&1 | FileCheck -check-prefix=CHECK-AUTO-PROFILE %s
+// RUN: not %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-profile-sample-use -fauto-profile %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE-NO-DEFAULT %s
+// RUN: not %clang -### -S -fauto-profile=%S/Inputs/file.prof 
-fno-auto-profile -fprofile-sample-use %s 2>&1 | FileCheck 
-check-prefix=CHECK-AUTO-PROFILE-NO-DEFAULT %s
+// CHECK-AUTO-PROFILE-NO-DEFAULT: error: no such file or directory: 
'default.profdata'
 
 // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE-LLVM %s
 // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE %s

From 259de937232aa98c79

[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-18 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/112747

>From c2f223d84c18498f3cbe1582b006b0d4c52999aa Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Thu, 17 Oct 2024 14:04:05 +0100
Subject: [PATCH 1/3] [Clang][AArch64] Fix Pure Scalables Types argument
 passing and return

Pure Scalable Types are defined in AAPCS64 here:
  
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#pure-scalable-types-psts

And should be passed according to Rule C.7 here:
  
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#682parameter-passing-rules

This part of the ABI is completely unimplemented in Clang, instead
it treats PSTs sometimes as HFAs/HVAs, sometime as general composite
types.

This patch implements the rules for passing PSTs by employing the
`CoerceAndExpand` method and extending it to:
  * allow array types in the `coerceToType`; Now only `[N x i8]` are
considered padding.
  * allow mismatch between the elements of the `coerceToType` and the
elements of the `unpaddedCoerceToType`; AArch64 uses this to map
fixed-length vector types to SVE vector types.

Corectly passing a PST argument needs a decision in Clang about
whether to pass it in memory or registers or, equivalently, whether
to use the `Indirect` or `Expand/CoerceAndExpand` method.
It was considered relatively harder (or not practically possible)
to make that decision in the AArch64 backend.
Hence this patch implements the register counting
from AAPCS64 (cf. "NSRN", "NPRN") to guide the Clang's decision.
---
 clang/include/clang/CodeGen/CGFunctionInfo.h  |  13 +-
 clang/lib/CodeGen/CGCall.cpp  |  85 +++--
 clang/lib/CodeGen/Targets/AArch64.cpp | 326 --
 .../test/CodeGen/aarch64-pure-scalable-args.c | 314 +
 4 files changed, 669 insertions(+), 69 deletions(-)
 create mode 100644 clang/test/CodeGen/aarch64-pure-scalable-args.c

diff --git a/clang/include/clang/CodeGen/CGFunctionInfo.h 
b/clang/include/clang/CodeGen/CGFunctionInfo.h
index d19f84d198876f..915f676d7d3905 100644
--- a/clang/include/clang/CodeGen/CGFunctionInfo.h
+++ b/clang/include/clang/CodeGen/CGFunctionInfo.h
@@ -272,11 +272,6 @@ class ABIArgInfo {
 unsigned unpaddedIndex = 0;
 for (auto eltType : coerceToType->elements()) {
   if (isPaddingForCoerceAndExpand(eltType)) continue;
-  if (unpaddedStruct) {
-assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
-  } else {
-assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
-  }
   unpaddedIndex++;
 }
 
@@ -295,12 +290,8 @@ class ABIArgInfo {
   }
 
   static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
-if (eltType->isArrayTy()) {
-  assert(eltType->getArrayElementType()->isIntegerTy(8));
-  return true;
-} else {
-  return false;
-}
+return eltType->isArrayTy() &&
+   eltType->getArrayElementType()->isIntegerTy(8);
   }
 
   Kind getKind() const { return TheKind; }
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..3c75dae9918af9 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1410,6 +1410,30 @@ static Address emitAddressAtOffset(CodeGenFunction &CGF, 
Address addr,
   return addr;
 }
 
+static std::pair
+CoerceScalableToFixed(CodeGenFunction &CGF, llvm::FixedVectorType *ToTy,
+  llvm::ScalableVectorType *FromTy, llvm::Value *V,
+  StringRef Name = "") {
+  // If we are casting a scalable i1 predicate vector to a fixed i8
+  // vector, first bitcast the source.
+  if (FromTy->getElementType()->isIntegerTy(1) &&
+  FromTy->getElementCount().isKnownMultipleOf(8) &&
+  ToTy->getElementType() == CGF.Builder.getInt8Ty()) {
+FromTy = llvm::ScalableVectorType::get(
+ToTy->getElementType(),
+FromTy->getElementCount().getKnownMinValue() / 8);
+V = CGF.Builder.CreateBitCast(V, FromTy);
+  }
+  if (FromTy->getElementType() == ToTy->getElementType()) {
+llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
+
+V->setName(Name + ".coerce");
+V = CGF.Builder.CreateExtractVector(ToTy, V, Zero, "cast.fixed");
+return {V, true};
+  }
+  return {V, false};
+}
+
 namespace {
 
 /// Encapsulates information about the way function arguments from
@@ -3196,26 +3220,14 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
   // a VLAT at the function boundary and the types match up, use
   // llvm.vector.extract to convert back to the original VLST.
   if (auto *VecTyTo = dyn_cast(ConvertType(Ty))) {
-llvm::Value *Coerced = Fn->getArg(FirstIRArg);
+llvm::Value *ArgVal = Fn->getArg(FirstIRArg);
 if (auto *VecTyFrom =
-dyn_cast(Coerced->getType())) {
-  // If we are casting a scalable i1 predicate vector to a fixed i8
-  // vector, bitcast the sour

[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-18 Thread Momchil Velikov via cfe-commits


@@ -533,11 +638,158 @@ bool 
AArch64ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate()
   return true;
 }
 
+// Check if a type is a Pure Scalable Type as defined by AAPCS64. Return the
+// number of data vectors and the number of predicate vectors in the types, 
into
+// `NVec` and `NPred`, respectively. Upon return `CoerceToSeq` contains an
+// expanded sequence of LLVM IR types, one element for each non-composite
+// member. For practical purposes, limit the length of `CoerceToSeq` to about
+// 12, the maximum size that could possibly fit in registers.
+bool AArch64ABIInfo::isPureScalableType(
+QualType Ty, unsigned &NVec, unsigned &NPred,
+SmallVectorImpl &CoerceToSeq) const {
+  if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
+uint64_t NElt = AT->getZExtSize();
+if (NElt == 0)
+  return false;
+
+unsigned NV = 0, NP = 0;
+SmallVector EltCoerceToSeq;
+if (!isPureScalableType(AT->getElementType(), NV, NP, EltCoerceToSeq))
+  return false;
+
+for (uint64_t I = 0; CoerceToSeq.size() < 12 && I < NElt; ++I)
+  llvm::copy(EltCoerceToSeq, std::back_inserter(CoerceToSeq));
+
+NVec += NElt * NV;
+NPred += NElt * NP;
+return true;
+  }
+
+  if (const RecordType *RT = Ty->getAs()) {
+// If the record cannot be passed in registers, then it's not a PST.
+if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
+RAA != CGCXXABI::RAA_Default)
+  return false;
+
+// Pure scalable types are never unions and never contain unions.
+const RecordDecl *RD = RT->getDecl();
+if (RD->isUnion())
+  return false;
+
+// If this is a C++ record, check the bases bases.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+  for (const auto &I : CXXRD->bases()) {
+if (isEmptyRecord(getContext(), I.getType(), true))
+  continue;
+if (!isPureScalableType(I.getType(), NVec, NPred, CoerceToSeq))
+  return false;
+  }
+}
+
+// Check members.
+for (const auto *FD : RD->fields()) {
+  QualType FT = FD->getType();
+  if (isEmptyRecord(getContext(), FT, true))
+continue;
+  if (!isPureScalableType(FT, NVec, NPred, CoerceToSeq))
+return false;
+}
+
+return true;
+  }
+
+  const auto *VT = Ty->getAs();
+  if (!VT)
+return false;
+
+  if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
+++NPred;
+if (CoerceToSeq.size() < 12)

momchil-velikov wrote:

Done.

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


[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)

2024-10-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112424

>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier
 for missing primary declarations

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Sema/SemaAccess.cpp | 3 ++-
 clang/test/SemaCXX/enum.cpp   | 8 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set 
for missing
+  primary declarations. (#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-MemberDecl->setAccess(LexicalAS);
+if (LexicalAS != AS_none)
+  MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
 })
   };
 };
+
+namespace GH112208 {
+class C {
+  enum E { e = 0 };
+  void f(int, enum E;); // expected-error {{ISO C++ forbids forward references 
to 'enum' types}} \
+// expected-error {{unexpected ';' before ')'}}
+};
+}

>From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 14:55:47 +0300
Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum
 forward declarations

---
 clang/docs/ReleaseNotes.rst   | 3 +--
 clang/lib/Sema/SemaAccess.cpp | 3 +--
 clang/lib/Sema/SemaDecl.cpp   | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64ffdcde045a3a..3fd37663ca7bc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,8 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when the default lexical access specifier was set 
for missing
-  primary declarations. (#GH112208)
+- Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 8b4a5b70669d84..df6edb21a50dee 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-if (LexicalAS != AS_none)
-  MemberDecl->setAccess(LexicalAS);
+MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..9eb3d06289e88f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
+  if (TUK == TagUseKind::Declaration && Name)
+Invalid = true;
 } else if (!PrevDecl) {
   Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
 }

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


[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)

2024-10-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112612

>From 6112d12f757cce0214132e9201dc2a434e40e0c7 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 16 Oct 2024 23:42:05 +0300
Subject: [PATCH 1/2] [Clang] prevent assertion failure in value-dependent
 initializer expressions

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/lib/AST/ExprConstant.cpp   |  3 +++
 clang/test/SemaCXX/constant-expression-cxx11.cpp | 10 ++
 3 files changed, 14 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..1cbf95f0b034d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when evaluating constant expressions in 
value-dependent initializers (#GH112140)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 52a7f5778ce6d2..62d88f0f82b760 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11536,6 +11536,9 @@ bool 
ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(
   LValue Subobject = This;
   Subobject.addArray(Info, ExprToVisit, CAT);
   auto Eval = [&](const Expr *Init, unsigned ArrayIndex) {
+if (Init->isValueDependent())
+  return EvaluateDependentExpr(Init, Info);
+
 if (!EvaluateInPlace(Result.getArrayInitializedElt(ArrayIndex), Info,
  Subobject, Init) ||
 !HandleLValueArrayAdjustment(Info, Init, Subobject,
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index e2ea984b37cd04..e01aaff1459e88 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2564,3 +2564,13 @@ GH50055::E2 GlobalInitNotCE2 = 
GH50055::testDefaultArgForParam(); // ok, not a c
 constexpr GH50055::E2 GlobalInitCE = (GH50055::E2)-1;
 // expected-error@-1 {{constexpr variable 'GlobalInitCE' must be initialized 
by a constant expression}}
 // expected-note@-2 {{integer value -1 is outside the valid range of values 
[0, 7] for the enumeration type 'E2'}}
+
+namespace GH {
+struct S {
+  constexpr S(const int &a = ) { } // expected-error {{expected expression}}
+};
+
+void foo() {
+  constexpr S s[2] = { }; // expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
+}
+}

>From dd7ed58af0746763ce223dc95bf30ce9f09aa296 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 13:22:07 +0300
Subject: [PATCH 2/2] update ReleaseNotes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a80ca9b834dde1..ddabcb4bc444ec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -537,7 +537,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when evaluating constant expressions in 
value-dependent initializers (#GH112140)
+- Fixed an assertion failure when evaluating an invalid expression in an array 
initializer (#GH112140)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [Clang][Sema] Fix exception specification comparison for functions with different template depths (PR #111561)

2024-10-18 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/111561

>From dd1095566251508aae4009a626774413eb8dc7a1 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 8 Oct 2024 12:54:26 -0400
Subject: [PATCH 1/3] [Clang][Sema] Fix exception specification comparison for
 functions with different template depths

---
 clang/include/clang/Sema/Sema.h |   5 ++
 clang/lib/Sema/SemaExceptionSpec.cpp| 105 +++-
 clang/test/CXX/basic/basic.link/p11.cpp |  37 +
 3 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CXX/basic/basic.link/p11.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0faa5aed4eec3b..9ae882f651e2b0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5028,6 +5028,11 @@ class Sema final : public SemaBase {
   /// special member function.
   void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD);
 
+  bool AreExceptionSpecsEqual(const NamedDecl *Old,
+  const Expr *OldExceptionSpec,
+  const NamedDecl *New,
+  const Expr *NewExceptionSpec);
+
   /// Check the given exception-specification and update the
   /// exception specification information with the results.
   void checkExceptionSpecification(bool IsTopLevel,
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index dbddd6c370aa07..c74686073df228 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -10,7 +10,6 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTMutationListener.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Expr.h"
@@ -19,6 +18,9 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/EnterExpressionEvaluationContext.h"
+#include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include 
@@ -314,6 +316,22 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, 
FunctionDecl *New) {
 return false;
   }
 
+  if (Old->getExceptionSpecType() == EST_DependentNoexcept &&
+  New->getExceptionSpecType() == EST_DependentNoexcept) {
+const auto *OldType = Old->getType()->getAs();
+const auto *NewType = New->getType()->getAs();
+OldType = ResolveExceptionSpec(New->getLocation(), OldType);
+if (!OldType)
+  return false;
+NewType = ResolveExceptionSpec(New->getLocation(), NewType);
+if (!NewType)
+  return false;
+
+if (AreExceptionSpecsEqual(Old, OldType->getNoexceptExpr(), New,
+   NewType->getNoexceptExpr()))
+  return false;
+  }
+
   // Check the types as written: they must match before any exception
   // specification adjustment is applied.
   if (!CheckEquivalentExceptionSpecImpl(
@@ -501,6 +519,89 @@ bool Sema::CheckEquivalentExceptionSpec(
   return Result;
 }
 
+static const Expr *SubstituteExceptionSpecWithoutEvaluation(
+Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
+const Expr *ExceptionSpec) {
+  MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
+  DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(),
+  /*Final=*/false, /*Innermost=*/std::nullopt,
+  /*RelativeToPrimary=*/true, /*ForConstraintInstantiation=*/true);
+
+  if (!MLTAL.getNumSubstitutedLevels())
+return ExceptionSpec;
+
+  Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+
+  Sema::InstantiatingTemplate Inst(
+  S, DeclInfo.getLocation(),
+  const_cast(DeclInfo.getDecl()->getAsFunction()),
+  Sema::InstantiatingTemplate::ExceptionSpecification());
+  if (Inst.isInvalid())
+return nullptr;
+
+  // Set up a dummy 'instantiation' scope in the case of reference to function
+  // parameters that the surrounding function hasn't been instantiated yet. 
Note
+  // this may happen while we're comparing two templates' constraint
+  // equivalence.
+  LocalInstantiationScope ScopeForParameters(S);
+  if (auto *FD = DeclInfo.getDecl()->getAsFunction())
+for (auto *PVD : FD->parameters())
+  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+
+  std::optional ThisScope;
+
+  // See TreeTransform::RebuildTemplateSpecializationType. A context scope is
+  // essential for having an injected class as the canonical type for a 
template
+  // specialization type at the rebuilding stage. This guarantees that, for
+  // out-of-line definitions, injected class name types and their equivalent
+  // template specializations can be profiled to the same value, which makes it
+  // possible that e.g. constraints involving C> and C are
+  // perceived identical.
+  std::optional ContextScope

[clang] [clang] LazyOffsetPtr: Use native pointer width (PR #111995)

2024-10-18 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

> > How about:
> > [...]
> 
> Yeah, I think that fixes it. For me that looks a lot less simple than using a 
> union, but it is nice to have only a single implementation. I'd be fine with 
> going in that direction.
> 
> For CHERI, can we assume that the least-significant byte of the pointer 
> representation is even when the alignment of the type is > 1?

The integer address portion of the capability has the same representation, so 
will be even. On all little-endian CHERI platforms that exist today this is 
laid out in memory as you would expect, i.e. with the first byte being the LSB 
of the address and the last byte being the MSB of the metadata. Big-endian 
CHERI did historically exist and was a bit weird for various reasons, but will 
hopefully(?) never return. If it does, whoever wants to tackle that beast can 
port this code if it's no longer true there by fiddling with the offset 
calculations. But yes, the short answer is that the code as written should work 
on Morello and CHERI-RISC-V.

> > The std::launder may be unnecessary
> 
> Formally I think it's correct and necessary for the pointer and integer case 
> because an array element and an object for which the array provides storage 
> are not pointer-interconvertible, but it's incorrect for the `unsigned char` 
> case because there's no in-lifetime `unsigned char` object at the provided 
> address.

I'll defer to your expert opinion for what exactly to do here. If the launder 
is needed for the other types but not GetLSB the obvious fix is to just inline 
a simple specialisation of As, assuming direct access to `Data` is still 
permitted despite there being no in-lifetime `unsigned char`.

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


[clang] [clang-tools-extra] [flang] [lldb] [llvm] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-10-18 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

This seems to have broken precommit CI on Windows: 
https://buildkite.com/llvm-project/github-pull-requests/builds/65#0192a01b-d3ac-44ad-abff-e53ac4a206ab
 all of the failures look related to line endings, and I noticed that I got a 
ton of command line messages of the form:
```
warning: in the working copy of 'clang/include/clang/Basic/Attr.td', LF will be 
replaced by CRLF the next time Git touches it
```

> Can we revert this until we figure out these bits?

Yes, please.

> Do we really want checkouts to default to having the majority of files with 
> CRLF on Windows? I would expect that most people working on Windows don't 
> really want this (this wasn't the case so far anyway)?

It certainly came as a surprise to me; my editors handle LF line endings just 
fine on Windows; it was very jarring to get hundreds of warnings from git that 
all seemed unactionable.


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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-18 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 3c8255f30f7548cfb86858d980cc3e1524b3607f Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 222 -
 clang/test/Sema/attr-format-missing.c | 228 ++
 clang/test/Sema/attr-format-missing.cpp   | 189 +++
 9 files changed, 654 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7a6ace8bb895d..07a20b49955abb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 8273701e7b0963..417f2dbdc6a68a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 883db838ca0147..5edd830fb945fa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1051,6 +1051,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bc9c422ed4c477..8dba328f6f50e0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4574,6 +4574,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 229c9080d558ec..37fbe669364e3d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16037,6 +16037,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6759aae37afac1..a

[clang] [NFC] clang add DiagnosticsTestHelper decl (PR #112820)

2024-10-18 Thread Jinsong Ji via cfe-commits

https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112820

>From 53683a8543bb6a558a778dc1cc15adb3180df7e4 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Fri, 18 Oct 2024 05:23:19 +0200
Subject: [PATCH 1/4] [NFC] clang add DiagnosticsTestHelper decl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by 
GCC 11.

Fix warning

llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:19:6: error: ‘void 
clang::DiagnosticsTestHelper(clang::DiagnosticsEngine&)’ has not been declared 
within ‘clang’ [-Werror]
   19 | void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
  |  ^
In file included from 
/iusers/jinsongj/llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:9:
/iusers/jinsongj/llvm-project/clang/include/clang/Basic/Diagnostic.h:567:15: 
note: only here as a ‘friend’
  567 |   friend void DiagnosticsTestHelper(DiagnosticsEngine &);
---
 clang/include/clang/Basic/Diagnostic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 3b1efdb12824c7..3f6e85634c3cf5 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,6 +1024,8 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// @}
 };
 
+void DiagnosticsTestHelper(DiagnosticsEngine &);
+
 /// RAII class that determines when any errors have occurred
 /// between the time the instance was created and the time it was
 /// queried.

>From 677dab12a67b801dd0406e38f092f89b71045785 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Fri, 18 Oct 2024 14:54:56 +0200
Subject: [PATCH 2/4] Add comments

---
 clang/include/clang/Basic/Diagnostic.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 3f6e85634c3cf5..dc7e49beb9a0f4 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,6 +1024,7 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// @}
 };
 
+/// Declare the friend function for testing to avoid GCC warning.
 void DiagnosticsTestHelper(DiagnosticsEngine &);
 
 /// RAII class that determines when any errors have occurred

>From 1154286563d33ffedc4981a1e7c9f72518a1cf6f Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Fri, 18 Oct 2024 08:37:38 -0700
Subject: [PATCH 3/4] Revert "Add comments"

This reverts commit 677dab12a67b801dd0406e38f092f89b71045785.
---
 clang/include/clang/Basic/Diagnostic.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index dc7e49beb9a0f4..3f6e85634c3cf5 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,7 +1024,6 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// @}
 };
 
-/// Declare the friend function for testing to avoid GCC warning.
 void DiagnosticsTestHelper(DiagnosticsEngine &);
 
 /// RAII class that determines when any errors have occurred

>From a40fb059ae8bb81806cc399361c48ea5caca0336 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Fri, 18 Oct 2024 08:37:11 -0700
Subject: [PATCH 4/4] Add the decl in unittest file only

---
 clang/include/clang/Basic/Diagnostic.h   | 2 --
 clang/unittests/Basic/DiagnosticTest.cpp | 4 
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 3f6e85634c3cf5..3b1efdb12824c7 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,8 +1024,6 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// @}
 };
 
-void DiagnosticsTestHelper(DiagnosticsEngine &);
-
 /// RAII class that determines when any errors have occurred
 /// between the time the instance was created and the time it was
 /// queried.
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index 691d74f697f278..54b32bc2bb7833 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -16,6 +16,10 @@
 using namespace llvm;
 using namespace clang;
 
+namespace clang {
+   void DiagnosticsTestHelper(DiagnosticsEngine &diag);
+}
+
 void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
   EXPECT_FALSE(diag.DiagStates.empty());
   EXPECT_TRUE(diag.DiagStatesByLoc.empty());

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


[clang] [LinkerWrapper] Extract device archives if symbol is used on the host (PR #111921)

2024-10-18 Thread Joseph Huber via cfe-commits

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


[clang] [NFC] clang add DiagnosticsTestHelper decl (PR #112820)

2024-10-18 Thread Jinsong Ji via cfe-commits


@@ -1024,6 +1024,9 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// @}
 };
 
+/// Declare the friend function for testing to avoid GCC warning.

jsji wrote:

Sure.

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


[clang] [NFC] Fix c++ style comment in c file (PR #112814)

2024-10-18 Thread Abhina Sree via cfe-commits


@@ -8,7 +8,6 @@
 #include "clang-c/Documentation.h"
 #include "clang-c/Index.h"
 #include "clang/Config/config.h"
-#include "llvm/Support/AutoConvert.h"

abhina-sree wrote:

Yes, I think that would be a better solution, I will try to get to that when I 
have time, thanks!

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


[clang] [NFC] add DiagnosticsTestHelper decl (PR #112820)

2024-10-18 Thread Jinsong Ji via cfe-commits

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


[clang] [LinkerWrapper] Extract device archives if symbol is used on the host (PR #111921)

2024-10-18 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Accidentally deleted this branch and forgot to reopen this. Tests will fail 
until https://github.com/llvm/llvm-project/pull/111890 lands.

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


[clang] [NFC] add DiagnosticsTestHelper decl (PR #112820)

2024-10-18 Thread Jinsong Ji via cfe-commits

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


[clang] [Clang] Fix an assertion in expression recovery (PR #112888)

2024-10-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-hip-vega20` running 
on `hip-vega20-0` while building `clang` at step 3 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/123/builds/7768


Here is the relevant piece of the build log for the reference

```
Step 3 (annotate) failure: 
'../llvm-zorg/zorg/buildbot/builders/annotated/hip-build.sh --jobs=' (failure)
...
[38/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 
-DNDEBUG  
External/HIP/CMakeFiles/InOneWeekend-hip-6.0.2.dir/workload/ray-tracing/InOneWeekend/main.cc.o
 -o External/HIP/InOneWeekend-hip-6.0.2  
--rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt 
-unwindlib=libgcc -frtlib-add-rpath && cd 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && 
/usr/local/bin/cmake -E create_symlink 
/buildbot/llvm-test-suite/External/HIP/InOneWeekend.reference_output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/InOneWeekend.reference_output-hip-6.0.2
[39/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 
-DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 
--offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 
--offload-arch=gfx1100 -xhip -mfma -MD -MT 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -MF 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d
 -o 
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -c 
/buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
[40/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 
-DNDEBUG  
External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o
 -o External/HIP/TheNextWeek-hip-6.0.2  
--rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt 
-unwindlib=libgcc -frtlib-add-rpath && cd 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && 
/usr/local/bin/cmake -E create_symlink 
/buildbot/llvm-test-suite/External/HIP/TheNextWeek.reference_output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/TheNextWeek.reference_output-hip-6.0.2
+ build_step 'Testing HIP test-suite'
+ echo '@@@BUILD_STEP Testing HIP test-suite@@@'
@@@BUILD_STEP Testing HIP test-suite@@@
+ ninja -v check-hip-simple
[0/1] cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP 
&& /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/llvm-lit -sv 
empty-hip-6.0.2.test with-fopenmp-hip-6.0.2.test saxpy-hip-6.0.2.test 
memmove-hip-6.0.2.test InOneWeekend-hip-6.0.2.test TheNextWeek-hip-6.0.2.test 
blender.test
-- Testing: 7 tests, 7 workers --
Testing:  0.. 10.. 20.. 30.. 40
FAIL: test-suite :: External/HIP/InOneWeekend-hip-6.0.2.test (4 of 7)
 TEST 'test-suite :: 
External/HIP/InOneWeekend-hip-6.0.2.test' FAILED 

/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/timeit-target 
--timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 
--limit-rss-size 838860800 --append-exitstatus --redirect-output 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out
 --redirect-input /dev/null --summary 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.time
 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/InOneWeekend-hip-6.0.2
cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP ; 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out
 InOneWeekend.reference_output-hip-6.0.2

+ cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP
+ /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target 
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out
 InOneWeekend.reference_output-hip-6.0.2
/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target: 
Comparison failed, textual difference between 'M' and 'i'

Input 1:
Memory access fault by GPU node-1 (Agent handle: 0x55882e50fac0) on address 
(nil). Reason: Page not present or supervisor privilege.
exit 134

Input 2:
image width = 1200 height = 675
block size = (16, 16) grid size = (75, 43)
Start rendering by GPU.
Done.
gpu.ppm and ref.ppm are the same.
exit 0


/usr/bin/strip: /bin/bash.stripped: Bad file descriptor
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Failed Tests (1):
  test-suite :: External/HIP/InOneWeekend-hip-6.0.2.test


Testing Time: 385.93s

Total Discovered Tests: 7
  Passed: 6 (85.71%)
  Fa

[clang] [analyzer] Improve solver (PR #112583)

2024-10-18 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/112583

>From dfb86a3ddad88a9a97fff054af1bf86d746ee49d Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 16 Oct 2024 15:52:31 +0200
Subject: [PATCH] [analyzer][Solver] Improve getSymVal and friends (1/2)

Instead of just doing a lookup in the existing constraints,
let's use `getRange()` for dissambling SymSymExprs and inferring from
the constraint system what end range set we can simplify.

This means that `getSymVal` gets more expensive while getting smarter.
I don't expect it to be an issue as this API is only rarely used, and
`getRange` is used a lot more often - yet without any observable hit on
performance.

This patch also removes dead declarations of EQClass overloads.
---
 .../Checkers/BitwiseShiftChecker.cpp  |  3 +-
 .../Core/RangeConstraintManager.cpp   | 21 +-
 clang/test/Analysis/infeasible-sink.c | 29 +++
 3 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
index 339927c165fe00..17f1214195b3ee 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
@@ -177,7 +177,8 @@ BugReportPtr BitwiseShiftValidator::checkOvershift() {
 RightOpStr = formatv(" '{0}'", ConcreteRight->getValue());
   else {
 SValBuilder &SVB = Ctx.getSValBuilder();
-if (const llvm::APSInt *MinRight = SVB.getMinValue(FoldedState, Right)) {
+if (const llvm::APSInt *MinRight = SVB.getMinValue(FoldedState, Right);
+MinRight && *MinRight >= LHSBitWidth) {
   LowerBoundStr = formatv(" >= {0},", MinRight->getExtValue());
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 70d5a609681790..ecf7974c838650 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1939,11 +1939,8 @@ class RangeConstraintManager : public 
RangedConstraintManager {
   RangeSet::Factory F;
 
   RangeSet getRange(ProgramStateRef State, SymbolRef Sym);
-  RangeSet getRange(ProgramStateRef State, EquivalenceClass Class);
   ProgramStateRef setRange(ProgramStateRef State, SymbolRef Sym,
RangeSet Range);
-  ProgramStateRef setRange(ProgramStateRef State, EquivalenceClass Class,
-   RangeSet Range);
 
   RangeSet getSymLTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
@@ -2866,24 +2863,22 @@ ConditionTruthVal 
RangeConstraintManager::checkNull(ProgramStateRef State,
 
 const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
   SymbolRef Sym) const {
-  const RangeSet *T = getConstraint(St, Sym);
-  return T ? T->getConcreteValue() : nullptr;
+  auto &MutableSelf = const_cast(*this);
+  return MutableSelf.getRange(St, Sym).getConcreteValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  const RangeSet *T = getConstraint(St, Sym);
-  if (!T || T->isEmpty())
-return nullptr;
-  return &T->getMinValue();
+  auto &MutableSelf = const_cast(*this);
+  RangeSet Range = MutableSelf.getRange(St, Sym);
+  return Range.isEmpty() ? nullptr : &Range.getMinValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  const RangeSet *T = getConstraint(St, Sym);
-  if (!T || T->isEmpty())
-return nullptr;
-  return &T->getMaxValue();
+  auto &MutableSelf = const_cast(*this);
+  RangeSet Range = MutableSelf.getRange(St, Sym);
+  return Range.isEmpty() ? nullptr : &Range.getMaxValue();
 }
 
 
//===--===//
diff --git a/clang/test/Analysis/infeasible-sink.c 
b/clang/test/Analysis/infeasible-sink.c
index 9cb66fcac0b6be..a88ca42f27e441 100644
--- a/clang/test/Analysis/infeasible-sink.c
+++ b/clang/test/Analysis/infeasible-sink.c
@@ -38,7 +38,7 @@ void test1(int x) {
 }
 
 int a, b, c, d, e;
-void test2() {
+void test2(void) {
 
   if (a == 0)
 return;
@@ -50,31 +50,10 @@ void test2() {
   b = d;
   a -= d;
 
-  if (a != 0)
-return;
-
-  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
 
-  /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
-  // The parent state is already infeasible, look at this contradiction:
-  clang_analyzer_eval(b > 0);  // expected-wrning{{FALSE}}
-  clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
-  // Crashes with expensive

[clang] [analyzer] Improve solver (PR #112583)

2024-10-18 Thread Balazs Benics via cfe-commits


@@ -50,31 +50,10 @@ void test2() {
   b = d;
   a -= d;
 
-  if (a != 0)
-return;
-
-  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
 
-  /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
-  // The parent state is already infeasible, look at this contradiction:
-  clang_analyzer_eval(b > 0);  // expected-wrning{{FALSE}}
-  clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
-  // Crashes with expensive checks.
-  if (b > 0) {
-clang_analyzer_warnIfReached(); // no-warning, OK
+  if (a != 0)
 return;
-  }
-  // Should not be reachable.
-  clang_analyzer_warnIfReached(); // expected-wrning{{REACHABLE}}
-  */
 
-  // The parent state is already infeasible, but we realize that only if b is
-  // constrained.
-  clang_analyzer_eval(b > 0);  // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(b <= 0); // expected-warning{{UNKNOWN}}
-  if (b > 0) {
-clang_analyzer_warnIfReached(); // no-warning
-return;
-  }
-  clang_analyzer_warnIfReached(); // no-warning
+  clang_analyzer_warnIfReached(); // no-warning: Even the parent state is 
unreachable.

steakhal wrote:

Fixed.

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


[clang] [Clang] Don't assert on substituted-but-yet-expanded packs for nested lambdas (PR #112896)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Nested lambdas could refer to outer packs that would be expanded by a larger 
CXXFoldExpr, in which case that reference could happen to be a full expression 
containing intermediate types/expressions, e.g. 
SubstTemplateTypeParmPackType/FunctionParmPackExpr. They are designated as 
"UnexpandedPack" dependencies but don't introduce new packs anyway.

Fixes #112352 

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+34-15) 
- (modified) clang/test/SemaCXX/lambda-pack-expansion.cpp (+40) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b430b2b0ee3187..d071c480f36dc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,7 +486,7 @@ Bug Fixes to C++ Support
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
 - Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
-- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361)
+- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361), (#GH112352)
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. (#GH63819), (#GH107560)
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 19bd4547665835..151b328872bd75 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -41,7 +41,7 @@ namespace {
 unsigned DepthLimit = (unsigned)-1;
 
 #ifndef NDEBUG
-bool ContainsFunctionParmPackExpr = false;
+bool ContainsIntermediatePacks = false;
 #endif
 
 void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
@@ -114,6 +114,11 @@ namespace {
   addUnexpanded(TTP);
   }
 
+#ifndef NDEBUG
+  ContainsIntermediatePacks |=
+  (bool)Template.getAsSubstTemplateTemplateParmPack();
+#endif
+
   return inherited::TraverseTemplateName(Template);
 }
 
@@ -297,13 +302,28 @@ namespace {
 
 #ifndef NDEBUG
 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *) {
-  ContainsFunctionParmPackExpr = true;
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool TraverseSubstNonTypeTemplateParmPackExpr(
+SubstNonTypeTemplateParmPackExpr *) {
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *) {
+  ContainsIntermediatePacks = true;
   return true;
 }
 
-bool containsFunctionParmPackExpr() const {
-  return ContainsFunctionParmPackExpr;
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc) {
+  ContainsIntermediatePacks = true;
+  return true;
 }
+
+bool containsIntermediatePacks() const { return ContainsIntermediatePacks; 
}
 #endif
   };
 }
@@ -439,21 +459,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
-  // FunctionParmPackExprs are special:
-  //
-  // 1) they're used to model DeclRefExprs to packs that have been expanded but
-  // had that expansion held off in the process of transformation.
-  //
-  // 2) they always have the unexpanded dependencies but don't introduce new
-  // unexpanded packs.
-  //
-  // We might encounter a FunctionParmPackExpr being a full expression, which a
-  // larger CXXFoldExpr would expand.
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
   Visitor.TraverseStmt(E);
-  assert((!Unexpanded.empty() || Visitor.containsFunctionParmPackExpr()) &&
+#ifndef NDEBUG
+  // The expression might contain a type/subexpression that has been 
substituted
+  // but has the expansion held off, e.g. a FunctionParmPackExpr which a larger
+  // CXXFoldExpr would expand. It's only possible when expanding a lambda as a
+  // pattern of a fold expression, so don't fire on an empty result in that
+  // case.
+  bool LambdaReferencingOuterPacks =
+  getEnclosingLambdaOrBlock() && Visitor.containsIntermediatePacks();
+  assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
  "Unable to find unexpanded parameter packs");
+#endif
   return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
 }
 
diff --git a/clang/test/SemaCXX/lambda-pack-expansion.cpp 
b/clang/test/SemaCXX/lambda-pack-expansion.cpp
index 0e60ecd8756600..7f7dd3bb095d57 100644
-

[clang] [Clang] Don't assert on substituted-but-yet-expanded packs for nested lambdas (PR #112896)

2024-10-18 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] Fix an assertion in expression recovery (PR #112888)

2024-10-18 Thread Erich Keane via cfe-commits

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


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


[clang] [Clang] Don't assert on substituted-but-yet-expanded packs for nested lambdas (PR #112896)

2024-10-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/112896

Nested lambdas could refer to outer packs that would be expanded by a larger 
CXXFoldExpr, in which case that reference could happen to be a full expression 
containing intermediate types/expressions, e.g. 
SubstTemplateTypeParmPackType/FunctionParmPackExpr. They are designated as 
"UnexpandedPack" dependencies but don't introduce new packs anyway.

Fixes #112352 

>From 6caf16d6ce8eb939c91ed87493c2ccab82d38411 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 18 Oct 2024 20:22:08 +0800
Subject: [PATCH] [Clang] Don't assert on substituted-but-yet-expanded packs
 for nested lambdas

---
 clang/docs/ReleaseNotes.rst  |  2 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp  | 49 ++--
 clang/test/SemaCXX/lambda-pack-expansion.cpp | 40 
 3 files changed, 75 insertions(+), 16 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b430b2b0ee3187..d071c480f36dc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,7 +486,7 @@ Bug Fixes to C++ Support
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
 - Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
-- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361)
+- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361), (#GH112352)
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. (#GH63819), (#GH107560)
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 19bd4547665835..151b328872bd75 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -41,7 +41,7 @@ namespace {
 unsigned DepthLimit = (unsigned)-1;
 
 #ifndef NDEBUG
-bool ContainsFunctionParmPackExpr = false;
+bool ContainsIntermediatePacks = false;
 #endif
 
 void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
@@ -114,6 +114,11 @@ namespace {
   addUnexpanded(TTP);
   }
 
+#ifndef NDEBUG
+  ContainsIntermediatePacks |=
+  (bool)Template.getAsSubstTemplateTemplateParmPack();
+#endif
+
   return inherited::TraverseTemplateName(Template);
 }
 
@@ -297,13 +302,28 @@ namespace {
 
 #ifndef NDEBUG
 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *) {
-  ContainsFunctionParmPackExpr = true;
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool TraverseSubstNonTypeTemplateParmPackExpr(
+SubstNonTypeTemplateParmPackExpr *) {
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *) {
+  ContainsIntermediatePacks = true;
   return true;
 }
 
-bool containsFunctionParmPackExpr() const {
-  return ContainsFunctionParmPackExpr;
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc) {
+  ContainsIntermediatePacks = true;
+  return true;
 }
+
+bool containsIntermediatePacks() const { return ContainsIntermediatePacks; 
}
 #endif
   };
 }
@@ -439,21 +459,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
-  // FunctionParmPackExprs are special:
-  //
-  // 1) they're used to model DeclRefExprs to packs that have been expanded but
-  // had that expansion held off in the process of transformation.
-  //
-  // 2) they always have the unexpanded dependencies but don't introduce new
-  // unexpanded packs.
-  //
-  // We might encounter a FunctionParmPackExpr being a full expression, which a
-  // larger CXXFoldExpr would expand.
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
   Visitor.TraverseStmt(E);
-  assert((!Unexpanded.empty() || Visitor.containsFunctionParmPackExpr()) &&
+#ifndef NDEBUG
+  // The expression might contain a type/subexpression that has been 
substituted
+  // but has the expansion held off, e.g. a FunctionParmPackExpr which a larger
+  // CXXFoldExpr would expand. It's only possible when expanding a lambda as a
+  // pattern of a fold expression, so don't fire on an empty result in that
+  // case.
+  bool LambdaReferencingOuterPacks =
+  getEnclosingLambdaOrBlock() && Visitor.containsIntermediatePacks();
+  assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
  "Unable to find unexpanded parameter packs");
+#endif
   return DiagnoseUnexpandedParameterPacks(E-

[clang] [flang] [lldb] [llvm] [mlir] Fix typo "instrinsic" (PR #112899)

2024-10-18 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thanks!

I blame my editor's dictionary 😂 

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


[clang] [Clang] Provide default value for -fprofile-sample-use, -fprofile-auto (PR #112750)

2024-10-18 Thread Mikołaj Piróg via cfe-commits

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


[clang] 6a623e8 - [NFC] add DiagnosticsTestHelper decl (#112820)

2024-10-18 Thread via cfe-commits

Author: Jinsong Ji
Date: 2024-10-18T12:53:59-04:00
New Revision: 6a623e8484fe713d7074acb7ceab520458bfa89c

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

LOG: [NFC] add DiagnosticsTestHelper decl (#112820)

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on.
Built by GCC 11.

Fix warning

llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:19:6: error: ‘void
clang::DiagnosticsTestHelper(clang::DiagnosticsEngine&)’ has not been
declared within ‘clang’ [-Werror]
   19 | void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
  |  ^
In file included from
llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:9:
llvm-project/clang/include/clang/Basic/Diagnostic.h:567:15: note: only
here as a ‘friend’
  567 |   friend void DiagnosticsTestHelper(DiagnosticsEngine &);

Added: 


Modified: 
clang/unittests/Basic/DiagnosticTest.cpp

Removed: 




diff  --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index 691d74f697f278..d8d23e3b670097 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -16,6 +16,11 @@
 using namespace llvm;
 using namespace clang;
 
+// Declare DiagnosticsTestHelper to avoid GCC warning
+namespace clang {
+void DiagnosticsTestHelper(DiagnosticsEngine &diag);
+}
+
 void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
   EXPECT_FALSE(diag.DiagStates.empty());
   EXPECT_TRUE(diag.DiagStatesByLoc.empty());



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


[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-18 Thread Eli Friedman via cfe-commits


@@ -353,6 +427,17 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 nullptr, true, Align);
   }
 
+  // In AAPCS named arguments of a Pure Scalable Type are passed expanded in
+  // registers, or indirectly if there are not enough registers.
+  if (Kind == AArch64ABIKind::AAPCS && !IsVariadic) {

efriedma-quic wrote:

I'm pretty sure "IsVariadic" is whether the function type is variadic, not 
whether the argument is named.

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


[clang] [llvm] [HLSL][SPIRV] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-18 Thread Finn Plummer via cfe-commits

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


[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-10-18 Thread Aaron Ballman via cfe-commits


@@ -13,246 +13,40 @@
 #include "IncrementalParser.h"
 
 #include "clang/AST/DeclContextInternals.h"
-#include "clang/CodeGen/BackendUtil.h"
-#include "clang/CodeGen/CodeGenAction.h"
-#include "clang/CodeGen/ModuleBuilder.h"
 #include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendAction.h"
-#include "clang/FrontendTool/Utils.h"
-#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Parse/Parser.h"
 #include "clang/Sema/Sema.h"
-#include "llvm/Option/ArgList.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/Timer.h"
 
 #include 
 
 namespace clang {
 
-class IncrementalASTConsumer final : public ASTConsumer {
-  Interpreter &Interp;
-  std::unique_ptr Consumer;
+// IncrementalParser::IncrementalParser() {}
 
-public:
-  IncrementalASTConsumer(Interpreter &InterpRef, std::unique_ptr 
C)
-  : Interp(InterpRef), Consumer(std::move(C)) {}
-
-  bool HandleTopLevelDecl(DeclGroupRef DGR) override final {
-if (DGR.isNull())
-  return true;
-if (!Consumer)
-  return true;
-
-for (Decl *D : DGR)
-  if (auto *TSD = llvm::dyn_cast(D);
-  TSD && TSD->isSemiMissing())
-TSD->setStmt(Interp.SynthesizeExpr(cast(TSD->getStmt(;
-
-return Consumer->HandleTopLevelDecl(DGR);
-  }
-  void HandleTranslationUnit(ASTContext &Ctx) override final {
-Consumer->HandleTranslationUnit(Ctx);
-  }
-  void HandleInlineFunctionDefinition(FunctionDecl *D) override final {
-Consumer->HandleInlineFunctionDefinition(D);
-  }
-  void HandleInterestingDecl(DeclGroupRef D) override final {
-Consumer->HandleInterestingDecl(D);
-  }
-  void HandleTagDeclDefinition(TagDecl *D) override final {
-Consumer->HandleTagDeclDefinition(D);
-  }
-  void HandleTagDeclRequiredDefinition(const TagDecl *D) override final {
-Consumer->HandleTagDeclRequiredDefinition(D);
-  }
-  void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override final {
-Consumer->HandleCXXImplicitFunctionInstantiation(D);
-  }
-  void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override final {
-Consumer->HandleTopLevelDeclInObjCContainer(D);
-  }
-  void HandleImplicitImportDecl(ImportDecl *D) override final {
-Consumer->HandleImplicitImportDecl(D);
-  }
-  void CompleteTentativeDefinition(VarDecl *D) override final {
-Consumer->CompleteTentativeDefinition(D);
-  }
-  void CompleteExternalDeclaration(DeclaratorDecl *D) override final {
-Consumer->CompleteExternalDeclaration(D);
-  }
-  void AssignInheritanceModel(CXXRecordDecl *RD) override final {
-Consumer->AssignInheritanceModel(RD);
-  }
-  void HandleCXXStaticMemberVarInstantiation(VarDecl *D) override final {
-Consumer->HandleCXXStaticMemberVarInstantiation(D);
-  }
-  void HandleVTable(CXXRecordDecl *RD) override final {
-Consumer->HandleVTable(RD);
-  }
-  ASTMutationListener *GetASTMutationListener() override final {
-return Consumer->GetASTMutationListener();
-  }
-  ASTDeserializationListener *GetASTDeserializationListener() override final {
-return Consumer->GetASTDeserializationListener();
-  }
-  void PrintStats() override final { Consumer->PrintStats(); }
-  bool shouldSkipFunctionBody(Decl *D) override final {
-return Consumer->shouldSkipFunctionBody(D);
-  }
-  static bool classof(const clang::ASTConsumer *) { return true; }
-};
-
-/// A custom action enabling the incremental processing functionality.
-///
-/// The usual \p FrontendAction expects one call to ExecuteAction and once it
-/// sees a call to \p EndSourceFile it deletes some of the important objects
-/// such as \p Preprocessor and \p Sema assuming no further input will come.
-///
-/// \p IncrementalAction ensures it keep its underlying action's objects alive
-/// as long as the \p IncrementalParser needs them.
-///
-class IncrementalAction : public WrapperFrontendAction {
-private:
-  bool IsTerminating = false;
-
-public:
-  IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx,
-llvm::Error &Err)
-  : WrapperFrontendAction([&]() {
-  llvm::ErrorAsOutParameter EAO(&Err);
-  std::unique_ptr Act;
-  switch (CI.getFrontendOpts().ProgramAction) {
-  default:
-Err = llvm::createStringError(
-std::errc::state_not_recoverable,
-"Driver initialization failed. "
-"Incremental mode for action %d is not supported",
-CI.getFrontendOpts().ProgramAction);
-return Act;
-  case frontend::ASTDump:
-[[fallthrough]];
-  case frontend::ASTPrint:
-[[fallthrough]];
-  case frontend::ParseSyntaxOnly:
-Act = CreateFrontendAction(CI);
-break;
-  case frontend::PluginAction:
-[[fallthrough]];
-  case frontend::EmitAssembly:
-[[fallthro

[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-10-18 Thread Vassil Vassilev via cfe-commits


@@ -13,246 +13,40 @@
 #include "IncrementalParser.h"
 
 #include "clang/AST/DeclContextInternals.h"
-#include "clang/CodeGen/BackendUtil.h"
-#include "clang/CodeGen/CodeGenAction.h"
-#include "clang/CodeGen/ModuleBuilder.h"
 #include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendAction.h"
-#include "clang/FrontendTool/Utils.h"
-#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Parse/Parser.h"
 #include "clang/Sema/Sema.h"
-#include "llvm/Option/ArgList.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/Timer.h"
 
 #include 
 
 namespace clang {
 
-class IncrementalASTConsumer final : public ASTConsumer {
-  Interpreter &Interp;
-  std::unique_ptr Consumer;
+// IncrementalParser::IncrementalParser() {}
 
-public:
-  IncrementalASTConsumer(Interpreter &InterpRef, std::unique_ptr 
C)
-  : Interp(InterpRef), Consumer(std::move(C)) {}
-
-  bool HandleTopLevelDecl(DeclGroupRef DGR) override final {
-if (DGR.isNull())
-  return true;
-if (!Consumer)
-  return true;
-
-for (Decl *D : DGR)
-  if (auto *TSD = llvm::dyn_cast(D);
-  TSD && TSD->isSemiMissing())
-TSD->setStmt(Interp.SynthesizeExpr(cast(TSD->getStmt(;
-
-return Consumer->HandleTopLevelDecl(DGR);
-  }
-  void HandleTranslationUnit(ASTContext &Ctx) override final {
-Consumer->HandleTranslationUnit(Ctx);
-  }
-  void HandleInlineFunctionDefinition(FunctionDecl *D) override final {
-Consumer->HandleInlineFunctionDefinition(D);
-  }
-  void HandleInterestingDecl(DeclGroupRef D) override final {
-Consumer->HandleInterestingDecl(D);
-  }
-  void HandleTagDeclDefinition(TagDecl *D) override final {
-Consumer->HandleTagDeclDefinition(D);
-  }
-  void HandleTagDeclRequiredDefinition(const TagDecl *D) override final {
-Consumer->HandleTagDeclRequiredDefinition(D);
-  }
-  void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override final {
-Consumer->HandleCXXImplicitFunctionInstantiation(D);
-  }
-  void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override final {
-Consumer->HandleTopLevelDeclInObjCContainer(D);
-  }
-  void HandleImplicitImportDecl(ImportDecl *D) override final {
-Consumer->HandleImplicitImportDecl(D);
-  }
-  void CompleteTentativeDefinition(VarDecl *D) override final {
-Consumer->CompleteTentativeDefinition(D);
-  }
-  void CompleteExternalDeclaration(DeclaratorDecl *D) override final {
-Consumer->CompleteExternalDeclaration(D);
-  }
-  void AssignInheritanceModel(CXXRecordDecl *RD) override final {
-Consumer->AssignInheritanceModel(RD);
-  }
-  void HandleCXXStaticMemberVarInstantiation(VarDecl *D) override final {
-Consumer->HandleCXXStaticMemberVarInstantiation(D);
-  }
-  void HandleVTable(CXXRecordDecl *RD) override final {
-Consumer->HandleVTable(RD);
-  }
-  ASTMutationListener *GetASTMutationListener() override final {
-return Consumer->GetASTMutationListener();
-  }
-  ASTDeserializationListener *GetASTDeserializationListener() override final {
-return Consumer->GetASTDeserializationListener();
-  }
-  void PrintStats() override final { Consumer->PrintStats(); }
-  bool shouldSkipFunctionBody(Decl *D) override final {
-return Consumer->shouldSkipFunctionBody(D);
-  }
-  static bool classof(const clang::ASTConsumer *) { return true; }
-};
-
-/// A custom action enabling the incremental processing functionality.
-///
-/// The usual \p FrontendAction expects one call to ExecuteAction and once it
-/// sees a call to \p EndSourceFile it deletes some of the important objects
-/// such as \p Preprocessor and \p Sema assuming no further input will come.
-///
-/// \p IncrementalAction ensures it keep its underlying action's objects alive
-/// as long as the \p IncrementalParser needs them.
-///
-class IncrementalAction : public WrapperFrontendAction {
-private:
-  bool IsTerminating = false;
-
-public:
-  IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx,
-llvm::Error &Err)
-  : WrapperFrontendAction([&]() {
-  llvm::ErrorAsOutParameter EAO(&Err);
-  std::unique_ptr Act;
-  switch (CI.getFrontendOpts().ProgramAction) {
-  default:
-Err = llvm::createStringError(
-std::errc::state_not_recoverable,
-"Driver initialization failed. "
-"Incremental mode for action %d is not supported",
-CI.getFrontendOpts().ProgramAction);
-return Act;
-  case frontend::ASTDump:
-[[fallthrough]];
-  case frontend::ASTPrint:
-[[fallthrough]];
-  case frontend::ParseSyntaxOnly:
-Act = CreateFrontendAction(CI);
-break;
-  case frontend::PluginAction:
-[[fallthrough]];
-  case frontend::EmitAssembly:
-[[fallthro

[clang] Remove type-punning in LazyOffsetPtr. (PR #112806)

2024-10-18 Thread Richard Smith via cfe-commits

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


[clang] Remove type-punning in LazyOffsetPtr. (PR #112806)

2024-10-18 Thread Richard Smith via cfe-commits

zygoloid wrote:

Closing in favour of #112927.

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


[clang] [Clang][Sema] Fix exception specification comparison for functions with different template depths (PR #111561)

2024-10-18 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/111561

>From 8fe948147c63311600994a0d846a3ad0bce95f2a Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 8 Oct 2024 12:54:26 -0400
Subject: [PATCH 1/4] [Clang][Sema] Fix exception specification comparison for
 functions with different template depths

---
 clang/include/clang/Sema/Sema.h |   5 ++
 clang/lib/Sema/SemaExceptionSpec.cpp| 105 +++-
 clang/test/CXX/basic/basic.link/p11.cpp |  37 +
 3 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CXX/basic/basic.link/p11.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bc9c422ed4c477..b295db62bf016d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5026,6 +5026,11 @@ class Sema final : public SemaBase {
   /// special member function.
   void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD);
 
+  bool AreExceptionSpecsEqual(const NamedDecl *Old,
+  const Expr *OldExceptionSpec,
+  const NamedDecl *New,
+  const Expr *NewExceptionSpec);
+
   /// Check the given exception-specification and update the
   /// exception specification information with the results.
   void checkExceptionSpecification(bool IsTopLevel,
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index dbddd6c370aa07..c74686073df228 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -10,7 +10,6 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTMutationListener.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Expr.h"
@@ -19,6 +18,9 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/EnterExpressionEvaluationContext.h"
+#include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include 
@@ -314,6 +316,22 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, 
FunctionDecl *New) {
 return false;
   }
 
+  if (Old->getExceptionSpecType() == EST_DependentNoexcept &&
+  New->getExceptionSpecType() == EST_DependentNoexcept) {
+const auto *OldType = Old->getType()->getAs();
+const auto *NewType = New->getType()->getAs();
+OldType = ResolveExceptionSpec(New->getLocation(), OldType);
+if (!OldType)
+  return false;
+NewType = ResolveExceptionSpec(New->getLocation(), NewType);
+if (!NewType)
+  return false;
+
+if (AreExceptionSpecsEqual(Old, OldType->getNoexceptExpr(), New,
+   NewType->getNoexceptExpr()))
+  return false;
+  }
+
   // Check the types as written: they must match before any exception
   // specification adjustment is applied.
   if (!CheckEquivalentExceptionSpecImpl(
@@ -501,6 +519,89 @@ bool Sema::CheckEquivalentExceptionSpec(
   return Result;
 }
 
+static const Expr *SubstituteExceptionSpecWithoutEvaluation(
+Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
+const Expr *ExceptionSpec) {
+  MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
+  DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(),
+  /*Final=*/false, /*Innermost=*/std::nullopt,
+  /*RelativeToPrimary=*/true, /*ForConstraintInstantiation=*/true);
+
+  if (!MLTAL.getNumSubstitutedLevels())
+return ExceptionSpec;
+
+  Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+
+  Sema::InstantiatingTemplate Inst(
+  S, DeclInfo.getLocation(),
+  const_cast(DeclInfo.getDecl()->getAsFunction()),
+  Sema::InstantiatingTemplate::ExceptionSpecification());
+  if (Inst.isInvalid())
+return nullptr;
+
+  // Set up a dummy 'instantiation' scope in the case of reference to function
+  // parameters that the surrounding function hasn't been instantiated yet. 
Note
+  // this may happen while we're comparing two templates' constraint
+  // equivalence.
+  LocalInstantiationScope ScopeForParameters(S);
+  if (auto *FD = DeclInfo.getDecl()->getAsFunction())
+for (auto *PVD : FD->parameters())
+  ScopeForParameters.InstantiatedLocal(PVD, PVD);
+
+  std::optional ThisScope;
+
+  // See TreeTransform::RebuildTemplateSpecializationType. A context scope is
+  // essential for having an injected class as the canonical type for a 
template
+  // specialization type at the rebuilding stage. This guarantees that, for
+  // out-of-line definitions, injected class name types and their equivalent
+  // template specializations can be profiled to the same value, which makes it
+  // possible that e.g. constraints involving C> and C are
+  // perceived identical.
+  std::optional ContextScope

[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-18 Thread Momchil Velikov via cfe-commits


@@ -533,11 +638,158 @@ bool 
AArch64ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate()
   return true;
 }
 
+// Check if a type is a Pure Scalable Type as defined by AAPCS64. Return the
+// number of data vectors and the number of predicate vectors in the types, 
into
+// `NVec` and `NPred`, respectively. Upon return `CoerceToSeq` contains an
+// expanded sequence of LLVM IR types, one element for each non-composite
+// member. For practical purposes, limit the length of `CoerceToSeq` to about
+// 12, the maximum size that could possibly fit in registers.
+bool AArch64ABIInfo::isPureScalableType(
+QualType Ty, unsigned &NVec, unsigned &NPred,
+SmallVectorImpl &CoerceToSeq) const {
+  if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
+uint64_t NElt = AT->getZExtSize();
+if (NElt == 0)
+  return false;
+
+unsigned NV = 0, NP = 0;
+SmallVector EltCoerceToSeq;
+if (!isPureScalableType(AT->getElementType(), NV, NP, EltCoerceToSeq))
+  return false;
+
+for (uint64_t I = 0; CoerceToSeq.size() < 12 && I < NElt; ++I)
+  llvm::copy(EltCoerceToSeq, std::back_inserter(CoerceToSeq));
+
+NVec += NElt * NV;
+NPred += NElt * NP;
+return true;
+  }
+
+  if (const RecordType *RT = Ty->getAs()) {
+// If the record cannot be passed in registers, then it's not a PST.
+if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
+RAA != CGCXXABI::RAA_Default)
+  return false;
+
+// Pure scalable types are never unions and never contain unions.
+const RecordDecl *RD = RT->getDecl();
+if (RD->isUnion())
+  return false;
+
+// If this is a C++ record, check the bases bases.
+if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+  for (const auto &I : CXXRD->bases()) {
+if (isEmptyRecord(getContext(), I.getType(), true))

momchil-velikov wrote:

Fixed, added test.

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


[clang] [llvm] [RISCV][ISel] Ensure 'in X' Constraints prevent X0 (PR #112563)

2024-10-18 Thread Sam Elliott via cfe-commits

lenary wrote:

Yeah, I went back and looked at that issue, it's helpful to know that it was 
more than just the register allocator, that it was also copy propagation, which 
wasn't obvious from the comments. 

The failing tests are not related, but presumably caused by the rebase, but 
I'll still wait a bit to merge this.

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


[clang] [clang] Make LazyOffsetPtr more portable (PR #112927)

2024-10-18 Thread via cfe-commits

ernsteiswuerfel wrote:

I can confirm it fixes issue 
[#86460](https://github.com/llvm/llvm-project/issues/86460) for me just as 
awilfox original PR.

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


[libunwind] [libunwind][AIX] Call dlclose only when dlsym() fails (PR #112768)

2024-10-18 Thread Hubert Tong via cfe-commits

https://github.com/hubert-reinterpretcast approved this pull request.

LGTM; thanks!

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


[clang] [clang][AST] CXXRecords in anony namespace from diff TUs shouldn't be equivalent (PR #112534)

2024-10-18 Thread Ding Fei via cfe-commits

danix800 wrote:

> The fix looks acceptable, but a test is needed. The test code in the bug 
> report can be used somehow in at the AST merge LIT tests or in the 
> `ASTImporterTest`.

Thanks for reviewing. There's one more other similar crash (with this fix) and 
I'm still reducing the testcase. I need to dig a  bit more for the cause of the 
later crash.

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


[clang] [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (PR #112887)

2024-10-18 Thread Balazs Benics via cfe-commits

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


[clang] 67e8421 - [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (#112887)

2024-10-18 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-10-18T16:15:33+02:00
New Revision: 67e84213f59e1f9485d15421bdb7243d25cee07e

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

LOG: [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) 
(#112887)

This patch should not introduce much overhead as it only does one more
constraint map lookup, which is really quick.

Depends on #112583

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/test/Analysis/unary-sym-expr.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ecf7974c838650..f0311b7028f56d 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
 // calculate the effective range set by intersecting the range set
 // for A - B and the negated range set of B - A.
 getRangeForNegatedSymSym(SSE),
+// If commutative, we may have constaints for the commuted variant.
+getRangeCommutativeSymSym(SSE),
 // If Sym is a comparison expression (except <=>),
 // find any other comparisons with the same operands.
 // See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
 Sym->getType());
   }
 
+  std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) {
+auto Op = SSE->getOpcode();
+bool IsCommutative = llvm::is_contained(
+// ==, !=, |, &, +, *, ^
+{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
+if (!IsCommutative)
+  return std::nullopt;
+
+SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
+if (const RangeSet *Range = getConstraint(State, Commuted))
+  return *Range;
+return std::nullopt;
+  }
+
   // Returns ranges only for binary comparison operators (except <=>)
   // when left and right operands are symbolic values.
   // Finds any other comparisons with the same operands.

diff  --git a/clang/test/Analysis/unary-sym-expr.c 
b/clang/test/Analysis/unary-sym-expr.c
index 7c4774f3cca82f..92e11b295bee7c 100644
--- a/clang/test/Analysis/unary-sym-expr.c
+++ b/clang/test/Analysis/unary-sym-expr.c
@@ -29,12 +29,39 @@ int test(int x, int y) {
   return 42;
 }
 
-void test_svalbuilder_simplification(int x, int y) {
+void test_svalbuilder_simplification_add(int x, int y) {
   if (x + y != 3)
 return;
   clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
-  // FIXME Commutativity is not supported yet.
-  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_mul(int x, int y) {
+  if (x * y != 3)
+return;
+  clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_and(int x, int y) {
+  if ((x & y) != 3)
+return;
+  clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_or(int x, int y) {
+  if ((x | y) != 3)
+return;
+  clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_xor(int x, int y) {
+  if ((x ^ y) != 3)
+return;
+  clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
 }
 
 int test_fp(int flag) {



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


[clang] [clang-tools-extra] [flang] [lldb] [llvm] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-10-18 Thread via cfe-commits

ldrumm wrote:

There are a couple of things to unpack here

> a number of test input files need to be in LF form to work

Which ones? Either there's a bug in a parser somewhere, or I missed some test 
files. In either case I'd like to fix the issue. I watched the buildbots quite 
closely last night and only noticed failures in ARM frame lowering - which 
isn't this, I think.

> Now after this change, due to the added .gitattributes which overrides the 
> core.autocrlf setting, these files get checked out with CRLF newlines (as the 
> native form for the platform).

It's my understanding that `text=auto` does not override `core.autocrlf`. As 
far as I can tell from the documentation it honours the user's configuration 
for `core.eol` in combination with  `core.autocrlf` - from `git config --help`:

>  core.eol
   Sets the line ending type to use in the working directory for files 
that are marked as text (either by having the text attribute set, or by having 
text=auto and
   Git auto-detecting the contents as text). Alternatives are lf, crlf 
and native, which uses the platform’s native line ending. The default value is 
native. See
   gitattributes(5) for more information on end-of-line conversion. 
Note that this value is ignored if core.autocrlf is set to true or input.

and

>  core.autocrlf
   Setting this variable to "true" is the same as setting the text 
attribute to "auto" on all files and core.eol to "crlf". Set to true if you 
want to have CRLF line
   endings in your working directory and the repository has LF line 
endings. This variable can be set to input, in which case no output conversion 
is performed.


> Can we revert this until we figure out these bits

Sure, but like I said, I'm happy to fix these broken cases. The old 
configuration was broken, but not in a controllable way, so I think it's 
reasonable to fix up the broken tests and move forward. Perhaps we also need 
clearer documentation?



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


[clang] [analyzer][Solver][NFC] Cleanup const-correctness inside range-based solver (PR #112891)

2024-10-18 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/112891

>From 6b1702b1ea58e5fa4566069345d277e081cd1165 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 18 Oct 2024 14:12:46 +0200
Subject: [PATCH] [analyzer][Solver][NFC] Cleanup const-correctness inside
 range-based solver

---
 .../Core/RangeConstraintManager.cpp   | 59 +--
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index f0311b7028f56d..c39fa81109c853 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1953,27 +1953,27 @@ class RangeConstraintManager : public 
RangedConstraintManager {
   const llvm::APSInt &To, const llvm::APSInt &Adjustment) override;
 
 private:
-  RangeSet::Factory F;
+  mutable RangeSet::Factory F;
 
-  RangeSet getRange(ProgramStateRef State, SymbolRef Sym);
+  RangeSet getRange(ProgramStateRef State, SymbolRef Sym) const;
   ProgramStateRef setRange(ProgramStateRef State, SymbolRef Sym,
RangeSet Range);
 
   RangeSet getSymLTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(llvm::function_ref RS,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
 };
 
 
//===--===//
@@ -2880,21 +2880,18 @@ ConditionTruthVal 
RangeConstraintManager::checkNull(ProgramStateRef State,
 
 const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
   SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  return MutableSelf.getRange(St, Sym).getConcreteValue();
+  return getRange(St, Sym).getConcreteValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMinValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMaxValue();
 }
 
@@ -3039,7 +3036,7 @@ 
RangeConstraintManager::removeDeadBindings(ProgramStateRef State,
 }
 
 RangeSet RangeConstraintManager::getRange(ProgramStateRef State,
-  SymbolRef Sym) {
+  SymbolRef Sym) const {
   return SymbolicRangeInferrer::inferRange(F, State, Sym);
 }
 
@@ -3094,10 +3091,10 @@ RangeConstraintManager::assumeSymEQ(ProgramStateRef St, 
SymbolRef Sym,
   return setRange(St, Sym, New);
 }
 
-RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
-   SymbolRef Sym,
-   const llvm::APSInt &Int,
-   const llvm::APSInt &Adjustment) 
{
+RangeSet
+RangeConstraintManager::getSymLTRange(ProgramStateRef St, SymbolRef Sym,
+  const llvm::APSInt &Int,
+  const llvm::APSInt &Adjustment) const {
   // Before we do any real work, see if the value can even show up.
   APSIntType AdjustmentType(Adjustment);
   switch (AdjustmentType.testInRange(Int, true)) {
@@ -3131,10 +3128,10 @@ RangeConstraintManager::assumeSymLT(ProgramStateRef St, 
SymbolRef Sym,
   return setRange(St, Sym, New);
 }
 
-RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
-

[clang] [analyzer][Solver][NFC] Cleanup const-correctness inside range-based solver (PR #112891)

2024-10-18 Thread Balazs Benics via cfe-commits

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


[clang] 1b49ee7 - [analyzer][Solver][NFC] Cleanup const-correctness inside range-based solver (#112891)

2024-10-18 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-10-18T16:16:29+02:00
New Revision: 1b49ee73fc3512551066cd3c6b969fad589c9d5e

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

LOG: [analyzer][Solver][NFC] Cleanup const-correctness inside range-based 
solver (#112891)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index f0311b7028f56d..c39fa81109c853 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1953,27 +1953,27 @@ class RangeConstraintManager : public 
RangedConstraintManager {
   const llvm::APSInt &To, const llvm::APSInt &Adjustment) override;
 
 private:
-  RangeSet::Factory F;
+  mutable RangeSet::Factory F;
 
-  RangeSet getRange(ProgramStateRef State, SymbolRef Sym);
+  RangeSet getRange(ProgramStateRef State, SymbolRef Sym) const;
   ProgramStateRef setRange(ProgramStateRef State, SymbolRef Sym,
RangeSet Range);
 
   RangeSet getSymLTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(llvm::function_ref RS,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
 };
 
 
//===--===//
@@ -2880,21 +2880,18 @@ ConditionTruthVal 
RangeConstraintManager::checkNull(ProgramStateRef State,
 
 const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
   SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  return MutableSelf.getRange(St, Sym).getConcreteValue();
+  return getRange(St, Sym).getConcreteValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMinValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMaxValue();
 }
 
@@ -3039,7 +3036,7 @@ 
RangeConstraintManager::removeDeadBindings(ProgramStateRef State,
 }
 
 RangeSet RangeConstraintManager::getRange(ProgramStateRef State,
-  SymbolRef Sym) {
+  SymbolRef Sym) const {
   return SymbolicRangeInferrer::inferRange(F, State, Sym);
 }
 
@@ -3094,10 +3091,10 @@ RangeConstraintManager::assumeSymEQ(ProgramStateRef St, 
SymbolRef Sym,
   return setRange(St, Sym, New);
 }
 
-RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
-   SymbolRef Sym,
-   const llvm::APSInt &Int,
-   const llvm::APSInt &Adjustment) 
{
+RangeSet
+RangeConstraintManager::getSymLTRange(ProgramStateRef St, SymbolRef Sym,
+  const llvm::APSInt &Int,
+  const llvm::APSInt &Adjustment) const {
   // Before we do any real work, see if the value can even show up.
   APSIntType AdjustmentType(Adjustment);
   switch (AdjustmentType.testInRange(Int, true)) {
@@ -3131,10 +3128,10 @@ RangeConstraintManager::assumeSymLT(ProgramStateRef St, 
SymbolRef Sym,
   return s

[clang] [clang][AST] CXXRecords in anony namespace from diff TUs shouldn't be equivalent (PR #112534)

2024-10-18 Thread Ding Fei via cfe-commits

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


[clang] [clang][Index][USR][NFC] Allow customizing langopts for USR generation (PR #109574)

2024-10-18 Thread Balazs Benics via cfe-commits

steakhal wrote:

Ping @AaronBallman 

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


[clang] [analyzer][Solver][NFC] Cleanup const-correctness inside range-based solver (PR #112891)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balazs Benics (steakhal)


Changes



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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+45-31) 
- (modified) clang/test/Analysis/unary-sym-expr.c (+30-3) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ecf7974c838650..c39fa81109c853 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
 // calculate the effective range set by intersecting the range set
 // for A - B and the negated range set of B - A.
 getRangeForNegatedSymSym(SSE),
+// If commutative, we may have constaints for the commuted variant.
+getRangeCommutativeSymSym(SSE),
 // If Sym is a comparison expression (except <=>),
 // find any other comparisons with the same operands.
 // See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
 Sym->getType());
   }
 
+  std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) {
+auto Op = SSE->getOpcode();
+bool IsCommutative = llvm::is_contained(
+// ==, !=, |, &, +, *, ^
+{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
+if (!IsCommutative)
+  return std::nullopt;
+
+SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
+if (const RangeSet *Range = getConstraint(State, Commuted))
+  return *Range;
+return std::nullopt;
+  }
+
   // Returns ranges only for binary comparison operators (except <=>)
   // when left and right operands are symbolic values.
   // Finds any other comparisons with the same operands.
@@ -1936,27 +1953,27 @@ class RangeConstraintManager : public 
RangedConstraintManager {
   const llvm::APSInt &To, const llvm::APSInt &Adjustment) override;
 
 private:
-  RangeSet::Factory F;
+  mutable RangeSet::Factory F;
 
-  RangeSet getRange(ProgramStateRef State, SymbolRef Sym);
+  RangeSet getRange(ProgramStateRef State, SymbolRef Sym) const;
   ProgramStateRef setRange(ProgramStateRef State, SymbolRef Sym,
RangeSet Range);
 
   RangeSet getSymLTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGTRange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymLERange(llvm::function_ref RS,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
   RangeSet getSymGERange(ProgramStateRef St, SymbolRef Sym,
  const llvm::APSInt &Int,
- const llvm::APSInt &Adjustment);
+ const llvm::APSInt &Adjustment) const;
 };
 
 
//===--===//
@@ -2863,21 +2880,18 @@ ConditionTruthVal 
RangeConstraintManager::checkNull(ProgramStateRef State,
 
 const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
   SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  return MutableSelf.getRange(St, Sym).getConcreteValue();
+  return getRange(St, Sym).getConcreteValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMinValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
  SymbolRef Sym) const {
-  auto &MutableSelf = const_cast(*this);
-  RangeSet Range = MutableSelf.getRange(St, Sym);
+  RangeSet Range = getRange(St, Sym);
   return Range.isEmpty() ? nullptr : &Range.getMaxValue();
 }
 
@@ -3022,7 +3036,7 @@ 
RangeConstraintManager::removeDeadBindings(ProgramStateRef State,
 }
 
 RangeSet RangeConstraintManager::getRange(ProgramStateRef State,
-

[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)

2024-10-18 Thread Oleksandr T. via cfe-commits


@@ -517,6 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when evaluating constant expressions in 
value-dependent initializers (#GH112140)

a-tarasyuk wrote:

@cor3ntin thanks for the review. I've added changed to release notes...

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


[clang] [llvm] [RISCV][ISel] Ensure 'in X' Constraints prevent X0 (PR #112563)

2024-10-18 Thread Sam Elliott via cfe-commits

https://github.com/lenary updated 
https://github.com/llvm/llvm-project/pull/112563

>From bbf0b885dc5912d4dc29abcec5fe7cee7cfd1758 Mon Sep 17 00:00:00 2001
From: Sam Elliott 
Date: Wed, 16 Oct 2024 05:04:45 -0700
Subject: [PATCH 1/2] [RISCV] Inline Assembly: RVC constraint and N modifier

This change implements support for the `cr` and `cf` register
constraints (which allocate a RVC GPR or RVC FPR respectively), and the
`N` modifier (which prints the raw encoding of a register rather than the
name).

The intention behind these additions is to make it easier to use inline
assembly when assembling raw instructions that are not supported by the
compiler, for instance when experimenting with new instructions or when
supporting proprietary extensions outside the toolchain.

These implement part of my proposal in riscv-non-isa/riscv-c-api-doc#92

As part of the implementation, I felt there was not enough coverage of
inline assembly and the "in X" floating-point extensions, so I have
added more regression tests around these configurations.
---
 clang/lib/Basic/Targets/RISCV.cpp |  10 ++
 clang/test/CodeGen/RISCV/riscv-inline-asm.c   |  40 -
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |   8 +
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  18 ++
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|  19 ++-
 .../RISCV/inline-asm-d-constraint-f.ll|  33 
 .../CodeGen/RISCV/inline-asm-d-modifier-N.ll  | 109 
 .../RISCV/inline-asm-f-constraint-f.ll|  28 +++-
 .../CodeGen/RISCV/inline-asm-f-modifier-N.ll  |  96 +++
 llvm/test/CodeGen/RISCV/inline-asm-invalid.ll |  20 +++
 .../RISCV/inline-asm-zdinx-constraint-r.ll|  92 ++
 .../RISCV/inline-asm-zfh-constraint-f.ll  |  41 +
 .../RISCV/inline-asm-zfh-modifier-N.ll| 157 +
 .../RISCV/inline-asm-zfinx-constraint-r.ll|  89 ++
 .../RISCV/inline-asm-zhinx-constraint-r.ll| 158 ++
 llvm/test/CodeGen/RISCV/inline-asm.ll |  66 
 .../CodeGen/RISCV/zdinx-asm-constraint.ll |  61 +++
 17 files changed, 1040 insertions(+), 5 deletions(-)
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-d-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-f-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zdinx-constraint-r.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zfh-modifier-N.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zfinx-constraint-r.ll
 create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-zhinx-constraint-r.ll

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 870f0f38bc3057..eaaba7642bd7b2 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -100,6 +100,14 @@ bool RISCVTargetInfo::validateAsmConstraint(
   case 'S': // A symbol or label reference with a constant offset
 Info.setAllowsRegister();
 return true;
+  case 'c':
+// A RVC register - GPR or FPR
+if (Name[1] == 'r' || Name[1] == 'f') {
+  Info.setAllowsRegister();
+  Name += 1;
+  return true;
+}
+return false;
   case 'v':
 // A vector register.
 if (Name[1] == 'r' || Name[1] == 'd' || Name[1] == 'm') {
@@ -114,6 +122,8 @@ bool RISCVTargetInfo::validateAsmConstraint(
 std::string RISCVTargetInfo::convertConstraint(const char *&Constraint) const {
   std::string R;
   switch (*Constraint) {
+  // c* and v* are two-letter constraints on RISC-V.
+  case 'c':
   case 'v':
 R = std::string("^") + std::string(Constraint, 2);
 Constraint += 1;
diff --git a/clang/test/CodeGen/RISCV/riscv-inline-asm.c 
b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
index fa0bf6aa6aa471..75b91d3c497c50 100644
--- a/clang/test/CodeGen/RISCV/riscv-inline-asm.c
+++ b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
@@ -3,7 +3,35 @@
 // RUN: %clang_cc1 -triple riscv64 -O2 -emit-llvm %s -o - \
 // RUN: | FileCheck %s
 
-// Test RISC-V specific inline assembly constraints.
+// Test RISC-V specific inline assembly constraints and modifiers.
+
+long test_r(long x) {
+// CHECK-LABEL: define{{.*}} {{i64|i32}} @test_r(
+// CHECK: call {{i64|i32}} asm sideeffect "", "=r,r"({{i64|i32}} %{{.*}})
+  long ret;
+  asm volatile ("" : "=r"(ret) : "r"(x));
+// CHECK: call {{i64|i32}} asm sideeffect "", "=r,r"({{i64|i32}} %{{.*}})
+  asm volatile ("" : "=r"(ret) : "r"(x));
+  return ret;
+}
+
+long test_cr(long x) {
+// CHECK-LABEL: define{{.*}} {{i64|i32}} @test_cr(
+// CHECK: call {{i64|i32}} asm sideeffect "", "=^cr,^cr"({{i64|i32}} %{{.*}})
+  long ret;
+  asm volatile ("" : "=cr"(ret) : "cr"(x));
+  return ret;
+}
+
+float cf;
+double cd;
+void test_cf(float f, double d) {
+// CHECK-LABEL: define{{.*}} void @test_cf(
+// CHECK: call float asm sideeffect "", "=^cf,^cf"(float %{{.*}})
+  asm volatile("" : "=cf"(cf) : "cf"(f));
+// CHECK: call double asm sideeffect "", "=^cf,^cf"(double %{{.*}})
+  asm volatile("" : "=cf"(cd) : 

[clang] [NFC] Fix c++ style comment in c file (PR #112814)

2024-10-18 Thread Abhina Sree via cfe-commits


@@ -8,7 +8,6 @@
 #include "clang-c/Documentation.h"
 #include "clang-c/Index.h"
 #include "clang/Config/config.h"
-#include "llvm/Support/AutoConvert.h"

abhina-sree wrote:

We need this header because we are using the function enablezOSAutoConversion 
below in this file

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


[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)

2024-10-18 Thread Patryk Wychowaniec via cfe-commits

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

Looks good to me as well!

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


[clang] [flang] [lldb] [llvm] [mlir] Fix typo "instrinsic" (PR #112899)

2024-10-18 Thread Shilei Tian via cfe-commits

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

Can't believe this many Lol

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


[clang] [NFC] Fix c++ style comment in c file (PR #112814)

2024-10-18 Thread Jinsong Ji via cfe-commits


@@ -8,7 +8,6 @@
 #include "clang-c/Documentation.h"
 #include "clang-c/Index.h"
 #include "clang/Config/config.h"
-#include "llvm/Support/AutoConvert.h"

jsji wrote:

This is a c++ header, if we really need it, then we need to update it to c. 
@abhina-sree Can you please help to do so? Thanks.

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


[clang] [flang] [lldb] [llvm] [mlir] Fix typo "instrinsic" (PR #112899)

2024-10-18 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/112899

None

>From 3a3b67f30cde766adaede4cc53bec340fbe5d99f Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 18 Oct 2024 13:53:51 +0100
Subject: [PATCH] Fix typo "instrinsic"

---
 clang/utils/TableGen/RISCVVEmitter.cpp   | 4 ++--
 flang/docs/OptionComparison.md   | 2 +-
 flang/include/flang/Runtime/magic-numbers.h  | 2 +-
 flang/lib/Evaluate/intrinsics.cpp| 2 +-
 flang/lib/Optimizer/Builder/Runtime/Numeric.cpp  | 6 +++---
 flang/lib/Optimizer/Builder/Runtime/Reduction.cpp| 2 +-
 lldb/CMakeLists.txt  | 2 +-
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td | 2 +-
 llvm/include/llvm/Transforms/Utils/SSAUpdater.h  | 2 +-
 llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp | 2 +-
 llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td  | 2 +-
 llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td  | 2 +-
 llvm/test/Bitcode/upgrade-aarch64-sve-intrinsics.ll  | 2 +-
 llvm/test/CodeGen/SystemZ/vec-reduce-add-01.ll   | 2 +-
 llvm/test/Transforms/JumpThreading/thread-debug-info.ll  | 2 +-
 llvm/test/Transforms/SROA/fake-use-sroa.ll   | 2 +-
 llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp| 2 +-
 mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp | 2 +-
 mlir/lib/Target/LLVMIR/ModuleImport.cpp  | 2 +-
 19 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 50f161fd38ce69..aecca0f5df8d93 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -169,7 +169,7 @@ static VectorTypeModifier getTupleVTM(unsigned NF) {
 
 static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
   // We need a special rule for segment load/store since the data width is not
-  // encoded in the instrinsic name itself.
+  // encoded in the intrinsic name itself.
   const StringRef IRName = RVVI->getIRName();
   constexpr unsigned RVV_VTA = 0x1;
   constexpr unsigned RVV_VMA = 0x2;
@@ -192,7 +192,7 @@ static unsigned getIndexedLoadStorePtrIdx(const 
RVVIntrinsic *RVVI) {
 static unsigned getSegInstLog2SEW(StringRef InstName) {
   // clang-format off
   // We need a special rule for indexed segment load/store since the data width
-  // is not encoded in the instrinsic name itself.
+  // is not encoded in the intrinsic name itself.
   if (InstName.starts_with("vloxseg") || InstName.starts_with("vluxseg") ||
   InstName.starts_with("vsoxseg") || InstName.starts_with("vsuxseg"))
 return (unsigned)-1;
diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index 9d6916ef62af2e..fb65498fa1f444 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -53,7 +53,7 @@ eN

fdec,
 
-fall-instrinsics
+fall-intrinsics

https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=297";>qxlf77,
 
diff --git a/flang/include/flang/Runtime/magic-numbers.h 
b/flang/include/flang/Runtime/magic-numbers.h
index bab0e9ae05299a..1d3c5dca0b4bfb 100644
--- a/flang/include/flang/Runtime/magic-numbers.h
+++ b/flang/include/flang/Runtime/magic-numbers.h
@@ -107,7 +107,7 @@ The denorm value is a nonstandard extension.
 
 #if 0
 ieee_round_type values
-The values are those of the llvm.get.rounding instrinsic, which is assumed by
+The values are those of the llvm.get.rounding intrinsic, which is assumed by
 ieee_arithmetic module rounding procedures.
 #endif
 #define _FORTRAN_RUNTIME_IEEE_TO_ZERO 0
diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index 4271faa0db12bf..aa44967817722e 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1690,7 +1690,7 @@ std::optional IntrinsicInterface::Match(
   // MAX and MIN (and others that map to them) allow their last argument to
   // be repeated indefinitely.  The actualForDummy vector is sized
   // and null-initialized to the non-repeated dummy argument count
-  // for other instrinsics.
+  // for other intrinsics.
   bool isMaxMin{dummyArgPatterns > 0 &&
   dummy[dummyArgPatterns - 1].optionality == Optionality::repeats};
   std::vector actualForDummy(
diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp 
b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
index c13064a284d127..d0092add0118f1 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
@@ -284,7 +284,7 @@ struct ForcedSpacing16 {
   }
 };
 
-/// Generate call to Exponent instrinsic runtime routine.
+/// Generate call to Exponent intrinsic runtime routine.
 mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder,
   mlir::Location loc, mlir::Type 
resultType,
   

[clang] [flang] [lldb] [llvm] [mlir] Fix typo "instrinsic" (PR #112899)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-systemz

Author: Jay Foad (jayfoad)


Changes



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


19 Files Affected:

- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+2-2) 
- (modified) flang/docs/OptionComparison.md (+1-1) 
- (modified) flang/include/flang/Runtime/magic-numbers.h (+1-1) 
- (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1) 
- (modified) flang/lib/Optimizer/Builder/Runtime/Numeric.cpp (+3-3) 
- (modified) flang/lib/Optimizer/Builder/Runtime/Reduction.cpp (+1-1) 
- (modified) lldb/CMakeLists.txt (+1-1) 
- (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+1-1) 
- (modified) llvm/include/llvm/Transforms/Utils/SSAUpdater.h (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td (+1-1) 
- (modified) llvm/test/Bitcode/upgrade-aarch64-sve-intrinsics.ll (+1-1) 
- (modified) llvm/test/CodeGen/SystemZ/vec-reduce-add-01.ll (+1-1) 
- (modified) llvm/test/Transforms/JumpThreading/thread-debug-info.ll (+1-1) 
- (modified) llvm/test/Transforms/SROA/fake-use-sroa.ll (+1-1) 
- (modified) llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp (+1-1) 
- (modified) mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp (+1-1) 
- (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+1-1) 


``diff
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 50f161fd38ce69..aecca0f5df8d93 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -169,7 +169,7 @@ static VectorTypeModifier getTupleVTM(unsigned NF) {
 
 static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
   // We need a special rule for segment load/store since the data width is not
-  // encoded in the instrinsic name itself.
+  // encoded in the intrinsic name itself.
   const StringRef IRName = RVVI->getIRName();
   constexpr unsigned RVV_VTA = 0x1;
   constexpr unsigned RVV_VMA = 0x2;
@@ -192,7 +192,7 @@ static unsigned getIndexedLoadStorePtrIdx(const 
RVVIntrinsic *RVVI) {
 static unsigned getSegInstLog2SEW(StringRef InstName) {
   // clang-format off
   // We need a special rule for indexed segment load/store since the data width
-  // is not encoded in the instrinsic name itself.
+  // is not encoded in the intrinsic name itself.
   if (InstName.starts_with("vloxseg") || InstName.starts_with("vluxseg") ||
   InstName.starts_with("vsoxseg") || InstName.starts_with("vsuxseg"))
 return (unsigned)-1;
diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index 9d6916ef62af2e..fb65498fa1f444 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -53,7 +53,7 @@ eN

fdec,
 
-fall-instrinsics
+fall-intrinsics

https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=297";>qxlf77,
 
diff --git a/flang/include/flang/Runtime/magic-numbers.h 
b/flang/include/flang/Runtime/magic-numbers.h
index bab0e9ae05299a..1d3c5dca0b4bfb 100644
--- a/flang/include/flang/Runtime/magic-numbers.h
+++ b/flang/include/flang/Runtime/magic-numbers.h
@@ -107,7 +107,7 @@ The denorm value is a nonstandard extension.
 
 #if 0
 ieee_round_type values
-The values are those of the llvm.get.rounding instrinsic, which is assumed by
+The values are those of the llvm.get.rounding intrinsic, which is assumed by
 ieee_arithmetic module rounding procedures.
 #endif
 #define _FORTRAN_RUNTIME_IEEE_TO_ZERO 0
diff --git a/flang/lib/Evaluate/intrinsics.cpp 
b/flang/lib/Evaluate/intrinsics.cpp
index 4271faa0db12bf..aa44967817722e 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1690,7 +1690,7 @@ std::optional IntrinsicInterface::Match(
   // MAX and MIN (and others that map to them) allow their last argument to
   // be repeated indefinitely.  The actualForDummy vector is sized
   // and null-initialized to the non-repeated dummy argument count
-  // for other instrinsics.
+  // for other intrinsics.
   bool isMaxMin{dummyArgPatterns > 0 &&
   dummy[dummyArgPatterns - 1].optionality == Optionality::repeats};
   std::vector actualForDummy(
diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp 
b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
index c13064a284d127..d0092add0118f1 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
@@ -284,7 +284,7 @@ struct ForcedSpacing16 {
   }
 };
 
-/// Generate call to Exponent instrinsic runtime routine.
+/// Generate call to Exponent intrinsic runtime routine.
 mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder,
   mlir::Location loc, mlir::Type 
resultType,
   mlir::Value x) {
@@ -320,7 +320,7 @@ mlir::Value fir::runtime::genExponent(f

[clang] Remove type-punning in LazyOffsetPtr. (PR #112806)

2024-10-18 Thread Jessica Clarke via cfe-commits

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


[clang] [NFC][Clang] Fix enumerated mismatch warning (PR #112816)

2024-10-18 Thread via cfe-commits


@@ -3150,8 +3150,8 @@ Parser::DeclGroupPtrTy 
Parser::ParseCXXClassMemberDeclaration(
   if (Tok.is(tok::kw_concept)) {
 Diag(Tok.getLocation(),
  DS.isFriendSpecified() || NextToken().is(tok::kw_friend)
- ? diag::err_friend_concept
- : diag::
+ ? (unsigned)diag::err_friend_concept
+ : (unsigned)diag::

err_concept_decls_may_only_appear_in_global_namespace_scope);

Sirraide wrote:

```suggestion
 ? unsigned(diag::err_friend_concept)
 : unsigned(diag::
   
err_concept_decls_may_only_appear_in_global_namespace_scope));
```
We generally try to avoid C-style casts. You might have to reformat that 
because idk what clang-format is gonna do w/ this.

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


[clang] [Clang] Don't assert on substituted-but-yet-expanded packs for nested lambdas (PR #112896)

2024-10-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/112896

>From 6caf16d6ce8eb939c91ed87493c2ccab82d38411 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 18 Oct 2024 20:22:08 +0800
Subject: [PATCH 1/2] [Clang] Don't assert on substituted-but-yet-expanded
 packs for nested lambdas

---
 clang/docs/ReleaseNotes.rst  |  2 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp  | 49 ++--
 clang/test/SemaCXX/lambda-pack-expansion.cpp | 40 
 3 files changed, 75 insertions(+), 16 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b430b2b0ee3187..d071c480f36dc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -486,7 +486,7 @@ Bug Fixes to C++ Support
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
 - Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
-- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361)
+- A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361), (#GH112352)
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. (#GH63819), (#GH107560)
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 19bd4547665835..151b328872bd75 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -41,7 +41,7 @@ namespace {
 unsigned DepthLimit = (unsigned)-1;
 
 #ifndef NDEBUG
-bool ContainsFunctionParmPackExpr = false;
+bool ContainsIntermediatePacks = false;
 #endif
 
 void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
@@ -114,6 +114,11 @@ namespace {
   addUnexpanded(TTP);
   }
 
+#ifndef NDEBUG
+  ContainsIntermediatePacks |=
+  (bool)Template.getAsSubstTemplateTemplateParmPack();
+#endif
+
   return inherited::TraverseTemplateName(Template);
 }
 
@@ -297,13 +302,28 @@ namespace {
 
 #ifndef NDEBUG
 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *) {
-  ContainsFunctionParmPackExpr = true;
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool TraverseSubstNonTypeTemplateParmPackExpr(
+SubstNonTypeTemplateParmPackExpr *) {
+  ContainsIntermediatePacks = true;
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *) {
+  ContainsIntermediatePacks = true;
   return true;
 }
 
-bool containsFunctionParmPackExpr() const {
-  return ContainsFunctionParmPackExpr;
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc) {
+  ContainsIntermediatePacks = true;
+  return true;
 }
+
+bool containsIntermediatePacks() const { return ContainsIntermediatePacks; 
}
 #endif
   };
 }
@@ -439,21 +459,20 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
   if (!E->containsUnexpandedParameterPack())
 return false;
 
-  // FunctionParmPackExprs are special:
-  //
-  // 1) they're used to model DeclRefExprs to packs that have been expanded but
-  // had that expansion held off in the process of transformation.
-  //
-  // 2) they always have the unexpanded dependencies but don't introduce new
-  // unexpanded packs.
-  //
-  // We might encounter a FunctionParmPackExpr being a full expression, which a
-  // larger CXXFoldExpr would expand.
   SmallVector Unexpanded;
   CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
   Visitor.TraverseStmt(E);
-  assert((!Unexpanded.empty() || Visitor.containsFunctionParmPackExpr()) &&
+#ifndef NDEBUG
+  // The expression might contain a type/subexpression that has been 
substituted
+  // but has the expansion held off, e.g. a FunctionParmPackExpr which a larger
+  // CXXFoldExpr would expand. It's only possible when expanding a lambda as a
+  // pattern of a fold expression, so don't fire on an empty result in that
+  // case.
+  bool LambdaReferencingOuterPacks =
+  getEnclosingLambdaOrBlock() && Visitor.containsIntermediatePacks();
+  assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
  "Unable to find unexpanded parameter packs");
+#endif
   return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
 }
 
diff --git a/clang/test/SemaCXX/lambda-pack-expansion.cpp 
b/clang/test/SemaCXX/lambda-pack-expansion.cpp
index 0e60ecd8756600..7f7dd3bb095d57 100644
--- a/clang/test/SemaCXX/lambda-pack-expansion.cpp
+++ b/clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -94,3 +94,43 @@ template  void g2(Ts... p1s) {
 void f1() { g(); }
 

[clang] [Clang] Fix handling of immediate escalation for inherited constructors (PR #112860)

2024-10-18 Thread Erich Keane via cfe-commits

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


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


[clang] [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (PR #112887)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balazs Benics (steakhal)


Changes

This patch should not introduce much overhead as it only does one more 
constraint map lookup, which is really quick.

Depends on #112583

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+17) 
- (modified) clang/test/Analysis/unary-sym-expr.c (+30-3) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ecf7974c838650..f0311b7028f56d 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
 // calculate the effective range set by intersecting the range set
 // for A - B and the negated range set of B - A.
 getRangeForNegatedSymSym(SSE),
+// If commutative, we may have constaints for the commuted variant.
+getRangeCommutativeSymSym(SSE),
 // If Sym is a comparison expression (except <=>),
 // find any other comparisons with the same operands.
 // See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
 Sym->getType());
   }
 
+  std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) {
+auto Op = SSE->getOpcode();
+bool IsCommutative = llvm::is_contained(
+// ==, !=, |, &, +, *, ^
+{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
+if (!IsCommutative)
+  return std::nullopt;
+
+SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
+if (const RangeSet *Range = getConstraint(State, Commuted))
+  return *Range;
+return std::nullopt;
+  }
+
   // Returns ranges only for binary comparison operators (except <=>)
   // when left and right operands are symbolic values.
   // Finds any other comparisons with the same operands.
diff --git a/clang/test/Analysis/unary-sym-expr.c 
b/clang/test/Analysis/unary-sym-expr.c
index 7c4774f3cca82f..92e11b295bee7c 100644
--- a/clang/test/Analysis/unary-sym-expr.c
+++ b/clang/test/Analysis/unary-sym-expr.c
@@ -29,12 +29,39 @@ int test(int x, int y) {
   return 42;
 }
 
-void test_svalbuilder_simplification(int x, int y) {
+void test_svalbuilder_simplification_add(int x, int y) {
   if (x + y != 3)
 return;
   clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
-  // FIXME Commutativity is not supported yet.
-  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_mul(int x, int y) {
+  if (x * y != 3)
+return;
+  clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_and(int x, int y) {
+  if ((x & y) != 3)
+return;
+  clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_or(int x, int y) {
+  if ((x | y) != 3)
+return;
+  clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_xor(int x, int y) {
+  if ((x ^ y) != 3)
+return;
+  clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
 }
 
 int test_fp(int flag) {

``




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


[clang] [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (PR #112887)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




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

Author: Balazs Benics (steakhal)


Changes

This patch should not introduce much overhead as it only does one more 
constraint map lookup, which is really quick.

Depends on #112583

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+17) 
- (modified) clang/test/Analysis/unary-sym-expr.c (+30-3) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index ecf7974c838650..f0311b7028f56d 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
 // calculate the effective range set by intersecting the range set
 // for A - B and the negated range set of B - A.
 getRangeForNegatedSymSym(SSE),
+// If commutative, we may have constaints for the commuted variant.
+getRangeCommutativeSymSym(SSE),
 // If Sym is a comparison expression (except <=>),
 // find any other comparisons with the same operands.
 // See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
 Sym->getType());
   }
 
+  std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) {
+auto Op = SSE->getOpcode();
+bool IsCommutative = llvm::is_contained(
+// ==, !=, |, &, +, *, ^
+{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
+if (!IsCommutative)
+  return std::nullopt;
+
+SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
+if (const RangeSet *Range = getConstraint(State, Commuted))
+  return *Range;
+return std::nullopt;
+  }
+
   // Returns ranges only for binary comparison operators (except <=>)
   // when left and right operands are symbolic values.
   // Finds any other comparisons with the same operands.
diff --git a/clang/test/Analysis/unary-sym-expr.c 
b/clang/test/Analysis/unary-sym-expr.c
index 7c4774f3cca82f..92e11b295bee7c 100644
--- a/clang/test/Analysis/unary-sym-expr.c
+++ b/clang/test/Analysis/unary-sym-expr.c
@@ -29,12 +29,39 @@ int test(int x, int y) {
   return 42;
 }
 
-void test_svalbuilder_simplification(int x, int y) {
+void test_svalbuilder_simplification_add(int x, int y) {
   if (x + y != 3)
 return;
   clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
-  // FIXME Commutativity is not supported yet.
-  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_mul(int x, int y) {
+  if (x * y != 3)
+return;
+  clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_and(int x, int y) {
+  if ((x & y) != 3)
+return;
+  clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_or(int x, int y) {
+  if ((x | y) != 3)
+return;
+  clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
+}
+
+void test_svalbuilder_simplification_xor(int x, int y) {
+  if ((x ^ y) != 3)
+return;
+  clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
 }
 
 int test_fp(int flag) {

``




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


[clang] [llvm] [Clang] Put offloading globals in the `.llvm.rodata.offloading` section (PR #111890)

2024-10-18 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Would there be any reason to put entries for different offloading languages 
> into distinctly named “sub entries”?

Not really, this is just a list of all the device-side symbols the host might 
want, that would make it more difficult to later extract.

Also ping.

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


[clang] Fix build break in SemaHLSL.cpp on MSVC 2022: warning C4715: 'getResourceClass': not all control paths return a value (PR #112767)

2024-10-18 Thread Daniel Paoliello via cfe-commits

https://github.com/dpaoliello updated 
https://github.com/llvm/llvm-project/pull/112767

>From 20f602b8c28d966a7cc957a3ca4c6ed43e71258e Mon Sep 17 00:00:00 2001
From: "Daniel Paoliello (HE/HIM)" 
Date: Thu, 17 Oct 2024 12:21:25 -0700
Subject: [PATCH 1/3] Fix build break in SemaHLSL.cpp on MSVC 2022: warning
 C4715: 'getResourceClass': not all control paths return a value

---
 clang/lib/Sema/SemaHLSL.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index efb0fbaa432d76..50f0a553bc86e3 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -102,6 +102,7 @@ static ResourceClass getResourceClass(RegisterType RT) {
 return ResourceClass::Sampler;
   case RegisterType::C:
   case RegisterType::I:
+  default:
 llvm_unreachable("unexpected RegisterType value");
   }
 }

>From 7caa2a9af7d1fa71d8874a476c9a4abd74f2b488 Mon Sep 17 00:00:00 2001
From: Daniel Paoliello 
Date: Thu, 17 Oct 2024 12:58:54 -0700
Subject: [PATCH 2/3] Update clang/lib/Sema/SemaHLSL.cpp

Co-authored-by: Matheus Izvekov 
---
 clang/lib/Sema/SemaHLSL.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 50f0a553bc86e3..0900ff114224a2 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -102,9 +102,9 @@ static ResourceClass getResourceClass(RegisterType RT) {
 return ResourceClass::Sampler;
   case RegisterType::C:
   case RegisterType::I:
-  default:
 llvm_unreachable("unexpected RegisterType value");
   }
+  llvm_unreachable("unhandled RegisterType");
 }
 
 DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,

>From 3271191eb74400de00a4cb909b16c34da28d4e9a Mon Sep 17 00:00:00 2001
From: Daniel Paoliello 
Date: Fri, 18 Oct 2024 09:40:49 -0700
Subject: [PATCH 3/3] Update SemaHLSL.cpp

---
 clang/lib/Sema/SemaHLSL.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 0900ff114224a2..9dd3ebddd5d498 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -102,9 +102,10 @@ static ResourceClass getResourceClass(RegisterType RT) {
 return ResourceClass::Sampler;
   case RegisterType::C:
   case RegisterType::I:
-llvm_unreachable("unexpected RegisterType value");
+// Deliberately falling through to the unreachable below.
+break;
   }
-  llvm_unreachable("unhandled RegisterType");
+  llvm_unreachable("unexpected RegisterType value");
 }
 
 DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,

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


[clang] [NFC][Sema][OpenMP] Fix free-nonheap-object warning (PR #112942)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jinsong Ji (jsji)


Changes

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by 
GCC 11.

Fix warning

In destructor ‘llvm::APInt::~APInt()’,
inlined from ‘llvm::APInt::~APInt()’ at 
llvm-project/llvm/include/llvm/ADT/APInt.h:190:3,
inlined from ‘llvm::APSInt::~APSInt()’ at 
llvm-project/llvm/include/llvm/ADT/APSInt.h:23:21,
inlined from ‘bool 
checkOMPArraySectionConstantForReduction(clang::ASTContext&, const 
clang::ArraySectionExpr*, bool&, 
llvm::SmallVectorImpl&)’ at 
llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18357:45,
inlined from ‘bool actOnOMPReductionKindClause(clang::Sema&, 
{anonymous}::DSAStackTy*, clang::OpenMPClauseKind, 
llvm::ArrayRef, clang::SourceLocation, 
clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, 
clang::CXXScopeSpec&, const clang::DeclarationNameInfo&, 
llvm::ArrayRef, {anonymous}::ReductionData&)’ at 
llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18715:68:
llvm-project/llvm/include/llvm/ADT/APInt.h:192:18: error: ‘void operator delete 
[](void*)’ called on a pointer to an unallocated object ‘1’ 
[-Werror=free-nonheap-object]
  192 |   delete[] U.pVal;
  |  ^~~~


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


1 Files Affected:

- (modified) clang/lib/Sema/SemaOpenMP.cpp (+4-2) 


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0232745b3c19e5..fa81fc42c0ee53 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -18335,7 +18335,8 @@ static bool checkOMPArraySectionConstantForReduction(
 return false;
 
   // This is an array subscript which has implicit length 1!
-  ArraySizes.push_back(llvm::APSInt::get(1));
+  llvm::APSInt ConstantOne = llvm::APSInt::get(1);
+  ArraySizes.push_back(ConstantOne);
 } else {
   Expr::EvalResult Result;
   if (!Length->EvaluateAsInt(Result, Context))
@@ -18354,7 +18355,8 @@ static bool checkOMPArraySectionConstantForReduction(
   if (!SingleElement) {
 while (const auto *TempASE = dyn_cast(Base)) {
   // Has implicit length 1!
-  ArraySizes.push_back(llvm::APSInt::get(1));
+  llvm::APSInt ConstantOne = llvm::APSInt::get(1);
+  ArraySizes.push_back(ConstantOne);
   Base = TempASE->getBase()->IgnoreParenImpCasts();
 }
   }

``




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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Farzon Lotfi via cfe-commits


@@ -489,6 +542,9 @@ class OpLowerer {
   case Intrinsic::dx_typedBufferStore:
 HasErrors |= lowerTypedBufferStore(F);
 break;
+  case Intrinsic::dx_splitdouble:

farzonl wrote:

`replaceFunctionWithNamedStructOp` seems like the right way to go.

My understanding from the meeting was we wanted to define the mapping for 
`SplitDoubleType` in DXIL.td so we wouldn't need a `case 
Intrinsic::dx_splitdouble:`?

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


[clang] [Clang] Add a flag to include GPU startup files (PR #112025)

2024-10-18 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/112025

>From a02a27171801ad3f5618099b5035ef8185c2f835 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 11 Oct 2024 12:21:49 -0500
Subject: [PATCH 1/3] [Clang] Add a flag to include GPU startup files

Summary:
The C library for GPUs provides the ability to target regular C/C++
programs by providing the C library and a file containing kernels that
call the `main` function. This is mostly used for unit tests, this patch
provides a quick way to add them without needing to know the paths. I
currently do this explicitly, but according to the libc++ contributors
we don't want to need to specify these paths manually. See the
discussion in https://github.com/llvm/llvm-project/pull/104515.

I just default to `lib/` if the target-specific one isn't found because
the linker will handle giving a reasonable error message if it's not
found. Basically the use-case looks like this.

```console
$ clang test.c --target=amdgcn-amd-amdhsa -mcpu=native -gpustartfiles
$ amdhsa-loader a.out
PASS!
```
---
 clang/include/clang/Driver/Options.td  | 3 +++
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 9 +
 clang/lib/Driver/ToolChains/Cuda.cpp   | 9 +
 clang/test/Driver/gpustartfiles.c  | 7 +++
 4 files changed, 28 insertions(+)
 create mode 100644 clang/test/Driver/gpustartfiles.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 379e75b197cf96..3583f46a972314 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1316,6 +1316,9 @@ defm offload_via_llvm : BoolFOption<"offload-via-llvm",
   BothFlags<[], [ClangOption], " LLVM/Offload as portable offloading 
runtime.">>;
 }
 
+def gpustartfiles : Flag<["-"], "gpustartfiles">, Group,
+  HelpText<"Link the GPU C startup utilities automatically, used for 
testing.">;
+
 // CUDA options
 let Group = cuda_Group in {
 def cuda_include_ptx_EQ : Joined<["--"], "cuda-include-ptx=">,
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 2c85d21ebd738c..9a648be4ea3915 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -648,6 +648,15 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 Args.MakeArgString("-plugin-opt=-mattr=" + llvm::join(Features, ",")));
   }
 
+  if (Args.hasArg(options::OPT_gpustartfiles)) {
+auto IncludePath = getToolChain().getStdlibPath();
+if (!IncludePath)
+  IncludePath = "/lib";
+SmallString<128> P(*IncludePath);
+llvm::sys::path::append(P, "crt1.o");
+CmdArgs.append({"-lc", "-lm", Args.MakeArgString(P)});
+  }
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(std::make_unique(
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index b368c473756731..20ec010ade04cb 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -643,6 +643,15 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
   CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
 
+  if (Args.hasArg(options::OPT_gpustartfiles)) {
+auto IncludePath = getToolChain().getStdlibPath();
+if (!IncludePath)
+  IncludePath = "/lib";
+SmallString<128> P(*IncludePath);
+llvm::sys::path::append(P, "crt1.o");
+CmdArgs.append({"-lc", "-lm", Args.MakeArgString(P)});
+  }
+
   C.addCommand(std::make_unique(
   JA, *this,
   ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8,
diff --git a/clang/test/Driver/gpustartfiles.c 
b/clang/test/Driver/gpustartfiles.c
new file mode 100644
index 00..c1b7a6fa922df4
--- /dev/null
+++ b/clang/test/Driver/gpustartfiles.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -gpustartfiles \
+// RUN:   -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=NVPTX %s
+// NVPTX: clang-nvlink-wrapper{{.*}}"-lc" "-lm" "{{.*}}crt1.o"
+//
+// RUN: %clang -target amdgcn-amd-amdhsa -march=gfx90a -gpustartfiles \
+// RUN:   -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=AMDGPU %s
+// AMDGPU: ld.lld{{.*}}"-lc" "-lm" "{{.*}}crt1.o"

>From 6ccba0250b564045c71ac693c2caf196ab993b1a Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 11 Oct 2024 12:52:49 -0500
Subject: [PATCH 2/3] Add -startfiles -stdlib positive versions for GPU

---
 clang/include/clang/Driver/Options.td  | 7 ---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 6 --
 clang/lib/Driver/ToolChains/Cuda.cpp   | 6 --
 clang/test/Driver/gpustartfiles.c  | 4 ++--
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3583f46a972314..a10330e992d016 100644
--- a/clang/include

[clang] [llvm] [NVPTX] Remove nvvm.ldg.global.* intrinsics (PR #112834)

2024-10-18 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.

LGTM. Please add a note about the intrinsic removal/deprecation to the release 
notes.

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


[clang] [clang] constexpr built-in fma function. (PR #113020)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (c8ef)


Changes

According to [P0533R9](https://wg21.link/P0533R9), the C++ standard library 
functions `fma` are now `constexpr`:

```c++
  constexpr floating-point-type fma(floating-point-type x, floating-point-type 
y,
floating-point-type z);
  constexpr float   fmaf(float x, float y, float z);
  constexpr long double fmal(long double x, long double y, long double 
z);
```

To implement this feature in libc++, we must make the built-in `fma` function 
`constexpr`. This patch adds the implementation of a `constexpr` fma function 
for the current constant evaluator and the new bytecode interpreter.

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/Builtins.td (+1) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+37) 
- (modified) clang/lib/AST/ExprConstant.cpp (+16) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+9) 
- (modified) clang/test/Sema/constant-builtins-2.c (+7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7a6ace8bb895d..605d55a9e51f37 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -273,6 +273,7 @@ Non-comprehensive list of changes in this release
 - Plugins can now define custom attributes that apply to statements
   as well as declarations.
 - ``__builtin_abs`` function can now be used in constant expressions.
+- ``__builtin_fma`` function can now be used in constant expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 90475a361bb8f8..55f470a9f715b9 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3723,6 +3723,7 @@ def Fma : FPMathTemplate, LibBuiltin<"math.h"> {
   let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions];
   let Prototype = "T(T, T, T)";
   let AddBuiltinPrefixedAlias = 1;
+  let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
 }
 
 def Fmax : FPMathTemplate, LibBuiltin<"math.h"> {
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d4a8e6c2035ee5..145f4627dd73da 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -142,6 +142,19 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, 
APValue &Result,
 #undef RET_CASE
 }
 
+/// Get rounding mode to use in evaluation of the specified expression.
+///
+/// If rounding mode is unknown at compile time, still try to evaluate the
+/// expression. If the result is exact, it does not depend on rounding mode.
+/// So return "tonearest" mode instead of "dynamic".
+static llvm::RoundingMode getActiveRoundingMode(InterpState &S, const Expr *E) 
{
+  llvm::RoundingMode RM =
+  E->getFPFeaturesInEffect(S.getLangOpts()).getRoundingMode();
+  if (RM == llvm::RoundingMode::Dynamic)
+RM = llvm::RoundingMode::NearestTiesToEven;
+  return RM;
+}
+
 static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
   const InterpFrame *Frame,
   const CallExpr *Call) {
@@ -549,6 +562,22 @@ static bool interp__builtin_fpclassify(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_fma(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *Func,
+const CallExpr *Call) {
+  const Floating &X = getParam(Frame, 0);
+  const Floating &Y = getParam(Frame, 1);
+  const Floating &Z = getParam(Frame, 2);
+  Floating Result;
+
+  llvm::RoundingMode RM = getActiveRoundingMode(S, Call);
+  Floating::mul(X, Y, RM, &Result);
+  Floating::add(Result, Z, RM, &Result);
+
+  S.Stk.push(Result);
+  return true;
+}
+
 // The C standard says "fabs raises no floating-point exceptions,
 // even if x is a signaling NaN. The returned value is independent of
 // the current rounding direction mode."  Therefore constant folding can
@@ -1814,6 +1843,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_fma:
+  case Builtin::BI__builtin_fmaf:
+  case Builtin::BI__builtin_fmal:
+  case Builtin::BI__builtin_fmaf128:
+if (!interp__builtin_fma(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   case Builtin::BI__builtin_fabs:
   case Builtin::BI__builtin_fabsf:
   case Builtin::BI__builtin_fabsl:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 8e36cad2d2c6e7..685ce8a63f6c9e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr

[clang] [clang] constexpr built-in fma function. (PR #113020)

2024-10-18 Thread via cfe-commits

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


[clang] [clang] constexpr built-in fma function. (PR #113020)

2024-10-18 Thread via cfe-commits

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


[clang] [clang] constexpr built-in fma function. (PR #113020)

2024-10-18 Thread via cfe-commits

c8ef wrote:

I'm not sure why there are noises in the Windows CI, as they seem unrelated. 
The Linux CI is working as expected.

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


[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)

2024-10-18 Thread Shafik Yaghmour via cfe-commits


@@ -11536,6 +11536,9 @@ bool 
ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(
   LValue Subobject = This;
   Subobject.addArray(Info, ExprToVisit, CAT);
   auto Eval = [&](const Expr *Init, unsigned ArrayIndex) {
+if (Init->isValueDependent())

shafik wrote:

This looks reasonable, but please again I have have stated before in other PRs 
the summary needs to be more detailed. Explain that we are passing ArrayFillers 
to EvaluateInPlace when they are dependent  and then explain what the fix 
is.

Thank you 

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


[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2024-10-18 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/105738

>From b775b7288035d83281434e27341b98a76623802f Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Thu, 22 Aug 2024 09:44:56 -0700
Subject: [PATCH 1/3] [Clang] Match MSVC handling of duplicate header search
 paths in Microsoft compatibility modes.

Clang has historically mimicked gcc behavior for header file searching in
which user search paths are ordered before system search paths, user search
paths that duplicate a (later) system search path are ignored, and search
paths that duplicate an earlier search path of the same user/system kind are
ignored.

MSVC behavior differs in that user search paths are ordered before system
search paths (like gcc), and search paths that duplicate an earlier search
path are ignored regardless of user/system kind (similar to gcc, but without
the preference for system search paths over duplicate user search paths).

The gcc and MSVC differences are observable for driver invocations that pass,
e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc behavior will result in
`dir2` being searched before `dir1` while the MSVC behavior will result in
`dir1` being searched before `dir2`.

This patch modifies Clang to match the MSVC behavior for handling of duplicate
header search paths when running in Microsoft compatibility mode (e.g., when
invoked with the `-fms-compatibility` option explicitly or implicitly enabled).
---
 clang/docs/ReleaseNotes.rst   | 14 +++
 clang/lib/Lex/InitHeaderSearch.cpp| 21 ++--
 clang/test/Driver/header-search-duplicates.c  | 76 +++
 .../microsoft-header-search-duplicates.c  | 97 +++
 4 files changed, 199 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/Driver/header-search-duplicates.c
 create mode 100644 clang/test/Driver/microsoft-header-search-duplicates.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1da8c82d52e618..03c27342f31f66 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -638,6 +638,20 @@ Windows Support
   When `-fms-compatibility-version=18.00` or prior is set on the command line 
this Microsoft extension is still
   allowed as VS2013 and prior allow it.
 
+- Clang now matches MSVC behavior for handling of duplicate header search paths
+  when running in Microsoft compatibility mode. Historically, Clang has
+  mimicked gcc behavior in which user search paths are ordered before
+  system search paths, user search paths that duplicate a (later) system search
+  path are ignored, and search paths that duplicate an earlier search path of
+  the same user/system kind are ignored. The MSVC behavior is that user search
+  paths are ordered before system search paths (like gcc), and search paths 
that
+  duplicate an earlier search path are ignored regardless of user/system kind
+  (similar to gcc, but without the preference for system search paths over
+  duplicate user search paths). These differences are observable for driver
+  invocations that pass, e.g., `-Idir1 -isystem dir2 -isystem dir1`. The gcc
+  behavior will search `dir2` before `dir1` and the MSVC behavior will search
+  `dir1` before `dir2`.
+
 LoongArch Support
 ^
 
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index 2218db15013d92..3f487f3a4c1c05 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -368,7 +368,8 @@ void InitHeaderSearch::AddDefaultIncludePaths(
 /// If there are duplicate directory entries in the specified search list,
 /// remove the later (dead) ones.  Returns the number of non-system headers
 /// removed, which is used to update NumAngled.
-static unsigned RemoveDuplicates(std::vector &SearchList,
+static unsigned RemoveDuplicates(const LangOptions &Lang,
+ std::vector &SearchList,
  unsigned First, bool Verbose) {
   llvm::SmallPtrSet SeenDirs;
   llvm::SmallPtrSet SeenFrameworkDirs;
@@ -394,14 +395,15 @@ static unsigned 
RemoveDuplicates(std::vector &SearchList,
 continue;
 }
 
-// If we have a normal #include dir/framework/headermap that is shadowed
-// later in the chain by a system include location, we actually want to
-// ignore the user's request and drop the user dir... keeping the system
-// dir.  This is weird, but required to emulate GCC's search path 
correctly.
+// When not in MSVC compatibility mode, if we have a normal
+// #include dir/framework/headermap that is shadowed later in the chain by
+// a system include location, we actually want to ignore the user's request
+// and drop the user dir... keeping the system dir.  This is weird, but
+// required to emulate GCC's search path correctly.
 //
 // Since dupes of system dirs are rare, just rescan to find the original
 // that we're nuking instead of using a De

[clang] [Clang] prevent assertion failure in value-dependent initializer expressions (PR #112612)

2024-10-18 Thread Shafik Yaghmour via cfe-commits

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


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


[clang] [clang] constexpr built-in fma function. (PR #113020)

2024-10-18 Thread via cfe-commits

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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-10-18 Thread Damyan Pepper via cfe-commits

https://github.com/damyanp commented:

LGTM. Would be good to get review from someone more familiar with ASTs and 
external sema source.

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


[clang] [llvm] [LLVM][MC][AArch64] Assembler support for Armv9.6-A memory systems extensions (PR #112341)

2024-10-18 Thread Jonathan Thackray via cfe-commits


@@ -1331,7 +1331,10 @@ TEST(TargetParserTest, AArch64ExtensionFeatures) {
   AArch64::AEK_SVE_F16F32MM, AArch64::AEK_SVE_AES2,
   AArch64::AEK_SSVE_AES, AArch64::AEK_F8F32MM,
   AArch64::AEK_F8F16MM,  AArch64::AEK_LSFE,
-  AArch64::AEK_FPRCVT,   AArch64::AEK_CMPBR};
+  AArch64::AEK_FPRCVT,   AArch64::AEK_CMPBR,
+  AArch64::AEK_LSUI, AArch64::AEK_OCCMO,
+  AArch64::AEK_PCDPHINT,
+};

jthackray wrote:

Fix `clang-format`:
```suggestion
  };
```

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


[clang] f7b6dc8 - [Clang] Fix missing `-` in argument to nvlinker

2024-10-18 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2024-10-18T19:16:42-05:00
New Revision: f7b6dc821ad2aa02e027db76f193b85a87443e0b

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

LOG: [Clang] Fix missing `-` in argument to nvlinker

Added: 


Modified: 
clang/lib/Driver/ToolChains/Cuda.cpp
clang/test/Driver/cuda-cross-compiling.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index e9d2e3fe6d5ce0..412b379304b1e6 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -635,7 +635,7 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   getNVPTXTargetFeatures(C.getDriver(), getToolChain().getTriple(), Args,
  Features);
   CmdArgs.push_back(
-  Args.MakeArgString("--plugin-opt=mattr=" + llvm::join(Features, ",")));
+  Args.MakeArgString("--plugin-opt=-mattr=" + llvm::join(Features, ",")));
 
   // Add paths for the default clang library path.
   SmallString<256> DefaultLibPath =

diff  --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 54c291fac66ffd..126e9e9fc83d57 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -104,4 +104,4 @@
 // RUN: %clang -target nvptx64-nvidia-cuda --cuda-feature=+ptx63 -march=sm_52 
-### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=FEATURE %s
 
-// FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=mattr=+ptx63"
+// FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=-mattr=+ptx63"



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


[clang] [llvm] [RISCV] Inline Assembly Support for GPR Pairs ('Pr') (PR #112983)

2024-10-18 Thread Sam Elliott via cfe-commits

lenary wrote:


> I'm concerned that if we make i128 legal, we will have to write custom 
> splitting code for every operation. Using v2i64 probably has other problems 
> conflicting with the V extension fixed vector support.

I sort-of expected that making `i128` legal would be problematic, I didn't 
realise that `v2i64` would also conflict with something we're currently using.

> The Arch64 MVT::i64x8 may be a way to work around this. We could have a 
> special pair MVT only used by inline assembly.

Ok, this sounds doable - so something like `MVT::xlen_pair` is the way I'll 
lean, rather than a different type for rv32/rv64.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -18952,6 +18955,142 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
+  case Builtin::BI__builtin_hlsl_splitdouble: {

tex3d wrote:

This is quite a lot of code in this case of the switch statement, perhaps we 
could break this out into a static function?

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -18952,6 +18955,142 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
+  case Builtin::BI__builtin_hlsl_splitdouble: {
+
+assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+   "asuint operands types mismatch");
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+const auto *OutArg1 = dyn_cast(E->getArg(1));
+const auto *OutArg2 = dyn_cast(E->getArg(2));
+
+CallArgList Args;
+LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, 
OutArg1->getType());
+LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, 
OutArg2->getType());
+
+if (getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+  Args.reverseWritebacks();
+
+auto EmitVectorCode =
+[](Value *Op, CGBuilderTy *Builder,
+   FixedVectorType *DestTy) -> std::pair {
+  Value *bitcast = Builder->CreateBitCast(Op, DestTy);
+
+  SmallVector LowbitsIndex;
+  SmallVector HighbitsIndex;
+
+  for (unsigned int Idx = 0; Idx < DestTy->getNumElements(); Idx += 2) {
+LowbitsIndex.push_back(Idx);
+HighbitsIndex.push_back(Idx + 1);
+  }
+
+  Value *Arg0 = Builder->CreateShuffleVector(bitcast, LowbitsIndex);
+  Value *Arg1 = Builder->CreateShuffleVector(bitcast, HighbitsIndex);
+
+  return std::make_pair(Arg0, Arg1);
+};
+
+Value *LastInst = nullptr;
+
+if (CGM.getTarget().getTriple().isDXIL()) {
+
+  llvm::Type *RetElementTy = Int32Ty;
+  if (auto *Op0VecTy = E->getArg(0)->getType()->getAs())
+RetElementTy = llvm::VectorType::get(
+Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
+  auto *RetTy = llvm::StructType::get(RetElementTy, RetElementTy);
+
+  CallInst *CI = Builder.CreateIntrinsic(
+  RetTy, Intrinsic::dx_splitdouble, {Op0}, nullptr, 
"hlsl.splitdouble");
+
+  Value *Arg0 = Builder.CreateExtractValue(CI, 0);
+  Value *Arg1 = Builder.CreateExtractValue(CI, 1);
+
+  Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+  LastInst = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+
+} else {
+
+  assert(!CGM.getTarget().getTriple().isDXIL() &&
+ "For non-DXIL targets we generate the instructions");
+
+  if (!Op0->getType()->isVectorTy()) {
+FixedVectorType *DestTy = FixedVectorType::get(Int32Ty, 2);
+Value *Bitcast = Builder.CreateBitCast(Op0, DestTy);
+
+Value *Arg0 = Builder.CreateExtractElement(Bitcast, 0.0);
+Value *Arg1 = Builder.CreateExtractElement(Bitcast, 1.0);
+
+Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+LastInst = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+  } else {
+
+const auto *TargTy = E->getArg(0)->getType()->getAs();
+
+int NumElements = TargTy->getNumElements();
+
+FixedVectorType *DestTy = FixedVectorType::get(Int32Ty, 4);
+if (NumElements == 1) {
+  FixedVectorType *DestTy = FixedVectorType::get(Int32Ty, 2);
+  Value *Bitcast = Builder.CreateBitCast(Op0, DestTy);
+
+  Value *Arg0 = Builder.CreateExtractElement(Bitcast, 0.0);
+  Value *Arg1 = Builder.CreateExtractElement(Bitcast, 1.0);
+
+  Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+  LastInst = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+} else if (NumElements == 2) {
+  auto [LowBits, HighBits] = EmitVectorCode(Op0, &Builder, DestTy);
+
+  Builder.CreateStore(LowBits, Op1TmpLValue.getAddress());
+  LastInst = Builder.CreateStore(HighBits, Op2TmpLValue.getAddress());
+} else {
+
+  SmallVector> EmitedValuePairs;
+
+  for (int It = 0; It < NumElements; It += 2) {
+// Due to existing restrictions to SPIR-V and splitdouble,
+// all shufflevector operations, should return vectors of
+// the same size, up to 4. Such introduce and edge case

tex3d wrote:

I don't understand why SPIR-V vector width/shuffle restrictions are being 
applied during builtin codegen.  Shouldn't constraints be applied elsewhere 
when necessary?  I would have expected the SPIR-V path to be much simpler here.

Most elementwise HLSL intrinsics must support matrices, which should map to 
large vectors.  Shuffles would be used in various cases on those as well.  I 
would think we need an approach that can handle arbitrary, legal llvm 
vector/shuffle code then transform and constrain these later for SPIR-V 
lowering.

Also `!DXIL` could mean more than just SPIR-V at some point, right?

https://github.com/llvm/llvm-project/pull/109331
___
cfe-commits mailing list
cfe-commits@lis

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -4871,6 +4871,12 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_splitdouble"];

tex3d wrote:

Are we inconsistent on the use of "elementwise"?  Shouldn't we have that here?

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -4681,6 +4601,87 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address 
Addr) const {
   IsUsed = true;
 }
 
+/// Emit the actual writing-back of a writeback.
+void CodeGenFunction::EmitWriteback(CodeGenFunction &CGF,

tex3d wrote:

Moving this function makes it hard to tell if it's been modified at the same 
time.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -5149,6 +5152,12 @@ class CodeGenFunction : public CodeGenTypeCache {
SourceLocation ArgLoc, AbstractCallee AC,
unsigned ParmNum);
 
+  /// EmitWriteback - Emit callbacks for function.
+  void EmitWritebacks(CodeGenFunction &CGF, const CallArgList &Args);
+
+  void EmitWriteback(CodeGenFunction &CGF,
+ const CallArgList::Writeback &writeback);

tex3d wrote:

Was it necessary to expose `EmitWriteback`?  It seems you would only need 
`EmitWritebacks`.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -2074,6 +2083,35 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_hlsl_splitdouble: {
+if (SemaRef.checkArgCount(TheCall, 3))
+  return true;
+
+Expr *Op0 = TheCall->getArg(0);
+
+auto CheckIsNotDouble = [](clang::QualType PassedType) -> bool {

tex3d wrote:

Naming convention for `CheckIsNotDouble` seems reversed from what I'd expect 
based on some of the established patterns, since double is the desired type.  
See similar functions `CheckAllArgsHaveFloatRepresentation`, 
`CheckFloatOrHalfRepresentations`, `CheckNoDoubleVectors`, 
`CheckFloatingOrIntRepresentation`, etc...

Note: same comment for function `CheckIsNotUint` below.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -18952,6 +18955,142 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
+  case Builtin::BI__builtin_hlsl_splitdouble: {
+
+assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+   "asuint operands types mismatch");
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+const auto *OutArg1 = dyn_cast(E->getArg(1));
+const auto *OutArg2 = dyn_cast(E->getArg(2));
+
+CallArgList Args;
+LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, 
OutArg1->getType());
+LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, 
OutArg2->getType());
+
+if (getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+  Args.reverseWritebacks();
+
+auto EmitVectorCode =
+[](Value *Op, CGBuilderTy *Builder,
+   FixedVectorType *DestTy) -> std::pair {
+  Value *bitcast = Builder->CreateBitCast(Op, DestTy);
+
+  SmallVector LowbitsIndex;
+  SmallVector HighbitsIndex;
+
+  for (unsigned int Idx = 0; Idx < DestTy->getNumElements(); Idx += 2) {
+LowbitsIndex.push_back(Idx);
+HighbitsIndex.push_back(Idx + 1);
+  }
+
+  Value *Arg0 = Builder->CreateShuffleVector(bitcast, LowbitsIndex);
+  Value *Arg1 = Builder->CreateShuffleVector(bitcast, HighbitsIndex);
+
+  return std::make_pair(Arg0, Arg1);
+};
+
+Value *LastInst = nullptr;
+
+if (CGM.getTarget().getTriple().isDXIL()) {
+
+  llvm::Type *RetElementTy = Int32Ty;
+  if (auto *Op0VecTy = E->getArg(0)->getType()->getAs())
+RetElementTy = llvm::VectorType::get(
+Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
+  auto *RetTy = llvm::StructType::get(RetElementTy, RetElementTy);
+
+  CallInst *CI = Builder.CreateIntrinsic(
+  RetTy, Intrinsic::dx_splitdouble, {Op0}, nullptr, 
"hlsl.splitdouble");
+
+  Value *Arg0 = Builder.CreateExtractValue(CI, 0);
+  Value *Arg1 = Builder.CreateExtractValue(CI, 1);
+
+  Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+  LastInst = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+
+} else {
+
+  assert(!CGM.getTarget().getTriple().isDXIL() &&
+ "For non-DXIL targets we generate the instructions");

tex3d wrote:

No need to assert the negation of the if condition in the else block, right?

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-18 Thread Tex Riddell via cfe-commits


@@ -438,6 +438,24 @@ template  constexpr uint asuint(T F) {
   return __detail::bit_cast(F);
 }
 
+//===--===//
+// asuint splitdouble builtins
+//===--===//
+
+/// \fn void asuint(double D, out uint lowbits, out int highbits)
+/// \brief Split and interprets the lowbits and highbits of double D into 
uints.
+/// \param D The input double.
+/// \param lowbits The output lowbits of D.
+/// \param highbits The highbits lowbits D.

tex3d wrote:

```suggestion
/// \param highbits The output highbits D.
```

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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-10-18 Thread Joshua Batista via cfe-commits


@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder {
 S.Context, Builder.Record->getDeclContext(), SourceLocation(),
 SourceLocation(), /* TemplateDepth */ 0, Position,
 &S.Context.Idents.get(Name, tok::TokenKind::identifier),
-/* Typename */ false,
-/* ParameterPack */ false);
+/* Typename */ true,
+/* ParameterPack */ false,
+/* HasTypeConstraint*/ false);
 if (!DefaultValue.isNull())
   Decl->setDefaultArgument(
   S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(),
  SourceLocation()));
-
+Decl->setReferenced();
 Params.emplace_back(Decl);
 return *this;
   }
 
-  BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
+  ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S,
+  ConceptDecl *CD) {
+ASTContext &context = S.getASTContext();
+SourceLocation loc = Builder.Record->getBeginLoc();
+DeclarationNameInfo DNI(CD->getDeclName(), loc);
+NestedNameSpecifierLoc NNSLoc;
+DeclContext *DC = Builder.Record->getDeclContext();
+TemplateArgumentListInfo TALI(loc, loc);
+
+// assume that the concept decl has just one template parameter
+TemplateTypeParmDecl *ConceptTTPD = dyn_cast(
+CD->getTemplateParameters()->getParam(0));
+
+clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create(

bob80905 wrote:

Added! I've left out the expected AST structure since it probably won't ever 
conform to clang format.

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


[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112081

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/2] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

[clang] [NvlinkWrapper] Use `-plugin-opt=mattr=` instead of a custom feature (PR #111712)

2024-10-18 Thread Joseph Huber via cfe-commits

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


[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)

2024-10-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112424

>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier
 for missing primary declarations

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Sema/SemaAccess.cpp | 3 ++-
 clang/test/SemaCXX/enum.cpp   | 8 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set 
for missing
+  primary declarations. (#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-MemberDecl->setAccess(LexicalAS);
+if (LexicalAS != AS_none)
+  MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
 })
   };
 };
+
+namespace GH112208 {
+class C {
+  enum E { e = 0 };
+  void f(int, enum E;); // expected-error {{ISO C++ forbids forward references 
to 'enum' types}} \
+// expected-error {{unexpected ';' before ')'}}
+};
+}

>From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 14:55:47 +0300
Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum
 forward declarations

---
 clang/docs/ReleaseNotes.rst   | 3 +--
 clang/lib/Sema/SemaAccess.cpp | 3 +--
 clang/lib/Sema/SemaDecl.cpp   | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64ffdcde045a3a..3fd37663ca7bc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,8 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when the default lexical access specifier was set 
for missing
-  primary declarations. (#GH112208)
+- Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 8b4a5b70669d84..df6edb21a50dee 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-if (LexicalAS != AS_none)
-  MemberDecl->setAccess(LexicalAS);
+MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..9eb3d06289e88f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
+  if (TUK == TagUseKind::Declaration && Name)
+Invalid = true;
 } else if (!PrevDecl) {
   Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
 }

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


[clang] [llvm] [HLSL][SPIRV] Implement `WaveActiveMax` intrinsic (PR #112991)

2024-10-18 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 6d13cc9411b998aabf1a55e0813236ba7a278929 
b18e40978cae2c0d9ba9aeb61cf7294809b75012 --extensions h,cpp -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Sema/SemaHLSL.cpp llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 6b9d5cab6d..b7a8fc91f9 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -1801,9 +1801,9 @@ bool 
SPIRVInstructionSelector::selectWaveActiveMax(Register ResVReg,
   SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
   // Retreive the operation to use based on input type
   bool IsFloatTy = GR.isScalarOrVectorOfType(InputRegister, 
SPIRV::OpTypeFloat);
-  auto Opcode =
-  IsFloatTy ? SPIRV::OpGroupNonUniformFMax : (IsSigned ?
-   SPIRV::OpGroupNonUniformSMax : SPIRV::OpGroupNonUniformUMax);
+  auto Opcode = IsFloatTy ? SPIRV::OpGroupNonUniformFMax
+  : (IsSigned ? SPIRV::OpGroupNonUniformSMax
+  : SPIRV::OpGroupNonUniformUMax);
   return BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
   .addDef(ResVReg)
   .addUse(GR.getSPIRVTypeID(ResType))

``




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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-10-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/112600

>From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 10 Oct 2024 14:31:25 -0700
Subject: [PATCH 01/14] ConceptSpecializationExpr shows up in AST!!!

---
 .../clang/Sema/HLSLExternalSemaSource.h   |   2 +
 clang/lib/AST/DeclTemplate.cpp|   6 +-
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +-
 3 files changed, 158 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 3c7495e66055dc..0266bc0f8b336e 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
   using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
+
+  ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl);
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 6fe817c5ef1c6b..2eae6d14718b86 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, 
DeclContext *DC,
  TemplateParameterList *Params,
  Expr *ConstraintExpr) {
   bool Invalid = AdoptTemplateParameterList(Params, DC);
-  auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);
+  auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);
   if (Invalid)
-TD->setInvalidDecl();
-  return TD;
+CD->setInvalidDecl();
+  return CD;
 }
 
 ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 2913d16fca4823..8104513857027c 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder {
   TemplateParameterListBuilder addTemplateArgumentList(Sema &S);
   BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S,
   ArrayRef Names);
+  BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S);
 };
 
 struct TemplateParameterListBuilder {
@@ -326,7 +327,8 @@ struct TemplateParameterListBuilder {
 SourceLocation(), /* TemplateDepth */ 0, Position,
 &S.Context.Idents.get(Name, tok::TokenKind::identifier),
 /* Typename */ false,
-/* ParameterPack */ false);
+/* ParameterPack */ false,
+/* HasTypeConstraint*/ true);
 if (!DefaultValue.isNull())
   Decl->setDefaultArgument(
   S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(),
@@ -336,6 +338,152 @@ struct TemplateParameterListBuilder {
 return *this;
   }
 
+  Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
+ TemplateTypeParmDecl *T) {
+clang::ASTContext &context = S.getASTContext();
+// Obtain the QualType for 'unsigned long'
+clang::QualType unsignedLongType = context.UnsignedLongTy;
+
+// Create a QualType that points to this TemplateTypeParmDecl
+clang::QualType TType = context.getTypeDeclType(T);
+
+// Create a TypeSourceInfo for the template type parameter 'T'
+clang::TypeSourceInfo *TTypeSourceInfo =
+context.getTrivialTypeSourceInfo(TType, NameLoc);
+
+clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext())
+clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo,
+unsignedLongType, NameLoc, NameLoc);
+
+// Create an IntegerLiteral for the value '16'
+llvm::APInt intValue(context.getIntWidth(context.IntTy), 4);
+clang::IntegerLiteral *intLiteral = new (context)
+clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc);
+
+// Create an ImplicitCastExpr to cast 'int' to 'unsigned long'
+FPOptionsOverride fpoo = FPOptionsOverride();
+clang::ImplicitCastExpr *implicitCastExpr = 
clang::ImplicitCastExpr::Create(
+context,
+unsignedLongType, // The type we are casting to (QualType for 'unsigned
+  // long')
+clang::CK_IntegralCast, // CastKind (e.g., Integral cast)
+intLiteral, // Sub-expression being cast
+nullptr,// Base path, usually null for implicit casts
+clang::VK_XValue,
+fpoo // Value kind, typically VK_RValue for implicit casts
+);
+
+clang::QualType BoolTy = context.BoolTy;
+
+clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create(
+context, sizeofExpr, // Left-hand side expression
+

[clang] [llvm] [HLSL][SPIRV] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Finn Plummer (inbelic)


Changes

```
  - add clang builtin to Builtins.td
  - link builtin in hlsl_intrinsics
  - add codegen for spirv intrinsic and two directx intrinsics to retain
signedness information of the operands in CGBuiltin.cpp
  - add semantic analysis in SemaHLSL.cpp
  - add lowering of spirv intrinsic to spirv backend in
SPIRVInstructionSelector.cpp

  - add test cases to illustrate passes

Note that this defines the dx intrinsics but does not implement the
DirectX lowering to DXIL. This will implemented in a second pr when
the dependent pr merges.
```
Part 1 of #70106 

---

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


11 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+34) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+99) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+31) 
- (added) clang/test/CodeGenHLSL/builtins/WaveActiveSum.hlsl (+48) 
- (added) clang/test/SemaHLSL/BuiltIns/WaveActiveSum-errors.hlsl (+28) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+2) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+33) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveSum.ll (+41) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 382fb6b7a3c031..7205f10b01c2b9 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4749,6 +4749,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "unsigned int(bool)";
 }
 
+def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_sum"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void (...)";
+}
+
 def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c458a62d9be48c..95093723c2f495 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9232,6 +9232,9 @@ def err_typecheck_expect_scalar_or_vector : Error<
   "a vector of such type is required">;
 def err_typecheck_expect_any_scalar_or_vector : Error<
   "invalid operand of type %0 where a scalar or vector is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<
+  "invalid operand of type %0 where %1 or "
+  "a vector of such type is not allowed">;
 def err_typecheck_expect_flt_or_vector : Error<
   "invalid operand of type %0 where floating, complex or "
   "a vector of such types is required">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 12f99d9f1178a9..46646492b30d31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18638,6 +18638,23 @@ static Intrinsic::ID 
getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
   return RT.getUDotIntrinsic();
 }
 
+// Return wave active sum that corresponds to the QT scalar type
+static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
+   CGHLSLRuntime &RT, QualType QT) 
{
+  switch (Arch) {
+  case llvm::Triple::spirv:
+return llvm::Intrinsic::spv_wave_active_sum;
+  case llvm::Triple::dxil: {
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::dx_wave_active_usum;
+return llvm::Intrinsic::dx_wave_active_sum;
+  }
+  default:
+llvm_unreachable("Intrinsic WaveActiveSum"
+ " not supported by target architecture");
+  }
+}
+
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -18883,6 +18900,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 /*ReturnType=*/Op0->getType(), CGM.getHLSLRuntime().getStepIntrinsic(),
 ArrayRef{Op0, Op1}, nullptr, "hlsl.step");
   }
+  case Builtin::BI__builtin_hlsl_wave_active_sum: {
+// Due to the use of variadic arguments, explicitly retreive argument
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType()}, false);
+Intrinsic::ID IID = getWaveActiveSumIntrinsic(
+getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
+E->getArg(0)->getType());
+
+// Get overloaded name
+std::string Name =
+Intrinsic::getName(IID, ArrayRef{OpExpr->getType()}, &CGM.getModule());
+

[clang] [llvm] [RISCV] Inline Assembly Support for GPR Pairs ('Pr') (PR #112983)

2024-10-18 Thread Craig Topper via cfe-commits

topperc wrote:

Is the plan to make i128 a legal type for RV64?

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


[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/112081

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/2] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/2] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

  1   2   3   4   5   >