[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-04-03 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9c9db34a9b0: PR58819: Correct linkage and mangling of 
lambdas in inline static member… (authored by dblaikie).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138247

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCXX/mangle-lambdas.cpp

Index: clang/test/CodeGenCXX/mangle-lambdas.cpp
===
--- clang/test/CodeGenCXX/mangle-lambdas.cpp
+++ clang/test/CodeGenCXX/mangle-lambdas.cpp
@@ -290,6 +290,17 @@
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
 
 
+extern int ExternalVariable;
+struct StaticInlineMember {
+  static constexpr auto x = [] { return ExternalVariable; };
+};
+
+// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
+// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
+void test_StaticInlineMember() {
+  StaticInlineMember::x();
+}
+
 // Check linkage of the various lambdas.
 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
 // CHECK: ret i32 1
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
-VariableTemplate,
+TemplatedVariable,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,15 +301,15 @@
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = TemplatedVariable;
   else if (Var->getDescribedVarTemplate())
-Kind = VariableTemplate;
+Kind = TemplatedVariable;
   else if (auto *VTS = dyn_cast(Var)) {
 if (!VTS->isExplicitSpecialization())
-  Kind = VariableTemplate;
+  Kind = TemplatedVariable;
   }
 } else if (isa(ManglingContextDecl)) {
   Kind = DataMember;
@@ -319,12 +321,9 @@
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in different translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
-  case VariableTemplate:
-//  -- the initializers of templated variables
+  case TemplatedVariable:
+//  -- the initializers of inline or templated variables
 return std::make_tuple(
 (ASTContext::NeedExtraManglingDecl,
   ManglingContextDecl),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e9c9db3 - PR58819: Correct linkage and mangling of lambdas in inline static member initializers

2023-04-03 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-04-04T04:45:32Z
New Revision: e9c9db34a9b04706937e9dd764d1d97ca84337b6

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

LOG: PR58819: Correct linkage and mangling of lambdas in inline static member 
initializers

https://llvm.org/pr58819 - clang is giving an externally visible lambda in a 
static data member internal linkage and the wrong linkage name.

Looks like we should be classifying this case the same as a non-static data 
member, so far as I can tell from the ABI docs and template examples (seems 
like the non-template inline-defined case should be the same).

This is a change in ABI, but not sure it qualifies as an ABI break as far as 
Apple and Sony are concerned - do you folks want this change? (it should fix 
the example in the bug where a static member in such a lambda ends up 
bifurcated, and I don't /think/ it'll break existing code since the symbol was 
previously internal anyway)

Looks like GCC has got this mangling slightly wrong (so we'd still end up with 
GCC+Clang bifurcation of the local static in the lambda, function address 
inequality, etc) in that they miss the variable name in the mangling in the 
non-template case. GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741

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

Added: 


Modified: 
clang/lib/Sema/SemaLambda.cpp
clang/test/CodeGenCXX/mangle-lambdas.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c633a5080996b..a809968b66032 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -283,12 +283,14 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 Normal,
 DefaultArgument,
 DataMember,
-StaticDataMember,
 InlineVariable,
-VariableTemplate,
+TemplatedVariable,
 Concept
   } Kind = Normal;
 
+  bool IsInNonspecializedTemplate =
+  inTemplateInstantiation() || CurContext->isDependentContext();
+
   // Default arguments of member function parameters that appear in a class
   // definition, as well as the initializers of data members, receive special
   // treatment. Identify them.
@@ -299,15 +301,15 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 if (LexicalDC->isRecord())
   Kind = DefaultArgument;
 } else if (VarDecl *Var = dyn_cast(ManglingContextDecl)) {
-  if (Var->getDeclContext()->isRecord())
-Kind = StaticDataMember;
-  else if (Var->getMostRecentDecl()->isInline())
+  if (Var->getMostRecentDecl()->isInline())
 Kind = InlineVariable;
+  else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
+Kind = TemplatedVariable;
   else if (Var->getDescribedVarTemplate())
-Kind = VariableTemplate;
+Kind = TemplatedVariable;
   else if (auto *VTS = dyn_cast(Var)) {
 if (!VTS->isExplicitSpecialization())
-  Kind = VariableTemplate;
+  Kind = TemplatedVariable;
   }
 } else if (isa(ManglingContextDecl)) {
   Kind = DataMember;
@@ -319,12 +321,9 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC) 
{
   // Itanium ABI [5.1.7]:
   //   In the following contexts [...] the one-definition rule requires closure
   //   types in 
diff erent translation units to "correspond":
-  bool IsInNonspecializedTemplate =
-  inTemplateInstantiation() || CurContext->isDependentContext();
   switch (Kind) {
   case Normal: {
-//  -- the bodies of non-exported nonspecialized template functions
-//  -- the bodies of inline functions
+//  -- the bodies of inline or templated functions
 if ((IsInNonspecializedTemplate &&
  !(ManglingContextDecl && isa(ManglingContextDecl))) ||
 isInInlineFunction(CurContext)) {
@@ -341,21 +340,13 @@ Sema::getCurrentMangleNumberContext(const DeclContext 
*DC) {
 // however the ManglingContextDecl is important for the purposes of
 // re-forming the template argument list of the lambda for constraint
 // evaluation.
-  case StaticDataMember:
-//  -- the initializers of nonspecialized static members of template 
classes
-if (!IsInNonspecializedTemplate)
-  return std::make_tuple(nullptr, ManglingContextDecl);
-// Fall through to get the current context.
-[[fallthrough]];
-
   case DataMember:
-//  -- the in-class initializers of class members
+//  -- default member initializers
   case DefaultArgument:
 //  -- default arguments appearing in class definitions
   case InlineVariable:
-//  -- the initializers of inline variables
-  case VariableTemplate:
-//  -- the initializers of templated variables
+  case TemplatedVariable:
+//  -- the initializers of inline or 

[PATCH] D147497: [AArch64] Use fneg instead of fsub -0.0, X Cin IR expansion of __builtin_neon_vfmsh_f16.

2023-04-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: efriedma, dmgreen, SjoerdMeijer, john.brawn.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: clang.

Addresses the FIXME and removes the only in tree use of
llvm::ConstantFP::getZeroValueForNegation for an FP type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147497

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c


Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
@@ -652,7 +652,7 @@
 }
 
 // CHECK-LABEL: test_vfmsh_f16
-// CHECK:  [[SUB:%.*]] = fsub half 0xH8000, %b
+// CHECK:  [[SUB:%.*]] = fneg half %b
 // CHECK:  [[ADD:%.*]] = call half @llvm.fma.f16(half [[SUB]], half %c, half 
%a)
 // CHECK:  ret half [[ADD]]
 float16_t test_vfmsh_f16(float16_t a, float16_t b, float16_t c) {
Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -290,8 +290,7 @@
 }
 
 // COMMON-LABEL: test_vfmsh_f16
-// UNCONSTRAINED:  [[SUB:%.*]] = fsub half 0xH8000, %b
-// CONSTRAINED:[[SUB:%.*]] = call half 
@llvm.experimental.constrained.fsub.f16(half 0xH8000, half %b, metadata 
!"round.tonearest", metadata !"fpexcept.strict")
+// COMMONIR:  [[SUB:%.*]] = fneg half %b
 // UNCONSTRAINED:  [[ADD:%.*]] = call half @llvm.fma.f16(half [[SUB]], half 
%c, half %a)
 // CONSTRAINED:[[ADD:%.*]] = call half 
@llvm.experimental.constrained.fma.f16(half [[SUB]], half %c, half %a, metadata 
!"round.tonearest", metadata !"fpexcept.strict")
 // COMMONIR:   ret half [[ADD]]
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -10965,14 +10965,12 @@
 *this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, HalfTy,
 {EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)), Ops[0]});
   case NEON::BI__builtin_neon_vfmsh_f16: {
-// FIXME: This should be an fneg instruction:
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(HalfTy);
-Value* Sub = Builder.CreateFSub(Zero, EmitScalarExpr(E->getArg(1)), 
"vsubh");
+Value* Neg = Builder.CreateFNeg(EmitScalarExpr(E->getArg(1)), "vsubh");
 
 // NEON intrinsic puts accumulator first, unlike the LLVM fma.
 return emitCallMaybeConstrainedFPBuiltin(
 *this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, HalfTy,
-{Sub, EmitScalarExpr(E->getArg(2)), Ops[0]});
+{Neg, EmitScalarExpr(E->getArg(2)), Ops[0]});
   }
   case NEON::BI__builtin_neon_vaddd_s64:
   case NEON::BI__builtin_neon_vaddd_u64:


Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics.c
@@ -652,7 +652,7 @@
 }
 
 // CHECK-LABEL: test_vfmsh_f16
-// CHECK:  [[SUB:%.*]] = fsub half 0xH8000, %b
+// CHECK:  [[SUB:%.*]] = fneg half %b
 // CHECK:  [[ADD:%.*]] = call half @llvm.fma.f16(half [[SUB]], half %c, half %a)
 // CHECK:  ret half [[ADD]]
 float16_t test_vfmsh_f16(float16_t a, float16_t b, float16_t c) {
Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -290,8 +290,7 @@
 }
 
 // COMMON-LABEL: test_vfmsh_f16
-// UNCONSTRAINED:  [[SUB:%.*]] = fsub half 0xH8000, %b
-// CONSTRAINED:[[SUB:%.*]] = call half @llvm.experimental.constrained.fsub.f16(half 0xH8000, half %b, metadata !"round.tonearest", metadata !"fpexcept.strict")
+// COMMONIR:  [[SUB:%.*]] = fneg half %b
 // UNCONSTRAINED:  [[ADD:%.*]] = call half @llvm.fma.f16(half [[SUB]], half %c, half %a)
 // CONSTRAINED:[[ADD:%.*]] = call half @llvm.experimental.constrained.fma.f16(half [[SUB]], half %c, half %a, metadata !"round.tonearest", metadata !"fpexcept.strict")
 // COMMONIR:   ret half [[ADD]]
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -10965,14 +10965,12 @@
 *this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, HalfTy,
 {EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)), Ops[0]});
   case 

[PATCH] D147495: [Clang][Attributes] Add MeaningfulToClassTemplateDefinition to unavailable attribute

2023-04-03 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: rsmith, aaron.ballman, erichkeane.
Herald added a subscriber: inglorion.
Herald added a project: All.
shafik requested review of this revision.

There may be cases in which we want to diagnose a type as unavailable but it 
may not be complete at the time. Setting `MeaningfulToClassTemplateDefinition` 
fixes this issue.

This fixes: https://github.com/llvm/llvm-project/issues/61815


https://reviews.llvm.org/D147495

Files:
  clang/include/clang/Basic/Attr.td
  clang/test/SemaCXX/attr-unavailable.cpp


Index: clang/test/SemaCXX/attr-unavailable.cpp
===
--- clang/test/SemaCXX/attr-unavailable.cpp
+++ clang/test/SemaCXX/attr-unavailable.cpp
@@ -172,3 +172,13 @@
 
 template 
 int phase_one_unavailable2(int x = unavailable_int()) 
__attribute__((unavailable)) {}
+
+namespace GH61815 {
+template 
+class __attribute__((unavailable)) polymorphic_allocator {}; // expected-note 
2 {{'polymorphic_allocator' has been explicitly marked unavailable here}}
+
+void f() {
+  polymorphic_allocator a; // expected-error 
{{'polymorphic_allocator' is unavailable}}
+  polymorphic_allocator b; // expected-error 
{{'polymorphic_allocator' is unavailable}}
+}
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2848,6 +2848,7 @@
  "IR_ARCInitReturnsUnrelated",
  "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
   let Documentation = [Undocumented];
+  let MeaningfulToClassTemplateDefinition = 1;
 }
 
 def DiagnoseIf : InheritableAttr {


Index: clang/test/SemaCXX/attr-unavailable.cpp
===
--- clang/test/SemaCXX/attr-unavailable.cpp
+++ clang/test/SemaCXX/attr-unavailable.cpp
@@ -172,3 +172,13 @@
 
 template 
 int phase_one_unavailable2(int x = unavailable_int()) __attribute__((unavailable)) {}
+
+namespace GH61815 {
+template 
+class __attribute__((unavailable)) polymorphic_allocator {}; // expected-note 2 {{'polymorphic_allocator' has been explicitly marked unavailable here}}
+
+void f() {
+  polymorphic_allocator a; // expected-error {{'polymorphic_allocator' is unavailable}}
+  polymorphic_allocator b; // expected-error {{'polymorphic_allocator' is unavailable}}
+}
+}
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2848,6 +2848,7 @@
  "IR_ARCInitReturnsUnrelated",
  "IR_ARCFieldWithOwnership"], 1, /*fake*/ 1>];
   let Documentation = [Undocumented];
+  let MeaningfulToClassTemplateDefinition = 1;
 }
 
 def DiagnoseIf : InheritableAttr {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146329: [Clang] Fix defaulted equality operator so that it does not attempt to compare unnamed bit-fields

2023-04-03 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D146329#4207522 , @royjacobson 
wrote:

> In D146329#4203174 , @shafik wrote:
>
>> I would have loved to test the case from 
>> https://github.com/llvm/llvm-project/issues/61335 directly but I think in 
>> order to do it nicely I need `__builtin_memset` to be usable in a constant 
>> expression context. I will add this to my todo list. I am open to other 
>> alternatives for testing this.
>
> I managed to generate relatively readable LLVM IR for this: 
> https://godbolt.org/z/z1YzoEcr3 (the generated equality operators are 
> obviously not correct yet), I think matching against that is testing the 
> issue pretty well.
>
> (The trick to making it readable was turning on optimization, though. Not 
> sure if we usually do that)

I think in general we can't rely on optimizations in test like this but wdyt 
@erichkeane


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

https://reviews.llvm.org/D146329

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


[PATCH] D133863: [RISCV] Add MC support of RISCV zcmt Extension

2023-04-03 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 510667.
VincentWu added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133863

Files:
  clang/test/Preprocessor/riscv-target-features.c
  lld/ELF/InputSection.h
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/lib/Target/RISCV/RISCVSchedRocket.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVSystemOperands.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmt-invalid.s
  llvm/test/MC/RISCV/rv32zcmt-valid.s
  llvm/test/MC/RISCV/rvzcmt-user-csr-name.s

Index: llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+#
+# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+
+##
+# Jump Vector Table CSR
+##
+
+# jvt
+# name
+# CHECK-INST: csrrs t1, jvt, zero
+# CHECK-ENC:  encoding: [0x73,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t1, jvt
+# uimm12
+# CHECK-INST: csrrs t2, jvt, zero
+# CHECK-ENC:  encoding: [0xf3,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t2, jvt
+# name
+csrrs t1, jvt, zero
+# uimm12
+csrrs t2, 0x017, zero
Index: llvm/test/MC/RISCV/rv32zcmt-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-valid.s
@@ -0,0 +1,39 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jt 1
+
+# CHECK-ASM: cm.jalt 1
+# CHECK-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 1
+
+# CHECK-ASM-AND-OBJ: cm.jalt 32
+# CHECK-ASM: encoding: [0x82,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 32
Index: llvm/test/MC/RISCV/rv32zcmt-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-invalid.s
@@ -0,0 +1,10 @@
+# RUN: not llvm-mc -triple=riscv32 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+# RUN: not llvm-mc -triple=riscv64 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: error: immediate must be an integer in the range [0, 31]
+cm.jt 64
+
+# CHECK-ERROR: error: immediate must be an integer in the range [0, 255]
+cm.jalt 256
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -219,6 

[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Alexander Shaposhnikov 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 rG60bee9ff5445: [Clang][Sema] Fix comparison of constraint 
expressions (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -947,9 +947,6 @@
   
 https://wg21.link/p1980r0;>P1980R0
   
-   
-https://wg21.link/p2103r0;>P2103R0
-  

 https://wg21.link/p2493r0;>P2493R0
   
@@ -961,6 +958,9 @@
 https://wg21.link/p2113r0;>P2113R0
 Clang 16
   
+  
+https://wg21.link/p2103r0;>P2103R0
+  
 
 
   Range-based for statements with initializer
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,12 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,153 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) {
+  return CONSTRAINED_METHOD_2;
+}
+
+// Verify that there is no amiguity in this case.

[clang] 60bee9f - [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2023-04-04T02:31:13Z
New Revision: 60bee9ff544541e83ffbd4be31923d0e8b644690

URL: 
https://github.com/llvm/llvm-project/commit/60bee9ff544541e83ffbd4be31923d0e8b644690
DIFF: 
https://github.com/llvm/llvm-project/commit/60bee9ff544541e83ffbd4be31923d0e8b644690.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.

The associated GitHub issue: https://github.com/llvm/llvm-project/issues/61414

Test plan:
1/ ninja check-all
2/ bootstrapped Clang passes tests

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

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/concepts-out-of-line-def.cpp
clang/test/SemaTemplate/concepts.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 2882b10613fdc..4e7033c9d588d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -260,6 +260,9 @@ calculateConstraintSatisfaction(Sema , const Expr 
*ConstraintExpr,
 return SubstitutedAtomicExpr;
   }
 
+  if (SubstitutedAtomicExpr.get()->isValueDependent())
+return SubstitutedAtomicExpr;
+
   EnterExpressionEvaluationContext ConstantEvaluated(
   S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   SmallVector EvaluationDiags;
@@ -752,27 +755,43 @@ namespace {
   };
 } // namespace
 
+static const Expr *SubstituteConstraintExpression(Sema , 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(const NamedDecl *Old,
  const Expr *OldConstr,
  const NamedDecl *New,
  const Expr *NewConstr) {
+  if (OldConstr == NewConstr)
+return true;
   if (Old && New && Old != New) {
-unsigned Depth1 = CalculateTemplateDepthForConstraints(
-*this, Old);
-unsigned Depth2 = CalculateTemplateDepthForConstraints(
-*this, New);
-
-// Adjust the 'shallowest' verison of this to increase the depth to match
-// the 'other'.
-if (Depth2 > Depth1) {
-  OldConstr = AdjustConstraintDepth(*this, Depth2 - Depth1)
-  .TransformExpr(const_cast(OldConstr))
-  .get();
-} else if (Depth1 > Depth2) {
-  NewConstr = AdjustConstraintDepth(*this, Depth1 - Depth2)
-  .TransformExpr(const_cast(NewConstr))
-  .get();
-}
+if (const Expr *SubstConstr =
+SubstituteConstraintExpression(*this, Old, OldConstr))
+  OldConstr = SubstConstr;
+else
+  return false;
+if (const Expr *SubstConstr =
+SubstituteConstraintExpression(*this, New, NewConstr))
+  NewConstr = SubstConstr;
+else
+  return false;
   }
 
   llvm::FoldingSetNodeID ID1, ID2;

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f10d937ed74d5..5cbd9e8a46234 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1294,7 +1294,7 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
 // We check the return type and template parameter lists for function
 // templates first; the remaining checks follow.
 bool SameTemplateParameterList = TemplateParameterListsAreEqual(
-NewTemplate->getTemplateParameters(),
+NewTemplate, NewTemplate->getTemplateParameters(), OldTemplate,
 OldTemplate->getTemplateParameters(), false, TPL_TemplateMatch);
 bool SameReturnType = Context.hasSameType(Old->getDeclaredReturnType(),
   New->getDeclaredReturnType());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 

[PATCH] D147417: [clang-tidy] Do not emit bugprone-exception-escape warnings from coroutines

2023-04-03 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp:75-79
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:11: warning: an exception may be thrown 
in function 'b_ShouldNotDiag' which should not throw exceptions
+  if (b == 0)
+throw b;
+
+  co_return a / b;

denizevrenci wrote:
> ChuanqiXu wrote:
> > I don't understand why we shouldn't emit the warning here. Since the 
> > function is marked `noexcept` but it may throw actually in 
> > `unhandled_exception`. I think it is meaningful to warn for this.
> Right, I now see that this behavior is different between Clang's 
> `-Wexceptions` and Clang Tidy's `bugprone-exception-escape`. The former does 
> not warn on this code, the latter does.
> 
> ```
> int foo() {
>   throw 1;
> }
> 
> int bar() noexcept {
>   return foo();
> }
> ```
> 
> We need to treat coroutines differently and check whether `task::task`, 
> `promise::promise`,  `promise::initial_suspend`, 
> `promise::get_return_object`, and `promise::unhandled_exception` can throw 
> instead of the body of the coroutine.
I investigated the exception issue in coroutines before: 
https://reviews.llvm.org/D108277. And it is much more complex than I thought. 
The short conclusion here is that the coroutine is still may throw even if all 
the promise's method wouldn't throw. For example:

```
struct Evil {
~Evil() noexcept(false) { throw 32; }
};

task foo() noexcept { // all promise's method of task wouldn't throw
throw Evil;
}
```

And in the above example, foo() may throw actually. Although the implicit 
`catch` block of `foo()` will catch `Evil`, the exception in the destructor of 
`Evil` will be thrown again.

So we can't be sure that a coroutine wouldn't throw even if all of its 
promise's method wouldn't throw.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147417

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


[PATCH] D147422: [clang-format] NFC Document the other space before colon option

2023-04-03 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

In D147422#4240024 , @MyDeveloperDay 
wrote:

> In D147422#4240021 , @owenpan wrote:
>
>> Should we extend `SpacesInContainerLiterals` so that it controls JSON colons 
>> too? If yes, then we don't need `SpaceBeforeJsonColon`. Otherwise, IMO we 
>> should leave the doc alone.
>
> My concern for `SpacesInContainerLiterals` is that it impacts arrays contents 
> too '[ 1, 2, 3 ]'.

It looks like a line break gets inserted in arrays.  Does that mean the option 
doesn't affect arrays?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147422

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


[PATCH] D133863: [RISCV] Add MC support of RISCV zcmt Extension

2023-04-03 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 510664.
VincentWu marked an inline comment as done.
VincentWu added a comment.
Herald added a subscriber: jobnoorman.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133863

Files:
  clang/test/Preprocessor/riscv-target-features.c
  lld/ELF/InputSection.h
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/lib/Target/RISCV/RISCVSchedRocket.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVSystemOperands.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmt-invalid.s
  llvm/test/MC/RISCV/rv32zcmt-valid.s
  llvm/test/MC/RISCV/rvzcmt-user-csr-name.s

Index: llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+#
+# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+
+##
+# Jump Vector Table CSR
+##
+
+# jvt
+# name
+# CHECK-INST: csrrs t1, jvt, zero
+# CHECK-ENC:  encoding: [0x73,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t1, jvt
+# uimm12
+# CHECK-INST: csrrs t2, jvt, zero
+# CHECK-ENC:  encoding: [0xf3,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t2, jvt
+# name
+csrrs t1, jvt, zero
+# uimm12
+csrrs t2, 0x017, zero
Index: llvm/test/MC/RISCV/rv32zcmt-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-valid.s
@@ -0,0 +1,39 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jt 1
+
+# CHECK-ASM: cm.jalt 1
+# CHECK-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 1
+
+# CHECK-ASM-AND-OBJ: cm.jalt 32
+# CHECK-ASM: encoding: [0x82,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 32
Index: llvm/test/MC/RISCV/rv32zcmt-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-invalid.s
@@ -0,0 +1,10 @@
+# RUN: not llvm-mc -triple=riscv32 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+# RUN: not llvm-mc -triple=riscv64 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: error: immediate must be an integer in the range [0, 31]
+cm.jt 64
+
+# CHECK-ERROR: error: immediate must be an integer in the range [0, 255]
+cm.jalt 256
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- 

[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 510662.
alexander-shaposhnikov added a comment.

Add test & minor optimization


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

https://reviews.llvm.org/D146178

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -947,9 +947,6 @@
   
 https://wg21.link/p1980r0;>P1980R0
   
-   
-https://wg21.link/p2103r0;>P2103R0
-  

 https://wg21.link/p2493r0;>P2493R0
   
@@ -961,6 +958,9 @@
 https://wg21.link/p2113r0;>P2113R0
 Clang 16
   
+  
+https://wg21.link/p2103r0;>P2103R0
+  
 
 
   Range-based for statements with initializer
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,12 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,153 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) {
+  return CONSTRAINED_METHOD_2;
+}
+
+// Verify that there is no amiguity in this case.
+static_assert(S<4>::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_member_sfinae
+
+namespace requires_expression_references_members {
+
+void 

[PATCH] D132819: [RISCV] Add MC support of RISCV zcmp Extension

2023-04-03 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 510661.
VincentWu added a comment.

rename FeatureExtZcmp -> FeatureStdExtZcmp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132819

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/lib/Target/RISCV/RISCVSchedRocket.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmp-invalid.s
  llvm/test/MC/RISCV/rv32zcmp-valid.s
  llvm/test/MC/RISCV/rv64zcmp-invalid.s
  llvm/test/MC/RISCV/rv64zcmp-valid.s

Index: llvm/test/MC/RISCV/rv64zcmp-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcmp-valid.s
@@ -0,0 +1,149 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=experimental-zcmp < %s \
+# RUN: | llvm-objdump --mattr=-c,experimental-zcmp -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: cm.mvsa01 s1, s0
+# CHECK-ASM: encoding: [0xa2,0xac]
+cm.mvsa01 s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.mva01s s1, s0
+# CHECK-ASM: encoding: [0xe2,0xac]
+cm.mva01s s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbe]
+cm.popret {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbe]
+cm.popret {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbe]
+cm.popret {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbe]
+cm.popret {ra,s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbe]
+cm.popret {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbe]
+cm.popret {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbe]
+cm.popret {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbe]
+cm.popret {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbe]
+cm.popret {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbc]
+cm.popretz {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbc]
+cm.popretz {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbc]
+cm.popretz {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbc]
+cm.popretz {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbc]
+cm.popretz {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbc]
+cm.popretz {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbc]
+cm.popretz {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbc]
+cm.popretz {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbc]
+cm.popretz {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xba]
+cm.pop {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xba]
+cm.pop {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0}, 16
+# CHECK-ASM: encoding: [0x52,0xba]
+cm.pop {ra, s0}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xba]
+cm.pop {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xba]
+cm.pop {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xba]
+cm.pop {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xba]
+cm.pop {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xba]
+cm.pop {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.push {ra}, -16
+# CHECK-ASM: encoding: [0x42,0xb8]
+cm.push {ra}, 

[PATCH] D147420: [X86] Support AMX Complex instructions

2023-04-03 Thread Xiang Zhang 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 rG038b7e6b761c: [X86] Support AMX Complex instructions 
(authored by xiangzhangllvm).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D147420?vs=510426=510660#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147420

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/amxcomplexintrin.h
  clang/lib/Headers/immintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/amx_complex_api.c
  clang/test/CodeGen/X86/amxcomplex-builtins.c
  clang/test/CodeGen/X86/amxcomplex-errors.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86ExpandPseudo.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86LowerAMXType.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/AMX/amx-tile-complex-internals.ll
  llvm/test/CodeGen/X86/AMX/amxcomplex-intrinsics.ll
  llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-att.txt
  llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-intel.txt
  llvm/test/MC/X86/AMX/x86-64-amx-complex-att.s
  llvm/test/MC/X86/AMX/x86-64-amx-complex-intel.s

Index: llvm/test/MC/X86/AMX/x86-64-amx-complex-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/AMX/x86-64-amx-complex-intel.s
@@ -0,0 +1,17 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  tcmmimfp16ps tmm6, tmm5, tmm4
+// CHECK: encoding: [0xc4,0xe2,0x59,0x6c,0xf5]
+   tcmmimfp16ps tmm6, tmm5, tmm4
+
+// CHECK:  tcmmimfp16ps tmm3, tmm2, tmm1
+// CHECK: encoding: [0xc4,0xe2,0x71,0x6c,0xda]
+   tcmmimfp16ps tmm3, tmm2, tmm1
+
+// CHECK:  tcmmrlfp16ps tmm6, tmm5, tmm4
+// CHECK: encoding: [0xc4,0xe2,0x58,0x6c,0xf5]
+   tcmmrlfp16ps tmm6, tmm5, tmm4
+
+// CHECK:  tcmmrlfp16ps tmm3, tmm2, tmm1
+// CHECK: encoding: [0xc4,0xe2,0x70,0x6c,0xda]
+   tcmmrlfp16ps tmm3, tmm2, tmm1
Index: llvm/test/MC/X86/AMX/x86-64-amx-complex-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/AMX/x86-64-amx-complex-att.s
@@ -0,0 +1,17 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding < %s  | FileCheck %s
+
+// CHECK:  tcmmimfp16ps %tmm4, %tmm5, %tmm6
+// CHECK: encoding: [0xc4,0xe2,0x59,0x6c,0xf5]
+   tcmmimfp16ps %tmm4, %tmm5, %tmm6
+
+// CHECK:  tcmmimfp16ps %tmm1, %tmm2, %tmm3
+// CHECK: encoding: [0xc4,0xe2,0x71,0x6c,0xda]
+   tcmmimfp16ps %tmm1, %tmm2, %tmm3
+
+// CHECK:  tcmmrlfp16ps %tmm4, %tmm5, %tmm6
+// CHECK: encoding: [0xc4,0xe2,0x58,0x6c,0xf5]
+   tcmmrlfp16ps %tmm4, %tmm5, %tmm6
+
+// CHECK:  tcmmrlfp16ps %tmm1, %tmm2, %tmm3
+// CHECK: encoding: [0xc4,0xe2,0x70,0x6c,0xda]
+   tcmmrlfp16ps %tmm1, %tmm2, %tmm3
Index: llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-intel.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-intel.txt
@@ -0,0 +1,13 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 -x86-asm-syntax=intel --output-asm-variant=1 | FileCheck %s
+
+# CHECK:  tcmmimfp16ps tmm6, tmm5, tmm4
+0xc4,0xe2,0x59,0x6c,0xf5
+
+# CHECK:  tcmmimfp16ps tmm3, tmm2, tmm1
+0xc4,0xe2,0x71,0x6c,0xda
+
+# CHECK:  tcmmrlfp16ps tmm6, tmm5, tmm4
+0xc4,0xe2,0x58,0x6c,0xf5
+
+# CHECK:  tcmmrlfp16ps tmm3, tmm2, tmm1
+0xc4,0xe2,0x70,0x6c,0xda
Index: llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-att.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-att.txt
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding --disassemble < %s  | FileCheck %s
+
+# CHECK:  tcmmimfp16ps %tmm4, %tmm5, %tmm6
+0xc4,0xe2,0x59,0x6c,0xf5
+
+# CHECK:  tcmmimfp16ps %tmm1, %tmm2, %tmm3
+0xc4,0xe2,0x71,0x6c,0xda
+
+# CHECK:  tcmmrlfp16ps %tmm4, %tmm5, %tmm6
+0xc4,0xe2,0x58,0x6c,0xf5
+
+# CHECK:  tcmmrlfp16ps %tmm1, %tmm2, %tmm3
+0xc4,0xe2,0x70,0x6c,0xda
Index: llvm/test/CodeGen/X86/AMX/amxcomplex-intrinsics.ll

[clang] 038b7e6 - [X86] Support AMX Complex instructions

2023-04-03 Thread Xiang1 Zhang via cfe-commits

Author: Xiang1 Zhang
Date: 2023-04-04T09:54:46+08:00
New Revision: 038b7e6b761c2bebb30440cdd39252a0fa74ac3f

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

LOG: [X86] Support AMX Complex instructions

Reviewed By: Wang Pengfei

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

Added: 
clang/lib/Headers/amxcomplexintrin.h
clang/test/CodeGen/X86/amx_complex_api.c
clang/test/CodeGen/X86/amxcomplex-builtins.c
clang/test/CodeGen/X86/amxcomplex-errors.c
llvm/test/CodeGen/X86/AMX/amx-tile-complex-internals.ll
llvm/test/CodeGen/X86/AMX/amxcomplex-intrinsics.ll
llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-att.txt
llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-complex-intel.txt
llvm/test/MC/X86/AMX/x86-64-amx-complex-att.s
llvm/test/MC/X86/AMX/x86-64-amx-complex-intel.s

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/BuiltinsX86_64.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/immintrin.h
clang/lib/Sema/SemaChecking.cpp
clang/test/Driver/x86-target-features.c
clang/test/Preprocessor/x86_target_features.c
llvm/include/llvm/IR/IntrinsicsX86.td
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/lib/Target/X86/X86.td
llvm/lib/Target/X86/X86ExpandPseudo.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86InstrAMX.td
llvm/lib/Target/X86/X86InstrInfo.td
llvm/lib/Target/X86/X86LowerAMXType.cpp
llvm/lib/Target/X86/X86RegisterInfo.cpp
llvm/lib/TargetParser/X86TargetParser.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53a0541ed290a..100be1b5e893c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -332,6 +332,9 @@ AMDGPU Support
 X86 Support
 ^^^
 
+- Add ISA of ``AMX-COMPLEX`` which supports ``tcmmimfp16ps`` and
+  ``tcmmrlfp16ps``.
+
 Arm and AArch64 Support
 ^^^
 

diff  --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 4b9e7d29d6517..e5c1fe8b31921 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -117,6 +117,8 @@ TARGET_BUILTIN(__builtin_ia32_tilestored64_internal, 
"vUsUsv*zV256i", "n", "amx-
 TARGET_BUILTIN(__builtin_ia32_tilezero_internal, "V256iUsUs", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tdpbf16ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-bf16")
 TARGET_BUILTIN(__builtin_ia32_tdpfp16ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-fp16")
+TARGET_BUILTIN(__builtin_ia32_tcmmimfp16ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-complex")
+TARGET_BUILTIN(__builtin_ia32_tcmmrlfp16ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-complex")
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -134,6 +136,9 @@ TARGET_BUILTIN(__builtin_ia32_tdpbuud, "vIUcIUcIUc", "n", 
"amx-int8")
 TARGET_BUILTIN(__builtin_ia32_tdpbf16ps, "vIUcIUcIUc", "n", "amx-bf16")
 TARGET_BUILTIN(__builtin_ia32_ptwrite64, "vUOi", "n", "ptwrite")
 
+TARGET_BUILTIN(__builtin_ia32_tcmmimfp16ps, "vIUcIUcIUc", "n", "amx-complex")
+TARGET_BUILTIN(__builtin_ia32_tcmmrlfp16ps, "vIUcIUcIUc", "n", "amx-complex")
+
 TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
 TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
 TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiv*SLLiSLLiIi", "n", 
"cmpccxadd")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0cc7052b67105..831f8dd65a3e6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4656,6 +4656,8 @@ def m3dnowa : Flag<["-"], "m3dnowa">, 
Group;
 def mno_3dnowa : Flag<["-"], "mno-3dnowa">, Group;
 def mamx_bf16 : Flag<["-"], "mamx-bf16">, Group;
 def mno_amx_bf16 : Flag<["-"], "mno-amx-bf16">, Group;
+def mamx_complex : Flag<["-"], "mamx-complex">, Group;
+def mno_amx_complex : Flag<["-"], "mno-amx-complex">, 
Group;
 def mamx_fp16 : Flag<["-"], "mamx-fp16">, Group;
 def mno_amx_fp16 : Flag<["-"], "mno-amx-fp16">, Group;
 def mamx_int8 : Flag<["-"], "mamx-int8">, Group;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index ac04bf9f3dd18..0cffc76d3f2ce 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -335,6 +335,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasAMXINT8 = true;
 } else if (Feature == "+amx-tile") {
   HasAMXTILE = 

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-04-03 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 510658.
HerrCai0907 edited the summary of this revision.
HerrCai0907 added a comment.

add feature update close comment in fixhint
update acc. comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147194

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp
@@ -143,7 +143,7 @@
 #endif
 } // namespace n40
 } // namespace n39
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n39::n40
 
 namespace n41 {
 namespace n42 {
@@ -154,7 +154,50 @@
 #endif
 } // namespace n42
 } // namespace n41
-// CHECK-FIXES: }
+// CHECK-FIXES: } // namespace n41::n42
+
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n43 {
+#define N43_INNER
+namespace n44 {
+void foo() {}
+} // namespace n44
+#undef N43_INNER
+} // namespace n43
+// CHECK-FIXES: #define N43_INNER
+// CHECK-FIXES: namespace n43::n44 {
+// CHECK-FIXES: } // namespace n43::n44
+// CHECK-FIXES: #undef N43_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace n45{
+#define N45_INNER
+namespace n46
+{
+#pragma clang diagnostic push
+namespace n47 {
+void foo() {}
+} // namespace n47
+#pragma clang diagnostic pop
+} //namespace n46
+#undef N45_INNER
+} //namespace n45
+// CHECK-FIXES: #define N45_INNER
+// CHECK-FIXES: #pragma clang diagnostic push
+// CHECK-FIXES: namespace n45::n46::n47 {
+// CHECK-FIXES: } // namespace n45::n46::n47
+// CHECK-FIXES: #pragma clang diagnostic pop
+// CHECK-FIXES: #undef N45_INNER
+
+// CHECK-MESSAGES-DAG: :[[@LINE+1]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+namespace avoid_add_close_comment {
+namespace inner {
+void foo() {}
+}
+}
+// CHECK-FIXES: namespace avoid_add_close_comment::inner {
+// CHECK-FIXES-NOT: } // namespace avoid_add_close_comment::inner
 
 int main() {
   n26::n27::n28::n29::n30::t();
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -5,4 +5,4 @@
 } // namespace nn2
 } // namespace nn1
 // CHECK-FIXES: void t();
-// CHECK-FIXES-NEXT: } // namespace nn1
+// CHECK-FIXES-NEXT: } // namespace nn1::nn2
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -275,6 +275,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed an issue in :doc:`modernize-concat-nested-namespaces
+  ` when using macro between 
+  namespace declarations could result incorrect fix.
+
 - Fixed a false positive in :doc:`performance-no-automatic-move
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -85,6 +85,10 @@
   }
 }
 
+std::optional
+findNextTokenIncludingComments(SourceLocation Start, const SourceManager ,
+   const LangOptions );
+
 // Finds next token that's not a comment.
 std::optional findNextTokenSkippingComments(SourceLocation Start,
const SourceManager ,
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -75,6 +75,29 @@
   return findNextAnyTokenKind(Start, SM, LangOpts, tok::comma, tok::semi);
 }
 
+std::optional

[PATCH] D147417: [clang-tidy] Do not emit bugprone-exception-escape warnings from coroutines

2023-04-03 Thread Deniz Evrenci via Phabricator via cfe-commits
denizevrenci added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp:75-79
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:11: warning: an exception may be thrown 
in function 'b_ShouldNotDiag' which should not throw exceptions
+  if (b == 0)
+throw b;
+
+  co_return a / b;

ChuanqiXu wrote:
> I don't understand why we shouldn't emit the warning here. Since the function 
> is marked `noexcept` but it may throw actually in `unhandled_exception`. I 
> think it is meaningful to warn for this.
Right, I now see that this behavior is different between Clang's `-Wexceptions` 
and Clang Tidy's `bugprone-exception-escape`. The former does not warn on this 
code, the latter does.

```
int foo() {
  throw 1;
}

int bar() noexcept {
  return foo();
}
```

We need to treat coroutines differently and check whether `task::task`, 
`promise::promise`,  `promise::initial_suspend`, `promise::get_return_object`, 
and `promise::unhandled_exception` can throw instead of the body of the 
coroutine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147417

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


[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D147477

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


[PATCH] D146595: [clang] Add "transparent_stepping" attribute

2023-04-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

> Is there some place (bug, discourse thread, etc) where the broader direction 
> is discussed? I want to checkin on the design decisions/alternatives without 
> fragmenting this across multiple reviews/losing context/etc?

No, I believe that all the relevant discussion happened in this review. While 
there is a separate review for an LLDB implementation, there is no general 
direction discussion there, it's just implementing a DWARF feature.

> (specifically - this started out with the trampoline attribute, then switched 
> to this transparent idea (perhaps based on my feedback? Also other feedback? 
> I'd like to know more about how that change in direction happened, what the 
> tradeoffs were, etc - I don't think my suggestion alone was probably enough 
> to make this direction clearly the right one (nor clearly the wrong one)), 
> etc)

It was partially based on your feedback, but also on @arphaman pointing out 
that the `DW_AT_trampoline("call_target")` implementation wouldn't be able to 
deal with the jump target being a virtual function call. So @augusto2112 
landed on implementing the "flag variant" of `DW_AT_trampiline` instead. This 
is also an existing DWARF feature, albeit not yet supported by LLVM.

> & there was some tangent about DWARF v COFF too, which I wouldn't mind 
> weighing in on, but feel like it's all a bit fragmented, so not sure where 
> all the discussions are/how to keep track of them.

That was also in this review; @aaron.ballman pointed out that it would be best 
if new Clang attributes weren't targeting only DWARF, though I believe this 
request may run into some hard limitations of what CodeView/PDB can support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146595

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 510637.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -947,9 +947,6 @@
   
 https://wg21.link/p1980r0;>P1980R0
   
-   
-https://wg21.link/p2103r0;>P2103R0
-  

 https://wg21.link/p2493r0;>P2493R0
   
@@ -961,6 +958,9 @@
 https://wg21.link/p2113r0;>P2113R0
 Clang 16
   
+  
+https://wg21.link/p2103r0;>P2103R0
+  
 
 
   Range-based for statements with initializer
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,153 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) {
+  return CONSTRAINED_METHOD_2;
+}
+
+// Verify that there is no amiguity in this case.
+static_assert(S<4>::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_member_sfinae
+
+namespace requires_expression_references_members {
+
+void accept1(int x);
+void accept2(XY xy);
+
+template  struct S {
+  T Field = T();
+
+  constexpr int constrained_method()
+  requires requires { accept1(Field); };
+
+  constexpr int constrained_method()
+  requires requires { accept2(Field); };
+};
+
+template 
+constexpr int S::constrained_method()
+  requires requires { accept1(Field); } {
+  return CONSTRAINED_METHOD_1;
+}
+
+template 
+constexpr int S::constrained_method()
+  requires requires { accept2(Field); } {
+  return CONSTRAINED_METHOD_2;
+}
+
+static_assert(S().constrained_method() == 

[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

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

Does my horrible lambda example work now? If so, that seems like a useful 
testcase.




Comment at: clang/lib/Sema/SemaConcept.cpp:781
+  /*ForConstraintInstantiation=*/true, /*SkipForSpecialization*/ false);
+  Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+  std::optional ThisScope;

Just a small optimization: there's no point doing the transform if we have 
nothing to substitute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 510634.
alexander-shaposhnikov added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp

Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,153 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) {
+  return CONSTRAINED_METHOD_2;
+}
+
+// Verify that there is no amiguity in this case.
+static_assert(S<4>::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_member_sfinae
+
+namespace requires_expression_references_members {
+
+void accept1(int x);
+void accept2(XY xy);
+
+template  struct S {
+  T Field = T();
+
+  constexpr int constrained_method()
+  requires requires { accept1(Field); };
+
+  constexpr int constrained_method()
+  requires requires { accept2(Field); };
+};
+
+template 
+constexpr int S::constrained_method()
+  requires requires { accept1(Field); } {
+  return CONSTRAINED_METHOD_1;
+}
+
+template 
+constexpr int S::constrained_method()
+  requires requires { accept2(Field); } {
+  return CONSTRAINED_METHOD_2;
+}
+
+static_assert(S().constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S().constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace requires_expression_references_members
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1653,33 +1653,12 @@
 << QualifierLoc.getSourceRange();
   return nullptr;
 }
-
-if (PrevClassTemplate) {
-  const ClassTemplateDecl *MostRecentPrevCT =
-  

[PATCH] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu created this revision.
myhsu added reviewers: 0x59616e, RKSimon.
Herald added a project: All.
myhsu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

- Add the `-m68881` flag
- Add floating point feature detection
- Macro definitions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147481

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -1,10 +1,16 @@
 // Check macro definitions
 // RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// CHECK-MX-NOT: #define __HAVE_68881__ 1
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
 // CHECK-MX: #define mc68000 1
 
 // RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// CHECK-MX10-NOT: #define __HAVE_68881__ 1
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
@@ -12,7 +18,10 @@
 // CHECK-MX10: #define mc68000 1
 // CHECK-MX10: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here.
+// CHECK-MX881: #define __HAVE_68881__ 1
+
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
@@ -20,7 +29,7 @@
 // CHECK-MX20: #define mc68000 1
 // CHECK-MX20: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
@@ -28,7 +37,7 @@
 // CHECK-MX30: #define mc68000 1
 // CHECK-MX30: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
@@ -36,7 +45,7 @@
 // CHECK-MX40: #define mc68000 1
 // CHECK-MX40: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
 // CHECK-MX60: #define __mc68000 1
 // CHECK-MX60: #define __mc68000__ 1
 // CHECK-MX60: #define __mc68060 1
Index: clang/test/Driver/m68k-features.cpp
===
--- clang/test/Driver/m68k-features.cpp
+++ clang/test/Driver/m68k-features.cpp
@@ -59,3 +59,23 @@
 // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s
 // CHECK-FIXED-D7: "-target-feature" "+reserve-d7"
 
+//  Floating point 
+// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68010 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68010 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68020 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68030 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX882 < %t %s
+
+// CHECK-MX881: "-target-feature" "+isa-68881"
+// CHECK-MX882: "-target-feature" "+isa-68882"
+
Index: clang/lib/Driver/ToolChains/Arch/M68k.h
===
--- clang/lib/Driver/ToolChains/Arch/M68k.h
+++ clang/lib/Driver/ToolChains/Arch/M68k.h
@@ -20,14 +20,6 @@

[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 510629.
benlangmuir added a comment.

Upload correct diff this time


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

https://reviews.llvm.org/D147477

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Modules/implicit-private-with-submodule-explicit.m


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,31 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+
+// Check lazily-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only 
%t/tu.m
+
+// Check eagerly-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=%t/A.pcm -fmodule-file=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 
'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, 
true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, 
IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,31 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+
+// Check lazily-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+// Check eagerly-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=%t/A.pcm -fmodule-file=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 

[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 510628.
benlangmuir added a comment.

Also test eagerly-loaded pcm


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

https://reviews.llvm.org/D147477

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Modules/implicit-private-with-submodule-explicit.m


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,31 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+
+// Check lazily-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only 
%t/tu.m
+
+// Check eagerly-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=A=%t/A.pcm -fmodule-file=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 
'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, 
true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, 
IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,31 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+
+// Check lazily-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+// Check eagerly-loaded module
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=A=%t/A.pcm -fmodule-file=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != 

[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Modules/implicit-private-with-submodule-explicit.m:9
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only 
%t/tu.m
+

Can we also test the `-fmodule-file=` mode? I assume it doesn't go 
through the changed code path, but having extra test coverage could be useful.


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

https://reviews.llvm.org/D147477

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


[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 510623.

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

https://reviews.llvm.org/D147477

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Modules/implicit-private-with-submodule-explicit.m


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,26 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only 
%t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 
'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, 
true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, 
IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,26 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147477: [clang][modules] Handle explicit modules when checking for .Private -> _Private

2023-04-03 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added reviewers: akyrtzi, jansvoboda11.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

While we eventually want to remove the mapping from .Private to _Private 
modules, until we do, ensure that it behaves the same for explicit modules.

rdar://107449872


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147477

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Modules/implicit-private-with-submodule-explicit.m


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,26 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module 
-fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules 
-fno-implicit-module-maps -fmodule-file=A=%t/A.pcm 
-fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 
'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, 
true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, 
IsInclusionDirective);
   if (Sub) {
 MapPrivateSubModToTopLevel = true;


Index: clang/test/Modules/implicit-private-with-submodule-explicit.m
===
--- /dev/null
+++ clang/test/Modules/implicit-private-with-submodule-explicit.m
@@ -0,0 +1,26 @@
+// Checks that the use of .Private to refer to _Private modules works with an
+// explicit module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A %t/module.modulemap -o %t/A.pcm
+// RUN: %clang_cc1 -x objective-c -fmodules -fno-implicit-modules -emit-module -fmodule-name=A_Private %t/module.modulemap -o %t/A_Private.pcm
+// RUN: %clang_cc1 -x objective-c -verify -fmodules -fno-implicit-modules -fno-implicit-module-maps -fmodule-file=A=%t/A.pcm -fmodule-file=A_Private=%t/A_Private.pcm -fsyntax-only %t/tu.m
+
+//--- module.modulemap
+module A { header "a.h" }
+module A_Private { header "priv.h" }
+
+//--- a.h
+
+//--- priv.h
+void priv(void);
+
+//--- tu.m
+@import A.Private; // expected-warning{{no submodule named 'Private' in module 'A'; using top level 'A_Private'}}
+// expected-note@*:* {{defined here}}
+
+void tu(void) {
+  priv();
+}
\ No newline at end of file
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -2026,8 +2026,12 @@
   PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
   PrivPath.push_back(std::make_pair(, Path[0].second));
 
+  std::string FileName;
+  // If there is a modulemap module or prebuilt module, load it.
   if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,
- !IsInclusionDirective))
+ !IsInclusionDirective) ||
+  selectModuleSource(nullptr, PrivateModule, FileName, BuiltModules,
+ PP->getHeaderSearchInfo()) != MS_ModuleNotFound)
 Sub = loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
   if (Sub) {
 

[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-04-03 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub added a comment.

Can you add a PowerPC codegen test case for `__attribute__((target(`? All of 
the updated test cases seem to only test `-target-feature`.
The only test case we have for `__attribute((target(` is a sema test 
`./clang/test/Sema/ppc-attr-target-inline.c`.

Converting the deleted `clang/test/Sema/ppc-mma-builtins.c` and 
`clang/test/Sema/ppc-paired-vector-builtins.c` to a codegen test cases
like `clang/test/CodeGen/PowerPC/builtins-ppc-htm.c` using FileCheck seems like 
a nice solution since it would reintroduce the testing
for `+paired-vector-memops,-mma` situations, as well as a for 
`__attribute__((target("no-mma")))`




Comment at: clang/include/clang/Basic/BuiltinsPPC.def:987
+
+UNALIASED_CUSTOM_BUILTIN(mma_assemble_acc, "vW512*", false, "mma")
+UNALIASED_CUSTOM_BUILTIN(mma_disassemble_acc, "vv*W512*", false, "mma")

stefanp wrote:
> Based on the original implementation in `SemaBuiltinPPCMMACall` all of the 
> `mma` builtins also require `paired-vector-memops`. 
> Is this something that we still need?
since we are able to supply a comma separated list as done with 
`TARGET_BUILTIN(__builtin_ppc_compare_exp_uo, "idd", "", 
"isa-v30-instructions,vsx")` @ 
`clang/include/clang/Basic/BuiltinsPPC.def:105`we should definitely also 
specify `paired-vector-memops,mma` for the `[UNALIASED_]CUSTOM_BUILTIN`s 
previously covered under the default case of `SemaBuiltinPPCMMACall()` 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[clang] d78ceeb - [Clang] Fix failing test on windows and add TODO for gpu headers

2023-04-03 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-04-03T16:54:22-05:00
New Revision: d78ceeba986b5ebe83f935175e584c346a52b8a3

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

LOG: [Clang] Fix failing test on windows and add TODO for gpu headers

Summary:
This test failed because of the path separators on Windows. Also this
was a good excuse to add an extra TODO that @tra wanted.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/gpu-libc-headers.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a17db9b9ceb7..65238830a57b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1166,8 +1166,9 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
getToolChain().getTriple().isAMDGCN())) {
 
   // Add include/gpu-none-libc/* to our system include path. This lets us 
use
-  // GPU-specific system headers first. These headers should be made to be
-  // compatible with the host environment's headers.
+  // GPU-specific system headers first. 
+  // TODO: We need to find a way to make these headers compatible with the
+  // host environment.
   SmallString<128> P(llvm::sys::path::parent_path(D.InstalledDir));
   llvm::sys::path::append(P, "include");
   llvm::sys::path::append(P, "gpu-none-llvm");

diff  --git a/clang/test/Driver/gpu-libc-headers.c 
b/clang/test/Driver/gpu-libc-headers.c
index c8f772f102d0..9437d3ed39a9 100644
--- a/clang/test/Driver/gpu-libc-headers.c
+++ b/clang/test/Driver/gpu-libc-headers.c
@@ -11,7 +11,7 @@
 // RUN: FileCheck %s --check-prefix=CHECK-HEADERS
 // RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib 
--sysroot=./ %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CHECK-HEADERS
-// CHECK-HEADERS: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"{{.*}}"-isysroot" "./"
+// CHECK-HEADERS: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include{{.*}}gpu-none-llvm"{{.*}}"-isysroot" "./"
 
 // RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
 // RUN: -nogpuinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
@@ -19,4 +19,4 @@
 // RUN: -nostdinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
 // RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
 // RUN: -nobuiltininc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
-// CHECK-HEADERS-DISABLED-NOT: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"
+// CHECK-HEADERS-DISABLED-NOT: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include{{.*}}gpu-none-llvm"



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


[PATCH] D146595: [clang] Add "transparent_stepping" attribute

2023-04-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Is there some place (bug, discourse thread, etc) where the broader direction is 
discussed? I want to checkin on the design decisions/alternatives without 
fragmenting this across multiple reviews/losing context/etc?

(specifically - this started out with the trampoline attribute, then switched 
to this transparent idea (perhaps based on my feedback? Also other feedback? 
I'd like to know more about how that change in direction happened, what the 
tradeoffs were, etc - I don't think my suggestion alone was probably enough to 
make this direction clearly the right one (nor clearly the wrong one)), etc)

& there was some tangent about DWARF v COFF too, which I wouldn't mind weighing 
in on, but feel like it's all a bit fragmented, so not sure where all the 
discussions are/how to keep track of them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146595

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


[clang] 64549f0 - [OpenMP][5.1] Fix parallel masked is ignored #59939

2023-04-03 Thread Jose Manuel Monsalve Diaz via cfe-commits

Author: Rafael A. Herrera Guaitero
Date: 2023-04-03T20:33:55Z
New Revision: 64549f0903e244fbe2e7f0131698334b6e45dc10

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

LOG: [OpenMP][5.1] Fix parallel masked is ignored #59939

Code generation support for 'parallel masked' directive.

The `EmitOMPParallelMaskedDirective` was implemented.
In addition, the appropiate device functions were added.

Fix #59939.

Reviewed By: jdoerfert

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

Added: 
clang/test/OpenMP/parallel_masked.cpp
clang/test/OpenMP/parallel_masked_target.cpp

Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Parse/ParseOpenMP.cpp
openmp/libomptarget/DeviceRTL/include/Interface.h
openmp/libomptarget/DeviceRTL/src/Synchronization.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 4432205eac7e1..af8edbf87f94c 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -428,7 +428,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 llvm_unreachable("target parallel loop directive not supported yet.");
 break;
   case Stmt::OMPParallelMaskedDirectiveClass:
-llvm_unreachable("parallel masked directive not supported yet.");
+EmitOMPParallelMaskedDirective(cast(*S));
 break;
   }
 }

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index c2c441207d8af..f0f662c5c5ea3 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4489,6 +4489,33 @@ void CodeGenFunction::EmitOMPParallelMasterDirective(
   checkForLastprivateConditionalUpdate(*this, S);
 }
 
+void CodeGenFunction::EmitOMPParallelMaskedDirective(
+const OMPParallelMaskedDirective ) {
+  // Emit directive as a combined directive that consists of two implicit
+  // directives: 'parallel' with 'masked' directive.
+  auto & = [](CodeGenFunction , PrePostActionTy ) {
+Action.Enter(CGF);
+OMPPrivateScope PrivateScope(CGF);
+emitOMPCopyinClause(CGF, S);
+(void)CGF.EmitOMPFirstprivateClause(S, PrivateScope);
+CGF.EmitOMPPrivateClause(S, PrivateScope);
+CGF.EmitOMPReductionClauseInit(S, PrivateScope);
+(void)PrivateScope.Privatize();
+emitMasked(CGF, S);
+CGF.EmitOMPReductionClauseFinal(S, /*ReductionKind=*/OMPD_parallel);
+  };
+  {
+auto LPCRegion =
+CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
+emitCommonOMPParallelDirective(*this, S, OMPD_masked, CodeGen,
+   emitEmptyBoundParameters);
+emitPostUpdateForReductionClause(*this, S,
+ [](CodeGenFunction &) { return nullptr; 
});
+  }
+  // Check for outer lastprivate conditional update.
+  checkForLastprivateConditionalUpdate(*this, S);
+}
+
 void CodeGenFunction::EmitOMPParallelSectionsDirective(
 const OMPParallelSectionsDirective ) {
   // Emit directive as a combined directive that consists of two implicit

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 4298eb6c2b714..dfd8b9e6e00a7 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3585,6 +3585,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   const OMPTargetTeamsDistributeSimdDirective );
   void EmitOMPGenericLoopDirective(const OMPGenericLoopDirective );
   void EmitOMPInteropDirective(const OMPInteropDirective );
+  void EmitOMPParallelMaskedDirective(const OMPParallelMaskedDirective );
 
   /// Emit device code for the target directive.
   static void EmitOMPTargetDeviceFunction(CodeGenModule ,

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index a31ceaeebd80a..10f0b532ebf3c 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2483,8 +2483,8 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 /// simd' | 'teams distribute parallel for simd' | 'teams distribute
 /// parallel for' | 'target teams' | 'target teams distribute' | 
'target
 /// teams distribute parallel for' | 'target teams distribute parallel
-/// for simd' | 'target teams distribute simd' | 'masked' {clause}
-/// annot_pragma_openmp_end
+/// for simd' | 'target teams distribute simd' | 'masked' |
+/// 'parallel masked' {clause} annot_pragma_openmp_end
 ///
 StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 ParsedStmtContext StmtCtx, bool ReadDirectiveWithinMetadirective) {

diff  --git a/clang/test/OpenMP/parallel_masked.cpp 

[PATCH] D143527: [OpenMP][5.1] Fix parallel masked is ignored #59939

2023-04-03 Thread Jose Manuel Monsalve Diaz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64549f0903e2: [OpenMP][5.1] Fix parallel masked is ignored 
#59939 (authored by randreshg, committed by josemonsalve2).
Herald added projects: clang, OpenMP.
Herald added subscribers: openmp-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143527

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/parallel_masked.cpp
  clang/test/OpenMP/parallel_masked_target.cpp
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Synchronization.cpp

Index: openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
===
--- openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
+++ openmp/libomptarget/DeviceRTL/src/Synchronization.cpp
@@ -520,6 +520,13 @@
 
 void __kmpc_end_master(IdentTy *Loc, int32_t TId) { FunctionTracingRAII(); }
 
+int32_t __kmpc_masked(IdentTy *Loc, int32_t TId, int32_t Filter) {
+  FunctionTracingRAII();
+  return omp_get_thread_num() == Filter;
+}
+
+void __kmpc_end_masked(IdentTy *Loc, int32_t TId) { FunctionTracingRAII(); }
+
 int32_t __kmpc_single(IdentTy *Loc, int32_t TId) {
   FunctionTracingRAII();
   return __kmpc_master(Loc, TId);
Index: openmp/libomptarget/DeviceRTL/include/Interface.h
===
--- openmp/libomptarget/DeviceRTL/include/Interface.h
+++ openmp/libomptarget/DeviceRTL/include/Interface.h
@@ -260,6 +260,10 @@
 
 void __kmpc_end_master(IdentTy *Loc, int32_t TId);
 
+int32_t __kmpc_masked(IdentTy *Loc, int32_t TId, int32_t Filter);
+
+void __kmpc_end_masked(IdentTy *Loc, int32_t TId);
+
 int32_t __kmpc_single(IdentTy *Loc, int32_t TId);
 
 void __kmpc_end_single(IdentTy *Loc, int32_t TId);
Index: clang/test/OpenMP/parallel_masked_target.cpp
===
--- /dev/null
+++ clang/test/OpenMP/parallel_masked_target.cpp
@@ -0,0 +1,112 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=52 -fopenmp-targets=nvptx64 -offload-device-only -x c -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+void foo();
+
+void masked() {
+#pragma target
+#pragma omp parallel masked
+{
+foo();
+}
+}
+
+void maskedFilter() {
+const int tid = 1;
+#pragma target
+#pragma omp parallel masked filter(tid)
+{
+foo();
+}
+}
+
+void master() {
+#pragma target
+#pragma omp parallel master
+{
+foo();
+}
+}
+// CHECK-LABEL: define {{[^@]+}}@masked
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB1:[0-9]+]], i32 0, ptr @.omp_outlined.)
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined.
+// CHECK-SAME: (ptr noalias noundef [[DOTGLOBAL_TID_:%.*]], ptr noalias noundef [[DOTBOUND_TID_:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = call i32 @__kmpc_masked(ptr @[[GLOB1]], i32 [[TMP1]], i32 0)
+// CHECK-NEXT:[[TMP3:%.*]] = icmp ne i32 [[TMP2]], 0
+// CHECK-NEXT:br i1 [[TMP3]], label [[OMP_IF_THEN:%.*]], label [[OMP_IF_END:%.*]]
+// CHECK:   omp_if.then:
+// CHECK-NEXT:call void (...) @foo()
+// CHECK-NEXT:call void @__kmpc_end_masked(ptr @[[GLOB1]], i32 [[TMP1]])
+// CHECK-NEXT:br label [[OMP_IF_END]]
+// CHECK:   omp_if.end:
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@maskedFilter
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TID:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 1, ptr [[TID]], align 4
+// CHECK-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB1]], i32 0, ptr @.omp_outlined..1)
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-SAME: (ptr noalias noundef [[DOTGLOBAL_TID_:%.*]], ptr noalias noundef [[DOTBOUND_TID_:%.*]]) #[[ATTR1]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:

[PATCH] D87338: [Driver][PGO] Driver support for de-Optimizing cold functions (PATCH 2/2)

2023-04-03 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu abandoned this revision.
myhsu added a comment.
Herald added subscribers: wlei, ormris, MaskRay.
Herald added a project: All.

just realized I haven't updated this patch for years. I'll come up with an 
up-to-date version when I have time.


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

https://reviews.llvm.org/D87338

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


[PATCH] D147068: Fix merging of member-like constrained friends across modules.

2023-04-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith closed this revision.
rsmith added a comment.

Refactoring and test landed in rGa07abe27b4d1d39ebb940a7f4e6235302444cbf0 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147068

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


[clang] fa95f20 - Update Clang 16 statuses

2023-04-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-04-03T15:31:20-04:00
New Revision: fa95f20f98c8dfd4d35590a724eb0eb7df64146a

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

LOG: Update Clang 16 statuses

Updates the C status tracking page for the recent release.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index a431508e6e16a..9ddd01b9fd445 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -783,7 +783,7 @@ C2x implementation status
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf;>N2508
-  Clang 16
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
@@ -842,7 +842,7 @@ C2x implementation status
 
   Unclear type relationship between a format specifier and its 
argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf;>N2562
-  Clang 16
+  Clang 16
 
 
 
@@ -869,7 +869,7 @@ C2x implementation status
 
   [[maybe_unused]] for labels
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2662.pdf;>N2662
-  Clang 16
+  Clang 16
 
 
   Zeros compare equal
@@ -1094,11 +1094,11 @@ C2x implementation status
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm;>N2927
-Clang 16
+Clang 16
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2930.pdf;>N2930
-Clang 16
+Clang 16
   
 
   Type annex tgmath narrowing macros with integer args v2
@@ -1165,7 +1165,7 @@ C2x implementation status
 
   Relax requirements for va_start
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf;>N2975
-  Clang 16
+  Clang 16
 
 
   Enhanced enumerations



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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:775-776
+static bool IsInsideImplicitFullTemplateSpecialization(const DeclContext *DC) {
+  auto *CTSDecl = dyn_cast_or_null(
+  DC->getOuterLexicalRecordContext());
+  return CTSDecl && !isa(CTSDecl) &&

rsmith wrote:
> This doesn't look right to me; there could be a class template nested inside 
> a non-templated class, so I think you would need to walk up the enclosing 
> `DeclContext`s one by one checking each in turn. But, we might be inside a 
> function template specialization or variable template specialization instead, 
> in some weird cases:
> 
> ```
> template concept C = true;
> template auto L = [] U>() {};
> struct Q {
>   template U> friend constexpr auto decltype(L)::operator()() 
> const;
> };
> ```
> 
> ... so I think we want a different approach than looking for an enclosing 
> class template specialization declaration.
> 
> Can we skip this check entirely, and instead always compute and substitute 
> the template instantiation arguments as is done below? That computation will 
> walk the enclosing contexts for us in a careful way that properly handles 
> cases like this lambda-in-variable-template situation. If we find we get zero 
> levels of template argument list, we can skip doing the actual substitution 
> as an optimization.
Sorry, that should be:
```
template concept C = true;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Can you also change www/cxx_status.html to list P2103R0 as supported in the 
most recent version of Clang rather than in some previous version?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `[any]` to `()[any]`

2023-04-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Looks great! LGTM except there's some dead code.




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:570-573
+if (const auto *ArraySubst =
+dyn_cast(Node->getSubExpr()))
+  if (const auto *DRE =
+  dyn_cast(ArraySubst->getBase()->IgnoreImpCasts())) {

These `dyn_cast`s are already checked by the matcher. They can be turned into 
`cast`s and this function can return `{DRE}` unconditionally.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1002
+
+  if (DREs.size() == 1)
+if (const auto *VD = dyn_cast(DREs.front()->getDecl())) {

Similarly, this check is redundant, it's already guaranteed by the matcher.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1077-1079
+  if (const auto *ArraySub = dyn_cast(Node->getSubExpr()))
+if (const auto *DRE =
+dyn_cast(ArraySub->getBase()->IgnoreImpCasts())) {

Same here!


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

https://reviews.llvm.org/D143128

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:775-776
+static bool IsInsideImplicitFullTemplateSpecialization(const DeclContext *DC) {
+  auto *CTSDecl = dyn_cast_or_null(
+  DC->getOuterLexicalRecordContext());
+  return CTSDecl && !isa(CTSDecl) &&

This doesn't look right to me; there could be a class template nested inside a 
non-templated class, so I think you would need to walk up the enclosing 
`DeclContext`s one by one checking each in turn. But, we might be inside a 
function template specialization or variable template specialization instead, 
in some weird cases:

```
template concept C = true;
template auto L = [] U>() {};
struct Q {
  template U> friend constexpr auto decltype(L)::operator()() const;
};
```

... so I think we want a different approach than looking for an enclosing class 
template specialization declaration.

Can we skip this check entirely, and instead always compute and substitute the 
template instantiation arguments as is done below? That computation will walk 
the enclosing contexts for us in a careful way that properly handles cases like 
this lambda-in-variable-template situation. If we find we get zero levels of 
template argument list, we can skip doing the actual substitution as an 
optimization.



Comment at: clang/lib/Sema/SemaOverload.cpp:1303
+OldTemplate->getTemplateParameters(), false, TPL_TemplateMatch,
+SourceLocation(), false /* PartialOrdering */);
 bool SameReturnType = Context.hasSameType(Old->getDeclaredReturnType(),

rsmith wrote:
> shafik wrote:
> > nit
> Just remove the final parameter; it has a default argument of `false` and no 
> other call site passes `false` here.  (I'm working on removing this parameter 
> in a different change.)
You can remove the `SourceLocation()` argument too; there's an identical 
default argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Aaron Ballman 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 rG5d8aaad4452f: [C2x] Implement support for empty brace 
initialization (WG14 N2900 and WG14… (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/array-init.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm;>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm;>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of 

[clang] 5d8aaad - [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-04-03T15:22:52-04:00
New Revision: 5d8aaad4452f60ba8902e921d9bed606713a8f26

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

LOG: [C2x] Implement support for empty brace initialization (WG14 N2900 and 
WG14 N3011)

This implements support for allowing {} to consistently zero initialize
objects. We already supported most of this work as a GNU extension, but
the C2x feature goes beyond what the GNU extension allowed.

The changes in this patch are:

* Removed the -Wgnu-empty-initializer warning group. The extension is
  now a C2x extension warning instead. Note that use of
  `-Wno-gnu-empty-initializer seems` to be quite low in the wild
(https://sourcegraph.com/search?q=context%3Aglobal+-file%3A.*test.*+%22-Wno-gnu-empty-initializer%22=standard=1=repo
  which currently only gives 8 hits total), so this is not expected to
  be an overly disruptive change. But I'm adding the clang vendors
  review group just in case this expectation is wrong.
* Reworded the diagnostic wording to be about a C2x extension, added a
  pre-C2x compat warning.
* Allow {} to zero initialize a VLA

This functionality is exposed as an extension in all older C modes
(same as the GNU extension was), but does *not* allow the extension for
VLA initialization in C++ due to concern about handling non-trivially
constructible types.

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

Added: 
clang/test/C/C2x/n2900_n3011.c
clang/test/C/C2x/n2900_n3011_2.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/Parse/ParseInit.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/array-init.c
clang/test/Sema/complex-init-list.c
clang/test/Sema/compound-literal.c
clang/test/Sema/flexible-array-init.c
clang/test/Sema/gnu-flags.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/vla.c
clang/test/SemaObjC/property.m
clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd9aae998a503..53a0541ed290a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -121,6 +121,18 @@ C2x Feature Support
   which introduces the ``bool``, ``static_assert``, ``alignas``, ``alignof``,
   and ``thread_local`` keywords in C2x.
 
+- Implemented `WG14 N2900 
`_
+  and `WG14 N3011 
`_
+  which allows for empty braced initialization in C.
+
+  .. code-block:: c
+
+struct S { int x, y } s = {}; // Initializes s.x and s.y to 0
+
+  As part of this change, the ``-Wgnu-empty-initializer`` warning group was
+  removed, as this is no longer a GNU extension but a C2x extension. You can
+  use ``-Wno-c2x-extensions`` to silence the extension warning instead.
+
 Non-comprehensive list of changes in this release
 -
 - Clang now saves the address of ABI-indirect function parameters on the stack,

diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f574b0f0171b7..bac77299671c5 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -130,6 +130,12 @@ def warn_cxx20_compat_consteval : Warning<
 def warn_missing_type_specifier : Warning<
   "type specifier missing, defaults to 'int'">,
   InGroup, DefaultIgnore;
+
+def ext_c_empty_initializer : Extension<
+  "use of an empty initializer is a C2x extension">, InGroup;
+def warn_c2x_compat_empty_initializer : Warning<
+  "use of an empty initializer is incompatible with C standards before C2x">,
+  InGroup, DefaultIgnore;
 }
 
 let CategoryName = "Nullability Issue" in {

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0d2829d64501f..31f64f4eceb7c 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -256,7 +256,6 @@ def EmptyBody : DiagGroup<"empty-body">;
 def Exceptions : DiagGroup<"exceptions">;
 def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">;
 
-def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;
 def ExtraTokens : DiagGroup<"extra-tokens">;
 def CXX98CompatExtraSemi : DiagGroup<"c++98-compat-extra-semi">;
@@ -1135,7 +1134,7 @@ def GNU : DiagGroup<"gnu", 

[PATCH] D147383: [clang-tidy] Allow bugprone-unchecked-optional-access to handle calls to `std::forward`

2023-04-03 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




Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:589-591
+  if (LocArg == nullptr) {
+return;
+  }

```
if (LocArg == nullptr)
return;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147383

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


[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 510574.
aaron.ballman marked 4 inline comments as done.
aaron.ballman added a comment.

Update based on review feedback:

- Added an assertion to codegen that a VLA with an initializer is an empty 
initializer
- Updated the codegen tests to use better identifiers
- Added a codegen test for empty initialization of VLA of structures


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

https://reviews.llvm.org/D147349

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/C/C2x/n2900_n3011.c
  clang/test/C/C2x/n2900_n3011_2.c
  clang/test/Sema/array-init.c
  clang/test/Sema/complex-init-list.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/flexible-array-init.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/vla.c
  clang/test/SemaObjC/property.m
  clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1083,11 +1083,11 @@
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm;>N2900
-Unknown
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm;>N3011
-Unknown
+Clang 17
   
 
   Not-so-magic: typeof
Index: clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
===
--- clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
+++ clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
@@ -28,37 +28,34 @@
   intel_sub_group_avc_sic_result_t result_sic = ss;
   intel_sub_group_avc_ime_result_single_reference_streamout_t sstreamout = v;
   intel_sub_group_avc_ime_result_dual_reference_streamout_t dstreamin_list = {0x0, 0x1};
-  intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list2 = {};
   intel_sub_group_avc_ime_single_reference_streamin_t dstreamin_list3 = {c};
   intel_sub_group_avc_ime_dual_reference_streamin_t dstreamin_list4 = {1};
 #ifdef EXT
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ref_result_t' with an expression of incompatible type '__private float'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_sic_result_t' with an expression of incompatible type '__private struct st'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_result_single_reference_streamout_t' with an expression of incompatible type '__private void *__private'}}
-// expected-warning@-14 {{excess elements in struct initializer}}
-// expected-error@-14 {{scalar initializer cannot be empty}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_single_reference_streamin_t' with an expression of incompatible type '__private char'}}
-// expected-error@-14 {{initializing '__private intel_sub_group_avc_ime_dual_reference_streamin_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_payload_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ref_payload_t' with an expression of incompatible type '__private float'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_sic_payload_t' with an expression of incompatible type '__private struct st'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_mce_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing '__private intel_sub_group_avc_ime_result_t' with an expression of incompatible type 'int'}}
+// expected-error@-13 {{initializing 

[PATCH] D147461: [Headers] Add some intrinsic function descriptions to immintrin.h

2023-04-03 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

FTR, I'll be working my way through a bunch of intrinsics over the next month 
or so, trying not to do too many at once. Mostly AVX2 but also some others.


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

https://reviews.llvm.org/D147461

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


[PATCH] D147461: [Headers] Add some intrinsic function descriptions to immintrin.h

2023-04-03 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: RKSimon, pengfei.
Herald added a project: All.
probinson requested review of this revision.

https://reviews.llvm.org/D147461

Files:
  clang/lib/Headers/immintrin.h

Index: clang/lib/Headers/immintrin.h
===
--- clang/lib/Headers/immintrin.h
+++ clang/lib/Headers/immintrin.h
@@ -284,18 +284,45 @@
 
 #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
 defined(__RDRND__)
+/// Returns a 16-bit hardware-generated random value.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDRAND  instruction.
+///
+/// \param __p
+///Pointer to a 16-bit location to place the random value.
+/// \returns 1 if the value was successfully generated, 0 otherwise.
 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
 _rdrand16_step(unsigned short *__p)
 {
   return (int)__builtin_ia32_rdrand16_step(__p);
 }
 
+/// Returns a 32-bit hardware-generated random value.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDRAND  instruction.
+///
+/// \param __p
+///Pointer to a 32-bit location to place the random value.
+/// \returns 1 if the value was successfully generated, 0 otherwise.
 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
 _rdrand32_step(unsigned int *__p)
 {
   return (int)__builtin_ia32_rdrand32_step(__p);
 }
 
+/// Returns a 64-bit hardware-generated random value.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDRAND  instruction.
+///
+/// \param __p
+///Pointer to a 64-bit location to place the random value.
+/// \returns 1 if the value was successfully generated, 0 otherwise.
 #ifdef __x86_64__
 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
 _rdrand64_step(unsigned long long *__p)
@@ -325,48 +352,108 @@
 #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
 defined(__FSGSBASE__)
 #ifdef __x86_64__
+/// Reads the FS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDFSBASE  instruction.
+///
+/// \returns The lower 32 bits of the FS base register.
 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _readfsbase_u32(void)
 {
   return __builtin_ia32_rdfsbase32();
 }
 
+/// Reads the FS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDFSBASE  instruction.
+///
+/// \returns The contents of the FS base register.
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _readfsbase_u64(void)
 {
   return __builtin_ia32_rdfsbase64();
 }
 
+/// Reads the GS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDGSBASE  instruction.
+///
+/// \returns The lower 32 bits of the GS base register.
 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _readgsbase_u32(void)
 {
   return __builtin_ia32_rdgsbase32();
 }
 
+/// Reads the GS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  RDGSBASE  instruction.
+///
+/// \returns The contents of the GS base register.
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _readgsbase_u64(void)
 {
   return __builtin_ia32_rdgsbase64();
 }
 
+/// Modifies the FS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  WRFSBASE  instruction.
+///
+/// \param __V
+///Value to use for the lower 32 bits of the FS base register.
 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _writefsbase_u32(unsigned int __V)
 {
   __builtin_ia32_wrfsbase32(__V);
 }
 
+/// Modifies the FS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  WRFSBASE  instruction.
+///
+/// \param __V
+///Value to use for the FS base register.
 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _writefsbase_u64(unsigned long long __V)
 {
   __builtin_ia32_wrfsbase64(__V);
 }
 
+/// Modifies the GS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  WRGSBASE  instruction.
+///
+/// \param __V
+///Value to use for the lower 32 bits of the GS base register.
 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 _writegsbase_u32(unsigned int __V)
 {
   __builtin_ia32_wrgsbase32(__V);
 }
 
+/// Modifies the GS base register.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  WRFSBASE  instruction.
+///
+/// \param __V
+///Value to use for GS base register.
 static __inline__ void __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
 

[PATCH] D146973: [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1196-1197
 
+  // If we are compiling for a GPU target we want to override the system 
headers
+  // with ones created by the 'libc' project if present.
+  if (!Args.hasArg(options::OPT_nostdinc) &&

jhuber6 wrote:
> tra wrote:
> > Please add a TODO with some details outlining what it's supposed to do, the 
> > issues we've discussed, and that this is intended to be a temporary 
> > solution (famous last words, I know).
> > 
> > 
> I'm not sure if we should consider this temporary, we simply need to ensure 
> that the headers in this directory are compatible with the host environment 
> somehow.
> we simply need to ensure that the headers in this directory are compatible 
> with the host environment somehow.

The problem is that you probably do not have the *correct* host environment to 
be compatible with, yet. You do need to compile the host headers with the 
host-specific macros defined and that will make some of the code in them 
uncompileable for NVPTX (e.g due to inline asm or unavailable builtins). 

Nor do we have the long-term solution for the "compatible, somehow" part, as 
we're replacing part of the host headers, implementation of which we do not 
control. 

We can drop the 'temporary' part, but I think the story here is far from over, 
so a prominent TODO is needed.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146973

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


[PATCH] D146973: [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Joseph Huber 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 rGf263bd8f7d4c: [Clang] Implicitly include LLVM libc headers 
for the GPU (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D146973?vs=509090=510560#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146973

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/gpu-libc-headers.c


Index: clang/test/Driver/gpu-libc-headers.c
===
--- /dev/null
+++ clang/test/Driver/gpu-libc-headers.c
@@ -0,0 +1,22 @@
+// REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp 
--sysroot=./ \
+// RUN: -fopenmp-targets=amdgcn-amd-amdhsa 
-Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx908  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp 
--sysroot=./ \
+// RUN: -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_70  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=nvptx64-nvidia-cuda -march=sm_70 -nogpulib 
--sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib 
--sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// CHECK-HEADERS: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"{{.*}}"-isysroot" "./"
+
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nogpuinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nostdinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nobuiltininc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// CHECK-HEADERS-DISABLED-NOT: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1157,6 +1157,24 @@
   if (JA.isOffloading(Action::OFK_HIP))
 getToolChain().AddHIPIncludeArgs(Args, CmdArgs);
 
+  // If we are compiling for a GPU target we want to override the system 
headers
+  // with ones created by the 'libc' project if present.
+  if (!Args.hasArg(options::OPT_nostdinc) &&
+  !Args.hasArg(options::OPT_nogpuinc) &&
+  !Args.hasArg(options::OPT_nobuiltininc) &&
+  (getToolChain().getTriple().isNVPTX() ||
+   getToolChain().getTriple().isAMDGCN())) {
+
+  // Add include/gpu-none-libc/* to our system include path. This lets us 
use
+  // GPU-specific system headers first. These headers should be made to be
+  // compatible with the host environment's headers.
+  SmallString<128> P(llvm::sys::path::parent_path(D.InstalledDir));
+  llvm::sys::path::append(P, "include");
+  llvm::sys::path::append(P, "gpu-none-llvm");
+  CmdArgs.push_back("-c-isystem");
+  CmdArgs.push_back(Args.MakeArgString(P));
+  }
+
   // If we are offloading to a target via OpenMP we need to include the
   // openmp_wrappers folder which contains alternative system headers.
   if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&


Index: clang/test/Driver/gpu-libc-headers.c
===
--- /dev/null
+++ clang/test/Driver/gpu-libc-headers.c
@@ -0,0 +1,22 @@
+// REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --sysroot=./ \
+// RUN: -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx908  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --sysroot=./ \
+// RUN: -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_70  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=nvptx64-nvidia-cuda -march=sm_70 -nogpulib --sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib --sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// CHECK-HEADERS: "-cc1"{{.*}}"-c-isystem" "{{.*}}include/gpu-none-llvm"{{.*}}"-isysroot" "./"
+
+// RUN:   %clang -### 

[clang] f263bd8 - [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-04-03T12:57:21-05:00
New Revision: f263bd8f7d4c82af9672803e6d8d57f25c929d00

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

LOG: [Clang] Implicitly include LLVM libc headers for the GPU

There is currently work to support basic `libc` functionality on the
GPU. Some basic information about the projects can be found at
https://libc.llvm.org/gpu_mode.html. Typically, including the system
headers on the GPU will result in an error. For this reason the LLVM
`libc` project will generate its own headers that can be used with the
GPU.

The problem is that these headers will use the same name as the system headers.
For that reason, D146970 places it in the `llvm-libc` subfolder. In order to
still pick these files up, this patch adds changes in clang to default to
searching this directory when targeting the GPU. This lets offloading languages
such as OpenMP use the system `string.h` when compiling for the host and then
the LLVM libc `string.h` when targeting the GPU.

Depends on D146970

Reviewed By: tra

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

Added: 
clang/test/Driver/gpu-libc-headers.c

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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41fe89337d1b1..a17db9b9ceb79 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1157,6 +1157,24 @@ void Clang::AddPreprocessingOptions(Compilation , 
const JobAction ,
   if (JA.isOffloading(Action::OFK_HIP))
 getToolChain().AddHIPIncludeArgs(Args, CmdArgs);
 
+  // If we are compiling for a GPU target we want to override the system 
headers
+  // with ones created by the 'libc' project if present.
+  if (!Args.hasArg(options::OPT_nostdinc) &&
+  !Args.hasArg(options::OPT_nogpuinc) &&
+  !Args.hasArg(options::OPT_nobuiltininc) &&
+  (getToolChain().getTriple().isNVPTX() ||
+   getToolChain().getTriple().isAMDGCN())) {
+
+  // Add include/gpu-none-libc/* to our system include path. This lets us 
use
+  // GPU-specific system headers first. These headers should be made to be
+  // compatible with the host environment's headers.
+  SmallString<128> P(llvm::sys::path::parent_path(D.InstalledDir));
+  llvm::sys::path::append(P, "include");
+  llvm::sys::path::append(P, "gpu-none-llvm");
+  CmdArgs.push_back("-c-isystem");
+  CmdArgs.push_back(Args.MakeArgString(P));
+  }
+
   // If we are offloading to a target via OpenMP we need to include the
   // openmp_wrappers folder which contains alternative system headers.
   if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&

diff  --git a/clang/test/Driver/gpu-libc-headers.c 
b/clang/test/Driver/gpu-libc-headers.c
new file mode 100644
index 0..c8f772f102d03
--- /dev/null
+++ b/clang/test/Driver/gpu-libc-headers.c
@@ -0,0 +1,22 @@
+// REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp 
--sysroot=./ \
+// RUN: -fopenmp-targets=amdgcn-amd-amdhsa 
-Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx908  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp 
--sysroot=./ \
+// RUN: -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_70  \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=nvptx64-nvidia-cuda -march=sm_70 -nogpulib 
--sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib 
--sysroot=./ %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HEADERS
+// CHECK-HEADERS: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"{{.*}}"-isysroot" "./"
+
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nogpuinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nostdinc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// RUN:   %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
+// RUN: -nobuiltininc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-HEADERS-DISABLED
+// CHECK-HEADERS-DISABLED-NOT: "-cc1"{{.*}}"-c-isystem" 
"{{.*}}include/gpu-none-llvm"



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


[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:51
+  // CHECK: define {{.*}} void @test_vla
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: %[[I:.+]] = alloca i32

so 'entry' isn't really a stable name AFAIK.  So this might fail in test 
configs that do the 'erase names' thing.  That said, a buildbot hasn't caught 
one of those in a long time, so *shrug*.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:55
+  // CHECK-NEXT: store i32 12, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM0:.+]] = load i32, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM1:.+]] = zext i32 %[[MEM0]] to i64

aaron.ballman wrote:
> erichkeane wrote:
> > These MEM# names are horrible to read :/  But the test is doing the right 
> > thing it appears.
> If you have suggestions for better names, I'm happy to use them.
`I`: `I_PTR`
`MEM0`: `I_VAL`
`MEM1`: `NUM_ELTS` (or `I_AS_64B`?).
`MEM3`: `COPY_BYTES`

Though, this all becomes a bit easier with 'i' in code being named `num_elts` 
or something.
`NUM_ELTS_PTR`
`NUM_ELTS`
`NUM_ELTS_EXT`
`BYTES_TO_COPY`




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

https://reviews.llvm.org/D147349

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


[PATCH] D143704: [flang] Feature list plugin

2023-04-03 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 510553.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143704

Files:
  flang/examples/CMakeLists.txt
  flang/examples/FeatureList/CMakeLists.txt
  flang/examples/FeatureList/FeatureList.cpp
  flang/test/CMakeLists.txt
  flang/test/Examples/feature-list-class.f90
  flang/test/Examples/feature-list-functions.f90

Index: flang/test/Examples/feature-list-functions.f90
===
--- /dev/null
+++ flang/test/Examples/feature-list-functions.f90
@@ -0,0 +1,76 @@
+! UNSUPPORTED: system-windows
+! REQUIRES: plugins, shell, examples
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangFeatureList%pluginext \
+! RUN:-plugin feature-list %s 2>&1 | FileCheck %s
+
+program list_features_test
+implicit none
+call test_sub(test_func(2, 3), 4)
+contains
+subroutine test_sub(a, b)
+integer, intent(in) :: a, b
+print "(I0)", a + b
+end subroutine
+
+integer function test_func(a, b)
+integer, intent(in) :: a, b
+test_func = a * b
+end function
+end program list_features_test
+
+! CHECK: Name: 19
+! CHECK-NEXT: Expr: 11
+! CHECK-NEXT: DataRef: 5
+! CHECK-NEXT: Designator: 5
+! CHECK-NEXT: ActualArg: 4
+! CHECK-NEXT: ActualArgSpec: 4
+! CHECK-NEXT: EntityDecl: 4
+! CHECK-NEXT: LiteralConstant: 4
+! CHECK-NEXT: ActionStmt: 3
+! CHECK-NEXT: Block: 3
+! CHECK-NEXT: DeclarationTypeSpec: 3
+! CHECK-NEXT: ExecutableConstruct: 3
+! CHECK-NEXT: ExecutionPart: 3
+! CHECK-NEXT: ExecutionPartConstruct: 3
+! CHECK-NEXT: ImplicitPart: 3
+! CHECK-NEXT: IntLiteralConstant: 3
+! CHECK-NEXT: IntegerTypeSpec: 3
+! CHECK-NEXT: IntrinsicTypeSpec: 3
+! CHECK-NEXT: SpecificationPart: 3
+! CHECK-NEXT: AttrSpec: 2
+! CHECK-NEXT: Call: 2
+! CHECK-NEXT: DeclarationConstruct: 2
+! CHECK-NEXT: DummyArg: 2
+! CHECK-NEXT: IntentSpec: 2
+! CHECK-NEXT: IntentSpec::Intent: 2
+! CHECK-NEXT: InternalSubprogram: 2
+! CHECK-NEXT: ProcedureDesignator: 2
+! CHECK-NEXT: SpecificationConstruct: 2
+! CHECK-NEXT: TypeDeclarationStmt: 2
+! CHECK-NEXT: AssignmentStmt: 1
+! CHECK-NEXT: CallStmt: 1
+! CHECK-NEXT: CharLiteralConstant: 1
+! CHECK-NEXT: ContainsStmt: 1
+! CHECK-NEXT: EndFunctionStmt: 1
+! CHECK-NEXT: EndProgramStmt: 1
+! CHECK-NEXT: EndSubroutineStmt: 1
+! CHECK-NEXT: Expr::Add: 1
+! CHECK-NEXT: Expr::Multiply: 1
+! CHECK-NEXT: Format: 1
+! CHECK-NEXT: FunctionReference: 1
+! CHECK-NEXT: FunctionStmt: 1
+! CHECK-NEXT: FunctionSubprogram: 1
+! CHECK-NEXT: ImplicitPartStmt: 1
+! CHECK-NEXT: ImplicitStmt: 1
+! CHECK-NEXT: InternalSubprogramPart: 1
+! CHECK-NEXT: MainProgram: 1
+! CHECK-NEXT: OutputItem: 1
+! CHECK-NEXT: PrefixSpec: 1
+! CHECK-NEXT: PrintStmt: 1
+! CHECK-NEXT: Program: 1
+! CHECK-NEXT: ProgramStmt: 1
+! CHECK-NEXT: ProgramUnit: 1
+! CHECK-NEXT: SubroutineStmt: 1
+! CHECK-NEXT: SubroutineSubprogram: 1
+! CHECK-NEXT: Variable: 1
Index: flang/test/Examples/feature-list-class.f90
===
--- /dev/null
+++ flang/test/Examples/feature-list-class.f90
@@ -0,0 +1,88 @@
+! UNSUPPORTED: system-windows
+! REQUIRES: plugins, shell, examples
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangFeatureList%pluginext \
+! RUN:-plugin feature-list %s 2>&1 | FileCheck %s
+
+module list_features_test
+implicit none
+
+type :: test_class_1
+integer :: a
+real :: b
+contains
+procedure :: sum => sum_test_class_1
+procedure :: set => set_values_test_class_1
+end type
+contains
+real function sum_test_class_1(self)
+class(test_class_1), intent(in) :: self
+sum_test_class_1 = self%a + self%b
+end function
+
+subroutine set_values_test_class_1(self, a, b)
+class(test_class_1), intent(out) :: self
+integer, intent(in) :: a, b
+self%a = a
+self%b = b
+end subroutine
+end module list_features_test
+
+! CHECK: Name: 32
+! CHECK-NEXT: DataRef: 11
+! CHECK-NEXT: Designator: 7
+! CHECK-NEXT: DeclarationTypeSpec: 6
+! CHECK-NEXT: Expr: 5
+! CHECK-NEXT: DeclarationConstruct: 4
+! CHECK-NEXT: EntityDecl: 4
+! CHECK-NEXT: IntrinsicTypeSpec: 4
+! CHECK-NEXT: SpecificationConstruct: 4
+! CHECK-NEXT: StructureComponent: 4
+! CHECK-NEXT: ActionStmt: 3
+! CHECK-NEXT: AssignmentStmt: 3
+! CHECK-NEXT: AttrSpec: 3
+! CHECK-NEXT: DummyArg: 3
+! CHECK-NEXT: ExecutableConstruct: 3
+! CHECK-NEXT: ExecutionPartConstruct: 3
+! CHECK-NEXT: ImplicitPart: 3
+! CHECK-NEXT: IntentSpec: 3
+! CHECK-NEXT: IntentSpec::Intent: 3
+! CHECK-NEXT: SpecificationPart: 3
+! CHECK-NEXT: TypeDeclarationStmt: 3
+! CHECK-NEXT: Variable: 3
+! CHECK-NEXT: Block: 2
+! CHECK-NEXT: ComponentDecl: 2
+! CHECK-NEXT: ComponentDefStmt: 2
+! CHECK-NEXT: ComponentOrFill: 2
+! CHECK-NEXT: ContainsStmt: 2
+! CHECK-NEXT: DataComponentDefStmt: 2
+! CHECK-NEXT: DeclarationTypeSpec::Class: 2
+! CHECK-NEXT: 

[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked 4 inline comments as done.
aaron.ballman added a comment.

In D147349#4240847 , @erichkeane 
wrote:

> So not necessary to this patch, but I suspect the non-trivially constructible 
> types could just be solved the same way we do for zero-init of these types in 
> fixed-size arrays, right?  Its a bit more complicated, but the IR is probably 
> just as do-able: https://godbolt.org/z/Gqf65xr8M
> There, in the in it of %6 is the only place the length matters, since it 
> looks like we do a 'begin/end' type emit for it.  %2 is kept as the 'current 
> element being processed', and %6 is the 'end', and %5 is the 'begin'.
>
> That said, only a few small comments/questions.

It's possible, but I'm also not convinced extending C++'s already inscrutable 
initialization rules is a good idea, especially given that it relates to VLAs 
(which are already a bit questionable as an extension to C++ IMO).




Comment at: clang/lib/CodeGen/CGExprAgg.cpp:1670
+// in C++, we can safely memset the array memory to zero.
+CGF.EmitNullInitialization(Dest.getAddress(), ExprToVisit->getType());
+return;

erichkeane wrote:
> I'd probably prefer an assert for 'initializer is empty' here to confirm 
> this, but else this seems fine.
I can add that assert, sure.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:41
+void test_zero_size_array() {
+  int unknown_size[] = {};
+  // CHECK: define {{.*}} void @test_zero_size_array

erichkeane wrote:
> This is strange... why is this not an error?  What is this supposed to mean?
Heh, this one took me a few minutes to convince myself is correct. This creates 
a zero-length array, which we support as an extension. There's a corresponding 
Sema test on n2900_n3011.c:18 that shows the behavior of the extension 
diagnostics in this case.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:55
+  // CHECK-NEXT: store i32 12, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM0:.+]] = load i32, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM1:.+]] = zext i32 %[[MEM0]] to i64

erichkeane wrote:
> These MEM# names are horrible to read :/  But the test is doing the right 
> thing it appears.
If you have suggestions for better names, I'm happy to use them.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:96
+void test_nested_structs() {
+  struct T t1 = { 1, {} };
+  struct T t2 = { 1, { 2, {} } };

erichkeane wrote:
> A VLA of these things still works right?  Is that worth a test?
I can add a test for that, sure.


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

https://reviews.llvm.org/D147349

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


[PATCH] D147411: [clang-tidy] Fix readability-static-accessed-through-instance check for anonymous structs

2023-04-03 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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147411

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


[PATCH] D147414: [python] Expose clang_Location_isInSystemHeader

2023-04-03 Thread Artur Ryt via Phabricator via cfe-commits
R2RT added a comment.

In D147414#4240343 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to land this on your behalf? If so, please let me 
> know what name and email address you would like for patch attribution.
>
> In D147414#4239453 , @R2RT wrote:
>
>> I thought about adding it into release notes, but recently Python section 
>> has got removed from ReleaseNotes.rst, so I am not sure what to do now: 
>> https://reviews.llvm.org/D142578
>
> The section was removed mostly because the python bindings weren't getting a 
> lot of updates. I think this deserves a release note, so let's add the python 
> bindings section back in and put a note under it for this.

I've brought back Python section with relevant note.

I have no idea how to land it, it is my first contribution here, so maybe it 
will be easier this way.
Please attribute it to Artur Ryt , thanks :)


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

https://reviews.llvm.org/D147414

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


[PATCH] D146973: [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1196-1197
 
+  // If we are compiling for a GPU target we want to override the system 
headers
+  // with ones created by the 'libc' project if present.
+  if (!Args.hasArg(options::OPT_nostdinc) &&

tra wrote:
> Please add a TODO with some details outlining what it's supposed to do, the 
> issues we've discussed, and that this is intended to be a temporary solution 
> (famous last words, I know).
> 
> 
I'm not sure if we should consider this temporary, we simply need to ensure 
that the headers in this directory are compatible with the host environment 
somehow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146973

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


[PATCH] D146973: [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1196-1197
 
+  // If we are compiling for a GPU target we want to override the system 
headers
+  // with ones created by the 'libc' project if present.
+  if (!Args.hasArg(options::OPT_nostdinc) &&

Please add a TODO with some details outlining what it's supposed to do, the 
issues we've discussed, and that this is intended to be a temporary solution 
(famous last words, I know).




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146973

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


[PATCH] D147419: [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

2023-04-03 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe51f46705e28: [clang-tidy] ignore NRVO const variables in 
performance-no-automatic-move. (authored by gnanabit, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147419

Files:
  clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
@@ -33,10 +33,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
 }
 
-Obj PositiveSelfConstValue() {
-  const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
+Obj PositiveCantNrvo(bool b) {
+  const Obj obj1;
+  const Obj obj2;
+  if (b) {
+return obj1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: constness of 'obj1' prevents automatic move [performance-no-automatic-move]
+  }
+  return obj2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj2' prevents automatic move [performance-no-automatic-move]
 }
 
 // FIXME: Ideally we would warn here too.
@@ -54,18 +59,32 @@
 // Negatives.
 
 StatusOr Temporary() {
-  return Make();
+  return Make();
 }
 
 StatusOr ConstTemporary() {
   return Make();
 }
 
-StatusOr Nrvo() {
+StatusOr ConvertingMoveConstructor() {
   Obj obj = Make();
   return obj;
 }
 
+Obj ConstNrvo() {
+  const Obj obj = Make();
+  return obj;
+}
+
+Obj NotNrvo(bool b) {
+  Obj obj1;
+  Obj obj2;
+  if (b) {
+return obj1;
+  }
+  return obj2;
+}
+
 StatusOr Ref() {
   Obj  = Make();
   return obj;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -275,6 +275,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed a false positive in :doc:`performance-no-automatic-move
+  ` when warning would be
+  emitted for a const local variable to which NRVO is applied.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
@@ -16,6 +16,12 @@
 
 namespace clang::tidy::performance {
 
+namespace {
+
+AST_MATCHER(VarDecl, isNRVOVariable) { return Node.isNRVOVariable(); }
+
+} // namespace
+
 NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -23,8 +29,9 @@
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
 
 void NoAutomaticMoveCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstLocalVariable =
+  const auto NonNrvoConstLocalVariable =
   varDecl(hasLocalStorage(), unless(hasType(lValueReferenceType())),
+  unless(isNRVOVariable()),
   hasType(qualType(
   isConstQualified(),
   hasCanonicalType(matchers::isExpensiveToCopy()),
@@ -48,7 +55,7 @@
cxxConstructExpr(
hasDeclaration(LValueRefCtor),
hasArgument(0, ignoringParenImpCasts(declRefExpr(
-  to(ConstLocalVariable)
+  to(NonNrvoConstLocalVariable)
.bind("ctor_call")),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] e51f467 - [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

2023-04-03 Thread Piotr Zegar via cfe-commits

Author: Logan Gnanapragasam
Date: 2023-04-03T17:01:59Z
New Revision: e51f46705e2876fbbdb59d4f1ba43fa6ecf78611

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

LOG: [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

In the following code:

```cc
struct Obj {
  Obj();
  Obj(const Obj &);
  Obj(Obj &&);
  virtual ~Obj();
};

Obj ConstNrvo() {
  const Obj obj;
  return obj;
}
```

performance-no-automatic-move warns about the constness of `obj`. However, NRVO
is applied to `obj`, so the `const` should have no effect on performance.

This change modifies the matcher to exclude NRVO variables.

#clang-tidy

Reviewed By: courbet, PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
index b9c411e26699..42bf8ff83186 100644
--- a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
@@ -16,6 +16,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::performance {
 
+namespace {
+
+AST_MATCHER(VarDecl, isNRVOVariable) { return Node.isNRVOVariable(); }
+
+} // namespace
+
 NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -23,8 +29,9 @@ NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef Name,
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
 
 void NoAutomaticMoveCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstLocalVariable =
+  const auto NonNrvoConstLocalVariable =
   varDecl(hasLocalStorage(), unless(hasType(lValueReferenceType())),
+  unless(isNRVOVariable()),
   hasType(qualType(
   isConstQualified(),
   hasCanonicalType(matchers::isExpensiveToCopy()),
@@ -48,7 +55,7 @@ void NoAutomaticMoveCheck::registerMatchers(MatchFinder 
*Finder) {
cxxConstructExpr(
hasDeclaration(LValueRefCtor),
hasArgument(0, ignoringParenImpCasts(declRefExpr(
-  to(ConstLocalVariable)
+  to(NonNrvoConstLocalVariable)
.bind("ctor_call")),
   this);
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8a82e4e5ca56..13a06efcf563 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -275,6 +275,10 @@ Changes in existing checks
   ` 
when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed a false positive in :doc:`performance-no-automatic-move
+  ` when warning would be
+  emitted for a const local variable to which NRVO is applied.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
index 6ca59b6bb902..d365f7de8b7c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
@@ -33,10 +33,15 @@ NonTemplate PositiveNonTemplateConstValue() {
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents 
automatic move [performance-no-automatic-move]
 }
 
-Obj PositiveSelfConstValue() {
-  const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents 
automatic move [performance-no-automatic-move]
+Obj PositiveCantNrvo(bool b) {
+  const Obj obj1;
+  const Obj obj2;
+  if (b) {
+return obj1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: constness of 'obj1' prevents 
automatic move [performance-no-automatic-move]
+  }
+  return obj2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj2' prevents 
automatic move [performance-no-automatic-move]
 }
 
 // FIXME: Ideally we would warn here too.
@@ -54,18 +59,32 @@ StatusOr PositiveStatusOrLifetimeExtension() {
 // Negatives.
 
 StatusOr Temporary() {
-  return Make();
+  return Make();
 }
 
 StatusOr ConstTemporary() {
   return Make();
 }
 
-StatusOr Nrvo() {
+StatusOr ConvertingMoveConstructor() {
   Obj obj = Make();
   return obj;
 }
 
+Obj ConstNrvo() {
+  const Obj 

[PATCH] D147414: [python] Expose clang_Location_isInSystemHeader

2023-04-03 Thread Artur Ryt via Phabricator via cfe-commits
R2RT updated this revision to Diff 510542.
R2RT added a comment.

Bring back Python section in release notes and document new 
`is_in_system_header` property.


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

https://reviews.llvm.org/D147414

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_location.py
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -436,6 +436,13 @@
 Sanitizers
 --
 
+Python Binding Changes
+--
+
+The following methods have been added:
+
+- `clang_Location_isInSystemHeader` exposed via `is_in_system_header` property
+  of `Location` class.
 
 Additional Information
 ==
Index: clang/bindings/python/tests/cindex/test_location.py
===
--- clang/bindings/python/tests/cindex/test_location.py
+++ clang/bindings/python/tests/cindex/test_location.py
@@ -7,6 +7,7 @@
 from clang.cindex import File
 from clang.cindex import SourceLocation
 from clang.cindex import SourceRange
+from clang.cindex import TranslationUnit
 from .util import get_cursor
 from .util import get_tu
 
@@ -103,3 +104,17 @@
 location3 = SourceLocation.from_position(tu, file, 1, 6)
 range3 = SourceRange.from_locations(location1, location3)
 self.assertNotEqual(range1, range3)
+
+def test_is_system_location(self):
+header = os.path.normpath('./fake/fake.h')
+tu = TranslationUnit.from_source('fake.c', 
[f'-isystem{os.path.dirname(header)}'], unsaved_files = [
+('fake.c', """
+#include 
+int one;
+"""),
+(header, "int two();")
+])
+one = get_cursor(tu, 'one')
+two = get_cursor(tu, 'two')
+self.assertFalse(one.location.is_in_system_header)
+self.assertTrue(two.location.is_in_system_header)
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -286,6 +286,11 @@
 """Get the file offset represented by this source location."""
 return self._get_instantiation()[3]
 
+@property
+def is_in_system_header(self):
+"""Returns true if the given source location is in a system header."""
+return conf.lib.clang_Location_isInSystemHeader(self)
+
 def __eq__(self, other):
 return conf.lib.clang_equalLocations(self, other)
 
@@ -4131,6 +4136,10 @@
[Cursor],
c_longlong),
 
+  ("clang_Location_isInSystemHeader",
+   [SourceLocation],
+   bool),
+
   ("clang_Type_getAlignOf",
[Type],
c_longlong),


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -436,6 +436,13 @@
 Sanitizers
 --
 
+Python Binding Changes
+--
+
+The following methods have been added:
+
+- `clang_Location_isInSystemHeader` exposed via `is_in_system_header` property
+  of `Location` class.
 
 Additional Information
 ==
Index: clang/bindings/python/tests/cindex/test_location.py
===
--- clang/bindings/python/tests/cindex/test_location.py
+++ clang/bindings/python/tests/cindex/test_location.py
@@ -7,6 +7,7 @@
 from clang.cindex import File
 from clang.cindex import SourceLocation
 from clang.cindex import SourceRange
+from clang.cindex import TranslationUnit
 from .util import get_cursor
 from .util import get_tu
 
@@ -103,3 +104,17 @@
 location3 = SourceLocation.from_position(tu, file, 1, 6)
 range3 = SourceRange.from_locations(location1, location3)
 self.assertNotEqual(range1, range3)
+
+def test_is_system_location(self):
+header = os.path.normpath('./fake/fake.h')
+tu = TranslationUnit.from_source('fake.c', [f'-isystem{os.path.dirname(header)}'], unsaved_files = [
+('fake.c', """
+#include 
+int one;
+"""),
+(header, "int two();")
+])
+one = get_cursor(tu, 'one')
+two = get_cursor(tu, 'two')
+self.assertFalse(one.location.is_in_system_header)
+self.assertTrue(two.location.is_in_system_header)
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -286,6 +286,11 @@
 """Get the file offset represented by this source location."""
 return self._get_instantiation()[3]
 
+@property
+def is_in_system_header(self):
+"""Returns true if the given source location is in a system header."""
+return 

[PATCH] D147411: [clang-tidy] Fix readability-static-accessed-through-instance check for anonymous structs

2023-04-03 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 510537.
AMS21 marked 2 inline comments as done.
AMS21 added a comment.

Implement suggested way of checking for anonymous structs
Add a new more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147411

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp
@@ -285,3 +285,60 @@
 // CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member
 
 } // namespace Bugzilla_48758
+
+// https://github.com/llvm/llvm-project/issues/61736
+namespace llvm_issue_61736
+{
+
+struct {
+  static void f() {}
+} AnonStruct, *AnonStructPointer;
+
+class {
+  public:
+  static void f() {}
+} AnonClass, *AnonClassPointer;
+
+void testAnonymousStructAndClass() {
+  AnonStruct.f();
+  AnonStructPointer->f();
+
+  AnonClass.f();
+  AnonClassPointer->f();
+}
+
+struct Embedded {
+  struct {
+static void f() {}
+  } static EmbeddedStruct, *EmbeddedStructPointer;
+
+  class {
+public:
+  static void f() {}
+  } static EmbeddedClass, *EmbeddedClassPointer;
+};
+
+void testEmbeddedAnonymousStructAndClass() {
+  Embedded::EmbeddedStruct.f();
+  Embedded::EmbeddedStructPointer->f();
+
+  Embedded::EmbeddedClass.f();
+  Embedded::EmbeddedClassPointer->f();
+
+  Embedded E;
+  E.EmbeddedStruct.f();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  llvm_issue_61736::Embedded::EmbeddedStruct.f();{{$}}
+  E.EmbeddedStructPointer->f();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  llvm_issue_61736::Embedded::EmbeddedStructPointer->f();{{$}}
+
+  E.EmbeddedClass.f();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  llvm_issue_61736::Embedded::EmbeddedClass.f();{{$}}
+  E.EmbeddedClassPointer->f();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  llvm_issue_61736::Embedded::EmbeddedClassPointer->f();{{$}}
+}
+
+} // namespace llvm_issue_61736
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -267,6 +267,10 @@
   string for ``Prefix`` or ``Suffix`` options could result in the style not
   being used.
 
+- Fixed an issue in :doc:`readability-static-accessed-through-instance
+  ` when using
+  anonymous structs or classes.
+
 - Fixed an issue in :doc:`google-readability-avoid-underscore-in-googletest-name
   ` when using
   ``DISABLED_`` in the test suite name.
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -58,7 +58,7 @@
   if (isa(BaseExpr))
 return;
 
-  QualType BaseType =
+  const QualType BaseType =
   BaseExpr->getType()->isPointerType()
   ? BaseExpr->getType()->getPointeeType().getUnqualifiedType()
   : BaseExpr->getType().getUnqualifiedType();
@@ -74,6 +74,11 @@
   std::string BaseTypeName =
   BaseType.getAsString(PrintingPolicyWithSupressedTag);
 
+  // Ignore anonymous structs/classes which will not have an identifier
+  const RecordDecl *RecDecl = BaseType->getAsCXXRecordDecl();
+  if (!RecDecl || RecDecl->getIdentifier() == nullptr)
+return;
+
   // Do not warn for CUDA built-in variables.
   if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8234
+ ParsedAttr , Sema ) {
+  // Target must have SVE.
+  if (!S.Context.getTargetInfo().hasFeature("zve32x")) {

I need to fix this comment.



Comment at: clang/lib/Sema/SemaType.cpp:8265
+  // The attribute vector size must match -mrvv-vector-bits.
+  // FIXME: LMUL from type and scale it.
+  if (VecSize != VScale->first * llvm::RISCV::RVVBitsPerBlock) {

aaron.ballman wrote:
> Should this be done as part of this patch (are we accepting code we shouldn't 
> be accepting)?
No. I need to phrase this FIXME better. I'm only accepting types that have 
LMUL=1. (length multiplier). This is enforced in `Type::isRVVVLSBuiltinType()` 
where there's another FIXME about LMUL=1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147419: [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

2023-04-03 Thread Logan Gnanapragasam via Phabricator via cfe-commits
gnanabit updated this revision to Diff 510532.
gnanabit added a comment.

Add release notes entry.

Thanks for the reviews! Happy to reword the release notes if they are unclear.

@courbet or @PiotrZSL, I don't have commit access. Can you land this patch for
me? Please use "Logan Gnanapragasam (gnana...@google.com)" to commit the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147419

Files:
  clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
@@ -33,10 +33,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
 }
 
-Obj PositiveSelfConstValue() {
-  const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
+Obj PositiveCantNrvo(bool b) {
+  const Obj obj1;
+  const Obj obj2;
+  if (b) {
+return obj1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: constness of 'obj1' prevents automatic move [performance-no-automatic-move]
+  }
+  return obj2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj2' prevents automatic move [performance-no-automatic-move]
 }
 
 // FIXME: Ideally we would warn here too.
@@ -54,18 +59,32 @@
 // Negatives.
 
 StatusOr Temporary() {
-  return Make();
+  return Make();
 }
 
 StatusOr ConstTemporary() {
   return Make();
 }
 
-StatusOr Nrvo() {
+StatusOr ConvertingMoveConstructor() {
   Obj obj = Make();
   return obj;
 }
 
+Obj ConstNrvo() {
+  const Obj obj = Make();
+  return obj;
+}
+
+Obj NotNrvo(bool b) {
+  Obj obj1;
+  Obj obj2;
+  if (b) {
+return obj1;
+  }
+  return obj2;
+}
+
 StatusOr Ref() {
   Obj  = Make();
   return obj;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -271,6 +271,10 @@
   ` when using
   ``DISABLED_`` in the test suite name.
 
+- Fixed a false positive in :doc:`performance-no-automatic-move
+  ` when warning would be
+  emitted for a const local variable to which NRVO is applied.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
@@ -16,6 +16,12 @@
 
 namespace clang::tidy::performance {
 
+namespace {
+
+AST_MATCHER(VarDecl, isNRVOVariable) { return Node.isNRVOVariable(); }
+
+} // namespace
+
 NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -23,8 +29,9 @@
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
 
 void NoAutomaticMoveCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstLocalVariable =
+  const auto NonNrvoConstLocalVariable =
   varDecl(hasLocalStorage(), unless(hasType(lValueReferenceType())),
+  unless(isNRVOVariable()),
   hasType(qualType(
   isConstQualified(),
   hasCanonicalType(matchers::isExpensiveToCopy()),
@@ -48,7 +55,7 @@
cxxConstructExpr(
hasDeclaration(LValueRefCtor),
hasArgument(0, ignoringParenImpCasts(declRefExpr(
-  to(ConstLocalVariable)
+  to(NonNrvoConstLocalVariable)
.bind("ctor_call")),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147307: [clang] Consider artificial always inline builtin as inline builtins

2023-04-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I'd be fine with just dropping the check for GNUInline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147307

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


[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-03 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 added a comment.

In D147395#4240227 , @hokein wrote:

> Thanks for the contribution!

It's quite interesting for me. Thanks for your time reviewing and your great 
advice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

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


[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-03 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 updated this revision to Diff 510521.
zhangyi1357 marked an inline comment as not done.
zhangyi1357 added a comment.

Try to fix the build problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +715,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node ) {
+  if (auto Value = uint32Value(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
@@ -375,6 +379,17 @@
 return std::nullopt;
   }
 
+  std::optional> uint32Value(Node , llvm::StringRef Desc) {
+if (auto Scalar = scalarValue(N, Desc)) {
+  unsigned long long Num;
+  if (!llvm::getAsUnsignedInteger(**Scalar, 0, Num)) {
+return Located(Num, Scalar->Range);
+  }
+}
+warning(Desc + " invalid number", N);
+return std::nullopt;
+  }
+
   // Try to parse a list of single scalar values, or just a single value.
   std::optional>> scalarValues(Node ) {
 std::vector> Result;
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints. (0 means no limit)
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -611,6 +611,11 @@
   Out.Apply.push_back([Value(**F.Designators)](const Params &, Config ) {
 C.InlayHints.Designators = Value;
   });
+if (F.TypeNameLimit)
+  Out.Apply.push_back(
+  [Value(**F.TypeNameLimit)](const Params &, Config ) {
+C.InlayHints.TypeNameLimit = Value;
+  });
   }
 
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,6 +147,8 @@
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
+// Limit the length of type names in inlay hints. (0 means no limit)
+uint32_t TypeNameLimit = 32;
   } InlayHints;
 };
 


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +715,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+

[PATCH] D147349: [C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

2023-04-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

So not necessary to this patch, but I suspect the non-trivially constructible 
types could just be solved the same way we do for zero-init of these types in 
fixed-size arrays, right?  Its a bit more complicated, but the IR is probably 
just as do-able: https://godbolt.org/z/Gqf65xr8M
There, in the in it of %6 is the only place the length matters, since it looks 
like we do a 'begin/end' type emit for it.  %2 is kept as the 'current element 
being processed', and %6 is the 'end', and %5 is the 'begin'.

That said, only a few small comments/questions.




Comment at: clang/lib/CodeGen/CGExprAgg.cpp:1670
+// in C++, we can safely memset the array memory to zero.
+CGF.EmitNullInitialization(Dest.getAddress(), ExprToVisit->getType());
+return;

I'd probably prefer an assert for 'initializer is empty' here to confirm this, 
but else this seems fine.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:41
+void test_zero_size_array() {
+  int unknown_size[] = {};
+  // CHECK: define {{.*}} void @test_zero_size_array

This is strange... why is this not an error?  What is this supposed to mean?



Comment at: clang/test/C/C2x/n2900_n3011_2.c:55
+  // CHECK-NEXT: store i32 12, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM0:.+]] = load i32, ptr %[[I]]
+  // CHECK-NEXT: %[[MEM1:.+]] = zext i32 %[[MEM0]] to i64

These MEM# names are horrible to read :/  But the test is doing the right thing 
it appears.



Comment at: clang/test/C/C2x/n2900_n3011_2.c:96
+void test_nested_structs() {
+  struct T t1 = { 1, {} };
+  struct T t2 = { 1, { 2, {} } };

A VLA of these things still works right?  Is that worth a test?


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

https://reviews.llvm.org/D147349

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


[PATCH] D147449: [include-cleaner] Only ignore builtins without a header

2023-04-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Certain standard library functions (e.g. std::move) are also implemented
as builtins. This patch moves filtering logic to the symbol->header
mapping phase to rather generate these references without any providers
only when we don't have a mapping.
That way we can also map them to header names mentioned in the builtin
mappings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147449

Files:
  clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -327,11 +327,5 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
-TEST(WalkAST, BuiltinSymbols) {
-  testWalk(R"cpp(
-extern "C" int __builtin_popcount(unsigned int) noexcept;
-  )cpp", "int x = ^__builtin_popcount(1);");
-}
-
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -93,12 +93,14 @@
   void $bar^bar($private^Private $p^p) {
 $foo^foo();
 std::$vector^vector $vconstructor^$v^v;
+$builtin^__builtin_popcount(1);
+std::$move^move(3);
   }
   )cpp");
   Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
-  namespace std { class vector {}; }
+  namespace std { class vector {}; int&& move(int&&); }
   )cpp");
   Inputs.ExtraFiles["private.h"] = guard(R"cpp(
 // IWYU pragma: private, include "path/public.h"
@@ -112,6 +114,7 @@
   auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(*tooling::stdlib::Header::named(""));
+  auto UtilitySTL = Header(*tooling::stdlib::Header::named(""));
   EXPECT_THAT(
   offsetToProviders(AST, SM),
   UnorderedElementsAre(
@@ -122,8 +125,9 @@
   Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
   Pair(Code.point("vector"), UnorderedElementsAre(VectorSTL)),
   Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL)),
-  Pair(Code.point("v"), UnorderedElementsAre(MainFile))
-  ));
+  Pair(Code.point("v"), UnorderedElementsAre(MainFile)),
+  Pair(Code.point("builtin"), testing::IsEmpty()),
+  Pair(Code.point("move"), UnorderedElementsAre(UtilitySTL;
 }
 
 TEST_F(WalkUsedTest, MultipleProviders) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -35,9 +35,6 @@
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
-// Don't report builtin symbols.
-if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
-  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
Index: clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
===
--- clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -10,18 +10,21 @@
 #include "TypesInternal.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
-#include 
+#include 
 #include 
 
 namespace clang::include_cleaner {
@@ -106,37 +109,68 @@
   return Results;
 }
 
-// Special-case the ambiguous standard library symbols (e.g. std::move) which
-// are not supported by the tooling stdlib lib.
-llvm::SmallVector>
-headersForSpecialSymbol(const Symbol , const SourceManager ,
-const PragmaIncludes *PI) {
-  if (S.kind() != Symbol::Declaration || 

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 510514.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/invalid_location.cpp

Index: clang/test/CoverageMapping/invalid_location.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/invalid_location.cpp
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -stdlib=libc++ -triple %itanium_abi_triple %s | FileCheck %s
+
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+0 ? T{} : T{};
+0 ? 1 : 2;
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
+
+// CHECK:  _ZN2S1IiE3fooEv:
+// CHECK-NEXT:   File 0, 11:21 -> 15:4 = #0
+// CHECK-NEXT:   File 0, 13:5 -> 13:6 = #0
+// CHECK-NEXT:   Branch,File 0, 13:5 -> 13:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 13:8 -> 13:9 = #1
+// FIXME: It's supposed to have two different counters for true and false
+//branches at line 13 as it has for line 14, shown below. It's missing
+//now because 'T{}' doesn't have a valid end location for now.
+//Once it's fixed, correct the following two "CHECK-NETX" and #3 and #2
+//may need to swap positions.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)
+
+// CHECK-NEXT:   File 0, 14:5 -> 14:6 = #0
+// CHECK-NEXT:   Branch,File 0, 14:5 -> 14:6 = 0, 0
+// CHECK-NEXT:   Gap,File 0, 14:8 -> 14:9 = #2
+// CHECK-NEXT:   File 0, 14:9 -> 14:10 = #2
+// CHECK-NEXT:   File 0, 14:13 -> 14:14 = (#0 - #2)
+
+// No crash for following example.
+// See https://github.com/llvm/llvm-project/issues/45481
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct S {
+friend bool operator<(const S&, const S&);
+friend bool operator==(const S&, const S&);
+};
+
+struct MyStruct {
+friend bool operator==(MyStruct const& lhs, MyStruct const& rhs) = delete;
+friend std::strong_ordering operator<=>(MyStruct const& lhs, MyStruct const& rhs) = default;
+S value;
+};
+
+void foo(MyStruct bar){
+(void)(bar <=> bar);
+}
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,13 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +631,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +699,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
  

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu marked an inline comment as done.
zequanwu added a comment.

In D147073#4240017 , @hans wrote:

> I'm not familiar with this code. I suppose the question is whether it's 
> reasonable for this code to expect that the source locations are always valid 
> or not?

Yes.

For `0 ? T{} : T{};`, the both branches have valid start location but 
invalid end location. See comments at 
https://github.com/llvm/llvm-project/issues/45481#issuecomment-1487267814.

For the `std::strong_ordering`, I found that `DeclRefExpr` in the 
ConditionalOperator's true branch has invalid start and end locations. It might 
because it's inside a `PseudoObjectExpr`. Maybe we should simply just skip 
visiting `PseudoObjectExpr`, I see that its begin and end location are the 
same. I'm not familiar with that expression, so, I just handled it by adding 
checks for validating begin and end locations.

  PseudoObjectExpr 0x629f3bf0 'const strong_ordering':'const class 
std::strong_ordering' lvalue
  |-BinaryOperator 0x629f3bd0 'const strong_ordering':'const class 
std::strong_ordering' lvalue '<=>'
  | |-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  | | `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  | `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
  | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  |-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
  | `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  |   `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  `-ConditionalOperator 0x629f3ba0 'const strong_ordering':'const class 
std::strong_ordering' lvalue
|-CXXOperatorCallExpr 0x629f3970 '_Bool' '==' adl
| |-ImplicitCastExpr 0x629f3958 '_Bool (*)(const S &, const S &)' 

| | `-DeclRefExpr 0x629f38d8 '_Bool (const S &, const S &)' lvalue 
Function 0x629f2a40 'operator==' '_Bool (const S &, const S &)'
| |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
| | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
| |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
| `-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
|   `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
| `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct MyStruct' 
lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
|-DeclRefExpr 0x629f3b80 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a4ed8 'equal' 'const 
strong_ordering':'const class std::strong_ordering'
`-ConditionalOperator 0x629f3b50 'const strong_ordering':'const class 
std::strong_ordering' lvalue
  |-CXXOperatorCallExpr 0x629f3ab0 '_Bool' '<' adl
  | |-ImplicitCastExpr 0x629f3a98 '_Bool (*)(const S &, const S &)' 

  | | `-DeclRefExpr 0x629f3a78 '_Bool (const S &, const S &)' lvalue 
Function 0x629f27a0 'operator<' '_Bool (const S &, const S &)'
  | |-OpaqueValueExpr 0x629f38a8 'const S':'const struct S' lvalue
  | | `-MemberExpr 0x629f3848 'const S':'const struct S' lvalue .value 
0x629f34d0
  | |   `-DeclRefExpr 0x629f3808 'const MyStruct':'const struct 
MyStruct' lvalue ParmVar 0x629f31b0 'lhs' 'const MyStruct &'
  | `-OpaqueValueExpr 0x629f38c0 'const S':'const struct S' lvalue
  |   `-MemberExpr 0x629f3878 'const S':'const struct S' lvalue .value 
0x629f34d0
  | `-DeclRefExpr 0x629f3828 'const MyStruct':'const struct 
MyStruct' lvalue ParmVar 0x629f3238 'rhs' 'const MyStruct &'
  |-DeclRefExpr 0x629f3b30 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a4c50 'less' 'const 
strong_ordering':'const class std::strong_ordering'
  `-DeclRefExpr 0x629f3ae8 'const strong_ordering':'const class 
std::strong_ordering' lvalue Var 0x629a5388 'greater' 'const 
strong_ordering':'const class std::strong_ordering'




Comment at: clang/test/CoverageMapping/invalid_location.cpp:31
+//now because 'T{}' doesn't have a valid end location for now.
+// CHECK-NETX:   File 0, 13:9 -> 13:14 = #3
+// CHECK-NETX:   File 0, 13:18 -> 13:23 = (#0 - #3)

hans 

[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-03 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 marked 2 inline comments as done.
zhangyi1357 added a comment.

In D147395#4240227 , @hokein wrote:

> Thanks for the contribution!

It's really interesting for me. Thanks for your time reviewing!




Comment at: clang-tools-extra/clangd/Config.h:151
+// Limit the length of type names in inlay hints.
+size_t TypeNameLimit = 32;
   } InlayHints;

hokein wrote:
> I would extend it a bit more -- 0 means no limit. 
> 
> Can you also add a unittest in `TEST(TypeHints, LongTypeName)` in 
> `InlayHintTests.cpp`? 
> 0 means no limit.
This is quite a good idea. I've done it.

For unittest, there is already `TEST(TypeHints, LongTypeName)` in 
`InlayHintTests.cpp`. Do you mean add more tests in the same `TEST` or another 
`TEST` with TypeNameLimit configured?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

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


[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-03 Thread Yi Zhang via Phabricator via cfe-commits
zhangyi1357 updated this revision to Diff 510508.
zhangyi1357 added a comment.

Add uint32Value() for uint32_t type parsing in config file.
For TypeNameLimit config, support no limit with value 0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -255,7 +255,7 @@
 F.Designators = *Value;
 });
 Dict.handle("TypeNameLimit", [&](Node ) {
-  if (auto Value = scalarValue(N, "TypeNameLimit"))
+  if (auto Value = uint32Value(N, "TypeNameLimit"))
 F.TypeNameLimit = *Value;
 });
 Dict.parse(N);
@@ -379,6 +379,17 @@
 return std::nullopt;
   }
 
+  std::optional> uint32Value(Node , llvm::StringRef Desc) {
+if (auto Scalar = scalarValue(N, Desc)) {
+  unsigned long long Num;
+  if (!llvm::getAsUnsignedInteger(**Scalar, 0, Num)) {
+return Located(Num, Scalar->Range);
+  }
+}
+warning(Desc + " invalid number", N);
+return std::nullopt;
+  }
+
   // Try to parse a list of single scalar values, or just a single value.
   std::optional>> scalarValues(Node ) {
 std::vector> Result;
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,8 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
-/// Limit the length of type name hints.
-std::optional> TypeNameLimit;
+/// Limit the length of type name hints. (0 means no limit)
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -614,7 +614,7 @@
 if (F.TypeNameLimit)
   Out.Apply.push_back(
   [Value(**F.TypeNameLimit)](const Params &, Config ) {
-C.InlayHints.TypeNameLimit = stoul(Value);
+C.InlayHints.TypeNameLimit = Value;
   });
   }
 
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,8 +147,8 @@
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
-// Limit the length of type names in inlay hints.
-size_t TypeNameLimit = 32;
+// Limit the length of type names in inlay hints. (0 means no limit)
+uint32_t TypeNameLimit = 32;
   } InlayHints;
 };
 


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < Cfg.InlayHints.TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -255,7 +255,7 @@
 F.Designators = *Value;
 });
 Dict.handle("TypeNameLimit", [&](Node ) {
-  if (auto Value = scalarValue(N, "TypeNameLimit"))
+  if (auto Value = uint32Value(N, "TypeNameLimit"))
 F.TypeNameLimit = *Value;
 });
 Dict.parse(N);
@@ -379,6 +379,17 @@
 return std::nullopt;
   }
 
+  std::optional> uint32Value(Node , llvm::StringRef Desc) {
+if (auto Scalar = scalarValue(N, Desc)) {
+  unsigned long long Num;
+  if 

[PATCH] D147417: [clang-tidy] Do not emit bugprone-exception-escape warnings from coroutines

2023-04-03 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp:91
+const auto d_ShouldNotDiag = [](const int a, const int b) -> task {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:30: warning: an exception may be thrown 
in function 'operator()' which should not throw exceptions
+  if (b == 0)

And based on ChuanqiXu comment, same here.

"All exceptions thrown in coroutine bodies are caught and
unhandled_exception member of the coroutine promise type is called."
This isn't expected behaviour, as it may hide exception.
Based on that we should assume, if there is noexcept, then it should not throw, 
and if its no noexcept, then it could throw. No point to change default 
behaviour then. 

Other option is to add check option to handle this.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147417

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


[PATCH] D147419: [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

2023-04-03 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Add release notes entry !.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147419

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


[PATCH] D147419: [clang-tidy] ignore NRVO const variables in performance-no-automatic-move.

2023-04-03 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

Current change is correct.
This check could be improved in future.
LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147419

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-04-03 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

Ping for review. Specifically, the option is renamed to `-mxcoff-roptr` and 
`-mno-xcoff-roptr` to indicate that this option only affects the `XCOFF` binary 
format, so it is expected to not affect `ELF` or other formats.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[clang] 82facc2 - [clang][Interp] Add missing static_assert message

2023-04-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-03T17:12:05+02:00
New Revision: 82facc2b2462441a83ca35d2d6ef1ab28244a1b3

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

LOG: [clang][Interp] Add missing static_assert message

This broke builders, e.g:
https://lab.llvm.org/buildbot/#builders/139/builds/38457

Added: 


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

Removed: 




diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 4b81e7d6be3b..06edcdeffa70 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -10,7 +10,7 @@ static_assert(gimme5() == 5, "");
 
 
 template constexpr T identity(T t) {
-  static_assert(true);
+  static_assert(true, "");
   return t;
 }
 static_assert(identity(true), "");



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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-03 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D144272: [clang][Interp] Ignore StaticAssertDecls

2023-04-03 Thread Timm Bäder 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 rG192c2c5c8947: [clang][Interp] Ignore StaticAssertDecls 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144272

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@
 static_assert(gimme5() == 5, "");
 
 
-template constexpr T identity(T t) { return t; }
+template constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static 
assertion failed}} \
+ // ref-error {{static assertion 
failed}} \
+ // expected-note {{evaluates to}} 
\
+ // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize(), "");
+static_assert(sameSize(), "");
+static_assert(sameSize(), ""); // expected-note {{in instantiation 
of function template specialization}} \
+   // ref-note {{in instantiation of 
function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -224,6 +224,9 @@
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+if (isa(D))
+  continue;
+
 const auto *VD = dyn_cast(D);
 if (!VD)
   return false;


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@
 static_assert(gimme5() == 5, "");
 
 
-template constexpr T identity(T t) { return t; }
+template constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static assertion failed}} \
+ // ref-error {{static assertion failed}} \
+ // expected-note {{evaluates to}} \
+ // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize(), "");
+static_assert(sameSize(), "");
+static_assert(sameSize(), ""); // expected-note {{in instantiation of function template specialization}} \
+   // ref-note {{in instantiation of function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -224,6 +224,9 @@
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+if (isa(D))
+  continue;
+
 const auto *VD = dyn_cast(D);
 if (!VD)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 192c2c5 - [clang][Interp] Ignore StaticAssertDecls

2023-04-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-03T16:56:58+02:00
New Revision: 192c2c5c89477e28d0129f37a7d262112585b353

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

LOG: [clang][Interp] Ignore StaticAssertDecls

They have already been handled before, but we can't just return false
when we encounter one.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 1735b9b0272b..6faa3f9a47a9 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -224,6 +224,9 @@ bool ByteCodeStmtGen::visitCompoundStmt(
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
+if (isa(D))
+  continue;
+
 const auto *VD = dyn_cast(D);
 if (!VD)
   return false;

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 2b44f42486d3..4b81e7d6be3b 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -9,11 +9,28 @@ constexpr int gimme5() {
 static_assert(gimme5() == 5, "");
 
 
-template constexpr T identity(T t) { return t; }
+template constexpr T identity(T t) {
+  static_assert(true);
+  return t;
+}
 static_assert(identity(true), "");
 static_assert(identity(true), ""); /// Compiled bytecode should be cached
 static_assert(!identity(false), "");
 
+template
+constexpr bool sameSize() {
+  static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static 
assertion failed}} \
+ // ref-error {{static assertion 
failed}} \
+ // expected-note {{evaluates to}} 
\
+ // ref-note {{evaluates to}}
+  return true;
+}
+static_assert(sameSize(), "");
+static_assert(sameSize(), "");
+static_assert(sameSize(), ""); // expected-note {{in instantiation 
of function template specialization}} \
+   // ref-note {{in instantiation of 
function template specialization}}
+
+
 constexpr auto add(int a, int b) -> int {
   return identity(a) + identity(b);
 }



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


[PATCH] D147302: [clang][dataflow] Add `create()` methods to `Environment` and `DataflowAnalysisContext`.

2023-04-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:215
   /// Creates an atomic boolean value.
-  AtomicBoolValue () {
-return takeOwnership(std::make_unique());
-  }
+  AtomicBoolValue () { return create(); 
}
 

ymandel wrote:
> Is there any reason for this function anymore or should we deprecate it (and 
> the Top version below)? Especially in this object which only used internally 
> and not by clients -- the extra two characters don't seem to justify a 
> function.
I had wondered the same thing. I've added `LLVM_DEPRECATED` to both.

(I'm not changing callers in this patch because I'd like to avoid expanding the 
size of the patch.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147302

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


[PATCH] D147302: [clang][dataflow] Add `create()` methods to `Environment` and `DataflowAnalysisContext`.

2023-04-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 510496.
mboehme marked an inline comment as done.
mboehme added a comment.

Changes in response to review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147302

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -312,8 +312,7 @@
 
   if (Member->getType()->isReferenceType()) {
 auto  = ThisLoc.getChild(*Member);
-Env.setValue(MemberLoc, Env.takeOwnership(std::make_unique(
-*InitStmtLoc)));
+Env.setValue(MemberLoc, Env.create(*InitStmtLoc));
   } else {
 auto  = ThisLoc.getChild(*Member);
 Env.setValue(MemberLoc, *InitStmtVal);
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -237,7 +237,7 @@
   Env.setStorageLocation(*S, *DeclLoc);
 } else {
   auto  = Env.createStorageLocation(*S);
-  auto  = Env.takeOwnership(std::make_unique(*DeclLoc));
+  auto  = Env.create(*DeclLoc);
   Env.setStorageLocation(*S, Loc);
   Env.setValue(Loc, Val);
 }
@@ -276,8 +276,7 @@
   // FIXME: reuse the ReferenceValue instead of creating a new one.
   if (auto *InitExprLoc =
   Env.getStorageLocation(*InitExpr, SkipPast::Reference)) {
-auto  =
-Env.takeOwnership(std::make_unique(*InitExprLoc));
+auto  = Env.create(*InitExprLoc);
 Env.setValue(Loc, Val);
   }
 } else if (auto *InitExprVal = Env.getValue(*InitExpr, SkipPast::None)) {
@@ -423,8 +422,8 @@
 
   auto  = Env.createStorageLocation(*S);
   Env.setStorageLocation(*S, Loc);
-  Env.setValue(Loc, Env.takeOwnership(std::make_unique(
-SubExprVal->getPointeeLoc(;
+  Env.setValue(Loc,
+   Env.create(SubExprVal->getPointeeLoc()));
   break;
 }
 case UO_AddrOf: {
@@ -437,8 +436,7 @@
 break;
 
   auto  = Env.createStorageLocation(*S);
-  auto  =
-  Env.takeOwnership(std::make_unique(*PointeeLoc));
+  auto  = Env.create(*PointeeLoc);
   Env.setStorageLocation(*S, PointerLoc);
   Env.setValue(PointerLoc, PointerVal);
   break;
@@ -468,8 +466,7 @@
 
 auto  = Env.createStorageLocation(*S);
 Env.setStorageLocation(*S, Loc);
-Env.setValue(Loc, Env.takeOwnership(
-  std::make_unique(*ThisPointeeLoc)));
+Env.setValue(Loc, Env.create(*ThisPointeeLoc));
   }
 
   void VisitReturnStmt(const ReturnStmt *S) {
@@ -523,8 +520,7 @@
 } else {
   auto  = Env.createStorageLocation(*S);
   Env.setStorageLocation(*S, Loc);
-  Env.setValue(Loc, Env.takeOwnership(
-std::make_unique(*VarDeclLoc)));
+  Env.setValue(Loc, Env.create(*VarDeclLoc));
 }
 return;
   }
@@ -558,8 +554,7 @@
 } else {
   auto  = Env.createStorageLocation(*S);
   Env.setStorageLocation(*S, Loc);
-  Env.setValue(
-  Loc, Env.takeOwnership(std::make_unique(MemberLoc)));
+  Env.setValue(Loc, Env.create(MemberLoc));
 }
   }
 
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -221,9 +221,9 @@
 /// Creates a symbolic value for an `optional` value using `HasValueVal` as the
 /// symbolic value of its "has_value" property.
 StructValue (Environment , BoolValue ) {
-  auto OptionalVal = std::make_unique();
-  setHasValue(*OptionalVal, HasValueVal);
-  return Env.takeOwnership(std::move(OptionalVal));
+  auto  = Env.create();
+  setHasValue(OptionalVal, HasValueVal);
+  return OptionalVal;
 }
 
 /// Returns the symbolic value that represents the "has_value" property of the
@@ -312,8 +312,8 @@
 return nullptr;
   auto  = Env.createStorageLocation(Ty);
   Env.setValue(ValueLoc, *ValueVal);
-  auto ValueRef = std::make_unique(ValueLoc);
-  OptionalVal.setProperty("value", 

[clang] b15a946 - [clang][Interp][NFC] Refactor VisitDeclRefExpr

2023-04-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-03T16:42:25+02:00
New Revision: b15a946b9f59f91518ae5e2cb6125592d9c1bf3c

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

LOG: [clang][Interp][NFC] Refactor VisitDeclRefExpr

Make it clearer that we only need to check for variables and parameters
if we don't have the easy case. Also only do the IsReference check if
necessary.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ee5dd73159a6..e620b4f9b2f6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1840,37 +1840,41 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 
 template 
 bool ByteCodeExprGen::VisitDeclRefExpr(const DeclRefExpr *E) {
-  const auto *Decl = E->getDecl();
+  const auto *D = E->getDecl();
+
+  if (const auto *ECD = dyn_cast(D)) {
+return this->emitConst(ECD->getInitVal(), E);
+  } else if (const auto *BD = dyn_cast(D)) {
+return this->visit(BD->getBinding());
+  } else if (const auto *FuncDecl = dyn_cast(D)) {
+const Function *F = getFunction(FuncDecl);
+return F && this->emitGetFnPtr(F, E);
+  }
+
   // References are implemented via pointers, so when we see a DeclRefExpr
   // pointing to a reference, we need to get its value directly (i.e. the
   // pointer to the actual value) instead of a pointer to the pointer to the
   // value.
-  bool IsReference = Decl->getType()->isReferenceType();
+  bool IsReference = D->getType()->isReferenceType();
 
-  if (auto It = Locals.find(Decl); It != Locals.end()) {
+  // Check for local/global variables and parameters.
+  if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
 
 if (IsReference)
   return this->emitGetLocal(PT_Ptr, Offset, E);
 return this->emitGetPtrLocal(Offset, E);
-  } else if (auto GlobalIndex = P.getGlobal(Decl)) {
+  } else if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference)
   return this->emitGetGlobal(PT_Ptr, *GlobalIndex, E);
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
-  } else if (const auto *PVD = dyn_cast(Decl)) {
+  } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
   if (IsReference)
 return this->emitGetParam(PT_Ptr, It->second, E);
   return this->emitGetPtrParam(It->second, E);
 }
-  } else if (const auto *ECD = dyn_cast(Decl)) {
-return this->emitConst(ECD->getInitVal(), E);
-  } else if (const auto *BD = dyn_cast(Decl)) {
-return this->visit(BD->getBinding());
-  } else if (const auto *FuncDecl = dyn_cast(Decl)) {
-const Function *F = getFunction(FuncDecl);
-return F && this->emitGetFnPtr(F, E);
   }
 
   return false;



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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: erichkeane, rjmccall, efriedma.
aaron.ballman added a comment.

Adding Erich as attributes code owner and John/Eli as ABI code owners.




Comment at: clang/lib/Sema/SemaType.cpp:8265
+  // The attribute vector size must match -mrvv-vector-bits.
+  // FIXME: LMUL from type and scale it.
+  if (VecSize != VScale->first * llvm::RISCV::RVVBitsPerBlock) {

Should this be done as part of this patch (are we accepting code we shouldn't 
be accepting)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[clang] 8c8b4d2 - [Clang] Update test checks (NFC)

2023-04-03 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-04-03T16:33:34+02:00
New Revision: 8c8b4d24f019e51900f15e008b52a05cf1e66381

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

LOG: [Clang] Update test checks (NFC)

These were affected by 9b5ff4436e446e9df97ee37b3bcf9ba029c7d9aa.

Added: 


Modified: 
clang/test/OpenMP/bug54082.c

Removed: 




diff  --git a/clang/test/OpenMP/bug54082.c b/clang/test/OpenMP/bug54082.c
index 64702017dcde6..beaebeb21cb77 100644
--- a/clang/test/OpenMP/bug54082.c
+++ b/clang/test/OpenMP/bug54082.c
@@ -99,7 +99,7 @@ void foo() {
 // CHECK-NEXT:[[CONV:%.*]] = inttoptr i64 [[TMP1]] to ptr
 // CHECK-NEXT:[[DOTX__VOID_ADDR:%.*]] = tail call ptr @__kmpc_alloc(i32 
[[TMP0]], i64 8, ptr [[CONV]])
 // CHECK-NEXT:call void @__kmpc_for_static_init_4(ptr nonnull 
@[[GLOB1:[0-9]+]], i32 [[TMP0]], i32 34, ptr nonnull [[DOTOMP_IS_LAST]], ptr 
nonnull [[DOTOMP_LB]], ptr nonnull [[DOTOMP_UB]], ptr nonnull 
[[DOTOMP_STRIDE]], i32 1, i32 1)
-// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4, !tbaa 
[[TBAA6]]
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
 // CHECK-NEXT:[[COND:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP2]], i32 
1023)
 // CHECK-NEXT:store i32 [[COND]], ptr [[DOTOMP_UB]], align 4, !tbaa 
[[TBAA6]]
 // CHECK-NEXT:call void @__kmpc_for_static_fini(ptr nonnull @[[GLOB1]], 
i32 [[TMP0]])



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


[clang-tools-extra] f323e7f - [include-cleaner] Treat member operator calls as implicit

2023-04-03 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-04-03T16:27:23+02:00
New Revision: f323e7f3ca760be786d2584c926edade34c3fbde

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

LOG: [include-cleaner] Treat member operator calls as implicit

26ff268b80c589fd9f71c1c214af77cd972642ca treated member operator calls
as explicit, while trying to treat them the same way as regular member
expressions, which should've been implicit.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index 8a1dd77176cd..ab1476ea0997 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -95,14 +95,15 @@ class ASTWalker : public RecursiveASTVisitor {
   // to them doesn't count as uses (generally the type should provide them, so
   // ignore them).
   // Unless we're using an operator defined as a member, in such cases treat
-  // this as a regular reference.
+  // these as regular member references.
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 if (!WalkUpFromCXXOperatorCallExpr(S))
   return false;
 if (auto *CD = S->getCalleeDecl()) {
   if (llvm::isa(CD)) {
 // Treat this as a regular member reference.
-report(S->getOperatorLoc(), 
getMemberProvider(S->getArg(0)->getType()));
+report(S->getOperatorLoc(), getMemberProvider(S->getArg(0)->getType()),
+   RefType::Implicit);
   } else {
 report(S->getOperatorLoc(), llvm::dyn_cast(CD),
RefType::Implicit);

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index fceec670076c..ac2085d82c1d 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -296,12 +296,12 @@ TEST(WalkAST, Operator) {
   testWalk(
   "struct string { friend int $implicit^operator+(string, string); }; ",
   "int k = string() ^+ string();");
-  // Unless they're members, we treat them as regular member expr calls.
-  testWalk("struct $explicit^string {int operator+(string); }; ",
+  // Treat member operators as regular member expr calls.
+  testWalk("struct $implicit^string {int operator+(string); }; ",
"int k = string() ^+ string();");
   // Make sure usage is attributed to the alias.
   testWalk(
-  "struct string {int operator+(string); }; using $explicit^foo = string;",
+  "struct string {int operator+(string); }; using $implicit^foo = string;",
   "int k = foo() ^+ string();");
 }
 



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


[PATCH] D146595: [clang] Add "transparent_stepping" attribute

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D146595#4237228 , @aprantl wrote:

> I think `debug_trampoline` both captures the semantics and makes it clear 
> that this is related to debugging.

I'd be fine with this, or `transparent_debug_stepping`, etc. Just something 
other than `transparent` or `trampoline` as those are rather generic terms.

In D146595#4228425 , @arphaman wrote:

> How is this attribute going to handle a trampoline that performs a virtual 
> dispatch from C++ call into Swift? In that case, the target is not known.

Additionally, should you be allowed to write this on a lambda to skip over the 
function call operator? (If so, you may need to move the attribute from the 
lambda declaration onto the function call operator.)




Comment at: clang/include/clang/Basic/Attr.td:775
+  let Spellings = [Clang<"transparent_stepping">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [TransparentSteppingDocs];

ObjC method decls as well?



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:71
 
+static bool getIsTransparentStepping(const Decl *D) {
+  if (!D)

How about something like this ("get is" just sounds weird to me)?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6773-6777
+static void handleTransparentStepping(Sema , Decl *D,
+  const ParsedAttr ) {
+  D->addAttr(::new (S.Context)
+ TransparentSteppingAttr(S.Context, AL));
+}

Can be removed entirely if we don't have any custom checking logic for it. 
Instead, do `let SimpleHandler = 1;` in the attribute definition in Attr.td.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:9090-9092
+  case ParsedAttr::AT_TransparentStepping:
+handleTransparentStepping(S, D, AL);
+break;

This can also be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146595

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


[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-04-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D144269#4237539 , @dkrupp wrote:

> This is a totally rewritten version of the patch which solely relies on the 
> existing "interestingness" utility to track back the taint propagation.  (And 
>  does not introduce a new FlowID in the ProgramState as requested in the 
> reviews.)
>
> -The new version also places a Note, when the taintedness is propagated to an 
> argument or to a return value. So it should be easier for the user to follow 
> how the taint information is spreading. 
> -"The taint originated here" is printed correctly at the taint source 
> function, which introduces taintedness. (Main goal of this patch.)
>
> Implementation:
> -The createTaintPreTag() function places a NoteTag at the taint propagation 
> function calls, if taintedness is propagated. Then at report creation, the 
> tainted arguments are marked interesting if propagated taintedness is 
> relevant for the bug report.
>
> - The isTainted() function is extended to return the actually tainted 
> SymbolRef. This is important to be able to consistently mark relevant symbol 
> interesting which carries the taintedness in a complex expression.

So this is how you circumvent introducing "transitive interestingness", because 
now you know which symbol to track.

> -createTaintPostTag(..) function places a NoteTag to the taint generating 
> function calls to mark them interesting if they are relevant for a 
> taintedness report. So if they propagated taintedness to interesting 
> symbol(s).
>
> The tests are passing and the reports on the open source projects are much 
> better understandable than before (twin, tmux, curl):
>
> https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=curl_curl-7_66_0_dkrupp_taint_origin_fix_new=tmux_2.6_dkrupp_taint_origin_fix_new=twin_v0.8.1_dkrupp_taint_origin_fix_new=on=New=%2auntrusted%2a=Out%20of%20bound%20memory%20access%20%28index%20is%20tainted%29

I've looked at the results you attached and they look good to me.

Do you have an example where two tainted values are contributing to the same 
bug? Something like:

  n <- read();
  m <- read();
  malloc(n+m)

Will both of these values tracked back? What do the notes look like?

---

All in all, I'm pleased to see the improvements. It looks much better now IMO.
Using two NoteTags cleans up the implementation quite a bit, kudos.
I don't think there are major problems with this implementation, so I decided 
to spew your code with my nitpicks :D

Remember to clang-format your code. See 
`clang/tools/clang-format/clang-format-diff.py`.
And there are a few overloads of `getNoteTag()`, and there could be a better 
fit for usecases; you should decide.

I also find it difficult to track how a variable got tainted across assignments 
and computations like in this 

 case.
This observation is completely orthogonal to your patch, I'm just noting it. it 
was bad previously as well.
Maybe we could have a visitor for explaining the taint tracking across 
assignments and computations to complement the NoteTag.

I hope I didn't miss much this time :D




Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:238-244
+if (kind == OOB_Tainted)
+  BT.reset(
+  new BugType(this, "Out-of-bound access", categories::TaintedData));
+else
+  BT.reset(
+  new BugType(this, "Out-of-bound access", categories::LogicError));
+  }





Comment at: clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp:45
 
-void DivZeroChecker::reportBug(
-const char *Msg, ProgramStateRef StateZero, CheckerContext ,
-std::unique_ptr Visitor) const {
+void DivZeroChecker::reportBug(const char *Msg, std::string Category,
+   ProgramStateRef StateZero, CheckerContext ,

It feels odd to have both `const char*` and a `std::string` on the same line.
Should we update `const char*` to a more sophisticated type?

I'm thinking of `StringRef`. It seems like that type should be used for the 
`Category` as well since the `PathSensitiveBugReport` constructor takes that, 
so we don't need to have an owning type here.



Comment at: clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp:91-96
+  SymbolRef TSR = isTainted(C.getState(), *DV);
+  if ((stateNotZero && stateZero && TSR)) {
+reportBug("Division by a tainted value, possibly zero",
+  categories::TaintedData, stateZero, C, TSR);
 return;
   }





Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:138-139

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Hmmm, is this effectively `std::has_unique_object_representations` (ensuring 
that all bits of the object representation contribute to the value)?




Comment at: clang/lib/AST/Type.cpp:2610
+
+  if (const auto *RecordDecl = CanonicalType->getAsCXXRecordDecl()) {
+if (!RecordDecl->isStandardLayout() || RecordDecl->isUnion())

Dependent types should probably return `false`?



Comment at: clang/lib/AST/Type.cpp:2640
+
+  return false;
+}

I think this might be missing cases, like complex integers, scoped 
enumerations, vector types?, pointer types, atomic versions of these types...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

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


[PATCH] D145860: [clang][Interp] Fix initializing fields after base class members

2023-04-03 Thread Timm Bäder 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 rG056042d21b72: [clang][Interp] Fix initializing fields after 
base class members (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D145860?vs=504408=510487#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145860

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/cxx20.cpp


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@
   constexpr Outer O;
   static_assert(O.bar() == 12);
 }
+
+namespace BaseAndFieldInit {
+  struct A {
+int a;
+  };
+
+  struct B : A {
+int b;
+  };
+
+  struct C : B {
+int c;
+  };
+
+  constexpr C c = {1,2,3};
+  static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@
 
 if (!this->emitPopPtr(Initializer))
   return false;
+++InitIndex;
   } else {
 // Initializer for a direct base class.
 if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  // Base initializers don't increase InitIndex, since they don't count
+  // into the Record's fields.
 } else {
   const Record::Field *FieldToInit = R->getField(InitIndex);
   // Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  ++InitIndex;
 }
   }
-  ++InitIndex;
 }
 
 return true;


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@
   constexpr Outer O;
   static_assert(O.bar() == 12);
 }
+
+namespace BaseAndFieldInit {
+  struct A {
+int a;
+  };
+
+  struct B : A {
+int b;
+  };
+
+  struct C : B {
+int c;
+  };
+
+  constexpr C c = {1,2,3};
+  static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@
 
 if (!this->emitPopPtr(Initializer))
   return false;
+++InitIndex;
   } else {
 // Initializer for a direct base class.
 if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  // Base initializers don't increase InitIndex, since they don't count
+  // into the Record's fields.
 } else {
   const Record::Field *FieldToInit = R->getField(InitIndex);
   // Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  ++InitIndex;
 }
   }
-  ++InitIndex;
 }
 
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 056042d - [clang][Interp] Fix initializing fields after base class members

2023-04-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-03T15:55:11+02:00
New Revision: 056042d21b72a86653f88719c0b54b07e35d2144

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

LOG: [clang][Interp] Fix initializing fields after base class members

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e5c9b2637b85..ee5dd73159a6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1384,6 +1384,7 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 
 if (!this->emitPopPtr(Initializer))
   return false;
+++InitIndex;
   } else {
 // Initializer for a direct base class.
 if (const Record::Base *B = R->getBase(Init->getType())) {
@@ -1395,6 +1396,8 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  // Base initializers don't increase InitIndex, since they don't count
+  // into the Record's fields.
 } else {
   const Record::Field *FieldToInit = R->getField(InitIndex);
   // Non-primitive case. Get a pointer to the field-to-initialize
@@ -1407,9 +1410,9 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 
   if (!this->emitPopPtr(Initializer))
 return false;
+  ++InitIndex;
 }
   }
-  ++InitIndex;
 }
 
 return true;

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 6cb106adf59c..37be7a41bf75 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -583,3 +583,20 @@ namespace Destructors {
   constexpr Outer O;
   static_assert(O.bar() == 12);
 }
+
+namespace BaseAndFieldInit {
+  struct A {
+int a;
+  };
+
+  struct B : A {
+int b;
+  };
+
+  struct C : B {
+int c;
+  };
+
+  constexpr C c = {1,2,3};
+  static_assert(c.a == 1 && c.b == 2 && c.c == 3);
+}



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


[clang-tools-extra] 26ff268 - [include-cleaner] Report references to operator calls as implicit

2023-04-03 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-04-03T15:49:28+02:00
New Revision: 26ff268b80c589fd9f71c1c214af77cd972642ca

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

LOG: [include-cleaner] Report references to operator calls as implicit

Missing these references can result in false negatives in the used-ness
analysis and break builds.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index b10c722b6653a..8a1dd77176cdf 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -91,14 +91,23 @@ class ASTWalker : public RecursiveASTVisitor {
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  // Operators are almost always ADL extension points and by design references
+  // to them doesn't count as uses (generally the type should provide them, so
+  // ignore them).
+  // Unless we're using an operator defined as a member, in such cases treat
+  // this as a regular reference.
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 if (!WalkUpFromCXXOperatorCallExpr(S))
   return false;
-
-// Operators are always ADL extension points, by design references to them
-// doesn't count as uses (generally the type should provide them).
-// Don't traverse the callee.
-
+if (auto *CD = S->getCalleeDecl()) {
+  if (llvm::isa(CD)) {
+// Treat this as a regular member reference.
+report(S->getOperatorLoc(), 
getMemberProvider(S->getArg(0)->getType()));
+  } else {
+report(S->getOperatorLoc(), llvm::dyn_cast(CD),
+   RefType::Implicit);
+  }
+}
 for (auto *Arg : S->arguments())
   if (!TraverseStmt(Arg))
 return false;

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index fd6c6da9d5509..fceec670076c9 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -291,13 +291,18 @@ TEST(WalkAST, ConstructExprs) {
 }
 
 TEST(WalkAST, Operator) {
-  // References to operators are not counted as uses.
-  testWalk("struct string {}; int operator+(string, string);",
-   "int k = string() ^+ string();");
-  testWalk("struct string {int operator+(string); }; ",
-   "int k = string() ^+ string();");
-  testWalk("struct string { friend int operator+(string, string); }; ",
+  // Operator calls are marked as implicit references as they're ADL-used and
+  // type should be providing them.
+  testWalk(
+  "struct string { friend int $implicit^operator+(string, string); }; ",
+  "int k = string() ^+ string();");
+  // Unless they're members, we treat them as regular member expr calls.
+  testWalk("struct $explicit^string {int operator+(string); }; ",
"int k = string() ^+ string();");
+  // Make sure usage is attributed to the alias.
+  testWalk(
+  "struct string {int operator+(string); }; using $explicit^foo = string;",
+  "int k = foo() ^+ string();");
 }
 
 TEST(WalkAST, VarDecls) {



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


[PATCH] D146973: [Clang] Implicitly include LLVM libc headers for the GPU

2023-04-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146973

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


[PATCH] D147144: [include-cleaner] Report references to operator calls as implicit

2023-04-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26ff268b80c5: [include-cleaner] Report references to 
operator calls as implicit (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147144

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -291,13 +291,18 @@
 }
 
 TEST(WalkAST, Operator) {
-  // References to operators are not counted as uses.
-  testWalk("struct string {}; int operator+(string, string);",
-   "int k = string() ^+ string();");
-  testWalk("struct string {int operator+(string); }; ",
-   "int k = string() ^+ string();");
-  testWalk("struct string { friend int operator+(string, string); }; ",
+  // Operator calls are marked as implicit references as they're ADL-used and
+  // type should be providing them.
+  testWalk(
+  "struct string { friend int $implicit^operator+(string, string); }; ",
+  "int k = string() ^+ string();");
+  // Unless they're members, we treat them as regular member expr calls.
+  testWalk("struct $explicit^string {int operator+(string); }; ",
"int k = string() ^+ string();");
+  // Make sure usage is attributed to the alias.
+  testWalk(
+  "struct string {int operator+(string); }; using $explicit^foo = string;",
+  "int k = foo() ^+ string();");
 }
 
 TEST(WalkAST, VarDecls) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -91,14 +91,23 @@
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  // Operators are almost always ADL extension points and by design references
+  // to them doesn't count as uses (generally the type should provide them, so
+  // ignore them).
+  // Unless we're using an operator defined as a member, in such cases treat
+  // this as a regular reference.
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 if (!WalkUpFromCXXOperatorCallExpr(S))
   return false;
-
-// Operators are always ADL extension points, by design references to them
-// doesn't count as uses (generally the type should provide them).
-// Don't traverse the callee.
-
+if (auto *CD = S->getCalleeDecl()) {
+  if (llvm::isa(CD)) {
+// Treat this as a regular member reference.
+report(S->getOperatorLoc(), 
getMemberProvider(S->getArg(0)->getType()));
+  } else {
+report(S->getOperatorLoc(), llvm::dyn_cast(CD),
+   RefType::Implicit);
+  }
+}
 for (auto *Arg : S->arguments())
   if (!TraverseStmt(Arg))
 return false;


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -291,13 +291,18 @@
 }
 
 TEST(WalkAST, Operator) {
-  // References to operators are not counted as uses.
-  testWalk("struct string {}; int operator+(string, string);",
-   "int k = string() ^+ string();");
-  testWalk("struct string {int operator+(string); }; ",
-   "int k = string() ^+ string();");
-  testWalk("struct string { friend int operator+(string, string); }; ",
+  // Operator calls are marked as implicit references as they're ADL-used and
+  // type should be providing them.
+  testWalk(
+  "struct string { friend int $implicit^operator+(string, string); }; ",
+  "int k = string() ^+ string();");
+  // Unless they're members, we treat them as regular member expr calls.
+  testWalk("struct $explicit^string {int operator+(string); }; ",
"int k = string() ^+ string();");
+  // Make sure usage is attributed to the alias.
+  testWalk(
+  "struct string {int operator+(string); }; using $explicit^foo = string;",
+  "int k = foo() ^+ string();");
 }
 
 TEST(WalkAST, VarDecls) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -91,14 +91,23 @@
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  // Operators are almost always ADL extension points and by design references
+  // to them doesn't count as uses (generally the type should provide them, so
+  // ignore them).
+  // Unless we're using an operator defined as a member, 

[PATCH] D147302: [clang][dataflow] Add `create()` methods to `Environment` and `DataflowAnalysisContext`.

2023-04-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Thanks!




Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:215
   /// Creates an atomic boolean value.
-  AtomicBoolValue () {
-return takeOwnership(std::make_unique());
-  }
+  AtomicBoolValue () { return create(); 
}
 

Is there any reason for this function anymore or should we deprecate it (and 
the Top version below)? Especially in this object which only used internally 
and not by clients -- the extra two characters don't seem to justify a function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147302

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


[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-04-03 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58cf70b2cdc1: [clang][Interp] Fix diagnostics for calling 
non-constexpr constructors (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D145841?vs=504406=510485#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145841

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@
 int OtherVal;
 
 constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a 
constant expression}} \
-  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
+  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}} \
+  // expected-note {{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
   };
 
   constexpr Derived D(12); // ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
-   // expected-error {{must be initialized by a 
constant expression}}
+   // expected-error {{must be initialized by a 
constant expression}} \
+   // expected-note {{in call to 'Derived(12)'}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}} \
  // expected-error {{not an integral constant 
expression}} \
@@ -348,7 +350,8 @@
   };
 
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \
+  // expected-note {{declared here}}
 int OtherVal;
 
 constexpr bool doit() const { return Val == OtherVal; }
@@ -356,8 +359,8 @@
 
   constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{constructor inherited 
from base class 'YetAnotherBase' cannot be used in a constant expression}} \
-   // expected-error {{must be initialized 
by a constant expression}}
-   // FIXME: Missing reason for rejection.
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{constructor 
inherited from base class 'YetAnotherBase' cannot be used in a constant 
expression}}
 };
 
 namespace EmptyCtor {
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -207,13 +207,15 @@
   // ref-note {{declared const here}}
 int a;
   public:
-constexpr Foo() {
+constexpr Foo() { // expected-note {{declared here}}
   this->a = 10;
   T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
   // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
 }
   };
   constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // FIXME: The following note is wrong. \
+   // expected-note {{undefined constructor 'Foo' cannot be 
used in a constant expression}} \
// ref-error {{must be initialized by a constant 
expression}}
 
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1350,7 +1350,7 @@
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func || !Func->isConstexpr())
+if (!Func)
   return false;
 
 // The This pointer is already on the stack because this is an initializer,


Index: clang/test/AST/Interp/records.cpp

[clang] 58cf70b - [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-04-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-03T15:42:08+02:00
New Revision: 58cf70b2cdc17a905f7db2ec5a6f9d497f9bd133

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

LOG: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/cxx20.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 665f60d572ea..e5c9b2637b85 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1350,7 +1350,7 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func || !Func->isConstexpr())
+if (!Func)
   return false;
 
 // The This pointer is already on the stack because this is an initializer,

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index cfa9729f4b03..6cb106adf59c 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -207,13 +207,15 @@ namespace ConstThis {
   // ref-note {{declared const here}}
 int a;
   public:
-constexpr Foo() {
+constexpr Foo() { // expected-note {{declared here}}
   this->a = 10;
   T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
   // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
 }
   };
   constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // FIXME: The following note is wrong. \
+   // expected-note {{undefined constructor 'Foo' cannot be 
used in a constant expression}} \
// ref-error {{must be initialized by a constant 
expression}}
 
 

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 37cdf341fbd7..a7085e45ca33 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@ namespace MI {
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@ namespace DeriveFailures {
 int OtherVal;
 
 constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a 
constant expression}} \
-  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
+  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}} \
+  // expected-note {{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
   };
 
   constexpr Derived D(12); // ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
-   // expected-error {{must be initialized by a 
constant expression}}
+   // expected-error {{must be initialized by a 
constant expression}} \
+   // expected-note {{in call to 'Derived(12)'}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}} \
  // expected-error {{not an integral constant 
expression}} \
@@ -348,7 +350,8 @@ namespace DeriveFailures {
   };
 
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \
+  // expected-note {{declared here}}
 int OtherVal;
 
 constexpr bool doit() const { return Val == OtherVal; }
@@ -356,8 +359,8 @@ namespace DeriveFailures {
 
   constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{constructor inherited 
from base class 'YetAnotherBase' cannot be used in a constant expression}} \
-   // expected-error {{must be initialized 
by a constant expression}}
-   // FIXME: Missing reason for rejection.

[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-04-03 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments!




Comment at: clang-tools-extra/clangd/IncludeCleaner.h:87
+std::optional
+firstMatchedProvider(const include_cleaner::Includes ,
+ llvm::ArrayRef Providers);

kadircet wrote:
> can you also move tests related to this functionality from HoverTests into 
> IncludeCleanerTests ?
Not really, not sure what you mean.

This function receives a ranked list of providers that should be a result of 
include_cleaner analysis.

If I just test the function based on a fake list of providers, the test will be 
trivial. The current hover test seems to provide more value than that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

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


[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-04-03 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 510484.
VitaNuo marked 5 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,50 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto  : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto  : T.points()) 
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -9,13 +9,17 @@
 #include "AST.h"
 #include "FindSymbols.h"
 #include "FindTarget.h"
+#include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +52,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +66,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1310,6 +1316,63 @@
 return printQualifiedName(*ND);
   return {};
 }
+
+std::optional
+maybeFindIncludeReferences(ParsedAST , Position Pos,
+   URIForFile URIMainFile) {
+  const auto  = AST.getIncludeStructure().MainFileIncludes;
+  auto IncludeOnLine = llvm::find_if(Includes, [](const Inclusion ) {
+return Inc.HashLine == Pos.line;
+  });
+  if (IncludeOnLine == Includes.end())
+return std::nullopt;
+
+  const auto  = *IncludeOnLine;
+  const SourceManager  = AST.getSourceManager();
+  ReferencesResult Results;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  auto ReferencedInclude = convertIncludes(SM, Inc);
+  include_cleaner::walkUsed(
+  AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+  AST.getPragmaIncludes(), SM,
+  [&](const include_cleaner::SymbolReference ,
+  llvm::ArrayRef Providers) {
+if (Ref.RT != include_cleaner::RefType::Explicit)
+  return;
+
+auto Provider =
+firstMatchedProvider(ConvertedMainFileIncludes, Providers);
+if (!Provider || ReferencedInclude.match(*Provider).empty())
+  return;
+
+auto Loc = SM.getFileLoc(Ref.RefLocation);
+// File locations can be outside of the main file if macro is
+// expanded through an #include.
+while (SM.getFileID(Loc) != 

[PATCH] D146234: [clang] Fix crash when handling nested immediate invocations

2023-04-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146234

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


[PATCH] D147144: [include-cleaner] Report references to operator calls as implicit

2023-04-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

still LG.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147144

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


  1   2   >