[clang-tools-extra] 7baf5d3 - [modularize] Stabilize iteration order when processing module maps

2023-07-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-20T22:44:23-07:00
New Revision: 7baf5d3841ee16df66e218b1b892d3d2a3f0680b

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

LOG: [modularize] Stabilize iteration order when processing module maps

Many diagnostics (e.g., ProblemsDuplicate.modularize,
ProblemsDisplayLists.modularize) are dependent on the iteration order of
StringMap, which is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
clang::ModuleMap::Modules is a StringMap. For now, sort by name in
modularize.

Added: 


Modified: 
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize

Removed: 




diff  --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp 
b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index 3ef808d204c617..043f6f5b20b80f 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -322,12 +322,13 @@ std::error_code ModularizeUtilities::loadModuleMap(
 // Walks the modules and collects referenced headers into
 // HeaderFileNames.
 bool ModularizeUtilities::collectModuleMapHeaders(clang::ModuleMap *ModMap) {
-  for (ModuleMap::module_iterator I = ModMap->module_begin(),
-E = ModMap->module_end();
-I != E; ++I) {
-if (!collectModuleHeaders(*I->second))
+  SmallVector, 0> Vec;
+  for (auto  : ModMap->modules())
+Vec.emplace_back(M.first(), M.second);
+  llvm::sort(Vec, llvm::less_first());
+  for (auto  : Vec)
+if (!collectModuleHeaders(*I.second))
   return false;
-  }
   return true;
 }
 

diff  --git a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize 
b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
index afe1ece5eec080..9721561511263b 100644
--- a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
+++ b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
@@ -12,5 +12,5 @@
 
 # CHECK: These are the combined files, with problem files preceded by #:
 
-# CHECK: Inputs/CompileError/Level1A.h
-# CHECK: {{.*}}Inputs/CompileError/HasError.h
+# CHECK:  Inputs/CompileError/HasError.h
+# CHECK-NEXT: Inputs/CompileError/Level1A.h



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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 2 inline comments as done.
FreddyYe added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1925
 // CHECK_GNR_M64: #define __AMX_BF16__ 1
-// CHECK_GNR_M64: #define __AMX_COMPLEX__ 1
+// CHECK_GNR_M64-NOT: #define __AMX_COMPLEX__ 1
+// CHECK_GNRD_M64: #define __AMX_COMPLEX__ 1

pengfei wrote:
> FreddyYe wrote:
> > RKSimon wrote:
> > > Won't this fail on the graniterapids-d run?
> > Whops, I didn't realize this problem before! But it indeed doesn't fail. 
> > Need to figure out why...
> I'm guessing when using multi prefixes, it will try to match with the second 
> one if the first failed. It's common and easy to understand for positive 
> check but a bit confusing for negative one.
I did some experiments and arrived at same guessing. It indeed worked here for 
graniterapids-d and checked each `#define` for it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155798/new/

https://reviews.llvm.org/D155798

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


[PATCH] D144164: [clang][Interp] Handle PtrMemOps

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:234
 
+  if (!LT || !RT || !T)
+return this->bail(BO);

aaron.ballman wrote:
> Should we be checking `!T` earlier (it's used within the `Discard` lambda 
> with an unprotected dereference)?
Probably, but I changed this again a bit in https://reviews.llvm.org/D148925, 
so I'd like to do that change in a later commit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144164/new/

https://reviews.llvm.org/D144164

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


[PATCH] D144164: [clang][Interp] Handle PtrMemOps

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 542762.
tbaeder marked 2 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144164/new/

https://reviews.llvm.org/D144164

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -689,5 +689,52 @@
 // ref-note {{initializer of 'D2' is not a constant expression}}
 
 }
+
+namespace VirtualFunctionPointers {
+  struct S {
+virtual constexpr int func() const { return 1; }
+  };
+
+  struct Middle : S {
+constexpr Middle(int i) : i(i) {}
+int i;
+  };
+
+  struct Other {
+constexpr Other(int k) : k(k) {}
+int k;
+  };
+
+  struct S2 : Middle, Other {
+int j;
+constexpr S2(int i, int j, int k) : Middle(i), Other(k), j(j) {}
+virtual constexpr int func() const { return i + j + k  + S::func(); }
+  };
+
+  constexpr S s;
+  constexpr decltype(::func) foo = ::func;
+  constexpr int value = (s.*foo)();
+  static_assert(value == 1);
+
+
+  constexpr S2 s2(1, 2, 3);
+  static_assert(s2.i == 1);
+  static_assert(s2.j == 2);
+  static_assert(s2.k == 3);
+
+  constexpr int value2 = s2.func();
+  constexpr int value3 = (s2.*foo)();
+  static_assert(value3 == 7);
+
+  constexpr int dynamicDispatch(const S ) {
+constexpr decltype(::func) SFunc = ::func;
+
+return (s.*SFunc)();
+  }
+
+  static_assert(dynamicDispatch(s) == 1);
+  static_assert(dynamicDispatch(s2) == 7);
+};
+
 };
 #endif
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -149,13 +149,10 @@
 // ref-error{{to a function type}}
 
 
-
-  /// FIXME: The following code should be accepted.
   struct S {
 void func();
   };
-  constexpr void (S::*Func)() = ::func; // expected-error {{must be initialized by a constant expression}} \
-  // expected-error {{interpreter failed to evaluate an expression}}
+  constexpr void (S::*Func)() = ::func;
   static_assert(sizeof(Func) == sizeof(::func), "");
 
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1716,6 +1716,9 @@
   if (!F || !F->isConstexpr())
 return false;
 
+  if (F->isVirtual())
+return CallVirt(S, OpPC, F);
+
   return Call(S, OpPC, F);
 }
 
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -88,12 +88,6 @@
 const LangOptions ::getLangOpts() const { return Ctx.getLangOpts(); }
 
 std::optional Context::classify(QualType T) const {
-  if (T->isFunctionPointerType() || T->isFunctionReferenceType())
-return PT_FnPtr;
-
-  if (T->isReferenceType() || T->isPointerType())
-return PT_Ptr;
-
   if (T->isBooleanType())
 return PT_Bool;
 
@@ -133,9 +127,22 @@
   if (T->isFloatingType())
 return PT_Float;
 
+  if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
+  T->isFunctionType())
+return PT_FnPtr;
+
+  if (T->isReferenceType() || T->isPointerType())
+return PT_Ptr;
+
   if (auto *AT = dyn_cast(T))
 return classify(AT->getValueType());
 
+  if (auto *DT = dyn_cast(T))
+return classify(DT->getUnderlyingType());
+
+  if (auto *DT = dyn_cast(T))
+return classify(DT->getPointeeType());
+
   return {};
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -207,13 +207,13 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
+  if (BO->isPtrMemOp())
+return this->visit(RHS);
+
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
   std::optional T = classify(BO->getType());
-  if (!LT || !RT || !T) {
-return this->bail(BO);
-  }
 
   auto Discard = [this, T, BO](bool Result) {
 if (!Result)
@@ -228,6 +228,9 @@
 return Discard(this->visit(RHS));
   }
 
+  if (!LT || !RT || !T)
+return this->bail(BO);
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (T == PT_Ptr || (LT == PT_Ptr && RT == PT_Ptr))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155890: [clang-tidy] Add folly::Optional to unchecked-optional-access

2023-07-20 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp requested changes to this revision.
carlosgalvezp added a comment.
This revision now requires changes to proceed.

This should be a configuration option, we should not hardcore project-specific 
things in the source code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155890/new/

https://reviews.llvm.org/D155890

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


[clang] dda8ac8 - Sarif: stabilize artifacts order

2023-07-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-20T21:37:50-07:00
New Revision: dda8ac8d3a6a7de7c1cc3f031bb5296bae74d754

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

LOG: Sarif: stabilize artifacts order

StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).

Added: 


Modified: 
clang/lib/Basic/Sarif.cpp
clang/unittests/Basic/SarifTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Sarif.cpp b/clang/lib/Basic/Sarif.cpp
index 75de9c9605b91f..e2af25c8143b33 100644
--- a/clang/lib/Basic/Sarif.cpp
+++ b/clang/lib/Basic/Sarif.cpp
@@ -294,8 +294,11 @@ void SarifDocumentWriter::endRun() {
   // Flush all the artifacts.
   json::Object  = getCurrentRun();
   json::Array *Artifacts = Run.getArray("artifacts");
-  for (const auto  : CurrentArtifacts) {
-const SarifArtifact  = Pair.getValue();
+  SmallVector, 0> Vec;
+  for (const auto &[K, V] : CurrentArtifacts)
+Vec.emplace_back(K, V);
+  llvm::sort(Vec, llvm::less_first());
+  for (const auto &[_, A] : Vec) {
 json::Object Loc{{"uri", A.Location.URI}};
 if (A.Location.Index.has_value()) {
   Loc["index"] = static_cast(*A.Location.Index);

diff  --git a/clang/unittests/Basic/SarifTest.cpp 
b/clang/unittests/Basic/SarifTest.cpp
index 33bccf56babb75..b7ddd8701d56d6 100644
--- a/clang/unittests/Basic/SarifTest.cpp
+++ b/clang/unittests/Basic/SarifTest.cpp
@@ -332,7 +332,7 @@ TEST_F(SarifDocumentWriterTest, checkSerializingArtifacts) {
 TEST_F(SarifDocumentWriterTest, checkSerializingCodeflows) {
   // GIVEN:
   const std::string ExpectedOutput =
-  
R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":28,"location":{"index":3,"uri":"file:///test-header-3.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":41,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]},{"length":30,"location":{"index":2,"uri":"file:///test-header-2.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":27,"location":{"index":1,"uri":"file:///test-header-1.h"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"codeFlows":[{"threadFlows":[{"locations":[{"importance":"essential","location":{"message":{"text":"Message
 
#1"},"physicalLocation":{"artifactLocation":{"index":1,"uri":"file:///test-header-1.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"important","location":{"message":{"text":"Message
 
#2"},"physicalLocation":{"artifactLocation":{"index":2,"uri":"file:///test-header-2.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"unimportant","location":{"message":{"text":"Message
 
#3"},"physicalLocation":{"artifactLocation":{"index":3,"uri":"file:///test-header-3.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1]}]}],"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:///main.cpp"},"region":{"endColumn":8,"endLine":2,"startColumn":5,"startLine":2}}}],"message":{"text":"Redefinition
 of 
'foo'"},"ruleId":"clang.unittest","ruleIndex":0}],"tool":{"driver":{"fullName":"sarif
 test 
runner","informationUri":"https://clang.llvm.org/docs/UsersManual.html","language":"en-US","name":"sarif
 
test","rules":[{"defaultConfiguration":{"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":"Example
 rule created during unit tests"},"id":"clang.unittest","name":"clang unit 
test"}],"version":"1.0.0"}}}],"version":"2.1.0"})";
+  
R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":41,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]},{"length":27,"location":{"index":1,"uri":"file:///test-header-1.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":30,"location":{"index":2,"uri":"file:///test-header-2.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":28,"location":{"index":3,"uri":"file:///test-header-3.h"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"codeFlows":[{"threadFlows":[{"locations":[{"importance":"essential","location":{"message":{"text":"Message
 
#1"},"physicalLocation":{"artifactLocation":{"index":1,"uri":"file:///test-header-1.h"},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"important","location":{"message":{"text":"Message
 

[clang] 99b2a11 - [Driver] -fopenmp-targets=: stabilize OrderedOffloadingToolchains value order

2023-07-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-20T21:17:04-07:00
New Revision: 99b2a1143f932c2da8395a69072f177f596547b2

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

LOG: [Driver] -fopenmp-targets=: stabilize OrderedOffloadingToolchains value 
order

to make actions deterministic.
StringSet iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/openmp-offload.c

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index fc52f47df00b5d..488350169efa49 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -70,7 +70,6 @@
 #include "clang/Driver/Types.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
@@ -100,6 +99,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #if LLVM_ON_UNIX
 #include  // getpid
@@ -858,7 +858,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
,
 
 llvm::StringMap> DerivedArchs;
 llvm::StringMap FoundNormalizedTriples;
-llvm::SmallVector OpenMPTriples;
+std::multiset OpenMPTriples;
 
 // If the user specified -fopenmp-targets= we create a toolchain for each
 // valid triple. Otherwise, if only --offload-arch= was specified we 
instead
@@ -870,7 +870,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
,
 << OpenMPTargets->getAsString(C.getInputArgs());
 return;
   }
-  llvm::copy(OpenMPTargets->getValues(), 
std::back_inserter(OpenMPTriples));
+  for (StringRef T : OpenMPTargets->getValues())
+OpenMPTriples.insert(T);
 } else if (C.getInputArgs().hasArg(options::OPT_offload_arch_EQ) &&
!IsHIP && !IsCuda) {
   const ToolChain *HostTC = 
C.getSingleOffloadToolChain();
@@ -925,7 +926,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
,
   }
 
   for (const auto  : DerivedArchs)
-OpenMPTriples.push_back(TripleAndArchs.first());
+OpenMPTriples.insert(TripleAndArchs.first());
 }
 
 for (StringRef Val : OpenMPTriples) {

diff  --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index e89d2099c01a8d..6bb10029b8ba5d 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -292,10 +292,10 @@
 // RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-NVIDIA-AMDGPU
 
 // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
+// CHECK-NVIDIA-AMDGPU: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[AMD_BC:.+]]"
 // CHECK-NVIDIA-AMDGPU: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[NVIDIA_PTX:.+]]"
 // CHECK-NVIDIA-AMDGPU: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[NVIDIA_PTX]]"], output: "[[NVIDIA_CUBIN:.+]]"
-// CHECK-NVIDIA-AMDGPU: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[AMD_BC:.+]]"
-// CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Packager", 
inputs: ["[[NVIDIA_CUBIN]]", "[[AMD_BC]]"], output: "[[BINARY:.*]]"
+// CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Packager", 
inputs: ["[[AMD_BC]]", "[[NVIDIA_CUBIN]]"], output: "[[BINARY:.*]]"
 // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]"
 // CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Linker", 
inputs: ["[[HOST_OBJ]]"], output: "a.out"
 

diff  --git a/clang/test/Driver/openmp-offload.c 
b/clang/test/Driver/openmp-offload.c
index 25ef25b7b32d53..9626c976d2c81c 100644
--- a/clang/test/Driver/openmp-offload.c
+++ b/clang/test/Driver/openmp-offload.c
@@ -128,17 +128,17 @@
 // CHK-PHASES-FILES-NEXT: 4: input, "[[INPUT]]", c, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 5: preprocessor, {4}, cpp-output, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 6: compiler, {5}, ir, (device-openmp)
-// CHK-PHASES-FILES-NEXT: 7: offload, "host-openmp (powerpc64-ibm-linux-gnu)" 
{3}, "device-openmp (x86_64-pc-linux-gnu)" {6}, ir
+// CHK-PHASES-FILES-NEXT: 7: offload, "host-openmp (powerpc64-ibm-linux-gnu)" 
{3}, "device-openmp (powerpc64-ibm-linux-gnu)" {6}, ir
 // CHK-PHASES-FILES-NEXT: 8: backend, {7}, assembler, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 9: assembler, {8}, object, (device-openmp)
-// CHK-PHASES-FILES-NEXT: 10: offload, "device-openmp (x86_64-pc-linux-gnu)" 
{9}, object
+// CHK-PHASES-FILES-NEXT: 10: 

[PATCH] D155501: Add new option -fkeep-persistent-storage-variables to Clang release notes

2023-07-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast accepted this revision.
hubert.reinterpretcast added a comment.
This revision is now accepted and ready to land.

LGTM; thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155501/new/

https://reviews.llvm.org/D155501

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


[PATCH] D153059: [-Wunsafe-buffer-usage] Group parameter fix-its

2023-07-20 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

I vote for splitting the patch to make both the review and any future debugging 
or git archeology easier.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153059/new/

https://reviews.llvm.org/D153059

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


[PATCH] D155674: [RISCV] Update zihintntl to 1p0

2023-07-20 Thread Piyou Chen via Phabricator via cfe-commits
BeMg abandoned this revision.
BeMg added a comment.

duplicate with https://reviews.llvm.org/D151547


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155674/new/

https://reviews.llvm.org/D155674

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


[clang] ac52488 - [clang] fix for D155342

2023-07-20 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-07-20T20:30:37-07:00
New Revision: ac524886094db58112ca176e1d727330a94634a8

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

LOG: [clang] fix for D155342

Added: 


Modified: 
clang/test/SemaCXX/goto2.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/goto2.cpp b/clang/test/SemaCXX/goto2.cpp
index 6fbe5b733f33c2..9b62a22cce9190 100644
--- a/clang/test/SemaCXX/goto2.cpp
+++ b/clang/test/SemaCXX/goto2.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++17 %s
 // expected-no-diagnostics
 
 //PR9463



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


[PATCH] D155863: [X86][Regcall] Add an option to respect regcall ABI v.4 in win64

2023-07-20 Thread Bing Yu via Phabricator via cfe-commits
yubing added a comment.

ping?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155863/new/

https://reviews.llvm.org/D155863

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D153536#4512897 , @dblaikie wrote:

> but at least at a first blush I can't reproduce the failures shown...

@dblaikie, you //did// reproduce the issue with the members. Both entries have 
DW_AT_decl_line 2 and DW_AT_data_member_location 0 (the second entry should 
indicate DW_AT_decl_line 3 and DW_AT_data_member_location 4):

>   0x002e:   DW_TAG_structure_type
>   DW_AT_calling_convention(DW_CC_pass_by_value)
>   DW_AT_name  ("t1")
>   DW_AT_byte_size (0x08)
>   DW_AT_decl_file 
> ("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
>   DW_AT_decl_line (1)
>   
>   0x0034: DW_TAG_member
> DW_AT_name("_")
> DW_AT_type(0x0047 "int")
> DW_AT_decl_file   
> ("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
> DW_AT_decl_line   (2)
> DW_AT_data_member_location(0x00)
>   
>   0x003d: DW_TAG_member
> DW_AT_name("_")
> DW_AT_type(0x0047 "int")
> DW_AT_decl_file   
> ("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
> DW_AT_decl_line   (2)
> DW_AT_data_member_location(0x00)
>   
>   0x0046: NULL

As for the block-scope case, I am still able to reproduce the issue (and also 
your result that does not exhibit the issue). The key seems to be having the 
`_`s on the same line.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

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


[PATCH] D154696: [Clang] Diagnose jumps into statement expressions

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D154696#4513510 , @cor3ntin wrote:

> FYI, this can be relanded after https://reviews.llvm.org/D155342 is merged

D155342  is all merged up


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154696/new/

https://reviews.llvm.org/D154696

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


[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf023f5cdb2e6: [clang][JumpDiagnostics] ignore non-asm goto 
target scopes (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/test/Sema/asm-goto.cpp
  clang/test/SemaCXX/goto2.cpp

Index: clang/test/SemaCXX/goto2.cpp
===
--- clang/test/SemaCXX/goto2.cpp
+++ clang/test/SemaCXX/goto2.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
 // expected-no-diagnostics
 
 //PR9463
@@ -46,3 +46,20 @@
 
 	return 0;
 }
+
+void asm_goto_try_catch() {
+  try {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  } catch(...) {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  };
+  if constexpr(false) {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  }
+}
Index: clang/test/Sema/asm-goto.cpp
===
--- clang/test/Sema/asm-goto.cpp
+++ clang/test/Sema/asm-goto.cpp
@@ -59,3 +59,13 @@
 loop:
   return 0;
 }
+
+void test4cleanup(int*);
+// No errors expected.
+void test4(void) {
+  asm goto(""l0);
+l0:;
+  int x __attribute__((cleanup(test4cleanup)));
+  asm goto(""l1);
+l1:;
+}
Index: clang/lib/Sema/JumpDiagnostics.cpp
===
--- clang/lib/Sema/JumpDiagnostics.cpp
+++ clang/lib/Sema/JumpDiagnostics.cpp
@@ -72,10 +72,9 @@
   SmallVector Jumps;
 
   SmallVector IndirectJumps;
-  SmallVector AsmJumps;
+  SmallVector IndirectJumpTargets;
   SmallVector MustTailStmts;
-  SmallVector IndirectJumpTargets;
-  SmallVector AsmJumpTargets;
+
 public:
   JumpScopeChecker(Stmt *Body, Sema );
 private:
@@ -86,7 +85,7 @@
   void BuildScopeInformation(Stmt *S, unsigned );
 
   void VerifyJumps();
-  void VerifyIndirectOrAsmJumps(bool IsAsmGoto);
+  void VerifyIndirectJumps();
   void VerifyMustTailStmts();
   void NoteJumpIntoScopes(ArrayRef ToScopes);
   void DiagnoseIndirectOrAsmJump(Stmt *IG, unsigned IGScope, LabelDecl *Target,
@@ -115,8 +114,7 @@
 
   // Check that all jumps we saw are kosher.
   VerifyJumps();
-  VerifyIndirectOrAsmJumps(false);
-  VerifyIndirectOrAsmJumps(true);
+  VerifyIndirectJumps();
   VerifyMustTailStmts();
 }
 
@@ -333,11 +331,8 @@
 // operand (to avoid recording the address-of-label use), which
 // works only because of the restricted set of expressions which
 // we detect as constant targets.
-if (cast(S)->getConstantTarget()) {
-  LabelAndGotoScopes[S] = ParentScope;
-  Jumps.push_back(S);
-  return;
-}
+if (cast(S)->getConstantTarget())
+  goto RecordJumpScope;
 
 LabelAndGotoScopes[S] = ParentScope;
 IndirectJumps.push_back(S);
@@ -354,27 +349,21 @@
   BuildScopeInformation(Var, ParentScope);
   ++StmtsToSkip;
 }
+goto RecordJumpScope;
+
+  case Stmt::GCCAsmStmtClass:
+if (!cast(S)->isAsmGoto())
+  break;
 [[fallthrough]];
 
   case Stmt::GotoStmtClass:
+  RecordJumpScope:
 // Remember both what scope a goto is in as well as the fact that we have
 // it.  This makes the second scan not have to walk the AST again.
 LabelAndGotoScopes[S] = ParentScope;
 Jumps.push_back(S);
 break;
 
-  case Stmt::GCCAsmStmtClass:
-if (auto *GS = dyn_cast(S))
-  if (GS->isAsmGoto()) {
-// Remember both what scope a goto is in as well as the fact that we
-// have it.  This makes the second scan not have to walk the AST again.
-LabelAndGotoScopes[S] = ParentScope;
-AsmJumps.push_back(GS);
-for (auto *E : GS->labels())
-  AsmJumpTargets.push_back(E->getLabel());
-  }
-break;
-
   case Stmt::IfStmtClass: {
 IfStmt *IS = cast(S);
 if (!(IS->isConstexpr() || IS->isConsteval() ||
@@ -666,6 +655,22 @@
   continue;
 }
 
+// If an asm goto jumps to a different scope, things like destructors or
+// initializers might not be run which may be suprising to users. Perhaps
+// this behavior can be changed in the future, but today Clang will not
+// generate such code. Produce a diagnostic instead. See also the
+// discussion here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110728.
+if (auto *G = dyn_cast(Jump)) {
+  for (AddrLabelExpr *L : G->labels()) {
+LabelDecl *LD = L->getLabel();
+unsigned JumpScope = LabelAndGotoScopes[G];
+unsigned TargetScope = LabelAndGotoScopes[LD->getStmt()];
+if (JumpScope != TargetScope)
+  DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
+  }
+  continue;
+}
+
 // We only 

[clang] f023f5c - [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-20 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2023-07-20T19:58:22-07:00
New Revision: f023f5cdb2e6c19026f04a15b5a935c041835d14

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

LOG: [clang][JumpDiagnostics] ignore non-asm goto target scopes

The current behavior of JumpScopeChecker::VerifyIndirectOrAsmJumps was
to cross validate the scope of every jumping statement (goto, asm goto)
against the scope of every label (even if the label was not even a
possible target of the asm goto).

When we have multiple asm goto's with unique targets, we could trigger
false positive build errors complaining that labels that weren't even in
the asm goto's label list could not be jumped to.  Example:

error: cannot jump from this asm goto statement to one of its possible 
targets
asm goto(""foo);
note: possible target of asm goto statement
bar:
^

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1886

Reviewed By: void, jyu2, rjmccall

Differential Revision: https://reviews.llvm.org/D155342

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/JumpDiagnostics.cpp
clang/test/Sema/asm-goto.cpp
clang/test/SemaCXX/goto2.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bb9daddef8d198..05a7ec04d60c31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -657,6 +657,9 @@ Bug Fixes in This Version
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Fixed false positive error diagnostic observed from mixing ``asm goto`` with
+  ``__attribute__((cleanup()))`` variables falsely warning that jumps to
+  non-targets would skip cleanup.
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index 4752f8af07d05c..5a6df56323a98b 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -72,10 +72,9 @@ class JumpScopeChecker {
   SmallVector Jumps;
 
   SmallVector IndirectJumps;
-  SmallVector AsmJumps;
+  SmallVector IndirectJumpTargets;
   SmallVector MustTailStmts;
-  SmallVector IndirectJumpTargets;
-  SmallVector AsmJumpTargets;
+
 public:
   JumpScopeChecker(Stmt *Body, Sema );
 private:
@@ -86,7 +85,7 @@ class JumpScopeChecker {
   void BuildScopeInformation(Stmt *S, unsigned );
 
   void VerifyJumps();
-  void VerifyIndirectOrAsmJumps(bool IsAsmGoto);
+  void VerifyIndirectJumps();
   void VerifyMustTailStmts();
   void NoteJumpIntoScopes(ArrayRef ToScopes);
   void DiagnoseIndirectOrAsmJump(Stmt *IG, unsigned IGScope, LabelDecl *Target,
@@ -115,8 +114,7 @@ JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema )
 
   // Check that all jumps we saw are kosher.
   VerifyJumps();
-  VerifyIndirectOrAsmJumps(false);
-  VerifyIndirectOrAsmJumps(true);
+  VerifyIndirectJumps();
   VerifyMustTailStmts();
 }
 
@@ -333,11 +331,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 // operand (to avoid recording the address-of-label use), which
 // works only because of the restricted set of expressions which
 // we detect as constant targets.
-if (cast(S)->getConstantTarget()) {
-  LabelAndGotoScopes[S] = ParentScope;
-  Jumps.push_back(S);
-  return;
-}
+if (cast(S)->getConstantTarget())
+  goto RecordJumpScope;
 
 LabelAndGotoScopes[S] = ParentScope;
 IndirectJumps.push_back(S);
@@ -354,27 +349,21 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
   BuildScopeInformation(Var, ParentScope);
   ++StmtsToSkip;
 }
+goto RecordJumpScope;
+
+  case Stmt::GCCAsmStmtClass:
+if (!cast(S)->isAsmGoto())
+  break;
 [[fallthrough]];
 
   case Stmt::GotoStmtClass:
+  RecordJumpScope:
 // Remember both what scope a goto is in as well as the fact that we have
 // it.  This makes the second scan not have to walk the AST again.
 LabelAndGotoScopes[S] = ParentScope;
 Jumps.push_back(S);
 break;
 
-  case Stmt::GCCAsmStmtClass:
-if (auto *GS = dyn_cast(S))
-  if (GS->isAsmGoto()) {
-// Remember both what scope a goto is in as well as the fact that we
-// have it.  This makes the second scan not have to walk the AST again.
-LabelAndGotoScopes[S] = ParentScope;
-AsmJumps.push_back(GS);
-for (auto *E : GS->labels())
-  AsmJumpTargets.push_back(E->getLabel());
-  }
-break;
-
   case Stmt::IfStmtClass: {
 IfStmt *IS = cast(S);
 if (!(IS->isConstexpr() || IS->isConsteval() ||
@@ -666,6 +655,22 @@ void JumpScopeChecker::VerifyJumps() {
   continue;
 }
 
+// If an asm goto 

[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.



Comment at: clang/lib/Sema/JumpDiagnostics.cpp:669
+if (JumpScope != TargetScope)
+  DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
+  }

shafik wrote:
> Do we have a test that checks this diagnostic?
Yes, //all// of the existing tests in clang/test/Sema/asm-goto.cpp are a result 
of this statement.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-20 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

> In GCC I added the numbers for "loongarch64" and "la464" although they are 
> the same, and GCC does not have "empty".  But yes we can do things later here.

Ah, I just realize `TuneCPU` is always not empty because:

  27 LoongArchSubtarget ::initializeSubtargetDependencies(
  28 const Triple , StringRef CPU, StringRef TuneCPU, StringRef FS,
  29 StringRef ABIName) {
  30   bool Is64Bit = TT.isArch64Bit();
  31   if (CPU.empty() || CPU == "generic")
  32 CPU = Is64Bit ? "generic-la64" : "generic-la32"; // empty CPU will be 
converted to generic-la{64,32}
  33 
  34   if (TuneCPU.empty())
  35 TuneCPU = CPU; // empty TuneCPU will be converted to CPU, so TuneCPU 
is not empty when we all initializeProperties below
  36 
  37   ParseSubtargetFeatures(CPU, TuneCPU, FS);
  38   initializeProperties(TuneCPU);

So, the problem is how to set numbers for `generic-la{64,32}` ? Currenly if we 
directly use `clang hello.c`, `TuneCPU` is `generic-la64`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1925
 // CHECK_GNR_M64: #define __AMX_BF16__ 1
-// CHECK_GNR_M64: #define __AMX_COMPLEX__ 1
+// CHECK_GNR_M64-NOT: #define __AMX_COMPLEX__ 1
+// CHECK_GNRD_M64: #define __AMX_COMPLEX__ 1

FreddyYe wrote:
> RKSimon wrote:
> > Won't this fail on the graniterapids-d run?
> Whops, I didn't realize this problem before! But it indeed doesn't fail. Need 
> to figure out why...
I'm guessing when using multi prefixes, it will try to match with the second 
one if the first failed. It's common and easy to understand for positive check 
but a bit confusing for negative one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155798/new/

https://reviews.llvm.org/D155798

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-20 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D155824#4521047 , @SixWeining 
wrote:

> In D155824#4518597 , @xry111 wrote:
>
>> Do we need to convert Xuerui's label alignment change to use the -mtune 
>> framework?
>
> How to set the numbers if `TuneCPU` is empty? If there is no differences 
> among `empty`, `loongarch64` and `la464`, seems it's better to do this until 
> we support other uarchs, e.g. `la[236]64`.
>
> Just like the `TODO` in D148622 :
>
>   63   // TODO: Check TuneCPU and override defaults (that are for LA464) once 
> we
>   64   // support optimizing for more uarchs.

In GCC I added the numbers for "loongarch64" and "la464" although they are the 
same, and GCC does not have "empty".  But yes we can do things later here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

2023-07-20 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 542743.
philnik added a comment.

- Address comments
- Try to fix CI
- Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151683/new/

https://reviews.llvm.org/D151683

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/AST/ast-dump-attr.m
  clang/test/AST/ast-dump-c-attr.c
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGen/attr-btf_type_tag-func.c
  clang/test/CodeGen/attr-btf_type_tag-var.c
  clang/test/Frontend/noderef.c
  clang/test/OpenMP/assumes_messages_attr.c
  clang/test/OpenMP/openmp_attribute_compat.cpp
  clang/test/Parser/asm.c
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/c2x-attributes.m
  clang/test/Parser/cxx-decl.cpp
  clang/test/Parser/objc-attr.m
  clang/test/ParserHLSL/group_shared.hlsl
  clang/test/Preprocessor/has_c_attribute.c
  clang/test/Sema/annotate-type.c
  clang/test/Sema/annotate.c
  clang/test/Sema/attr-availability-square-brackets.c
  clang/test/Sema/attr-external-source-symbol-cxx.cpp
  clang/test/Sema/attr-external-source-symbol.c
  clang/test/Sema/attr-likelihood.c
  clang/test/Sema/attr-objc-bridge-related.m
  clang/test/Sema/attr-regparm.c
  clang/test/Sema/attr-type-safety.c
  clang/test/Sema/c2x-attr.c
  clang/test/Sema/c2x-noreturn.c
  clang/test/Sema/internal_linkage.c
  clang/test/Sema/matrix-type-builtins.c
  clang/test/Sema/neon-vector-types.c
  clang/test/Sema/overload-arm-mve.c
  clang/test/Sema/overloadable.c
  clang/test/Sema/vector-gcc-compat.c
  clang/test/SemaCXX/attr-cxx-disabled.cpp
  clang/test/SemaCXX/cxx98-compat.cpp
  clang/test/SemaCXX/warn-c++11-extensions.cpp
  clang/test/SemaObjC/attr-objc-gc.m
  clang/unittests/AST/AttrTest.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -575,7 +575,6 @@
 // FIXME: We should ask the driver for the appropriate default flags.
 lang_opts.GNUMode = true;
 lang_opts.GNUKeywords = true;
-lang_opts.DoubleSquareBracketAttributes = true;
 lang_opts.CPlusPlus11 = true;
 
 // The Darwin libc expects this macro to be set.
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3394,14 +3394,10 @@
   // If this is the C++11 variety, also add in the LangOpts test.
   if (Variety == "CXX11")
 Test += " && LangOpts.CPlusPlus11";
-  else if (Variety == "C2x")
-Test += " && LangOpts.DoubleSquareBracketAttributes";
 } else if (Variety == "CXX11")
   // C++11 mode should be checked against LangOpts, which is presumed to be
   // present in the caller.
   Test = "LangOpts.CPlusPlus11";
-else if (Variety == "C2x")
-  Test = "LangOpts.DoubleSquareBracketAttributes";
 
 std::string TestStr = !Test.empty()
   ? Test + " ? " + llvm::itostr(Version) + " : 0"
Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -157,7 +157,7 @@
   AST = buildASTFromCodeWithArgs(R"c(
 __auto_type [[clang::annotate_type("auto")]] auto_var = 1;
   )c",
- {"-fdouble-square-bracket-attributes"},
+ {},
  "input.c");
 
   {
Index: clang/test/SemaObjC/attr-objc-gc.m
===
--- clang/test/SemaObjC/attr-objc-gc.m
+++ clang/test/SemaObjC/attr-objc-gc.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 static id __attribute((objc_gc(weak))) a;
 static id __attribute((objc_gc(strong))) b;
 
Index: clang/test/SemaCXX/warn-c++11-extensions.cpp
===
--- clang/test/SemaCXX/warn-c++11-extensions.cpp
+++ clang/test/SemaCXX/warn-c++11-extensions.cpp
@@ -7,3 +7,5 @@
 
 enum struct E1 { A, B }; // expected-warning {{scoped enumerations are a C++11 extension}}
 enum class E2 { C, D }; // expected-warning {{scoped enumerations are a C++11 extension}}
+
+[[]] void 

[PATCH] D154931: [LoongArch] Support InlineAsm for LSX and LASX

2023-07-20 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:56
 addRegisterClass(MVT::f64, ::FPR64RegClass);
+  if (Subtarget.hasExtLSX()) {
+for (auto VT : {MVT::v4f32, MVT::v2f64, MVT::v16i8, MVT::v8i16, MVT::v4i32,

useless brace



Comment at: llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll:40
+
+;; The lower 64-bit of the vector register '$xr31' is same as the
+;; floating-point register '$f31' ('$fs7'). And '$f31' ('$fs7')

`overlapped with` is more accurate.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154931/new/

https://reviews.llvm.org/D154931

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


[PATCH] D155861: [Headers][doc] Add SHA1/SHA256 intrinsic descriptions

2023-07-20 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155861/new/

https://reviews.llvm.org/D155861

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-20 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

In D155824#4518597 , @xry111 wrote:

> Do we need to convert Xuerui's label alignment change to use the -mtune 
> framework?

How to set the numbers if `TuneCPU` is empty? If there is no differences among 
`empty`, `loongarch64` and `la464`, seems it's better to do this until we 
support other uarchs, e.g. `la[236]64`.

Just like the `TODO` in D148622 :

  63   // TODO: Check TuneCPU and override defaults (that are for LA464) once we
  64   // support optimizing for more uarchs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D150338: [-Wunsafe-buffer-usage] Improving insertion of the [[clang::unsafe_buffer_usage]] attribute

2023-07-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Looks like the patch has landed, let's close the revision? 樂


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150338/new/

https://reviews.llvm.org/D150338

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


[PATCH] D155859: [Headers][doc] Add misc non-AVX2 intrinsic descriptions

2023-07-20 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/rdseedintrin.h:56
+/// ELSE
+///   Store16(__p, 0)
+///   result := 0

32



Comment at: clang/lib/Headers/rdseedintrin.h:84
+/// ELSE
+///   Store16(__p, 0)
+///   result := 0

64



Comment at: clang/lib/Headers/xsavecintrin.h:34
+/// ENDFOR
+/// __p.Header.XSTATE_BV := mask
+/// \endcode

It's not `mask` but `mask AND XINUSE[62:0]`. The bit[1] also relies on `MXCSR ≠ 
1F80H`. I think we can simply use `__p.Header.XSTATE_BV[62:0] := 
INIT_FUNCTION(mask[62:0])`



Comment at: clang/lib/Headers/xsavecintrin.h:65
+/// ENDFOR
+/// __p.Header.XSTATE_BV := mask
+/// \endcode

ditto.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155859/new/

https://reviews.llvm.org/D155859

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


[PATCH] D153059: [-Wunsafe-buffer-usage] Group parameter fix-its

2023-07-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I just want to add to this, that the NFC part is actually insanely valuable 
(despite technically not doing anything). This patch is so complex primarily 
because `UnsafeBufferUsage.cpp` already has 1300 lines of code in unstructured 
static functions - that's more than half of our code! I really appreciate every 
bit of effort to separate it into components with clear boundaries and 
contracts, and even the new comments really help 梁


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153059/new/

https://reviews.llvm.org/D153059

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


[PATCH] D155396: [Sema][ObjC] Propagating value-dependent errors into BlockExpr

2023-07-20 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 542735.
danix800 edited the summary of this revision.
danix800 added a comment.
Herald added a reviewer: gkistanova.

Update clang/docs/ReleaseNotes.rst to reflect this fix.


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155396/new/

https://reviews.llvm.org/D155396

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaObjC/crash-on-val-dep-block-expr.m


Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m
===
--- /dev/null
+++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// no crash
+
+int (^a)() = ^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+};
+
+int (^b)() = (^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+});
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3730,6 +3730,13 @@
   if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
 
+  if (auto *CurBlock = dyn_cast(CurCap);
+  CurBlock && CurCap->HasImplicitReturnType) {
+BlockDecl *BD = CurBlock->TheDecl;
+if (!BD->isInvalidDecl() && RetValExp && RetValExp->containsErrors())
+  BD->setInvalidDecl();
+  }
+
   return Result;
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17159,6 +17159,9 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  if (BD->isInvalidDecl())
+return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(),
+  {Result}, Result->getType());
   return Result;
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -657,6 +657,10 @@
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Invalidate BlockDecl with implicit return type, in case any of the return
+  value exprs is invalid. Propagating the error info up by replacing BlockExpr
+  with a RecoveryExpr. This fixes:
+  (`#63863 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m
===
--- /dev/null
+++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// no crash
+
+int (^a)() = ^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+};
+
+int (^b)() = (^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+});
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3730,6 +3730,13 @@
   if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
 
+  if (auto *CurBlock = dyn_cast(CurCap);
+  CurBlock && CurCap->HasImplicitReturnType) {
+BlockDecl *BD = CurBlock->TheDecl;
+if (!BD->isInvalidDecl() && RetValExp && RetValExp->containsErrors())
+  BD->setInvalidDecl();
+  }
+
   return Result;
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17159,6 +17159,9 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  if (BD->isInvalidDecl())
+return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(),
+  {Result}, Result->getType());
   return Result;
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -657,6 +657,10 @@
   (`#63169 _`)
 - Fix crash when casting an object to an array type.
   (`#63758 _`)
+- Invalidate BlockDecl with implicit return type, in case any of the return
+  value exprs is invalid. Propagating the error info up by replacing BlockExpr
+  with a RecoveryExpr. This fixes:
+  (`#63863 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-07-20 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 542732.
ellis added a comment.

If `#!special-case-list-v2` is the first line in the special case list, then we 
will use globs to match patterns. Otherwise, we fall back to the original 
behavior of using regexes to match patterns. Once this feature is stable, and 
after a version cut, we can remove the regex case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string ) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string ,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,29 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(Error, "malformed section at line 2: '[': invalid glob pattern: [");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));

[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked an inline comment as done.
FreddyYe added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1925
 // CHECK_GNR_M64: #define __AMX_BF16__ 1
-// CHECK_GNR_M64: #define __AMX_COMPLEX__ 1
+// CHECK_GNR_M64-NOT: #define __AMX_COMPLEX__ 1
+// CHECK_GNRD_M64: #define __AMX_COMPLEX__ 1

RKSimon wrote:
> Won't this fail on the graniterapids-d run?
Whops, I didn't realize this problem before! But it indeed doesn't fail. Need 
to figure out why...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155798/new/

https://reviews.llvm.org/D155798

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


[PATCH] D154007: Reland "Try to implement lambdas with inalloca parameters by forwarding without use of inallocas."

2023-07-20 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGClass.cpp:3095
+  StringRef CallOpName = CallOpFn->getName();
+  std::string ImplName = ("__impl" + CallOpName).str();
+

The old code tried to find the "" part of the function name and 
replace the front with "?__impl@", so that the function name was consistent 
with the mangling scheme.  But apparently there are some cases where when the 
function name is too long, it uses a hash instead (?), so the attempt to find 
the  was failing. 

I couldn't find a good way to name this function through the actual mangling 
code -- is it fine to just add "__impl" to the front and have it not be mangled 
correctly? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154007/new/

https://reviews.llvm.org/D154007

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


[clang] 2565887 - [clang][test] Remove unused variable 'SM' (NFC)

2023-07-20 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2023-07-21T07:59:30+08:00
New Revision: 25658879a022ca9a8d91ed214701bfd724d159a8

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

LOG: [clang][test] Remove unused variable 'SM' (NFC)

/data/llvm-project/clang/unittests/AST/DeclTest.cpp:153:18: error: unused 
variable 'SM' [-Werror,-Wunused-variable]
  SourceManager  = Ctx.getSourceManager();
 ^
1 error generated.

Added: 


Modified: 
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/DeclTest.cpp 
b/clang/unittests/AST/DeclTest.cpp
index 54a1f2c5843548..2ed2ed750941c4 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -150,7 +150,6 @@ TEST(Decl, ConceptDecl) {
 
   auto AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
   ASTContext  = AST->getASTContext();
-  SourceManager  = Ctx.getSourceManager();
 
   const auto *Decl =
   selectFirst("decl", match(conceptDecl().bind("decl"), Ctx));



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


[PATCH] D143109: [Sema] Push a LambdaScopeInfo before calling SubstDefaultArgument

2023-07-20 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak abandoned this revision.
ahatanak added a comment.

It looks like a7579b25df78a9f53d62300020d4ae3c4734 
 fixed the 
crash. Thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143109/new/

https://reviews.llvm.org/D143109

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


[PATCH] D154007: Reland "Try to implement lambdas with inalloca parameters by forwarding without use of inallocas."

2023-07-20 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 542721.
akhuang added a comment.

Change impl function naming scheme


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154007/new/

https://reviews.llvm.org/D154007

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenTypes.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/test/CodeGenCXX/inalloca-lambda.cpp

Index: clang/test/CodeGenCXX/inalloca-lambda.cpp
===
--- clang/test/CodeGenCXX/inalloca-lambda.cpp
+++ clang/test/CodeGenCXX/inalloca-lambda.cpp
@@ -1,11 +1,63 @@
-// RUN: not %clang_cc1 -triple i686-windows-msvc -emit-llvm -o /dev/null %s  2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -o - %s  2>&1 | FileCheck %s
 
-// PR28299
-// CHECK: error: cannot compile this forwarded non-trivially copyable parameter yet
-
-class A {
+struct A {
+  A();
   A(const A &);
+  int x;
 };
-typedef void (*fptr_t)(A);
-fptr_t fn1() { return [](A) {}; }
+void decayToFp(int (*f)(A));
+void test() {
+  auto ld = [](A a) {
+static int calls = 0;
+++calls;
+return a.x + calls;
+  };
+  decayToFp(ld);
+  ld(A{});
+}
+
+// CHECK: define internal x86_thiscallcc noundef i32
+// CHECK-SAME: @"??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %[[V:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32
+// CHECK-SAME: @"__impl??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[V]])
+
+// CHECK: define internal noundef i32
+// CHECK-SAME: @"?__invoke@@?0??test@@YAXXZ@CA?A?@@UA@@@Z"
+// CHECK-SAME: (ptr inalloca(<{ %struct.A }>) %[[ARG:.*]])
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: %[[VAR:.*]] = getelementptr inbounds <{ %struct.A }>, ptr %[[ARG]], i32 0, i32 0
+// CHECK: %call = call x86_thiscallcc noundef i32
+// CHECK-SAME: @"__impl??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %unused.capture, ptr noundef %[[VAR]])
+// CHECK: ret i32 %call
+
+// CHECK: define internal x86_thiscallcc noundef i32
+// CHECK-SAME: @"__impl??R@?0??test@@YAXXZ@QBE?A?@@UA@@@Z"
+// CHECK-SAME: (ptr noundef %this, ptr noundef %[[ARG:.*]])
+// CHECK: %this.addr = alloca ptr, align 4
+// CHECK: store ptr %this, ptr %this.addr, align 4
+// CHECK: %this1 = load ptr, ptr %this.addr, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %inc = add nsw i32 %{{.*}}, 1
+// CHECK: store i32 %inc, ptr @"?calls@?1???R
+// CHECK: %{{.*}} = getelementptr inbounds %struct.A, ptr %{{.*}}, i32 0, i32 0
+// CHECK: %{{.*}} = load i32, ptr %{{.*}}, align 4
+// CHECK: %{{.*}} = load i32, ptr @"?calls@?1???R
+// CHECK: %add = add nsw i32 %{{.*}}, %{{.*}}
+// CHECK: ret i32 %add
+
+// Make sure we don't try to copy an uncopyable type.
+struct B {
+  B();
+  B(B &);
+  void operator=(B);
+  long long x;
+} b;
+
+void f() {
+  [](B) {}(b);
+}
 
Index: clang/lib/CodeGen/Targets/X86.cpp
===
--- clang/lib/CodeGen/Targets/X86.cpp
+++ clang/lib/CodeGen/Targets/X86.cpp
@@ -140,7 +140,8 @@
 
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState ) const;
-  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ) const;
+  ABIArgInfo classifyArgumentType(QualType RetTy, CCState ,
+  bool isDelegateCall) const;
 
   /// Updates the number of available free registers, returns
   /// true if any registers were allocated.
@@ -737,8 +738,8 @@
   }
 }
 
-ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
-   CCState ) const {
+ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState ,
+   bool isDelegateCall) const {
   // FIXME: Set alignment on indirect arguments.
   bool IsFastCall = State.CC == llvm::CallingConv::X86_FastCall;
   bool IsRegCall = State.CC == llvm::CallingConv::X86_RegCall;
@@ -753,6 +754,12 @@
 CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
 if (RAA == CGCXXABI::RAA_Indirect) {
   return getIndirectResult(Ty, false, State);
+} else if (isDelegateCall) {
+  // Avoid having different alignments on delegate call args by always
+  // setting the alignment to 4, which is what we do for inallocas.
+  ABIArgInfo Res = getIndirectResult(Ty, false, State);
+  Res.setIndirectAlign(CharUnits::fromQuantity(4));
+  return Res;
 } else if (RAA == CGCXXABI::RAA_DirectInMemory) {
   // The field 

[PATCH] D155549: [clang] adds `conceptDecl` as an ASTMatcher

2023-07-20 Thread Christopher Di Bella via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38e1c597033d: [clang] adds `conceptDecl` as an ASTMatcher 
(authored by cjdb).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155549/new/

https://reviews.llvm.org/D155549

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -12,9 +12,11 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -140,6 +142,22 @@
   ASSERT_TRUE(0 == MangleB.compare("_ZTSAT0__T_"));
 }
 
+TEST(Decl, ConceptDecl) {
+  llvm::StringRef Code(R"(
+template
+concept integral = __is_integral(T);
+  )");
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
+  ASTContext  = AST->getASTContext();
+  SourceManager  = Ctx.getSourceManager();
+
+  const auto *Decl =
+  selectFirst("decl", match(conceptDecl().bind("decl"), Ctx));
+  ASSERT_TRUE(Decl != nullptr);
+  EXPECT_EQ(Decl->getName(), "integral");
+}
+
 TEST(Decl, EnumDeclRange) {
   llvm::Annotations Code(R"(
 typedef int Foo;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -172,6 +172,7 @@
   REGISTER_MATCHER(compoundLiteralExpr);
   REGISTER_MATCHER(compoundStmt);
   REGISTER_MATCHER(coawaitExpr);
+  REGISTER_MATCHER(conceptDecl);
   REGISTER_MATCHER(conditionalOperator);
   REGISTER_MATCHER(constantArrayType);
   REGISTER_MATCHER(constantExpr);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -800,6 +800,7 @@
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
+const internal::VariadicDynCastAllOfMatcher conceptDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1334,6 +1334,16 @@
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeductionGuideDecl;
 
+/// Matches concept declarations.
+///
+/// Example matches integral
+/// \code
+///   template
+///   concept integral = std::is_integral_v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+conceptDecl;
+
 /// Matches variable declarations.
 ///
 /// Note: this does not match declarations of member variables, which are
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -262,6 +262,7 @@
 - Added ``__builtin_elementwise_nearbyint`` for floating point
   types. This allows access to ``llvm.nearbyint`` for arbitrary
   floating-point and vector of floating-point types.
+- Clang AST matcher now matches concept declarations with `conceptDecl`.
 
 New Compiler Flags
 --
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -682,6 +682,15 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclconceptDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ConceptDecl.html;>ConceptDecl...
+Matches concept declarations.
+
+Example matches integral
+  templatetypename T
+  concept integral = std::is_integral_vT;
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclcxxConstructorDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html;>CXXConstructorDecl...
 Matches C++ constructor declarations.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38e1c59 - [clang] adds `conceptDecl` as an ASTMatcher

2023-07-20 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2023-07-20T23:33:46Z
New Revision: 38e1c597033de0c7655abb39335b364408865d2a

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

LOG: [clang] adds `conceptDecl` as an ASTMatcher

Closes #63934

Differential Revision: https://reviews.llvm.org/D155549

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index b4f282fbf43816..4f2a1f9508baa2 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -682,6 +682,15 @@ Node Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclconceptDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ConceptDecl.html;>ConceptDecl...
+Matches concept 
declarations.
+
+Example matches integral
+  templatetypename T
+  concept integral = std::is_integral_vT;
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclcxxConstructorDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html;>CXXConstructorDecl...
 Matches C++ 
constructor declarations.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f1d098ef02f41d..bb9daddef8d198 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -262,6 +262,7 @@ Non-comprehensive list of changes in this release
 - Added ``__builtin_elementwise_nearbyint`` for floating point
   types. This allows access to ``llvm.nearbyint`` for arbitrary
   floating-point and vector of floating-point types.
+- Clang AST matcher now matches concept declarations with `conceptDecl`.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a9313139226ca4..f49204a3d90626 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1334,6 +1334,16 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeductionGuideDecl;
 
+/// Matches concept declarations.
+///
+/// Example matches integral
+/// \code
+///   template
+///   concept integral = std::is_integral_v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+conceptDecl;
+
 /// Matches variable declarations.
 ///
 /// Note: this does not match declarations of member variables, which are

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index ad6b20f4fd2ff8..3470467112dd5f 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -800,6 +800,7 @@ const internal::VariadicDynCastAllOfMatcher 
tagDecl;
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
+const internal::VariadicDynCastAllOfMatcher conceptDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index d3594455b55a46..1098df032a64b9 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -172,6 +172,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(compoundLiteralExpr);
   REGISTER_MATCHER(compoundStmt);
   REGISTER_MATCHER(coawaitExpr);
+  REGISTER_MATCHER(conceptDecl);
   REGISTER_MATCHER(conditionalOperator);
   REGISTER_MATCHER(constantArrayType);
   REGISTER_MATCHER(constantExpr);

diff  --git a/clang/unittests/AST/DeclTest.cpp 
b/clang/unittests/AST/DeclTest.cpp
index 463f35c1cd08b7..54a1f2c5843548 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -12,9 +12,11 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -140,6 +142,22 @@ TEST(Decl, MangleDependentSizedArray) {
   ASSERT_TRUE(0 == MangleB.compare("_ZTSAT0__T_"));
 }
 
+TEST(Decl, ConceptDecl) {
+  llvm::StringRef Code(R"(
+template
+concept integral = __is_integral(T);
+  )");
+
+  auto AST = 

[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-07-20 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

In D149162#4520747 , @MaskRay wrote:

> In D149162#4520497 , @agozillon 
> wrote:
>
>> In D149162#4520395 , @MaskRay 
>> wrote:
>>
>>> In D149162#4517500 , @MaskRay 
>>> wrote:
>>>
 `registerTargetGlobalVariable` relies on the iteration order of StringMap, 
 which is not guaranteed. The bug is caught by D155789 
 

   curl -L 'https://reviews.llvm.org/D155789?download=1' | patch -p1
   cmake ... -DLLVM_ENABLE_REVERSE_ITERATION=on
   ninja -C ... check-llvm-unit  #  `LLVM-Unit :: 
 Frontend/./LLVMFrontendTests/OpenMPIRBuilderTest/registerTargetGlobalVariable`
  fails
>>>
>>> Looks like the issue might be introduced by 
>>> 03f270c900e1f8563419fdd302683a9503e98722 in the iteration order of 
>>> `OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar` (a 
>>> StringMap).
>>> Unfortunately, changing it to `MapVector>> OffloadEntryInfoDeviceGlobalVar>` will break other tests like 
>>> `clang/test/OpenMP/declare_target_codegen.cpp`, which suggests that there 
>>> are other weird iteration order dependent behavior.
>>> Hopefully someone familiar with OpenMP can investigate :)
>>
>> I wasn't the original creator of this segment of code 
>> (03f270c900e1f8563419fdd302683a9503e98722) unfortunately, I just moved it 
>> into the OMPIRBuilder with some slight modifications, I can investigate it 
>> but I will unfortunately be on vacation from tomorrow onwards until the 9th 
>> of August, so if it is urgent it'd greatly be appreciated if someone else 
>> could have a look into it. Otherwise, I can pick it up when I get back.
>>
>> If it is just the test added by this patch that is causing breakage and it 
>> affects no other OpenMP components currently, then you could perhaps 
>> deactivate this test for the time being until I can get time to look at it, 
>> if no one else has a moment to spare. It is perhaps because I am verifying 
>> the index value that's given to each piece of metadata/named global (e.g. 
>> test_data_int_1_decl_tgt_ref_ptr) and expecting they will remain the same in 
>> every case for this test, but with the introduction of 
>> LLVM_ENABLE_REVERSE_ITERATION that's perhaps no longer the case.
>>
>> I am very sorry for the trouble.
>
> Thank you for offering help! No hurry. For `LLVM_ENABLE_REVERSE_ITERATION`, 
> my commit 14c55e6e2fa1c342a1ef908445db3d31a3475485 
>  has 
> worked for me.
>
> The underlying issue  that `!omp_offload.info` has an operand order that is 
> dependent on `StringMap` can be fixed later :) FWIW one of my attempts was:
>
>   --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
>   +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
>   @@ -5982,8 +5982,12 @@ void 
> OffloadEntriesInfoManager::registerDeviceGlobalVarEntryInfo(
>void OffloadEntriesInfoManager::actOnDeviceGlobalVarEntriesInfo(
>const OffloadDeviceGlobalVarEntryInfoActTy ) {
>  // Scan all target region entries and perform the provided action.
>   +  SmallVector, 0> 
> Vec;
>  for (const auto  : OffloadEntriesDeviceGlobalVar)
>   -Action(E.getKey(), E.getValue());
>   +Vec.emplace_back(E.getKey(), E.getValue());
>   +  llvm::sort(Vec, less_first());
>   +  for (const auto  : Vec)
>   +Action(E.first, E.second);
>}
>   
>void CanonicalLoopInfo::collectControlBlocks(
>
> and it would break `clang/test/OpenMP/declare_target_codegen.cpp`, so I 
> didn't investigate further.

Thank you very much for looking into it and fixing it for the time being, I'm 
sorry for the bother! I'll add it to my TODO list for when I get back to have a 
deeper look into it, if someone else doesn't get to it first.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149162/new/

https://reviews.llvm.org/D149162

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


[PATCH] D155890: [clang-tidy] Add folly::Optional to unchecked-optional-access

2023-07-20 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added a comment.
This revision is now accepted and ready to land.

Thank you! Do you have commit access or do you need me to commit this patch for 
you?




Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:843
 
+  // optional::hasValue for folly::Optional
+  .CaseOfCFGStmt(




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155890/new/

https://reviews.llvm.org/D155890

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


[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-07-20 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a reviewer: clang-language-wg.
shafik added a comment.

I am not sure about this change but I think we at least need a test and this 
does not seem non-functional if it prevents a crash.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155809/new/

https://reviews.llvm.org/D155809

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


[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D149162#4520497 , @agozillon wrote:

> In D149162#4520395 , @MaskRay wrote:
>
>> In D149162#4517500 , @MaskRay 
>> wrote:
>>
>>> `registerTargetGlobalVariable` relies on the iteration order of StringMap, 
>>> which is not guaranteed. The bug is caught by D155789 
>>> 
>>>
>>>   curl -L 'https://reviews.llvm.org/D155789?download=1' | patch -p1
>>>   cmake ... -DLLVM_ENABLE_REVERSE_ITERATION=on
>>>   ninja -C ... check-llvm-unit  #  `LLVM-Unit :: 
>>> Frontend/./LLVMFrontendTests/OpenMPIRBuilderTest/registerTargetGlobalVariable`
>>>  fails
>>
>> Looks like the issue might be introduced by 
>> 03f270c900e1f8563419fdd302683a9503e98722 in the iteration order of 
>> `OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar` (a 
>> StringMap).
>> Unfortunately, changing it to `MapVector> OffloadEntryInfoDeviceGlobalVar>` will break other tests like 
>> `clang/test/OpenMP/declare_target_codegen.cpp`, which suggests that there 
>> are other weird iteration order dependent behavior.
>> Hopefully someone familiar with OpenMP can investigate :)
>
> I wasn't the original creator of this segment of code 
> (03f270c900e1f8563419fdd302683a9503e98722) unfortunately, I just moved it 
> into the OMPIRBuilder with some slight modifications, I can investigate it 
> but I will unfortunately be on vacation from tomorrow onwards until the 9th 
> of August, so if it is urgent it'd greatly be appreciated if someone else 
> could have a look into it. Otherwise, I can pick it up when I get back.
>
> If it is just the test added by this patch that is causing breakage and it 
> affects no other OpenMP components currently, then you could perhaps 
> deactivate this test for the time being until I can get time to look at it, 
> if no one else has a moment to spare. It is perhaps because I am verifying 
> the index value that's given to each piece of metadata/named global (e.g. 
> test_data_int_1_decl_tgt_ref_ptr) and expecting they will remain the same in 
> every case for this test, but with the introduction of 
> LLVM_ENABLE_REVERSE_ITERATION that's perhaps no longer the case.
>
> I am very sorry for the trouble.

Thank you for offering help! No hurry. For `LLVM_ENABLE_REVERSE_ITERATION`, my 
commit 14c55e6e2fa1c342a1ef908445db3d31a3475485 
 has 
worked for me.

The underlying issue  that `!omp_offload.info` has an operand order that is 
dependent on `StringMap` can be fixed later :) FWIW one of my attempts was:

  --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  @@ -5982,8 +5982,12 @@ void 
OffloadEntriesInfoManager::registerDeviceGlobalVarEntryInfo(
   void OffloadEntriesInfoManager::actOnDeviceGlobalVarEntriesInfo(
   const OffloadDeviceGlobalVarEntryInfoActTy ) {
 // Scan all target region entries and perform the provided action.
  +  SmallVector, 0> Vec;
 for (const auto  : OffloadEntriesDeviceGlobalVar)
  -Action(E.getKey(), E.getValue());
  +Vec.emplace_back(E.getKey(), E.getValue());
  +  llvm::sort(Vec, less_first());
  +  for (const auto  : Vec)
  +Action(E.first, E.second);
   }
  
   void CanonicalLoopInfo::collectControlBlocks(

and it would break `clang/test/OpenMP/declare_target_codegen.cpp`, so I didn't 
investigate further.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149162/new/

https://reviews.llvm.org/D149162

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


[PATCH] D155890: [clang-tidy] Add folly::Optional to unchecked-optional-access

2023-07-20 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

To be honest, all those things just should be configurable instead of 
hardcoding them.
For example, a project that I work for got 4 different custom optional 
implementations, and this check is useless for all of them.
And still no boost::optional support.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155890/new/

https://reviews.llvm.org/D155890

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


[PATCH] D155549: [clang] adds `conceptDecl` as an ASTMatcher

2023-07-20 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 542706.
cjdb edited the summary of this revision.
cjdb added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

just trying to get CI close to green :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155549/new/

https://reviews.llvm.org/D155549

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -12,9 +12,11 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -140,6 +142,22 @@
   ASSERT_TRUE(0 == MangleB.compare("_ZTSAT0__T_"));
 }
 
+TEST(Decl, ConceptDecl) {
+  llvm::StringRef Code(R"(
+template
+concept integral = __is_integral(T);
+  )");
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
+  ASTContext  = AST->getASTContext();
+  SourceManager  = Ctx.getSourceManager();
+
+  const auto *Decl =
+  selectFirst("decl", match(conceptDecl().bind("decl"), Ctx));
+  ASSERT_TRUE(Decl != nullptr);
+  EXPECT_EQ(Decl->getName(), "integral");
+}
+
 TEST(Decl, EnumDeclRange) {
   llvm::Annotations Code(R"(
 typedef int Foo;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -172,6 +172,7 @@
   REGISTER_MATCHER(compoundLiteralExpr);
   REGISTER_MATCHER(compoundStmt);
   REGISTER_MATCHER(coawaitExpr);
+  REGISTER_MATCHER(conceptDecl);
   REGISTER_MATCHER(conditionalOperator);
   REGISTER_MATCHER(constantArrayType);
   REGISTER_MATCHER(constantExpr);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -800,6 +800,7 @@
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
+const internal::VariadicDynCastAllOfMatcher conceptDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1334,6 +1334,16 @@
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeductionGuideDecl;
 
+/// Matches concept declarations.
+///
+/// Example matches integral
+/// \code
+///   template
+///   concept integral = std::is_integral_v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+conceptDecl;
+
 /// Matches variable declarations.
 ///
 /// Note: this does not match declarations of member variables, which are
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -262,6 +262,7 @@
 - Added ``__builtin_elementwise_nearbyint`` for floating point
   types. This allows access to ``llvm.nearbyint`` for arbitrary
   floating-point and vector of floating-point types.
+- Clang AST matcher now matches concept declarations with `conceptDecl`.
 
 New Compiler Flags
 --
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -682,6 +682,15 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclconceptDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ConceptDecl.html;>ConceptDecl...
+Matches concept declarations.
+
+Example matches integral
+  templatetypename T
+  concept integral = std::is_integral_vT;
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclcxxConstructorDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html;>CXXConstructorDecl...
 Matches C++ constructor declarations.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155850: [Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-07-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:5542
+  if (!getLangOpts().HIPStdPar)
+ErrorUnsupported(E, "builtin function");
 

AlexVlx wrote:
> efriedma wrote:
> > This doesn't make sense; we can't just ignore bits of the source code.  I 
> > guess this is related to "the decision on their validity is deferred", but 
> > I don't see how you expect this to work.
> This is one of the weirder parts, so let's consider the following example:
> 
> ```cpp
> void foo() { __builtin_ia32_pause(); }
> void bar() { __builtin_trap(); }
> 
> void baz(const vector& v) {
> return for_each(par_unseq, cbegin(v), cend(v), [](auto&& x) { if (x == 
> 42) bar(); });
> }
> ```
> 
> In the case above, what we'd offload to the accelerator, and ask the target 
> BE to lower, is the implementation of `for_each`, and `bar`, because it is 
> reachable from the latter. `foo` is not reachable by any execution path on 
> the accelerator side, however it includes a builtin that is unsupported by 
> the accelerator (unless said accelerator is x86, which is not impossible, but 
> not something we're dealing with at the moment). If we were to actually error 
> out early, in the FE, in these cases, there's almost no appeal to what is 
> being proposed, because standard headers, as well as other libraries, are 
> littered with various target specific builtins that are not going to be 
> supported. This all builds on the core invariant of this model / extension / 
> thingamabob, which is that the algorithms, and only the algorithms, are 
> targets for offload. It thus follows that as long as code that is reachable 
> from an algorithm's implementation is safe, all is fine, but we cannot know 
> this in the FE / on an AST level, because we need the actual CFG. This part 
> is handled in LLVM in the `SelectAcceleratorCodePass` that's in the last 
> patch in this series.
> 
> Now, you will quite correctly observe that there's nothing preventing an user 
> from calling `foo` in the callable they pass to an algorithm; they might read 
> the docs / appreciate that this won't work, but even there they are not safe, 
> because there via some opaque call chain they might end up touching some 
> unsupported builtin. My intuition here, which is reflected above in letting 
> builtins just flow through, is that such cases are better served with a 
> compile time error, which is what will obtain once the target BE chokes 
> trying to lower an unsupported builtin. It's not going to be a beautiful 
> error, and we could probably prettify it somewhat if we were to check after 
> we've done the accelerator code selection pass, but it will happen at compile 
> time. Another solution would be to emit these as traps (poison + trap for 
> value returning ones), but I am concerned that it would lead to really 
> fascinating debug journeys.
> 
> Having said this, if there's a better way to deal with these scenarios, it 
> would be rather nice. Similarly, if the above doesn't make sense, please let 
> me know.
> 
Oh, I see; you "optimistically" compile everything assuming it might run on the 
accelerator, then run LLVM IR optimizations, then determine late which bits of 
code will actually run on the accelerator, which then prunes the code which 
shouldn't run.

I'm not sure I really like this... would it be possible to infer which 
functions need to be run on the accelerator based on the AST?  I mean, if your 
API takes a lambda expression that runs on the accelerator, you can mark the 
lambda's body as "must be emitted for GPU", then recursively mark all the 
functions referred to by the lambda.

Emiting errors lazily from the backend means you get different diagnostics 
depending on the optimization level.

If you do go with this codegen-based approach, it's not clear to me how you 
detect that a forbidden builtin was called; if you skip the error handling, you 
just get a literal "undef".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155850/new/

https://reviews.llvm.org/D155850

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


[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-20 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/JumpDiagnostics.cpp:669
+if (JumpScope != TargetScope)
+  DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
+  }

Do we have a test that checks this diagnostic?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

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


[PATCH] D155898: [clangd] Fix go-to-type target location

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Previously it'd ~always jump to the lexically first declaration, which was
often an unhelpful forward declaration.

- consult the index for definition and preferred declaration locations (query 
code shared with go-to-definition)
- when unwrapping to LSP, prefer definition to declaration This matches 
"go-to-definition", which is the most common go-to operation


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155898

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -33,12 +33,10 @@
 namespace {
 
 using ::testing::AllOf;
-using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Eq;
 using ::testing::IsEmpty;
 using ::testing::Matcher;
-using ::testing::Not;
 using ::testing::UnorderedElementsAre;
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
@@ -1879,7 +1877,7 @@
 
 ASSERT_GT(A.points().size(), 0u) << Case;
 for (auto Pos : A.points())
-  EXPECT_THAT(findType(AST, Pos),
+  EXPECT_THAT(findType(AST, Pos, nullptr),
   ElementsAre(
 sym("Target", HeaderA.range("Target"), HeaderA.range("Target"
   << Case;
@@ -1892,7 +1890,7 @@
 TU.Code = A.code().str();
 ParsedAST AST = TU.build();
 
-EXPECT_THAT(findType(AST, A.point()),
+EXPECT_THAT(findType(AST, A.point(), nullptr),
 UnorderedElementsAre(
   sym("Target", HeaderA.range("Target"), HeaderA.range("Target")),
   sym("smart_ptr", HeaderA.range("smart_ptr"), HeaderA.range("smart_ptr"))
@@ -1901,6 +1899,39 @@
   }
 }
 
+TEST(FindType, Definition) {
+  Annotations A(R"cpp(
+class $decl[[X]];
+X *^x;
+class $def[[X]] {};
+  )cpp");
+  auto TU = TestTU::withCode(A.code().str());
+  ParsedAST AST = TU.build();
+
+  EXPECT_THAT(findType(AST, A.point(), nullptr),
+  ElementsAre(sym("X", A.range("decl"), A.range("def";
+}
+
+TEST(FindType, Index) {
+  Annotations Def(R"cpp(
+// This definition is only available through the index.
+class [[X]] {};
+  )cpp");
+  TestTU DefTU = TestTU::withHeaderCode(Def.code());
+  DefTU.HeaderFilename = "def.h";
+  auto DefIdx = DefTU.index();
+
+  Annotations A(R"cpp(
+class [[X]];
+X *^x;
+  )cpp");
+  auto TU = TestTU::withCode(A.code().str());
+  ParsedAST AST = TU.build();
+
+  EXPECT_THAT(findType(AST, A.point(), DefIdx.get()),
+  ElementsAre(sym("X", A.range(), Def.range(;
+}
+
 void checkFindRefs(llvm::StringRef Test, bool UseIndex = false) {
   Annotations T(Test);
   auto TU = TestTU::withCode(T.code());
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -107,7 +107,8 @@
 ///
 /// For example, given `b^ar()` wher bar return Foo, this function returns the
 /// definition of class Foo.
-std::vector findType(ParsedAST , Position Pos);
+std::vector findType(ParsedAST , Position Pos,
+const SymbolIndex *Index);
 
 /// Returns references of the symbol at a specified \p Pos.
 /// \p Limit limits the number of results returned (0 means no limit).
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -341,6 +341,46 @@
   return Results;
 }
 
+// Given LocatedSymbol results derived from the AST, query the index to obtain
+// definitions and preferred declarations.
+void enhanceLocatedSymbolsFromIndex(
+llvm::MutableArrayRef Result,
+const llvm::DenseMap ,
+const SymbolIndex *Index, llvm::StringRef MainFilePath) {
+  if (!Index || ResultIndex.empty())
+return;
+  LookupRequest QueryRequest;
+  for (auto It : ResultIndex)
+QueryRequest.IDs.insert(It.first);
+  std::string Scratch;
+  Index->lookup(QueryRequest, [&](const Symbol ) {
+auto  = Result[ResultIndex.lookup(Sym.ID)];
+
+if (R.Definition) { // from AST
+  // Special case: if the AST yielded a definition, then it may not be
+  // the right *declaration*. Prefer the one from the index.
+  if (auto Loc = toLSPLocation(Sym.CanonicalDeclaration, MainFilePath))
+R.PreferredDeclaration = *Loc;
+
+  // We might 

[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

2023-07-20 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D139586#4363725 , @cor3ntin wrote:

> @hubert.reinterpretcast I'll try to look at that but unless I'm mistaken,  
> the wording excludes function parameters
>
>> The fourth context is when a temporary object **other than a function 
>> parameter** object is created in the for-range-initializer of a range-based 
>> for statement. If such a temporary object would otherwise be destroyed at 
>> the end of the for-range-initializer full-expression, the object persists 
>> for the lifetime of the reference initialized by the for-range-initializer.
>
> I think that invalidates some of your examples?

@cor3ntin, the examples I gave were for temporary objects created for binding 
to a reference (that, in turn, happens to be a function parameter). Those 
temporary objects are not function parameters.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139586/new/

https://reviews.llvm.org/D139586

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-20 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:507
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of

john.brawn wrote:
> shafik wrote:
> > This section does not exist anymore, it was replaced in 
> > [p1787](https://wg21.link/p1787) which resolved a very large number of DRs 
> > and reflector discussions. I have not fully digested the paper myself but 
> > this change should reflect the new wording as it exists in the current 
> > draft. 
> It looks like https://eel.is/c++draft/basic.lookup#general-4 is the same 
> thing but worded differently. That draft hasn't gone into a published 
> standard though, and could change before it gets published, and the same 
> section is referenced elsewhere in this file (and there are probably other 
> references in this file to parts of the standard that will get changed in the 
> next version), so I think it would make more sense to change all such 
> comments at once when that change has gone into a published version of the 
> standard.
This paper was voted in 
[11/2020](https://github.com/cplusplus/draft/issues/4326) and it considered 
[C++23](https://github.com/cplusplus/papers/issues/533) and so it is safe to 
rely on this wording. Any behavior that does not match this wording should be 
considered a bug.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154503/new/

https://reviews.llvm.org/D154503

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


[PATCH] D155191: clang/HIP: Directly use f32 exp and log builtins

2023-07-20 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

5f1d3834a2bc3b77e126a278a0e7f00bce5576fc 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155191/new/

https://reviews.llvm.org/D155191

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


[clang] 5f1d383 - clang/HIP: Directly use f32 exp and log builtins

2023-07-20 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-07-20T18:14:24-04:00
New Revision: 5f1d3834a2bc3b77e126a278a0e7f00bce5576fc

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

LOG: clang/HIP: Directly use f32 exp and log builtins

These are now lowered correctly by the backend, and you get proper
fast math flags when directly handled.

Added: 


Modified: 
clang/lib/Headers/__clang_hip_math.h
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 8a90c4acd94105..86013d0ffc2b7a 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -221,10 +221,10 @@ __DEVICE__
 float exp10f(float __x) { return __ocml_exp10_f32(__x); }
 
 __DEVICE__
-float exp2f(float __x) { return __ocml_exp2_f32(__x); }
+float exp2f(float __x) { return __builtin_exp2f(__x); }
 
 __DEVICE__
-float expf(float __x) { return __ocml_exp_f32(__x); }
+float expf(float __x) { return __builtin_expf(__x); }
 
 __DEVICE__
 float expm1f(float __x) { return __ocml_expm1_f32(__x); }
@@ -315,19 +315,19 @@ __DEVICE__
 long long int llroundf(float __x) { return __builtin_roundf(__x); }
 
 __DEVICE__
-float log10f(float __x) { return __ocml_log10_f32(__x); }
+float log10f(float __x) { return __builtin_log10f(__x); }
 
 __DEVICE__
 float log1pf(float __x) { return __ocml_log1p_f32(__x); }
 
 __DEVICE__
-float log2f(float __x) { return __ocml_log2_f32(__x); }
+float log2f(float __x) { return __builtin_log2f(__x); }
 
 __DEVICE__
 float logbf(float __x) { return __ocml_logb_f32(__x); }
 
 __DEVICE__
-float logf(float __x) { return __ocml_log_f32(__x); }
+float logf(float __x) { return __builtin_logf(__x); }
 
 __DEVICE__
 long int lrintf(float __x) { return __ocml_rint_f32(__x); }

diff  --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index 21864d2ecb4dfd..bfb66ce27e6171 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -755,13 +755,13 @@ extern "C" __device__ double test_exp10(double x) {
 
 // DEFAULT-LABEL: @test_exp2f(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract float 
@__ocml_exp2_f32(float noundef [[X:%.*]]) #[[ATTR15]]
-// DEFAULT-NEXT:ret float [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float 
@llvm.exp2.f32(float [[X:%.*]])
+// DEFAULT-NEXT:ret float [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_exp2f(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_exp2_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR15]]
-// FINITEONLY-NEXT:ret float [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract float 
@llvm.exp2.f32(float [[X:%.*]])
+// FINITEONLY-NEXT:ret float [[TMP0]]
 //
 extern "C" __device__ float test_exp2f(float x) {
   return exp2f(x);
@@ -783,13 +783,13 @@ extern "C" __device__ double test_exp2(double x) {
 
 // DEFAULT-LABEL: @test_expf(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract float 
@__ocml_exp_f32(float noundef [[X:%.*]]) #[[ATTR15]]
-// DEFAULT-NEXT:ret float [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float 
@llvm.exp.f32(float [[X:%.*]])
+// DEFAULT-NEXT:ret float [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_expf(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_exp_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR15]]
-// FINITEONLY-NEXT:ret float [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract float 
@llvm.exp.f32(float [[X:%.*]])
+// FINITEONLY-NEXT:ret float [[TMP0]]
 //
 extern "C" __device__ float test_expf(float x) {
   return expf(x);
@@ -1543,13 +1543,13 @@ extern "C" __device__ long long int test_llround(double 
x) {
 
 // DEFAULT-LABEL: @test_log10f(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract float 
@__ocml_log10_f32(float noundef [[X:%.*]]) #[[ATTR15]]
-// DEFAULT-NEXT:ret float [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float 
@llvm.log10.f32(float [[X:%.*]])
+// DEFAULT-NEXT:ret float [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_log10f(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_log10_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR15]]
-// FINITEONLY-NEXT:ret float [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract float 
@llvm.log10.f32(float [[X:%.*]])
+// FINITEONLY-NEXT:ret float [[TMP0]]
 //
 

[PATCH] D155895: Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.

2023-07-20 Thread Łukasz Anforowicz via Phabricator via cfe-commits
lukasza added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:10299
 
   if (!HasNonDeletedCopyOrMoveConstructor()) {
 PrintDiagAndRemoveAttr(0);

I tried to change this condition to `!RD.isAnonymousStructOrUnion() && 
!HasNonDeletedCopyOrMoveConstructor()` but it seems that at this point 
`isAnonymousStructOrUnion` doesn't yet work because `setAnonymousStructOrUnion` 
is called at a later point.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:10350
   }
 }
 

Alternative fix I've considered:
1.1. `setHasTrivialSpecialMemberForCall` for anonymous unions *if* their 
`DeclContext` is trivial.
1.2. Don't check `!HasNonDeletedCopyOrMoveConstructor()` for anonymous unions.

I don't know how to do 1.1 - this seems like a chicken-and-egg problem.  We 
can't know if `DeclContext` is trivial until we check 
`checkIllFormedTrivialABIStruct`, but when `checkIllFormedTrivialABIStruct` 
checks fields it requires that the triviality of the anonymous union is already 
known.

I don't know how to do 1.2 - changing the condition above to 
`!RD.isAnonymousStructOrUnion() && !HasNonDeletedCopyOrMoveConstructor()` 
doesn't work because at that point `isAnonymousStructOrUnion` doesn't yet work 
because `setAnonymousStructOrUnion` is called at a later point.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155895/new/

https://reviews.llvm.org/D155895

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


[PATCH] D155895: git squash commit for trivial-abi-vs-anonymous-unions.

2023-07-20 Thread Łukasz Anforowicz via Phabricator via cfe-commits
lukasza created this revision.
Herald added a project: All.
lukasza requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

1480d173fca1c83809ed5ac350c19021c7036a99
Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.

Consider the test input below:

  struct [[clang::trivial_abi]] Trivial {
Trivial() {}
Trivial(Trivial&& other) {}
Trivial& operator=(Trivial&& other) { return *this; }
~Trivial() {}
  };
  static_assert(__is_trivially_relocatable(Trivial), "");
  
  struct [[clang::trivial_abi]] S2 {
S2(S2&& other) {}
S2& operator=(S2&& other) { return *this; }
~S2() {}
union { Trivial field; };
  };
  static_assert(__is_trivially_relocatable(S2), "");


Before the fix Clang would warn that 'trivial_abi' is disallowed on 'S2'
because it has a field of a non-trivial class type (the type of the
anonymous union is non-trivial, because it doesn't have the
`[[clang::trivial_abi]]` attribute applied to it).  Consequently, before
the fix the `static_assert` about `__is_trivially_relocatable` would
fail.

Note that `[[clang::trivial_abi]]` cannot be applied to the anonymous
union, because Clang warns that 'trivial_abi' is disallowed on '(unnamed
union at ...)' because its copy constructors and move constructors are
all deleted. Also note that it is impossible to provide copy nor move
constructors for anonymous unions and structs.

f1ba3de456dd2b5561c5ef78ddeea345066f8400
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155895

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/attr-trivial-abi.cpp

Index: clang/test/SemaCXX/attr-trivial-abi.cpp
===
--- clang/test/SemaCXX/attr-trivial-abi.cpp
+++ clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -169,3 +169,94 @@
 static_assert(__is_trivially_relocatable(S20), "");
 #endif
 } // namespace deletedCopyMoveConstructor
+
+namespace anonymousUnionsAndStructs {
+  // Test helper:
+  struct [[clang::trivial_abi]] Trivial {
+Trivial() {}
+Trivial(Trivial&& other) {}
+Trivial& operator=(Trivial&& other) { return *this; }
+~Trivial() {}
+  };
+  static_assert(__is_trivially_relocatable(Trivial), "");
+
+  // Test helper:
+  struct Nontrivial {
+Nontrivial() {}
+Nontrivial(Nontrivial&& other) {}
+Nontrivial& operator=(Nontrivial&& other) { return *this; }
+~Nontrivial() {}
+  };
+  static_assert(!__is_trivially_relocatable(Nontrivial), "");
+
+  // Basic smoke test, not yet related to anonymous unions or structs:
+  struct [[clang::trivial_abi]] S1 {
+S1(S1&& other) {}
+S1& operator=(S1&& other) { return *this; }
+~S1() {}
+Trivial field;
+  };
+  static_assert(__is_trivially_relocatable(S1), "");
+
+  // `S2` is like `S1`, but `field` is wrapped in an anonymous union (and it
+  // seems that trivial relocatability of `S1` and `S2` should be the same).
+  //
+  // It's impossible to declare a constructor for an anonymous unions so to
+  // support applying `[[clang::trivial_abi]]` to structs containing anonymous
+  // unions, and therefore when processing fields of the struct containing the
+  // anonymous union, the trivial relocatability of the *union* is ignored and
+  // instead the union's fields are recursively inspected in
+  // `checkIllFormedTrivialABIStruct`.
+  struct [[clang::trivial_abi]] S2 {
+S2(S2&& other) {}
+S2& operator=(S2&& other) { return *this; }
+~S2() {}
+union { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(S2), "");
+
+  // `S3` is like `S2` but uses an anonymous `struct` rather than an anonymous
+  // `union.
+  struct [[clang::trivial_abi]] S3 {
+S3(S3&& other) {}
+S3& operator=(S3&& other) { return *this; }
+~S3() {}
+struct { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(S3), "");
+
+  // `S4` is like `S2` but with `[[clang::trivial_abi]]` also applied to the
+  // anonymous union.
+  //
+  // `S2` and `S3` examples above show that `[[clang::trivial_abi]]`
+  // *implicitly* propagates into anonymous union and structs.  The example
+  // below shows that it is still *not* okay to *explicitly* apply
+  // `[[clang::trivial_abi]]` to anonymous unions. Handling this would require
+  // relaxing the `HasNonDeletedCopyOrMoveConstructor` check when
+  // `isAnonymousStructOrUnion` in `checkIllFormedTrivialABIStruct` but when
+  // that check runs `setAnonymousStructOrUnion` hasn't been called yet
+  // (i.e. at this point it's not possible to rely on
+  // `RD->isAnonymousStructOrUnion()`).
+  struct [[clang::trivial_abi]] S4 {
+S4(S4&& other) {}
+S4& operator=(S4&& other) { return *this; }
+~S4() {}
+union [[clang::trivial_abi]] { // expected-warning {{'trivial_abi' cannot be applied to '(unnamed union}} expected-note {{copy constructors and move constructors are all deleted}}
+  Trivial field;
+};
+  };
+  

[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-20 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Your explanation makes sense, I wish we had some documentation someplace that 
covered how it is expected to work with some examples with expected results. 
Maybe we should think about tests that might exercise this code a bit more.

The definition of `MultiLevelTemplateArgumentList` they have a basic example 
but that seems to be it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155705/new/

https://reviews.llvm.org/D155705

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


[PATCH] D154658: Optimize emission of `dynamic_cast` to final classes.

2023-07-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D154658#4516554 , @rjmccall wrote:

> LGTM, except, should we have a way to turn this optimization off specifically?

Sure. I suppose even for an internal linkage vtable there could be a reason to 
want to turn this off (eg, if someone constructs a custom vtable at runtime). 
I've added `-fno-assume-unique-vtables` to disable the optimization.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154658/new/

https://reviews.llvm.org/D154658

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


[PATCH] D154658: Optimize emission of `dynamic_cast` to final classes.

2023-07-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 542693.
rsmith added a comment.
Herald added a subscriber: MaskRay.

- Add option to disable vptr-based dynamic_cast optimization.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154658/new/

https://reviews.llvm.org/D154658

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/dynamic-cast-always-null.cpp
  clang/test/CodeGenCXX/dynamic-cast-exact-disabled.cpp
  clang/test/CodeGenCXX/dynamic-cast-exact.cpp
  clang/test/Driver/fassume-unique-vtables.cpp

Index: clang/test/Driver/fassume-unique-vtables.cpp
===
--- /dev/null
+++ clang/test/Driver/fassume-unique-vtables.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang -### -fno-assume-unique-vtables %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
+// RUN: %clang -### -fno-assume-unique-vtables -fassume-unique-vtables %s -S 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
+// CHECK-OPT: "-fno-assume-unique-vtables"
+// CHECK-NOOPT-NOT: "-fno-assume-unique-vtables"
Index: clang/test/CodeGenCXX/dynamic-cast-exact.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-exact.cpp
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s --implicit-check-not='call {{.*}} @__dynamic_cast'
+struct Offset { virtual ~Offset(); };
+struct A { virtual ~A(); };
+struct B final : Offset, A { };
+
+struct C { virtual ~C(); int c; };
+struct D : A { int d; };
+struct E : A { int e; };
+struct F : virtual A { int f; };
+struct G : virtual A { int g; };
+struct H final : C, D, E, F, G { int h; };
+
+// CHECK-LABEL: @_Z7inexactP1A
+C *inexact(A *a) {
+  // CHECK: call {{.*}} @__dynamic_cast
+  return dynamic_cast(a);
+}
+
+// CHECK-LABEL: @_Z12exact_singleP1A
+B *exact_single(A *a) {
+  // CHECK: %[[PTR_NULL:.*]] = icmp eq ptr %[[PTR:.*]], null
+  // CHECK: br i1 %[[PTR_NULL]], label %[[LABEL_FAILED:.*]], label %[[LABEL_NOTNULL:.*]]
+
+  // CHECK: [[LABEL_NOTNULL]]:
+  // CHECK: %[[VPTR:.*]] = load ptr, ptr %[[PTR]]
+  // CHECK: %[[MATCH:.*]] = icmp eq ptr %[[VPTR]], getelementptr inbounds ({ [4 x ptr], [4 x ptr] }, ptr @_ZTV1B, i32 0, inrange i32 1, i32 2)
+  // CHECK: %[[RESULT:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i64 -8
+  // CHECK: br i1 %[[MATCH]], label %[[LABEL_END:.*]], label %[[LABEL_FAILED]]
+
+  // CHECK: [[LABEL_FAILED]]:
+  // CHECK: br label %[[LABEL_END]]
+
+  // CHECK: [[LABEL_END]]:
+  // CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, %[[LABEL_FAILED]] ]
+  return dynamic_cast(a);
+}
+
+// CHECK-LABEL: @_Z9exact_refR1A
+B _ref(A ) {
+  // CHECK: %[[PTR_NULL:.*]] = icmp eq ptr %[[PTR:.*]], null
+  // CHECK: br i1 %[[PTR_NULL]], label %[[LABEL_FAILED:.*]], label %[[LABEL_NOTNULL:.*]]
+
+  // CHECK: [[LABEL_NOTNULL]]:
+  // CHECK: %[[VPTR:.*]] = load ptr, ptr %[[PTR]]
+  // CHECK: %[[MATCH:.*]] = icmp eq ptr %[[VPTR]], getelementptr inbounds ({ [4 x ptr], [4 x ptr] }, ptr @_ZTV1B, i32 0, inrange i32 1, i32 2)
+  // CHECK: %[[RESULT:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i64 -8
+  // CHECK: br i1 %[[MATCH]], label %[[LABEL_END:.*]], label %[[LABEL_FAILED]]
+
+  // CHECK: [[LABEL_FAILED]]:
+  // CHECK: call {{.*}} @__cxa_bad_cast
+  // CHECK: unreachable
+
+  // CHECK: [[LABEL_END]]:
+  // CHECK: ret ptr %[[RESULT]]
+  return dynamic_cast(a);
+}
+
+// CHECK-LABEL: @_Z11exact_multiP1A
+H *exact_multi(A *a) {
+  // CHECK: %[[PTR_NULL:.*]] = icmp eq ptr %[[PTR:.*]], null
+  // CHECK: br i1 %[[PTR_NULL]], label %[[LABEL_FAILED:.*]], label %[[LABEL_NOTNULL:.*]]
+
+  // CHECK: [[LABEL_NOTNULL]]:
+  // CHECK: %[[VPTR:.*]] = load ptr, ptr %[[PTR]]
+  // CHECK: %[[OFFSET_TO_TOP_SLOT:.*]] = getelementptr inbounds i64, ptr %[[VPTR]], i64 -2
+  // CHECK: %[[OFFSET_TO_TOP:.*]] = load i64, ptr %[[OFFSET_TO_TOP_SLOT]]
+  // CHECK: %[[RESULT:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i64 %[[OFFSET_TO_TOP]]
+  // CHECK: %[[DERIVED_VPTR:.*]] = load ptr, ptr %[[RESULT]]
+  // CHECK: %[[MATCH:.*]] = icmp eq ptr %[[DERIVED_VPTR]], getelementptr inbounds ({ [5 x ptr], [4 x ptr], [4 x ptr], [6 x ptr], [6 x ptr] }, ptr @_ZTV1H, i32 0, inrange i32 0, i32 3)
+  // CHECK: br i1 %[[MATCH]], label %[[LABEL_END:.*]], label %[[LABEL_FAILED]]
+
+  // CHECK: [[LABEL_FAILED]]:
+  // CHECK: br label %[[LABEL_END]]
+
+  // CHECK: [[LABEL_END]]:
+  // CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, %[[LABEL_FAILED]] ]
+  return dynamic_cast(a);
+}
Index: clang/test/CodeGenCXX/dynamic-cast-exact-disabled.cpp

[PATCH] D155890: [clang-tidy] Add folly::Optional to unchecked-optional-access

2023-07-20 Thread Anton Dukeman via Phabricator via cfe-commits
adukeman created this revision.
adukeman added reviewers: njames93, ymandel, sgatev.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
adukeman requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

The unchecked-optional-access check identifies attempted value
unwrapping without checking if the value exists. These changes extend
that support to checking folly::Optional.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155890

Files:
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/folly/types/Optional.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -56,9 +56,10 @@
   }
 
   if (RD.getName() == "Optional") {
-// Check whether namespace is "::base".
+// Check whether namespace is "::base" or "::folly".
 const auto *N = dyn_cast_or_null(RD.getDeclContext());
-return N != nullptr && isTopLevelNamespaceWithName(*N, "base");
+return N != nullptr && (isTopLevelNamespaceWithName(*N, "base") ||
+isTopLevelNamespaceWithName(*N, "folly"));
   }
 
   return false;
@@ -109,15 +110,15 @@
 }
 
 auto isMakeOptionalCall() {
-  return callExpr(
-  callee(functionDecl(hasAnyName(
-  "std::make_optional", "base::make_optional", "absl::make_optional"))),
-  hasOptionalType());
+  return callExpr(callee(functionDecl(hasAnyName(
+  "std::make_optional", "base::make_optional",
+  "absl::make_optional", "folly::make_optional"))),
+  hasOptionalType());
 }
 
 auto nulloptTypeDecl() {
-  return namedDecl(
-  hasAnyName("std::nullopt_t", "absl::nullopt_t", "base::nullopt_t"));
+  return namedDecl(hasAnyName("std::nullopt_t", "absl::nullopt_t",
+  "base::nullopt_t", "folly::None"));
 }
 
 auto hasNulloptType() { return hasType(nulloptTypeDecl()); }
@@ -129,8 +130,8 @@
 }
 
 auto inPlaceClass() {
-  return recordDecl(
-  hasAnyName("std::in_place_t", "absl::in_place_t", "base::in_place_t"));
+  return recordDecl(hasAnyName("std::in_place_t", "absl::in_place_t",
+   "base::in_place_t", "folly::in_place_t"));
 }
 
 auto isOptionalNulloptConstructor() {
@@ -839,6 +840,11 @@
   isOptionalMemberCallWithName("has_value"),
   transferOptionalHasValueCall)
 
+  // optional::hasValue for folly::Optional
+  .CaseOfCFGStmt(
+  isOptionalMemberCallWithName("hasValue"),
+  transferOptionalHasValueCall)
+
   // optional::operator bool
   .CaseOfCFGStmt(
   isOptionalMemberCallWithName("operator bool"),
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
@@ -1,6 +1,7 @@
 // RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- -- -I %S/Inputs/unchecked-optional-access
 
 #include "absl/types/optional.h"
+#include "folly/types/Optional.h"
 
 void unchecked_value_access(const absl::optional ) {
   opt.value();
@@ -21,12 +22,34 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional value
 }
 
+void folly_check_value_then_reset(folly::Optional opt) {
+  if (opt) {
+opt.reset();
+opt.value();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: unchecked access to optional value
+  }
+}
+
+void folly_value_after_swap(folly::Optional opt1, folly::Optional opt2) {
+  if (opt1) {
+opt1.swap(opt2);
+opt1.value();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: unchecked access to optional value
+  }
+}
+
 void checked_access(const absl::optional ) {
   if (opt.has_value()) {
 opt.value();
   }
 }
 
+void folly_checked_access(const folly::Optional ) {
+  if (opt.hasValue()) {
+opt.value();
+  }
+}
+
 template 
 void function_template_without_user(const absl::optional ) {
   opt.value(); // no-warning
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/folly/types/Optional.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/folly/types/Optional.h
@@ -0,0 +1,56 @@
+#ifndef 

[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-07-20 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

In D149162#4520395 , @MaskRay wrote:

> In D149162#4517500 , @MaskRay wrote:
>
>> `registerTargetGlobalVariable` relies on the iteration order of StringMap, 
>> which is not guaranteed. The bug is caught by D155789 
>> 
>>
>>   curl -L 'https://reviews.llvm.org/D155789?download=1' | patch -p1
>>   cmake ... -DLLVM_ENABLE_REVERSE_ITERATION=on
>>   ninja -C ... check-llvm-unit  #  `LLVM-Unit :: 
>> Frontend/./LLVMFrontendTests/OpenMPIRBuilderTest/registerTargetGlobalVariable`
>>  fails
>
> Looks like the issue might be introduced by 
> 03f270c900e1f8563419fdd302683a9503e98722 in the iteration order of 
> `OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar` (a StringMap).
> Unfortunately, changing it to `MapVector OffloadEntryInfoDeviceGlobalVar>` will break other tests like 
> `clang/test/OpenMP/declare_target_codegen.cpp`, which suggests that there are 
> other weird iteration order dependent behavior.
> Hopefully someone familiar with OpenMP can investigate :)

I wasn't the original creator of this segment of code 
(03f270c900e1f8563419fdd302683a9503e98722) unfortunately, I just moved it into 
the OMPIRBuilder with some slight modifications, I can investigate it but I 
will unfortunately be on vacation from tomorrow onwards until the 9th of 
August, so if it is urgent it'd greatly be appreciated if someone else could 
have a look into it. Otherwise, I can pick it up when I get back.

If it is just the test added by this patch that is causing breakage and it 
affects no other OpenMP components currently, then you could perhaps deactivate 
this test for the time being until I can get time to look at it, if no one else 
has a moment to spare. It is perhaps because I am verifying the index value 
that's given to each piece of metadata/named global (e.g. 
test_data_int_1_decl_tgt_ref_ptr) and expecting they will remain the same in 
every case for this test, but with the introduction of 
LLVM_ENABLE_REVERSE_ITERATION that's perhaps no longer the case.

I am very sorry for the trouble.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149162/new/

https://reviews.llvm.org/D149162

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


[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D149162#4517500 , @MaskRay wrote:

> `registerTargetGlobalVariable` relies on the iteration order of StringMap, 
> which is not guaranteed. The bug is caught by D155789 
> 
>
>   curl -L 'https://reviews.llvm.org/D155789?download=1' | patch -p1
>   cmake ... -DLLVM_ENABLE_REVERSE_ITERATION=on
>   ninja -C ... check-llvm-unit  #  `LLVM-Unit :: 
> Frontend/./LLVMFrontendTests/OpenMPIRBuilderTest/registerTargetGlobalVariable`
>  fails

Looks like the issue might be introduced by 
03f270c900e1f8563419fdd302683a9503e98722 in the iteration order of 
`OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar` (a StringMap).
Unfortunately, changing it to `MapVector` will break other tests like 
`clang/test/OpenMP/declare_target_codegen.cpp`, which suggests that there are 
other weird iteration order dependent behavior.
Hopefully someone familiar with OpenMP can investigate :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149162/new/

https://reviews.llvm.org/D149162

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


[PATCH] D155885: [include-cleaner] Switch Include from FileEntry* -> FileEntryRef

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: PiotrZSL, carlosgalvezp, arphaman.
Herald added a reviewer: njames93.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Unlike Header, we really do have a preferred spelling for an include: the one
that we used to open the file.

The fact that Header is still FileEntry* makes it difficult to accidentally
use path equality when we want inode equality.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155885

Files:
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
  clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -26,8 +26,8 @@
   // Ensure it doesn't do any actual IO.
   auto FS = llvm::makeIntrusiveRefCnt();
   FileManager FM(FileSystemOptions{});
-  const FileEntry *A = FM.getVirtualFile("/path/a", /*Size=*/0, time_t{});
-  const FileEntry *B = FM.getVirtualFile("/path/b", /*Size=*/0, time_t{});
+  FileEntryRef A = FM.getVirtualFileRef("/path/a", /*Size=*/0, time_t{});
+  FileEntryRef B = FM.getVirtualFileRef("/path/b", /*Size=*/0, time_t{});
 
   Includes Inc;
   Inc.add(Include{"a", A, SourceLocation(), 1});
@@ -35,10 +35,11 @@
   Inc.add(Include{"b", B, SourceLocation(), 3});
   Inc.add(Include{"vector", B, SourceLocation(), 4});
   Inc.add(Include{"vector", B, SourceLocation(), 5});
-  Inc.add(Include{"missing", nullptr, SourceLocation(), 6});
+  Inc.add(Include{"missing", std::nullopt, SourceLocation(), 6});
 
-  EXPECT_THAT(Inc.match(A), ElementsAre(line(1), line(2)));
-  EXPECT_THAT(Inc.match(B), ElementsAre(line(3), line(4), line(5)));
+  EXPECT_THAT(Inc.match(()), ElementsAre(line(1), line(2)));
+  EXPECT_THAT(Inc.match(()),
+  ElementsAre(line(3), line(4), line(5)));
   EXPECT_THAT(Inc.match(*tooling::stdlib::Header::named("")),
   ElementsAre(line(4), line(5)));
 }
Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -171,7 +171,7 @@
   EXPECT_EQ(H.HashLocation,
 AST.sourceManager().getComposedLoc(
 AST.sourceManager().getMainFileID(), MainFile.point("H")));
-  EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get());
+  EXPECT_EQ(H.Resolved, *AST.fileManager().getOptionalFileRef("header.h"));
   EXPECT_FALSE(H.Angled);
 
   auto  = Recorded.Includes.all().back();
@@ -179,7 +179,7 @@
   EXPECT_EQ(M.HashLocation,
 AST.sourceManager().getComposedLoc(
 AST.sourceManager().getMainFileID(), MainFile.point("M")));
-  EXPECT_EQ(M.Resolved, nullptr);
+  EXPECT_EQ(M.Resolved, std::nullopt);
   EXPECT_TRUE(M.Angled);
 }
 
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -102,7 +102,7 @@
 
   BySpellingIt->second.push_back(Index);
   if (I.Resolved)
-ByFile[I.Resolved].push_back(Index);
+ByFile[>getFileEntry()].push_back(Index);
   ByLine[I.Line] = Index;
 }
 
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -47,7 +47,7 @@
 
 Include I;
 I.HashLocation = Hash;
-I.Resolved = File ? >getFileEntry() : nullptr;
+I.Resolved = File;
 I.Line = SM.getSpellingLineNumber(Hash);
 I.Spelled = SpelledFilename;
 I.Angled = IsAngled;
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -88,14 +88,14 @@
   AnalysisResults Results;
   for (const Include  : Inc.all()) {
 if (Used.contains() || !I.Resolved ||
-HeaderFilter(I.Resolved->tryGetRealPathName()))
+HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()))
   continue;
 if (PI) {
   if (PI->shouldKeep(I.Line))
 continue;
   

[PATCH] D155850: [Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-07-20 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:5542
+  if (!getLangOpts().HIPStdPar)
+ErrorUnsupported(E, "builtin function");
 

efriedma wrote:
> This doesn't make sense; we can't just ignore bits of the source code.  I 
> guess this is related to "the decision on their validity is deferred", but I 
> don't see how you expect this to work.
This is one of the weirder parts, so let's consider the following example:

```cpp
void foo() { __builtin_ia32_pause(); }
void bar() { __builtin_trap(); }

void baz(const vector& v) {
return for_each(par_unseq, cbegin(v), cend(v), [](auto&& x) { if (x == 42) 
bar(); });
}
```

In the case above, what we'd offload to the accelerator, and ask the target BE 
to lower, is the implementation of `for_each`, and `bar`, because it is 
reachable from the latter. `foo` is not reachable by any execution path on the 
accelerator side, however it includes a builtin that is unsupported by the 
accelerator (unless said accelerator is x86, which is not impossible, but not 
something we're dealing with at the moment). If we were to actually error out 
early, in the FE, in these cases, there's almost no appeal to what is being 
proposed, because standard headers, as well as other libraries, are littered 
with various target specific builtins that are not going to be supported. This 
all builds on the core invariant of this model / extension / thingamabob, which 
is that the algorithms, and only the algorithms, are targets for offload. It 
thus follows that as long as code that is reachable from an algorithm's 
implementation is safe, all is fine, but we cannot know this in the FE / on an 
AST level, because we need the actual CFG. This part is handled in LLVM in the 
`SelectAcceleratorCodePass` that's in the last patch in this series.

Now, you will quite correctly observe that there's nothing preventing an user 
from calling `foo` in the callable they pass to an algorithm; they might read 
the docs / appreciate that this won't work, but even there they are not safe, 
because there via some opaque call chain they might end up touching some 
unsupported builtin. My intuition here, which is reflected above in letting 
builtins just flow through, is that such cases are better served with a compile 
time error, which is what will obtain once the target BE chokes trying to lower 
an unsupported builtin. It's not going to be a beautiful error, and we could 
probably prettify it somewhat if we were to check after we've done the 
accelerator code selection pass, but it will happen at compile time. Another 
solution would be to emit these as traps (poison + trap for value returning 
ones), but I am concerned that it would lead to really fascinating debug 
journeys.

Having said this, if there's a better way to deal with these scenarios, it 
would be rather nice. Similarly, if the above doesn't make sense, please let me 
know.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155850/new/

https://reviews.llvm.org/D155850

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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-07-20 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 542660.
DiggerLin added a comment.

1. rebase the code
2. for the `env OBJECT_MODE=` or is `env OBJECT_MODE=""` , the `ranlib` and 
`ar` in AIX OS , have different behaviors(ranlib looks as -X32 , but `ar` and 
`nm` output error ),

I change `llvm-ranlib` as the same behavior as `ar` and `llvm-ar`, output an 
error(I think output error is more reasonable).  and look env OBJECT_MODE unset 
as default 32-BIT for `llvm-ranlib`  as AIX OS command `ranlib` , `nm` ,`ar`.

bash-5.0$ env OBJECT_MODE= ar  -q tmp.a bug.patch
ar: 0707-133 The OBJECT_MODE environment variable has an invalid setting.

  OBJECT_MODE must be 32, 64, 32_64, d64, or any.

bash-5.0$ env OBJECT_MODE="" ar  -q tmp.a bug.patch
ar: 0707-133 The OBJECT_MODE environment variable has an invalid setting.

  OBJECT_MODE must be 32, 64, 32_64, d64, or any.

bash-5.0$ env OBJECT_MODE="" ranlib  tmpk.a
bash-5.0$ env OBJECT_MODE= ranlib  tmpk.a


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142660/new/

https://reviews.llvm.org/D142660

Files:
  clang/test/lit.cfg.py
  llvm/include/llvm/Object/Archive.h
  llvm/include/llvm/Object/ArchiveWriter.h
  llvm/lib/Object/Archive.cpp
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/test/lit.cfg.py
  llvm/test/tools/llvm-ranlib/aix-X-option.test
  llvm/tools/llvm-ar/llvm-ar.cpp

Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -69,7 +69,10 @@
  << "  -v --version  - Display the version of this program\n"
  << "  -D- Use zero for timestamps and uids/gids "
 "(default)\n"
- << "  -U- Use actual timestamps and uids/gids\n";
+ << "  -U- Use actual timestamps and uids/gids\n"
+ << "  -X{32|64|32_64}   - Specifies which archive symbol tables "
+"should "
+"be generated if they do not already exist (AIX OS only)\n";
 }
 
 static void printArHelp(StringRef ToolName) {
@@ -225,7 +228,7 @@
 static bool CompareFullPath = false;  ///< 'P' modifier
 static bool OnlyUpdate = false;   ///< 'u' modifier
 static bool Verbose = false;  ///< 'v' modifier
-static bool Symtab = true;///< 's' modifier
+static WriteSymTabType Symtab = true; ///< 's' modifier
 static bool Deterministic = true; ///< 'D' and 'U' modifiers
 static bool Thin = false; ///< 'T' modifier
 static bool AddLibrary = false;   ///< 'L' modifier
@@ -1074,9 +1077,27 @@
   // In summary, we only need to update the symbol table if we have none.
   // This is actually very common because of broken build systems that think
   // they have to run ranlib.
-  if (OldArchive->hasSymbolTable())
-return;
+  if (OldArchive->hasSymbolTable()) {
+if (OldArchive->kind() != object::Archive::K_AIXBIG)
+  return;
 
+// For archives in the Big Archive format, the bit mode option specifies
+// which symbol table to generate. The presence of a symbol table that does
+// not match the specified bit mode does not prevent creation of the symbol
+// table that has been requested.
+if (OldArchive->kind() == object::Archive::K_AIXBIG) {
+  BigArchive *BigArc = dyn_cast(OldArchive);
+  if (BigArc->has32BitGlobalSymtab() &&
+  Symtab.getBitMode() == WriteSymTabType::BitMode::Bit32)
+return;
+
+  if (BigArc->has64BitGlobalSymtab() &&
+  Symtab.getBitMode() == WriteSymTabType::BitMode::Bit64)
+return;
+
+  Symtab.setBitMode(WriteSymTabType::BitMode::Both);
+}
+  }
   if (OldArchive->isThin())
 Thin = true;
   performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr);
@@ -1389,6 +1410,8 @@
 
 static int ranlib_main(int argc, char **argv) {
   std::vector Archives;
+
+  bool HasAIXXOption = false;
   for (int i = 1; i < argc; ++i) {
 StringRef arg(argv[i]);
 if (handleGenericOption(arg)) {
@@ -1406,6 +1429,30 @@
 } else if (arg.front() == 'v') {
   cl::PrintVersionMessage();
   return 0;
+} else if (arg.front() == 'X') {
+  if (object::Archive::getDefaultKindForHost() ==
+  object::Archive::K_AIXBIG) {
+HasAIXXOption = true;
+arg.consume_front("X");
+const char *Xarg = arg.data();
+if (Xarg[0] == '\0') {
+  if (argv[i + 1][0] != '-')
+BitMode = getBitMode(argv[++i]);
+  else
+BitMode = BitModeTy::Unknown;
+} else
+  BitMode = getBitMode(arg.data());
+
+// -X option in ranlib do not accept "any"
+if (BitMode == BitModeTy::Unknown || BitMode == BitModeTy::Any)
+  fail(
+  Twine("the specified object mode is not valid. Specify -X32, "
+

[PATCH] D155857: [clang] fix nonnull warnings during build

2023-07-20 Thread Farid Zakaria via Phabricator via cfe-commits
fzakaria updated this revision to Diff 542663.
fzakaria added a comment.

Added comment to explain why we are disabling


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155857/new/

https://reviews.llvm.org/D155857

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -770,6 +770,9 @@
   append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
   append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" 
CMAKE_CXX_FLAGS)
 
+  # Disabling this GCC warning as it is emitting a lot of false positives
+  append_if(CMAKE_COMPILER_IS_GNUCXX "-Wno-nonnull" CMAKE_CXX_FLAGS)
+
   # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
   # LLVM's ADT classes.
   check_cxx_compiler_flag("-Wclass-memaccess" 
CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -770,6 +770,9 @@
   append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
   append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
 
+  # Disabling this GCC warning as it is emitting a lot of false positives
+  append_if(CMAKE_COMPILER_IS_GNUCXX "-Wno-nonnull" CMAKE_CXX_FLAGS)
+
   # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
   # LLVM's ADT classes.
   check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76169: [WIP][AST] Allow ExprConstant to evaluate structs in C.

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers requested changes to this revision.
nickdesaulniers added a comment.
This revision now requires changes to proceed.
Herald added a project: All.

Folded into D151587 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76169/new/

https://reviews.llvm.org/D76169

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


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 542655.
gedare added a comment.

Add missing parser check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155529/new/

https://reviews.llvm.org/D155529

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16748,6 +16748,7 @@
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16822,6 +16823,12 @@
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__( ( asdf ) );", Spaces);
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("call(x, y, z);", Spaces);
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -217,6 +217,7 @@
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator);
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InAttributeSpecifiers);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
@@ -594,19 +595,23 @@
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, true));
+  FormatStyle::SpacesInParensCustom(true, true, false, false,
+  true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, false));
+  FormatStyle::SpacesInParensCustom(false, true, false, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, true, false, false));
+  FormatStyle::SpacesInParensCustom(false, false, true, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, false, true, false));
+  FormatStyle::SpacesInParensCustom(false, false, false, true,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3810,10 +3810,16 @@
   }
 
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
-return (Right.is(TT_CastRParen) ||
-(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))
-   ? Style.SpacesInParensOptions.InCStyleCasts
-   : Style.SpacesInParensOptions.Other;
+if (Right.is(TT_CastRParen) ||
+(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
+  return Style.SpacesInParensOptions.InCStyleCasts;
+}
+if (Left.is(TT_AttributeParen) || Right.is(TT_AttributeParen) ||
+(Left.Previous && Left.Previous->is(TT_AttributeParen)) ||
+(Right.Next && Right.Next->is(TT_AttributeParen))) {
+  return Style.SpacesInParensOptions.InAttributeSpecifiers;
+}
+return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
 return false;
Index: 

[PATCH] D155878: [clangd] Loose include-cleaner matching for verbatim headers

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 542653.
sammccall added a comment.
Herald added a subscriber: ChuanqiXu.

extract isPreferredProvider helper


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155878/new/

https://reviews.llvm.org/D155878

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h

Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -172,8 +172,20 @@
   /// Registers a directory on the include path (-I etc) from HeaderSearch.
   /// This allows reasoning about equivalence of e.g. "path/a/b.h" and "a/b.h".
   /// This must be called before calling add() in order to take effect.
+  ///
+  /// The paths may be relative or absolute, but the paths passed to
+  /// addSearchDirectory() and add() (that is: Include.Resolved->getName())
+  /// should be consistent, as they are compared lexically.
+  /// Generally, this is satisfied if you obtain paths through HeaderSearch
+  /// and FileEntries through PPCallbacks::IncludeDirective().
+  ///
+  /// FIXME: change Include to use FileEntryRef so callers don't have to worry
+  ///about the behavior of FileEntry::getName() to follow this contract.
   void addSearchDirectory(llvm::StringRef);
 
+  /// Registers an include directive seen in the main file.
+  ///
+  /// This should only be called after all search directories are added.
   void add(const Include &);
 
   /// All #includes seen, in the order they appear.
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -19,7 +19,9 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Syntax/Tokens.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
@@ -459,46 +461,42 @@
   MainCode.range());
 }
 
-TEST(IncludeCleaner, FirstMatchedProvider) {
-  struct {
-const char *Code;
-const std::vector Providers;
-const std::optional ExpectedProvider;
-  } Cases[] = {
-  {R"cpp(
-#include "bar.h"
-#include "foo.h"
-  )cpp",
-   {include_cleaner::Header{"bar.h"}, include_cleaner::Header{"foo.h"}},
-   include_cleaner::Header{"bar.h"}},
-  {R"cpp(
-#include "bar.h"
-#include "foo.h"
-  )cpp",
-   {include_cleaner::Header{"foo.h"}, include_cleaner::Header{"bar.h"}},
-   include_cleaner::Header{"foo.h"}},
-  {"#include \"bar.h\"",
-   {include_cleaner::Header{"bar.h"}},
-   include_cleaner::Header{"bar.h"}},
-  {"#include \"bar.h\"", {include_cleaner::Header{"foo.h"}}, std::nullopt},
-  {"#include \"bar.h\"", {}, std::nullopt}};
-  for (const auto  : Cases) {
-Annotations Code{Case.Code};
-SCOPED_TRACE(Code.code());
-
-TestTU TU;
-TU.Code = Code.code();
-TU.AdditionalFiles["bar.h"] = "";
-TU.AdditionalFiles["foo.h"] = "";
-
-auto AST = TU.build();
-std::optional MatchedProvider =
-firstMatchedProvider(
-convertIncludes(AST.getSourceManager(),
-AST.getIncludeStructure().MainFileIncludes),
-Case.Providers);
-EXPECT_EQ(MatchedProvider, Case.ExpectedProvider);
-  }
+TEST(IncludeCleaner, IsPreferredProvider) {
+  auto TU = TestTU::withCode(R"cpp(
+ #include "decl.h"
+ #include "def.h"
+
+ X *x;
+ Y *y;
+  )cpp");
+  TU.AdditionalFiles["decl.h"] = R"cpp(
+ #pragma once
+ class X;
+ class Y;
+  )cpp";
+  TU.AdditionalFiles["def.h"] = R"cpp(
+ #pragma once
+ class X {};
+ class Y;
+  )cpp";
+
+  auto AST = TU.build();
+  auto Includes = convertIncludes(AST);
+  llvm::StringMap> Providers;
+  include_cleaner::walkUsed(AST.getLocalTopLevelDecls(), {},
+AST.getPragmaIncludes(), AST.getSourceManager(),
+[&](const include_cleaner::SymbolReference ,
+llvm::ArrayRef P) {
+  Providers[llvm::to_string(Ref.Target)] = P.vec();
+});
+  auto  = AST.getIncludeStructure().MainFileIncludes.front();

[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:220
   CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InAttributeSpecifiers);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);

You forgot this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155529/new/

https://reviews.llvm.org/D155529

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Nice work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D76096: [clang] allow const structs to be constant expressions for C

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers planned changes to this revision.
nickdesaulniers added inline comments.



Comment at: clang/test/Sema/builtins.c:181-186
+  ASSERT(!OPT(test17_c));
+  ASSERT(!OPT(_c[0]));
+  ASSERT(!OPT((char*)test17_c));
   ASSERT(!OPT(test17_d));// expected-warning {{folding}}
   ASSERT(!OPT(_d[0]));// expected-warning {{folding}}
   ASSERT(!OPT((char*)test17_d)); // expected-warning {{folding}}

efriedma wrote:
> nickdesaulniers wrote:
> > `test17_c` and `test17_d` are both declared as `const char [4];` not sure 
> > why this case would differ
> `strlen(test17_c)` is 3; `strlen(test17_d)` is undefined behavior.  I assume 
> the difference is because the latter doesn't fold.
Ah right, test17_d is not a NUL-terminated C style string. I'll add a comment 
(or update the existing one) to the test about that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76096/new/

https://reviews.llvm.org/D76096

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


[PATCH] D142702: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-20 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc added inline comments.



Comment at: clang/test/Driver/aarch64-implied-sme-features.c:49
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme+sme-i16i64 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT-REV
+// SME-SUBFEATURE-CONFLICT-REV: "-target-feature" "-sme-f64f64" 
"-target-feature" "+sme-i16i64" "-target-feature" "+sme" "-target-feature" 
"+bf16"

MaskRay wrote:
> michaelplatings wrote:
> > Hi Bryan, this test fails in our downstream toolchain because it has 
> > additional features that show up in between these features. Breaking the 
> > line up as shown would fix this. Another option could be to add `{{.*}}` 
> > between the features. Doing likewise for other checks in this file would 
> > make them less brittle as well.
> First: `-target ` has been deprecated since Clang 3.4, Use `--target=` for 
> new tests.
> 
> Do you know why you have additional features? I think placing 
> `"-target-feature"` on the same line is generally a good practice. It 
> strengthens the test to ensure the feature set is compressive is not 
> interleaved by other stuff.
@michaelplatings @MaskRay  I can submit a patch quickly to fix `-target`. I am 
curious what features show up between those ones in my test, because the 
options to toggle dependent features should be added immediately after one 
another. When I placed the `"-target-feature"` strings on the same line, I was 
following the example in `aarch64-implied-sve-features.c`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142702/new/

https://reviews.llvm.org/D142702

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/AST/Expr.cpp:3462-3468
   ->isConstantInitializer(Ctx, false, Culprit);
   case CXXDefaultArgExprClass:
 return cast(this)->getExpr()
   ->isConstantInitializer(Ctx, false, Culprit);
   case CXXDefaultInitExprClass:
 return cast(this)->getExpr()
   ->isConstantInitializer(Ctx, false, Culprit);

efriedma wrote:
> nickdesaulniers wrote:
> > @efriedma should a few more of these cases be changed from passing `false` 
> > as the `ForRef` param of `isConstantInitializer` to `IsForRef`?  If I 
> > change the rest of the cases except for `MaterializeTemporaryExprClass` 
> > then tests are still green.
> One of the reasons I didn't go with this approach is that I really didn't 
> want to think about this question...
> 
> We probably don't have good test coverage for the C++ constructs, since we 
> don't really use isConstantInitializer() outside of C++03 mode.
It looks like I should be able to test this against all of Android, and against 
Google's internal C++ codebase.  Let me work through that, and see if I can 
shake out additional tests cases to add here so that we have lower risk of 
regression.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151587/new/

https://reviews.llvm.org/D151587

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


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 542651.
gedare added a comment.

Add one more attribute test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155529/new/

https://reviews.llvm.org/D155529

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16748,6 +16748,7 @@
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16822,6 +16823,12 @@
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
+  verifyFormat("void f( ) __attribute__( ( asdf ) );", Spaces);
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("call(x, y, z);", Spaces);
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -594,19 +594,23 @@
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, true));
+  FormatStyle::SpacesInParensCustom(true, true, false, false,
+  true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, false));
+  FormatStyle::SpacesInParensCustom(false, true, false, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, true, false, false));
+  FormatStyle::SpacesInParensCustom(false, false, true, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, false, true, false));
+  FormatStyle::SpacesInParensCustom(false, false, false, true,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3810,10 +3810,16 @@
   }
 
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
-return (Right.is(TT_CastRParen) ||
-(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))
-   ? Style.SpacesInParensOptions.InCStyleCasts
-   : Style.SpacesInParensOptions.Other;
+if (Right.is(TT_CastRParen) ||
+(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
+  return Style.SpacesInParensOptions.InCStyleCasts;
+}
+if (Left.is(TT_AttributeParen) || Right.is(TT_AttributeParen) ||
+(Left.Previous && Left.Previous->is(TT_AttributeParen)) ||
+(Right.Next && Right.Next->is(TT_AttributeParen))) {
+  return Style.SpacesInParensOptions.InAttributeSpecifiers;
+}
+return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -713,6 +713,7 @@
 
 template <> struct MappingTraits {
   static void mapping(IO , FormatStyle::SpacesInParensCustom ) {
+IO.mapOptional("InAttributeSpecifiers", Spaces.InAttributeSpecifiers);
 IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts);
 IO.mapOptional("InConditionalStatements", Spaces.InConditionalStatements);
 IO.mapOptional("InEmptyParentheses", 

[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 542650.
gedare added a comment.

Rebase onto D155239 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155529/new/

https://reviews.llvm.org/D155529

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16748,6 +16748,7 @@
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16822,6 +16823,11 @@
   verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
   verifyFormat("void f( ) __attribute__((asdf));", Spaces);
 
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo(int bar)", Spaces);
+  Spaces.SpacesInParensOptions.InAttributeSpecifiers = false;
+
   // Run the first set of tests again with:
   Spaces.SpaceAfterCStyleCast = true;
   verifyFormat("call(x, y, z);", Spaces);
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -594,19 +594,23 @@
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, true));
+  FormatStyle::SpacesInParensCustom(true, true, false, false,
+  true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, false, false, false));
+  FormatStyle::SpacesInParensCustom(false, true, false, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, true, false, false));
+  FormatStyle::SpacesInParensCustom(false, false, true, false,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(false, false, true, false));
+  FormatStyle::SpacesInParensCustom(false, false, false, true,
+  false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3810,10 +3810,16 @@
   }
 
   if (Left.is(tok::l_paren) || Right.is(tok::r_paren)) {
-return (Right.is(TT_CastRParen) ||
-(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))
-   ? Style.SpacesInParensOptions.InCStyleCasts
-   : Style.SpacesInParensOptions.Other;
+if (Right.is(TT_CastRParen) ||
+(Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen))) {
+  return Style.SpacesInParensOptions.InCStyleCasts;
+}
+if (Left.is(TT_AttributeParen) || Right.is(TT_AttributeParen) ||
+(Left.Previous && Left.Previous->is(TT_AttributeParen)) ||
+(Right.Next && Right.Next->is(TT_AttributeParen))) {
+  return Style.SpacesInParensOptions.InAttributeSpecifiers;
+}
+return Style.SpacesInParensOptions.Other;
   }
   if (Right.isOneOf(tok::semi, tok::comma))
 return false;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -713,6 +713,7 @@
 
 template <> struct MappingTraits {
   static void mapping(IO , FormatStyle::SpacesInParensCustom ) {
+IO.mapOptional("InAttributeSpecifiers", Spaces.InAttributeSpecifiers);
 IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts);
 IO.mapOptional("InConditionalStatements", Spaces.InConditionalStatements);
 IO.mapOptional("InEmptyParentheses", Spaces.InEmptyParentheses);
@@ -1140,6 +1141,7 @@
 

[PATCH] D142702: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/aarch64-implied-sme-features.c:49
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme+sme-i16i64 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT-REV
+// SME-SUBFEATURE-CONFLICT-REV: "-target-feature" "-sme-f64f64" 
"-target-feature" "+sme-i16i64" "-target-feature" "+sme" "-target-feature" 
"+bf16"

michaelplatings wrote:
> Hi Bryan, this test fails in our downstream toolchain because it has 
> additional features that show up in between these features. Breaking the line 
> up as shown would fix this. Another option could be to add `{{.*}}` between 
> the features. Doing likewise for other checks in this file would make them 
> less brittle as well.
First: `-target ` has been deprecated since Clang 3.4, Use `--target=` for new 
tests.

Do you know why you have additional features? I think placing 
`"-target-feature"` on the same line is generally a good practice. It 
strengthens the test to ensure the feature set is compressive is not 
interleaved by other stuff.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142702/new/

https://reviews.llvm.org/D142702

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


[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-07-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/unittests/Interpreter/CodeCompletionTest.cpp:71
+Completer(std::string("void app("), 9);
+  EXPECT_EQ((size_t)0, out.length());
+}

capfredf wrote:
> @v.g.vassilev The way I fixed this is a bit hacky. Do you have a better idea?
Now I think I understand what you were after. Instead of handling the error in 
the constructor we should handle it in the caller. Here is some information how 
we could do that: 
https://llvm.org/docs/ProgrammersManual.html#fallible-constructors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154382/new/

https://reviews.llvm.org/D154382

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D155239#4520067 , 
@HazardyKnusperkeks wrote:

> Everything is fine, I just need to know how the attribute stuff is formatted 
> with plain LLVM style.

`__attribute__` is formatted with plain LLVM style in 5-10 other test cases.  
For plain llvm style probably the best is `UnderstandsAttributes`. I did add 
the test cases at the start of `ConfigurableSpacesInParens` with plain llvm 
style to establish a baseline.

In reviewing those test cases I did see a good reason to add another test of 
attribute placement. I have now covered function decl attributes before and 
after the function name, and variable attributes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 542649.
gedare added a comment.

Add more __attribute__ test cases.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -807,7 +807,8 @@
"  if (x)\n"
"x = x;",
Style);
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("if ( x )\n"
"  x = x;\n"
"else if ( x )\n"
@@ -903,7 +904,8 @@
   verifyFormat("repeat (x) begin\n"
"end");
   auto Style = getDefaultStyle();
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("foreach ( x[x] )\n"
"  x = x;",
Style);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11031,14 +11031,16 @@
   verifyFormat("template  void operator=(T) && {}", AlignMiddle);
 
   FormatStyle Spaces = getLLVMStyle();
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Deleted =(const Deleted &) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces);
   verifyFormat("Deleted =(const Deleted &) &;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
-  Spaces.SpacesInCStyleCastParentheses = false;
-  Spaces.SpacesInParentheses = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
+  Spaces.SpacesInParensOptions.Other = true;
   verifyFormat("Deleted =( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
Spaces);
@@ -13674,7 +13676,8 @@
 
   FormatStyle SpaceBetweenBraces = getLLVMStyle();
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
-  SpaceBetweenBraces.SpacesInParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -13697,7 +13700,8 @@
 "};",
 format("vectorx{1,2,3,4,};", SpaceBetweenBraces));
   verifyFormat("vector< int > x{};", SpaceBetweenBraces);
-  SpaceBetweenBraces.SpaceInEmptyParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.InEmptyParentheses = true;
   verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
 }
 
@@ -16707,10 +16711,43 @@
   verifyFormat("! ! x", Spaces);
 }
 
-TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
+TEST_F(FormatTest, ConfigurableSpacesInParens) {
   FormatStyle Spaces = getLLVMStyle();
 
-  Spaces.SpacesInParentheses = true;
+  verifyFormat("do_something(::globalVar);", Spaces);
+  verifyFormat("call(x, y, z);", Spaces);
+  verifyFormat("call();", Spaces);
+  verifyFormat("std::function callback;", Spaces);
+  verifyFormat("void inFunction() { std::function fct; }",
+   Spaces);
+  verifyFormat("while ((bool)1)\n"
+   "  continue;",
+   Spaces);
+  verifyFormat("for (;;)\n"
+   "  continue;",
+   Spaces);
+  verifyFormat("if (true)\n"
+   "  f();\n"
+   "else if (true)\n"
+   "  f();",
+   Spaces);
+  verifyFormat("do {\n"
+   "  do_something((int)i);\n"
+   "} while (something());",
+   Spaces);
+  verifyFormat("switch (x) {\n"
+   "default:\n"
+   "  break;\n"
+   "}",
+   Spaces);
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
+  verifyFormat("void f() __attribute__((asdf));", Spaces);
+
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  

[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D155239#4520081 , @gedare wrote:

> In D155239#4520067 , 
> @HazardyKnusperkeks wrote:
>
>> Everything is fine, I just need to know how the attribute stuff is formatted 
>> with plain LLVM style.
>
> oh, sorry. plain llvm style. I will look for a good place to add that.

You can put it in the same test case in front to build the baseline.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-20 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.

This is a good change since the default copy constructor would do bad things 
when `ownsOutputFile` is true. The copy assignment operator is already 
implicitly deleted because of the presence of a data member of reference type, 
but I think it is helpful to explicitly delete both.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155842/new/

https://reviews.llvm.org/D155842

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


[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-20 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155635/new/

https://reviews.llvm.org/D155635

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


[PATCH] D155878: [clangd] Loose include-cleaner matching for verbatim headers

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This updates clangd to take advantage of the APIs added in D155819 
.
The main difficulties here are around path normalization.

For layering and performance reasons Includes compares paths lexically, and so
we should have consistent paths that can be compared across addSearchPath() and
add(): symlinks resolved or not, relative or absolute.
This patch spells out that requirement, for most tools consistent use of
FileManager/HeaderSearch is enough.

For clangd this does not work: IncludeStructure doesn't hold FileEntrys due to
the preamble/main-file split. It records paths, but canonicalizes them first.
We choose to use this canonical form as our common representation, so we have
to canonicalize the directory entries too. This is done in preamble-build and
recorded in IncludeStructure, as canonicalization is quite expensive.

Left as future work: while include-cleaner correctly uses FileEntry for Header,
as it cares about inode identity, actual Includes have a single path.
They can be modeled with FileEntryRef, and probably should be.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155878

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h

Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -172,8 +172,20 @@
   /// Registers a directory on the include path (-I etc) from HeaderSearch.
   /// This allows reasoning about equivalence of e.g. "path/a/b.h" and "a/b.h".
   /// This must be called before calling add() in order to take effect.
+  ///
+  /// The paths may be relative or absolute, but the paths passed to
+  /// addSearchDirectory() and add() (that is: Include.Resolved->getName())
+  /// should be consistent, as they are compared lexically.
+  /// Generally, this is satisfied if you obtain paths through HeaderSearch
+  /// and FileEntries through PPCallbacks::IncludeDirective().
+  ///
+  /// FIXME: change Include to use FileEntryRef so callers don't have to worry
+  ///about the behavior of FileEntry::getName() to follow this contract.
   void addSearchDirectory(llvm::StringRef);
 
+  /// Registers an include directive seen in the main file.
+  ///
+  /// This should only be called after all search directories are added.
   void add(const Include &);
 
   /// All #includes seen, in the order they appear.
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -459,48 +459,6 @@
   MainCode.range());
 }
 
-TEST(IncludeCleaner, FirstMatchedProvider) {
-  struct {
-const char *Code;
-const std::vector Providers;
-const std::optional ExpectedProvider;
-  } Cases[] = {
-  {R"cpp(
-#include "bar.h"
-#include "foo.h"
-  )cpp",
-   {include_cleaner::Header{"bar.h"}, include_cleaner::Header{"foo.h"}},
-   include_cleaner::Header{"bar.h"}},
-  {R"cpp(
-#include "bar.h"
-#include "foo.h"
-  )cpp",
-   {include_cleaner::Header{"foo.h"}, include_cleaner::Header{"bar.h"}},
-   include_cleaner::Header{"foo.h"}},
-  {"#include \"bar.h\"",
-   {include_cleaner::Header{"bar.h"}},
-   include_cleaner::Header{"bar.h"}},
-  {"#include \"bar.h\"", {include_cleaner::Header{"foo.h"}}, std::nullopt},
-  {"#include \"bar.h\"", {}, std::nullopt}};
-  for (const auto  : Cases) {
-Annotations Code{Case.Code};
-SCOPED_TRACE(Code.code());
-
-TestTU TU;
-TU.Code = Code.code();
-TU.AdditionalFiles["bar.h"] = "";
-TU.AdditionalFiles["foo.h"] = "";
-
-auto AST = TU.build();
-std::optional MatchedProvider =
-firstMatchedProvider(
-convertIncludes(AST.getSourceManager(),
-AST.getIncludeStructure().MainFileIncludes),
-Case.Providers);
-EXPECT_EQ(MatchedProvider, Case.ExpectedProvider);
-  }
-}
-
 TEST(IncludeCleaner, BatchFix) {
   TestTU TU;
   TU.Filename = "main.cpp";
@@ -564,6 +522,32 @@
  

[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 542632.
gedare added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -807,7 +807,8 @@
"  if (x)\n"
"x = x;",
Style);
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("if ( x )\n"
"  x = x;\n"
"else if ( x )\n"
@@ -903,7 +904,8 @@
   verifyFormat("repeat (x) begin\n"
"end");
   auto Style = getDefaultStyle();
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("foreach ( x[x] )\n"
"  x = x;",
Style);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11031,14 +11031,16 @@
   verifyFormat("template  void operator=(T) && {}", AlignMiddle);
 
   FormatStyle Spaces = getLLVMStyle();
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Deleted =(const Deleted &) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces);
   verifyFormat("Deleted =(const Deleted &) &;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
-  Spaces.SpacesInCStyleCastParentheses = false;
-  Spaces.SpacesInParentheses = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
+  Spaces.SpacesInParensOptions.Other = true;
   verifyFormat("Deleted =( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
Spaces);
@@ -13674,7 +13676,8 @@
 
   FormatStyle SpaceBetweenBraces = getLLVMStyle();
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
-  SpaceBetweenBraces.SpacesInParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -13697,7 +13700,8 @@
 "};",
 format("vectorx{1,2,3,4,};", SpaceBetweenBraces));
   verifyFormat("vector< int > x{};", SpaceBetweenBraces);
-  SpaceBetweenBraces.SpaceInEmptyParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.InEmptyParentheses = true;
   verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
 }
 
@@ -16707,10 +16711,13 @@
   verifyFormat("! ! x", Spaces);
 }
 
-TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
+TEST_F(FormatTest, ConfigurableSpacesInParens) {
   FormatStyle Spaces = getLLVMStyle();
 
-  Spaces.SpacesInParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16737,9 +16744,12 @@
"  break;\n"
"}",
Spaces);
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
 
-  Spaces.SpacesInParentheses = false;
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Type *A = ( Type * )P;", Spaces);
   verifyFormat("Type *A = ( vector )P;", Spaces);
   verifyFormat("x = ( int32 )y;", Spaces);
@@ -16750,9 +16760,10 @@
   verifyFormat("#define x (( int )-1)", Spaces);
 
   // Run the first set of tests again with:
-  Spaces.SpacesInParentheses = false;
-  Spaces.SpaceInEmptyParentheses = true;
-  

[PATCH] D155846: [NFC][clang] Fix static analyzer concerns

2023-07-20 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

> there's no bug being fixed which makes me think this should go back to the 
> static analysis vendor to report this as a false positive.

I agree. I'll try to isolate a reproducible test case and report it to the 
vendor.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155846/new/

https://reviews.llvm.org/D155846

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


[PATCH] D154324: [C++20] [Modules] [ODRHash] Use CanonicalType for base classes

2023-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D154324#4516964 , @alexfh wrote:

> In D154324#4516917 , @ChuanqiXu 
> wrote:
>
>> Maybe we got something wrong with this. I'd like to revert this patch in 
>> case it breaks something. But would you like to reduce your reproducer 
>> further to a state without external includes to STL or protobuf? Then we can 
>> add the reduced reproducer to the tests to avoid further regressions.
>
> That turned out to be quite time-consuming, but I can try nevertheless. I 
> also asked @rsmith if he could figure out what the problem is. Hopefully, he 
> can help with the test case, if gets to the bottom of the problem.

I have a reduced reproducer, but I still depends on the internal build setup. I 
need a bit more time to make the reproducer standalone.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154324/new/

https://reviews.llvm.org/D154324

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


[PATCH] D76096: [clang] allow const structs to be constant expressions for C

2023-07-20 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/test/Sema/builtins.c:181-186
+  ASSERT(!OPT(test17_c));
+  ASSERT(!OPT(_c[0]));
+  ASSERT(!OPT((char*)test17_c));
   ASSERT(!OPT(test17_d));// expected-warning {{folding}}
   ASSERT(!OPT(_d[0]));// expected-warning {{folding}}
   ASSERT(!OPT((char*)test17_d)); // expected-warning {{folding}}

nickdesaulniers wrote:
> `test17_c` and `test17_d` are both declared as `const char [4];` not sure why 
> this case would differ
`strlen(test17_c)` is 3; `strlen(test17_d)` is undefined behavior.  I assume 
the difference is because the latter doesn't fold.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76096/new/

https://reviews.llvm.org/D76096

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D155239#4520067 , 
@HazardyKnusperkeks wrote:

> Everything is fine, I just need to know how the attribute stuff is formatted 
> with plain LLVM style.

oh, sorry. plain llvm style. I will look for a good place to add that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/baremetal.cpp:348
 
+// RUN: %clang %s -### --target=powerpc-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPCEABI %s

MaskRay wrote:
> Without a sysroot, we may pick up powerpc-unknown-eabi-gcc (if installed) and 
> the paths below may be incorrect.
I managed to notice an issue. See the commit message of the follow-up fix: 
eddc4850d81f4c9f79d0b17869d67eac8ca88070 (really obscure,  I forgot it...)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154357/new/

https://reviews.llvm.org/D154357

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:16748
+  verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
 

and here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:16791
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
 

@HazardyKnusperkeks here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Everything is fine, I just need to know how the attribute stuff is formatted 
with plain LLVM style.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D154093: [clang-format] Break long strings in Verilog

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Apart from that I'm okay.




Comment at: clang/lib/Format/WhitespaceManager.cpp:1428
+  // case, it is allowed if there is a replacement for the empty range
+  // between 2 tokens and another non-empty range at the start of the 
second
+  // token.

HazardyKnusperkeks wrote:
> Can you elaborate where the 2 replacements come from, and why we can't make 
> sure there is no empty range?
This is open (at least for me).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154093/new/

https://reviews.llvm.org/D154093

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


[PATCH] D155783: [clang-format] Fix variable lacks of blank when previous operator is star

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Please provide a diff with the full context (`-U99` will do the trick).

And another context is needed, just `x * y` will never be (meaningful) be 
formatted. At least a `;` is missing, and I'd argue if your example is just

  ... something ...
  x * y;
  ... something ...

Your patch is wrong. While it is of course possible to just multiply something 
and drop the result, that's nonsense.
If the overloaded `operator*` has side effects, that's also possible, but bad 
code.
But defining a pointer `y` pointing to type `x` and not initializing it 
directly is more often the case:

  struct x;
  x* y;
  ... something ...




Comment at: clang/unittests/Format/FormatTest.cpp:96
   EXPECT_EQ(0, ReplacementCount);
+  EXPECT_EQ("x*y",
+format("x * y"));

This is the wrong place.

You want a TokenAnnotatorTests, there is UnderstandStarAmp or something like 
that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155783/new/

https://reviews.llvm.org/D155783

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


[PATCH] D154368: [Clang] Fix constraint checking of non-generic lambdas.

2023-07-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from some questions about comments in the test.




Comment at: clang/test/SemaTemplate/concepts.cpp:531
   SingleDepthReferencesTopLambda(v);
   // FIXME: This should error on constraint failure! (Lambda!)
   SingleDepthReferencesTopLambda(will_fail);

Comment is now stale and can be removed?



Comment at: clang/test/SemaTemplate/concepts.cpp:580
   ChecksLocalVar(v);
   // FIXME: This should error on constraint failure! (Lambda!)
   ChecksLocalVar(will_fail);

This one can also be removed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154368/new/

https://reviews.llvm.org/D154368

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


[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-20 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay added a comment.

In D155635#4512243 , @ABataev wrote:

> In D155635#4512188 , @mdfazlay 
> wrote:
>
>> In D155635#4512183 , @ABataev 
>> wrote:
>>
>>> Tests?
>>
>> I think I need to use `-fopenmp-version=60` to test this revision. As OMP 
>> 6.0 is not official yet, am I allowed to use `-fopenmp-version=60` in my LIT 
>> test?
>
> Yes

I have added a few LIT tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155635/new/

https://reviews.llvm.org/D155635

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


[PATCH] D155857: [clang] fix nonnull warnings during build

2023-07-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision as: rsmith.
rsmith added a comment.
This revision is now accepted and ready to land.

Seems reasonable to me. Given that this affects all of LLVM I'd like to wait a 
day or so to see if anyone has concerns.




Comment at: llvm/cmake/modules/HandleLLVMOptions.cmake:774
+
+  append_if(CMAKE_COMPILER_IS_GNUCXX "-Wno-nonnull" CMAKE_CXX_FLAGS)
+

It'd be useful to leave a comment for future readers that we're disabling this 
due to false positives.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155857/new/

https://reviews.llvm.org/D155857

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


[PATCH] D155857: [clang] fix nonnull warnings during build

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Perhaps this can be placed beside `llvm/cmake/config-ix.cmake` 
`-Wmaybe-uninitialized`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155857/new/

https://reviews.llvm.org/D155857

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


[clang] 04cc892 - Speculatively fix Clang build bots

2023-07-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-07-20T15:11:52-04:00
New Revision: 04cc892eedf579584f642670efd71a5e6fd1494d

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

LOG: Speculatively fix Clang build bots

This is intended to address the issues found in:
https://lab.llvm.org/buildbot/#/builders/192/builds/3337
https://lab.llvm.org/buildbot/#/builders/124/builds/7968

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9e2845384bc170..30e8e380e6596b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16925,7 +16925,7 @@ bool Sema::EvaluateStaticAssertMessageAsString(Expr 
*Message,
 OverloadCandidateSet::iterator Best;
 switch (Candidates.BestViableFunction(*this, Loc, Best)) {
 case OR_Success:
-  return MemberLookup;
+  return std::move(MemberLookup);
 default:
   if (Diag)
 Candidates.NoteCandidates(



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


[PATCH] D155857: [clang] fix nonnull warnings during build

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Perhaps `-Wno-nonnull` should be GCC specific (i.e. not apply to Clang).

This option will disable certain warnings related to Clang `_Nonnull` (seems 
unused in llvm-project) and `__attribute__((nonnull))` (used in a few places).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155857/new/

https://reviews.llvm.org/D155857

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


[PATCH] D76096: [clang] allow const structs to be constant expressions for C

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Sema/builtins.c:181-186
+  ASSERT(!OPT(test17_c));
+  ASSERT(!OPT(_c[0]));
+  ASSERT(!OPT((char*)test17_c));
   ASSERT(!OPT(test17_d));// expected-warning {{folding}}
   ASSERT(!OPT(_d[0]));// expected-warning {{folding}}
   ASSERT(!OPT((char*)test17_d)); // expected-warning {{folding}}

`test17_c` and `test17_d` are both declared as `const char [4];` not sure why 
this case would differ


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76096/new/

https://reviews.llvm.org/D76096

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


[PATCH] D154755: [clang-format] Fix formatting of if statements with BlockIndent

2023-07-20 Thread Gedare Bloom via Phabricator via cfe-commits
gedare marked 3 inline comments as done.
gedare added a comment.

I have fixed the bug in a different way that avoids using `BlockIndent` on `if` 
conditionals. `AlwaysBreak` will continue to apply to `if` conditionals by 
default. I may propose a style option to control that behavior later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154755/new/

https://reviews.llvm.org/D154755

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


[PATCH] D76096: [clang] allow const structs to be constant expressions for C

2023-07-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 542627.
nickdesaulniers retitled this revision from "[clang] allow const structs to be 
constant expressions in initializer lists" to "[clang] allow const structs to 
be constant expressions for C".
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- rebase onto D151587 
- replace my impl with D76169 
- update description


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76096/new/

https://reviews.llvm.org/D76096

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/builtin-constant-p.c
  clang/test/CodeGen/const-init.c
  clang/test/Sema/builtins.c
  clang/test/Sema/init.c

Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,36 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { (uintptr_t) }; // expected-error {{initializer element is not a compile-time constant}}
+
+// PR45157
+struct PR4517_foo {};
+struct PR4517_bar {
+  struct PR4517_foo foo;
+};
+const struct PR4517_foo my_foo = {};
+struct PR4517_bar my_bar = {
+.foo = my_foo, // no-warning
+};
+struct PR4517_bar my_bar2 = (struct PR4517_bar){
+.foo = my_foo, // no-warning
+};
+struct PR4517_bar my_bar3 = {
+my_foo, // no-warning
+};
+struct PR4517_bar my_bar4 = (struct PR4517_bar){
+my_foo // no-warning
+};
+extern const struct PR4517_foo my_foo2;
+struct PR4517_bar my_bar5 = {
+  .foo = my_foo2, // expected-error {{initializer element is not a compile-time constant}}
+};
+int PR4517_a[2] = {0, 1};
+const int PR4517_ca[2] = {0, 1};
+int PR4517_idx = 0;
+const int PR4517_idxc = 1;
+int PR4517_x1 = PR4517_a[PR4517_idx]; // expected-error {{initializer element is not a compile-time constant}}
+int PR4517_x2 = PR4517_a[PR4517_idxc]; // expected-error {{initializer element is not a compile-time constant}}
+int PR4517_x3 = PR4517_a[0]; // expected-error {{initializer element is not a compile-time constant}}
+int PR4517_y1 = PR4517_ca[PR4517_idx]; // expected-error {{initializer element is not a compile-time constant}}
+int PR4517_y2 = PR4517_ca[PR4517_idxc]; // no-warning
+int PR4517_y3 = PR4517_ca[0]; // no-warning
Index: clang/test/Sema/builtins.c
===
--- clang/test/Sema/builtins.c
+++ clang/test/Sema/builtins.c
@@ -178,9 +178,9 @@
   ASSERT(!OPT("abcd"));
   // In these cases, the strlen is non-constant, but the __builtin_constant_p
   // is 0: the array size is not an ICE but is foldable.
-  ASSERT(!OPT(test17_c));// expected-warning {{folding}}
-  ASSERT(!OPT(_c[0]));// expected-warning {{folding}}
-  ASSERT(!OPT((char*)test17_c)); // expected-warning {{folding}}
+  ASSERT(!OPT(test17_c));
+  ASSERT(!OPT(_c[0]));
+  ASSERT(!OPT((char*)test17_c));
   ASSERT(!OPT(test17_d));// expected-warning {{folding}}
   ASSERT(!OPT(_d[0]));// expected-warning {{folding}}
   ASSERT(!OPT((char*)test17_d)); // expected-warning {{folding}}
Index: clang/test/CodeGen/const-init.c
===
--- clang/test/CodeGen/const-init.c
+++ clang/test/CodeGen/const-init.c
@@ -190,3 +190,28 @@
 struct { const float *floats; } compoundliteral = {
   (float[1]) { 0.1, },
 };
+
+struct PR4517_foo {
+  int x;
+};
+struct PR4517_bar {
+  struct PR4517_foo foo;
+};
+const struct PR4517_foo my_foo = {.x = 42};
+struct PR4517_bar my_bar = {.foo = my_foo};
+struct PR4517_bar my_bar2 = (struct PR4517_bar){.foo = my_foo};
+struct PR4517_bar my_bar3 = {my_foo};
+struct PR4517_bar my_bar4 = (struct PR4517_bar){my_foo};
+// CHECK: @my_foo = constant %struct.PR4517_foo { i32 42 }, align 4
+// CHECK: @my_bar = global %struct.PR4517_bar { %struct.PR4517_foo { i32 42 } }, align 4
+// CHECK: @my_bar2 = global %struct.PR4517_bar { %struct.PR4517_foo { i32 42 } }, align 4
+// CHECK: @my_bar3 = global %struct.PR4517_bar { %struct.PR4517_foo { i32 42 } }, align 4
+// CHECK: @my_bar4 = global %struct.PR4517_bar { %struct.PR4517_foo { i32 42 } }, align 4
+const int PR4517_arrc[2] = {41, 42};
+int PR4517_x = PR4517_arrc[1];
+const int PR4517_idx = 1;
+int PR4517_x2 = PR4517_arrc[PR4517_idx];
+// CHECK: @PR4517_arrc = constant [2 x i32] [i32 41, i32 42], align 4
+// CHECK: @PR4517_x = global i32 42, align 4
+// CHECK: @PR4517_idx = constant i32 1, align 4
+// CHECK: @PR4517_x2 = global i32 42, align 4
Index: clang/test/CodeGen/builtin-constant-p.c
===
--- clang/test/CodeGen/builtin-constant-p.c
+++ clang/test/CodeGen/builtin-constant-p.c
@@ -76,7 +76,7 @@
 
 int test7(void) {
   // CHECK-LABEL: test7
-  // CHECK: call i1 @llvm.is.constant.i32
+  // CHECK: ret i32 1
   return 

[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-07-20 Thread Fred Fu via Phabricator via cfe-commits
capfredf added inline comments.



Comment at: clang/unittests/Interpreter/CodeCompletionTest.cpp:71
+Completer(std::string("void app("), 9);
+  EXPECT_EQ((size_t)0, out.length());
+}

@v.g.vassilev The way I fixed this is a bit hacky. Do you have a better idea?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154382/new/

https://reviews.llvm.org/D154382

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


  1   2   3   >