[clang] [clang][Interp] Implement __builtin_addressof (PR #77303)

2024-01-11 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] e3993e0 - [clang][Interp] Implement __builtin_addressof (#77303)

2024-01-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-01-11T09:02:24+01:00
New Revision: e3993e044ec5925e59c131f798f823a9f16f0433

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

LOG: [clang][Interp] Implement __builtin_addressof (#77303)

We don't need to do anything here, since the input is already a Pointer.
The only complexity is that we pre-classify the parameters as PT_Ptr,
but they might end up being of a different pointer type, e.g. PT_FnPtr.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 21ea2503b94bff..9de0926b9dba9c 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -134,6 +134,18 @@ void cleanupAfterFunctionCall(InterpState &S, CodePtr 
OpPC) {
   if (CurFunc->isUnevaluatedBuiltin())
 return;
 
+  // Some builtin functions require us to only look at the call site, since
+  // the classified parameter types do not match.
+  if (CurFunc->isBuiltin()) {
+const auto *CE =
+cast(S.Current->Caller->getExpr(S.Current->getRetPC()));
+for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+  const Expr *A = CE->getArg(I);
+  popArg(S, A);
+}
+return;
+  }
+
   if (S.Current->Caller && CurFunc->isVariadic()) {
 // CallExpr we're look for is at the return PC of the current function, 
i.e.
 // in the caller.

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b55b1569a25983..754ca96b0c645e 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -164,6 +164,8 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, 
APValue &Result,
   case X:  
\
 return Ret(S, OpPC, Result);
   switch (*T) {
+RET_CASE(PT_Ptr);
+RET_CASE(PT_FnPtr);
 RET_CASE(PT_Float);
 RET_CASE(PT_Bool);
 RET_CASE(PT_Sint8);
@@ -613,15 +615,34 @@ static bool interp__builtin_ffs(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
+  const InterpFrame *Frame,
+  const Function *Func,
+  const CallExpr *Call) {
+  PrimType PtrT =
+  S.getContext().classify(Call->getArg(0)->getType()).value_or(PT_Ptr);
+
+  if (PtrT == PT_FnPtr) {
+const FunctionPointer &Arg = S.Stk.peek();
+S.Stk.push(Arg);
+  } else if (PtrT == PT_Ptr) {
+const Pointer &Arg = S.Stk.peek();
+S.Stk.push(Arg);
+  } else {
+assert(false && "Unsupported pointer type passed to 
__builtin_addressof()");
+  }
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
-  QualType ReturnType = Call->getCallReturnType(S.getCtx());
-  std::optional ReturnT = S.getContext().classify(ReturnType);
+  std::optional ReturnT = S.getContext().classify(Call->getType());
+
   // If classify failed, we assume void.
-  assert(ReturnT || ReturnType->isVoidType());
+  assert(ReturnT || Call->getType()->isVoidType());
 
   switch (F->getBuiltinID()) {
   case Builtin::BI__builtin_is_constant_evaluated:
@@ -820,6 +841,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 if (!interp__builtin_ffs(S, OpPC, Frame, F, Call))
   return false;
 break;
+  case Builtin::BIaddressof:
+  case Builtin::BI__addressof:
+  case Builtin::BI__builtin_addressof:
+if (!interp__builtin_addressof(S, OpPC, Frame, F, Call))
+  return false;
+break;
 
   default:
 return false;

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 179a195098b132..75f3c5d192b2cf 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -389,3 +389,27 @@ namespace Packs {
   static_assert(foo() == 2, "");
   static_assert(foo<>() == 0, "");
 }
+
+namespace AddressOf {
+  struct S {} s;
+  static_assert(__builtin_addressof(s) == &s, "");
+
+  struct T { constexpr T *operator&() const { return nullptr; } int n; } t;
+  constexpr T *pt = __builtin_addressof(t);
+  static_assert(&pt->n == &t.n, "");
+
+  struct U { int n : 5; } u;
+  int *pbf = __builtin_addressof(u.n); // expected-error {{address of 
bit-field requested}} \
+   // ref-error {{address of bit-field 
requested}}
+
+  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address 
of a temporary}} \
+ 

[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/77458

>From 53993a1f1eaf0f6dc336d45a94b8638c4119ba2e Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 9 Jan 2024 19:42:10 +0700
Subject: [PATCH 1/7] [RISCV] Add support for new unprivileged extensions
 defined in profiles spec

This adds minimal support for 7 new extensions that were defined as a part of
the RISC-V Profiles specification here:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#7-new-isa-extensions

As stated in the specification, these extensions don't add any new features but
describe existing features. So this patch only adds parsing and subtarget
features.
---
 llvm/lib/Support/RISCVISAInfo.cpp  |  7 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td | 26 ++
 llvm/test/CodeGen/RISCV/attributes.ll  | 14 ++
 3 files changed, 47 insertions(+)

diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 70f531e40b90e6..c5c8f86a72d9d7 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -93,6 +93,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"xtheadvdot", RISCVExtensionVersion{1, 0}},
 {"xventanacondops", RISCVExtensionVersion{1, 0}},
 
+{"za128rs", RISCVExtensionVersion{1, 0}},
+{"za64rs", RISCVExtensionVersion{1, 0}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 
 {"zba", RISCVExtensionVersion{1, 0}},
@@ -121,9 +123,14 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 {"zhinx", RISCVExtensionVersion{1, 0}},
 {"zhinxmin", RISCVExtensionVersion{1, 0}},
 
+{"zic64b", RISCVExtensionVersion{1, 0}},
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicbop", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
+{"ziccamoa", RISCVExtensionVersion{1, 0}},
+{"ziccif", RISCVExtensionVersion{1, 0}},
+{"zicclsm", RISCVExtensionVersion{1, 0}},
+{"ziccrse", RISCVExtensionVersion{1, 0}},
 {"zicntr", RISCVExtensionVersion{2, 0}},
 {"zicsr", RISCVExtensionVersion{2, 0}},
 {"zifencei", RISCVExtensionVersion{2, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index bb7a3291085d43..17ed2a3aa2c57c 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -86,6 +86,22 @@ def HasStdExtZifencei : 
Predicate<"Subtarget->hasStdExtZifencei()">,
AssemblerPredicate<(all_of 
FeatureStdExtZifencei),
"'Zifencei' (fence.i)">;
 
+def FeatureStdExtZiccamoa
+: SubtargetFeature<"ziccamoa", "HasStdExtZiccamoa", "true",
+   "'Ziccamoa' (Main Memory Supports All Atomics in A)">;
+
+def FeatureStdExtZiccif
+: SubtargetFeature<"ziccif", "HasStdExtZiccif", "true",
+   "'Ziccif' (Main Memory Supports Instruction Fetch with 
Atomicity Requirement)">;
+
+def FeatureStdExtZicclsm
+: SubtargetFeature<"zicclsm", "HasStdExtZicclsm", "true",
+   "'Zicclsm' (Main Memory Supports Misaligned 
Loads/Stores)">;
+
+def FeatureStdExtZiccrse
+: SubtargetFeature<"ziccrse", "HasStdExtZiccrse", "true",
+   "'Ziccrse' (Main Memory Supports Forward Progress on 
LR/SC Sequences)">;
+
 def FeatureStdExtZicntr
 : SubtargetFeature<"zicntr", "HasStdExtZicntr", "true",
"'Zicntr' (Base Counters and Timers)",
@@ -510,6 +526,10 @@ def HasStdExtZfhOrZvfh
"'Zfh' (Half-Precision Floating-Point) or "
"'Zvfh' (Vector Half-Precision 
Floating-Point)">;
 
+def FeatureStdExtZic64b
+: SubtargetFeature<"zic64b", "HasStdExtZic64b", "true",
+   "'Zic64b' (Cache Block Size Is 64 Bytes)">;
+
 def FeatureStdExtZicbom
 : SubtargetFeature<"zicbom", "HasStdExtZicbom", "true",
"'Zicbom' (Cache-Block Management Instructions)">;
@@ -554,6 +574,12 @@ def HasStdExtZtso : 
Predicate<"Subtarget->hasStdExtZtso()">,
   "'Ztso' (Memory Model - Total Store Order)">;
 def NotHasStdExtZtso : Predicate<"!Subtarget->hasStdExtZtso()">;
 
+def FeatureStdExtZa164rs : SubtargetFeature<"za64rs", "HasStdExtZa64rs", 
"true",
+"'Za64rs' (Reservation Set Size of 
at Most 64 Bytes)">;
+
+def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
+"'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
+
 def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true",
   "'Zawrs' (Wait on Reservation Set)">;
 def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 9a6e78c09ad8c3..83

[clang] 79889fe - [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (#77645)

2024-01-11 Thread via cfe-commits

Author: Luke Lau
Date: 2024-01-11T15:07:24+07:00
New Revision: 79889fedc57707e99740abc1f48e6c5601d5a3f3

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

LOG: [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (#77645)

We have two structs for representing the version of an extension in
RISCVISAInfo, RISCVExtensionInfo and RISCVExtensionVersion, both
with the exact same fields. This patch deduplicates them.

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
lld/ELF/Arch/RISCV.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Support/RISCVISAInfo.cpp
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..fb312b6cf26e02 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -163,9 +163,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 auto ExtName = Extension.first;
 auto ExtInfo = Extension.second;
 
-Builder.defineMacro(
-Twine("__riscv_", ExtName),
-Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
+Builder.defineMacro(Twine("__riscv_", ExtName),
+Twine(getVersionValue(ExtInfo.Major, ExtInfo.Minor)));
   }
 
   if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))

diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 62498ded1a2b16..8906de07373547 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -957,8 +957,8 @@ static void mergeArch(RISCVISAInfo::OrderedExtensionMap 
&mergedExts,
   } else {
 for (const auto &ext : info.getExtensions()) {
   if (auto it = mergedExts.find(ext.first); it != mergedExts.end()) {
-if (std::tie(it->second.MajorVersion, it->second.MinorVersion) >=
-std::tie(ext.second.MajorVersion, ext.second.MinorVersion))
+if (std::tie(it->second.Major, it->second.Minor) >=
+std::tie(ext.second.Major, ext.second.Minor))
   continue;
   }
   mergedExts[ext.first] = ext.second;

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 97f1051b0540a7..46df93d7522602 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -18,11 +18,6 @@
 #include 
 
 namespace llvm {
-struct RISCVExtensionInfo {
-  unsigned MajorVersion;
-  unsigned MinorVersion;
-};
-
 void riscvExtensionsHelp(StringMap DescMap);
 
 class RISCVISAInfo {
@@ -30,6 +25,12 @@ class RISCVISAInfo {
   RISCVISAInfo(const RISCVISAInfo &) = delete;
   RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
 
+  /// Represents the major and version number components of a RISC-V extension.
+  struct ExtensionVersion {
+unsigned Major;
+unsigned Minor;
+  };
+
   static bool compareExtension(const std::string &LHS, const std::string &RHS);
 
   /// Helper class for OrderedExtensionMap.
@@ -41,7 +42,7 @@ class RISCVISAInfo {
 
   /// OrderedExtensionMap is std::map, it's specialized to keep entries
   /// in canonical order of extension.
-  typedef std::map
+  typedef std::map
   OrderedExtensionMap;
 
   RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
@@ -104,8 +105,7 @@ class RISCVISAInfo {
 
   OrderedExtensionMap Exts;
 
-  void addExtension(StringRef ExtName, unsigned MajorVersion,
-unsigned MinorVersion);
+  void addExtension(StringRef ExtName, ExtensionVersion Version);
 
   Error checkDependency();
 

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 70f531e40b90e6..390d950486a795 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -24,16 +24,11 @@
 using namespace llvm;
 
 namespace {
-/// Represents the major and version number components of a RISC-V extension
-struct RISCVExtensionVersion {
-  unsigned Major;
-  unsigned Minor;
-};
 
 struct RISCVSupportedExtension {
   const char *Name;
   /// Supported version.
-  RISCVExtensionVersion Version;
+  RISCVISAInfo::ExtensionVersion Version;
 
   bool operator<(const RISCVSupportedExtension &RHS) const {
 return StringRef(Name) < StringRef(RHS.Name);
@@ -50,161 +45,161 @@ static const char *RISCVGImplications[] = {
 
 // NOTE: This table should be sorted alphabetically by extension name.
 static const RISCVSupportedExtension SupportedExtensions[] = {
-{"a", RISCVExtensionVersion{2, 1}},
-{"c", RISCVExtensionVersion{2, 0}},
-{"d", RISCVExtensionVersion{2, 2}},
-{"e", RISCVExtensionVersion{2, 0}},
-{"f", RISCVExtensionVersion{2, 2}},
-{"h", RISCVExtensionVersion{1, 0}},
-{"i", RISCVExtensionVersion{2, 1}},
-{"m", RISCVExtensionVersion{2

[lld] [clang] [llvm] [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (PR #77645)

2024-01-11 Thread Luke Lau via cfe-commits

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


[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/77458

>From 8de2b22ba2723fccf16ca4d2a863f84fd1b66493 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 9 Jan 2024 19:42:10 +0700
Subject: [PATCH 1/7] [RISCV] Add support for new unprivileged extensions
 defined in profiles spec

This adds minimal support for 7 new extensions that were defined as a part of
the RISC-V Profiles specification here:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#7-new-isa-extensions

As stated in the specification, these extensions don't add any new features but
describe existing features. So this patch only adds parsing and subtarget
features.
---
 llvm/lib/Support/RISCVISAInfo.cpp  |  7 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td | 26 ++
 llvm/test/CodeGen/RISCV/attributes.ll  | 14 ++
 3 files changed, 47 insertions(+)

diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 390d950486a795..bac7fa1b8f07da 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -88,6 +88,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"xtheadvdot", {1, 0}},
 {"xventanacondops", {1, 0}},
 
+{"za128rs", {1, 0}},
+{"za64rs", {1, 0}},
 {"zawrs", {1, 0}},
 
 {"zba", {1, 0}},
@@ -116,9 +118,14 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 {"zhinx", {1, 0}},
 {"zhinxmin", {1, 0}},
 
+{"zic64b", {1, 0}},
 {"zicbom", {1, 0}},
 {"zicbop", {1, 0}},
 {"zicboz", {1, 0}},
+{"ziccamoa", {1, 0}},
+{"ziccif", {1, 0}},
+{"zicclsm", {1, 0}},
+{"ziccrse", {1, 0}},
 {"zicntr", {2, 0}},
 {"zicsr", {2, 0}},
 {"zifencei", {2, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 279509575bb52a..1d34fb2c4b5cf6 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -86,6 +86,22 @@ def HasStdExtZifencei : 
Predicate<"Subtarget->hasStdExtZifencei()">,
AssemblerPredicate<(all_of 
FeatureStdExtZifencei),
"'Zifencei' (fence.i)">;
 
+def FeatureStdExtZiccamoa
+: SubtargetFeature<"ziccamoa", "HasStdExtZiccamoa", "true",
+   "'Ziccamoa' (Main Memory Supports All Atomics in A)">;
+
+def FeatureStdExtZiccif
+: SubtargetFeature<"ziccif", "HasStdExtZiccif", "true",
+   "'Ziccif' (Main Memory Supports Instruction Fetch with 
Atomicity Requirement)">;
+
+def FeatureStdExtZicclsm
+: SubtargetFeature<"zicclsm", "HasStdExtZicclsm", "true",
+   "'Zicclsm' (Main Memory Supports Misaligned 
Loads/Stores)">;
+
+def FeatureStdExtZiccrse
+: SubtargetFeature<"ziccrse", "HasStdExtZiccrse", "true",
+   "'Ziccrse' (Main Memory Supports Forward Progress on 
LR/SC Sequences)">;
+
 def FeatureStdExtZicntr
 : SubtargetFeature<"zicntr", "HasStdExtZicntr", "true",
"'Zicntr' (Base Counters and Timers)",
@@ -510,6 +526,10 @@ def HasStdExtZfhOrZvfh
"'Zfh' (Half-Precision Floating-Point) or "
"'Zvfh' (Vector Half-Precision 
Floating-Point)">;
 
+def FeatureStdExtZic64b
+: SubtargetFeature<"zic64b", "HasStdExtZic64b", "true",
+   "'Zic64b' (Cache Block Size Is 64 Bytes)">;
+
 def FeatureStdExtZicbom
 : SubtargetFeature<"zicbom", "HasStdExtZicbom", "true",
"'Zicbom' (Cache-Block Management Instructions)">;
@@ -554,6 +574,12 @@ def HasStdExtZtso : 
Predicate<"Subtarget->hasStdExtZtso()">,
   "'Ztso' (Memory Model - Total Store Order)">;
 def NotHasStdExtZtso : Predicate<"!Subtarget->hasStdExtZtso()">;
 
+def FeatureStdExtZa164rs : SubtargetFeature<"za64rs", "HasStdExtZa64rs", 
"true",
+"'Za64rs' (Reservation Set Size of 
at Most 64 Bytes)">;
+
+def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
+"'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
+
 def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true",
   "'Zawrs' (Wait on Reservation Set)">;
 def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 9a6e78c09ad8c3..8373ead932a695 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -130,6 +130,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zkn,+zkr,+zkt %s -o - | FileCheck 
--check-prefixes=CHECK,RV64COMBINEINTOZK %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb,+zbkc,+zbkx,+zkne,+zknd,+zknh %s -o - 
| FileCheck --check-prefixes=CHECK,RV64COMBINEINTOZKN %s
 ; RUN: llc -mtri

[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

lukel97 wrote:

Rebased on top of 79889fedc57707e99740abc1f48e6c5601d5a3f3

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


[clang] [clang-format] Add SpaceInParensOption for __attribute__ keyword (PR #77522)

2024-01-11 Thread Owen Pan via cfe-commits

owenca wrote:

> The __attribute((specifier-list)) currently is formatted based on the 
> SpacesInParensOptions.Other (previously, SpacesInParentheses). This change 
> allows finer control over addition of spaces between the consecutive parens, 
> and between the inner parens and the list of attribute specifiers.
> 
> Differential Revision: https://reviews.llvm.org/D155529
> 
> This is migrated from Phabricator, see more discussion there.

I expressed my opinion there:

> I would have no problem if this new option is extended to handle all double 
> parens, e.g. if (( i = j )), decltype(( x )), etc.

So I still prefer that we have a boolean suboption (e.g. 
`ConsecutiveParentheses`) that covers all double parens.

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


[llvm] [clang] [Clang][RISCV] Move getVScaleRange logic into libLLVMFrontendDriver. NFC (PR #77327)

2024-01-11 Thread Luke Lau via cfe-commits

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


[clang] [llvm] [Clang][RISCV] Move getVScaleRange logic into libLLVMFrontendDriver. NFC (PR #77327)

2024-01-11 Thread Luke Lau via cfe-commits

lukel97 wrote:

Closing for now as deduplication the clang/flang frontend logic most likely 
requires more thought and discussion

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


[clang] [Clang] Set writable and dead_on_unwind attributes on sret arguments (PR #77116)

2024-01-11 Thread Nikita Popov via cfe-commits

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77727

>From cdc04d0b5b934c4dc4c8294dd000539275bf4222 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 3 files changed, 17 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..1006e7d65dd868 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA;
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[lldb] [openmp] [clang] [clang-tools-extra] [lld] [libunwind] [mlir] [llvm] [flang] [compiler-rt] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread Phoebe Wang via cfe-commits


@@ -1363,6 +1363,14 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
   }
+  // Add rest successors of MBB to successors of FallThrough. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE; ++SI)
+if (*SI != &*FallThrough && !FallThrough->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  FallThrough->copySuccessor(MBB, SI);
+}

phoebewang wrote:

This doesn't answer the questions. My questions are:

- Why can't put the code in `ReplaceUsesOfBlockWith`? The `isSuccessor` can 
make sure the same BB won't add again;
- Is it possible the added BB might be removed latter. We don't have a 
mechanism to remove the dead successors. Would it be a problem if we keep an 
edge to dead BBs?

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77727

>From 75e9a81a5aa4042197201450fa676b8036a3d2cd Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/docs/HLSL/FunctionCalls.rst| 2 +-
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 4 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/docs/HLSL/FunctionCalls.rst 
b/clang/docs/HLSL/FunctionCalls.rst
index 996ddd6944b1ce..7317de2163f897 100644
--- a/clang/docs/HLSL/FunctionCalls.rst
+++ b/clang/docs/HLSL/FunctionCalls.rst
@@ -144,7 +144,7 @@ undefined behavior in HLSL, and any use of the argument 
after the call is a use
 of an undefined value which may be illegal in the target (DXIL programs with
 used or potentially used ``undef`` or ``poison`` values fail validation).
 
-Clang Implementation 
+Clang Implementation
 
 
 .. note::
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..1006e7d65dd868 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA;
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits


@@ -324,6 +343,60 @@ void error_fseek_0(void) {
   fclose(F);
 }
 
+void error_fseeko_0(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseeko(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get ferror or no error, but not feof.
+clang_analyzer_eval(IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof);
+// expected-warning@-1 {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
+
+void error_ftell(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  long rc = ftell(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_feof_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
+  StreamTesterChecker_make_ferror_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{TRUE}}
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  long rc = ftello(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}

balazske wrote:

To be exact, this test should be a copy of the previous test, only with 
`ftello` (and use of `off_t`).

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits


@@ -268,8 +268,12 @@ class StreamChecker : public Checkerhttps://github.com/llvm/llvm-project/pull/77580
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Handle lambda scopes inside Node::getDeclContext() (PR #76329)

2024-01-11 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

The CI failure on windows seems irrelevant, so I'm landing it anyway.

```
FAILED: tools/clang/tools/extra/clangd/CompletionModel.h 
tools/clang/tools/extra/clangd/CompletionModel.cpp
cmd.exe /C "cd /D C:\ws\src\build\tools\clang\tools\extra\clangd && 
C:\Python39\python.exe 
C:/ws/src/clang-tools-extra/clangd/quality/CompletionModelCodegen.py --model 
C:/ws/src/clang-tools-extra/clangd/quality/model --output_dir 
C:/ws/src/build/tools/clang/tools/extra/clangd --filename CompletionModel 
--cpp_class clang::clangd::Example"
C:\Python39\python.exe: can't open file 
'C:\ws\src\clang-tools-extra\clangd\quality\CompletionModelCodegen.py': [Errno 
22] Invalid argument
```

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


[clang-tools-extra] 9ef2ac3 - [clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)

2024-01-11 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-01-11T16:59:18+08:00
New Revision: 9ef2ac3ad1bd5aa9e589f63047e8abeac11ad1b2

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

LOG: [clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)

We used to consider the `DeclContext` for selection nodes inside a
lambda as the enclosing scope of the lambda expression, rather than the
lambda itself.

For example,

```cpp
void foo();
auto lambda = [] {
  return ^foo();
};
```

where `N` is the selection node for the expression `foo()`,
`N.getDeclContext()` returns the `TranslationUnitDecl` previously, which
IMO is wrong, since the method `operator()` of the lambda is closer.

Incidentally, this fixes a glitch in add-using-declaration tweaks.
(Thanks @HighCommander4 for the test case.)

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 8c6d5750ecefdb..277cb8769a1b12 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -1113,6 +1113,9 @@ const DeclContext &SelectionTree::Node::getDeclContext() 
const {
   return *DC;
   return *Current->getLexicalDeclContext();
 }
+if (const auto *LE = CurrentNode->ASTNode.get())
+  if (CurrentNode != this)
+return *LE->getCallOperator();
   }
   llvm_unreachable("A tree must always be rooted at TranslationUnitDecl.");
 }

diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 4c019a1524f3c3..754e8c287c5148 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -880,6 +880,19 @@ TEST(SelectionTest, DeclContextIsLexical) {
   }
 }
 
+TEST(SelectionTest, DeclContextLambda) {
+  llvm::Annotations Test(R"cpp(
+void foo();
+auto lambda = [] {
+  return $1^foo();
+};
+  )cpp");
+  auto AST = TestTU::withCode(Test.code()).build();
+  auto ST = SelectionTree::createRight(AST.getASTContext(), AST.getTokens(),
+   Test.point("1"), Test.point("1"));
+  EXPECT_TRUE(ST.commonAncestor()->getDeclContext().isFunctionOrMethod());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
index 1fd2487378d705..c2dd8e1bb8eefa 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -309,6 +309,29 @@ namespace foo { void fun(); }
 void foo::fun() {
   ff();
 })cpp"},
+  // Inside a lambda.
+  {
+  R"cpp(
+namespace NS {
+void unrelated();
+void foo();
+}
+
+auto L = [] {
+  using NS::unrelated;
+  NS::f^oo();
+};)cpp",
+  R"cpp(
+namespace NS {
+void unrelated();
+void foo();
+}
+
+auto L = [] {
+  using NS::foo;using NS::unrelated;
+  foo();
+};)cpp",
+  },
   // If all other using are fully qualified, add ::
   {R"cpp(
 #include "test.hpp"



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


[clang-tools-extra] [clangd] Handle lambda scopes inside Node::getDeclContext() (PR #76329)

2024-01-11 Thread Younan Zhang via cfe-commits

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


[compiler-rt] [flang] [openmp] [clang-tools-extra] [mlir] [clang] [lldb] [llvm] [lld] [libunwind] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread Phoebe Wang via cfe-commits


@@ -1624,6 +1632,15 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 } else {
   DidChange = true;
   PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
+  // Add rest successors of MBB to successors of CurTBB. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE;
+   ++SI)
+if (*SI != CurTBB && !CurTBB->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  CurTBB->copySuccessor(MBB, SI);

phoebewang wrote:

I see we assert for `(*SI)->isEHPad()`, but `bb.6` is not a EHPad. Did I 
misunderstand something here?
BTW, can we use `SI->isEHPad()` directly?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-11 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 50fd47f2bfda527807f8cc5e46425050246868aa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/3] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 728 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(A

[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-11 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Update: 

Previously we will always try to load the specializations with the
corresponding arguments before finding the specializations. This
requires to hash the template arguments.

This patch tries to improve this by trying to load the specializations
only if we can't find it locally.

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-11 Thread Nemanja Ivanovic via cfe-commits


@@ -985,9 +1003,10 @@ void 
RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
 };
 
 for (auto Reg : CSRegs)
-  SavedRegs.set(Reg);
+  if (Reg < RISCV::X16 || !Subtarget.isRVE())

nemanjai wrote:

Sounds good. Maybe just a little comment here to demonstrate to the user that 
this isn't an omission but a conscious decision.

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-11 Thread Nemanja Ivanovic via cfe-commits

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

My comments have been addressed, so this LGTM. I'll of course defer to @asb and 
@topperc for final approval.

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


[clang] [clang][Interp] Implement IntegralAP::{div, rem} (PR #72614)

2024-01-11 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/77580

>From cb79cad6837dba5d33476c65923ec714507a3fef Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 10 Jan 2024 19:00:27 +0800
Subject: [PATCH 1/5] [clang][analyzer] Support 'tello' and 'fseeko' in the
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  4 +
 .../Analysis/Inputs/system-header-simulator.h |  3 +
 clang/test/Analysis/stream-error.c| 82 +++
 3 files changed, 89 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index fbfa101257d5e1..f6e6f3122f3aa7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -268,8 +268,12 @@ class StreamChecker : public Checker= 0)) {
+clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  off_t Ret = ftello(F);
+  if (!(Ret == -1)) {
+clang_analyzer_eval(Ret >= 0);   // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
 void error_fflush_after_fclose(void) {
   FILE *F = tmpfile();
   int Ret;

>From ac08796261b3970d9a99c4ac6a2c0e7331620944 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Thu, 11 Jan 2024 09:44:08 +0800
Subject: [PATCH 2/5] [clang][analyzer] Support 'tello' and 'fseeko' in the
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 10 ++---
 clang/test/Analysis/stream-error.c| 39 ++-
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index f6e6f3122f3aa7..742426a628e065 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1117,10 +1117,10 @@ void StreamChecker::evalFtell(const FnDescription 
*Desc, const CallEvent &Call,
   NonLoc RetVal = makeRetVal(C, CE).castAs();
   ProgramStateRef StateNotFailed =
   State->BindExpr(CE, C.getLocationContext(), RetVal);
-  auto Cond = SVB.evalBinOp(State, BO_GE, RetVal,
-SVB.makeZeroVal(C.getASTContext().LongTy),
-SVB.getConditionType())
-  .getAs();
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, 
SVB.makeZeroVal(Call.getResultType()),
+SVB.getConditionType())
+  .getAs();
   if (!Cond)
 return;
   StateNotFailed = StateNotFailed->assume(*Cond, true);
@@ -1128,7 +1128,7 @@ void StreamChecker::evalFtell(const FnDescription *Desc, 
const CallEvent &Call,
 return;
 
   ProgramStateRef StateFailed = State->BindExpr(
-  CE, C.getLocationContext(), SVB.makeIntVal(-1, 
C.getASTContext().LongTy));
+  CE, C.getLocationContext(), SVB.makeIntVal(-1, Call.getResultType()));
 
   // This function does not affect the stream state.
   // Still we add success and failure state with the appropriate return value.
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 1b14fc2eee2003..5cd6ef4bb7424d 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -348,9 +348,6 @@ void error_fseek_0(void) {
   } else {
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
-// Error flags should not change.
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   }
   fclose(F);
 }
@@ -368,12 +365,6 @@ void error_fseeko_0(void) {
 // expected-warning@-2 {{TRUE}}
 clang_analyzer_eval(IsFEof);
 // expected-warning@-1 {{FALSE}}
-// Error flags should not change.
-clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
-if (IsFError)
-  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   } else {
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
@@ -388,21 +379,33 @@ void error_ftell(void) {
   FILE *F = fopen("file", "r");
   if (!F)
 return;
-  long Ret = ftell(F);
-  if (!(Ret >= 0)) {
-clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
-  }
+  long rc = ftell(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_feof_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
+ 

[clang] [llvm] [clang][Driver] Don't ignore -gmodules .gch files (PR #77711)

2024-01-11 Thread via cfe-commits

zmodem wrote:

Thanks for looking into this. I wasn't aware of `-gmodules` relying on "gch 
probing" when I wrote the previous patch.

It seems unfortunate to make `maybeHasClangPchSignature` so broad as to return 
true for any file format that we recognize. Would it be possible to at least 
tighten it to only consider the kind of object files which could have a 
clangast section? Or is that list too long? What does the code that reads these 
files look like, could we leverage that somehow?

An alternative would be turn the logic around, and only ignore GCC PCH files (I 
believe they all start with the file magic `gpch`). However I do think that the 
current approach of "whitelisting" the kind of file we're looking for is better.

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


[clang] 9d97247 - [clang] Fix color consistency in C paper tracking web page

2024-01-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-11T10:23:37+01:00
New Revision: 9d97247e26eaca29bf27c842e08bd983a34fab93

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

LOG: [clang] Fix color consistency in C paper tracking web page

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index fe56bc791ccbe1..b9e0650ddca242 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -9,7 +9,7 @@
 .none { background-color: #FF }
 .partial { background-color: #FFE0B0 }
 .unreleased { background-color: #99 }
-.unknown { background-color: #DDAEF7 }
+.unknown { background-color: #EBCAFE }
 .full { background-color: #CCFF99 }
 .na { background-color: #DD }
 :target { background-color: #BB; outline: #55 solid thin; }



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


[lld] [clang] [clang-tools-extra] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-11 Thread Clement Courbet via cfe-commits


@@ -112,9 +116,11 @@ class Counter {
   PerfEvent Event;
   int FileDescriptor = -1;
   bool IsDummyEvent;
+  std::vector ValidationEvents;

legrosbuffle wrote:

OK, let's rename `Counter` to `CounterGroup`, but let's at least create a 
(private) abstraction for an event and attached FD, to avoid the aligned arrays 
code duplication in `Counter::initRealEvent`:

```
  struct ConfiguredEvent {
llvm::Error init(const pid_t ProcessID, const int GroupFd) {
  constexpr  int Cpu = -1; // measure any processor.
  constexpr int GroupFd = -1; // no grouping of counters.
  constexpr uint32_t Flags = 0;
  perf_event_attr AttrCopy = *Event.attribute();
  FileDescriptor = perf_event_open(&AttrCopy, ProcessID, Cpu, GroupFd, 
Flags);
  if (FileDescriptor == -1) {
return ...;
  }
};
PerfEvent Event;
int FileDescriptor = -1;
  };
  // The main event, configured as an ungrouped event.
  ConfiguredEvent MainEvent;
  bool IsDummyEvent;
  // A set of optional validation events grouped into the file descriptor for
  // `MainEvent` using `PERF_IOC_FLAG_GROUP`.
  std::vector ValidationEvents;
```

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


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-11 Thread James Henderson via cfe-commits

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


[llvm] [clang] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-11 Thread James Henderson via cfe-commits

https://github.com/jh7370 commented:

Sorry, I'm a bit snowed under with reviews. I'm happy to defer to others on 
this patch.

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


[clang-tools-extra] [llvm] [clang] [clang] Add test for CWG472 (PR #67948)

2024-01-11 Thread via cfe-commits

cor3ntin wrote:

After additional archeology, I found the following minutes from Portland , 2012

> Core issue 472: Casting across protected inheritance
> _ Would the example work if P2 derived privately from N2?
> _ ... Yes.. Hm, that was a good point.
> redrafting.


Given that, I'd rather we don't try to read the tea leaves.
If we think this is important enough to fix, we should ping CWG.
But there seems to be some consistency across implementations, so I think we 
should punt work on this issue.

@zygoloid 


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


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-11 Thread James Henderson via cfe-commits


@@ -1419,32 +1419,50 @@ void ELFState::writeSectionContent(
   CBA.write(E.Feature);
   SHeader.sh_size += 2;
 }
-
-if (Section.PGOAnalyses) {
-  if (E.Version < 2)
-WithColor::warning()
-<< "unsupported SHT_LLVM_BB_ADDR_MAP version when using PGO: "
-<< static_cast(E.Version) << "; must use version >= 2";
+auto FeatureOrErr = llvm::object::BBAddrMap::Features::decode(E.Feature);
+bool MultiBBRangeFeatureEnabled = false;
+if (!FeatureOrErr)
+  WithColor::warning() << toString(FeatureOrErr.takeError());
+else
+  MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
+bool MultiBBRange =
+MultiBBRangeFeatureEnabled ||
+(E.NumBBRanges.has_value() && E.NumBBRanges.value() > 1) ||
+(E.BBRanges && E.BBRanges->size() > 1);
+if (MultiBBRange && !MultiBBRangeFeatureEnabled)
+  WithColor::warning() << "Feature value(" << E.Feature

jh7370 wrote:

```suggestion
  WithColor::warning() << "feature value(" << E.Feature
```
Nit, per coding standards.

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-01-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

Ping. Lets pickup the discussion from before Christmas. Is the solution with 
the dummy warning (that @hazohelet wrote about in a previous comment) an 
acceptable solution?


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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-11 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 50fd47f2bfda527807f8cc5e46425050246868aa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/3] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 728 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(A

[llvm] [clang-tools-extra] [clang] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)

2024-01-11 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Build bot has been updated, and the RFC has no pushback. I will land this now.

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


[clang-tools-extra] [llvm] [clang] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)

2024-01-11 Thread Utkarsh Saxena via cfe-commits

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


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-11 Thread Wang Pengcheng via cfe-commits


@@ -985,9 +1003,10 @@ void 
RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
 };
 
 for (auto Reg : CSRegs)
-  SavedRegs.set(Reg);
+  if (Reg < RISCV::X16 || !Subtarget.isRVE())

wangpc-pp wrote:

Though it's nearly impossible to have such configuration in real application, I 
saved x15-x16 in 
https://github.com/llvm/llvm-project/pull/76777/commits/20ffba38548c823d6ef286bcad63385087438d57.

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


[clang] [clang-tools-extra] [libc] [llvm] [libc] Fix buggy AVX2 / AVX512 `memcmp` (PR #77081)

2024-01-11 Thread Guillaume Chatelet via cfe-commits

https://github.com/gchatelet updated 
https://github.com/llvm/llvm-project/pull/77081

>From fb8dbd55aacb3a25678b8092a11dd4e562857344 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Fri, 5 Jan 2024 11:01:30 +
Subject: [PATCH 1/6] [libc] Fix buggy AVX2 `memcmp`

Fixes 77080.
---
 libc/src/string/memory_utils/op_x86.h | 33 ++-
 libc/test/src/string/memcmp_test.cpp  |  7 ++
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/libc/src/string/memory_utils/op_x86.h 
b/libc/src/string/memory_utils/op_x86.h
index 1a20659c178cd1..23e6b897997e90 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -129,7 +129,8 @@ LIBC_INLINE __m128i bytewise_reverse(__m128i value) {
   8, 9, 10, 11, 12, 13, 14, 15));
 }
 LIBC_INLINE uint16_t big_endian_cmp_mask(__m128i max, __m128i value) {
-  return 
static_cast(_mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, 
value;
+  return static_cast(
+  _mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, value;
 }
 template <> LIBC_INLINE bool eq<__m128i>(CPtr p1, CPtr p2, size_t offset) {
   const auto a = load<__m128i>(p1, offset);
@@ -181,11 +182,31 @@ LIBC_INLINE __m256i bytewise_max(__m256i a, __m256i b) {
   return _mm256_max_epu8(a, b);
 }
 LIBC_INLINE __m256i bytewise_reverse(__m256i value) {
-  return _mm256_shuffle_epi8(value,
- _mm256_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, //
- 8, 9, 10, 11, 12, 13, 14, 15,   //
- 16, 17, 18, 19, 20, 21, 22, 23, //
- 24, 25, 26, 27, 28, 29, 30, 31));
+  const __m256i indices = _mm256_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, //
+  8, 9, 10, 11, 12, 13, 14, 15,   //
+  16, 17, 18, 19, 20, 21, 22, 23, //
+  24, 25, 26, 27, 28, 29, 30, 31);
+#if defined(__AVX512VBMI__) && defined(__AVX512VL__)
+  // AVX512 allows full __m256i byte permutation.
+  // ymm = ymm[31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,
+  //   15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+  return _mm256_permutexvar_epi8(value, indices);
+#else
+  // We can't byte-reverse __m256i in a single instruction with AVX2.
+  // '_mm256_shuffle_epi8' can only shuffle within each xmm lane
+  // leading to:
+  // ymm = ymm[15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
+  //   31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16]
+  const __m256i tmp = _mm256_shuffle_epi8(value, indices);
+  // Then we shuffle accross lanes using 64 bit values.
+  // ymm = ymm[2,3,0,1]
+  // Leading to a fully reversed vector
+  // ymm = ymm[31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,
+  //   15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+  // The immediate encodes the 64 bit word indices  :1, 0, 3, 2.
+  // Each index is encoded with 2 bits  : 0b01'00'11'10.
+  return _mm256_permute4x64_epi64(tmp, 0b01'00'11'10);
+#endif
 }
 LIBC_INLINE uint32_t big_endian_cmp_mask(__m256i max, __m256i value) {
   return _mm256_movemask_epi8(bytewise_reverse(_mm256_cmpeq_epi8(max, value)));
diff --git a/libc/test/src/string/memcmp_test.cpp 
b/libc/test/src/string/memcmp_test.cpp
index 03a0ac1c0ba655..a69257704a64a2 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -37,6 +37,13 @@ TEST(LlvmLibcMemcmpTest, LhsAfterRhsLexically) {
   EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 2), 0);
 }
 
+TEST(LlvmLibcMemcmpTest, Issue77080) {
+  // https://github.com/llvm/llvm-project/issues/77080
+  constexpr char lhs[35] = "1.069cd68bbe76eb2143a3284d27ebe220";
+  constexpr char rhs[35] = "1.0500185b5d966a544e2d0fa40701b0f3";
+  EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 0);
+}
+
 // Adapt CheckMemcmp signature to memcmp.
 static inline int Adaptor(cpp::span p1, cpp::span p2, size_t size) 
{
   return LIBC_NAMESPACE::memcmp(p1.begin(), p2.begin(), size);

>From 04891668ef388ed354d9a18969ada20d54371ce6 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet 
Date: Mon, 8 Jan 2024 08:51:12 +
Subject: [PATCH 2/6] Make test clearer

---
 libc/test/src/string/memcmp_test.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/string/memcmp_test.cpp 
b/libc/test/src/string/memcmp_test.cpp
index a69257704a64a2..ca7a5c7ce37023 100644
--- a/libc/test/src/string/memcmp_test.cpp
+++ b/libc/test/src/string/memcmp_test.cpp
@@ -41,7 +41,7 @@ TEST(LlvmLibcMemcmpTest, Issue77080) {
   // https://github.com/llvm/llvm-project/issues/77080
   constexpr char lhs[35] = "1.069cd68bbe76eb2143a3284d27ebe220";
   constexpr char rhs[35] = "1.0500185b5d966a544e2d0fa40701b0f3";
-  EXPECT_GT(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 0);
+  ASSERT_GE(LIBC_NAMESPACE::memcmp(lhs, rhs, 34), 1);
 }
 
 // Adapt C

[clang] [openmp] [llvm] [clang-tools-extra] Fix Issue #76121 [OpenMP] [Flang] Program crashes at runtime (PR #76122)

2024-01-11 Thread chandan singh via cfe-commits

https://github.com/chandankds updated 
https://github.com/llvm/llvm-project/pull/76122

>From 46b1085445209ac31600eccd863326b3d34b973e Mon Sep 17 00:00:00 2001
From: orequest 
Date: Wed, 20 Dec 2023 20:19:11 -0800
Subject: [PATCH] Fix Issue #76121 [OpenMP] [Flang] Program crashes at runtime
 with Segmentation fault when OMP PARALLEL DO IF(.false.) is encountered

---
 openmp/runtime/src/kmp_csupport.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openmp/runtime/src/kmp_csupport.cpp 
b/openmp/runtime/src/kmp_csupport.cpp
index 9eeaeb88fb9ec7..91a48ad393d703 100644
--- a/openmp/runtime/src/kmp_csupport.cpp
+++ b/openmp/runtime/src/kmp_csupport.cpp
@@ -368,7 +368,7 @@ void __kmpc_fork_call_if(ident_t *loc, kmp_int32 argc, 
kmpc_micro microtask,
   __kmp_invoke_microtask(VOLATILE_CAST(microtask_t) microtask, gtid,
  /*npr=*/0,
  /*argc=*/0,
- /*args=*/nullptr
+ /*args=*/&args
 #if OMPT_SUPPORT
  ,
  &exit_frame_ptr

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


[clang] 4b0314d - [clang][ASTImporter] Improve import of friend class templates. (#74627)

2024-01-11 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-01-11T11:18:11+01:00
New Revision: 4b0314d14f888cc1916556574ecaa35cc118ee00

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

LOG: [clang][ASTImporter] Improve import of friend class templates. (#74627)

A friend template that is in a dependent context is not linked into
declaration chains (for example with the definition of the befriended
template). This condition was not correctly handled by `ASTImporter`.

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 0540159f07e8a3..b762d6a4cd3800 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5929,15 +5929,22 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   if (ToD)
 return ToD;
 
-  bool IsFriendTemplate = D->getFriendObjectKind() != Decl::FOK_None;
-  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
-: DC->isDependentContext();
-  bool DependentFriend = IsFriendTemplate && IsDependentContext;
+  // Should check if a declaration is friend in a dependent context.
+  // Such templates are not linked together in a declaration chain.
+  // The ASTImporter strategy is to map existing forward declarations to
+  // imported ones only if strictly necessary, otherwise import these as new
+  // forward declarations. In case of the "dependent friend" declarations, new
+  // declarations are created, but not linked in a declaration chain.
+  auto IsDependentFriend = [](ClassTemplateDecl *TD) {
+return TD->getFriendObjectKind() != Decl::FOK_None &&
+   TD->getLexicalDeclContext()->isDependentContext();
+  };
+  bool DependentFriend = IsDependentFriend(D);
 
   ClassTemplateDecl *FoundByLookup = nullptr;
 
   // We may already have a template of the same name; try to find and match it.
-  if (!DependentFriend && !DC->isFunctionOrMethod()) {
+  if (!DC->isFunctionOrMethod()) {
 SmallVector ConflictingDecls;
 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
 for (auto *FoundDecl : FoundDecls) {
@@ -5953,10 +5960,13 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 
 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
 bool IgnoreTemplateParmDepth =
-FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
-!D->specializations().empty();
+(FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
+(D->getFriendObjectKind() != Decl::FOK_None);
 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
   IgnoreTemplateParmDepth)) {
+  if (DependentFriend || IsDependentFriend(FoundTemplate))
+continue;
+
   ClassTemplateDecl *TemplateWithDef =
   getTemplateDefinition(FoundTemplate);
   if (D->isThisDeclarationADefinition() && TemplateWithDef)

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index e4bd0d646cc9db..37cf14bdff6b33 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -4540,6 +4540,162 @@ TEST_P(ImportFriendClasses, 
ImportOfClassDefinitionAndFwdFriendShouldBeLinked) {
   EXPECT_EQ(ImportedFwd, ImportedDef->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses,
+   ImportFriendTemplatesInDependentContext_DefToFriend) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template
+  struct X {
+template
+friend struct Y;
+  };
+  )",
+  Lang_CXX03);
+  auto *ToYFriend = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("Y")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template
+  struct Y {};
+  )",
+  Lang_CXX03, "input0.cc");
+  auto *FromYDef = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("Y")));
+  auto *ImportedYDef = Import(FromYDef, Lang_CXX03);
+  EXPECT_TRUE(ImportedYDef);
+  EXPECT_FALSE(ImportedYDef->getPreviousDecl());
+  EXPECT_NE(ImportedYDef, ToYFriend);
+}
+
+TEST_P(ImportFriendClasses,
+   ImportFriendTemplatesInDependentContext_DefToFriend_NE) {
+  getToTuDecl(
+  R"(
+  template
+  struct X {
+template
+friend struct Y;
+  };
+  )",
+  Lang_CXX03);
+  Decl *FromTU = getTuDecl(
+  R"(
+  template
+  struct Y {};
+  )",
+  Lang_CXX03, "input0.cc");
+  auto *FromYDef = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("Y")));
+  auto *ImportedYDef = Import(FromYDef, Lang_CXX03);
+  EXPECT_FALSE(ImportedYDef);
+}
+
+TEST_P(ImportFriendClas

[clang] [clang][ASTImporter] Improve import of friend class templates. (PR #74627)

2024-01-11 Thread Balázs Kéri via cfe-commits

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits

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


[clang-tools-extra] [lldb] [clang] [llvm] [flang] [compiler-rt] [libunwind] [openmp] [mlir] [lld] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread via cfe-commits


@@ -1363,6 +1363,14 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
   }
+  // Add rest successors of MBB to successors of FallThrough. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE; ++SI)
+if (*SI != &*FallThrough && !FallThrough->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  FallThrough->copySuccessor(MBB, SI);
+}

HaohaiWen wrote:

> Why can't put the code in ReplaceUsesOfBlockWith? The isSuccessor can make 
> sure the same BB won't add again;

It's possible MBB don't have any predecessor. e.g. The function entry BB is 
invoke llvm.seh.scope.begin. In such case, we still need to add bb.4 as 
successor of bb.3 before removing MBB.
```
bb.2:
  successors: %bb.3(0x7800), %bb.4(0x0800); %bb.3(100.00%), %bb.4(0.00%)


bb.3:
; predecessors: %bb.2
  successors: %bb.6(0x8000); %bb.6(100.00%)

  JMP_1 %bb.6

bb.4 (machine-block-address-taken, landing-pad, ehfunclet-entry):
; predecessors: %bb.2
  successors: %bb.5(0x8000); %bb.5(100.00%)

  CLEANUPRET

bb.5 (landing-pad, ehfunclet-entry):
; predecessors: %bb.4

  CLEANUPRET

bb.6:
; predecessors: %bb.3

  RET 0

# End machine code for function main.
```

> Is it possible the added BB might be removed latter. We don't have a 
> mechanism to remove the dead successors. Would it be a problem if we keep an 
> edge to dead BBs?

No, addSuccessor(), removeSuccessor() will properly maintain predecessors. We 
don't need to care about that.

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


[compiler-rt] [mlir] [libunwind] [llvm] [flang] [lldb] [clang-tools-extra] [clang] [lld] [openmp] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread via cfe-commits


@@ -1624,6 +1632,15 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 } else {
   DidChange = true;
   PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
+  // Add rest successors of MBB to successors of CurTBB. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE;
+   ++SI)
+if (*SI != CurTBB && !CurTBB->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  CurTBB->copySuccessor(MBB, SI);

HaohaiWen wrote:

bb.6 is CurTBB so it will be skipped.
using pred_iterator = std::vector< MachineBasicBlock * >::iterator
Dereference pred_iterator get MachineBasicBlock *.


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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits

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


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


[libcxx] [clang] [llvm] [flang] [compiler-rt] [openmp] [mlir] [lld] [flang] include sys/wait.h for EXECUTE_COMMAND_LINE (PR #77675)

2024-01-11 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm approved this pull request.

Thanks for providing this fix!

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


[clang] [clang-tools-extra] [lldb] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-11 Thread via cfe-commits

cor3ntin wrote:

@bolshakov-a we are going to branch LLVM 23 in about 10 days. If you can update 
this by early next week, we will try to finish the review so that it can land 
in 18.

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


[clang] [clang]not lookup name containing a dependent type (PR #77587)

2024-01-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/77587

>From f6b9afa26fabb5f9dcea5615c92914bed93ef474 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 10 Jan 2024 19:27:31 +0800
Subject: [PATCH 1/2] [clang]not lookup name containing a dependent type

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template instantiation 
dependent name issues but still missing some cases
This patch want to enhance the dependent name check
---
 clang/lib/Sema/SemaExprMember.cpp  |  3 ++-
 clang/test/SemaCXX/conversion-function.cpp | 14 +++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 2abec3d86a27d9..32998ae60eafe2 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -782,7 +782,8 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
const Scope *S,
ActOnMemberAccessExtraArgs *ExtraArgs) {
   if (BaseType->isDependentType() ||
-  (SS.isSet() && isDependentScopeSpecifier(SS)))
+  (SS.isSet() && isDependentScopeSpecifier(SS)) ||
+  NameInfo.getName().isDependentName())
 return ActOnDependentMemberExpr(Base, BaseType,
 IsArrow, OpLoc,
 SS, TemplateKWLoc, FirstQualifierInScope,
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index b6e6142d179066..220ae78f2d8246 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,13 +475,21 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  template struct A {
+  struct A1 {
+operator int();
+  };
+  template struct C {
+template  using Lookup = decltype(T{}.operator U());
+  };
+  C v{};
+
+  template struct A2 {
 operator T();
   };
-  template struct B : A {
+  template struct B : A2 {
 template using Lookup = decltype(&B::operator U);
   };
   using Result = B::Lookup;
-  using Result = int (A::*)();
+  using Result = int (A2::*)();
 }
 #endif

>From e48e981d65502948972d091c612ee7a354abb3d0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 11 Jan 2024 18:39:31 +0800
Subject: [PATCH 2/2] add release note

---
 clang/docs/ReleaseNotes.rst|  4 ++-
 clang/test/SemaCXX/conversion-function.cpp | 33 +++---
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f8bbc89d8949..8e403530a19502 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -708,7 +708,9 @@ Bug Fixes in This Version
 - Clang now emits correct source location for code-coverage regions in `if 
constexpr`
   and `if consteval` branches.
   Fixes (`#54419 `_)
-
+- Fix an issue where clang cannot find conversion function with template
+  parameter when instantiation of template class.
+  Fixes (`#77583 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index 220ae78f2d8246..749e2fc1b452b6 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,21 +475,22 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  struct A1 {
-operator int();
-  };
-  template struct C {
-template  using Lookup = decltype(T{}.operator U());
-  };
-  C v{};
-
-  template struct A2 {
-operator T();
-  };
-  template struct B : A2 {
-template using Lookup = decltype(&B::operator U);
-  };
-  using Result = B::Lookup;
-  using Result = int (A2::*)();
+namespace gh77583 {
+struct A1 {
+  operator int();
+};
+template struct C {
+  template  using Lookup = decltype(T{}.operator U());
+};
+C v{};
+}
+template struct A2 {
+  operator T();
+};
+template struct B : A2 {
+  template using Lookup = decltype(&B::operator U);
+};
+using Result = B::Lookup;
+using Result = int (A2::*)();
 }
 #endif

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits

https://github.com/ckandeler updated 
https://github.com/llvm/llvm-project/pull/69477

>From 0ad973446c970e110f1b9c1213e97a7d3da8 Mon Sep 17 00:00:00 2001
From: Christian Kandeler 
Date: Wed, 18 Oct 2023 17:24:04 +0200
Subject: [PATCH] [clangd] Do not offer extraction to variable for decl init
 expression

That would turn:
  int x = f() + 1;
into:
  auto placeholder = f() + 1;
  int x = placeholder;
which makes little sense and is clearly not intended, as stated
explicitly by a comment in eligibleForExtraction(). It appears that the
declaration case was simply forgotten (the assignment case was already
implemented).
---
 .../refactor/tweaks/ExtractVariable.cpp   | 44 +--
 .../unittests/tweaks/ExtractVariableTests.cpp | 27 +++-
 2 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index 79bf962544242b..3b378153eafd52 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -468,7 +468,8 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
   // Extracting Exprs like a = 1 gives placeholder = a = 1 which isn't useful.
   // FIXME: we could still hoist the assignment, and leave the variable there?
   ParsedBinaryOperator BinOp;
-  if (BinOp.parse(*N) && BinaryOperator::isAssignmentOp(BinOp.Kind))
+  bool IsBinOp = BinOp.parse(*N);
+  if (IsBinOp && BinaryOperator::isAssignmentOp(BinOp.Kind))
 return false;
 
   const SelectionTree::Node &OuterImplicit = N->outerImplicit();
@@ -483,13 +484,48 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
   OuterImplicit.ASTNode.get()))
 return false;
 
+  std::function IsFullySelected =
+  [&](const SelectionTree::Node *N) {
+if (N->ASTNode.getSourceRange().isValid() &&
+N->Selected != SelectionTree::Complete)
+  return false;
+for (const auto *Child : N->Children) {
+  if (!IsFullySelected(Child))
+return false;
+}
+return true;
+  };
+  auto ExprIsFullySelectedTargetNode = [&](const Expr *E) {
+if (E != OuterImplicit.ASTNode.get())
+  return false;
+
+// The above condition is the only relevant one except for binary 
operators.
+// Without the following code, we would fail to offer extraction for e.g.:
+//   int x = 1 + 2 + [[3 + 4 + 5]];
+// See the documentation of ParsedBinaryOperator for further details.
+if (!IsBinOp)
+  return true;
+return IsFullySelected(N);
+  };
+
   // Disable extraction of full RHS on assignment operations, e.g:
-  // auto x = [[RHS_EXPR]];
+  // x = [[RHS_EXPR]];
   // This would just result in duplicating the code.
   if (const auto *BO = Parent->ASTNode.get()) {
-if (BO->isAssignmentOp() &&
-BO->getRHS() == OuterImplicit.ASTNode.get())
+if (BO->isAssignmentOp() && ExprIsFullySelectedTargetNode(BO->getRHS()))
+  return false;
+  }
+
+  // The same logic as for assignments applies to initializations.
+  // However, we do allow extracting the RHS of an init capture, as it is
+  // a valid use case to move non-trivial expressions out of the capture 
clause.
+  // FIXME: In that case, the extracted variable should be captured directly,
+  //rather than an explicit copy.
+  if (const auto *Decl = Parent->ASTNode.get()) {
+if (!Decl->isInitCapture() &&
+ExprIsFullySelectedTargetNode(Decl->getInit())) {
   return false;
+}
   }
 
   return true;
diff --git a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index eb5b06cfee4316..42dd612c46 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -27,10 +27,10 @@ TEST_F(ExtractVariableTest, Test) {
   return t.b[[a]]r]]([[t.z]])]];
 }
 void f() {
-  int a = [[5 +]] [[4 * xyz]]();
+  int a = 5 + [[4 * xyz]]();
   // multivariable initialization
   if(1)
-int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
+int x = [[1]] + 1, y = a + [[1]], a = [[1]] + 2, z = a + 1;
   // if without else
   if([[1]])
 a = [[1]] + 1;
@@ -61,7 +61,7 @@ TEST_F(ExtractVariableTest, Test) {
   ExtraArgs = {"-xc"};
   const char *AvailableC = R"cpp(
 void foo() {
-  int x = [[1]];
+  int x = [[1]] + 1;
 })cpp";
   EXPECT_AVAILABLE(AvailableC);
 
@@ -79,7 +79,7 @@ TEST_F(ExtractVariableTest, Test) {
 @end
 @implementation Foo
 - (void)method {
-  int x = [[1 + 2]];
+  int x = [[1]] + 2;
 }
 @end)cpp";
   EXPECT_AVAILABLE(AvailableObjC);
@@ -103,6 +103,9 @@ TEST_F(ExtractVariableTest, Test) {
 }
 int z = [[1]];
   } t;
+  int x = [

[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-11 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/77750

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.


>From 732a0b343b24eee4bb5f17e4c2edbe7268aa8955 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 11 Jan 2024 10:42:23 +
Subject: [PATCH] [clang][dataflow] Process terminator condition within
 `transferCFGBlock()`.

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.
---
 .../TypeErasedDataflowAnalysis.cpp| 42 +--
 .../Analysis/FlowSensitive/LoggerTest.cpp |  1 +
 .../Analysis/FlowSensitive/TransferTest.cpp   | 31 ++
 3 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ea..b2b1acd288bd9f 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,19 +126,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from different environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond = dyn_cast_or_null(
+  Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if
+  // statement is one such example.
+  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
+   State.Env);
+
+// If the transfer function didn't produce a value, create an atom so that
+// we have *some* value for the condition expression. This ensures that
+// when we extend the flow condition, it actually changes.
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolVa

[clang] [llvm] [AArch64][SME] Fix multi vector cvt builtins (PR #77656)

2024-01-11 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/77656

>From 67be98b05d771dabe11af54b69532641fa548fb1 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Wed, 10 Jan 2024 17:58:30 +
Subject: [PATCH 1/2] [AArch64][SME] Fix multi vector cvt builtins

This fixes cvt multi vector builtins that erroneously had inverted
return vectors and vector parameters. This caused the incorrect
instructions to be emitted.
---
 clang/include/clang/Basic/arm_sve.td  | 18 ++---
 .../aarch64-sme2-intrinsics/acle_sme2_cvt.c   | 32 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  8 +-
 .../CodeGen/AArch64/sme2-intrinsics-cvt.ll| 80 +--
 4 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 7f80fb0386cc77..301ef67b3d40bc 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2238,15 +2238,15 @@ let TargetGuard = "sme2" in {
   def SVCVT_F16_X2  : SInst<"svcvt_f16[_f32_x2]", "e2", "f", MergeNone, 
"aarch64_sve_fcvt_x2", [IsStreaming],[]>;
   def SVCVT_BF16_X2 : SInst<"svcvt_bf16[_f32_x2]", "$2", "f", MergeNone, 
"aarch64_sve_bfcvt_x2", [IsOverloadNone, IsStreaming],[]>;
 
-  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
-  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
-  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
-  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
-
-  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
-  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
-  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
-  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
+  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
+  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
+  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
+
+  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
+  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
+  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
 }
 
 //
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
index a3ee7d2092f79f..f596b3167f2b82 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
@@ -59,7 +59,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv8f32.nxv4f32( poison,  [[TMP3]], i64 0)
 // CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
@@ -70,7 +70,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CPP-CHECK-NEXT:  entry:
 // CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
 // CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
 // CPP-CHEC

[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.


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


3 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+30-12) 
- (modified) clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp (+1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+31) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ea..b2b1acd288bd9f 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,19 +126,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from different environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond = dyn_cast_or_null(
+  Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if
+  // statement is one such example.
+  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
+   State.Env);
+
+// If the transfer function didn't produce a value, create an atom so that
+// we have *some* value for the condition expression. This ensures that
+// when we extend the flow condition, it actually changes.
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
+AC.Log.recordState(State);
+  }
+
   return State;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index a60dbe1f61f6d6..c5594aa3fe9d1f 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,6 +123,7 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
+recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d832..6d88e25f77c807 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -64

[clang] bd2a6ef - [clang]not lookup name containing a dependent type (#77587)

2024-01-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-01-11T18:43:36+08:00
New Revision: bd2a6efb305bfc2a4d9b368388da3d76d1b98b34

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

LOG: [clang]not lookup name containing a dependent type (#77587)

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template
instantiation dependent name issues but still missing some cases This
patch want to enhance the dependent name check

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprMember.cpp
clang/test/SemaCXX/conversion-function.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a18d36a16b1a9c..59732962caac65 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -719,7 +719,9 @@ Bug Fixes in This Version
 - Clang now emits correct source location for code-coverage regions in `if 
constexpr`
   and `if consteval` branches.
   Fixes (`#54419 `_)
-
+- Fix an issue where clang cannot find conversion function with template
+  parameter when instantiation of template class.
+  Fixes (`#77583 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 2abec3d86a27d9..32998ae60eafe2 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -782,7 +782,8 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType 
BaseType,
const Scope *S,
ActOnMemberAccessExtraArgs *ExtraArgs) {
   if (BaseType->isDependentType() ||
-  (SS.isSet() && isDependentScopeSpecifier(SS)))
+  (SS.isSet() && isDependentScopeSpecifier(SS)) ||
+  NameInfo.getName().isDependentName())
 return ActOnDependentMemberExpr(Base, BaseType,
 IsArrow, OpLoc,
 SS, TemplateKWLoc, FirstQualifierInScope,

diff  --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index b6e6142d179066..749e2fc1b452b6 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,13 +475,22 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  template struct A {
-operator T();
-  };
-  template struct B : A {
-template using Lookup = decltype(&B::operator U);
-  };
-  using Result = B::Lookup;
-  using Result = int (A::*)();
+namespace gh77583 {
+struct A1 {
+  operator int();
+};
+template struct C {
+  template  using Lookup = decltype(T{}.operator U());
+};
+C v{};
+}
+template struct A2 {
+  operator T();
+};
+template struct B : A2 {
+  template using Lookup = decltype(&B::operator U);
+};
+using Result = B::Lookup;
+using Result = int (A2::*)();
 }
 #endif



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


[clang] [clang]not lookup name containing a dependent type (PR #77587)

2024-01-11 Thread Congcong Cai via cfe-commits

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


[clang] [llvm] [AArch64][SME] Fix multi vector cvt builtins (PR #77656)

2024-01-11 Thread Matthew Devereau via cfe-commits


@@ -3095,23 +3095,23 @@ let TargetPrefix = "aarch64" in {
 [llvm_anyvector_ty, LLVMMatchType<0>, 
LLVMMatchType<0>, LLVMMatchType<0>],
 [IntrNoMem]>;
 
-  class SME2_CVT_FtoI_VG2_Intrinsic
+  class SME2_CVT_ItoF_VG2_Intrinsic

MDevereau wrote:

Done

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


[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-11 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 cc21aa1922b3d0c4fde52046d8d16d1048f8064e 
732a0b343b24eee4bb5f17e4c2edbe7268aa8955 -- 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index b2b1acd288..fdb2aeacf0 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -488,8 +488,8 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext &AC,
   // important that we evaluate it here (rather than while processing the
   // terminator) so that we put the corresponding value in the right
   // environment.
-  if (const Expr *TerminatorCond = dyn_cast_or_null(
-  Block.getTerminatorCondition())) {
+  if (const Expr *TerminatorCond =
+  dyn_cast_or_null(Block.getTerminatorCondition())) {
 if (State.Env.getValue(*TerminatorCond) == nullptr)
   // FIXME: This only runs the builtin transfer, not the analysis-specific
   // transfer. Fixing this isn't trivial, as the analysis-specific transfer

``




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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits


@@ -27,10 +27,10 @@ TEST_F(ExtractVariableTest, Test) {
   return t.b[[a]]r]]([[t.z]])]];
 }
 void f() {
-  int a = [[5 +]] [[4 * xyz]]();
+  int a = 5 + [[4 * xyz]]();
   // multivariable initialization
   if(1)
-int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
+int x = [[1]] + 1, y = [[a + 1]], a = [[1]] + 2, z = a + 1;

ckandeler wrote:

Yes, I got side-tracked by fixing all the regressions, and in the end the patch 
didn't fulfill its original purpose anymore.
Fixed  now.

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


[clang] [clang-tools-extra] [llvm] [libc] [libc] Fix buggy AVX2 / AVX512 `memcmp` (PR #77081)

2024-01-11 Thread Guillaume Chatelet via cfe-commits

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits


@@ -422,8 +422,6 @@ TEST_F(ExtractVariableTest, Test) {
 int member = 42;
 };
 )cpp"},
-  {R"cpp(void f() { auto x = [[ [](){ return 42; }]]; })cpp",

ckandeler wrote:

Done.

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits


@@ -504,68 +502,6 @@ TEST_F(ExtractVariableTest, Test) {
 int main() {
   auto placeholder = []() { return 42; }(); return  placeholder ;
 })cpp"},
-  {R"cpp(

ckandeler wrote:

Done.

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits


@@ -504,68 +502,6 @@ TEST_F(ExtractVariableTest, Test) {
 int main() {
   auto placeholder = []() { return 42; }(); return  placeholder ;
 })cpp"},
-  {R"cpp(
-template 
-void foo(Ts ...args) {
-  auto x = [[ [&args...]() {} ]];
-}
-  )cpp",
-   R"cpp(
-template 
-void foo(Ts ...args) {
-  auto placeholder = [&args...]() {}; auto x =  placeholder ;
-}
-  )cpp"},
-  {R"cpp(

ckandeler wrote:

Done.

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits


@@ -490,6 +491,13 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
 BO->getRHS() == OuterImplicit.ASTNode.get())
   return false;
   }
+  if (const auto *Decl = Parent->ASTNode.get()) {
+if (!Decl->isInitCapture() &&

ckandeler wrote:

I think I found a not-too-horrible solution.

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


[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-11 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/77750

>From 74ad27d843947e17d1cce38bee5a1bff2d9045f7 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 11 Jan 2024 10:47:41 +
Subject: [PATCH] [clang][dataflow] Process terminator condition within
 `transferCFGBlock()`.

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.
---
 .../TypeErasedDataflowAnalysis.cpp| 42 +--
 .../Analysis/FlowSensitive/LoggerTest.cpp |  1 +
 .../Analysis/FlowSensitive/TransferTest.cpp   | 31 ++
 3 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ea..fdb2aeacf063ab 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,19 +126,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from different environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond =
+  dyn_cast_or_null(Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if
+  // statement is one such example.
+  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
+   State.Env);
+
+// If the transfer function didn't produce a value, create an atom so that
+// we have *some* value for the condition expression. This ensures that
+// when we extend the flow condition, it actually changes.
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
+AC.Log.recordState(State);
+  }
+
   return State;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index a60dbe1f61f6d6..c5594aa3fe9d1f 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,6 +123,7 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
+recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d832..6d88e25f77c807 10

[clang] [Clang] Rename and enable boolean get, set, create and undef for sme2 (PR #77338)

2024-01-11 Thread Kerry McLaughlin via cfe-commits


@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O2 -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O2 -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -O2 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -O2 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK

kmclaughlin-arm wrote:

Please can you also add a line to test these builtins end to end? For example:
`RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s`

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


[clang] 19081f4 - [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (#77580)

2024-01-11 Thread via cfe-commits

Author: Ben Shi
Date: 2024-01-11T18:48:31+08:00
New Revision: 19081f4a504053f551eb88bfa8a09a075c826e64

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

LOG: [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker 
(#77580)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/stream-error.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index fbfa101257d5e1..742426a628e065 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -268,8 +268,12 @@ class StreamChecker : public Checker();
   ProgramStateRef StateNotFailed =
   State->BindExpr(CE, C.getLocationContext(), RetVal);
-  auto Cond = SVB.evalBinOp(State, BO_GE, RetVal,
-SVB.makeZeroVal(C.getASTContext().LongTy),
-SVB.getConditionType())
-  .getAs();
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, 
SVB.makeZeroVal(Call.getResultType()),
+SVB.getConditionType())
+  .getAs();
   if (!Cond)
 return;
   StateNotFailed = StateNotFailed->assume(*Cond, true);
@@ -1124,7 +1128,7 @@ void StreamChecker::evalFtell(const FnDescription *Desc, 
const CallEvent &Call,
 return;
 
   ProgramStateRef StateFailed = State->BindExpr(
-  CE, C.getLocationContext(), SVB.makeIntVal(-1, 
C.getASTContext().LongTy));
+  CE, C.getLocationContext(), SVB.makeIntVal(-1, Call.getResultType()));
 
   // This function does not affect the stream state.
   // Still we add success and failure state with the appropriate return value.

diff  --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index caae59c38a4c8e..cd7ac616bcc67f 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -13,6 +13,7 @@ typedef __typeof(sizeof(int)) size_t;
 typedef long long __int64_t;
 typedef __int64_t __darwin_off_t;
 typedef __darwin_off_t fpos_t;
+typedef int off_t;
 
 typedef struct _FILE FILE;
 #define SEEK_SET 0 /* Seek from beginning of file. */
@@ -55,7 +56,9 @@ int fputc(int ch, FILE *stream);
 int fputs(const char *restrict s, FILE *restrict stream);
 int ungetc(int c, FILE *stream);
 int fseek(FILE *__stream, long int __off, int __whence);
+int fseeko(FILE *__stream, off_t __off, int __whence);
 long int ftell(FILE *__stream);
+off_t ftello(FILE *__stream);
 void rewind(FILE *__stream);
 int fgetpos(FILE *restrict stream, fpos_t *restrict pos);
 int fsetpos(FILE *stream, const fpos_t *pos);

diff  --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index c038348e799d29..2d03c0bbe7c474 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -295,6 +295,25 @@ void error_fseek(void) {
   fclose(F);
 }
 
+void error_fseeko(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseeko(F, 1, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get feof or ferror or no error.
+clang_analyzer_eval(IsFEof || IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof && IsFError); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
+
 void error_fseek_0(void) {
   FILE *F = fopen("file", "r");
   if (!F)
@@ -324,6 +343,68 @@ void error_fseek_0(void) {
   fclose(F);
 }
 
+void error_fseeko_0(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseeko(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get ferror or no error, but not feof.
+clang_analyzer_eval(IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof);
+// expected-warning@-1 {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
+
+void error_ftell(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  long rc = ftell(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_feof_str

[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Ben Shi via cfe-commits

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


[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

2024-01-11 Thread Christian Kandeler via cfe-commits

ckandeler wrote:

The latest patch set addresses all the comments.

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


[clang] [clang-tools-extra] [llvm] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-11 Thread via cfe-commits

https://github.com/r4nt updated https://github.com/llvm/llvm-project/pull/76245

>From 52cb11f0279dbd9f65f15e81f44869cfac00d544 Mon Sep 17 00:00:00 2001
From: Manuel Klimek 
Date: Thu, 2 Mar 2023 14:00:35 +
Subject: [PATCH 1/3] [ClangFormat] Fix formatting bugs.

1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not to
   break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).
---
 clang/lib/Format/FormatToken.h| 26 +
 clang/lib/Format/TokenAnnotator.cpp   | 13 +++
 clang/lib/Format/UnwrappedLineFormatter.cpp   | 10 +++--
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +
 .../Format/FormatTestMacroExpansion.cpp   | 38 +++
 5 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3f9664f8f78a3e..b1e3ae8ab303d6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -275,14 +275,15 @@ class AnnotatedLine;
 struct FormatToken {
   FormatToken()
   : HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
-MustBreakBefore(false), IsUnterminatedLiteral(false),
-CanBreakBefore(false), ClosesTemplateDeclaration(false),
-StartsBinaryExpression(false), EndsBinaryExpression(false),
-PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
-Finalized(false), ClosesRequiresClause(false),
-EndsCppAttributeGroup(false), BlockKind(BK_Unknown),
-Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
-TypeIsFinalized(false), Type(TT_Unknown) {}
+MustBreakBefore(false), MustBreakBeforeFinalized(false),
+IsUnterminatedLiteral(false), CanBreakBefore(false),
+ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
+EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
+ContinuesLineCommentSection(false), Finalized(false),
+ClosesRequiresClause(false), EndsCppAttributeGroup(false),
+BlockKind(BK_Unknown), Decision(FD_Unformatted),
+PackingKind(PPK_Inconclusive), TypeIsFinalized(false),
+Type(TT_Unknown) {}
 
   /// The \c Token.
   Token Tok;
@@ -318,6 +319,10 @@ struct FormatToken {
   /// before the token.
   unsigned MustBreakBefore : 1;
 
+  /// Whether MustBreakBefore is finalized during parsing and must not
+  /// be reset between runs.
+  unsigned MustBreakBeforeFinalized : 1;
+
   /// Set to \c true if this token is an unterminated literal.
   unsigned IsUnterminatedLiteral : 1;
 
@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+
 Type = T;
 TypeIsFinalized = true;
   }
   void overwriteFixedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
 TypeIsFinalized = false;
 setType(T);
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3551af3424396..c26b248a3b2d40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2769,13 +2769,6 @@ class ExpressionParser {
   // Consume operators with higher precedence.
   parse(Precedence + 1);
 
-  // Do not assign fake parenthesis to tokens that are part of an
-  // unexpanded macro call. The line within the macro call contains
-  // the parenthesis and commas, and we will not find operators within
-  // that structure.
-  if (Current && Current->MacroParent)
-break;
-
   int CurrentPrecedence = getCurrentPrecedence();
 
   if (Precedence == CurrentPrecedence && Current &&
@@ -2919,6 +2912,12 @@ class ExpressionParser {
 
   void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
   FormatToken *End = nullptr) {
+// Do not assign fake parenthesis to tokens that are part of an
+// unexpanded macro call. The line within the macro call contains
+// the parenthesis and commas, and we will not find operators within
+// that structure.
+if (Start->MacroParent) return;
+
 Start->FakeLParens.push_back(Precedence);
 if (Precedence > prec::Unknown)
   Start->StartsBinaryExpression = true;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Fo

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/77753

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html 
function/constructor/destructor can be marked `constexpr` even though it never 
produces a constant expression.
Non-literal types as return types and parameter types of functions marked 
`constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for C++ 
standards older than C++23.

>From 699f47bba02012523e1862f9b15ce9de1d7511b5 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 18 Oct 2023 02:47:33 -0700
Subject: [PATCH] [Clang][C++23] Implement P2448R2: Relaxing some constexpr
 restrictions

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html
function/constructor/destructor can be marked `constexpr` even though it never
produces a constant expression.
Non-literal types as return types and parameter types of functions
marked `constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for
C++ standards older than C++23.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  42 +++--
 clang/lib/Sema/SemaDeclCXX.cpp|  54 +--
 clang/test/AST/Interp/cxx23.cpp   |  24 +--
 clang/test/AST/Interp/literals.cpp|   2 +-
 clang/test/AST/Interp/shifts.cpp  |   8 +-
 clang/test/CXX/basic/basic.types/p10.cpp  |  26 +--
 .../dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp   |   8 +-
 .../dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp  |   4 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  27 ++--
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |  20 +--
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp |   6 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp |   2 +-
 .../dcl.fct.def/dcl.fct.def.default/p2.cpp|   6 +-
 clang/test/CXX/drs/dr13xx.cpp |  22 +--
 clang/test/CXX/drs/dr14xx.cpp |   6 +-
 clang/test/CXX/drs/dr16xx.cpp |  12 +-
 clang/test/CXX/drs/dr6xx.cpp  |  24 +--
 clang/test/CXX/expr/expr.const/p2-0x.cpp  |   2 +-
 clang/test/CXX/expr/expr.const/p5-26.cpp  |   4 +-
 clang/test/CXX/special/class.copy/p13-0x.cpp  |   2 +-
 clang/test/PCH/cxx11-constexpr.cpp|   2 +-
 clang/test/SemaCXX/builtin_vectorelements.cpp |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  29 ++--
 .../SemaCXX/constant-expression-cxx14.cpp |  33 ++--
 .../SemaCXX/constant-expression-cxx2b.cpp |  18 ++-
 .../constexpr-function-recovery-crash.cpp |   4 +-
 .../test/SemaCXX/cxx1z-constexpr-lambdas.cpp  |   4 +-
 .../test/SemaCXX/cxx23-invalid-constexpr.cpp  | 152 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp|   4 +-
 .../SemaCXX/deduced-return-type-cxx14.cpp |   8 +-
 clang/test/SemaCXX/ms-constexpr-invalid.cpp   |   6 +-
 clang/test/SemaCXX/ms-constexpr.cpp   |   2 +-
 clang/test/SemaCXX/sizeless-1.cpp |   2 +-
 .../addrspace-constructors.clcpp  |   2 +-
 clang/www/cxx_status.html |   9 +-
 36 files changed, 378 insertions(+), 202 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a18d36a16b1a9c..23342a6a7256d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..67409374f26dfa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2765,10 +2765,14 @@ def err_constexpr_tag : Error<
   "cannot be marked %sub{select_constexpr_spec_kind}1">;
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
-def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+def ext_constexpr_dtor_subobject : ExtWarn<
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
-  "constexpr destructor">;
+  "constexpr destructor">, InGroup, DefaultError;
+def warn_cxx23_compat_constexpr_dtor_subobject : ExtWarn<
+  "%sub{select_constexpr_spec_kind}0 destructor is incompatible with C++ 
standards before C++23 because "
+  "%select{data member %2|base class %3}1 does not have a "
+  "constexpr destructor">, InGroup, DefaultIgnore;
 def note_constexpr_

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html 
function/constructor/destructor can be marked `constexpr` even though it never 
produces a constant expression.
Non-literal types as return types and parameter types of functions marked 
`constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for C++ 
standards older than C++23.

---

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


36 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+26-16) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+39-15) 
- (modified) clang/test/AST/Interp/cxx23.cpp (+6-18) 
- (modified) clang/test/AST/Interp/literals.cpp (+1-1) 
- (modified) clang/test/AST/Interp/shifts.cpp (+4-4) 
- (modified) clang/test/CXX/basic/basic.types/p10.cpp (+13-13) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp (+4-4) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp (+2-2) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp (+13-14) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp (+10-10) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp (+3-3) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp (+1-1) 
- (modified) clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp 
(+3-3) 
- (modified) clang/test/CXX/drs/dr13xx.cpp (+11-11) 
- (modified) clang/test/CXX/drs/dr14xx.cpp (+3-3) 
- (modified) clang/test/CXX/drs/dr16xx.cpp (+6-6) 
- (modified) clang/test/CXX/drs/dr6xx.cpp (+12-12) 
- (modified) clang/test/CXX/expr/expr.const/p2-0x.cpp (+1-1) 
- (modified) clang/test/CXX/expr/expr.const/p5-26.cpp (+2-2) 
- (modified) clang/test/CXX/special/class.copy/p13-0x.cpp (+1-1) 
- (modified) clang/test/PCH/cxx11-constexpr.cpp (+1-1) 
- (modified) clang/test/SemaCXX/builtin_vectorelements.cpp (+1-1) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+15-14) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+17-16) 
- (modified) clang/test/SemaCXX/constant-expression-cxx2b.cpp (+12-6) 
- (modified) clang/test/SemaCXX/constexpr-function-recovery-crash.cpp (+2-2) 
- (modified) clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp (+2-2) 
- (added) clang/test/SemaCXX/cxx23-invalid-constexpr.cpp (+152) 
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+2-2) 
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+4-4) 
- (modified) clang/test/SemaCXX/ms-constexpr-invalid.cpp (+3-3) 
- (modified) clang/test/SemaCXX/ms-constexpr.cpp (+1-1) 
- (modified) clang/test/SemaCXX/sizeless-1.cpp (+1-1) 
- (modified) clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp (+1-1) 
- (modified) clang/www/cxx_status.html (+1-8) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a18d36a16b1a9c..23342a6a7256d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..67409374f26dfa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2765,10 +2765,14 @@ def err_constexpr_tag : Error<
   "cannot be marked %sub{select_constexpr_spec_kind}1">;
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
-def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+def ext_constexpr_dtor_subobject : ExtWarn<
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
-  "constexpr destructor">;
+  "constexpr destructor">, InGroup, DefaultError;
+def warn_cxx23_compat_constexpr_dtor_subobject : ExtWarn<
+  "%sub{select_constexpr_spec_kind}0 destructor is incompatible with C++ 
standards before C++23 because "
+  "%select{data member %2|base class %3}1 does not have a "
+  "constexpr destructor">, InGroup, DefaultIgnore;
 def note_constexpr_dtor_subobject : Note<
   "%select{data member %1|base class %2}0 declared here">;
 def err_constexpr_wrong_decl_kind : Error<
@@ -2800,11 +2804,14 @@ def note_non_literal_incomplete : Note<
 def note_non_literal_virtual_base : Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classe

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 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 dc974573a8a2364f24ce69c75ad80ab30753fe9a 
699f47bba02012523e1862f9b15ce9de1d7511b5 -- 
clang/test/SemaCXX/cxx23-invalid-constexpr.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/test/AST/Interp/cxx23.cpp clang/test/AST/Interp/literals.cpp 
clang/test/AST/Interp/shifts.cpp clang/test/CXX/basic/basic.types/p10.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp 
clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp 
clang/test/CXX/drs/dr13xx.cpp clang/test/CXX/drs/dr14xx.cpp 
clang/test/CXX/drs/dr16xx.cpp clang/test/CXX/drs/dr6xx.cpp 
clang/test/CXX/expr/expr.const/p2-0x.cpp 
clang/test/CXX/expr/expr.const/p5-26.cpp 
clang/test/CXX/special/class.copy/p13-0x.cpp clang/test/PCH/cxx11-constexpr.cpp 
clang/test/SemaCXX/builtin_vectorelements.cpp 
clang/test/SemaCXX/constant-expression-cxx11.cpp 
clang/test/SemaCXX/constant-expression-cxx14.cpp 
clang/test/SemaCXX/constant-expression-cxx2b.cpp 
clang/test/SemaCXX/constexpr-function-recovery-crash.cpp 
clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp 
clang/test/SemaCXX/cxx2a-consteval.cpp 
clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
clang/test/SemaCXX/ms-constexpr-invalid.cpp clang/test/SemaCXX/ms-constexpr.cpp 
clang/test/SemaCXX/sizeless-1.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index aa49dc73e1..20c8c3ef6c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7881,8 +7881,8 @@ bool 
Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
   << CSM << MD->isConsteval();
 }
 // FIXME: Explain why the special member can't be constexpr.
-if (!getLangOpts().CPlusPlus23)
-  HadError = true;
+if (!getLangOpts().CPlusPlus23)
+  HadError = true;
   }
 
   if (First) {

``




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


[clang] [clang][ExtractAPI] improve template argument name deduction (PR #77716)

2024-01-11 Thread Daniel Grumberg via cfe-commits


@@ -196,8 +196,7 @@ template class Foo {};
   "spelling": "<"
 },
 {
-  "kind": "typeIdentifier",
-  "preciseIdentifier": "c:t0.0",
+  "kind": "genericArgument",

daniel-grumberg wrote:

might be best to leave these as generic text fragments

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


[clang] [clang-format] Handle possible crash in `getCells` (PR #77723)

2024-01-11 Thread via cfe-commits

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


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


[clang] [clang-format] Don't confuse initializer equal signs in for loops (PR #77712)

2024-01-11 Thread via cfe-commits

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


[clang] [clang-format] Don't confuse initializer equal signs in for loops (PR #77712)

2024-01-11 Thread via cfe-commits


@@ -703,7 +703,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 
   if (Current.is(tok::equal) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
-  CurrentState.VariablePos == 0) {
+  CurrentState.VariablePos == 0 &&
+  (!Previous.Previous ||
+   Previous.Previous->isNot(TT_DesignatedInitializerPeriod))) {

mydeveloperday wrote:

maybe we handle that in seperate issue?

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


[clang] [clang-format] Don't confuse initializer equal signs in for loops (PR #77712)

2024-01-11 Thread via cfe-commits

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

For me I'm happy if we keep it to this use case only.

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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-11 Thread via cfe-commits

https://github.com/mydeveloperday commented:

LGTM

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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-11 Thread via cfe-commits

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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-11 Thread via cfe-commits


@@ -1066,6 +1066,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("template \n"
+"concept C = (!Foo) && Bar;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);

mydeveloperday wrote:

out of interest what did it think it was  before?

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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-11 Thread via cfe-commits

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


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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-11 Thread Emilia Kond via cfe-commits


@@ -1066,6 +1066,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("template \n"
+"concept C = (!Foo) && Bar;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);

rymiel wrote:

TT_UnaryOperator, as outlined in the issue description

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


[clang] [clang-format] Add SpaceInParensOption for __attribute__ keyword (PR #77522)

2024-01-11 Thread via cfe-commits

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

LGTM

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

I checked changes to DR tests, as that's the only part of this PR I'm competent 
enough for.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -153,16 +153,16 @@ namespace dr1460 { // dr1460: 3.5
   namespace Defaulted {
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
-// cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+// cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Endilll wrote:

11 through 17 we expect a 23 extension warning, but what happens in 20 mode?

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -410,11 +410,11 @@ namespace dr1358 { // dr1358: 3.1
   struct B : Virt {
 int member;
 constexpr B(NonLit u) : member(u) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLit' is not a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
 constexpr NonLit f(NonLit u) const { return NonLit(); }
-// since-cxx11-error@-1 {{constexpr function's return type 'NonLit' is not 
a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr function with non-literal return type 
'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -584,8 +584,8 @@ namespace dr647 { // dr647: 3.1
   struct C {
 constexpr C(NonLiteral);
 constexpr C(NonLiteral, int) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLiteral' is not a literal type}}
-//   since-cxx11-note@#dr647-NonLiteral {{'NonLiteral' is not literal 
because it is not an aggregate and has no constexpr constructors other than 
copy or move constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLiteral' is a C++23 extension}}
+// cxx11-20-note@#dr647-NonLiteral {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr647-NonLiteral {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}
```

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -423,13 +423,13 @@ namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
   union B { constexpr B() = default; int a; }; // #dr1359-B
-  // cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+  // cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Endilll wrote:

11 through 17 we expect a 23 extension warning, but what happens in 20 mode?

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -410,11 +410,11 @@ namespace dr1358 { // dr1358: 3.1
   struct B : Virt {
 int member;
 constexpr B(NonLit u) : member(u) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLit' is not a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -349,8 +349,8 @@ namespace dr1684 { // dr1684: 3.6
   };
   constexpr int f(NonLiteral &) { return 0; }
   constexpr int f(NonLiteral) { return 0; }
-  // since-cxx11-error@-1 {{constexpr function's 1st parameter type 
'NonLiteral' is not a literal type}}
-  //   since-cxx11-note@#dr1684-struct {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}
+  // cxx11-20-error@-1 {{constexpr function with 1st non-literal parameter 
type 'NonLiteral' is a C++23 extension}}
+  // cxx11-20-note@#dr1684-struct {{'NonLiteral' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
  //   cxx11-20-note@#dr1684-struct {{'NonLiteral' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

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


[clang] [clang-format] TableGen keywords support. (PR #77477)

2024-01-11 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/77477

>From 4e9f2bc86c4e48c4d412fea7804c226f041d022c Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 9 Jan 2024 22:57:53 +0900
Subject: [PATCH] [clang-format] TableGen keywords support.

Add TableGen keywords to the additional keyword list of the formatter.
---
 clang/include/clang/Format/Format.h   |  1 +
 clang/lib/Format/FormatToken.h| 75 +++
 clang/lib/Format/FormatTokenLexer.cpp |  3 +
 clang/lib/Format/TokenAnnotator.cpp   |  6 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 18 +
 5 files changed, 103 insertions(+)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 59b645ecab715b..5ffd63ee73fc36 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3055,6 +3055,7 @@ struct FormatStyle {
   bool isProto() const {
 return Language == LK_Proto || Language == LK_TextProto;
   }
+  bool isTableGen() const { return Language == LK_TableGen; }
 
   /// Language, this format style is targeted at.
   /// \version 3.5
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 3f9664f8f78a3e..bd21a972441a98 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1202,6 +1202,21 @@ struct AdditionalKeywords {
 kw_verilogHashHash = &IdentTable.get("##");
 kw_apostrophe = &IdentTable.get("\'");
 
+// TableGen keywords
+kw_bit = &IdentTable.get("bit");
+kw_bits = &IdentTable.get("bits");
+kw_code = &IdentTable.get("code");
+kw_dag = &IdentTable.get("dag");
+kw_def = &IdentTable.get("def");
+kw_defm = &IdentTable.get("defm");
+kw_defset = &IdentTable.get("defset");
+kw_defvar = &IdentTable.get("defvar");
+kw_dump = &IdentTable.get("dump");
+kw_include = &IdentTable.get("include");
+kw_list = &IdentTable.get("list");
+kw_multiclass = &IdentTable.get("multiclass");
+kw_then = &IdentTable.get("then");
+
 // Keep this at the end of the constructor to make sure everything here
 // is
 // already initialized.
@@ -1294,6 +1309,27 @@ struct AdditionalKeywords {
  kw_wildcard, kw_wire,
  kw_with, kw_wor,
  kw_verilogHash,  kw_verilogHashHash});
+
+TableGenExtraKeywords = std::unordered_set({
+kw_assert,
+kw_bit,
+kw_bits,
+kw_code,
+kw_dag,
+kw_def,
+kw_defm,
+kw_defset,
+kw_defvar,
+kw_dump,
+kw_foreach,
+kw_in,
+kw_include,
+kw_let,
+kw_list,
+kw_multiclass,
+kw_string,
+kw_then,
+});
   }
 
   // Context sensitive keywords.
@@ -1539,6 +1575,21 @@ struct AdditionalKeywords {
   // Symbols in Verilog that don't exist in C++.
   IdentifierInfo *kw_apostrophe;
 
+  // TableGen keywords
+  IdentifierInfo *kw_bit;
+  IdentifierInfo *kw_bits;
+  IdentifierInfo *kw_code;
+  IdentifierInfo *kw_dag;
+  IdentifierInfo *kw_def;
+  IdentifierInfo *kw_defm;
+  IdentifierInfo *kw_defset;
+  IdentifierInfo *kw_defvar;
+  IdentifierInfo *kw_dump;
+  IdentifierInfo *kw_include;
+  IdentifierInfo *kw_list;
+  IdentifierInfo *kw_multiclass;
+  IdentifierInfo *kw_then;
+
   /// Returns \c true if \p Tok is a keyword or an identifier.
   bool isWordLike(const FormatToken &Tok) const {
 // getIdentifierinfo returns non-null for keywords as well as identifiers.
@@ -1811,6 +1862,27 @@ struct AdditionalKeywords {
 }
   }
 
+  bool isTableGenDefinition(const FormatToken &Tok) const {
+return Tok.isOneOf(kw_def, kw_defm, kw_defset, kw_defvar, kw_multiclass,
+   kw_let, tok::kw_class);
+  }
+
+  bool isTableGenKeyword(const FormatToken &Tok) const {
+switch (Tok.Tok.getKind()) {
+case tok::kw_class:
+case tok::kw_else:
+case tok::kw_false:
+case tok::kw_if:
+case tok::kw_int:
+case tok::kw_true:
+  return true;
+default:
+  return Tok.is(tok::identifier) &&
+ TableGenExtraKeywords.find(Tok.Tok.getIdentifierInfo()) !=
+ TableGenExtraKeywords.end();
+}
+  }
+
 private:
   /// The JavaScript keywords beyond the C++ keyword set.
   std::unordered_set JsExtraKeywords;
@@ -1820,6 +1892,9 @@ struct AdditionalKeywords {
 
   /// The Verilog keywords beyond the C++ keyword set.
   std::unordered_set VerilogExtraKeywords;
+
+  /// The TableGen keywords beyond the C++ keyword set.
+  std::unordered_set TableGenExtraKeywords;
 };
 
 inline bool isLineComment(const FormatToken &FormatTok) {
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 61430282c6f88c..a1fd6dd6effe6c 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1182,6 +1182,9 @@ FormatToken *FormatTokenLexer::getNextToken() {
   

[clang] [llvm] [clang][Driver] Don't ignore -gmodules .gch files (PR #77711)

2024-01-11 Thread Michael Spencer via cfe-commits

Bigcheese wrote:

> What does the code that reads these files look like, could we leverage that 
> somehow?

You can call `clang::ObjectFilePCHContainerReader::ExtractPCH()` and then check 
the magic. This lives in the CodeGen library which I don't think the driver 
currently (or should) links against, but this is the best way to know if 
something is valid.
 
> An alternative would be turn the logic around, and only ignore GCC PCH files 
> (I believe they all start with the file magic `gpch`). However I do think 
> that the current approach of "whitelisting" the kind of file we're looking 
> for is better.

I would be fine with this approach, but agree that it's best if we can be more 
selective. My concern is that 
`clang::ObjectFilePCHContainerReader::ExtractPCH()` and this detection may get 
out of sync, as support for `-gmodules` is automatic anytime someone adds a new 
object format.

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


[clang] [clang-format] TableGen keywords support. (PR #77477)

2024-01-11 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you for reviewing!
I do not have write permission to the repository.  Could you please commit this 
or tell me what I can do?
 

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -153,16 +153,16 @@ namespace dr1460 { // dr1460: 3.5
   namespace Defaulted {
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
-// cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+// cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Fznamznon wrote:

In C++20 mode such constructor is considered as a valid and producing 
`constexpr` due to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1331r2.pdf , so no 
extension warning there.

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -423,13 +423,13 @@ namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
   union B { constexpr B() = default; int a; }; // #dr1359-B
-  // cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+  // cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Fznamznon wrote:

Same, In C++20 mode such constructor is considered as a valid and producing 
constexpr due to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1331r2.pdf , so no 
extension warning there.

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


[llvm] [libc] [clang] [libcxx] [compiler-rt] [flang] [clang-tools-extra] [lldb] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2024-01-11 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm closed 
https://github.com/llvm/llvm-project/pull/71222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2024-01-11 Thread Nemanja Ivanovic via cfe-commits

https://github.com/nemanjai updated 
https://github.com/llvm/llvm-project/pull/68919

>From 71f1352bf00d6a9eefa3f199859d47d093f272f8 Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic 
Date: Thu, 12 Oct 2023 14:08:42 -0400
Subject: [PATCH 1/3] [PowerPC][X86] Make cpu id builtins target independent
 and lower for PPC

Make __builtin_cpu_{init|supports|is} target independent and provide
an opt-in query for targets that want to support it. Each target is
still responsible for their specific lowering/code-gen.
Also provide code-gen for PowerPC.
---
 clang/include/clang/Basic/Builtins.def|   5 +
 clang/include/clang/Basic/BuiltinsX86.def |   7 -
 clang/include/clang/Basic/TargetInfo.h|   6 +
 clang/lib/Basic/Targets/PPC.cpp   |  14 ++
 clang/lib/Basic/Targets/PPC.h |   7 +
 clang/lib/Basic/Targets/X86.h |   4 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  42 +-
 clang/lib/Sema/SemaChecking.cpp   | 124 +++---
 clang/test/CodeGen/builtin-cpu-supports.c |  68 ++
 clang/test/Sema/builtin-cpu-supports.c|   8 +-
 llvm/include/llvm/IR/IntrinsicsPowerPC.td |   6 +
 .../llvm/TargetParser/PPCTargetParser.def |  80 +++
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |   4 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp  |  33 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.td   |   3 +
 llvm/lib/Target/PowerPC/PPCTargetMachine.h|   3 +
 llvm/test/CodeGen/PowerPC/cpu-supports.ll | 111 
 17 files changed, 443 insertions(+), 82 deletions(-)
 create mode 100644 llvm/include/llvm/TargetParser/PPCTargetParser.def
 create mode 100644 llvm/test/CodeGen/PowerPC/cpu-supports.ll

diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5..5e1f4088ff63f8 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -118,6 +118,11 @@
 #  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+// Builtins for checking CPU features based on the GCC builtins.
+BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
+BUILTIN(__builtin_cpu_is, "bcC*", "nc")
+BUILTIN(__builtin_cpu_init, "v", "n")
+
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fne")
 BUILTIN(__builtin_atan2f, "fff"  , "Fne")
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index e4802f8ab1c156..2acc5ce0f4a365 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -26,13 +26,6 @@
 #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-// Miscellaneous builtin for checking x86 cpu features.
-// TODO: Make this somewhat generic so that other backends
-// can use it?
-BUILTIN(__builtin_cpu_init, "v", "n")
-BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
-BUILTIN(__builtin_cpu_is, "bcC*", "nc")
-
 // Undefined Values
 //
 TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "")
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9d56e97a3d4bb8..3d83b387aac093 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1415,6 +1415,12 @@ class TargetInfo : public TransferrableTargetInfo,
 getTriple().isOSFreeBSD());
   }
 
+  // Identify whether this target supports __builtin_cpu_supports and
+  // __builtin_cpu_is.
+  virtual bool supportsCpuSupports() const { return false; }
+  virtual bool supportsCpuIs() const { return false; }
+  virtual bool supportsCpuInit() const { return false; }
+
   // Validate the contents of the __builtin_cpu_supports(const char*)
   // argument.
   virtual bool validateCpuSupports(StringRef Name) const { return false; }
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f..d8759c86c9932c 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -873,3 +873,17 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
   return llvm::ArrayRef(BuiltinInfo,
 clang::PPC::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
+
+bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+#define PPC_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, true)
+  return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
+
+bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+#define PPC_CPU(NAME, NUM) .Case(NAME, true)
+  return llvm::StringSwitch(CPUName)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c..f700b625b79030 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -359,6 +359,13 @@ class LL

  1   2   3   4   5   6   >