[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

2023-07-02 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:475
 
+/// Whether to emit all variables that have a persisent storage duration,
+/// including global, static and thread local variables.

Minor nit: Typo.



Comment at: clang/include/clang/Driver/Options.td:1700
   BothFlags<[NoXarchOption], " static const variables if unused">>;
+defm keep_persistent_storage_variables : 
BoolFOption<"keep-persistent-storage-variables",
+  CodeGenOpts<"KeepPersistentStorageVariables">, DefaultFalse,

Please update the patch title and description to match.



Comment at: clang/test/CodeGen/keep-persistent-storage-variables.cpp:18-19
+// CHECK: @_ZN2ST2s6E = global i32 7, align 4
+// CHECK-ELF: @llvm.compiler.used = appending global [14 x ptr] [ptr @_ZL2g1, 
ptr @_ZL2g2, ptr @_ZL2g3, ptr @_ZL2g4, ptr @tl1, ptr @tl2, ptr @_ZL3tl3, ptr 
@_ZL3tl4, ptr @g5, ptr @g6, ptr @_ZZ5test3vE2s3, ptr @_ZN12_GLOBAL__N_12s4E, 
ptr @_ZZ5test5vE3tl5, ptr @_ZN2ST2s6E], section "llvm.metadata"
+// CHECK-NON-ELF: @llvm.used = appending global [14 x ptr] [ptr @_ZL2g1, ptr 
@_ZL2g2, ptr @_ZL2g3, ptr @_ZL2g4, ptr @tl1, ptr @tl2, ptr @_ZL3tl3, ptr 
@_ZL3tl4, ptr @g5, ptr @g6, ptr @_ZZ5test3vE2s3, ptr @_ZN12_GLOBAL__N_12s4E, 
ptr @_ZZ5test5vE3tl5, ptr @_ZN2ST2s6E], section "llvm.metadata"
+

If we don't care which of `llvm.compiler.used` or `llvm.used` is used (no pun 
intended), then maybe we can use a regex? For example, 
`@llvm{{(\.compiler)?}}.used`.



Comment at: clang/test/CodeGen/keep-persistent-storage-variables.cpp:32-39
+int test1() {
+  g1 = 3;
+  return g1;
+}
+
+int test2() {
+  return g2;

Why add functions that use `g1` and `g2`? Is there some reason to suspect that 
using the variables will cause them not to be emitted as explicitly used?

If removing these functions, please also remove `g3` and `g4` as redundant.



Comment at: clang/test/CodeGen/keep-persistent-storage-variables.cpp:50
+}
+void *test4() { return  }
+

Same comment re: why add a function?



Comment at: clang/test/Driver/fkeep-persistent-storage-variables.c:1
+// RUN: %clang -fkeep-persistent-storage-variables -c %s -### 2>&1 | FileCheck 
%s
+

Please add test for `-fkeep-persistent-storage-variables 
-fno-keep-persistent-storage-variables`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen accepted this revision.
ychen added a comment.
This revision is now accepted and ready to land.

LGTM. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 536648.
MitalAshok edited the summary of this revision.
MitalAshok added a comment.

Add status for CWG2681 and fixed aggregate-deduction-candidate test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from string literal
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2682.html;>2682
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from 

[PATCH] D153003: [ODRHash] Fix ODR hashing of template names

2023-07-02 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D153003#4463426 , @v.g.vassilev 
wrote:

> In D153003#4462388 , @ChuanqiXu 
> wrote:
>
>>> Oh, I guess we're somehow adding a semi-resolved form of the base class 
>>> type of D into the ODR hash, which then includes details of the 
>>> using-declaration. That seems wrong -- we should either (preferably) be 
>>> including only the syntactic form of the base specifier (because local 
>>> syntax is what the ODR covers), or the canonical type (which should be the 
>>> same for both using-declarations).
>>
>> Got it. I'll try to fix it. Thanks for the suggestion.
>
> Thanks @rsmith for the differential diagnosis!
>
> @ChuanqiXu, could you add me and @Hahnfeld in the loop as that's critical for 
> us.

Got it. No problem : )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153003

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


[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getCPUDispatchMangling

2023-07-02 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 536645.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Rebase, especially for D151696 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific-avx-abi.c
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -6,16 +6,24 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i586 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i686 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentiumpro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_pro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_ii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii_no_xmm_regs 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=yonah 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=prescott 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4_sse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lakemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=raptorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=meteorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -26,26 +34,39 @@
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core_2_duo_ssse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=penryn 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null 

[PATCH] D154209: [X86] Add missing features for ivybridge, sandybridge and knl in X86TargetParser.def.

2023-07-02 Thread Freddy, Ye 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 rGb026c9eb1051: [X86] Add missing features for ivybridge, 
sandybridge and knl in… (authored by FreddyYe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154209

Files:
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def


Index: llvm/include/llvm/TargetParser/X86TargetParser.def
===
--- llvm/include/llvm/TargetParser/X86TargetParser.def
+++ llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -262,9 +262,9 @@
 CPU_SPECIFIC("core_aes_pclmulqdq", "westmere", 'Q', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
 CPU_SPECIFIC("atom_sse4_2_movbe", "silvermont", 'd', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
 CPU_SPECIFIC("goldmont", "goldmont", 'i', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt")
-CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx")
+CPU_SPECIFIC("sandybridge", "sandybridge", 'R', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_2nd_gen_avx", "sandybridge", "sandybridge")
-CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx")
+CPU_SPECIFIC("ivybridge", "ivybridge", 'S', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+f16c,+avx,+pclmul")
 CPU_SPECIFIC_ALIAS("core_3rd_gen_avx", "ivybridge", "ivybridge")
 CPU_SPECIFIC("haswell", "haswell", 'V', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2")
 CPU_SPECIFIC_ALIAS("core_4th_gen_avx", "haswell", "haswell")
@@ -272,7 +272,7 @@
 CPU_SPECIFIC("broadwell", "broadwell", 'X', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
 CPU_SPECIFIC_ALIAS("core_5th_gen_avx", "broadwell", "broadwell")
 CPU_SPECIFIC("core_5th_gen_avx_tsx", "broadwell", 'Y', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx")
-CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd")
+CPU_SPECIFIC("knl", "knl", 'Z', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512f,+adx,+avx512er,+avx512pf,+avx512cd,+pclmul,+bmi2,+aes")
 CPU_SPECIFIC_ALIAS("mic_avx512", "knl", "knl")
 CPU_SPECIFIC("skylake", "skylake", 'b', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+adx,+mpx")
 CPU_SPECIFIC( "skylake_avx512", "skylake-avx512", 'a', 
"+cmov,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+movbe,+popcnt,+f16c,+avx,+fma,+bmi,+lzcnt,+avx2,+avx512dq,+avx512f,+adx,+avx512cd,+avx512bw,+avx512vl,+clwb")
Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -44,8 +44,8 @@
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
@@ -53,8 +53,8 @@
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -74,8 +74,8 @@
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991

[clang] b026c9e - [X86] Add missing features for ivybridge, sandybridge and knl in X86TargetParser.def.

2023-07-02 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2023-07-03T08:13:17+08:00
New Revision: b026c9eb1051c854ff13980cd30369f60b9a88c3

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

LOG: [X86] Add missing features for ivybridge, sandybridge and knl in 
X86TargetParser.def.

This is also a pre-commit change for D151696

Reviewed By: RKSimon

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

Added: 


Modified: 
clang/test/CodeGen/attr-cpuspecific.c
llvm/include/llvm/TargetParser/X86TargetParser.def

Removed: 




diff  --git a/clang/test/CodeGen/attr-cpuspecific.c 
b/clang/test/CodeGen/attr-cpuspecific.c
index 2cab5affd356c3..7b2207b2eb9e48 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -44,8 +44,8 @@ void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
@@ -53,8 +53,8 @@ void SingleVersion(void);
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
-// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -74,8 +74,8 @@ void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
-// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 59754495
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 59754495
 // LINUX: ret ptr @TwoVersions.Z
 // LINUX: ret ptr @TwoVersions.S
 // LINUX: call void @llvm.trap
@@ -84,8 +84,8 @@ void TwoVersions(void);
 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
 // WINDOWS: call void @__cpu_indicator_init()
 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
-// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
-// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 59754495
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 59754495
 // WINDOWS: call void @TwoVersions.Z()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @TwoVersions.S()
@@ -351,9 +351,9 @@ int DispatchFirst(void) {return 1;}
 ATTR(cpu_specific(knl))
 void OrderDispatchUsageSpecific(void) {}
 
-// CHECK: attributes #[[S]] = 
{{.*}}"target-features"="+avx,+cmov,+crc32,+cx8,+f16c,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
+// CHECK: attributes #[[S]] = 
{{.*}}"target-features"="+avx,+cmov,+crc32,+cx8,+f16c,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
 // CHECK-SAME: "tune-cpu"="ivybridge"
-// CHECK: attributes #[[K]] = 
{{.*}}"target-features"="+adx,+avx,+avx2,+avx512cd,+avx512er,+avx512f,+avx512pf,+bmi,+cmov,+crc32,+cx8,+f16c,+fma,+lzcnt,+mmx,+movbe,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
+// CHECK: attributes #[[K]] = 
{{.*}}"target-features"="+adx,+aes,+avx,+avx2,+avx512cd,+avx512er,+avx512f,+avx512pf,+bmi,+bmi2,+cmov,+crc32,+cx8,+f16c,+fma,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
 // CHECK-SAME: "tune-cpu"="knl"
 // CHECK: attributes #[[O]] = 
{{.*}}"target-features"="+cmov,+cx8,+mmx,+movbe,+sse,+sse2,+sse3,+ssse3,+x87"
 // CHECK-SAME: "tune-cpu"="atom"

diff  --git a/llvm/include/llvm/TargetParser/X86TargetParser.def 
b/llvm/include/llvm/TargetParser/X86TargetParser.def
index 7ed594167734ef..db02c619008427 100644
--- a/llvm/include/llvm/TargetParser/X86TargetParser.def
+++ 

[PATCH] D154270: [clang][CodeGen] Fix global variables initialized with an inheriting constructor.

2023-07-02 Thread Eli Friedman 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 rGb4bae3fd8ede: [clang][CodeGen] Fix global variables 
initialized with an inheriting… (authored by efriedma).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154270

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/inheriting-constructor.cpp


Index: clang/test/CodeGenCXX/inheriting-constructor.cpp
===
--- clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -4,6 +4,24 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple i386-windows 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN32
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple 
x86_64-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI 
--check-prefix=WIN64
 
+// PR63618: make sure we generate definitions for all the globals defined in 
the test
+// MSABI: @"?b@@3UB@@A" = {{.*}} zeroinitializer
+// MSABI: @"?d@@3UD@@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+
+// MSABI-NOT: @this
+
 // PR12219
 struct A { A(int); virtual ~A(); };
 struct B : A { using A::A; ~B(); };
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2453,7 +2453,10 @@
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
 
-  Arg.getAnyValue()->setName(D.getName());
+  // Set the name of the parameter's initial value to make IR easier to
+  // read. Don't modify the names of globals.
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 
   QualType Ty = D.getType();
 


Index: clang/test/CodeGenCXX/inheriting-constructor.cpp
===
--- clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -4,6 +4,24 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple i386-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN32
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple x86_64-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN64
 
+// PR63618: make sure we generate definitions for all the globals defined in the test
+// MSABI: @"?b@@3UB@@A" = {{.*}} zeroinitializer
+// MSABI: @"?d@@3UD@@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+
+// MSABI-NOT: @this
+
 // PR12219
 struct A { A(int); virtual ~A(); };
 struct B : A { using A::A; ~B(); };
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2453,7 +2453,10 @@
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
 
-  Arg.getAnyValue()->setName(D.getName());
+  // Set the name of the parameter's initial value to make IR easier to
+  // read. Don't modify the names of globals.
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 
   QualType Ty = D.getType();
 
___
cfe-commits mailing list

[clang] b4bae3f - [clang][CodeGen] Fix global variables initialized with an inheriting constructor.

2023-07-02 Thread Eli Friedman via cfe-commits

Author: Eli Friedman
Date: 2023-07-02T14:25:25-07:00
New Revision: b4bae3fd8ede10026a6f6e1caaec476125f5ac67

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

LOG: [clang][CodeGen] Fix global variables initialized with an inheriting 
constructor.

For inheriting constructors which have to be emitted inline, we use
CodeGenFunction::EmitInlinedInheritingCXXConstructorCall to emit the
required code.  This code uses EmitParmDecl to emit the "this" argument
of the call.  EmitParmDecl then helpfully calls llvm::Value::setName to
name the parameter... which renames the global variable to "this".

To fix the issue, skip the setName call on globals.

The renaming still has slightly weird results in other cases (it renames
all local variables initialized with an inlined inheriting constructor
to "this"), but the result isn't actually wrong in those cases, so I'm
just going to leave it for now.

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

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

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGenCXX/inheriting-constructor.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index fc16fb370dbaa4..e143687479ee3e 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2453,7 +2453,10 @@ void CodeGenFunction::EmitParmDecl(const VarDecl , 
ParamValue Arg,
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
 
-  Arg.getAnyValue()->setName(D.getName());
+  // Set the name of the parameter's initial value to make IR easier to
+  // read. Don't modify the names of globals.
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 
   QualType Ty = D.getType();
 

diff  --git a/clang/test/CodeGenCXX/inheriting-constructor.cpp 
b/clang/test/CodeGenCXX/inheriting-constructor.cpp
index b984ea177f211f..37e9166becb4fd 100644
--- a/clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ b/clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -4,6 +4,24 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple i386-windows 
-emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI --check-prefix=WIN32
 // RUN: %clang_cc1 -no-enable-noundef-analysis -std=c++11 -triple 
x86_64-windows -emit-llvm -o - %s | FileCheck %s --check-prefix=MSABI 
--check-prefix=WIN64
 
+// PR63618: make sure we generate definitions for all the globals defined in 
the test
+// MSABI: @"?b@@3UB@@A" = {{.*}} zeroinitializer
+// MSABI: @"?d@@3UD@@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@noninline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@noninline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inalloca_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inalloca_virt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_nonvirt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_nonvirt@@3UC@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?b@inline_virt@@3UB@1@A" = {{.*}} zeroinitializer
+// MSABI: @"?c@inline_virt@@3UC@1@A" = {{.*}} zeroinitializer
+
+// MSABI-NOT: @this
+
 // PR12219
 struct A { A(int); virtual ~A(); };
 struct B : A { using A::A; ~B(); };



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


[PATCH] D144829: [WIP][BPF] Add a few new insns under cpu=v4

2023-07-02 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

In D144829#4465193 , @eddyz87 wrote:

> Hi Yonghong,
>
> What is the current plan for these changes?
> I'd like to refresh D140804  to make BPF_ST 
> instruction available for cpu v4.
> I see that the latest CI run failed because of libcxx issue, I think it is 
> completely unrelated to this revision, see here 
> .

Eduard, please go ahead to refresh BPF_ST patch (D140804 
). For this patch, we will land it until the 
kernel patch addressed all major comments. When it is ready to merge, you will 
comment and let you know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144829

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


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

2023-07-02 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 536623.
philnik edited the summary of this revision.
philnik added a comment.

Try to fix CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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

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

[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 536622.
sousajo added a comment.

Thanks ^^ added the release note. Can someone please land it for me?

Jorge Pinto Sousa 


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

https://reviews.llvm.org/D154297

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
 void g() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -325,6 +325,10 @@
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-constant-array-index
+  ` to 
also check
+  for ``std::array`` type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -49,7 +49,8 @@
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("[]"),
   hasArgument(
-  0, hasType(cxxRecordDecl(hasName("::std::array")).bind("type"))),
+  0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::std::array")).bind("type")),
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the 

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

2023-07-02 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 536620.
philnik marked 16 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151683

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

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

[PATCH] D153906: [clang] Allow disassembly of multi-module bitcode files

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

FWIW, the precommit CI Windows bot found an issue with the newly added test 
case. Maybe test the Itanium and MS ABIs separately? (Uncertain if an 
Itanium-only test is appropriate but that's another option.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153906

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


[PATCH] D154284: [C11] Correct global atomic pointer initialization from an integer constant

2023-07-02 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 rG7b69eabdc187: [C11] Correct global atomic pointer 
initialization from an integer constant (authored by aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D154284?vs=536536=536619#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154284

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/atomic.c


Index: clang/test/CodeGen/atomic.c
===
--- clang/test/CodeGen/atomic.c
+++ clang/test/CodeGen/atomic.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
 
+// CHECK: @[[NONSTATIC_GLOB_POINTER_FROM_INT:.+]] = global ptr null
 // CHECK: @[[GLOB_POINTER:.+]] = internal global ptr null
+// CHECK: @[[GLOB_POINTER_FROM_INT:.+]] = internal global ptr null
 // CHECK: @[[GLOB_INT:.+]] = internal global i32 0
 // CHECK: @[[GLOB_FLT:.+]] = internal global float {{[0e\+-\.]+}}, align
 
@@ -125,6 +127,8 @@
 
 // Ensure that global initialization of atomics is correct.
 static _Atomic(int *) glob_pointer = (void *)0;
+static _Atomic(int *) glob_pointer_from_int = 0;
+_Atomic(int *) nonstatic_glob_pointer_from_int = 0LL;
 static _Atomic int glob_int = 0;
 static _Atomic float glob_flt = 0.0f;
 
@@ -132,6 +136,12 @@
   (void)glob_pointer;
   // CHECK: %[[LOCAL_INT:.+]] = load atomic i32, ptr @[[GLOB_POINTER]] seq_cst
   // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT]] to ptr
+  (void)glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_2:.+]] = load atomic i32, ptr 
@[[GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_2]] to ptr
+  (void)nonstatic_glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_3:.+]] = load atomic i32, ptr 
@[[NONSTATIC_GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_3]] to ptr
   (void)glob_int;
   // CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
   (void)glob_flt;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -14896,6 +14896,8 @@
 default:
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
 case CK_NullToPointer:
+  VisitIgnoredValue(E->getSubExpr());
+  return ZeroInitialization(E);
 case CK_NonAtomicToAtomic:
   return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr())
   : Evaluate(Result, Info, E->getSubExpr());


Index: clang/test/CodeGen/atomic.c
===
--- clang/test/CodeGen/atomic.c
+++ clang/test/CodeGen/atomic.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
 
+// CHECK: @[[NONSTATIC_GLOB_POINTER_FROM_INT:.+]] = global ptr null
 // CHECK: @[[GLOB_POINTER:.+]] = internal global ptr null
+// CHECK: @[[GLOB_POINTER_FROM_INT:.+]] = internal global ptr null
 // CHECK: @[[GLOB_INT:.+]] = internal global i32 0
 // CHECK: @[[GLOB_FLT:.+]] = internal global float {{[0e\+-\.]+}}, align
 
@@ -125,6 +127,8 @@
 
 // Ensure that global initialization of atomics is correct.
 static _Atomic(int *) glob_pointer = (void *)0;
+static _Atomic(int *) glob_pointer_from_int = 0;
+_Atomic(int *) nonstatic_glob_pointer_from_int = 0LL;
 static _Atomic int glob_int = 0;
 static _Atomic float glob_flt = 0.0f;
 
@@ -132,6 +136,12 @@
   (void)glob_pointer;
   // CHECK: %[[LOCAL_INT:.+]] = load atomic i32, ptr @[[GLOB_POINTER]] seq_cst
   // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT]] to ptr
+  (void)glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_2:.+]] = load atomic i32, ptr @[[GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_2]] to ptr
+  (void)nonstatic_glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_3:.+]] = load atomic i32, ptr @[[NONSTATIC_GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_3]] to ptr
   (void)glob_int;
   // CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
   (void)glob_flt;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -14896,6 +14896,8 @@
 default:
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
 case CK_NullToPointer:
+  VisitIgnoredValue(E->getSubExpr());
+  return ZeroInitialization(E);
 case CK_NonAtomicToAtomic:
   return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr())
   : Evaluate(Result, Info, E->getSubExpr());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7b69eab - [C11] Correct global atomic pointer initialization from an integer constant

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

Author: Aaron Ballman
Date: 2023-07-02T14:41:21-04:00
New Revision: 7b69eabdc18799e4a6c61b79b52d330c6ada

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

LOG: [C11] Correct global atomic pointer initialization from an integer constant

This is a follow-up to 2e275e24355cb224981f9beb2b026a3169fc7232 and
1395cde24b3641e284bb1daae7d56c189a2635e3 which corrects a missed case:
initializing an _Atomic(T *) from a null pointer constant in the form
of the integer literal 0.

Fixes https://github.com/llvm/llvm-project/issues/63550
Differential Revision: https://reviews.llvm.org/D154284

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/atomic.c

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 777245f86bdff7..09466253778a90 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14896,6 +14896,8 @@ class AtomicExprEvaluator :
 default:
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
 case CK_NullToPointer:
+  VisitIgnoredValue(E->getSubExpr());
+  return ZeroInitialization(E);
 case CK_NonAtomicToAtomic:
   return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr())
   : Evaluate(Result, Info, E->getSubExpr());

diff  --git a/clang/test/CodeGen/atomic.c b/clang/test/CodeGen/atomic.c
index 69f06eedb7caa6..242ec41ae1727f 100644
--- a/clang/test/CodeGen/atomic.c
+++ b/clang/test/CodeGen/atomic.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
 
+// CHECK: @[[NONSTATIC_GLOB_POINTER_FROM_INT:.+]] = global ptr null
 // CHECK: @[[GLOB_POINTER:.+]] = internal global ptr null
+// CHECK: @[[GLOB_POINTER_FROM_INT:.+]] = internal global ptr null
 // CHECK: @[[GLOB_INT:.+]] = internal global i32 0
 // CHECK: @[[GLOB_FLT:.+]] = internal global float {{[0e\+-\.]+}}, align
 
@@ -125,6 +127,8 @@ void addrspace(int  __attribute__((address_space(256))) * 
P) {
 
 // Ensure that global initialization of atomics is correct.
 static _Atomic(int *) glob_pointer = (void *)0;
+static _Atomic(int *) glob_pointer_from_int = 0;
+_Atomic(int *) nonstatic_glob_pointer_from_int = 0LL;
 static _Atomic int glob_int = 0;
 static _Atomic float glob_flt = 0.0f;
 
@@ -132,6 +136,12 @@ void force_global_uses(void) {
   (void)glob_pointer;
   // CHECK: %[[LOCAL_INT:.+]] = load atomic i32, ptr @[[GLOB_POINTER]] seq_cst
   // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT]] to ptr
+  (void)glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_2:.+]] = load atomic i32, ptr 
@[[GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_2]] to ptr
+  (void)nonstatic_glob_pointer_from_int;
+  // CHECK: %[[LOCAL_INT_3:.+]] = load atomic i32, ptr 
@[[NONSTATIC_GLOB_POINTER_FROM_INT]] seq_cst
+  // CHECK-NEXT: inttoptr i32 %[[LOCAL_INT_3]] to ptr
   (void)glob_int;
   // CHECK: load atomic i32, ptr @[[GLOB_INT]] seq_cst
   (void)glob_flt;



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


[PATCH] D154284: [C11] Correct global atomic pointer initialization from an integer constant

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D154284#4467154 , @efriedma wrote:

> The testcase doesn't actually trigger the assertion... but I guess it still 
> tests the output, so that's probably okay?  Maybe add a case `static 
> _Atomic(int *) glob_pointer_from_long = 0LL;` just to be sure.

Thanks for catching that! I added an additional test that doesn't use `static`, 
as that was relevant to reproducing the original issue: 
https://godbolt.org/z/cf4Wzeo3z

> Otherwise LGTM
>
> (The "VarSize == CstSize" assertion has been catching a surprising number of 
> cases of bad codegen; I'm happy I spent the time to add it.)

Yeah, this is a handy assertion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154284

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


[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 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.

Looks good, probably hasCanonicalType would be sufficient but 
hasUnqualifiedDesugaredType will also do a job.
Release notes need to be updated.


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

https://reviews.llvm.org/D154297

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


[PATCH] D154284: [C11] Correct global atomic pointer initialization from an integer constant

2023-07-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

The testcase doesn't actually trigger the assertion... but I guess it still 
tests the output, so that's probably okay?  Maybe add a case `static 
_Atomic(int *) glob_pointer_from_long = 0LL;` just to be sure.

Otherwise LGTM

(The "VarSize == CstSize" assertion has been catching a surprising number of 
cases of bad codegen; I'm happy I spent the time to add it.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154284

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


[PATCH] D154270: [clang][CodeGen] Fix global variables initialized with an inheriting constructor.

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



Comment at: clang/lib/CodeGen/CGDecl.cpp:2459
+  if (!isa(Arg.getAnyValue()))
+Arg.getAnyValue()->setName(D.getName());
 

rsmith wrote:
> Is it feasible to only set the name if the value doesn't already have a name, 
> or do we give values bad names often enough that it's better to overwrite an 
> existing name here?
Outside the EmitInlinedInheritingCXXConstructorCall case, the arguments are 
generally either llvm::Argument, or llvm::Instruction generated by calling 
convention code.  It might make sense to just make the calling convention code 
name the values itself (it already names some of the values it generates).

But I'll stick with the conservative fix here, and leave that for a followup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154270

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

`clang/test/SemaTemplate/aggregate-deduction-candidate.cpp` seems need updates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Thanks for catching this. The change LGTM. I think this is 
https://wg21.link/cwg2681. Could you please move the test to 
`clang/test/CXX/drs/dr26xx.cpp` and keep only these tests that are in the DR? 
Then you could run `clang/www/make_cxx_dr_status` to update 
`clang/www/cxx_dr_status.html`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

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


[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

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

LGTM, thank you!




Comment at: clang/docs/ReleaseNotes.rst:552
   (`#63503 `_)
+- Fixed parsing of elaborated type specifier inside of a new expression
+  (`#34341 `_)





Comment at: clang/include/clang/Parse/Parser.h:2221
+DSC_association, // A _Generic selection expression's type association
+DSC_new  // C++ new operator
   };

Fznamznon wrote:
> aaron.ballman wrote:
> > Adding the comma so the next person doesn't have to, and realigning to the 
> > usual indentation
> Added comma, but the indentation is what clang-format gave me. I'm afraid I 
> won't pass the pre-commit with different .
Ah, we don't care if pre-commit CI fails because of clang-format due to 
following the surrounding formatting style. That said, this formatting is 
already inconsistent (I hadn't noticed the first three are at a different 
indentation level as well), so this is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153857

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


[PATCH] D154283: [clang-tidy] Fix width/precision argument order in modernize-use-std-print

2023-07-02 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:73
+  // puts the width and preicision first.
+  std::vector> ArgRotates;
+

PiotrZSL wrote:
> mikecrowe wrote:
> > PiotrZSL wrote:
> > > NOTE: You can use std::pair here.
> > True, but in my mind `std::pair` only exists because `std::tuple` couldn't 
> > be implemented in the C++98.
> > 
> > I was going to change it to use `std::pair` anyway, but I notice that I 
> > already use `std::tuple` for `ArgFixes` just above. Should I change both of 
> > them?
> It will be compiled to same thing anyway. So it's up to you. Keep it 
> consistent.
> I personally use std::pair for 2 arguments, and std::tuple for more than 2.
> But to be honest probably better would be to introduce some structure so that 
> those two `unsigned` could be named. And probably same for ArgFixes, but 
> there we got different types, so it's not a big problem.
I think that you're probably right, but the names won't be used from the call 
site since I use structured binding there. Do you mind if I do both together in 
a separate commit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154283

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


[PATCH] D153881: Create diagnostic group for definition deprecation warning

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think it's a bit odd that we'd leave `const` under `-Wdeprecated` but 
separate `constexpr` out into its own warning flag, but I'm also not opposed. 
Can you explain the need a bit more though? I think our belief was that 
silencing this diagnostic was pretty trivial (delete the line in question), so 
we wouldn't need a separate diagnostic group for it.

Also, these changes should have a release note added to 
`clang/docs/ReleaseNotes.rst`.




Comment at: clang/test/CXX/basic/basic.def/p3.cpp:1
+// RUN: %clang_cc1 -std=c++17 -verify %s -Werror -Wdeprecated 
-Wno-error=deprecated-redundant-constexpr-static-def
+

nuriamari wrote:
> I'm not familiar with the naming convention of these test files. 
> https://reviews.llvm.org/D126664 included a change in p2.cpp, and there is 
> also a p4.cpp in the same directory, so I somewhat arbitrarily named this 
> test p3.cpp. If these are meant to somehow correspond to the C++ standard or 
> similar, please let me know.
Tests that live in `clang/test/CXX/` or `clang/test/C` are for testing specific 
details of the standard specification. In C, we track based on which N-numbered 
document the feature was proposed in, and in C++ we track based on stable name 
(`basic/basic.def`) and paragraph number (`p2.cpp`) of the changes being tested.

I think your new test should live in `clang/test/SemaCXX/` as that's where we 
put tests for more general compiler behaviors like warning flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153881

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


[PATCH] D154287: [clang-tidy] Add modernize-use-std-format check

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

To be honest, I do not see to much use case for this check. But that's fine.




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:46-51
+  StatementMatcher StrFormatMatcher =
+  callExpr(callee(functionDecl(matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")),
+   hasArgument(0, stringLiteral()))
+  .bind("StrFormat");

NOTE: put those things directly into addMatcher



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:50
+  .bind("func_decl")),
+   hasArgument(0, stringLiteral()))
+  .bind("StrFormat");

put hasArgument before callee (performance), you can also add 
`unless(argumentCountIs(0))`.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:69
+  const auto *OldFunction = Result.Nodes.getNodeAs("func_decl");
+  const auto *StrFormat = Result.Nodes.getNodeAs("StrFormat");
+

keep binding consistent `StrFormat` vs `func_decl`



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:78
+  if (!Converter.canApply()) {
+DiagnosticBuilder Diag = diag(StrFormatCall->getBeginLoc(),
+  "unable to use '%0' instead of %1 because 
%2")

Use callExpr location, not calee for diagnostic if possible (should point to 
same place anyway).



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:81
+ << ReplacementFormatFunction
+ << OldFunction->getIdentifier()
+ << Converter.conversionNotPossibleReason();

using ``<< OldFunction`` should be sufficient and more safe, same in line 88



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:629-630
+  if (Config.AllowTrailingNewlineRemoval &&
+  StringRef(StandardFormatString).ends_with("\\n") &&
   !StringRef(StandardFormatString).ends_with("n")) {
 UsePrintNewlineFunction = true;

what if it's ends with Windows new line style ? Will it work ?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst:27
+The check uses the same format-string-conversion algorithm as
+`modernize-use-std-print ` and its
+shortcomings are described in the documentation for that check.

is this link correct ? shouldn't this be put into `doc:`, verify if its working



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst:33
+
+.. option:: StrictMode TODO
+

If not implemented, do not add it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154287

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


[PATCH] D154283: [clang-tidy] Fix width/precision argument order in modernize-use-std-print

2023-07-02 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:73
+  // puts the width and preicision first.
+  std::vector> ArgRotates;
+

mikecrowe wrote:
> PiotrZSL wrote:
> > NOTE: You can use std::pair here.
> True, but in my mind `std::pair` only exists because `std::tuple` couldn't be 
> implemented in the C++98.
> 
> I was going to change it to use `std::pair` anyway, but I notice that I 
> already use `std::tuple` for `ArgFixes` just above. Should I change both of 
> them?
It will be compiled to same thing anyway. So it's up to you. Keep it consistent.
I personally use std::pair for 2 arguments, and std::tuple for more than 2.
But to be honest probably better would be to introduce some structure so that 
those two `unsigned` could be named. And probably same for ArgFixes, but there 
we got different types, so it's not a big problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154283

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


[PATCH] D153659: [RISCV] Fix name mangling for LMUL!=1 vector types with attribute(rvv_vector_bits)

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rjmccall.
aaron.ballman added a subscriber: rjmccall.
aaron.ballman added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:3879
+
+  Out << "9__RVV_VLSI" << 'u' << TypeNameStr.size() << TypeNameStr << "Lj"
   << VecSizeInBits << "EE";

CC @rjmccall for ABI review -- naĂŻve, possibly dumb question: shouldn't we be 
using the vendor extended builtin type encoding for this sort of thing? 
(https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.builtin-type)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153659

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


[PATCH] D147888: Update declaration message of extern linkage

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D147888#4467002 , 
@Krishna-13-cyber wrote:

> In D147888#4466998 , @aaron.ballman 
> wrote:
>
>> I think the existing wording is pretty reasonable, changing "non-static 
>> declaration" into "extern declaration" isn't really giving the user any more 
>> information to help them resolve the issue. "please pick exactly one" 
>> doesn't seem likely to help the user either -- they already know there's a 
>> conflict, so picking one is already the solution the user is likely to have 
>> in mind. The hard part for the user is with figuring which one to pick, but 
>> we have no way to help them make that choice. So I'm not certain changes are 
>> needed in this space (I'm not opposed either), but I do think the idea @cjdb 
>> had to combine all these diagnostics into one using `%select` could be 
>> helpful. However, there are enough options that it could also be pretty 
>> complex to reason about. There's static, extern, and thread-local, as well 
>> as "non-" versions of each of those, so there are quite a few combinations.
>
> Yes I agree with this,
> Changing the whole set of diagnostics will be quite challenging, but I think 
> `extern` has an edge over  `non-static` declaration when we are able to see 
> the diagnostics in gcc if are not going with the `pick-exactly one` 
> convention.

I can sort of buy the argument that `extern` has a slight edge, but I think 
what would really help are test cases for all the various combinations so we 
can see them at once (static, extern. no linkage, thread local vs each 
counterpart). I'm concerned that the code you added conflicts with the existing 
code immediately below your changes and the standards wording quoted above your 
changes, but I left a comment on what would make me more comfortable.




Comment at: clang/lib/Sema/SemaDecl.cpp:4641-4657
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }





Comment at: clang/test/SemaCXX/extern_static.cpp:7
+}
\ No newline at end of file


Be sure to add the newline back.

Also, I think there should be a C run line for the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


[PATCH] D147888: Update declaration message of extern linkage

2023-07-02 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4466998 , @aaron.ballman 
wrote:

> I think the existing wording is pretty reasonable, changing "non-static 
> declaration" into "extern declaration" isn't really giving the user any more 
> information to help them resolve the issue. "please pick exactly one" doesn't 
> seem likely to help the user either -- they already know there's a conflict, 
> so picking one is already the solution the user is likely to have in mind. 
> The hard part for the user is with figuring which one to pick, but we have no 
> way to help them make that choice. So I'm not certain changes are needed in 
> this space (I'm not opposed either), but I do think the idea @cjdb had to 
> combine all these diagnostics into one using `%select` could be helpful. 
> However, there are enough options that it could also be pretty complex to 
> reason about. There's static, extern, and thread-local, as well as "non-" 
> versions of each of those, so there are quite a few combinations.

Yes I agree with this,
Changing the whole set of diagnostics will be quite challenging, but I think 
`extern` has an edge over  `non-static` declaration when we are able to see the 
diagnostics in gcc if are not going with the `pick-exactly one` convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D153510#4441541 , @craig.topper 
wrote:

> @aaron.ballman The backend crashes at -O0 when scalable vector variables are 
> declared because the stack frame code doesn't expect to see them when the 
> vector extension isn't enabled.

That's a good reason to diagnose the declaration, but this makes the usage 
diagnostic very chatty -- if someone forgets to enable the extension, they'll 
get a diagnostic for each time they use the type and each time they declare 
something with the type, and there are likely to be more uses than there are 
declarations. No need to drown the user in repeated messages, so I think the 
diagnostic on usage should be disabled. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D147888: Update declaration message of extern linkage

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think the existing wording is pretty reasonable, changing "non-static 
declaration" into "extern declaration" isn't really giving the user any more 
information to help them resolve the issue. "please pick exactly one" doesn't 
seem likely to help the user either -- they already know there's a conflict, so 
picking one is already the solution the user is likely to have in mind. The 
hard part for the user is with figuring which one to pick, but we have no way 
to help them make that choice. So I'm not certain changes are needed in this 
space (I'm not opposed either), but I do think the idea @cjdb had to combine 
all these diagnostics into one using `%select` could be helpful. However, there 
are enough options that it could also be pretty complex to reason about. 
There's static, extern, and thread-local, as well as "non-" versions of each of 
those, so there are quite a few combinations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-02 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok created this revision.
Herald added a project: All.
MitalAshok edited the summary of this revision.
MitalAshok added reviewers: ychen, aaron.ballman, cor3ntin.
MitalAshok added a subscriber: cfe-commits.
MitalAshok retitled this revision from "Fix CTAD with string literals adding 
extra const" to "Fix aggregate CTAD with string literals adding extra const".
MitalAshok added inline comments.
MitalAshok published this revision for review.
Herald added a project: clang.



Comment at: clang/lib/Sema/SemaInit.cpp:10707
 //   if e_i is of array type and x_i is a bstring-literal, T_i is an
 //   lvalue reference to the const-qualified declared type of e_i and
 // C++ [over.match.class.deduct]p1.10:

The "const-qualified" here was missing


Missing a `withConst`, so when deducing from a string literal, a `const` is 
erroneously added to the deduced type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp


Index: 
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
===
--- /dev/null
+++ 
clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+
+template
+struct K {
+  char array[N];
+};
+K k = { "abc" };
+static_assert(__is_same(decltype(k), K<4>));
+
+template
+struct L {
+  const T array[N];
+};
+L l = { "abc" };
+static_assert(__is_same(decltype(l), L));
+
+template
+struct M {
+  T array[sizeof(T) == 0 ? 4 : 4];
+};
+M m = { "abc" };
+static_assert(__is_same(decltype(m), M));
+
+/*
+template
+struct N {
+  T array[4];
+};
+// The C99 extension, brace elision for designated initializers,
+// makes `T = const char*` viable, and that is used instead
+N n = { .array = "abc" };
+static_assert(__is_same(decltype(n), N));
+ */
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
===
--- /dev/null
+++ clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p1-9.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction guide}}
+
+template
+struct K {
+  char array[N];
+};
+K k = { "abc" };
+static_assert(__is_same(decltype(k), K<4>));
+
+template
+struct L {
+  const T array[N];
+};
+L l = { "abc" };
+static_assert(__is_same(decltype(l), L));
+
+template
+struct M {
+  T array[sizeof(T) == 0 ? 4 : 4];
+};
+M m = { "abc" };
+static_assert(__is_same(decltype(m), M));
+
+/*
+template
+struct N {
+  T array[4];
+};
+// The C99 extension, brace elision for designated initializers,
+// makes `T = const char*` viable, and that is used instead
+N n = { .array = "abc" };
+static_assert(__is_same(decltype(n), N));
+ */
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  

[PATCH] D154207: [AMDGPU] Rename predefined macro __AMDGCN_WAVEFRONT_SIZE

2023-07-02 Thread Yaxun Liu 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 rGad96f25b9365: [AMDGPU] Rename predefined macro 
__AMDGCN_WAVEFRONT_SIZE (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154207

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
  clang/test/Driver/hip-macros.hip


Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -17,6 +17,8 @@
 // RUN: %clang -E -dM --offload-arch=gfx1010 -mno-wavefrontsize64 \
 // RUN:   --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 64
+// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 32
 // WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64
 // WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32
 
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -20,7 +20,7 @@
 #define __maybe_undef __attribute__((maybe_undef))
 #define WARP_SIZE 64
 
-static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
 
 __device__ static inline unsigned int __lane_id() {
 return  __builtin_amdgcn_mbcnt_hi(
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -315,6 +315,8 @@
   if (hasFastFMA())
 Builder.defineMacro("FP_FAST_FMA");
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
   Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
 }


Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -17,6 +17,8 @@
 // RUN: %clang -E -dM --offload-arch=gfx1010 -mno-wavefrontsize64 \
 // RUN:   --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 64
+// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 32
 // WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64
 // WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32
 
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -20,7 +20,7 @@
 #define __maybe_undef __attribute__((maybe_undef))
 #define WARP_SIZE 64
 
-static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
 
 __device__ static inline unsigned int __lane_id() {
 return  __builtin_amdgcn_mbcnt_hi(
Index: clang/lib/Basic/Targets/AMDGPU.cpp
===
--- clang/lib/Basic/Targets/AMDGPU.cpp
+++ clang/lib/Basic/Targets/AMDGPU.cpp
@@ -315,6 +315,8 @@
   if (hasFastFMA())
 Builder.defineMacro("FP_FAST_FMA");
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
   Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ad96f25 - [AMDGPU] Rename predefined macro __AMDGCN_WAVEFRONT_SIZE

2023-07-02 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-07-02T11:10:06-04:00
New Revision: ad96f25b9365d65459740142a24db4a339705099

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

LOG: [AMDGPU] Rename predefined macro __AMDGCN_WAVEFRONT_SIZE

rename it to __AMDGCN_WAVEFRONT_SIZE__ for consistency.

__AMDGCN_WAVEFRONT_SIZE will be deprecated in the future.

Reviewed by: Matt Arsenault, Johannes Doerfert

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

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.cpp
clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
clang/test/Driver/hip-macros.hip

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 7025c7c4840017..f15216ac15a100 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -315,6 +315,8 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
,
   if (hasFastFMA())
 Builder.defineMacro("FP_FAST_FMA");
 
+  Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
+  // ToDo: deprecate this macro for naming consistency.
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
   Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
 }

diff  --git a/clang/test/CodeGenHIP/maybe_undef-attr-verify.hip 
b/clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
index b7ab32ac408f1f..571fba148f5ccc 100644
--- a/clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
+++ b/clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -20,7 +20,7 @@
 #define __maybe_undef __attribute__((maybe_undef))
 #define WARP_SIZE 64
 
-static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE__;
 
 __device__ static inline unsigned int __lane_id() {
 return  __builtin_amdgcn_mbcnt_hi(

diff  --git a/clang/test/Driver/hip-macros.hip 
b/clang/test/Driver/hip-macros.hip
index 6056e785f2cee8..6289ef91dd04fa 100644
--- a/clang/test/Driver/hip-macros.hip
+++ b/clang/test/Driver/hip-macros.hip
@@ -17,6 +17,8 @@
 // RUN: %clang -E -dM --offload-arch=gfx1010 -mno-wavefrontsize64 \
 // RUN:   --cuda-device-only -nogpuinc -nogpulib \
 // RUN:   -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s
+// WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 64
+// WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE__ 32
 // WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64
 // WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32
 



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


[PATCH] D153017: [analyzer] Fix false negative when using a nullable parameter directly without binding to a variable

2023-07-02 Thread tripleCC via Phabricator via cfe-commits
tripleCC added a comment.

In D153017#4428432 , @steakhal wrote:

> LGTM; I'll commit this on Monday.

Oops, It seems that I missed the invitation, I just noticed the invitation 
email in my gmail now ...
I will request Chris to send the invitation again.
Thank you for your recommendation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153017

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


[PATCH] D154283: [clang-tidy] Fix width/precision argument order in modernize-use-std-print

2023-07-02 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 536595.
mikecrowe added a comment.

Use emplace_back rather than push_back(make_tuple())


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154283

Files:
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -1024,7 +1024,7 @@
 
   printf("Right-justified integer with field width argument %*d after\n", 5, 424242);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Right-justified integer with field width argument {:{}} after", 5, 424242);
+  // CHECK-FIXES: std::println("Right-justified integer with field width argument {:{}} after", 424242, 5);
 
   printf("Right-justified integer with field width argument %2$*1$d after\n", 5, 424242);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
@@ -1061,7 +1061,7 @@
 
   printf("Left-justified integer with field width argument %-*d after\n", 5, 424242);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Left-justified integer with field width argument {:<{}} after", 5, 424242);
+  // CHECK-FIXES: std::println("Left-justified integer with field width argument {:<{}} after", 424242, 5);
 
   printf("Left-justified integer with field width argument %2$-*1$d after\n", 5, 424242);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
@@ -1087,15 +1087,15 @@
 
   printf("Hello %.*f after\n", 10, 3.14159265358979323846);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Hello {:.{}f} after", 10, 3.14159265358979323846);
+  // CHECK-FIXES: std::println("Hello {:.{}f} after", 3.14159265358979323846, 10);
 
   printf("Hello %10.*f after\n", 3, 3.14159265358979323846);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Hello {:10.{}f} after", 3, 3.14159265358979323846);
+  // CHECK-FIXES: std::println("Hello {:10.{}f} after", 3.14159265358979323846, 3);
 
   printf("Hello %*.*f after\n", 10, 4, 3.14159265358979323846);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Hello {:{}.{}f} after", 10, 4, 3.14159265358979323846);
+  // CHECK-FIXES: std::println("Hello {:{}.{}f} after", 3.14159265358979323846, 10, 4);
 
   printf("Hello %1$.*2$f after\n", 3.14159265358979323846, 4);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
@@ -1112,9 +1112,33 @@
 }
 
 void printf_field_width_and_precision() {
-  printf("Hello %1$*2$.*3$f after\n", 3.14159265358979323846, 4, 2);
+  printf("width only:%*d width and precision:%*.*f precision only:%.*f\n", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
-  // CHECK-FIXES: std::println("Hello {0:{1}.{2}f} after", 3.14159265358979323846, 4, 2);
+  // CHECK-FIXES: std::println("width only:{:{}} width and precision:{:{}.{}f} precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5);
+
+  printf("width and precision positional:%1$*2$.*3$f after\n", 3.14159265358979323846, 4, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::println("width and precision positional:{0:{1}.{2}f} after", 3.14159265358979323846, 4, 2);
+
+  const int width = 10, precision = 3;
+  printf("width only:%3$*1$d width and precision:%4$*1$.*2$f precision only:%5$.*2$f\n", width, precision, 42, 3.1415926, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::println("width only:{2:{0}} width and precision:{3:{0}.{1}f} precision only:{4:.{1}f}", width, precision, 42, 3.1415926, 2.718);
+}
+
+void fprintf_field_width_and_precision() {
+  fprintf(stderr, "width only:%*d width and precision:%*.*f precision only:%.*f\n", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'fprintf' [modernize-use-std-print]
+  // CHECK-FIXES: 

[PATCH] D154283: [clang-tidy] Fix width/precision argument order in modernize-use-std-print

2023-07-02 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

Thanks for the review.




Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:356-357
+  if (ArgCount)
+ArgRotates.push_back(
+std::make_tuple(FS.getArgIndex() + ArgsOffset, ArgCount));
+}

PiotrZSL wrote:
> 
Good point.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:73
+  // puts the width and preicision first.
+  std::vector> ArgRotates;
+

PiotrZSL wrote:
> NOTE: You can use std::pair here.
True, but in my mind `std::pair` only exists because `std::tuple` couldn't be 
implemented in the C++98.

I was going to change it to use `std::pair` anyway, but I notice that I already 
use `std::tuple` for `ArgFixes` just above. Should I change both of them?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154283

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


[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-02 Thread Youngsuk Kim 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 rG6f986bffc51a: [clang] Remove 
CGBuilderTy::CreateElementBitCast (authored by JOE1994).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154285

Files:
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp

Index: clang/lib/CodeGen/Targets/RISCV.cpp
===
--- clang/lib/CodeGen/Targets/RISCV.cpp
+++ clang/lib/CodeGen/Targets/RISCV.cpp
@@ -462,10 +462,8 @@
 
   // Empty records are ignored for parameter passing purposes.
   if (isEmptyRecord(getContext(), Ty, true)) {
-Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
-   getVAListElementType(CGF), SlotSize);
-Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
-return Addr;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/Targets/CSKY.cpp
===
--- clang/lib/CodeGen/Targets/CSKY.cpp
+++ clang/lib/CodeGen/Targets/CSKY.cpp
@@ -63,10 +63,8 @@
 
   // Empty records are ignored for parameter passing purposes.
   if (isEmptyRecord(getContext(), Ty, true)) {
-Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
-   getVAListElementType(CGF), SlotSize);
-Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
-return Addr;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -809,12 +809,9 @@
 
   CGBuilderTy  = CGF.Builder;
 
-  // Cast to char*.
-  Base = Builder.CreateElementBitCast(Base, CGF.Int8Ty);
-
   // Apply the offset, which we assume is non-null.
-  return Builder.CreateInBoundsGEP(Base.getElementType(), Base.getPointer(),
-   MemPtr, "memptr.offset");
+  return Builder.CreateInBoundsGEP(CGF.Int8Ty, Base.getPointer(), MemPtr,
+   "memptr.offset");
 }
 
 /// Perform a bitcast, derived-to-base, or base-to-derived member pointer
@@ -2043,7 +2040,7 @@
   if (!NonVirtualAdjustment && !VirtualAdjustment)
 return InitialPtr.getPointer();
 
-  Address V = CGF.Builder.CreateElementBitCast(InitialPtr, CGF.Int8Ty);
+  Address V = InitialPtr.withElementType(CGF.Int8Ty);
 
   // In a base-to-derived cast, the non-virtual adjustment is applied first.
   if (NonVirtualAdjustment && !IsReturnAdjustment) {
@@ -2054,7 +2051,7 @@
   // Perform the virtual adjustment if we have one.
   llvm::Value *ResultPtr;
   if (VirtualAdjustment) {
-Address VTablePtrPtr = CGF.Builder.CreateElementBitCast(V, CGF.Int8PtrTy);
+Address VTablePtrPtr = V.withElementType(CGF.Int8PtrTy);
 llvm::Value *VTablePtr = CGF.Builder.CreateLoad(VTablePtrPtr);
 
 llvm::Value *Offset;
@@ -2151,8 +2148,7 @@
 CookiePtr = CGF.Builder.CreateConstInBoundsByteGEP(CookiePtr, CookieOffset);
 
   // Write the number of elements into the appropriate slot.
-  Address NumElementsPtr =
-  CGF.Builder.CreateElementBitCast(CookiePtr, CGF.SizeTy);
+  Address NumElementsPtr = CookiePtr.withElementType(CGF.SizeTy);
   llvm::Instruction *SI = CGF.Builder.CreateStore(NumElements, NumElementsPtr);
 
   // Handle the array cookie specially in ASan.
@@ -2184,7 +2180,7 @@
   CGF.Builder.CreateConstInBoundsByteGEP(numElementsPtr, numElementsOffset);
 
   unsigned AS = allocPtr.getAddressSpace();
-  numElementsPtr = CGF.Builder.CreateElementBitCast(numElementsPtr, CGF.SizeTy);
+  numElementsPtr = numElementsPtr.withElementType(CGF.SizeTy);
   if (!CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) || AS != 0)
 return CGF.Builder.CreateLoad(numElementsPtr);
   // In asan mode emit a function call instead of a regular load and let the
@@ -2223,7 +2219,7 @@
   Address cookie = newPtr;
 
   // The first element is the element size.
-  cookie = CGF.Builder.CreateElementBitCast(cookie, CGF.SizeTy);
+  cookie = cookie.withElementType(CGF.SizeTy);
   llvm::Value *elementSize = llvm::ConstantInt::get(CGF.SizeTy,
  getContext().getTypeSizeInChars(elementType).getQuantity());
   CGF.Builder.CreateStore(elementSize, cookie);
@@ -2246,7 

[clang] 6f986bf - [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-02 Thread via cfe-commits

Author: Youngsuk Kim
Date: 2023-07-02T10:40:16-04:00
New Revision: 6f986bffc51a243a1f4328b11624a0f21918a78f

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

LOG: [clang] Remove CGBuilderTy::CreateElementBitCast

`CGBuilderTy::CreateElementBitCast()` no longer does what its name suggests.

Remove remaining in-tree uses by one of the following methods.

* drop the call entirely
* fold it to an `Address` construction
* replace it with `Address::withElementType()`

This is a NFC cleanup effort.

Reviewed By: barannikov88, nikic, jrtc27

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/Targets/CSKY.cpp
clang/lib/CodeGen/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 92dd38868ace8a..68535920088c49 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -155,12 +155,6 @@ class CGBuilderTy : public CGBuilderBaseTy {
 Addr.isKnownNonNull());
   }
 
-  /// This method is to be deprecated. Use `Address::withElementType` instead.
-  Address CreateElementBitCast(Address Addr, llvm::Type *Ty) {
-return Address(Addr.getPointer(), Ty, Addr.getAlignment(),
-   Addr.isKnownNonNull());
-  }
-
   using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
   Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty,
   llvm::Type *ElementTy,

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bb59d2ea90f554..e0f3de0b8ddc41 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3951,7 +3951,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 
 // Call LLVM's EH setjmp, which is lightweight.
 Function *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp);
-Buf = Builder.CreateElementBitCast(Buf, Int8Ty);
 return RValue::get(Builder.CreateCall(F, Buf.getPointer()));
   }
   case Builtin::BI__builtin_longjmp: {
@@ -4259,7 +4258,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 PtrTy->castAs()->getPointeeType().isVolatileQualified();
 
 Address Ptr = EmitPointerWithAlignment(E->getArg(0));
-Ptr = Builder.CreateElementBitCast(Ptr, Int8Ty);
+Ptr = Ptr.withElementType(Int8Ty);
 Value *NewVal = Builder.getInt8(0);
 Value *Order = EmitScalarExpr(E->getArg(1));
 if (isa(Order)) {
@@ -7287,7 +7286,7 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
   case NEON::BI__builtin_neon_vld1_dup_v:
   case NEON::BI__builtin_neon_vld1q_dup_v: {
 Value *V = PoisonValue::get(Ty);
-PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType());
+PtrOp0 = PtrOp0.withElementType(VTy->getElementType());
 LoadInst *Ld = Builder.CreateLoad(PtrOp0);
 llvm::Constant *CI = ConstantInt::get(SizeTy, 0);
 Ops[0] = Builder.CreateInsertElement(V, Ld, CI);
@@ -8099,7 +8098,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
 Value *Val = EmitScalarExpr(E->getArg(0));
 Builder.CreateStore(Val, Tmp);
 
-Address LdPtr = Builder.CreateElementBitCast(Tmp, STy);
+Address LdPtr = Tmp.withElementType(STy);
 Val = Builder.CreateLoad(LdPtr);
 
 Value *Arg0 = Builder.CreateExtractValue(Val, 0);
@@ -8473,7 +8472,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
 [[fallthrough]];
   case NEON::BI__builtin_neon_vld1_lane_v: {
 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
-PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType());
+PtrOp0 = PtrOp0.withElementType(VTy->getElementType());
 Value *Ld = Builder.CreateLoad(PtrOp0);
 return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane");
   }
@@ -8537,9 +8536,8 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   case NEON::BI__builtin_neon_vst1_lane_v: {
 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
 Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]);
-auto St = Builder.CreateStore(
-Ops[1], Builder.CreateElementBitCast(PtrOp0, Ops[1]->getType()));
-return St;
+return Builder.CreateStore(Ops[1],
+   PtrOp0.withElementType(Ops[1]->getType()));
   }
   case NEON::BI__builtin_neon_vtbl1_v:
 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1),
@@ -10203,7 +10201,7 @@ Value 

[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention this change in Release Notes.


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

https://reviews.llvm.org/D154297

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


[PATCH] D153738: Add LibClang guide

2023-07-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for adding this new documentation! In general, this is looking 
fantastic. Given how closely tied the C indexing APIs are with the rest of the 
compiler internals, I think it'd be helpful to add links to 
https://clang.llvm.org/docs/InternalsManual.html to various parts of this 
documentation to link the user back to more details. e.g., the section on 
source locations can link to 
https://clang.llvm.org/docs/InternalsManual.html#the-sourcelocation-and-sourcemanager-classes,
 etc. WDYT?




Comment at: clang/docs/LibClang.rst:4-5
+
+Libclang tutorial
+
+The C Interface to Clang provides a relatively small API that exposes 
facilities for parsing source code into an abstract syntax tree (AST), loading 
already-parsed ASTs, traversing the AST, associating physical source locations 
with elements within the AST, and other facilities that support Clang-based 
development tools.

Sphinx will complain if the underlines aren't the same length as what's being 
underlined.



Comment at: clang/docs/LibClang.rst:23-24
+
+CXCursor
+~
+A cursor representing a pointer to some element in the abstract syntax tree of 
a translation unit.





Comment at: clang/docs/LibClang.rst:33
+  
+  // file.hpp
+  struct foo{

Should we name this .cpp instead of .hpp? It's pretty weird to compile a header 
file, so using .cpp makes it clear that the TU is parsed as C++ code rather 
than as a header.



Comment at: clang/docs/LibClang.rst:37-38
+int* bar_pointer;
+  };
+.. code-block:: cpp
+  

Pretty sure Sphinx will want a newline here.



Comment at: clang/docs/LibClang.rst:86
+
+The return value of ``CXCursorVisitor``, the callable argument of 
``clang_visitChildren``, can return of of the three:
+





Comment at: clang/docs/LibClang.rst:114-116
+- ``CXCursor_StructDecl``: A C or C++ struct.
+- ``CXCursor_FieldDecl``: A field in a struct, union, or C++ class.
+- ``CXCursor_CallExpr``: An expression that calls a function

I noticed this in a few places -- you should make sure the punctuation is 
consistent for list elements.



Comment at: clang/docs/LibClang.rst:141-145
+``void* data[2]`` holds additional necessary type info, for example
+
+- Which struct was referred to?
+- What type is the pointer pointing to?
+- Qualifiers (e.g. ``const``, ``volatile``)?

I don't think we should document the `data` field in this way -- that's an 
implementation detail. Users should assume `data` is not something they can 
inspect or modify. Instead, users should use indexing APIs like 
`clang_equalTypes()`.



Comment at: clang/docs/LibClang.rst:150
+- ``clang_isConstQualifiedType`` to check for ``const``
+- ``clang_isRestrictQualifiedType`` to check for ``__restrict__``
+- ``clang_isVolatileQualifiedType`` to check for ``volatile``





Comment at: clang/docs/LibClang.rst:183
+
+The expected output of this program is
+





Comment at: clang/docs/LibClang.rst:260
+
+The expected output of this program is
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153738

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


[PATCH] D154300: [CUDA][HIP] Fix template argument deduction

2023-07-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, rsmith.
Herald added subscribers: mattd, carlosgalvezp.
Herald added a project: All.
yaxunl requested review of this revision.

nvcc allows using std::malloc and std::free in device code.
When std::malloc or std::free is passed as a template
function argument with template argument deduction,
there is no diagnostics. e.g.

  #include 
  
  __global__ void kern() {
  void *p = std::malloc(1);
  std::free(p);
  }
  int main()
  {
  
  std::shared_ptr a;
  a = std::shared_ptr(
(float*)std::malloc(sizeof(float) * 100),
std::free
  );
  return 0;
  }

However, the same code fails to compile with clang
(https://godbolt.org/z/1roGvo6YY). The reason is
that clang does not have logic to choose a function
argument from an overloaded set of candidates
based on host/device attributes for template argument
deduction.

Currently, clang does have a logic to choose a candidate
based on the constraints of the candidates. This patch
extends that logic to account for the CUDA host/device-based
preference.


https://reviews.llvm.org/D154300

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCUDA/template-arg-deduction.cu

Index: clang/test/SemaCUDA/template-arg-deduction.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/template-arg-deduction.cu
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
+
+// expected-no-diagnostics
+
+#include "Inputs/cuda.h"
+
+void foo();
+__device__ void foo();
+
+template
+void host_temp(F f);
+
+template
+__device__ void device_temp(F f);
+
+void host_caller() {
+  host_temp(foo);
+}
+
+__global__ void kernel_caller() {
+  device_temp(foo);
+}
+
+__device__ void device_caller() {
+  device_temp(foo);
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12697,6 +12697,20 @@
   DeclAccessPair DAP;
   SmallVector AmbiguousDecls;
 
+  auto CheckCUDAPreference = [&](FunctionDecl *FD1,
+ FunctionDecl *FD2) -> std::optional {
+FunctionDecl *Caller = getCurFunctionDecl(/*AllowLambda=*/true);
+int Preference1 = IdentifyCUDAPreference(Caller, FD1);
+int Preference2 = IdentifyCUDAPreference(Caller, FD2);
+if (Preference1 > Preference2) {
+  return true;
+} else if (Preference1 < Preference2) {
+  return false;
+} else {
+  return std::nullopt;
+}
+  };
+
   auto CheckMoreConstrained = [&](FunctionDecl *FD1,
   FunctionDecl *FD2) -> std::optional {
 if (FunctionDecl *MF = FD1->getInstantiatedFromMemberFunction())
@@ -12727,9 +12741,33 @@
 if (!checkAddressOfFunctionIsAvailable(FD))
   continue;
 
+// If we found a better result, update Result.
+auto FoundBetter = [&]() {
+  IsResultAmbiguous = false;
+  DAP = I.getPair();
+  Result = FD;
+};
+
 // We have more than one result - see if it is more constrained than the
 // previous one.
 if (Result) {
+  // Check CUDA preference first. If the candidates have differennt CUDA
+  // preference, choose the one with higher CUDA preference. Otherwise,
+  // choose the one with more constraints.
+  if (getLangOpts().CUDA) {
+std::optional MorePreferableByCUDA =
+CheckCUDAPreference(FD, Result);
+// If FD has different CUDA preference than Result.
+if (MorePreferableByCUDA) {
+  // FD is less preferable than Result.
+  if (!*MorePreferableByCUDA)
+continue;
+  // FD is more preferable than Result.
+  FoundBetter();
+}
+  }
+  // FD has the same CUDA prefernece than Result. Continue check
+  // constraints.
   std::optional MoreConstrainedThanPrevious =
   CheckMoreConstrained(FD, Result);
   if (!MoreConstrainedThanPrevious) {
@@ -12741,9 +12779,7 @@
 continue;
   // FD is more constrained - replace Result with it.
 }
-IsResultAmbiguous = false;
-DAP = I.getPair();
-Result = FD;
+FoundBetter();
   }
 
   if (IsResultAmbiguous)
@@ -12753,9 +12789,15 @@
 SmallVector ResultAC;
 // We skipped over some ambiguous declarations which might be ambiguous with
 // the selected result.
-for (FunctionDecl *Skipped : AmbiguousDecls)
+for (FunctionDecl *Skipped : AmbiguousDecls) {
+  // If skipped candidate has different CUDA preference than the result,
+  // there is no ambiguity. Otherwise check whether they have different
+  // constraints.
+  if (getLangOpts().CUDA && CheckCUDAPreference(Skipped, Result))
+continue;
   if (!CheckMoreConstrained(Skipped, Result))
 return nullptr;
+}
 

[PATCH] D154283: [clang-tidy] Fix width/precision argument order in modernize-use-std-print

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

Just few nits, from functionally point of view looks fine.




Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:356-357
+  if (ArgCount)
+ArgRotates.push_back(
+std::make_tuple(FS.getArgIndex() + ArgsOffset, ArgCount));
+}





Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:73
+  // puts the width and preicision first.
+  std::vector> ArgRotates;
+

NOTE: You can use std::pair here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154283

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


[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors

2023-07-02 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

friendly ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153296

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


[PATCH] D145302: [clangd] Add library for clangd main function

2023-07-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added a comment.

In D145302#4441334 , @kadircet wrote:

> thanks LG and seems to be working in a couple build configurations I tried. 
> but there might still be breakages in different configs, so please be on the 
> watchout after landing this for breakages in https://lab.llvm.org/.

@kadircet , could you look at the final version?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145302

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


[PATCH] D145302: [clangd] Add library for clangd main function

2023-07-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clangd/tool/CMakeLists.txt:37
+
+target_link_libraries(clangdMain
+  PRIVATE

kadircet wrote:
> you can merge this with the previous rule
fixed



Comment at: clang-tools-extra/clangd/tool/CMakeLists.txt:61
 
 target_link_libraries(clangd
   PRIVATE

kadircet wrote:
> you can get rid of this rule too
fixed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145302

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


[PATCH] D145302: [clangd] Add library for clangd main function

2023-07-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko marked an inline comment as not done.
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clangd/tool/CMakeLists.txt:11
+  ClangdToolMain.cpp
   $
   )

kadircet wrote:
> we should move this into `clangdMain` target now
Unfortunately it did not work and broke the clangd unit tests.

Note: all other comments were fixed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145302

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


[PATCH] D152435: [analyzer][CStringChecker] Adjust the invalidation operation on the super region of the destination buffer during string copy

2023-07-02 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:1054
+SVal SizeV, QualType SizeTy) {
+  return InvalidateBufferAux(
+  C, S, BufE, BufV,

steakhal wrote:
> OikawaKirie wrote:
> > steakhal wrote:
> > > Shouldn't we assert that `SizeV` is some known value or at least smaller 
> > > than (or equal to) the extent of the buffer?
> > The calls in `CStringChecker::evalCopyCommon` and 
> > `CStringChecker::evalStrcpyCommon` seem to have chances able to pass an 
> > unknown value. But I am not very sure about this.
> > 
> > If the `SizeV` is sure to be smaller or equal to the extent of the buffer, 
> > the `IsFirstBufInBound` check seems useless.
> > Maybe I need to dig deeper into the callers.
> Indeed.
Function `CStringChecker::CheckBufferAccess` is responsible to check whether 
the size overflows.
However, when `Filter.CheckCStringOutOfBounds` is set to false, the function 
will skip the overflow checking.
This makes that we cannot assert SizeV is always inbound, and the check in 
`IsFirstBufInBound` seems to be necessary.
(`evalMemset` -> `CheckBufferAccess`(skip overflow checking) -> `memsetAux` -> 
`InvalidateDestinationBufferBySize` with function call of `memset(x.arr, 'a', 
42)`)

Besides, if the size argument is originally an unknown value expression (e.g. 
`(unsigned char) 1.0`), the unknown value can be passed to this function.
(`CStringChecker::evalCopyCommon` -> `invalidateDestinationBufferBySize`, with 
function call of `memcpy(x.arr, "hi", (unsigned char) 1.0)`)

Hence, we cannot make such an assertion here. : (


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

https://reviews.llvm.org/D152435

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


[PATCH] D152435: [analyzer][CStringChecker] Adjust the invalidation operation on the super region of the destination buffer during string copy

2023-07-02 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie updated this revision to Diff 536578.
OikawaKirie marked 12 inline comments as done and an inline comment as not done.
OikawaKirie added a comment.

1. Function and variable names: functions: lower camel, variables: upper camel, 
lambdas: upper camel
2. std::function -> llvm::function_ref
3. update test case verification directions by following others in this file.


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

https://reviews.llvm.org/D152435

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/issue-55019.cpp
  clang/test/Analysis/pr22954.c

Index: clang/test/Analysis/pr22954.c
===
--- clang/test/Analysis/pr22954.c
+++ clang/test/Analysis/pr22954.c
@@ -556,12 +556,13 @@
   x263.s2 = strdup("hello");
   char input[] = {'a', 'b', 'c', 'd'};
   memcpy(x263.s1, input, *(len + n));
-  clang_analyzer_eval(x263.s1[0] == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(x263.s1[0] == 0); // expected-warning{{UNKNOWN}}\
+  expected-warning{{Potential leak of memory pointed to by 'x263.s2'}}
   clang_analyzer_eval(x263.s1[1] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s1[2] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s1[3] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s2 == 0); // expected-warning{{UNKNOWN}}
-  return 0; // expected-warning{{Potential leak of memory pointed to by 'x263.s2'}}
+  return 0;
 }
 
 
Index: clang/test/Analysis/issue-55019.cpp
===
--- /dev/null
+++ clang/test/Analysis/issue-55019.cpp
@@ -0,0 +1,89 @@
+// Refer issue 55019 for more details.
+// A supplemental test case of pr22954.c for other functions modeled in
+// the CStringChecker.
+
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+#include "Inputs/system-header-simulator-cxx.h"
+
+void *malloc(size_t);
+void free(void *);
+
+struct mystruct {
+  void *ptr;
+  char arr[4];
+};
+
+void clang_analyzer_dump(const void *);
+
+// CStringChecker::memsetAux
+void fmemset() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  memset(x.arr, 0, sizeof(x.arr));
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalCopyCommon
+void fmemcpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  memcpy(x.arr, "hi", 2);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStrcpyCommon
+void fstrcpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  strcpy(x.arr, "hi");
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+void fstrncpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  strncpy(x.arr, "hi", sizeof(x.arr));
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStrsep
+void fstrsep() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  char *p = x.arr;
+  (void)strsep(, "x");
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStdCopyCommon
+void fstdcopy() {
+  mystruct x;
+  x.ptr = new char;
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+
+  const char *p = "x";
+  std::copy(p, p + 1, x.arr);
+
+  // FIXME: As we currently cannot know whether the copy overflows, the checker
+  // invalidates the entire `x` object. When the copy size through iterators
+  // can be correctly modeled, we can then update the verify direction from
+  // SymRegion to HeapSymRegion as this std::copy call never overflows and
+  // hence the pointer `x.ptr` shall not be invalidated.
+  clang_analyzer_dump(x.ptr);   // expected-warning {{SymRegion}}
+  delete static_cast(x.ptr); // no-leak-warning
+}
Index: clang/test/Analysis/Inputs/system-header-simulator.h
===
--- clang/test/Analysis/Inputs/system-header-simulator.h
+++ clang/test/Analysis/Inputs/system-header-simulator.h
@@ -63,7 +63,9 @@
 
 char *strcpy(char *restrict, const char *restrict);
 char *strncpy(char *dst, const char *src, size_t n);
+char *strsep(char **stringp, const char *delim);
 void 

[PATCH] D145302: [clangd] Add library for clangd main function

2023-07-02 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 536577.
ivanmurashko added a comment.

Fixed clangd unit tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145302

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/tool/ClangdMain.h
  clang-tools-extra/clangd/tool/ClangdToolMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdToolMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangdMain.h"
+
+int main(int argc, char **argv) {
+  return clang::clangd::clangdMain(argc, argv);
+}
Index: clang-tools-extra/clangd/tool/ClangdMain.h
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,19 @@
+//===--- ClangdMain.h - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+namespace clang {
+namespace clangd {
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangdMain.h"
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
@@ -710,8 +711,6 @@
   }
 };
 } // namespace
-} // namespace clangd
-} // namespace clang
 
 enum class ErrorResultCode : int {
   NoShutdownRequest = 1,
@@ -719,10 +718,7 @@
   CheckFailed = 3
 };
 
-int main(int argc, char *argv[]) {
-  using namespace clang;
-  using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
@@ -1041,3 +1037,6 @@
 
   return ExitCode;
 }
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,6 +1,13 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdToolMain.cpp)
+
+add_clang_library(clangdMain
   ClangdMain.cpp
   Check.cpp
+  )
+
+add_clang_tool(clangd
+  ClangdToolMain.cpp
   $
   )
 
@@ -13,7 +20,7 @@
   list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
 endif()
 
-clang_target_link_libraries(clangd
+clang_target_link_libraries(clangdMain
   PRIVATE
   clangAST
   clangBasic
@@ -25,14 +32,14 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
-  )
-
-target_link_libraries(clangd
-  PRIVATE
   clangTidy
-
   clangDaemon
   clangdRemoteIndex
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+clang_target_link_libraries(clangd
+  PRIVATE
+  clangdMain
+  )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, jeroen.dobbelaere, arphaman, 
kbarton, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
sousajo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Index accessing checks are not performed for aliases
of `std::array`, as only `std::array` itself seems to be checked.

This patchs aims to extend it for aliases such as:
 `using MyArray = std::array;`


https://reviews.llvm.org/D154297

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
 void g() {
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -49,7 +49,8 @@
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("[]"),
   hasArgument(
-  0, hasType(cxxRecordDecl(hasName("::std::array")).bind("type"))),
+  0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::std::array")).bind("type")),
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside 

[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-02 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic 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/D154285/new/

https://reviews.llvm.org/D154285

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


[PATCH] D154290: [WIP][Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:16384
+   Expr *SizeExpression,
+   Expr *PtrExpression, ASTContext ,
+   EvalResult ) const {

tbaeder wrote:
> Any reason the `Expr*` pointers here can't be `const`?
Nope!. Note that I'm not entirely sold on this interface,  having a function in 
Expr taking a bunch of function pointers does not feel amazing,
but Sema can't access to evaluation functions, so one way or another this 
functions needs to end up in `ExprConstants.cpp` and making it an Expr member 
doesn't seem more terribler than the alternative 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[PATCH] D154290: [WIP][Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 536571.
cor3ntin added a comment.

Make EvaluateCharPointerAsString parameters const.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/static-assert-cxx26.cpp
  clang/tools/libclang/CIndex.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -140,7 +140,7 @@
  
   User-generated static_assert messages
   https://wg21.link/P2741R3;>P2741R3
-  No
+  Clang 17
  
  
   Placeholder variables with no name
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (StringLiteral *Message = D->getMessage())
+  if (auto *Message = dyn_cast(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_cc1 -std=c++2c -fsyntax-only %s -verify
+
+static_assert(true, "");
+static_assert(true, 0); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct Empty{};
+static_assert(true, Empty{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct NoData {
+unsigned long size() const;
+};
+struct NoSize {
+const char* data() const;
+};
+static_assert(true, NoData{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+static_assert(true, NoSize{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+
+struct InvalidSize {
+const char* size() const;
+const char* data() const;
+};
+static_assert(true, InvalidSize{}); // expected-error {{the message in a static_assert declaration must have a size() member function returning an object convertible to std::size_t}} \
+// expected-error {{value of type 'const char *' is not implicitly convertible to 'unsigned long'}}
+struct InvalidData {
+unsigned long size() const;
+unsigned long data() const;
+};
+static_assert(true, InvalidData{}); // expected-error {{the message in a static_assert declaration must have a data() member function returning an object convertible to const char*}} \
+// expected-error {{value of type 'unsigned long' is not implicitly convertible to 'const char *'}}
+
+struct NonConstexprSize {
+unsigned long size() const; // expected-note {{declared here}}
+constexpr const char* data() const;
+};
+
+static_assert(true, NonConstexprSize{});
+static_assert(false, NonConstexprSize{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'size' cannot be used in a constant expression}}
+
+struct NonConstexprData {
+constexpr unsigned long size() const {
+return 32;
+}
+const char* data() const;  // expected-note {{declared here}}
+};
+
+static_assert(true, NonConstexprData{});
+static_assert(false, NonConstexprData{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'data' cannot be used in a constant expression}}
+
+struct string_view {
+int S;
+const char* D;
+constexpr string_view(const char* 

[PATCH] D154290: [WIP][Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 536570.
cor3ntin edited the summary of this revision.
cor3ntin added a comment.

Add feature test macro and complete ODRDiagsEmitter change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/static-assert-cxx26.cpp
  clang/tools/libclang/CIndex.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -140,7 +140,7 @@
  
   User-generated static_assert messages
   https://wg21.link/P2741R3;>P2741R3
-  No
+  Clang 17
  
  
   Placeholder variables with no name
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (StringLiteral *Message = D->getMessage())
+  if (auto *Message = dyn_cast(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_cc1 -std=c++2c -fsyntax-only %s -verify
+
+static_assert(true, "");
+static_assert(true, 0); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct Empty{};
+static_assert(true, Empty{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct NoData {
+unsigned long size() const;
+};
+struct NoSize {
+const char* data() const;
+};
+static_assert(true, NoData{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+static_assert(true, NoSize{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+
+struct InvalidSize {
+const char* size() const;
+const char* data() const;
+};
+static_assert(true, InvalidSize{}); // expected-error {{the message in a static_assert declaration must have a size() member function returning an object convertible to std::size_t}} \
+// expected-error {{value of type 'const char *' is not implicitly convertible to 'unsigned long'}}
+struct InvalidData {
+unsigned long size() const;
+unsigned long data() const;
+};
+static_assert(true, InvalidData{}); // expected-error {{the message in a static_assert declaration must have a data() member function returning an object convertible to const char*}} \
+// expected-error {{value of type 'unsigned long' is not implicitly convertible to 'const char *'}}
+
+struct NonConstexprSize {
+unsigned long size() const; // expected-note {{declared here}}
+constexpr const char* data() const;
+};
+
+static_assert(true, NonConstexprSize{});
+static_assert(false, NonConstexprSize{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'size' cannot be used in a constant expression}}
+
+struct NonConstexprData {
+constexpr unsigned long size() const {
+return 32;
+}
+const char* data() const;  // expected-note {{declared here}}
+};
+
+static_assert(true, NonConstexprData{});
+static_assert(false, NonConstexprData{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'data' cannot be used in a constant expression}}
+
+struct string_view {
+int S;
+