[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [7/7]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520611.
barannikov88 retitled this revision from "[clang][CodeGen] Break up 
TargetInfo.cpp [6/6]" to "[clang][CodeGen] Break up TargetInfo.cpp [7/7]".
barannikov88 edited the summary of this revision.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AArch64.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/AMDGPU.h
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARC.h
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/ARM.h
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/AVR.h
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/BPF.h
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/CSKY.h
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Hexagon.h
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/Lanai.h
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/LoongArch.h
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/M68k.h
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/MSP430.h
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/Mips.h
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/NVPTX.h
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PNaCl.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/PPC.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/RISCV.h
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/SPIR.h
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/Sparc.h
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/SystemZ.h
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/TCE.h
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/VE.h
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/WebAssembly.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/X86.h
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/lib/CodeGen/Targets/XCore.h
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [7/7]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520613.
barannikov88 added a comment.

Remove introduced duplicate functions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AArch64.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/AMDGPU.h
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARC.h
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/ARM.h
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/AVR.h
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/BPF.h
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/CSKY.h
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Hexagon.h
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/Lanai.h
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/LoongArch.h
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/M68k.h
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/MSP430.h
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/Mips.h
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/NVPTX.h
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PNaCl.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/PPC.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/RISCV.h
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/SPIR.h
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/Sparc.h
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/SystemZ.h
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/TCE.h
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/VE.h
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/WebAssembly.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/X86.h
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/lib/CodeGen/Targets/XCore.h
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-05-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks! LGTM with one final nit (the other comment is just food for future 
thought)




Comment at: clang-tools-extra/clangd/Hover.cpp:503
+
+std::optional printExprValue(const SelectionTree::Node *N,
+  const ASTContext &Ctx) {

nit: just inline this into its only call site as `doPrintExprValue(N, 
Ctx).PrintedValue` (and then we can call the function `printExprValue` instead 
of `doPrintExprValue`)



Comment at: clang-tools-extra/clangd/Hover.cpp:705
+
+  // If macro expands to one single token, rule out punctuator or digraph.
+  // E.g., for the case `array L_BRACKET 42 R_BRACKET;` where L_BRACKET and

zyounan wrote:
> nridge wrote:
> > This check for punctuators actually makes the behaviour **more strict** for 
> > macros than for non-macros in some cases.
> > 
> > For example:
> > 
> > ```
> > #define PLUS +
> > 
> > constexpr int A = 2 + 3;  // hover over `+` shows `Value = 5`
> > constexpr int B = 2 PLUS 3;  // hover over `PLUS` does not show `Value`
> > ```
> > 
> > I don't think this is a particularly important use case (it's a bit of a 
> > hack to get the expression's value this way, much better would be to select 
> > the entire expression you want to evaluate in the editor, but unfortunately 
> > LSP only sends a single position in `textDocument/hover`, not a full 
> > range...), but perhaps we could consider relaxing this in the future. (I'm 
> > thinking, if we switched to "allow partial selection via macros that expand 
> > to a single token", we could probably drop this condition.)
> Thanks for clarifying this intention (for any bug hunter in the future).
> > if we switched to "allow partial selection via macros that expand to a 
> > single token", we could probably drop this condition.
> 
> I'm afraid we can't. For the array case in the test,
> ```
> vector left_b^racket 3 right_b^racket;
> // left_bracket -> [
> // right_bracket -> ]
> ```
> the associated selection tree is,
> ```
>  TranslationUnitDecl 
>FunctionDecl void function()
>  CompoundStmt { …
>   .ArraySubscriptExpr vector[3]
> ```
> (`function` is the wrapper that facilitates writing single expression, 
> doesn't matter here.)
> It expands to one single token and is partially selected, which exactly 
> matches the strategy. If we do allow evaluation, we'd get a value/type on `[` 
> or `]`. Yes, it is a contrived and weird use case, but for now I think it's 
> fine to keep it unevaluated to avoid issue aforementioned.
> 
> (But I'm willing to remove this restriction if you prefer a relaxed strategy.)
> If we do allow evaluation, we'd get a value/type on [ or ].

Out of curiosity, I tried commenting out this condition locally, and the 
`left_bracket` test case still passed for me.

The reason is that in that test case, the ArraySubscriptExpr cannot be 
evaluated (we don't know what the array values are).

In a modified version of the testcase where the array values are known, but 
macros are not used:

```
int main() {
  constexpr int vector[3] = {1, 2, 3};
  vector [ 2 ];
}
```

hovering over the `[` or `]` does work (in clangd today, no patch needed).

(But maybe a hover in this situation is more confusing than useful, and it 
would be better if it didn't work?)

Anyways, we can discuss this further in follow-up issues like 
https://github.com/clangd/clangd/issues/1622, I think this is good enough for 
now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


cfe-commits@lists.llvm.org

2023-05-09 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-05-09T07:42:20Z
New Revision: 0c852dc88e9276b74532fd7d233dd23ec1bbed6f

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

LOG: [clang][dataflow][NFC] Remove `SkipPast` param from `getValue(const 
ValueDecl &)`.

This parameter was already a no-op, so removing it doesn't change behavior.

Reviewed By: ymandel

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 7f24755d9923a..c23e0db7f82d3 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -314,11 +314,7 @@ class Environment {
 
   /// Equivalent to `getValue(getStorageLocation(D, SP), SkipPast::None)` if 
`D`
   /// is assigned a storage location in the environment, otherwise returns 
null.
-  ///
-  /// The `SP` parameter is deprecated and has no effect. In addition, it is
-  /// not permitted to pass `SkipPast::ReferenceThenPointer` for this 
parameter.
-  /// New uses of this function should use the default argument for `SP`.
-  Value *getValue(const ValueDecl &D, SkipPast SP = SkipPast::None) const;
+  Value *getValue(const ValueDecl &D) const;
 
   /// Equivalent to `getValue(getStorageLocation(E, SP), SkipPast::None)` if 
`E`
   /// is assigned a storage location in the environment, otherwise returns 
null.

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 479aa12d191ee..0d269f503f4eb 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -680,9 +680,7 @@ Value *Environment::getValue(const StorageLocation &Loc) 
const {
   return It == LocToVal.end() ? nullptr : It->second;
 }
 
-Value *Environment::getValue(const ValueDecl &D, SkipPast SP) const {
-  assert(SP != SkipPast::ReferenceThenPointer);
-
+Value *Environment::getValue(const ValueDecl &D) const {
   auto *Loc = getStorageLocation(D);
   if (Loc == nullptr)
 return nullptr;

diff  --git a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
index 86feca486ec7c..f88a179f93a45 100644
--- a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -158,7 +158,7 @@ TEST(ChromiumCheckModelTest, 
CheckSuccessImpliesConditionHolds) {
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-auto *FooVal = cast(Env.getValue(*FooDecl, SkipPast::None));
+auto *FooVal = cast(Env.getValue(*FooDecl));
 
 EXPECT_TRUE(Env.flowConditionImplies(*FooVal));
   };
@@ -189,7 +189,7 @@ TEST(ChromiumCheckModelTest, UnrelatedCheckIgnored) {
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-auto *FooVal = cast(Env.getValue(*FooDecl, SkipPast::None));
+auto *FooVal = cast(Env.getValue(*FooDecl));
 
 EXPECT_FALSE(Env.flowConditionImplies(*FooVal));
   };

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index 2f874b44c49bf..1c78dd380c774 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -124,7 +124,7 @@ TEST_F(EnvironmentTest, InitGlobalVarsFun) {
 
   // Verify the global variable is populated when we analyze `Target`.
   Environment Env(DAContext, *Fun);
-  EXPECT_THAT(Env.getValue(*Var, SkipPast::None), NotNull());
+  EXPECT_THAT(Env.getValue(*Var), NotNull());
 }
 
 // Tests that fields mentioned only in default member initializers are included
@@ -255,7 +255,7 @@ TEST_F(EnvironmentTest, InitGlobalVarsConstructor) {
 
   // Verify the global variable is populated when we analyze `Target`.
   Environment Env(DAContext, *Ctor);
-  EXPECT_THAT(En

cfe-commits@lists.llvm.org

2023-05-09 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c852dc88e92: [clang][dataflow][NFC] Remove `SkipPast` param 
from `getValue(const ValueDecl… (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150137

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -489,8 +489,7 @@
 ASSERT_THAT(FooDecl, NotNull());
 
 auto GetFooValue = [FooDecl](const Environment &Env) {
-  return cast(
-  Env.getValue(*FooDecl, SkipPast::None)->getProperty("is_set"));
+  return cast(Env.getValue(*FooDecl)->getProperty("is_set"));
 };
 
 EXPECT_FALSE(Env1.flowConditionImplies(*GetFooValue(Env1)));
@@ -640,7 +639,7 @@
 ASSERT_THAT(FooDecl, NotNull());
 
 auto GetFooValue = [FooDecl](const Environment &Env) {
-  return Env.getValue(*FooDecl, SkipPast::None);
+  return Env.getValue(*FooDecl);
 };
 
 EXPECT_EQ(GetFooValue(Env1)->getProperty("has_value"),
@@ -685,7 +684,7 @@
 ASSERT_THAT(FooDecl, NotNull());
 
 auto GetFooValue = [FooDecl](const Environment &Env) {
-  return Env.getValue(*FooDecl, SkipPast::None);
+  return Env.getValue(*FooDecl);
 };
 
 EXPECT_EQ(GetFooValue(Env1)->getProperty("has_value"),
@@ -725,8 +724,7 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *BarVal =
-cast(Env.getValue(*BarDecl, SkipPast::None));
+const auto *BarVal = cast(Env.getValue(*BarDecl));
 EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc);
   });
 }
@@ -755,7 +753,7 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *FooVal = Env.getValue(*FooDecl);
 EXPECT_EQ(FooVal->getProperty("has_value"),
   &Env.getBoolLiteralValue(true));
   });
@@ -804,13 +802,11 @@
 ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
 
 const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
-auto *FooVal1 =
-cast(Env1.getValue(*FooDecl, SkipPast::None));
+auto *FooVal1 = cast(Env1.getValue(*FooDecl));
 EXPECT_TRUE(Env1.flowConditionImplies(*FooVal1));
 
 const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
-auto *FooVal2 =
-cast(Env2.getValue(*FooDecl, SkipPast::None));
+auto *FooVal2 = cast(Env2.getValue(*FooDecl));
 EXPECT_FALSE(Env2.flowConditionImplies(*FooVal2));
   });
 }
@@ -837,13 +833,11 @@
 ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
 
 const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
-auto *FooVal1 =
-cast(Env1.getValue(*FooDecl, SkipPast::None));
+auto *FooVal1 = cast(Env1.getValue(*FooDecl));
 EXPECT_FALSE(Env1.flowConditionImplies(*FooVal1));
 
 const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
-auto *FooVal2 =
-cast(Env2.getValue(*FooDecl, SkipPast::None));
+auto *FooVal2 = cast(Env2.getValue(*FooDecl));
 EXPECT_TRUE(Env2.flowConditionImplies(*FooVal2));
   });
 }
@@ -867,7 +861,7 @@
 ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
 const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
-auto *FooVal = cast(Env.getValue(*FooDecl, SkipPast::None));
+auto *FooVal = cast(Env.getValue(*FooDecl));
 EXPECT_TRUE(Env.flowConditionImplies(*FooVal));
   });
 }
@@ -896,14 +890,14 @@
 ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
 
 const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
-auto *FooVal1 = cast(Env1.getValue(*FooDecl, SkipPast::None));
-auto *BarVal1 = cast(Env1.getValue(*BarDecl, SkipPast::None));
+auto *FooVal1 = cast(Env1.getValue(*FooDecl));
+auto *BarVal1 = cast(Env1.getValue(*BarDecl));
 EXPECT_TRUE(Env1.flow

[clang] cac4d7f - [CodeGen] Only consider innermost cast for !heapallocsite

2023-05-09 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-05-09T09:49:42+02:00
New Revision: cac4d7ff4652815e12132c990a62d68873ba4b9e

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

LOG: [CodeGen] Only consider innermost cast for !heapallocsite

Without opaque pointers, this code determined !heapallocsite based
on the innermost cast of the allocation call. With opaque pointers,
the casts no longer generate an instruction, so the outermost cast
is used. Add an explicit check for nested casts to prevent this.

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/debug-info-codeview-heapallocsite.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 2243c75ed2608..cf24e3211dbc3 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2098,7 +2098,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 
 // Update heapallocsite metadata when there is an explicit pointer cast.
 if (auto *CI = dyn_cast(Src)) {
-  if (CI->getMetadata("heapallocsite") && isa(CE)) {
+  if (CI->getMetadata("heapallocsite") && isa(CE) &&
+  !isa(E)) {
 QualType PointeeType = DestTy->getPointeeType();
 if (!PointeeType.isNull())
   CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType,

diff  --git a/clang/test/CodeGen/debug-info-codeview-heapallocsite.c 
b/clang/test/CodeGen/debug-info-codeview-heapallocsite.c
index a8cae112dcec2..6cc34f688e4dc 100644
--- a/clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ b/clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc 
-debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited 
-gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
 
 struct Foo;
 struct Bar;
@@ -14,10 +14,10 @@ void call_alloc(void) {
 }
 
 // CHECK-LABEL: define {{.*}}void @call_alloc
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
+// CHECK: call ptr {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"



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


[PATCH] D145788: [CodeGen] Only consider innermost cast for !heapallocsite

2023-05-09 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcac4d7ff4652: [CodeGen] Only consider innermost cast for 
!heapallocsite (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145788

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc 
-debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited 
-gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
 
 struct Foo;
 struct Bar;
@@ -14,10 +14,10 @@
 }
 
 // CHECK-LABEL: define {{.*}}void @call_alloc
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
+// CHECK: call ptr {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2098,7 +2098,8 @@
 
 // Update heapallocsite metadata when there is an explicit pointer cast.
 if (auto *CI = dyn_cast(Src)) {
-  if (CI->getMetadata("heapallocsite") && isa(CE)) {
+  if (CI->getMetadata("heapallocsite") && isa(CE) &&
+  !isa(E)) {
 QualType PointeeType = DestTy->getPointeeType();
 if (!PointeeType.isNull())
   CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType,


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
 
 struct Foo;
 struct Bar;
@@ -14,10 +14,10 @@
 }
 
 // CHECK-LABEL: define {{.*}}void @call_alloc
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
-// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
+// CHECK: call ptr {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
+// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2098,7 +2098,8 @@
 
 // Update heapallocsite metadata when there is an explicit pointer cast.
 if (auto *CI = dyn_cast(Src)) {
-  if (CI->getMetadata("heapallocsite") && isa(CE)) {
+  if (CI->getMetadata("heapallocsite") && isa(CE) &&
+  !isa(E)) {
 QualType PointeeType = DestTy->getPointeeType();
 if (!PointeeType.isNull())
   CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150181: [XCOFF][DWARF] XCOFF64 should be able to select the dwarf version under intergrated-as mode.

2023-05-09 Thread Esme Yi via Phabricator via cfe-commits
Esme created this revision.
Esme added reviewers: shchenz, lkail, PowerPC, DiggerLin.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Esme requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

DWARF32 is not supported for XCOFF64 under non integrated-as mode, because 
system assembler will fill the debug section lengths according to DWARF64 
format.
While in intergrated-as mode, XCOFF64 should be able to select the DWARF 
version.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150181

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/XCOFF/dwarf-format.ll


Index: llvm/test/DebugInfo/XCOFF/dwarf-format.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/XCOFF/dwarf-format.ll
@@ -0,0 +1,33 @@
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj %s -o - \
+; RUN:   | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK
+
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -dwarf64 %s -o - \
+; RUN:   | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK64
+
+; CHECK: file format aix5coff64-rs6000
+; CHECK: format: DWARF32
+
+; CHECK64: file format aix5coff64-rs6000
+; CHECK64: format: DWARF64
+
+source_filename = "1.c"
+target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
+
+@foo = global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, 
type: !5, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang 
version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: 
FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "1.c", directory: "llvm-project")
+!4 = !{!0}
+!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!6 = !{i32 7, !"Dwarf Version", i32 3}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{i32 1, !"wchar_size", i32 2}
+!9 = !{i32 8, !"PIC Level", i32 2}
+!10 = !{i32 7, !"frame-pointer", i32 2}
+!11 = !{!"clang version 17.0.0"}
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -389,6 +389,7 @@
   DwarfVersion =
   TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION);
 
+  bool UseIntegratedAs = Asm->OutStreamer->isIntegratedAssemblerRequired();
   bool Dwarf64 = DwarfVersion >= 3 && // DWARF64 was introduced in DWARFv3.
  TT.isArch64Bit();// DWARF64 requires 64-bit relocations.
 
@@ -396,15 +397,18 @@
   // 1: For ELF when requested.
   // 2: For XCOFF64: the AIX assembler will fill in debug section lengths
   //according to the DWARF64 format for 64-bit assembly, so we must use
-  //DWARF64 in the compiler too for 64-bit mode.
+  //DWARF64 in the compiler for 64-bit mode on non-integrated-as mode.
   Dwarf64 &=
-  ((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
-   TT.isOSBinFormatELF()) ||
-  TT.isOSBinFormatXCOFF();
-
-  if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF())
-report_fatal_error("XCOFF requires DWARF64 for 64-bit mode!");
-
+  ((TT.isOSBinFormatELF() ||
+(TT.isOSBinFormatXCOFF() && UseIntegratedAs)) &&
+   (Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64())) ||
+  (TT.isOSBinFormatXCOFF() && !UseIntegratedAs);
+
+  if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF() &&
+  !UseIntegratedAs)
+report_fatal_error(
+"XCOFF requires DWARF64 for 64-bit mode on non-integrated-as mode!");
+  
   UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
 
   // Use sections as references. Force for NVPTX.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4131,9 +4131,9 @@
 else if (!T.isArch64Bit())
   D.Diag(diag::err_drv_argument_only_allowed_with)
   << DwarfFormatArg->getAsString(Args) << "64 bit architecture";
-else if (!T.isOSBinFormatELF())
+else if (!(T.isOSBinFormatELF() || T.isOSBinFormatXCOFF()))
   D.Diag(diag::err_drv_argument_only_allowed_with)
-  << DwarfFormatArg->getAsString(Args) << "ELF platforms";
+  << DwarfFormatArg->getAsString(Args) << "ELF/XCOFF platforms";
   }
 
   DwarfFormatArg->render(Args, CmdArgs);


Index: llvm/test/DebugInfo/XCOFF/dwarf-format.ll
===
--- /dev/null
+++ ll

[PATCH] D143260: [clangd] Add semantic token for labels

2023-05-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

(sorry for taking so long to get back to this)

In D143260#4270807 , @nridge wrote:

> In the case of labels (and angle brackets (D139926 
> ) and operators (D136594 
> )), the set of users benefiting from them 
> includes presumably "all QtCreator users" (assuming QtCreator assigns a 
> default color to these).

thanks this is useful, i think i know about this reasoning in the previous two 
reviews but wasn't sure about this one.

> You're right that vscode users don't benefit from them unless they configure 
> `semanticTokenColorCustomizations`; in my mind, this is a reason for us to 
> write some vscode themes, rather than to avoid adding new tokens. (I 
> volunteer to write vscode themes if that helps change your mind.)

Vscode is one that we have control over (similar to Qt creator if that helps 
reasoning) but I am afraid customizing vscode too much and assessing impact of 
features with a bias of those customization might hinder usability in the long 
run (also again custom themes etc. doesn't really scale).

> I'm not sure whether you mean LSP-based editors, but if we're counting 
> editors that had "label" as a semantic token type pre-LSP, and are now 
> looking to maintain that through their switch to LSP, then both Eclipse CDT 
> and (I assume) Qt Creator fall into that category.

Considering that we have added a bunch of token kinds, let me ask you another 
question then, how many more new token kinds do we expect to have? e.g. if 
label is the last one sure, but if we plan to have 10 more or if we don't know 
how many more we would like to have, i think it's better to first come up with 
a plan and an agreement to make sure we can avoid such discussions with every 
attempt. does that sound fair?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:302
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift >= 64 && "Shift is out of encodable range");
   return (V << Shift) & Mask;

erichkeane wrote:
> Shouldn't this be: `assert(Shift < 64 &&"...")`?
> 
> `expr.shift` (https://eel.is/c++draft/expr.shift) says:
> ```
> The operands shall be of integral or unscoped enumeration type and integral 
> promotions are performed.
> The type of the result is that of the promoted left operand.
> The behavior is undefined if the right operand is negative, or greater than 
> or equal to the width of the promoted left operand.```
> 
> uint64 stays as an `unsigned long`, so it is still 64 bits, so the only 
> invalid value for `Shift` is 64 (though >64 is 'nonsense', but only 
> impossible because of `llvm::countr_zero`).
> 
> One thing to consider: I wonder if we should instead be changing the 'shift' 
> to be:
> 
> `(V << (Shift % 64)) && Mask` ?  It looks like `arm_sve.td` has the `NoFlags` 
> value as zero, which I think will end up going through here possibly (or at 
> least, inserted into `FlagTypes`.
> 
> So I suspect an assert might not be sufficient, since a 64 bit shift is 
> possible in that case (since a zero 'Mask' is the only case where 
> `countr_zero` will end up being 64).
> 
> 
> So I suspect an assert might not be sufficient, since a 64 bit shift is 
> possible in that case (since a zero 'Mask' is the only case where countr_zero 
> will end up being 64).
It should be fine to assert that `Mask != 0`, since that would be an invalid 
mask.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150140

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


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-05-09 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Some comments, but otherwise LGTM




Comment at: clang/include/clang/Interpreter/Interpreter.h:43
 public:
+  IncrementalCompilerBuilder(){};
+

and this should probably be run through `clang-format`...



Comment at: clang/include/clang/Interpreter/Interpreter.h:45
+
+  void SetCompilerArgs(const std::vector Args) {
+UserArgs = Args;





Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6257
+  // Device code should not be at top level.
+  if (LangOpts.CUDA && LangOpts.CUDAIsDevice)
+return;

tra wrote:
> Could you give me an example of what exactly we'll be skipping here?
> Will it affect `__device__` variables? 
> 
This concerns statements at the global scope that only concern the REPL; see 
https://reviews.llvm.org/D127284 for the original revision. Global variables on 
the other hand are passed via `EmitTopLevelDecl` -> `EmitGlobal`.



Comment at: clang/lib/Interpreter/Interpreter.cpp:143
   // FIXME: Print proper driver diagnostics if the driver flags are wrong.
   // We do C++ by default; append right after argv[0] if no "-x" given
   ClangArgv.insert(ClangArgv.end(), "-Xclang");

This comment should move as well



Comment at: clang/lib/Interpreter/Interpreter.cpp:144-146
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
   ClangArgv.insert(ClangArgv.end(), "-c");

This doesn't do what the comments claim - it appends at the end, not prepends. 
For that it would need to be `ClangArgv.insert(ClangArgv.begin(), "-c")`. 
@v.g.vassilev what do we want here? (probably doesn't block this revision, but 
it's odd nevertheless)



Comment at: clang/lib/Interpreter/Offload.h:36-37
+
+  // Write last PTX to the fatbinary file
+  // llvm::Error WriteFatbinary() const;
+

unused


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[clang] 74fd474 - [clang] Evaluate non-type default template argument when it is required

2023-05-09 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-05-09T04:21:46-04:00
New Revision: 74fd474eea53e85fc8f64422f565fd2bd50fd7e4

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

LOG: [clang] Evaluate non-type default template argument when it is required

Before this change a default template argument for a non-type template
parameter was evaluated and checked immediately after it is met by
parser. In some cases it is too early.

Fixes https://github.com/llvm/llvm-project/issues/62224
Fixes https://github.com/llvm/llvm-project/issues/62596

Reviewed By: shafik, erichkeane, cor3ntin

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

Added: 
clang/test/SemaCXX/GH62596.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/AST/ast-dump-decl.cpp
clang/test/CXX/expr/expr.const/p3-0x.cpp
clang/test/Index/Core/index-source.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
clang/test/SemaTemplate/deduction-guide.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fcc6fb7df0c87..d3d731cf9d438 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,6 +376,10 @@ Bug Fixes in This Version
 - Fix crash when attempting to pass a non-pointer type as first argument of
   ``__builtin_assume_aligned``.
   (`#62305 `_)
+- A default argument for a non-type template parameter is evaluated and checked
+  at the point where it is required. This fixes:
+  (`#62224 `_) and
+  (`#62596 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4fe4b9192ecd3..c6ba58724e774 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1610,16 +1610,6 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
 if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
   return Param;
 
-TemplateArgument SugaredConverted, CanonicalConverted;
-ExprResult DefaultRes = CheckTemplateArgument(
-Param, Param->getType(), Default, SugaredConverted, CanonicalConverted,
-CTAK_Specified);
-if (DefaultRes.isInvalid()) {
-  Param->setInvalidDecl();
-  return Param;
-}
-Default = DefaultRes.get();
-
 Param->setDefaultArgument(Default);
   }
 

diff  --git a/clang/test/AST/ast-dump-decl.cpp 
b/clang/test/AST/ast-dump-decl.cpp
index 63148d54962f4..3be99c9489640 100644
--- a/clang/test/AST/ast-dump-decl.cpp
+++ b/clang/test/AST/ast-dump-decl.cpp
@@ -455,9 +455,7 @@ namespace testClassTemplateDecl {
 // CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-148]]:3, col:31> 
col:31 TestTemplateDefaultNonType
 // CHECK-NEXT:  |-NonTypeTemplateParmDecl 0x{{.+}}  col:16 
'int' depth 0 index 0 I
 // CHECK-NEXT:  | `-TemplateArgument expr
-// CHECK-NEXT:  |   `-ConstantExpr 0x{{.+}}  'int'
-// CHECK-NEXT:  | |-value: Int 42
-// CHECK-NEXT:  | `-IntegerLiteral 0x{{.+}}  'int' 42
+// CHECK-NEXT:  |   `-IntegerLiteral 0x{{.+}}  'int' 42
 // CHECK-NEXT:  `-CXXRecordDecl 0x{{.+}}  col:31 struct 
TestTemplateDefaultNonType
 
 // CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:{{.*}}:3, col:68> col:68 
TestTemplateTemplateDefaultType
@@ -661,9 +659,7 @@ namespace TestNonTypeTemplateParmDecl {
 // CHECK-NEXT:   FunctionTemplateDecl
 // CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} 'int' depth 0 index 0 I
 // CHECK-NEXT:   TemplateArgument expr
-// CHECK-NEXT: ConstantExpr{{.*}} 'int'
-// CHECK-NEXT:   value: Int 1
-// CHECK-NEXT:   IntegerLiteral{{.*}} 'int' 1
+// CHECK-NEXT: IntegerLiteral{{.*}} 'int' 1
 // CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} 'int' depth 0 index 1 ... J
 
 namespace TestTemplateTemplateParmDecl {

diff  --git a/clang/test/CXX/expr/expr.const/p3-0x.cpp 
b/clang/test/CXX/expr/expr.const/p3-0x.cpp
index 47968eed75b66..5bd70c5250b59 100644
--- a/clang/test/CXX/expr/expr.const/p3-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p3-0x.cpp
@@ -10,6 +10,7 @@ void NonConstF() {
 case nonconst: // expected-error {{case value is not a constant 
expression}} expected-note {{read of non-const}}
   break;
   }
+  NonConstT<> V; // expected-note {{while checking a default template argument 
used here}}
   return;
 }
 

diff  --git a/clang/test/Index/Core/index-source.cpp 
b/clang/test/Index/Core/index-source.cpp
index 781343e008fa6..8f9fbc4c8d29c 100644
--- a/clang/test/Index/Core/index-source.cpp
+++ b/c

[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

2023-05-09 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74fd474eea53: [clang] Evaluate non-type default template 
argument when it is required (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D150108?vs=520325&id=520622#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150108

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/Index/Core/index-source.cpp
  clang/test/SemaCXX/GH62596.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1156,8 +1156,6 @@
   NonTypeTemplateParmDecl *To = Import(From, Lang_CXX03);
   ASSERT_TRUE(To->hasDefaultArgument());
   Stmt *ToArg = To->getDefaultArgument();
-  ASSERT_TRUE(isa(ToArg));
-  ToArg = *ToArg->child_begin();
   ASSERT_TRUE(isa(ToArg));
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -204,8 +204,8 @@
 }
 
 namespace PR6964 {
-  template  // expected-warning 2{{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
-  // expected-note 2{{template parameter is declared here}}
+  template  // expected-warning {{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
+  // expected-note {{template parameter is declared here}}
   struct as_nview { };
 
   template  
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -224,9 +224,7 @@
 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
 // CHECK:   `-TemplateArgument expr
 // CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
-// CHECK: |   `-ConstantExpr {{.*}} 'char'
-// CHECK: | |-value: Int 120
-// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |   `-CharacterLiteral {{.*}} 'char' 120
 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
 // CHECK: |-ParenExpr {{.*}} 'bool'
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -79,3 +79,16 @@
 };
 void f(A a = A()) { }
 }
+
+namespace GH62224 {
+  consteval int fwd();
+  template 
+  struct C {
+consteval C(int = fwd()) { }
+consteval int get() { return i; }
+  };
+
+  consteval int fwd() { return 42; }
+  C<> Val; // No error since fwd is defined already.
+  static_assert(Val.get() == 42);
+}
Index: clang/test/SemaCXX/GH62596.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH62596.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+struct foo {
+  static constexpr bool bar() {
+  return true;
+  }
+
+  template
+  static constexpr bool baz() {
+  return B;
+  }
+};
+static_assert(foo::baz(), "");
+
+// expected-no-diagnostics
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -405,7 +405,7 @@
 // CHECK: [[@LINE-1]]:23 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
 // CHECK-NEXT: RelCont | TemplateDefaultValues | c:@ST>3#T#NI#t>1#T@TemplateDefaultValues
  int x = Record::C,
-// CHECK: [[@LINE-1]]:26 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,Read,RelCont | rel: 1
+// CHECK: [[@LINE-1]]:26 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,RelCont | rel: 1
 // CHECK-NEXT: RelCont | TemplateDefaultValues | c:@ST>3#T#NI#t>1#T@TemplateDefaultValues
 // CHECK: [[@LINE-3]]:18 | struct/C++ | Record | c:@S@Record |  | Ref,RelCont | rel: 1
  template  class Collection = ns2::ACollectionDecl>
Index: clang/test/CXX/expr/expr.const/p3-0x.cpp
===
--- clang/test/CXX/exp

[PATCH] D143260: [clangd] Add semantic token for labels

2023-05-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D143260#4328948 , @kadircet wrote:

> Considering that we have added a bunch of token kinds, let me ask you another 
> question then, how many more new token kinds do we expect to have? e.g. if 
> label is the last one sure, but if we plan to have 10 more or if we don't 
> know how many more we would like to have, i think it's better to first come 
> up with a plan and an agreement to make sure we can avoid such discussions 
> with every attempt. does that sound fair?

That's a totally fair question.

For my part, I don't have any additional token kinds in mind to add. (The 
suggestion in https://github.com/clangd/clangd/issues/787 to split "template 
parameter" into type vs. non-type is an interesting one, but it's more like a 
nice-to-have enhancement.)

Not sure about Qt Creator, will let @ckandeler chime in on whether he had any 
other token kinds in mind for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


[PATCH] D143260: [clangd] Add semantic token for labels

2023-05-09 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In D143260#4328948 , @kadircet wrote:

> Considering that we have added a bunch of token kinds, let me ask you another 
> question then, how many more new token kinds do we expect to have? e.g. if 
> label is the last one sure, but if we plan to have 10 more or if we don't 
> know how many more we would like to have, i think it's better to first come 
> up with a plan and an agreement to make sure we can avoid such discussions 
> with every attempt. does that sound fair?

Speaking for myself, I don't currently have any plans to add further tokens, 
but it's difficult to say with certainty that this will be the last one. For 
instance, new C++ features in future standards might suggest new token types 
(like "concept" for C++20). And if https://github.com/clangd/clangd/issues/1115 
gets implemented, then there will be "string", "number" and "keyword", though 
these are all part of the LSP spec already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


[PATCH] D150183: [Clang][clang-cl] Implement `__builtin_FUNCSIG`

2023-05-09 Thread Jakub Mazurkiewicz via Phabricator via cfe-commits
JMazurkiewicz created this revision.
JMazurkiewicz added a reviewer: clang.
Herald added a project: All.
JMazurkiewicz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch implements `__builtin_FUNCSIG` intrinsic which returns the same 
string as `__FUNCSIG__`.

Closes #58951.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150183

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/source_location.cpp

Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
-// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -86,6 +86,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 
 // test noexcept
@@ -94,6 +95,7 @@
 static_assert(noexcept(__builtin_FILE()));
 static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
+static_assert(noexcept(__builtin_FUNCSIG()));
 static_assert(noexcept(__builtin_source_location()));
 
 //===--===//
@@ -450,6 +452,55 @@
 
 } // namespace test_func
 
+//===--===//
+//__builtin_FUNCSIG()
+//===--===//
+
+namespace test_funcsig {
+
+constexpr const char *test_funcsig_simple(const char *f = __builtin_FUNCSIG()) {
+  return f;
+}
+constexpr const char *get_funcsig() {
+  return __FUNCSIG__;
+}
+constexpr bool test_funcsig() {
+  return is_equal(__FUNCSIG__, test_funcsig_simple()) &&
+ !is_equal(get_funcsig(), test_funcsig_simple());
+}
+static_assert(test_funcsig());
+
+template 
+constexpr Pair test_funcsig_template(T, const char* f = __builtin_FUNCSIG()) {
+  return {f, __builtin_FUNCSIG()};
+}
+template 
+void func_template_tests() {
+  constexpr auto P = test_funcsig_template(42);
+  static_assert(is_equal(P.first, __FUNCSIG__), "");
+  static_assert(!is_equal(P.second, __FUNCSIG__), "");
+}
+template void func_template_tests();
+
+template 
+struct TestCtor {
+  T funcsig = __builtin_FUNCSIG();
+  T ctor_funcsig;
+  TestCtor() = default;
+  template 
+  constexpr TestCtor(int, F f = __builtin_FUNCSIG()) : ctor_funcsig(f) {}
+};
+void ctor_tests() {
+  constexpr TestCtor<> Template{42};
+  static_assert(is_equal(Template.funcsig, "__cdecl test_funcsig::TestCtor<>::TestCtor(int, F) [T = const char *, F = const char *]"));
+  static_assert(is_equal(Template.ctor_funcsig, __FUNCSIG__));
+}
+
+constexpr const char* global_funcsig = __builtin_FUNCSIG();
+static_assert(is_equal(global_funcsig, ""));
+
+} // namespace test_funcsig
+
 //===--===//
 //__builtin_COLUMN()
 //===--===//
Index: clang/test/Sema/source_location.c
===
--- clang/test/Sema/source_location.c
+++ clang/test/Sema/source_location.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c90 -fconst-strings -DCONST_STRINGS -verify %s
-// RUN: %clang_cc1 -std=c90 -verify %s
+// RUN: %clang_cc1 -std=c90 -fms-extensions -fconst-strings -DCONST_STRINGS -verify %s
+// RUN: %clang_cc1 -std=c90 -fms-extensions -verify %s
 
 // expected-no-diagnostics
 
@@ -13,6 +13,7 @@
 #ifndef CONST_STRINGS
 char *const NCFILE = __builtin_FILE();
 char *const NCFUNC = __builtin_FUNCTION();
+char *const NCFNSG = __builtin_FUNCSIG();
 #endif
 
 #ifdef CONST_STRINGS
@@ -20,6 +21,7 @@
 _Static_assert(IsEqual(__builtin_FILE_NAME(), __FILE_NAME__), "");
 _Static_assert(__builtin_LINE() == __LINE__, "");
 _Static_assert(IsEqual("", __builtin_FUNCTION()), "");
+_Static_assert(IsEqual("", __builtin_FUNCSIG()), "");
 
 #line 42 "my_file.c"
 _Static_assert(__builtin_LINE() == 42, "");
@@ -30,5 +32,6 @@
 
 void foo(void) {
   _Static_assert(IsEqual(__builtin_FUNCTION(), "foo"), "");
+  _Static_assert(IsEqual(__builtin_FUNCSIG(), "void __cdecl foo(void)"), "");
 

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 520628.
ilya-biryukov added a comment.

- Moved the relase note to 'C++20 feature support', fixed typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/PCH/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/cxx1z-using-declaration.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -473,7 +473,8 @@
   template  void bar() {
 auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
// expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
-   // expected-note  {{passing argument to parameter 'a' here}}
+   // expected-note  {{passing argument to parameter 'a' here}} \
+   // expected-note {{while substituting into a lambda}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -496,6 +497,7 @@
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
   // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
   // expected-note@-3  {{passing argument to parameter 'x' here}}
+  // expected-note@-4  {{while substituting into a lambda}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -160,7 +160,7 @@
 consume([]() noexcept(sizeof(T) == 4) {} ...);
   }
   template void j() {
-consume([](void (*p)() noexcept(B)) {
+consume([](void (*p)() noexcept(B)) { // expected-note {{substituting into a lambda}}
   void (*q)() noexcept = p; // expected-error {{not superset of source}}
 } ...);
   }
Index: clang/test/SemaTemplate/cxx1z-using-declaration.cpp
===
--- clang/test/SemaTemplate/cxx1z-using-declaration.cpp
+++ clang/test/SemaTemplate/cxx1z-using-declaration.cpp
@@ -157,7 +157,7 @@
 
 // Test partial substitution into class-scope pack.
 template auto lambda1() {
-  return [](auto x) {
+  return [](auto x) { // expected-note 1+{{substituting into a lambda}}
 struct A : T::template X... { // expected-note 1+{{instantiation of}}
   using T::template X::f ...;
   using typename T::template X::type ...;
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -119,7 +119,7 @@
 []() -> C auto{ return T(); }(); // expected-error {{expression contains unexpanded parameter pack '

[PATCH] D150178: [clang][CodeGen] Break up TargetInfo.cpp [6/7]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a project: All.
barannikov88 published this revision for review.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane, jdoerfert, 
efriedma.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Make `qualifyWindowsLibrary` and `addStackProbeTargetAttributes`
protected members of `TargetCodeGenInfo`.
These are helper functions used by `getDependentLibraryOption` and
`setTargetAttributes` methods when targeting Windows. The change will
allow these functions to be reused after splitting `TargetInfo.cpp`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150178

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h


Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -397,6 +397,12 @@
   virtual llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const {
 return nullptr;
   }
+
+protected:
+  static std::string qualifyWindowsLibrary(StringRef Lib);
+
+  void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule &CGM) const;
 };
 
 } // namespace CodeGen
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2559,6 +2559,7 @@
 const FunctionDecl *Callee,
 const CallArgList &Args) const override;
 };
+} // namespace
 
 static void initFeatureMaps(const ASTContext &Ctx,
 llvm::StringMap &CallerMap,
@@ -2657,7 +2658,7 @@
   }
 }
 
-static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
+std::string TargetCodeGenInfo::qualifyWindowsLibrary(StringRef Lib) {
   // If the argument does not end in .lib, automatically add the suffix.
   // If the argument contains a space, enclose it in quotes.
   // This matches the behavior of MSVC.
@@ -2670,6 +2671,7 @@
   return ArgStr;
 }
 
+namespace {
 class WinX86_32TargetCodeGenInfo : public X86_32TargetCodeGenInfo {
 public:
   WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
@@ -2693,11 +2695,11 @@
 Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
   }
 };
+} // namespace
 
-static void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
-  CodeGen::CodeGenModule &CGM) {
+void TargetCodeGenInfo::addStackProbeTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const {
   if (llvm::Function *Fn = dyn_cast_or_null(GV)) {
-
 if (CGM.getCodeGenOpts().StackProbeSize != 4096)
   Fn->addFnAttr("stack-probe-size",
 llvm::utostr(CGM.getCodeGenOpts().StackProbeSize));
@@ -2714,6 +2716,7 @@
   addStackProbeTargetAttributes(D, GV, CGM);
 }
 
+namespace {
 class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   WinX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
@@ -2752,6 +2755,7 @@
 Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
   }
 };
+} // namespace
 
 void WinX86_64TargetCodeGenInfo::setTargetAttributes(
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const {
@@ -2769,7 +2773,6 @@
 
   addStackProbeTargetAttributes(D, GV, CGM);
 }
-}
 
 void X86_64ABIInfo::postMerge(unsigned AggregateSize, Class &Lo,
   Class &Hi) const {


Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -397,6 +397,12 @@
   virtual llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const {
 return nullptr;
   }
+
+protected:
+  static std::string qualifyWindowsLibrary(StringRef Lib);
+
+  void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule &CGM) const;
 };
 
 } // namespace CodeGen
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2559,6 +2559,7 @@
 const FunctionDecl *Callee,
 const CallArgList &Args) const override;
 };
+} // namespace
 
 static void initFeatureMaps(const ASTContext &Ctx,
 llvm::StringMap &CallerMap,
@@ -2657,7 +2658,7 @@
   }
 }
 
-static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
+std::string TargetCodeGenInfo::qualifyWindowsLibrary(StringRef Lib) {
   // If the argument does not end in .lib, automatically add the suffix.
   // If the argument contains a space, enclose it in quotes.
   // This matches the behavior of MSVC.
@@ -2670,6 +2671,7 @@
   re

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 520630.
ilya-biryukov added a comment.

- Fix a typo (forgot to commit last time)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/PCH/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/cxx1z-using-declaration.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -473,7 +473,8 @@
   template  void bar() {
 auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
// expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
-   // expected-note  {{passing argument to parameter 'a' here}}
+   // expected-note  {{passing argument to parameter 'a' here}} \
+   // expected-note {{while substituting into a lambda}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -496,6 +497,7 @@
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
   // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
   // expected-note@-3  {{passing argument to parameter 'x' here}}
+  // expected-note@-4  {{while substituting into a lambda}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -160,7 +160,7 @@
 consume([]() noexcept(sizeof(T) == 4) {} ...);
   }
   template void j() {
-consume([](void (*p)() noexcept(B)) {
+consume([](void (*p)() noexcept(B)) { // expected-note {{substituting into a lambda}}
   void (*q)() noexcept = p; // expected-error {{not superset of source}}
 } ...);
   }
Index: clang/test/SemaTemplate/cxx1z-using-declaration.cpp
===
--- clang/test/SemaTemplate/cxx1z-using-declaration.cpp
+++ clang/test/SemaTemplate/cxx1z-using-declaration.cpp
@@ -157,7 +157,7 @@
 
 // Test partial substitution into class-scope pack.
 template auto lambda1() {
-  return [](auto x) {
+  return [](auto x) { // expected-note 1+{{substituting into a lambda}}
 struct A : T::template X... { // expected-note 1+{{instantiation of}}
   using T::template X::f ...;
   using typename T::template X::type ...;
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -119,7 +119,7 @@
 []() -> C auto{ return T(); }(); // expected-error {{expression contains unexpanded parameter pack 'T'}}
   }
   template 

[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

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



Comment at: clang/lib/Interpreter/Interpreter.cpp:144-146
   ClangArgv.insert(ClangArgv.end(), "-Xclang");
   ClangArgv.insert(ClangArgv.end(), "-fincremental-extensions");
   ClangArgv.insert(ClangArgv.end(), "-c");

Hahnfeld wrote:
> This doesn't do what the comments claim - it appends at the end, not 
> prepends. For that it would need to be `ClangArgv.insert(ClangArgv.begin(), 
> "-c")`. @v.g.vassilev what do we want here? (probably doesn't block this 
> revision, but it's odd nevertheless)
Yeah, this forces the clang::Driver to have some sort of action. In turn, this 
helps produce diagnostics from the driver before failing. That's a known bug 
since the early days of clang that nobody addressed... 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: VitaNuo.
Herald added subscribers: PiotrZSL, carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150187

Files:
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t
+
+struct Foo {
+  operator bool();
+};
+
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -453,9 +453,12 @@
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  // Don't keep track for non-identifier names.
+  if (auto *II = Decl->getIdentifier()) {
+return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
+ II->getName()),
+Range, SourceMgr);
+  }
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t
+
+struct Foo {
+  operator bool();
+};
+
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -453,9 +453,12 @@
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  // Don't keep track for non-identifier names.
+  if (auto *II = Decl->getIdentifier()) {
+return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
+ II->getName()),
+Range, SourceMgr);
+  }
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-05-09 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite updated this revision to Diff 520636.
argentite marked 3 inline comments as done.
argentite added a comment.

Added a check to run CUDA tests only on systems with CUDA. We need some ideas 
for the actual tests.
Rename Offload.cpp to DeviceOffload.cpp
Other syntax/style fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

Files:
  clang/include/clang/CodeGen/ModuleBuilder.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/DeviceOffload.cpp
  clang/lib/Interpreter/DeviceOffload.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/CUDA/lit.local.cfg
  clang/test/Interpreter/CUDA/sanity.cu
  clang/test/lit.cfg.py
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -40,7 +40,9 @@
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
-  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgs);
+  auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
   return cantFail(clang::Interpreter::create(std::move(CI)));
Index: clang/unittests/Interpreter/IncrementalProcessingTest.cpp
===
--- clang/unittests/Interpreter/IncrementalProcessingTest.cpp
+++ clang/unittests/Interpreter/IncrementalProcessingTest.cpp
@@ -52,7 +52,9 @@
 
 TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
   std::vector ClangArgv = {"-Xclang", "-emit-llvm-only"};
-  auto CI = llvm::cantFail(IncrementalCompilerBuilder::create(ClangArgv));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgv);
+  auto CI = cantFail(CB.CreateCpp());
   auto Interp = llvm::cantFail(Interpreter::create(std::move(CI)));
 
   std::array PTUs;
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -21,6 +21,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
+#include "llvm-c/Error.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -38,7 +39,9 @@
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
-  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgs);
+  auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
   return cantFail(clang::Interpreter::create(std::move(CI)));
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -23,6 +23,10 @@
 #include "llvm/Support/TargetSelect.h" // llvm::Initialize*
 #include 
 
+static llvm::cl::opt CudaEnabled("cuda", llvm::cl::Hidden);
+static llvm::cl::opt CudaPath("cuda-path", llvm::cl::Hidden);
+static llvm::cl::opt OffloadArch("offload-arch", llvm::cl::Hidden);
+
 static llvm::cl::list
 ClangArgs("Xcc",
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
@@ -90,9 +94,36 @@
 return 0;
   }
 
+  clang::IncrementalCompilerBuilder CB;
+  CB.SetCompilerArgs(ClangArgv);
+
+  std::unique_ptr DeviceCI;
+  if (CudaEnabled) {
+// initialize NVPTX backend
+LLVMInitializeNVPTXTargetInfo();
+LLVMInitializeNVPTXTarget();
+LLVMInitializeNVPTXTargetMC();
+LLVMInitializeNVPTXAsmPrinter();
+
+if (!CudaPath.empty())
+  CB.SetCudaSDK(CudaPath);
+
+if (OffloadArch.empty()) {
+  OffloadArch = "sm_35";
+}
+CB.SetOffloadArch(OffloadArch);
+
+DeviceCI = ExitOnErr(CB.CreateCudaDev

[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-05-09 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 520638.
zyounan added a comment.

Final update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 
 #include "gtest/gtest.h"
 #include 
@@ -529,6 +530,8 @@
[](HoverInfo &HI) {
  HI.Name = "MACRO";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Value = "41 (0x29)";
+ HI.Type = "int";
  HI.Definition = "#define MACRO 41\n\n"
  "// Expands to\n"
  "41";
@@ -560,6 +563,7 @@
[](HoverInfo &HI) {
  HI.Name = "DECL_STR";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Type = HoverInfo::PrintedType("const char *");
  HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
  "STRINGIFY(VALUE)\n\n"
  "// Expands to\n"
@@ -1850,6 +1854,8 @@
   )cpp",
   [](HoverInfo &HI) {
 HI.Name = "MACRO";
+HI.Value = "0";
+HI.Type = "int";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0\n\n"
 "// Expands to\n"
@@ -3769,6 +3775,232 @@
   EXPECT_EQ(H->Type->Type, "int");
   EXPECT_EQ(H->Definition, "using foo = type");
 }
+
+TEST(Hover, EvaluateMacros) {
+  llvm::StringRef PredefinedCXX = R"cpp(
+#define X 42
+#define SizeOf sizeof
+#define AlignOf alignof
+#define PLUS_TWO +2
+#define TWO 2
+
+using u64 = unsigned long long;
+// calculate (a ** b) % p
+constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
+  u64 ret = 1;
+  while (b) {
+if (b & 1)
+  ret = (ret * a) % p;
+a = (a * a) % p;
+b >>= 1;
+  }
+  return ret;
+}
+#define last_n_digit(x, y, n)  \
+  pow_with_mod(x, y, pow_with_mod(10, n, 2147483647))
+#define declare_struct(X, name, value) \
+  struct X {   \
+constexpr auto name() { return value; }\
+  }
+#define gnu_statement_expression(value)\
+  ({   \
+declare_struct(Widget, getter, value); \
+Widget().getter(); \
+  })
+#define define_lambda_begin(lambda, ...)   \
+  [&](__VA_ARGS__) {
+#define define_lambda_end() }
+
+#define left_bracket [
+#define right_bracket ]
+#define dg_left_bracket <:
+#define dg_right_bracket :>
+#define array_decl(type, name, size) type name left_bracket size right_bracket
+  )cpp";
+
+  struct {
+llvm::StringRef Code;
+const std::function, size_t /*Id*/)>
+Validator;
+  } Cases[] = {
+  {
+  /*Code=*/R"cpp(
+X^;
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "42 (0x2a)");
+EXPECT_EQ(HI->Type, HoverInfo::PrintedType("int"));
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+Size^Of(int);
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+// Don't validate type or value of `sizeof` and `alignof` as we're
+// getting different values or desugared types on different
+// platforms. Same as below.
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  struct Y {
+int y;
+double z;
+  };
+  Alig^nOf(Y);
+)cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  // 2**32 == 4294967296
+  last_n_di^git(2, 32, 6);
+)cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "967296 (0xec280)");
+EXPECT_EQ(HI->Type, "u64");
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  gnu_statement_exp^ression(42);
+)cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "42 (0x2a)");
+   

[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM, fell free to deliver (to quickly fix crash).
Any improvements could be done later.




Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp:457
+  // Don't keep track for non-identifier names.
+  if (auto *II = Decl->getIdentifier()) {
+return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),

Most probably this could be done before for, as overridden/cannonical decl 
should have same naming.
And looks we get here from VisitMemberExpr.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp:3-5
+struct Foo {
+  operator bool();
+};

i would merge this with some existing test file...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150187

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


[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-nocrash.cpp:3-5
+struct Foo {
+  operator bool();
+};

PiotrZSL wrote:
> i would merge this with some existing test file...
yep, tests fails due to lack of CHECK_MESSGAES, merge this with some other test 
file, main one for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150187

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


[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks! This looks like a useful addition.

Could you add a test into `libIndex` for this too? Just for the sake of having 
better coverage, some folks probably don't run `clang-tools-extra` tests.
Also, could we add a test that a label does not get indexed if local function 
indexing is off?




Comment at: clang/lib/Index/IndexBody.cpp:148
+  bool VisitGotoStmt(GotoStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,

`IndexingContext::handleReference` already has this check, we should call 
`handleReference` unconditionally.





Comment at: clang/lib/Index/IndexBody.cpp:158
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent,
+  ParentDC, {});

We should call `handleDecl`, indexing output can differentiate between a 
declarations and a references.
`LabelStmt` is exactly the node that declares a `LabelDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a reviewer: kadircet.
ilya-biryukov added a comment.

In `clangd` we also have `findExplicitReferences` and `targetDecl` functions 
that seem to handle the `GoToStmt`.
In fact, I believe they are used in `findDocumentHighlights`, so I'm not sure 
why your test did not work before this patch.

I have also not looked into `libIndex` for quite a long time, so looping in 
@kadircet for a second pair of eyes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D150116: clang-format: [JS] support import/export type

2023-05-09 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Looks good! Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150116

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


[clang] 629170f - [Sema] Lambdas are not part of immediate context for deduction

2023-05-09 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2023-05-09T12:06:33+02:00
New Revision: 629170fe452f4849c89fc289d6e2cf5f08534342

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

LOG: [Sema] Lambdas are not part of immediate context for deduction

This commit implements [temp.deduct]p9.
Test updates include:
- New notes in `cxx1y-init-captures.cpp`, `lambda-expressions.cpp`
  and 'warn-unused-lambda-capture.cpp'.
  This seems to be caused by diagnosing errors earlier (during
  deduction) that were previously surfaced later (during
  instantiation).
- New error `lambda-unevaluated.cpp` is in line with [temp.deduct]p9.

Reviewed By: erichkeane, #clang-language-wg

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

Added: 
clang/test/CXX/temp/temp.deduct/p9.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
clang/test/PCH/cxx1y-init-captures.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
clang/test/SemaCXX/cxx1y-init-captures.cpp
clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/lambda-expressions.cpp
clang/test/SemaCXX/lambda-pack-expansion.cpp
clang/test/SemaCXX/lambda-unevaluated.cpp
clang/test/SemaCXX/vartemplate-lambda.cpp
clang/test/SemaCXX/warn-unused-lambda-capture.cpp
clang/test/SemaTemplate/concepts.cpp
clang/test/SemaTemplate/cxx1z-using-declaration.cpp
clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
clang/test/SemaTemplate/instantiate-local-class.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d3d731cf9d438..4ec4e4a49de6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -91,6 +91,9 @@ C++20 Feature Support
   building of standard modules. This diagnostic may be strengthened into an
   error again in the future once there is a less fragile way to mark a module
   as being part of the implementation rather than a user module.
+- Clang now implements `[temp.deduct]p9`. Substitution failures inside lambdas 
from
+  unevaluated contexts will be surfaced as errors. They were previously 
handled as
+  SFINAE.
 
 C++23 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index bade9ad5d5be3..e6b2e28a82ded 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5327,6 +5327,8 @@ def note_constraint_normalization_here : Note<
 def note_parameter_mapping_substitution_here : Note<
   "while substituting into concept arguments here; substitution failures not "
   "allowed in concept arguments">;
+def note_lambda_substitution_here : Note<
+  "while substituting into a lambda expression here">;
 def note_instantiation_contexts_suppressed : Note<
   "(skipping %0 context%s0 in backtrace; use -ftemplate-backtrace-limit=0 to "
   "see all)">;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f65f8e3f2b50b..5296d7000b5cc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9261,6 +9261,9 @@ class Sema final {
   /// a TemplateDecl.
   DeducedTemplateArgumentSubstitution,
 
+  /// We are substituting into a lambda expression.
+  LambdaExpressionSubstitution,
+
   /// We are substituting prior template arguments into a new
   /// template parameter. The template parameter itself is either a
   /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index c947772ec3e70..f62a29c02ee13 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -372,6 +372,8 @@ class DefaultTemplateInstCallback : public 
TemplateInstantiationCallback {
   return "ExplicitTemplateArgumentSubstitution";
 case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
   return "DeducedTemplateArgumentSubstitution";
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  return "LambdaExpression

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-05-09 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG629170fe452f: [Sema] Lambdas are not part of immediate 
context for deduction (authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/PCH/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/cxx1z-using-declaration.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -473,7 +473,8 @@
   template  void bar() {
 auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
// expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
-   // expected-note  {{passing argument to parameter 'a' here}}
+   // expected-note  {{passing argument to parameter 'a' here}} \
+   // expected-note {{while substituting into a lambda}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -496,6 +497,7 @@
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
   // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
   // expected-note@-3  {{passing argument to parameter 'x' here}}
+  // expected-note@-4  {{while substituting into a lambda}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -160,7 +160,7 @@
 consume([]() noexcept(sizeof(T) == 4) {} ...);
   }
   template void j() {
-consume([](void (*p)() noexcept(B)) {
+consume([](void (*p)() noexcept(B)) { // expected-note {{substituting into a lambda}}
   void (*q)() noexcept = p; // expected-error {{not superset of source}}
 } ...);
   }
Index: clang/test/SemaTemplate/cxx1z-using-declaration.cpp
===
--- clang/test/SemaTemplate/cxx1z-using-declaration.cpp
+++ clang/test/SemaTemplate/cxx1z-using-declaration.cpp
@@ -157,7 +157,7 @@
 
 // Test partial substitution into class-scope pack.
 template auto lambda1() {
-  return [](auto x) {
+  return [](auto x) { // expected-note 1+{{substituting into a lambda}}
 struct A : T::template X... { // expected-note 1+{{instantiation of}}
   using T::template X::f ...;
   using typename T::template X::type ...;
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -119,7 +119,7 @@
 []() -> C auto{ return T(); }(); // expected-erro

[clang] 60a3784 - [C++20] [Modules] Handle modules visible relationship properly

2023-05-09 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-09T18:36:37+08:00
New Revision: 60a3784b3e1f0e65e2a0e6daf070bbc7cd4bbab5

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

LOG: [C++20] [Modules] Handle modules visible relationship properly

Close https://github.com/llvm/llvm-project/issues/62589.

Previously, for global module fragments, we will justify if it is
visible by the visibility of their top level parents. But this is an
overkill, it is problematic if we have a deduction guide in the global
module fragments. See the attached test for example. In this example, we
will mark the global module fragments as visible, but our old strategy
will miss the case surprisingly due to we will only search for the top
level modules.

Added: 
clang/test/Modules/named-modules-adl-3.cppm
clang/test/Modules/pr62589.cppm

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e82c17cfe630f..202e5f49ac4a1 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1877,14 +1877,14 @@ bool Sema::isModuleVisible(const Module *M, bool 
ModulePrivate) {
   if (LookupModules.empty())
 return false;
 
+  // If our lookup set contains the module, it's visible.
+  if (LookupModules.count(M))
+return true;
+
   // The global module fragments are visible to its corresponding module unit.
   // So the global module fragment should be visible if the its corresponding
   // module unit is visible.
-  if (M->isGlobalModule())
-M = M->getTopLevelModule();
-
-  // If our lookup set contains the module, it's visible.
-  if (LookupModules.count(M))
+  if (M->isGlobalModule() && LookupModules.count(M->getTopLevelModule()))
 return true;
 
   // For a module-private query, that's everywhere we get to look.

diff  --git a/clang/test/Modules/named-modules-adl-3.cppm 
b/clang/test/Modules/named-modules-adl-3.cppm
new file mode 100644
index 0..2fc2962c926b1
--- /dev/null
+++ b/clang/test/Modules/named-modules-adl-3.cppm
@@ -0,0 +1,64 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.pcm  
-emit-module-interface \
+// RUN: -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/c.cppm -fmodule-file=a=%t/a.pcm 
-fmodule-file=b=%t/b.pcm \
+// RUN: -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/a.cppm 
-emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/b.cppm 
-fmodule-file=a=%t/a.pcm  \
+// RUN: -emit-module-interface -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/c.cppm 
-fmodule-file=a=%t/a.pcm \
+// RUN: -fmodule-file=b=%t/b.pcm -fsyntax-only -verify
+
+//--- foo.h
+namespace n {
+
+struct s { };
+
+void operator+(s, int) {}
+
+} // namespace n
+
+//--- a.cppm
+module;
+#include "foo.h"
+export module a;
+export namespace n {
+using n::s;
+#ifdef EXPORT_OPERATOR
+using n::operator+;
+#endif
+}
+
+//--- b.cppm
+export module b;
+export import a;
+
+export template
+void b(T x) {
+   n::s() + x;
+}
+
+//--- c.cppm
+#ifdef EXPORT_OPERATOR
+// expected-no-diagnostics
+#endif
+export module c;
+import b;
+
+void c(int x) {
+#ifndef EXPORT_OPERATOR
+   // expected-er...@b.cppm:6 {{invalid operands to binary expression 
('n::s' and 'int')}}
+// expected-note@+2 {{in instantiation of function template specialization 
'b' requested here}}
+#endif
+b(0);
+
+#ifndef EXPORT_OPERATOR
+// expected-error@+2 {{invalid operands to binary expression ('n::s' and 
'int')}}
+#endif
+n::s() + x;
+}

diff  --git a/clang/test/Modules/pr62589.cppm b/clang/test/Modules/pr62589.cppm
new file mode 100644
index 0..4164c3405ac0e
--- /dev/null
+++ b/clang/test/Modules/pr62589.cppm
@@ -0,0 +1,79 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++23 -emit-module-interface %t/a.cppm -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++23 %t/b.cpp -fmodule-file=a=%t/a.pcm -fsyntax-only 
-verify
+
+//--- foo.h
+class TypeA {};
+
+template
+concept __comparable = requires (_Tp &&__t, _Up &&__u) {
+__t == __u;
+};
+
+namespace ranges {
+namespace __end {
+  template 
+  concept __member_end =
+requires(_Tp&& __t) {
+{ __t.end() } -> __comparable;
+};
+
+  struct __fn {
+template 
+  requires __member_end<_Tp>
+constexpr auto operator()(_Tp&& __t) const
+{
+  return true;
+}
+
+void operator()(auto&&) const = delete;
+  };
+}
+
+inline namespace __cpo {
+  inline constexpr auto end = __end::__fn{};
+}
+}
+
+template 
+concept range = requires(_Tp& __t) {
+ranges:

[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 520648.
kadircet marked 3 inline comments as done.
kadircet added a comment.

Merge with existing tests
Perform check earlier


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150187

Files:
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
@@ -3,3 +3,14 @@
 // This used to cause a null pointer dereference.
 auto [left] = right;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
+
+namespace crash_on_nonidentifiers {
+struct Foo {
+  operator bool();
+};
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
  const SourceManager *SourceMgr) {
+  // Don't keep track for non-identifier names.
+  auto *II = Decl->getIdentifier();
+  if (!II)
+return;
   if (const auto *Method = dyn_cast(Decl)) {
 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  return addUsage(
+  RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()),
+  Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
@@ -3,3 +3,14 @@
 // This used to cause a null pointer dereference.
 auto [left] = right;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
+
+namespace crash_on_nonidentifiers {
+struct Foo {
+  operator bool();
+};
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
  const SourceManager *SourceMgr) {
+  // Don't keep track for non-identifier names.
+  auto *II = Decl->getIdentifier();
+  if (!II)
+return;
   if (const auto *Method = dyn_cast(Decl)) {
 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  return addUsage(
+  RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()),
+  Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 7385cc3 - [clangd] Support macro evaluation on hover

2023-05-09 Thread Younan Zhang via cfe-commits

Author: Younan Zhang
Date: 2023-05-09T18:50:27+08:00
New Revision: 7385cc389abad29eb9044d260b23dd483d674718

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

LOG: [clangd] Support macro evaluation on hover

Creating a SelectionTree at the location where macro expands allows
us to obtain the associated expression, which might then be used to
evaluate compile-time values if possible.

Closes clangd/clangd#1595.

Reviewed By: nridge

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 558769f209860..9b789901e77c6 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -463,8 +463,23 @@ std::optional printExprValue(const Expr *E,
   return Constant.Val.getAsString(Ctx, T);
 }
 
-std::optional printExprValue(const SelectionTree::Node *N,
-  const ASTContext &Ctx) {
+struct PrintExprResult {
+  /// The evaluation result on expression `Expr`.
+  std::optional PrintedValue;
+  /// The Expr object that represents the closest evaluable
+  /// expression.
+  const Expr *Expr;
+  /// The node of selection tree where the traversal stops.
+  const SelectionTree::Node *Node;
+};
+
+// Seek the closest evaluable expression along the ancestors of node N
+// in a selection tree. If a node in the path can be converted to an evaluable
+// Expr, a possible evaluation would happen and the associated context
+// is returned.
+// If evaluation couldn't be done, return the node where the traversal ends.
+PrintExprResult printExprValue(const SelectionTree::Node *N,
+   const ASTContext &Ctx) {
   for (; N; N = N->Parent) {
 // Try to evaluate the first evaluatable enclosing expression.
 if (const Expr *E = N->ASTNode.get()) {
@@ -473,14 +488,16 @@ std::optional printExprValue(const 
SelectionTree::Node *N,
   if (!E->getType().isNull() && E->getType()->isVoidType())
 break;
   if (auto Val = printExprValue(E, Ctx))
-return Val;
+return PrintExprResult{/*PrintedValue=*/std::move(Val), /*Expr=*/E,
+   /*Node=*/N};
 } else if (N->ASTNode.get() || N->ASTNode.get()) {
   // Refuse to cross certain non-exprs. (TypeLoc are OK as part of Exprs).
   // This tries to ensure we're showing a value related to the cursor.
   break;
 }
   }
-  return std::nullopt;
+  return PrintExprResult{/*PrintedValue=*/std::nullopt, /*Expr=*/nullptr,
+ /*Node=*/N};
 }
 
 std::optional fieldName(const Expr *E) {
@@ -677,6 +694,54 @@ getPredefinedExprHoverContents(const PredefinedExpr &PE, 
ASTContext &Ctx,
   return HI;
 }
 
+HoverInfo evaluateMacroExpansion(unsigned int SpellingBeginOffset,
+ unsigned int SpellingEndOffset,
+ llvm::ArrayRef Expanded,
+ ParsedAST &AST) {
+  auto &Context = AST.getASTContext();
+  auto &Tokens = AST.getTokens();
+  auto PP = getPrintingPolicy(Context.getPrintingPolicy());
+  auto Tree = SelectionTree::createRight(Context, Tokens, SpellingBeginOffset,
+ SpellingEndOffset);
+
+  // If macro expands to one single token, rule out punctuator or digraph.
+  // E.g., for the case `array L_BRACKET 42 R_BRACKET;` where L_BRACKET and
+  // R_BRACKET expand to
+  // '[' and ']' respectively, we don't want the type of
+  // 'array[42]' when user hovers on L_BRACKET.
+  if (Expanded.size() == 1)
+if (tok::getPunctuatorSpelling(Expanded[0].kind()))
+  return {};
+
+  auto *StartNode = Tree.commonAncestor();
+  if (!StartNode)
+return {};
+  // If the common ancestor is partially selected, do evaluate if it has no
+  // children, thus we can disallow evaluation on incomplete expression.
+  // For example,
+  // #define PLUS_2 +2
+  // 40 PL^US_2
+  // In this case we don't want to present 'value: 2' as PLUS_2 actually 
expands
+  // to a non-value rather than a binary operand.
+  if (StartNode->Selected == SelectionTree::Selection::Partial)
+if (!StartNode->Children.empty())
+  return {};
+
+  HoverInfo HI;
+  // Attempt to evaluate it from Expr first.
+  auto ExprResult = printExprValue(StartNode, Context);
+  HI.Value = std::move(ExprResult.PrintedValue);
+  if (auto *E = ExprResult.Expr)
+HI.Type = printType(E->getType(), Context, PP);
+
+  // If failed, extract the type from Decl if possible.
+  if (!HI.Value && !HI.Type && ExprResult.Node)
+if (auto *VD = ExprResult.Node->ASTNode.get())
+  HI.Type = printType(VD->

[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-05-09 Thread Younan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7385cc389aba: [clangd] Support macro evaluation on hover 
(authored by zyounan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 
 #include "gtest/gtest.h"
 #include 
@@ -529,6 +530,8 @@
[](HoverInfo &HI) {
  HI.Name = "MACRO";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Value = "41 (0x29)";
+ HI.Type = "int";
  HI.Definition = "#define MACRO 41\n\n"
  "// Expands to\n"
  "41";
@@ -560,6 +563,7 @@
[](HoverInfo &HI) {
  HI.Name = "DECL_STR";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Type = HoverInfo::PrintedType("const char *");
  HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
  "STRINGIFY(VALUE)\n\n"
  "// Expands to\n"
@@ -1850,6 +1854,8 @@
   )cpp",
   [](HoverInfo &HI) {
 HI.Name = "MACRO";
+HI.Value = "0";
+HI.Type = "int";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0\n\n"
 "// Expands to\n"
@@ -3769,6 +3775,232 @@
   EXPECT_EQ(H->Type->Type, "int");
   EXPECT_EQ(H->Definition, "using foo = type");
 }
+
+TEST(Hover, EvaluateMacros) {
+  llvm::StringRef PredefinedCXX = R"cpp(
+#define X 42
+#define SizeOf sizeof
+#define AlignOf alignof
+#define PLUS_TWO +2
+#define TWO 2
+
+using u64 = unsigned long long;
+// calculate (a ** b) % p
+constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
+  u64 ret = 1;
+  while (b) {
+if (b & 1)
+  ret = (ret * a) % p;
+a = (a * a) % p;
+b >>= 1;
+  }
+  return ret;
+}
+#define last_n_digit(x, y, n)  \
+  pow_with_mod(x, y, pow_with_mod(10, n, 2147483647))
+#define declare_struct(X, name, value) \
+  struct X {   \
+constexpr auto name() { return value; }\
+  }
+#define gnu_statement_expression(value)\
+  ({   \
+declare_struct(Widget, getter, value); \
+Widget().getter(); \
+  })
+#define define_lambda_begin(lambda, ...)   \
+  [&](__VA_ARGS__) {
+#define define_lambda_end() }
+
+#define left_bracket [
+#define right_bracket ]
+#define dg_left_bracket <:
+#define dg_right_bracket :>
+#define array_decl(type, name, size) type name left_bracket size right_bracket
+  )cpp";
+
+  struct {
+llvm::StringRef Code;
+const std::function, size_t /*Id*/)>
+Validator;
+  } Cases[] = {
+  {
+  /*Code=*/R"cpp(
+X^;
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "42 (0x2a)");
+EXPECT_EQ(HI->Type, HoverInfo::PrintedType("int"));
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+Size^Of(int);
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+// Don't validate type or value of `sizeof` and `alignof` as we're
+// getting different values or desugared types on different
+// platforms. Same as below.
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  struct Y {
+int y;
+double z;
+  };
+  Alig^nOf(Y);
+)cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  // 2**32 == 4294967296
+  last_n_di^git(2, 32, 6);
+)cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "967296 (0xec280)");
+EXPECT_EQ(HI->Type, "u64");
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+  gnu_statement_exp^ression(42);
+)cpp",
+  /*Validator=*/
+ 

[clang-tools-extra] b36a2e7 - [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-05-09T12:50:57+02:00
New Revision: b36a2e7828befcf948f461b72c78a8d2386db2e7

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

LOG: [tidy][IdentifierNaming] Fix crashes on non-identifiers

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 5347dadf18ac5..ee400d88a3a74 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@ void RenamerClangTidyCheck::addUsage(
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
  const SourceManager *SourceMgr) {
+  // Don't keep track for non-identifier names.
+  auto *II = Decl->getIdentifier();
+  if (!II)
+return;
   if (const auto *Method = dyn_cast(Decl)) {
 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  return addUsage(
+  RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()),
+  Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
index 9f892ebceccf2..25f2c71a316d7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
@@ -3,3 +3,14 @@
 // This used to cause a null pointer dereference.
 auto [left] = right;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
+
+namespace crash_on_nonidentifiers {
+struct Foo {
+  operator bool();
+};
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
+}



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


[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Kadir Cetinkaya 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 rGb36a2e7828be: [tidy][IdentifierNaming] Fix crashes on 
non-identifiers (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150187

Files:
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
@@ -3,3 +3,14 @@
 // This used to cause a null pointer dereference.
 auto [left] = right;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
+
+namespace crash_on_nonidentifiers {
+struct Foo {
+  operator bool();
+};
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
  const SourceManager *SourceMgr) {
+  // Don't keep track for non-identifier names.
+  auto *II = Decl->getIdentifier();
+  if (!II)
+return;
   if (const auto *Method = dyn_cast(Decl)) {
 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  return addUsage(
+  RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()),
+  Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-bugfix.cpp
@@ -3,3 +3,14 @@
 // This used to cause a null pointer dereference.
 auto [left] = right;
 // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
+
+namespace crash_on_nonidentifiers {
+struct Foo {
+  operator bool();
+};
+void foo() {
+  // Make sure we don't crash on non-identifier names (e.g. conversion
+  // operators).
+  if (Foo()) {}
+}
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -448,14 +448,18 @@
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
  const SourceManager *SourceMgr) {
+  // Don't keep track for non-identifier names.
+  auto *II = Decl->getIdentifier();
+  if (!II)
+return;
   if (const auto *Method = dyn_cast(Decl)) {
 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
   Decl = Overridden;
   }
   Decl = cast(Decl->getCanonicalDecl());
-  return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
-   Decl->getName()),
-  Range, SourceMgr);
+  return addUsage(
+  RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), II->getName()),
+  Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-05-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Generally lgtm, let's extend the test coverage.




Comment at: clang/lib/Interpreter/DeviceOffload.cpp:1
+//===-- Offload.cpp - CUDA Offloading ---*- C++ 
-*-===//
+//

Likewise.



Comment at: clang/lib/Interpreter/DeviceOffload.h:1
+//===--- Offload.h - CUDA Offloading *- C++ 
-*-===//
+//

We should probably update the name here as well and maybe drop CUDA?



Comment at: clang/test/Interpreter/CUDA/sanity.cu:10
+// CHECK: CUDA Error: 0
+
+%quit

Let's extend the coverage with some more standard hello world examples. We can 
draw some inspiration from 
https://github.com/root-project/cling/tree/master/test/CUDADeviceCode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146389

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


[PATCH] D150187: [tidy][IdentifierNaming] Fix crashes on non-identifiers

2023-05-09 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp:457
+  // Don't keep track for non-identifier names.
+  if (auto *II = Decl->getIdentifier()) {
+return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),

PiotrZSL wrote:
> Most probably this could be done before for, as overridden/cannonical decl 
> should have same naming.
> And looks we get here from VisitMemberExpr.
Could you do an early return instead? I believe it's clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150187

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


[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: cjdb, aaron.ballman, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Just a small improvement.

Before:

  array.cpp:1279:9: error: use of undeclared identifier 'foo'
   1279 | int a = foo();
| ^
  array.cpp:1280:9: error: use of undeclared identifier 'foo'
   1280 | int b = foo;
| ^
  2 errors generated.

After:

  array.cpp:1279:9: error: use of undeclared identifier 'foo'
   1279 | int a = foo();
| ^~~
  array.cpp:1280:9: error: use of undeclared identifier 'foo'
   1280 | int b = foo;
| ^~~
  2 errors generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150191

Files:
  clang/include/clang/Sema/Lookup.h
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2173,7 +2173,7 @@
 
 static void emitEmptyLookupTypoDiagnostic(
 const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS,
-DeclarationName Typo, SourceLocation TypoLoc, ArrayRef Args,
+DeclarationName Typo, SourceRange TypoRange, ArrayRef Args,
 unsigned DiagnosticID, unsigned DiagnosticSuggestID) {
   DeclContext *Ctx =
   SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false);
@@ -2181,10 +2181,10 @@
 // Emit a special diagnostic for failed member lookups.
 // FIXME: computing the declaration context might fail here (?)
 if (Ctx)
-  SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
- << SS.getRange();
+  SemaRef.Diag(TypoRange.getBegin(), diag::err_no_member)
+  << Typo << Ctx << TypoRange;
 else
-  SemaRef.Diag(TypoLoc, DiagnosticID) << Typo;
+  SemaRef.Diag(TypoRange.getEnd(), DiagnosticID) << Typo << TypoRange;
 return;
   }
 
@@ -2198,9 +2198,9 @@
 SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo,
  SemaRef.PDiag(NoteID));
   else
-SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
- << Typo << Ctx << DroppedSpecifier
- << SS.getRange(),
+SemaRef.diagnoseTypo(TC,
+ SemaRef.PDiag(diag::err_no_member_suggest)
+ << Typo << Ctx << DroppedSpecifier << TypoRange,
  SemaRef.PDiag(NoteID));
 }
 
@@ -2324,16 +2324,16 @@
 DC = DC->getLookupParent();
   }
 
+  SourceRange TypoRange = R.getNameRange();
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
-SourceLocation TypoLoc = R.getNameLoc();
 assert(!ExplicitTemplateArgs &&
"Diagnosing an empty lookup with explicit template args!");
 *Out = CorrectTypoDelayed(
 R.getLookupNameInfo(), R.getLookupKind(), S, &SS, CCC,
 [=](const TypoCorrection &TC) {
-  emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args,
+  emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoRange, Args,
 diagnostic, diagnostic_suggest);
 },
 nullptr, CTK_ErrorRecovery);
@@ -2436,7 +2436,7 @@
   }
 
   // Give up, we can't recover.
-  Diag(R.getNameLoc(), diagnostic) << Name;
+  Diag(R.getNameLoc(), diagnostic) << Name << TypoRange;
   return true;
 }
 
Index: clang/include/clang/Sema/Lookup.h
===
--- clang/include/clang/Sema/Lookup.h
+++ clang/include/clang/Sema/Lookup.h
@@ -633,6 +633,10 @@
 return NameInfo.getLoc();
   }
 
+  SourceRange getNameRange() const {
+return SourceRange(NameInfo.getBeginLoc(), NameInfo.getEndLoc());
+  }
+
   /// Get the Sema object that this lookup result is searching
   /// with.
   Sema &getSema() const { return *SemaPtr; }


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2173,7 +2173,7 @@
 
 static void emitEmptyLookupTypoDiagnostic(
 const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS,
-DeclarationName Typo, SourceLocation TypoLoc, ArrayRef Args,
+DeclarationName Typo, SourceRange TypoRange, ArrayRef Args,
 unsigned DiagnosticID, unsigned DiagnosticSuggestID) {
   DeclContext *Ctx =
   SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false);
@@ -2181,10 +2181,10 @@
 // Emit a special diagnostic for failed member lookups.
 // FIXME: computing the declaration context might fail here (?)
 if (Ctx)
-  SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
- << SS.getRange();
+  SemaRef.Diag(

[PATCH] D150192: Allow clang to emit inrange metadata when generating code for array subscripts

2023-05-09 Thread Simeon Krastnikov via Phabricator via cfe-commits
simeon-imgtec created this revision.
simeon-imgtec added reviewers: pcc, eli.friedman.
simeon-imgtec created this object with visibility "All Users".
Herald added subscribers: mattd, asavonic, jdoerfert, pengfei, hiraditya, 
jvesely.
Herald added a project: All.
simeon-imgtec requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

As out-of-bounds array accesses are undefined in C/C++ 
, we can capture 
this restriction using the newly introduced inrange attribute on individual GEP 
indices. The underlying motivation is that it would enable less conservative 
inferences in (basic) alias analysis, in turn improving passes such as GVN and 
LICM.

As the inrange keyword is currently only supported on constant GEPs, we extend 
the support to GEP instructions, and mofiy clang to emit the inrange flag in an 
array subscript scenario where it is safe to do so.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150192

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/2005-01-02-ConstantInits.c
  clang/test/CodeGen/2010-07-14-ref-off-end.c
  clang/test/CodeGen/X86/va-arg-sse.c
  clang/test/CodeGen/builtin-align-array.c
  clang/test/CodeGen/exprs.c
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGen/ubsan-pointer-overflow.c
  clang/test/CodeGen/unaligned-expr.c
  clang/test/CodeGen/union-tbaa1.c
  clang/test/CodeGen/vla.c
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/compound-literals.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/lambda-expressions.cpp
  clang/test/CodeGenCXX/no-odr-use.cpp
  clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  clang/test/OpenMP/align_clause_codegen.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/for_firstprivate_codegen.cpp
  clang/test/OpenMP/for_lastprivate_codegen.cpp
  clang/test/OpenMP/for_private_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp
  clang/test/OpenMP/for_scan_codegen.cpp
  clang/test/OpenMP/for_simd_scan_codegen.cpp
  clang/test/OpenMP/irbuilder_simd_aligned.cpp
  clang/test/OpenMP/master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/ordered_codegen.cpp
  clang/test/OpenMP/parallel_copyin_codegen.cpp
  clang/test/OpenMP/parallel_firstprivate_codegen.cpp
  clang/test/OpenMP/parallel_for_scan_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_firstprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/parallel_private_codegen.cpp
  clang/test/OpenMP/parallel_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/sections_firstprivate_codegen.cpp
  clang/test/OpenMP/sections_lastprivate_codegen.cpp
  clang/test/OpenMP/sections_private_codegen.cpp
  clang/test/OpenMP/sections_reduction_codegen.cpp
  clang/test/OpenMP/single_firstprivate_codegen.cpp
  clang/test/OpenMP/single_private_codegen.cpp

[PATCH] D149119: [CMake] Use LLVM own tools in extract_symbols.py

2023-05-09 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for doing this. Please give it a couple of days in case others 
have comments.


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

https://reviews.llvm.org/D149119

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


[PATCH] D149119: [CMake] Use LLVM own tools in extract_symbols.py

2023-05-09 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

I've not really looked into this patch significantly, so this may well be 
addressed in the patch, given I see you have modified stuff to do with the 
NATIVE build, but in the past I have seen LLVM using its own tools to build 
other parts of its system. I believe it was using llvm-nm to extract the list 
of symbols needed for export, possibly to do with part of the clang build, 
possibly even using this script, I don't remember. The problem was that it was 
using the just-built version of llvm-nm, rather than specifically one from a 
release build. On a debug build this caused particularly slow builds for me, so 
much so that I stopped building the relevant parts of LLVM. Please don't 
introduce a similar situation/make the situation worse (it's quite possible 
this was fixed some time ago, but I haven't tried recently, nor do I remember 
the exact thing causing the issue): much like tablegen, any parts of the LLVM 
build that use just-built tools should make use of release builds, even in 
debug configuration, at least if an appropriate cmake option is specified.


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

https://reviews.llvm.org/D149119

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D139837#4326501 , @cor3ntin wrote:

> @erichkeane @aaron.ballman I think we should determine how much works remains 
> there and if the author is not responsive maybe one of us can push this up 
> the finishing line.

That seems like a reasonable approach to me; it'd be good to get this into 
Clang 17 if possible, and @ychen seems to have been away for ~2 months now, so 
it seems reasonable to commandeer this review if we need to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D149982: AMDGPU: Add basic gfx941 target

2023-05-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Target/AMDGPU/AMDGPU.td:1231-1261
+  [FeatureGFX9,
+   FeatureGFX90AInsts,
+   FeatureGFX940Insts,
+   FeatureFmaMixInsts,
+   FeatureLDSBankCount32,
+   FeatureDLInsts,
+   FeatureFmacF64Inst,

We probably should make better use of groups and implied features to cut down 
on the size of these lists for each of these 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149982

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


[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Should this be a feature set by default in the subtarget constructor instead? 
Should you be able to turn this off?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149986

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


[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The changes are reasonable but should have test coverage. We test source ranges 
with `-fdiagnostics-print-source-range-info` as in 
https://github.com/llvm/llvm-project/blob/929a8c9f72dc405779a8aaf82304efdb7f1ab5e4/clang/test/Misc/diag-greatergreater.cpp#L4


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150191

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


[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Right, I expect (hope?) precommit CI to fail, but I'm stuck at an airport right 
now so I'll leave tests for when I'm back home.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150191

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread CaprYang via Phabricator via cfe-commits
CaprYang updated this revision to Diff 520660.

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

https://reviews.llvm.org/D150043

Files:
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
  llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
  llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll

Index: llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll
@@ -0,0 +1,101 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @double_ascast(
+; CHECK: call void @use(<4 x ptr addrspace(3)> %input)
+; CHECK: ret void
+define void @double_ascast(<4 x ptr addrspace(3)> %input) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  %tmp1 = addrspacecast <4 x ptr> %tmp0 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp1)
+  ret void
+}
+
+; CHECK-LABEL: @double_gep(
+; CHECK: %tmp1 = getelementptr float, ptr addrspace(3) %input, <4 x i64> %i
+; CHECK: %tmp2 = getelementptr float, <4 x ptr addrspace(3)> %tmp1, i64 %j
+; CHECK: call void @use(<4 x ptr addrspace(3)> %tmp2)
+; CHECK: ret void
+define void @double_gep(ptr addrspace(3) %input, <4 x i64> %i, i64 %j) {
+entry:
+  %tmp0 = addrspacecast ptr addrspace(3) %input to ptr
+  %tmp1 = getelementptr float, ptr %tmp0, <4 x i64> %i
+  %tmp2 = getelementptr float, <4 x ptr> %tmp1, i64 %j
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_phi(
+; CHECK: entry:
+; CHECK: br i1 %cond, label %inc, label %end
+; CHECK: inc:
+; CHECK: %tmp1 = getelementptr float, <4 x ptr addrspace(3)> %input, i64 1
+; CHECK: br label %end
+; CHECK: end:
+; CHECK: %tmp2 = phi <4 x ptr addrspace(3)> [ %input, %entry ], [ %tmp1, %inc ]
+; CHECK: call void @use(<4 x ptr addrspace(3)> %tmp2)
+; CHECK: ret void
+define void @inferas_phi(<4 x ptr addrspace(3)> %input, i1 %cond) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  br i1 %cond, label %inc, label %end
+
+inc:
+  %tmp1 = getelementptr float, <4 x ptr> %tmp0, i64 1
+  br label %end
+
+end:
+  %tmp2 = phi <4 x ptr> [ %tmp0, %entry ], [ %tmp1, %inc ]
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_ptr2int2ptr(
+; CHECK: call void @use(<4 x ptr addrspace(3)> %input)
+; CHECK: ret void
+define void @inferas_ptr2int2ptr(<4 x ptr addrspace(3)> %input) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  %tmp1 = ptrtoint <4 x ptr> %tmp0 to <4 x i64>
+  %tmp2 = inttoptr <4 x i64> %tmp1 to <4 x ptr>
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_loop(
+; CHECK: entry:
+; CHECK: br label %loop
+; CHECK: loop:
+; CHECK: %now = phi <4 x ptr addrspace(3)> [ %begin, %entry ], [ %next, %loop ]
+; CHECK: call void @use(<4 x ptr addrspace(3)> %now)
+; CHECK: %next = getelementptr float, <4 x ptr addrspace(3)> %now, i64 1
+; CHECK: %veq = icmp eq <4 x ptr addrspace(3)> %next, %end
+; CHECK: %mask = bitcast <4 x i1> %veq to i4
+; CHECK: %cond = icmp eq i4 %mask, 0
+; CHECK: br i1 %cond, label %loop, label %exit
+; CHECK: exit:
+; CHECK: ret void
+define void @inferas_loop(<4 x ptr addrspace(3)> %begin, <4 x ptr addrspace(3)> %end) {
+entry:
+  %begin0 = addrspacecast <4 x ptr addrspace(3)> %begin to <4 x ptr>
+  %end0 = addrspacecast <4 x ptr addrspace(3)> %end to <4 x ptr>
+  br label %loop
+
+loop:
+  %now = phi <4 x ptr> [ %begin0, %entry ], [ %next, %loop ]
+  %now3 = addrspacecast <4 x ptr> %now to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %now3)
+  %next = getelementptr float, <4 x ptr> %now, i64 1
+  %veq = icmp eq <4 x ptr> %next, %end0
+  %mask = bitcast <4 x i1> %veq to i4
+  %cond = icmp eq i4 %mask, 0
+  br i1 %cond, label %loop, label %exit
+
+exit:
+  ret void
+}
+
+declare void @use(<4 x ptr addrspace(3)>)
\ No newline at end of file
Index: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1
+define <4 x i32> @masked_gather_inferas(ptr addrspace(1) %out, <4 x i64> %index) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  %value

[PATCH] D150139: [clang-repl] Enable basic multiline support.

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Interpreter/multiline.cpp:12-17
+void f(int x) \ 
+{   \
+  printf("x=\
+  %d", x); \
+}
+f(i);

Another fun test case:
```
// Requires -ftrigraphs but the following line ends with a backslash (surprise!)
i=??/
  12;
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D150139

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread CaprYang via Phabricator via cfe-commits
CaprYang added inline comments.



Comment at: llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll:151
 ; CHECK-LABEL: @icmp_flat_flat_from_group_vector(
-; CHECK: %cmp = icmp eq <2 x ptr> %cast0, %cast1
+; CHECK: %cmp = icmp eq <2 x ptr addrspace(3)> %group.ptr.0, %group.ptr.1
 define <2 x i1> @icmp_flat_flat_from_group_vector(<2 x ptr addrspace(3)> 
%group.ptr.0, <2 x ptr addrspace(3)> %group.ptr.1) #0 {

CaprYang wrote:
> arsenm wrote:
> > You touched a lot more than just icmp, so this needs more tests to cover 
> > all the newly handled cases 
> I will add more tests later
added


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

https://reviews.llvm.org/D150043

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


[PATCH] D150122: [Clang] Fix status of P0960

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: ayzhao.
aaron.ballman added subscribers: ayzhao, tstellar.
aaron.ballman added a comment.

I believe we are having another release of Clang 16, but @tstellar can confirm 
or deny that.

AIUI, there were a few issues holding us back from claiming complete support 
(added @ayzhao as a reviewer in case he has a different opinion):
https://github.com/llvm/llvm-project/issues/61145  (backported to 16.x)
https://github.com/llvm/llvm-project/issues/62296  (backported to 16.x)
https://github.com/llvm/llvm-project/issues/62266  (not backported)
https://github.com/llvm/llvm-project/issues/61567  (not backported)

If we backport the two other issues to 16, then I think the changes in this 
review are fine. If we don't backport those two, I think we should claim Clang 
17 to be conservative.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp:289
+
+static bool hasSameElementOfPtrOrVecPtrs(Type *Ty1, Type *Ty2) {
+  assert(isPtrOrVecOfPtrsType(Ty1) && isPtrOrVecOfPtrsType(Ty2));

arsenm wrote:
> Ditto, only opaque pointers matter now
You don't need to bother using getWithSamePointeeType. You can use 
Type::getWithNewType



Comment at: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll:3
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1

Generate full checks 



Comment at: llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll:2
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace 
%s | FileCheck %s
+
+; CHECK-LABEL: @double_ascast(

Generate full checks 


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

https://reviews.llvm.org/D150043

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


[clang-tools-extra] 28bdff1 - [clangd][NFX][FIX] Fix conflicting symbol name `Expr`

2023-05-09 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-05-09T07:58:36-05:00
New Revision: 28bdff19e3ad981ef83e372e8c301f1407b82135

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

LOG: [clangd][NFX][FIX] Fix conflicting symbol name `Expr`

Summary:
This class has a member named `Expr` which conflicts with the clang type
of the same name due to the namespace. If we want to do this we need to
explicitly scope the variable. This was preventing me from building.
This was introduced in https://reviews.llvm.org/D148457

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 9b789901e77c..61bed1ad8141 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -468,7 +468,7 @@ struct PrintExprResult {
   std::optional PrintedValue;
   /// The Expr object that represents the closest evaluable
   /// expression.
-  const Expr *Expr;
+  const clang::Expr *Expr;
   /// The node of selection tree where the traversal stops.
   const SelectionTree::Node *Node;
 };



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


[PATCH] D148700: [clang] Add support for “regular” keyword attributes

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2427-2430
+def ArmStreaming : TypeAttr, TargetSpecificAttr {
+  let Spellings = [RegularKeyword<"__arm_streaming">];
+  let Documentation = [Undocumented];
+}

I'd feel more comfortable switching an existing attribute over to use this new 
functionality instead of introducing a new attribute at the same time. (Also, 
we ask that there be no new undocumented attributes unless there's a Very Good 
Reason to leave it undocumented.)



Comment at: clang/include/clang/Lex/Token.h:122
+
+  /// Return true if K is a keyword that is parsed in the same position as
+  /// a standard attribute, but that has semantic meaning and so cannot be





Comment at: clang/lib/AST/TypePrinter.cpp:1724-1727
+  if (T->getAttrKind() == attr::ArmStreaming) {
+OS << "__arm_streaming";
+return;
+  }

This seems like something that tablegen should automatically handle more 
generally for these attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148700

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In general, I think this is incremental progress on the diagnostic behavior. 
However, it's clear that there is room for interpretation on what is or is not 
a false positive diagnostic for this, so we should pay close attention to user 
feedback during the 17.x release cycle. If it seems we're getting significant 
push back, we may need to come back and rethink.

Specifically, I think we've improved the situation for code like this:

  // `p` is a pointer, `x` is an `int`, and `b` is a `bool`
  p + x ? 1 : 2; // previously didn't warn, now warns
  p + b ? 1 : 2; // always warned

Does anyone feel we should not move forward with accepting the patch in its 
current form?




Comment at: clang/docs/ReleaseNotes.rst:374-375
   (`#62305 `_)
+  (`#62305 `_)
+- Print diagnostic warning about precedence when integer expression is used
+  without parentheses in an conditional operator expression

It looks like a rebase accidentally duplicated this line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread CaprYang via Phabricator via cfe-commits
CaprYang added inline comments.



Comment at: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp:289
+
+static bool hasSameElementOfPtrOrVecPtrs(Type *Ty1, Type *Ty2) {
+  assert(isPtrOrVecOfPtrsType(Ty1) && isPtrOrVecOfPtrsType(Ty2));

arsenm wrote:
> arsenm wrote:
> > Ditto, only opaque pointers matter now
> You don't need to bother using getWithSamePointeeType. You can use 
> Type::getWithNewType
Does it mean this? do't check non-opaque types.

```
static Type *getPtrOrVecOfPtrsWithNewAS(Type *Ty, unsigned NewAddrSpace) {
  assert(Ty->isPtrOrPtrVectorTy());
  PointerType *NPT = PointerType::get(Ty->getContext(), NewAddrSpace);
  return Ty->getWithNewType(NPT);
}
```


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

https://reviews.llvm.org/D150043

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


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:302
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift >= 64 && "Shift is out of encodable range");
   return (V << Shift) & Mask;

sdesmalen wrote:
> erichkeane wrote:
> > Shouldn't this be: `assert(Shift < 64 &&"...")`?
> > 
> > `expr.shift` (https://eel.is/c++draft/expr.shift) says:
> > ```
> > The operands shall be of integral or unscoped enumeration type and integral 
> > promotions are performed.
> > The type of the result is that of the promoted left operand.
> > The behavior is undefined if the right operand is negative, or greater than 
> > or equal to the width of the promoted left operand.```
> > 
> > uint64 stays as an `unsigned long`, so it is still 64 bits, so the only 
> > invalid value for `Shift` is 64 (though >64 is 'nonsense', but only 
> > impossible because of `llvm::countr_zero`).
> > 
> > One thing to consider: I wonder if we should instead be changing the 
> > 'shift' to be:
> > 
> > `(V << (Shift % 64)) && Mask` ?  It looks like `arm_sve.td` has the 
> > `NoFlags` value as zero, which I think will end up going through here 
> > possibly (or at least, inserted into `FlagTypes`.
> > 
> > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > possible in that case (since a zero 'Mask' is the only case where 
> > `countr_zero` will end up being 64).
> > 
> > 
> > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > possible in that case (since a zero 'Mask' is the only case where 
> > countr_zero will end up being 64).
> It should be fine to assert that `Mask != 0`, since that would be an invalid 
> mask.
Thanks for the comment @sdesmalen!  Is there something that prevents the 
`NoFlags` from being passed as the `MaskName` here?  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150140

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


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:302
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift >= 64 && "Shift is out of encodable range");
   return (V << Shift) & Mask;

erichkeane wrote:
> sdesmalen wrote:
> > erichkeane wrote:
> > > Shouldn't this be: `assert(Shift < 64 &&"...")`?
> > > 
> > > `expr.shift` (https://eel.is/c++draft/expr.shift) says:
> > > ```
> > > The operands shall be of integral or unscoped enumeration type and 
> > > integral promotions are performed.
> > > The type of the result is that of the promoted left operand.
> > > The behavior is undefined if the right operand is negative, or greater 
> > > than or equal to the width of the promoted left operand.```
> > > 
> > > uint64 stays as an `unsigned long`, so it is still 64 bits, so the only 
> > > invalid value for `Shift` is 64 (though >64 is 'nonsense', but only 
> > > impossible because of `llvm::countr_zero`).
> > > 
> > > One thing to consider: I wonder if we should instead be changing the 
> > > 'shift' to be:
> > > 
> > > `(V << (Shift % 64)) && Mask` ?  It looks like `arm_sve.td` has the 
> > > `NoFlags` value as zero, which I think will end up going through here 
> > > possibly (or at least, inserted into `FlagTypes`.
> > > 
> > > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > > possible in that case (since a zero 'Mask' is the only case where 
> > > `countr_zero` will end up being 64).
> > > 
> > > 
> > > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > > possible in that case (since a zero 'Mask' is the only case where 
> > > countr_zero will end up being 64).
> > It should be fine to assert that `Mask != 0`, since that would be an 
> > invalid mask.
> Thanks for the comment @sdesmalen!  Is there something that prevents the 
> `NoFlags` from being passed as the `MaskName` here?  
There's nothing that actively prevents it, but `encodeFlag` is a utility 
function that has no uses outside this file and has only 4 uses. Adding an 
assert should be sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150140

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2583
+if (ArraySize->containsErrors()) {
+  RecoveryExpr *RE = RecoveryExpr::Create(
+  Context, ArraySize->getType(), ArraySize->getBeginLoc(),

HerrCai0907 wrote:
> erichkeane wrote:
> > Actually thinking further... rather than create a NEW RecoveryExpr, is 
> > there a problem KEEPING the ArraySize expression?  It'd likely give more 
> > information/keep more AST consistency.
> > 
> > ALSO, creating this as size-0 has some implications we probably don't want. 
> >  I wonder if a different for the placeholder would be better?  
> > 
> > I'D ALSO suggest hoisting this ArraySize->containsError out of the else-if 
> > and into its own branch (rather than inside the dependent checks).
> > KEEPING the ArraySize expression
> Agree.
> 
> > creating this as size-0 has some implications we probably don't want.
> Do you think we can modify it as 1? But I don't find a better way to 
> identifier it as undef or other.
> 
> > hoisting this ArraySize->containsError out of the else-if 
> Done
I don't have good evidence for what else we could do (whether an incomplete or 
variable type would be better), but at least 1 is 'legal', so perhaps we can 
live with this for now and see if there is any fallout.

What happens if we try to 'merge' a valid and an invalid here? Does it make the 
experience worse?  So same example you added below, but the 1st one has no 
error in its brackets?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149612

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-05-09 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 520678.
bolshakov-a added a comment.

Fix MS compatibility mangling algorithm. Tested with MSVC ver. 19.35 (toolset 
ver. 143).


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7305,6 +7305,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -849,6 +849,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1053,13 +1053,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1";>P1907R1
+  
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1";>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3";>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1570,6 +1570,11 @@
   return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
 return false;
 
+  case TemplateArgument::StructuralValue:
+if (Expr *E = TAL.getSourceStructuralValueExpression())
+  return Vis

[PATCH] D149119: [CMake] Use LLVM own tools in extract_symbols.py

2023-05-09 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

One potential area of concern here: If `llvm-driver` is ever extended to work 
as a plugin loader (thus exporting its symbols), removing support for the 
pre-installed host tools could cause a cyclic dependency.


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

https://reviews.llvm.org/D149119

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


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 520681.
Manna edited the summary of this revision.
Manna added a comment.

Thank you for reviews and comments @erichkeane and @sdesmalen!  I have updated 
patch.


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

https://reviews.llvm.org/D150140

Files:
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Mask != 0 && "Mask is out of encodable range");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Mask != 0 && "Mask is out of encodable range");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked 4 inline comments as done.
Manna added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:302
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift >= 64 && "Shift is out of encodable range");
   return (V << Shift) & Mask;

sdesmalen wrote:
> erichkeane wrote:
> > sdesmalen wrote:
> > > erichkeane wrote:
> > > > Shouldn't this be: `assert(Shift < 64 &&"...")`?
> > > > 
> > > > `expr.shift` (https://eel.is/c++draft/expr.shift) says:
> > > > ```
> > > > The operands shall be of integral or unscoped enumeration type and 
> > > > integral promotions are performed.
> > > > The type of the result is that of the promoted left operand.
> > > > The behavior is undefined if the right operand is negative, or greater 
> > > > than or equal to the width of the promoted left operand.```
> > > > 
> > > > uint64 stays as an `unsigned long`, so it is still 64 bits, so the only 
> > > > invalid value for `Shift` is 64 (though >64 is 'nonsense', but only 
> > > > impossible because of `llvm::countr_zero`).
> > > > 
> > > > One thing to consider: I wonder if we should instead be changing the 
> > > > 'shift' to be:
> > > > 
> > > > `(V << (Shift % 64)) && Mask` ?  It looks like `arm_sve.td` has the 
> > > > `NoFlags` value as zero, which I think will end up going through here 
> > > > possibly (or at least, inserted into `FlagTypes`.
> > > > 
> > > > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > > > possible in that case (since a zero 'Mask' is the only case where 
> > > > `countr_zero` will end up being 64).
> > > > 
> > > > 
> > > > So I suspect an assert might not be sufficient, since a 64 bit shift is 
> > > > possible in that case (since a zero 'Mask' is the only case where 
> > > > countr_zero will end up being 64).
> > > It should be fine to assert that `Mask != 0`, since that would be an 
> > > invalid mask.
> > Thanks for the comment @sdesmalen!  Is there something that prevents the 
> > `NoFlags` from being passed as the `MaskName` here?  
> There's nothing that actively prevents it, but `encodeFlag` is a utility 
> function that has no uses outside this file and has only 4 uses. Adding an 
> assert should be sufficient.
Thank you for the explanation!


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

https://reviews.llvm.org/D150140

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread CaprYang via Phabricator via cfe-commits
CaprYang updated this revision to Diff 520692.

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

https://reviews.llvm.org/D150043

Files:
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
  llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
  llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll

Index: llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/vector-of-pointers.ll
@@ -0,0 +1,104 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @double_ascast(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use(<4 x ptr addrspace(3)> [[INPUT:%.*]])
+; CHECK-NEXT: ret void
+define void @double_ascast(<4 x ptr addrspace(3)> %input) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  %tmp1 = addrspacecast <4 x ptr> %tmp0 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp1)
+  ret void
+}
+
+; CHECK-LABEL: @double_gep(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr float, ptr addrspace(3) [[INPUT:%.*]], <4 x i64> [[I:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = getelementptr float, <4 x ptr addrspace(3)> [[TMP1]], i64 [[J:%.*]]
+; CHECK-NEXT: call void @use(<4 x ptr addrspace(3)> [[TMP2]])
+; CHECK-NEXT: ret void
+define void @double_gep(ptr addrspace(3) %input, <4 x i64> %i, i64 %j) {
+entry:
+  %tmp0 = addrspacecast ptr addrspace(3) %input to ptr
+  %tmp1 = getelementptr float, ptr %tmp0, <4 x i64> %i
+  %tmp2 = getelementptr float, <4 x ptr> %tmp1, i64 %j
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_phi(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label %inc, label %end
+; CHECK: inc:
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr float, <4 x ptr addrspace(3)> [[INPUT:%.*]], i64 1
+; CHECK-NEXT: br label %end
+; CHECK: end:
+; CHECK-NEXT: [[TMP2:%.*]] = phi <4 x ptr addrspace(3)> [ [[INPUT]], %entry ], [ [[TMP1]], %inc ]
+; CHECK-NEXT: call void @use(<4 x ptr addrspace(3)> [[TMP2]])
+; CHECK-NEXT: ret void
+define void @inferas_phi(<4 x ptr addrspace(3)> %input, i1 %cond) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  br i1 %cond, label %inc, label %end
+
+inc:
+  %tmp1 = getelementptr float, <4 x ptr> %tmp0, i64 1
+  br label %end
+
+end:
+  %tmp2 = phi <4 x ptr> [ %tmp0, %entry ], [ %tmp1, %inc ]
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_ptr2int2ptr(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use(<4 x ptr addrspace(3)> [[INPUT:%.*]])
+; CHECK-NEXT: ret void
+define void @inferas_ptr2int2ptr(<4 x ptr addrspace(3)> %input) {
+entry:
+  %tmp0 = addrspacecast <4 x ptr addrspace(3)> %input to <4 x ptr>
+  %tmp1 = ptrtoint <4 x ptr> %tmp0 to <4 x i64>
+  %tmp2 = inttoptr <4 x i64> %tmp1 to <4 x ptr>
+  %tmp3 = addrspacecast <4 x ptr> %tmp2 to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %tmp3)
+  ret void
+}
+
+; CHECK-LABEL: @inferas_loop(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK: loop:
+; CHECK-NEXT: [[NOW:%.*]] = phi <4 x ptr addrspace(3)> [ [[BEGIN:%.*]], %entry ], [ [[NEXT:%.*]], %loop ]
+; CHECK-NEXT: call void @use(<4 x ptr addrspace(3)> [[NOW]])
+; CHECK-NEXT: [[NEXT]] = getelementptr float, <4 x ptr addrspace(3)> [[NOW]], i64 1
+; CHECK-NEXT: [[VEQ:%.*]] = icmp eq <4 x ptr addrspace(3)> [[NEXT]], [[END:%.*]]
+; CHECK-NEXT: [[MASK:%.*]] = bitcast <4 x i1> [[VEQ]] to i4
+; CHECK-NEXT: [[COND:%.*]] = icmp eq i4 [[MASK]], 0
+; CHECK-NEXT: br i1 [[COND]], label %loop, label %exit
+; CHECK: exit:
+; CHECK-NEXT: ret void
+define void @inferas_loop(<4 x ptr addrspace(3)> %begin, <4 x ptr addrspace(3)> %end) {
+entry:
+  %begin0 = addrspacecast <4 x ptr addrspace(3)> %begin to <4 x ptr>
+  %end0 = addrspacecast <4 x ptr addrspace(3)> %end to <4 x ptr>
+  br label %loop
+
+loop:
+  %now = phi <4 x ptr> [ %begin0, %entry ], [ %next, %loop ]
+  %now3 = addrspacecast <4 x ptr> %now to <4 x ptr addrspace(3)>
+  call void @use(<4 x ptr addrspace(3)> %now3)
+  %next = getelementptr float, <4 x ptr> %now, i64 1
+  %veq = icmp eq <4 x ptr> %next, %end0
+  %mask = bitcast <4 x i1> %veq to i4
+  %cond = icmp eq i4 %mask, 0
+  br i1 %cond, label %loop, label %exit
+
+exit:
+  ret void
+}
+
+declare void @use(<4 x ptr addrspace(3)>)
\ No newline at end of file
Index: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
@@ -0,0 +1,31 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-ad

[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-09 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 520693.
Manna marked an inline comment as done.

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

https://reviews.llvm.org/D150140

Files:
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Mask != 0 && "Invalid mask value");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Mask != 0 && "Invalid mask value");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-09 Thread CaprYang via Phabricator via cfe-commits
CaprYang added inline comments.



Comment at: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll:3
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1

arsenm wrote:
> Generate full checks 
updated


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

https://reviews.llvm.org/D150043

___
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-05-09 Thread Jan Sjödin via Phabricator via cfe-commits
jsjodin added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:865
+  TargetRegionEntryInfo EntryInfo, StringRef MangledName,
+  Module *LlvmModule, std::vector &GeneratedRefs,
+  bool OpenMPSIMD, std::vector TargetTriple,

Instead of passing in the Module, we should be able to use M in the 
OpenMPIRBuilder.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:5225
+std::function VariableLinkage,
+llvm::Type *LlvmPtrTy, llvm::Constant *Addr) {
+  if (DeviceClause != OffloadEntriesInfoManager::OMPTargetDeviceClauseAny ||

no llvm::prefix (look for more occurrences)


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] D149495: [RISCV] Add support for V extension in SiFive7

2023-05-09 Thread Philip Reames via Phabricator via cfe-commits
reames accepted this revision.
reames added a comment.
This revision is now accepted and ready to land.

LGTM, thought please wait for other review feedback to settle.

I am very very happy to have this upstream, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

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


[clang] f859835 - [HIP] Detect HIP for Ubuntu, Mint, Gentoo, etc.

2023-05-09 Thread Yaxun Liu via cfe-commits

Author: Cordell Bloor
Date: 2023-05-09T11:31:57-04:00
New Revision: f8598357662dc8dd0f4400bcaeb48e8befe43ecc

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

LOG: [HIP] Detect HIP for Ubuntu, Mint, Gentoo, etc.

HIP may be installed into /usr or /usr/local on a variety of Linux
operating systems. It may become unwieldy to list them all.

Reviewed by: Siu Chi Chan, Yaxun Liu

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index acedcfabefe1..1eb22ed8704c 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -11,7 +11,6 @@
 #include "clang/Basic/TargetID.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
-#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
@@ -309,13 +308,10 @@ RocmInstallationDetector::getInstallationPathCandidates() 
{
 ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
 /*StrictChecking=*/true);
 
-  Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple()));
-  if (Dist.IsDebian() || Dist.IsRedhat()) {
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
-/*StrictChecking=*/true);
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
-/*StrictChecking=*/true);
-  }
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+  /*StrictChecking=*/true);
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+  /*StrictChecking=*/true);
 
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;



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


[PATCH] D149110: [HIP] Detect HIP for Ubuntu, Mint, Gentoo, etc.

2023-05-09 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8598357662d: [HIP] Detect HIP for Ubuntu, Mint, Gentoo, 
etc. (authored by cgmb, committed by yaxunl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149110

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -11,7 +11,6 @@
 #include "clang/Basic/TargetID.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
-#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
@@ -309,13 +308,10 @@
 ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
 /*StrictChecking=*/true);
 
-  Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple()));
-  if (Dist.IsDebian() || Dist.IsRedhat()) {
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
-/*StrictChecking=*/true);
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
-/*StrictChecking=*/true);
-  }
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+  /*StrictChecking=*/true);
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+  /*StrictChecking=*/true);
 
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -11,7 +11,6 @@
 #include "clang/Basic/TargetID.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
-#include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
@@ -309,13 +308,10 @@
 ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
 /*StrictChecking=*/true);
 
-  Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple()));
-  if (Dist.IsDebian() || Dist.IsRedhat()) {
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
-/*StrictChecking=*/true);
-ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
-/*StrictChecking=*/true);
-  }
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+  /*StrictChecking=*/true);
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+  /*StrictChecking=*/true);
 
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-05-09 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 520716.
bolshakov-a added a comment.

Rebased.


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7305,6 +7305,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -849,6 +849,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1049,13 +1049,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2";>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1";>P1907R1
+  
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1";>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3";>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1570,6 +1570,11 @@
   return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
 return false;
 
+  case TemplateArgument::StructuralValue:
+if (Expr *E = TAL.getSourceStructuralValueExpression())
+  return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
+return false;
+
   ca

[libclc] 21508fa - libclc: clspv: fix fma, add vstore and fix inlining issues

2023-05-09 Thread Kévin Petit via cfe-commits

Author: Kévin Petit
Date: 2023-05-09T16:52:13+01:00
New Revision: 21508fa76914a5e4281dc5bc77cac7f2e8bc3aef

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

LOG: libclc: clspv: fix fma, add vstore and fix inlining issues

https://reviews.llvm.org/D147773

Patch by Romaric Jodin 

Added: 
libclc/clspv/lib/shared/vstore_half.cl
libclc/clspv/lib/shared/vstore_half.inc

Modified: 
libclc/CMakeLists.txt
libclc/clspv/lib/SOURCES
libclc/clspv/lib/math/fma.cl
libclc/generic/include/clc/clcfunc.h

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 89f08b889ea1e..0eda12670b710 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -271,11 +271,11 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( spvflags --spirv-max-version=1.1 )
elseif( ${ARCH} STREQUAL "clspv" )
set( t "spir--" )
-   set( build_flags )
+   set( build_flags "-Wno-unknown-assumption")
set( opt_flags -O3 )
elseif( ${ARCH} STREQUAL "clspv64" )
set( t "spir64--" )
-   set( build_flags )
+   set( build_flags "-Wno-unknown-assumption")
set( opt_flags -O3 )
else()
set( build_flags )

diff  --git a/libclc/clspv/lib/SOURCES b/libclc/clspv/lib/SOURCES
index 98bc71a869b2a..7c369aa379e98 100644
--- a/libclc/clspv/lib/SOURCES
+++ b/libclc/clspv/lib/SOURCES
@@ -1,5 +1,6 @@
 math/fma.cl
 math/nextafter.cl
+shared/vstore_half.cl
 subnormal_config.cl
 ../../generic/lib/geometric/distance.cl
 ../../generic/lib/geometric/length.cl
@@ -45,6 +46,12 @@ subnormal_config.cl
 ../../generic/lib/math/frexp.cl
 ../../generic/lib/math/half_cos.cl
 ../../generic/lib/math/half_divide.cl
+../../generic/lib/math/half_exp.cl
+../../generic/lib/math/half_exp10.cl
+../../generic/lib/math/half_exp2.cl
+../../generic/lib/math/half_log.cl
+../../generic/lib/math/half_log10.cl
+../../generic/lib/math/half_log2.cl
 ../../generic/lib/math/half_powr.cl
 ../../generic/lib/math/half_recip.cl
 ../../generic/lib/math/half_sin.cl

diff  --git a/libclc/clspv/lib/math/fma.cl b/libclc/clspv/lib/math/fma.cl
index fdc8b8b296876..4f2806933eda9 100644
--- a/libclc/clspv/lib/math/fma.cl
+++ b/libclc/clspv/lib/math/fma.cl
@@ -34,6 +34,92 @@ struct fp {
   uint sign;
 };
 
+static uint2 u2_set(uint hi, uint lo) {
+  uint2 res;
+  res.lo = lo;
+  res.hi = hi;
+  return res;
+}
+
+static uint2 u2_set_u(uint val) { return u2_set(0, val); }
+
+static uint2 u2_mul(uint a, uint b) {
+  uint2 res;
+  res.hi = mul_hi(a, b);
+  res.lo = a * b;
+  return res;
+}
+
+static uint2 u2_sll(uint2 val, uint shift) {
+  if (shift == 0)
+return val;
+  if (shift < 32) {
+val.hi <<= shift;
+val.hi |= val.lo >> (32 - shift);
+val.lo <<= shift;
+  } else {
+val.hi = val.lo << (shift - 32);
+val.lo = 0;
+  }
+  return val;
+}
+
+static uint2 u2_srl(uint2 val, uint shift) {
+  if (shift == 0)
+return val;
+  if (shift < 32) {
+val.lo >>= shift;
+val.lo |= val.hi << (32 - shift);
+val.hi >>= shift;
+  } else {
+val.lo = val.hi >> (shift - 32);
+val.hi = 0;
+  }
+  return val;
+}
+
+static uint2 u2_or(uint2 a, uint b) {
+  a.lo |= b;
+  return a;
+}
+
+static uint2 u2_and(uint2 a, uint2 b) {
+  a.lo &= b.lo;
+  a.hi &= b.hi;
+  return a;
+}
+
+static uint2 u2_add(uint2 a, uint2 b) {
+  uint carry = (hadd(a.lo, b.lo) >> 31) & 0x1;
+  a.lo += b.lo;
+  a.hi += b.hi + carry;
+  return a;
+}
+
+static uint2 u2_add_u(uint2 a, uint b) { return u2_add(a, u2_set_u(b)); }
+
+static uint2 u2_inv(uint2 a) {
+  a.lo = ~a.lo;
+  a.hi = ~a.hi;
+  return u2_add_u(a, 1);
+}
+
+static uint u2_clz(uint2 a) {
+  uint leading_zeroes = clz(a.hi);
+  if (leading_zeroes == 32) {
+leading_zeroes += clz(a.lo);
+  }
+  return leading_zeroes;
+}
+
+static bool u2_eq(uint2 a, uint2 b) { return a.lo == b.lo && a.hi == b.hi; }
+
+static bool u2_zero(uint2 a) { return u2_eq(a, u2_set_u(0)); }
+
+static bool u2_gt(uint2 a, uint2 b) {
+  return a.hi > b.hi || (a.hi == b.hi && a.lo > b.lo);
+}
+
 _CLC_DEF _CLC_OVERLOAD float fma(float a, float b, float c) {
   /* special cases */
   if (isnan(a) || isnan(b) || isnan(c) || isinf(a) || isinf(b)) {
@@ -63,12 +149,9 @@ _CLC_DEF _CLC_OVERLOAD float fma(float a, float b, float c) 
{
   st_b.exponent = b == .0f ? 0 : ((as_uint(b) & 0x7f80) >> 23) - 127;
   st_c.exponent = c == .0f ? 0 : ((as_uint(c) & 0x7f80) >> 23) - 127;
 
-  st_a.mantissa.lo = a == .0f ? 0 : (as_uint(a) & 0x7f) | 0x80;
-  st_b.mantissa.lo = b == .0f ? 0 : (as_uint(b) & 0x7f) | 0x80;
-  st_c.mantissa.lo = c == .0f ? 0 : (as_uint(c

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-09 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 520725.
chaitanyav added a comment.

Rebase with upstream and remove duplicate line from ReleaseNotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = ((actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND);
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i)

[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-05-09 Thread Ritanya via Phabricator via cfe-commits
RitanyaB updated this revision to Diff 520729.

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

https://reviews.llvm.org/D146418

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_messages.cpp
  clang/test/OpenMP/declare_target_variables_ast_print.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp

Index: clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
===
--- clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
+++ clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
@@ -95,7 +95,7 @@
 int (*D)() = C; // expected-note {{used here}}
 // host-note@-1 {{used here}}
 #pragma omp end declare target
-int foobar3() { throw 1; }
+int foobar3() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
 
 // Check no infinite recursion in deferred diagnostic emitter.
 long E = (long)&E;
Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -0,0 +1,111 @@
+// RUN: %clang_cc1 -w -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK
+// expected-no-diagnostics
+
+static int variable = 100; 
+static float variable1 = 200;
+static float variable2 = variable1; 
+
+static int var = 1;
+
+static int var1 = 10;
+static int *var2 = &var1;
+static int **ptr1 = &var2;
+
+int arr[2] = {1,2};
+int (*arrptr)[2] = &arr;
+
+class declare{
+  public: int x;
+  void print();
+};
+declare obj1;
+declare *obj2 = &obj1;
+
+struct target{
+  int x;
+  void print();
+};
+static target S;
+
+#pragma omp declare target
+int target_var = variable;
+float target_var1 = variable2;
+int *ptr = &var;
+int ***ptr2 = &ptr1;
+int (**ptr3)[2] = &arrptr;
+declare **obj3 = &obj2;
+target *S1 = &S;
+#pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int variable = 100;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable1 = 200;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable2 = variable1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int var = 1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var1 = 10;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *var2 = &var1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int **ptr1 = &var2;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int arr[2] = {1, 2};
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (*arrptr)[2] = &arr;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: class declare {
+// CHECK-NEXT: public: 
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare obj1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare *obj2 = &obj1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: struct target {
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static target S;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int target_var = variable;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: float target_var1 = variable2;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int *ptr = &var;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int ***ptr2 = &ptr1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (**ptr3)[2] = &arrptr;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare **obj3 = &obj2; 
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: target *S1 = &S;
+// CHECK-NEXT: #pragma omp end declare target
Index: clang/test/OpenMP/declare_target_messages.cpp
===
--- clang/test/OpenMP/declare_target_messages.cpp
+++ clang/test/OpenMP/declare_target_messages.cpp
@@ -233,6 +233,42 @@
 #pragma omp declar

[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-05-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14473
+  // directive and has static storage duration.
+  if (auto *VD = dyn_cast_or_null(D);
+  LangOpts.OpenMP && VD && VD->hasAttr() &&

В is already checked that is not nullptr, so just a dyn_cast should be enough



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23094-23095
+public:
+  SmallVector DeclVector;
+  Decl *TargetDecl;
+  void VisitDeclRefExpr(const DeclRefExpr *Node) {

Why public?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23098
+Decl *DeclVar = nullptr;
+if (const VarDecl *VD = dyn_cast(Node->getDecl())) {
+  DeclVar = (Decl *)Node->getDecl();

const auto *VD



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23099
+if (const VarDecl *VD = dyn_cast(Node->getDecl())) {
+  DeclVar = (Decl *)Node->getDecl();
+  
DeclVar->addAttr((this->TargetDecl)->getAttr());

Use VD instead of this and drop const



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23100-23101
+  DeclVar = (Decl *)Node->getDecl();
+  
DeclVar->addAttr((this->TargetDecl)->getAttr());
+  (this->DeclVector).push_back(DeclVar);
+}

Drop this and extra parens



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23107-23110
+  if (isa(*it))
+VisitExpr(dyn_cast(*it));
+  if (isa(*it))
+Visit(*it);

Just Visit(*it)?


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

https://reviews.llvm.org/D146418

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


[PATCH] D149872: [OpenMP][OMPIRBuilder] Migrate emitOffloadingArrays and EmitNonContiguousDescriptor from Clang

2023-05-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 520730.
TIFitis added a comment.

Addressed reviewer comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4368,6 +4368,260 @@
 Builder.CreatePointerCast(Info.RTArgs.MappersArray, VoidPtrPtrTy);
 }
 
+void OpenMPIRBuilder::emitNonContiguousDescriptor(InsertPointTy AllocaIP,
+  InsertPointTy CodeGenIP,
+  MapInfosTy &CombinedInfo,
+  TargetDataInfo &Info) {
+  MapInfosTy::StructNonContiguousInfo &NonContigInfo =
+  CombinedInfo.NonContigInfo;
+
+  // Build an array of struct descriptor_dim and then assign it to
+  // offload_args.
+  //
+  // struct descriptor_dim {
+  //  uint64_t offset;
+  //  uint64_t count;
+  //  uint64_t stride
+  // };
+  Type *Int64Ty = Builder.getInt64Ty();
+  StructType *DimTy = StructType::create(
+  M.getContext(), ArrayRef({Int64Ty, Int64Ty, Int64Ty}),
+  "struct.descriptor_dim");
+
+  enum { OffsetFD = 0, CountFD, StrideFD };
+  // We need two index variable here since the size of "Dims" is the same as
+  // the size of Components, however, the size of offset, count, and stride is
+  // equal to the size of base declaration that is non-contiguous.
+  for (unsigned I = 0, L = 0, E = NonContigInfo.Dims.size(); I < E; ++I) {
+// Skip emitting ir if dimension size is 1 since it cannot be
+// non-contiguous.
+if (NonContigInfo.Dims[I] == 1)
+  continue;
+Builder.restoreIP(AllocaIP);
+ArrayType *ArrayTy = ArrayType::get(DimTy, NonContigInfo.Dims[I]);
+AllocaInst *DimsAddr =
+Builder.CreateAlloca(ArrayTy, /* ArraySize = */ nullptr, "dims");
+Builder.restoreIP(CodeGenIP);
+for (unsigned II = 0, EE = NonContigInfo.Dims[I]; II < EE; ++II) {
+  unsigned RevIdx = EE - II - 1;
+  Value *DimsLVal = Builder.CreateInBoundsGEP(
+  DimsAddr->getAllocatedType(), DimsAddr,
+  {Builder.getInt64(0), Builder.getInt64(II)});
+  // Offset
+  Value *OffsetLVal = Builder.CreateStructGEP(DimTy, DimsLVal, OffsetFD);
+  Builder.CreateAlignedStore(
+  NonContigInfo.Offsets[L][RevIdx], OffsetLVal,
+  M.getDataLayout().getPrefTypeAlign(OffsetLVal->getType()));
+  // Count
+  Value *CountLVal = Builder.CreateStructGEP(DimTy, DimsLVal, CountFD);
+  Builder.CreateAlignedStore(
+  NonContigInfo.Counts[L][RevIdx], CountLVal,
+  M.getDataLayout().getPrefTypeAlign(CountLVal->getType()));
+  // Stride
+  Value *StrideLVal = Builder.CreateStructGEP(DimTy, DimsLVal, StrideFD);
+  Builder.CreateAlignedStore(
+  NonContigInfo.Strides[L][RevIdx], StrideLVal,
+  M.getDataLayout().getPrefTypeAlign(CountLVal->getType()));
+}
+// args[I] = &dims
+Builder.restoreIP(CodeGenIP);
+Value *DAddr = Builder.CreatePointerBitCastOrAddrSpaceCast(
+DimsAddr, Builder.getInt8PtrTy());
+Value *P = Builder.CreateConstInBoundsGEP2_32(
+ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs),
+Info.RTArgs.PointersArray, 0, I);
+Builder.CreateAlignedStore(
+DAddr, P, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
+++L;
+  }
+}
+
+void OpenMPIRBuilder::emitOffloadingArrays(
+InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
+TargetDataInfo &Info, bool IsNonContiguous,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
+
+  // Reset the array information.
+  Info.clearArrayInfo();
+  Info.NumberOfPtrs = CombinedInfo.BasePointers.size();
+
+  if (Info.NumberOfPtrs) {
+Builder.restoreIP(AllocaIP);
+// Detect if we have any capture size requiring runtime evaluation of the
+// size so that a constant array could be eventually used.
+ArrayType *PointerArrayType =
+ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs);
+
+Info.RTArgs.BasePointersArray = Builder.CreateAlloca(
+PointerArrayType, /* ArraySize = */ nullptr, ".offload_baseptrs");
+
+Info.RTArgs.PointersArray = Builder.CreateAlloca(
+PointerArrayType, /* ArraySize = */ nullptr, ".offload_ptrs");
+AllocaInst *MappersArray = Builder.CreateAlloca(
+PointerArrayType, /* ArraySize = */ nullptr, ".offload_mappers");
+Info.RTArgs.MappersArray = MappersArray;
+
+// If we don't have any VLA types or other types that require runtime
+// evaluation, we can use a constant array for the map sizes, otherwise we
+ 

[clang-tools-extra] 0d6d8a8 - [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

2023-05-09 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-05-09T16:45:02Z
New Revision: 0d6d8a853a6ea29b5f461a475a8f8eb7e7ba18e2

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

LOG: [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

Some time ago a patch was merged to disable all clang-tidy warnings
from system macros. This led to bugprone-assert-side-effect
silently no longer working, since the warnings came from a system
macro. The problem was not detected because the fake assert functions
were implemented in the same file as the test, instead of being a
system include like it's done in the real world.

Move the assert to a proper system header, and fix the code to
warn at the correct location.

This patch is breakdown from https://reviews.llvm.org/D147081
by PiotrZSL.

Fixes https://github.com/llvm/llvm-project/issues/62314

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h

Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 600a923b211cf..07a987359d4d8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -117,13 +117,13 @@ void AssertSideEffectCheck::check(const 
MatchFinder::MatchResult &Result) {
   StringRef AssertMacroName;
   while (Loc.isValid() && Loc.isMacroID()) {
 StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
+Loc = SM.getImmediateMacroCallerLoc(Loc);
 
 // Check if this macro is an assert.
 if (llvm::is_contained(AssertMacros, MacroName)) {
   AssertMacroName = MacroName;
   break;
 }
-Loc = SM.getImmediateMacroCallerLoc(Loc);
   }
   if (AssertMacroName.empty())
 return;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
new file mode 100644
index 0..904597ff2184e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
@@ -0,0 +1,40 @@
+#pragma clang system_header
+
+int abort();
+
+#ifdef NDEBUG
+#define assert(x) 1
+#else
+#define assert(x)  
\
+  if (!(x))
\
+  (void)abort()
+#endif
+
+void print(...);
+#define assert2(e) (__builtin_expect(!(e), 0) ?
\
+   print (#e, __FILE__, __LINE__) : (void)0)
+
+#ifdef NDEBUG
+#define my_assert(x) 1
+#else
+#define my_assert(x)   
\
+  ((void)((x) ? 1 : abort()))
+#endif
+
+#ifdef NDEBUG
+#define not_my_assert(x) 1
+#else
+#define not_my_assert(x)   
\
+  if (!(x))
\
+  (void)abort()
+#endif
+
+#define real_assert(x) ((void)((x) ? 1 : abort()))
+#define wrap1(x) real_assert(x)
+#define wrap2(x) wrap1(x)
+#define convoluted_assert(x) wrap2(x)
+
+#define msvc_assert(expression) (void)(
\
+(!!(expression)) ||
\
+(abort(), 0)   
\
+)

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
index c327007651d4c..ccafeb4b7f3b1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
@@ -1,47 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- 
-config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, 
value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 
'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: 
bugprone-assert-side-effect.IgnoredFunctions, value: 
'MyClass::badButIgnoredFunc'}]}" -- -fexceptions
-
-//===--- assert definition block 
--===//
-int abort() { return 0; }
-
-#ifdef NDEBUG
-#define assert(x) 1
-#else
-#define assert(x)  
\
-  if (!(x))   

[PATCH] D150071: [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

2023-05-09 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
carlosgalvezp marked 2 inline comments as done.
Closed by commit rG0d6d8a853a6e: [clang-tidy] Fix bugprone-assert-side-effect 
to actually give warnings (authored by carlosgalvezp).

Changed prior to commit:
  https://reviews.llvm.org/D150071?vs=520194&id=520732#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150071

Files:
  clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
@@ -1,47 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- -config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: bugprone-assert-side-effect.IgnoredFunctions, value: 'MyClass::badButIgnoredFunc'}]}" -- -fexceptions
-
-//===--- assert definition block --===//
-int abort() { return 0; }
-
-#ifdef NDEBUG
-#define assert(x) 1
-#else
-#define assert(x)  \
-  if (!(x))\
-  (void)abort()
-#endif
-
-void print(...);
-#define assert2(e) (__builtin_expect(!(e), 0) ?\
-   print (#e, __FILE__, __LINE__) : (void)0)
-
-#ifdef NDEBUG
-#define my_assert(x) 1
-#else
-#define my_assert(x)   \
-  ((void)((x) ? 1 : abort()))
-#endif
-
-#ifdef NDEBUG
-#define not_my_assert(x) 1
-#else
-#define not_my_assert(x)   \
-  if (!(x))\
-  (void)abort()
-#endif
-
-#define real_assert(x) ((void)((x) ? 1 : abort()))
-#define wrap1(x) real_assert(x)
-#define wrap2(x) wrap1(x)
-#define convoluted_assert(x) wrap2(x)
-
-#define msvc_assert(expression) (void)(\
-(!!(expression)) ||\
-(abort(), 0)   \
-)
-
-
-//===--===//
+// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- -config="{CheckOptions: [{key: bugprone-assert-side-effect.CheckFunctionCalls, value: true}, {key: bugprone-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert,msvc_assert'}, {key: bugprone-assert-side-effect.IgnoredFunctions, value: 'MyClass::badButIgnoredFunc'}]}" -- -fexceptions -I %S/Inputs/assert-side-effect
+#include 
 
 bool badButIgnoredFunc(int a, int b) { return a * b > 0; }
 
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/assert-side-effect/assert.h
@@ -0,0 +1,40 @@
+#pragma clang system_header
+
+int abort();
+
+#ifdef NDEBUG
+#define assert(x) 1
+#else
+#define assert(x)  \
+  if (!(x))\
+  (void)abort()
+#endif
+
+void print(...);
+#define assert2(e) (__builtin_expect(!(e), 0) ?\
+   print (#e, __FILE__, __LINE__) : (void)0)
+
+#ifdef NDEBUG
+#define my_assert(x) 1
+#else
+#define my_assert(x)   \
+  ((void)((x) ? 1 : abort()))
+#endif
+
+#ifdef NDEBUG
+#define not_my_assert(x) 1
+#else
+#define not_my_assert(x)   \
+  if (!(x))\
+  (void)abort()
+#endif
+
+#define real_assert(x) ((void)((x) ? 1 : abort()))
+#define wrap1(x) real_assert(x)
+#define wrap2(x) wrap1(x)
+#define convoluted_assert(x) wrap2(x)
+
+#define msvc_assert(expression) (void)(\
+(!!(expression)) ||\
+(abort(), 0)   \
+)
Index: clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
=

[PATCH] D150071: [clang-tidy] Fix bugprone-assert-side-effect to actually give warnings

2023-05-09 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Thanks for the review! Fixed your comments before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150071

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


[PATCH] D150122: [Clang] Fix status of P0960

2023-05-09 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D150122#4329401 , @aaron.ballman 
wrote:

> I believe we are having another release of Clang 16, but @tstellar can 
> confirm or deny that.
>
> AIUI, there were a few issues holding us back from claiming complete support 
> (added @ayzhao as a reviewer in case he has a different opinion):
> https://github.com/llvm/llvm-project/issues/61145  (backported to 16.x)
> https://github.com/llvm/llvm-project/issues/62296  (backported to 16.x)
> https://github.com/llvm/llvm-project/issues/62266  (not backported)
> https://github.com/llvm/llvm-project/issues/61567  (not backported)
>
> If we backport the two other issues to 16, then I think the changes in this 
> review are fine. If we don't backport those two, I think we should claim 
> Clang 17 to be conservative.

I started the backporting process for the remaining 2 bugs. I'm doing 
https://github.com/llvm/llvm-project/issues/62266 first before doing 
https://github.com/llvm/llvm-project/issues/61567 because otherwise there will 
be a merge issue. Once those two commits are backported then this patch LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-09 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks reopened this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

the following crashes with this patch:

  struct StringRef {
StringRef(const char *);
  };
  template 
  StringRef getTypeName() {
StringRef s = __func__;
  }

`clang -cc1 -fms-extensions -std=c++17 -x c++ a.cpp -fsyntax-only`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[clang] ee8ed0b - [clang][deps] Teach dep directive scanner about _Pragma

2023-05-09 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2023-05-09T10:05:12-07:00
New Revision: ee8ed0b3099e63ba0a18cca42b9cfdf098bc6201

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

LOG: [clang][deps] Teach dep directive scanner about _Pragma

While we cannot handle `_Pragma` used inside macros, we can handle
this at the top level, and it some projects use the `_Pragma("once")`
spelling like that, which was causing spurious failures in the scanner.

Limitations
* Cannot handle #define ONCE _Pragma("once"), same issue as using
  @import in a macro -- ideally we should diagnose this in obvious cases
* Our LangOpts are currently fixed, so we are not handling u"" strings
  or R"()" strings that require C11/C++11.

rdar://108629982

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

Added: 
clang/test/ClangScanDeps/_Pragma-once.c

Modified: 
clang/include/clang/Lex/Pragma.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/Pragma.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Pragma.h 
b/clang/include/clang/Lex/Pragma.h
index cf8cca5414eac..67eca618f6c4f 100644
--- a/clang/include/clang/Lex/Pragma.h
+++ b/clang/include/clang/Lex/Pragma.h
@@ -123,6 +123,13 @@ class PragmaNamespace : public PragmaHandler {
   PragmaNamespace *getIfNamespace() override { return this; }
 };
 
+/// Destringize a \c _Pragma("") string according to C11 6.10.9.1:
+/// "The string literal is destringized by deleting any encoding prefix,
+/// deleting the leading and trailing double-quotes, replacing each escape
+/// sequence \" by a double-quote, and replacing each escape sequence \\ by a
+/// single backslash."
+void prepare_PragmaString(SmallVectorImpl &StrVal);
+
 } // namespace clang
 
 #endif // LLVM_CLANG_LEX_PRAGMA_H

diff  --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index a506b49176302..2bd2c5f8388c0 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Pragma.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
@@ -72,6 +73,8 @@ struct Scanner {
 // Set the lexer to use 'tok::at' for '@', instead of 'tok::unknown'.
 LangOpts.ObjC = true;
 LangOpts.LineComment = true;
+// FIXME: we do not enable C11 or C++11, so we are missing u/u8/U"" and
+// R"()" literals.
 return LangOpts;
   }
 
@@ -91,6 +94,10 @@ struct Scanner {
   void skipLine(const char *&First, const char *const End);
   void skipDirective(StringRef Name, const char *&First, const char *const 
End);
 
+  /// Returns the spelling of a string literal or identifier after performing
+  /// any processing needed to handle \c clang::Token::NeedsCleaning.
+  StringRef cleanStringIfNeeded(const dependency_directives_scan::Token &Tok);
+
   /// Lexes next token and if it is identifier returns its string, otherwise
   /// it skips the current line and returns \p std::nullopt.
   ///
@@ -112,6 +119,22 @@ struct Scanner {
 const char *&First,
 const char *const End);
 
+  /// Lexes next token and returns true iff it matches the kind \p K.
+  /// Otherwise it skips the current line and returns false.
+  ///
+  /// In any case (whatever the token kind) \p First and the \p Lexer will
+  /// advance beyond the token.
+  [[nodiscard]] bool isNextTokenOrSkipLine(tok::TokenKind K, const char 
*&First,
+   const char *const End);
+
+  /// Lexes next token and if it is string literal, returns its string.
+  /// Otherwise, it skips the current line and returns \p std::nullopt.
+  ///
+  /// In any case (whatever the token kind) \p First and the \p Lexer will
+  /// advance beyond the token.
+  [[nodiscard]] std::optional
+  tryLexStringLiteralOrSkipLine(const char *&First, const char *const End);
+
   [[nodiscard]] bool scanImpl(const char *First, const char *const End);
   [[nodiscard]] bool lexPPLine(const char *&First, const char *const End);
   [[nodiscard]] bool lexAt(const char *&First, const char *const End);
@@ -119,6 +142,7 @@ struct Scanner {
   [[nodiscard]] bool lexDefine(const char *HashLoc, const char *&First,
const char *const End);
   [[nodiscard]] bool lexPragma(const char *&First, const char *const End);
+  [[nodiscard]] bool lex_Pragma(const char *&First, const char *const End);
   [[nodiscard]] bool lexEndif(const char *&First, const char *const End);
   [[nodiscard]] bool lexDef

[PATCH] D150001: [clang] Fix initializer_list matching failures with modules

2023-05-09 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 520744.
ayzhao added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150001

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Modules/match_initializer_list.cpp


Index: clang/test/Modules/match_initializer_list.cpp
===
--- /dev/null
+++ clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.


Index: clang/test/Modules/match_initializer_list.cpp
===
--- /dev/null
+++ clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149884: [clang][deps] Teach dep directive scanner about _Pragma

2023-05-09 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee8ed0b3099e: [clang][deps] Teach dep directive scanner 
about _Pragma (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149884

Files:
  clang/include/clang/Lex/Pragma.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/ClangScanDeps/_Pragma-once.c
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -503,6 +503,92 @@
   EXPECT_STREQ("#pragma clang module import\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, UnderscorePragma) {
+  SmallVector Out;
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_)", Out));
+  EXPECT_STREQ("\n", Out.data());
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_Pragma)", Out));
+  EXPECT_STREQ("\n", Out.data());
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_Pragma()", Out));
+  EXPECT_STREQ("\n", Out.data());
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_Pragma())", Out));
+  EXPECT_STREQ("\n", Out.data());
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_Pragma(")", Out));
+  EXPECT_STREQ("\n", Out.data());
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(R"(_Pragma("A"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"x(_Pragma("push_macro(\"MACRO\")"))x", Out));
+  EXPECT_STREQ(R"x(_Pragma("push_macro(\"MACRO\")"))x"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"x(_Pragma("pop_macro(\"MACRO\")"))x", Out));
+  EXPECT_STREQ(R"x(_Pragma("pop_macro(\"MACRO\")"))x"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"x(_Pragma("include_alias(\"A\", \"B\")"))x", Out));
+  EXPECT_STREQ(R"x(_Pragma("include_alias(\"A\", \"B\")"))x"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"x(_Pragma("include_alias(, )"))x", Out));
+  EXPECT_STREQ(R"x(_Pragma("include_alias(, )"))x"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives(R"(_Pragma("clang"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives(R"(_Pragma("clang module"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma("clang module impor"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma("clang module import"))", Out));
+  EXPECT_STREQ(R"(_Pragma("clang module import"))"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma("clang \
+  module \
+  import"))",
+  Out));
+  EXPECT_STREQ(R"(_Pragma("clang \
+  module \
+  import"))"
+   "\n",
+   Out.data());
+
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma(L"clang module import"))", Out));
+  EXPECT_STREQ(R"(_Pragma(L"clang module import"))"
+   "\n",
+   Out.data());
+
+  // FIXME: u"" strings depend on using C11 language mode
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma(u"clang module import"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+
+  // FIXME: R"()" strings depend on using C++ 11 language mode
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(
+  R"(_Pragma(R"abc(clang module import)abc"))", Out));
+  EXPECT_STREQ("\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Include) {
   SmallVector Out;
 
@@ -757,20 +843,26 @@
 #pragma once
 // another comment
 #include 
+_Pragma("once")
 )";
   ASSERT_FALSE(
   minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives));
-  EXPECT_STREQ("#pragma once\n#include \n", Out.data());
-  ASSERT_EQ(Directives.size(), 3u);
+  EXPECT_STREQ("#pragma once\n#include \n_Pragma(\"once\")\n",
+   Out.data());
+  ASSERT_EQ(Directives.size(), 4u);
   EXPECT_EQ(Directives[0].Kind, dependency_directives_scan::pp_pragma_once);
+  EXPECT_EQ(Directives[2].Kind, dependency_directives_scan::pp_pragma_once);
 
   Source = R"(// comment
 #pragma once extra tokens
 // another comment
 #include 
+_Pragma("once") extra tokens
 )";
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
-  EXPECT_STREQ("#pragma once extra tokens\n#include \n", Out.data());
+  EXPECT_STREQ("#pragma once extra tokens\n#include "
+   "\n_P

[clang] d1d35f0 - [clang] Fix initializer_list matching failures with modules

2023-05-09 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-09T10:31:43-07:00
New Revision: d1d35f04c6cb2e3d5b0fbc6101d5425a33f8fc63

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

LOG: [clang] Fix initializer_list matching failures with modules

Previously, if a class with a defined public virtual destructor is
declared before including  and initializer_list is
provided via a Clang module, then overload resolution would fail for
std::initializer_list. This is because when Clang sees the virtual
destructor, Clang creates an implicit NamespaceDecl for std to
implicitly declare a std::bad_alloc. That NamespaceDecl is not added to
the translation unit's lookup table, so when the module containing
std::initializer_list is imported later, that module's std NamespaceDecl
can't find the previous std NamespaceDecl during redeclaration lookup,
causing overload resolution to fail.

To fix this, implicitly created std NamespaceDecls are now added to the
lookup map. At the same time, their IdentifierNamespace members are
cleared to prevent regular name lookups from finding it.

Fixes 60929

Reviewed By: ChuanqiXu, #clang-language-wg, inclyc

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

Added: 
clang/test/Modules/match_initializer_list.cpp

Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e86eadab0a8a4..be76d1648b9ac 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@ class alignas(8) Decl {
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4efa1b408607d..e68afaa61ef1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@ NamespaceDecl *Sema::getOrCreateStdNamespace() {
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();

diff  --git a/clang/test/Modules/match_initializer_list.cpp 
b/clang/test/Modules/match_initializer_list.cpp
new file mode 100644
index 0..31e2b015a9d05
--- /dev/null
+++ b/clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }



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


[PATCH] D150001: [clang] Fix initializer_list matching failures with modules

2023-05-09 Thread Alan Zhao 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 rGd1d35f04c6cb: [clang] Fix initializer_list matching failures 
with modules (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150001

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Modules/match_initializer_list.cpp


Index: clang/test/Modules/match_initializer_list.cpp
===
--- /dev/null
+++ clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.


Index: clang/test/Modules/match_initializer_list.cpp
===
--- /dev/null
+++ clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150013: [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:546
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  Args.AddAllArgs(CmdArgs, options::OPT_L);

jhuber6 wrote:
> yaxunl wrote:
> > jhuber6 wrote:
> > > yaxunl wrote:
> > > > AddLinkerInputs has code doing that, and it handles env var 
> > > > LIBRARY_PATH. However that code is disabled for AMDGPU because AMDGPU 
> > > > returns true for isCrossCompiling.
> > > > 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp#L236
> > > > 
> > > > It seems isCrossCompiling is solely for controlling whether to consume 
> > > > `-L`. If we want amdgpu toolchain to accept `-L`, we can simply let 
> > > > isCrossCompiling return false.
> > > Good catch, we could maybe set `isCrossCompiling` to false if targeted 
> > > directly by the user, e.g. `--target=amdgcn-amd-amdhsa` vs 
> > > `--offload-arch`.
> > That would be better. Thanks.
> It still is technically cross compiling, since we are building for a target 
> that does not match the system's architecture. The original code that 
> prevents passing `-L` was contributed by @MaskRay. I understand that we may 
> not want to pass `LIBRARY_PATH` defines, but what's the rationale for not 
> passing any `-L` options manually specified by the user?
The `LIBRARY_PATH` code had been there when I moved it in 2019. It'd be best 
not to rely on `LIBRARY_PATH`. I think that forwarding `-L` seems reasonable 
but I am not familiar with the amdgpu ecosystem..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150013

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


[PATCH] D150013: [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:546
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  Args.AddAllArgs(CmdArgs, options::OPT_L);

MaskRay wrote:
> jhuber6 wrote:
> > yaxunl wrote:
> > > jhuber6 wrote:
> > > > yaxunl wrote:
> > > > > AddLinkerInputs has code doing that, and it handles env var 
> > > > > LIBRARY_PATH. However that code is disabled for AMDGPU because AMDGPU 
> > > > > returns true for isCrossCompiling.
> > > > > 
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp#L236
> > > > > 
> > > > > It seems isCrossCompiling is solely for controlling whether to 
> > > > > consume `-L`. If we want amdgpu toolchain to accept `-L`, we can 
> > > > > simply let isCrossCompiling return false.
> > > > Good catch, we could maybe set `isCrossCompiling` to false if targeted 
> > > > directly by the user, e.g. `--target=amdgcn-amd-amdhsa` vs 
> > > > `--offload-arch`.
> > > That would be better. Thanks.
> > It still is technically cross compiling, since we are building for a target 
> > that does not match the system's architecture. The original code that 
> > prevents passing `-L` was contributed by @MaskRay. I understand that we may 
> > not want to pass `LIBRARY_PATH` defines, but what's the rationale for not 
> > passing any `-L` options manually specified by the user?
> The `LIBRARY_PATH` code had been there when I moved it in 2019. It'd be best 
> not to rely on `LIBRARY_PATH`. I think that forwarding `-L` seems reasonable 
> but I am not familiar with the amdgpu ecosystem..
The linker is just `lld` so it should be the same conceptually. I'm just 
figuring that even if the user is cross compiling we should respect `-L` passed 
on the command line. Should I change this patch to make that change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150013

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


[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150209

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,14 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant 
expression}} \
+// ref-cxx17-error {{never produces a constant 
expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -125,6 +126,16 @@
 QualType Ty = E->getType();
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
+  } else if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+// C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+// E1 x 2^E2 module 2^N.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << 12;
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
   }
   return true;
 }
@@ -1612,7 +1623,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1629,7 +1640,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { return llvm::countl_zero(V); }
+  unsigned countLeadingZeros() const {
+if constexpr (!Signed)
+  return llvm::countl_zero(V);
+llvm_unreachable("Don't call countLeadingZeros() on signed types.");
+  }
 
   Integral truncate(unsigned TruncBits) const {
 if (TruncBits >= Bits)


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,14 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant expression}} \
+// ref-cxx17-error {{never produces a constant expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, C

[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2023-05-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the continued work on this! In general, I think the test coverage 
should verify the deduced type information more often. e.g., if we accept the 
code, there should probably be a `static_assert` nearby that ensures the 
deduced type is what we'd expect.

I applied the patch locally and tried out various things, and here's some test 
coverage I think we're lacking.

  // Important: these two declarations are at file scope, we're testing that 
the storage
  // class specifier is ignored because we're deducing the type.
  auto i = 12; // Ok, deduces int
  auto j = 12ull; // Ok, deduces unsigned long long
  
  // This is testing whether storage specifier order matters:
  void func() {
const auto static i = 12; // Ok, static variable of type const int
  }



In D133289#4279054 , @to268 wrote:

> I have *hopefully* fixed my broken patch.
> This is all the things in need to address:
>
>   auto str2[] = "string";
>   [[clang::overloadable]] auto test(auto x) { return x; }
>
> and maybe retry to support `auto` in compound literals,
> becaue i have seen heavy macro users that want compound literals to work.
>
> I think it's safe to say that we will not support all features from N3076 
>  in this patch.

My testing of your patch suggests those aren't issues left to address 
(perhaps). e.g.,

  auto test[] = "foo";
  static_assert(_Generic(test, char * : 1, default : 0));

this matches what I'd expect (no warning, no failed assertion; string literals 
have type `char []` in C, not `const char[]`.

My testing of `__attribute__((overloadable))` with your patch is that we 
currently reject use of `auto` in those functions. I think that's good initial 
behavior -- if we want to allow `auto` there, that's probably better left to a 
follow-up patch anyway because I'd expect there to be some debate around 
whether that's a good idea or not.

As for compound literals, I think we've determined they're not supported by C 
currently.




Comment at: clang/test/C/C2x/n3007.c:20
+void test_atomic(void) {
+  _Atomic auto i = 12;  // expected-error {{_Atomic cannot be applied to type 
'auto' which is not trivially copyable}}
+  _Atomic(auto) j = 12; // expected-error {{'auto' not allowed here}} \

This diagnostic is incorrect -- I believe this code should be accepted.



Comment at: clang/test/C/C2x/n3007.c:21
+  _Atomic auto i = 12;  // expected-error {{_Atomic cannot be applied to type 
'auto' which is not trivially copyable}}
+  _Atomic(auto) j = 12; // expected-error {{'auto' not allowed here}} \
+   expected-error {{a type specifier is required for 
all declarations}}

This diagnostic is correct.



Comment at: clang/test/C/C2x/n3007.c:31-32
+  double A[3] = { 0 };
+  auto pA = A;
+  auto qA = &A;
+  auto pi = 3.14;

We should test that the types match our expectations:
```
double A[3] = { 0 };
auto pA = A; // pA is double * due to array decay on A
static_assert(_Generic(pA, double * : 1, default : 0));
auto qA = &A; // qA is double (*)[3]
static_assert(_Generic(qA, double (*)[3] : 1, default : 0));
```



Comment at: clang/test/C/C2x/n3007.c:46
+  auto auto_size = sizeof(auto);  // expected-error {{expected expression}}
+  _Alignas(auto) auto b[4];   // expected-error {{declaration of variable 
'b' with deduced type 'auto[4]' requires an initializer}} \
+ expected-error {{expected expression}}

I think this would make it more clear that what's being tested is the 
`_Alignas` behavior.



Comment at: clang/test/C/C2x/n3007.c:56-57
+void test_initializer_list(void) {
+  // FIXME: as mentioned in N3076, it seems that intializer list are allowed
+  // even with an initializer list containing one item
+  auto a = {};// expected-error {{cannot use 'auto' with 
initializer list in C}}

This should now be resolved in N3096  so the FIXME comment can be removed.



Comment at: clang/test/C/C2x/n3007.c:66
+void test_structs(void) {
+  auto a = (struct { int a; } *)0;
+  struct B { auto b; };   // expected-error {{'auto' not allowed in struct 
member}}

This is awfully close to the examples from the paper (6.7.9p3):
```
auto p1 = (struct { int a; } *)0; // error expected

struct s;
auto p2 = (struct s { int a; } *)0; // error expected
```
They are expected to be diagnosed due to changes in N3006 (underspecified 
object definitions), so I think it's fine to add a FIXME comment with the test 
cases instead of trying to also implement N3006 at the same time. We currently 
list that as `unknown` in our status page, but I think it's clearly a `no` now.



Comment at: clang/test/C/C2x/n3007.c:100
+  auto d = 

[PATCH] D150212: [clang][Sema] Improve diagnostics for auto return type

2023-05-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall, rsmith.
Herald added a project: All.
yaxunl requested review of this revision.

Currently when clang fails to deduce auto return type of a function,
it does not emit any notes about why it fails. This causes difficulty
for users to fix such errors.

Actually, clang already generates the information for emitting notes
about the failed deduction. There is a TODO for actually emitting
them.

This patch tries to implement the TODO. Basically it passes the
failed template specialization candidate set from the point of
specialization failure back to the point where the deduction starts.

It is not comprehensive but would be a start for further improvement.


https://reviews.llvm.org/D150212

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/auto-type-from-cxx.cpp

Index: clang/test/SemaCXX/auto-type-from-cxx.cpp
===
--- clang/test/SemaCXX/auto-type-from-cxx.cpp
+++ clang/test/SemaCXX/auto-type-from-cxx.cpp
@@ -18,3 +18,28 @@
   new __auto_type; // expected-error {{'__auto_type' not allowed in type allocated by 'new'}}
 }
 
+namespace TestDeductionFail {
+
+template
+void caller(T x) {x.fun();} // expected-note {{candidate template ignored: substitution failure [with T = TestDeductionFail::Abstract]: parameter type 'TestDeductionFail::Abstract' is an abstract class}}
+
+template
+auto getCaller(){
+  return caller; // expected-error {{cannot deduce return type 'auto' from returned value of type ''}}
+}
+
+class Abstract{
+  public:
+void fun();
+virtual void vfun()=0;
+void call(){getCaller()(*this);} // expected-note {{in instantiation of function template specialization 'TestDeductionFail::getCaller' requested here}}
+};
+
+class Derived: public Abstract{
+  public:
+void vfun();
+};
+
+Derived X;
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3748,7 +3748,8 @@
 static QualType
 ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams,
 Expr *Arg, QualType ParamType,
-bool ParamWasReference) {
+bool ParamWasReference,
+TemplateSpecCandidateSet *FailedTSC = nullptr) {
 
   OverloadExpr::FindResult R = OverloadExpr::find(Arg);
 
@@ -3770,8 +3771,10 @@
   !ParamType->isMemberFunctionPointerType()) {
 if (Ovl->hasExplicitTemplateArgs()) {
   // But we can still look for an explicit specialization.
-  if (FunctionDecl *ExplicitSpec
-= S.ResolveSingleFunctionTemplateSpecialization(Ovl))
+  if (FunctionDecl *ExplicitSpec =
+  S.ResolveSingleFunctionTemplateSpecialization(
+  Ovl, /*Complain=*/false,
+  /*FoundDeclAccessPair=*/nullptr, FailedTSC))
 return GetTypeOfFunction(S, R, ExplicitSpec);
 }
 
@@ -3853,7 +3856,8 @@
 /// overloaded function set that could not be resolved.
 static bool AdjustFunctionParmAndArgTypesForDeduction(
 Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
-QualType &ParamType, QualType &ArgType, Expr *Arg, unsigned &TDF) {
+QualType &ParamType, QualType &ArgType, Expr *Arg, unsigned &TDF,
+TemplateSpecCandidateSet *FailedTSC = nullptr) {
   // C++0x [temp.deduct.call]p3:
   //   If P is a cv-qualified type, the top level cv-qualifiers of P's type
   //   are ignored for type deduction.
@@ -3870,9 +3874,8 @@
   // but there are sometimes special circumstances.  Typically
   // involving a template-id-expr.
   if (ArgType == S.Context.OverloadTy) {
-ArgType = ResolveOverloadForDeduction(S, TemplateParams,
-  Arg, ParamType,
-  ParamRefType != nullptr);
+ArgType = ResolveOverloadForDeduction(S, TemplateParams, Arg, ParamType,
+  ParamRefType != nullptr, FailedTSC);
 if (ArgType.isNull())
   return true;
   }
@@ -3950,7 +3953,8 @@
 QualType ParamType, Expr *Arg, TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced,
 SmallVectorImpl &OriginalCallArgs,
-bool DecomposedParam, unsigned ArgIdx, unsigned TDF);
+bool DecomposedParam, unsigned ArgIdx, unsigned TDF,
+TemplateSpecCandidateSet *FailedTSC = nullptr);
 
 /// Attempt template argument deduction from an initializer list
 ///deemed to be an argument in a function call.
@@ -4026,14 +4030,16 @@
 QualType ParamType, Expr *Arg, TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced,
 SmallVectorImpl &OriginalCallArgs,
-bool DecomposedParam, 

[PATCH] D150192: Allow clang to emit inrange metadata when generating code for array subscripts

2023-05-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

From what I recall, "inrange" is actually more restrictive than the normal 
C/C++ array indexing rules.  Specifically, the bits regarding comparisons. 
"inrange" was designed to allow splitting globals indexed using inrange.

That isn't to say that functionality like this isn't useful, but we probably 
need to call it something different.  And I'm not sure an attribute on a GEP is 
actually the best way to represent the semantics. It might make sense to use a 
separate intrinsic to represent this, especially given the direction of 
https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150192

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


[clang] 6db007a - [Clang][Sema] Fix comparison of constraint expressions

2023-05-09 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2023-05-09T18:14:39Z
New Revision: 6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b

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

LOG: [Clang][Sema] Fix comparison of constraint expressions

This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.
This is a recommit of 3a54022934.

Differential revision: https://reviews.llvm.org/D146178

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/concepts-friends.cpp
clang/test/SemaTemplate/concepts-out-of-line-def.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 3677335fa176f..7cd505218f2b9 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -2309,9 +2309,15 @@ class ClassTemplateDecl : public 
RedeclarableTemplateDecl {
 return static_cast(RedeclarableTemplateDecl::getCommonPtr());
   }
 
+  void setCommonPtr(Common *C) {
+RedeclarableTemplateDecl::Common = C;
+  }
+
 public:
+
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
+  friend class TemplateDeclInstantiator;
 
   /// Load any lazily-loaded specializations from the external source.
   void LoadLazySpecializations() const;

diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 48e8b78311e12..1de2cc6917b42 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -232,9 +232,21 @@ enum class TemplateSubstitutionKind : char {
 /// Replaces the current 'innermost' level with the provided argument list.
 /// This is useful for type deduction cases where we need to get the entire
 /// list from the AST, but then add the deduced innermost list.
-void replaceInnermostTemplateArguments(ArgList Args) {
-  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty 
list?");
-  TemplateArgumentLists[0].Args = Args;
+void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) 
{
+  assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
+ "Replacing in an empty list?");
+
+  if (!TemplateArgumentLists.empty()) {
+assert((TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ||
+TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ==
+AssociatedDecl) &&
+   "Trying to change incorrect declaration?");
+TemplateArgumentLists[0].Args = Args;
+  } else {
+--NumRetainedOuterLevels;
+TemplateArgumentLists.push_back(
+{{AssociatedDecl, /*Final=*/false}, Args});
+  }
 }
 
 /// Add an outermost level that we are not substituting. We have no

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 7aa06b615fec2..1126c2c517fe4 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -722,7 +722,7 @@ CalculateTemplateDepthForConstraints(Sema &S, const 
NamedDecl *ND,
   ND, /*Final=*/false, /*Innermost=*/nullptr, /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr,
   /*ForConstraintInstantiation=*/true, SkipForSpecialization);
-  return MLTAL.getNumSubstitutedLevels();
+  return MLTAL.getNumLevels();
 }
 
 namespace {
@@ -753,27 +753,44 @@ namespace {
   };
 } // namespace
 
+static const Expr *SubstituteConstraintExpression(Sema &S, const NamedDecl *ND,
+  const Expr *ConstrExpr) {
+  MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
+  ND, /*Final=*/false, /*Innermost=*/nullptr,
+  /*RelativeToPrimary=*/true,
+  /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
+  /*SkipForSpecialization*/ false);
+  if (MLTAL.getNumSubstitutedLevels() == 0)
+return ConstrExpr;
+
+  Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+  std::optional ThisScope;
+  if (auto *RD = dyn_cast(ND->getDeclContext()))
+ThisScope.emplace(S, const_cast(RD), Qualifiers());
+  ExprResult SubstConstr =
+  S.SubstConstraintExpr(const_cast(ConstrExpr), MLTAL);
+  if (SFINAE.hasErrorOccurred() || !SubstConstr.isUsable())
+return nullptr;
+  return SubstConstr.get();
+}
+
 bool Sema::AreConstraintExpressionsEqual(co

[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-09 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added a comment.

In D149986#4329302 , @arsenm wrote:

> Should this be a feature set by default in the subtarget constructor instead? 
> Should you be able to turn this off?

Users should not be able to turn this off. If user wants it off, user can use 
gfx942. Should it be moved to the subtarget constructor?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149986

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


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520772.
barannikov88 retitled this revision from "[clang][CodeGen] Break up 
TargetInfo.cpp [7/7]" to "[clang][CodeGen] Break up TargetInfo.cpp [8/8]".
barannikov88 edited the summary of this revision.
barannikov88 added a comment.

Rebase on top of the commit that introduced factory functions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/XCore.cpp

Index: clang/lib/CodeGen/Targets/XCore.cpp
===
--- clang/lib/CodeGen/Targets/XCore.cpp
+++ clang/lib/CodeGen/Targets/XCore.cpp
@@ -77,7 +77,7 @@
 ///   been exited too soon for the encoding to be correct for the member.
 ///
 class TypeStringCache {
-  enum Status {NonRecursive, Recursive, Incomplete, IncompleteUsed};
+  enum Status { NonRecursive, Recursive, Incomplete, IncompleteUsed };
   struct Entry {
 std::string Str; // The encoded TypeString for the type.
 enum Status State;   // Information about the encoding in 'Str'.
@@ -91,8 +91,7 @@
   TypeStringCache() : IncompleteCount(0), IncompleteUsedCount(0) {}
   void addIncomplete(const IdentifierInfo *ID, std::string StubEnc);
   bool removeIncomplete(const IdentifierInfo *ID);
-  void addIfComplete(const IdentifierInfo *ID, StringRef Str,
- bool IsRecursive);
+  void addIfComplete(const IdentifierInfo *ID, StringRef Str, bool IsRecursive);
   StringRef lookupStr(const IdentifierInfo *ID);
 };
 
@@ -101,11 +100,13 @@
 class FieldEncoding {
   bool HasName;
   std::string Enc;
+
 public:
   FieldEncoding(bool b, SmallStringEnc &e) : HasName(b), Enc(e.c_str()) {}
   StringRef str() { return Enc; }
   bool operator<(const FieldEncoding &rhs) const {
-if (HasName != rhs.HasName) return HasName;
+if (HasName != rhs.HasName)
+  return HasName;
 return Enc < rhs.Enc;
   }
 };
@@ -196,7 +197,7 @@
   if (!ID)
 return;
   Entry &E = Map[ID];
-  assert( (E.Str.empty() || E.State == Recursive) &&
+  assert((E.Str.empty() || E.State == Recursive) &&
  "Incorrectly use of addIncomplete");
   assert(!StubEnc.empty() && "Passing an empty string to addIncomplete()");
   E.Swapped.swap(E.Str); // swap out the Recursive
@@ -215,8 +216,7 @@
   auto I = Map.find(ID);
   assert(I != Map.end() && "Entry not present");
   Entry &E = I->second;
-  assert( (E.State == Incomplete ||
-   E.State == IncompleteUsed) &&
+  assert((E.State == Incomplete || E.State == IncompleteUsed) &&
  "Entry must be an incomplete type");
   bool IsRecursive = false;
   if (E.State == IncompleteUsed) {
@@ -244,7 +244,7 @@
 return; // No key or it is an incomplete sub-type so don't add.
   Entry &E = Map[ID];
   if (IsRecursive && !E.Str.empty()) {
-assert(E.State==Recursive && E.Str.size() == Str.size() &&
+assert(E.State == Recursive && E.Str.size() == Str.size() &&
"This is not the same Recursive entry");
 // The parent container was not recursive after all, so we could have used
 // this Recursive sub-member entry after all, but we assumed the worse when
@@ -253,7 +253,7 @@
   }
   assert(E.Str.empty() && "Entry already present");
   E.Str = Str.str();
-  E.State = IsRecursive? Recursive : NonRecursive;
+  E.State = IsRecursive ? Recursive : NonRecursive;
 }
 
 /// Return a cached TypeString encoding for the ID. If there isn't one, or we
@@ -261,13 +261,13 @@
 /// encoding is Recursive, return an empty StringRef.
 StringRef TypeStringCache::lookupStr(const IdentifierInfo *ID) {
   if (!ID)
-return StringRef();   // We have no key.
+return StringRef(); // We have no key.
   auto I = Map.find(ID);
   if (I == Map.end())
-return StringRef();   // We have no encoding.
+return StringRef(); // We have no encoding.
   Entry &E = I->second;
   if (E.State == Recursive && IncompleteCount)
-return StringRef();   // We don't use Recursive encodings for member types.
+return StringRef(); // We don't use Recursive encodings for member types.
 
   if (E.State == Incomplete) {
 // The incomplete type is being used to 

[PATCH] D150215: [clang][CodeGen] Break up TargetInfo.cpp [7/8]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added subscribers: s.egerton, simoncook, asb, fedor.sergeev, dschuff.
Herald added a project: All.
barannikov88 published this revision for review.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane, jdoerfert, 
efriedma.
Herald added subscribers: cfe-commits, pcwang-thead, aheejin.
Herald added a project: clang.

Wrap calls to XXXTargetCodeGenInfo constructors into factory functions.
This allows moving implementations of TargetCodeGenInfo to dedicated cpp
files without a change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150215

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h

Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -405,6 +405,150 @@
  CodeGen::CodeGenModule &CGM) const;
 };
 
+std::unique_ptr
+createDefaultTargetCodeGenInfo(CodeGenModule &CGM);
+
+enum class AArch64ABIKind {
+  AAPCS = 0,
+  DarwinPCS,
+  Win64,
+};
+
+std::unique_ptr
+createAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind Kind);
+
+std::unique_ptr
+createWindowsAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind K);
+
+std::unique_ptr
+createAMDGPUTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createARCTargetCodeGenInfo(CodeGenModule &CGM);
+
+enum class ARMABIKind {
+  APCS = 0,
+  AAPCS = 1,
+  AAPCS_VFP = 2,
+  AAPCS16_VFP = 3,
+};
+
+std::unique_ptr
+createARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind Kind);
+
+std::unique_ptr
+createWindowsARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind K);
+
+std::unique_ptr
+createAVRTargetCodeGenInfo(CodeGenModule &CGM, unsigned NPR, unsigned NRR);
+
+std::unique_ptr
+createBPFTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createCSKYTargetCodeGenInfo(CodeGenModule &CGM, unsigned FLen);
+
+std::unique_ptr
+createHexagonTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createLanaiTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createLoongArchTargetCodeGenInfo(CodeGenModule &CGM, unsigned GRLen,
+ unsigned FLen);
+
+std::unique_ptr
+createM68kTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createMIPSTargetCodeGenInfo(CodeGenModule &CGM, bool IsOS32);
+
+std::unique_ptr
+createMSP430TargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createNVPTXTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createPNaClTargetCodeGenInfo(CodeGenModule &CGM);
+
+enum class PPC64_SVR4_ABIKind {
+  ELFv1 = 0,
+  ELFv2,
+};
+
+std::unique_ptr
+createAIXTargetCodeGenInfo(CodeGenModule &CGM, bool Is64Bit);
+
+std::unique_ptr
+createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI);
+
+std::unique_ptr
+createPPC64TargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createPPC64_SVR4_TargetCodeGenInfo(CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind,
+   bool SoftFloatABI);
+
+std::unique_ptr
+createRISCVTargetCodeGenInfo(CodeGenModule &CGM, unsigned XLen, unsigned FLen);
+
+std::unique_ptr
+createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createSPIRVTargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createSparcV8TargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createSparcV9TargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector,
+   bool SoftFloatABI);
+
+std::unique_ptr
+createTCETargetCodeGenInfo(CodeGenModule &CGM);
+
+std::unique_ptr
+createVETargetCodeGenInfo(CodeGenModule &CGM);
+
+enum class WebAssemblyABIKind {
+  MVP = 0,
+  ExperimentalMV = 1,
+};
+
+std::unique_ptr
+createWebAssemblyTargetCodeGenInfo(CodeGenModule &CGM, WebAssemblyABIKind K);
+
+/// The AVX ABI level for X86 targets.
+enum class X86AVXABILevel {
+  None,
+  AVX,
+  AVX512,
+};
+
+std::unique_ptr createX86_32TargetCodeGenInfo(
+CodeGenModule &CGM, bool DarwinVectorABI, bool Win32StructABI,
+unsigned NumRegisterParameters, bool SoftFloatABI);
+
+std::unique_ptr
+createWinX86_32TargetCodeGenInfo(CodeGenModule &CGM, bool DarwinVectorABI,
+ bool Win32StructABI,
+ unsigned NumRegisterParameters);
+
+std::unique_ptr
+createX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel);
+
+std::unique_ptr
+createWinX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel);
+
+std::unique_ptr
+createXCoreTargetCodeGenInfo(CodeGenModule &CGM);
+
 } // namespace CodeGen
 } // namespace clang
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -827,11 +827,6 @@
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 //===-

[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520774.
barannikov88 added a comment.

Squash commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGOpenCLRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/lib/CodeGen/TargetCodeGenInfo.cpp
  clang/lib/CodeGen/TargetCodeGenInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520777.
barannikov88 added a comment.

Undo file renaming so that it does not look like the file was replaced


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-09 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 520781.
barannikov88 added a comment.

Undo unintended formatting changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-05-09 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D149193#4316293 , @dblaikie wrote:

> I guess my main question is: What's the motivation for implementing this? Do 
> you have a need/use for this? (it doesn't seem to be motivated by GCC 
> compatibility - as discussed, looks like we're diverging in a bunch of ways 
> from their behavior and the argument made that these are "developer" flags, 
> so not a stable/compatible interface used across both compilers)

Even if we only align the default behavior of Clang with the default behavior 
of GCC it seems like a win. AFAIU we could implement this without `-dumpdir` at 
all, but the baseline notion of being able to specify where to put 
auxiliary/dump files seems useful.

Do we need to match every quirk and add every other knob from GCC in order to 
use the same name? Is there precedent in terms of other options where Clang is 
close but opinionated about behavior relative to GCC?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


  1   2   >