[PATCH] D138810: [RISCV] Support vector crypto extension C intrinsics

2023-07-26 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 544624.
4vtomat marked 5 inline comments as done.
4vtomat added a comment.

After discusstion in 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/pull/234,
we will have multiple lmuls for scalar type operands.
Currently the test cases for those instructions are only presented in vaesdf,
all other instructions test cases will be copied from rvv-intrinsic-doc once
they're ready.
Also added test case for sema checking for checking valid lmul.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138810

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Basic/riscv_vector_common.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaesdf.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaesdm.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaesef.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaesem.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaeskf1.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaeskf2.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaesz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vandn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vbrev.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vbrev8.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vclmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vclmulh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vclz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcpopv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vctz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vgmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vrev8.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vrol.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vror.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ch.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2cl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ms.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsm3c.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsm3me.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsm4k.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsm4r.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vwsll.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaesdf.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaesdm.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaesef.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaesem.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaeskf1.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaeskf2.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaesz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vandn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vbrev.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vbrev8.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vclmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vclmulh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vclz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vcpopv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vctz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vgmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vrev8

[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-26 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D155457#4535941 , @aaron.ballman 
wrote:

> In D155457#4526168 , @xgupta wrote:
>
>> In D155457#4523388 , @cor3ntin 
>> wrote:
>>
>>> I'm not sure I understand the motivation for this change. Sure, people do 
>>> that but they also might do the same thing for ssize_t, intmax_t, or to 
>>> compare int to int32_t.
>>> I think a better heuristic would be to not emit a warning for any integral 
>>> (and floating point?) type that have the same canonical types (but we 
>>> probably still want one if their non-canonical type if the same)
>>
>> I am not sure but are you expecting these changes -
>>
>>   // Don't warn if the comparison involves integral or floating-point types 
>> with the same canonical types.
>>   QualType LHSCanonical = Constant->getType().getCanonicalType();
>>   QualType RHSCanonical = Other->getType().getCanonicalType();
>>   if ((LHSCanonical->isIntegralOrEnumerationType() || 
>> LHSCanonical->isFloatingType()) &&
>>   S.Context.hasSameType(LHSCanonical, RHSCanonical)) {
>> return false;
>>   }
>>
>> This will silence a lot of warnings and a total 5 test case fails.
>
> Can you share some examples of what test cases start failing with that 
> approach? What you have above matches what I think @cor3ntin was asking for 
> and does seem like a pretty reasonable way to silence false positives.

Sure, updated three test cases in the patch and list the other two here -

  FAIL: Clang :: Sema/tautological-constant-compare.c (865 of 18988)
   TEST 'Clang :: Sema/tautological-constant-compare.c' 
FAILED 
  
  error: 'warning' diagnostics expected but not seen: 
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 560 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:568):
 comparison of 3-bit signed value < 4 is always true
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 574 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:585):
 comparison of 8-bit unsigned value < 0 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 593 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:595):
 comparison of 2-bit unsigned value > 3 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 603: result of comparison 'int' > 2147483647 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 608 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:610):
 comparison of 15-bit unsigned value > 32767 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 614 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:616):
 comparison of 6-bit signed value > 31 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 621 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:637):
 comparison of 4-bit signed value < -8 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 623 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:638):
 comparison of 4-bit signed value > 7 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 628 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:639):
 comparison of 5-bit signed value < -16 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 629 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:640):
 comparison of 5-bit signed value > 15 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 632 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:641):
 comparison of 4-bit signed value > 7 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 633 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:642):
 comparison of 4-bit signed value < -8 is always false
File 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c 
Line 635 (directive at 
/home/shivam/.llvm/llvm-project/clang/test/Sema/tautological-constant-compare.c:643):
 comparison of 5-bit si

[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-26 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 544622.
xgupta added a comment.

Update as per comment of @cor3ntin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155457

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/atomic-compare.c
  clang/test/Sema/tautological-objc-bool-compare.m
  clang/test/Sema/type-limit-compare.cpp
  clang/test/SemaCXX/bool-compare.cpp

Index: clang/test/SemaCXX/bool-compare.cpp
===
--- clang/test/SemaCXX/bool-compare.cpp
+++ clang/test/SemaCXX/bool-compare.cpp
@@ -5,16 +5,16 @@
 
   bool a,b;
 
-  if(b > true){} // expected-warning {{comparison of true with expression of type 'bool' is always false}}
+  if(b > true){}
   if(b < true){} // no warning
   if(b >= true)   {} // no warning
-  if(b <= true)   {} // expected-warning {{comparison of true with expression of type 'bool' is always true}}
+  if(b <= true)   {}
   if(b == true)   {} // no warning
   if(b != true)   {} // no warning
 
   if(b > false)   {} // no warning
-  if(b < false)   {} // expected-warning {{comparison of false with expression of type 'bool' is always false}}
-  if(b >= false)  {} // expected-warning {{comparison of false with expression of type 'bool' is always true}}
+  if(b < false)   {}
+  if(b >= false)  {}
   if(b <= false)  {} // no warning
   if(b == false)  {} // no warning
   if(b != false)  {} // no warning
Index: clang/test/Sema/type-limit-compare.cpp
===
--- /dev/null
+++ clang/test/Sema/type-limit-compare.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wtautological-type-limit-compare -verify
+
+// expected-no-diagnostics
+#if defined(_WIN32)
+typedef unsigned long long uint64_t;
+#else
+typedef unsigned long uint64_t;
+#endif
+
+namespace std {
+using size_t = decltype(sizeof(0));
+} // namespace std
+
+bool func(uint64_t Size) {
+  if (sizeof(std::size_t) < sizeof(uint64_t) &&
+ Size > (uint64_t)(__SIZE_MAX__))
+return false;
+  return true;
+}
+
Index: clang/test/Sema/tautological-objc-bool-compare.m
===
--- clang/test/Sema/tautological-objc-bool-compare.m
+++ clang/test/Sema/tautological-objc-bool-compare.m
@@ -15,10 +15,10 @@
   r = B >= 0; // expected-warning {{result of comparison of constant 0 with expression of type 'BOOL' is always true, as the only well defined values for 'BOOL' are YES and NO}}
   r = B <= 0;
 
-  r = B > YES; // expected-warning {{result of comparison of constant YES with expression of type 'BOOL' is always false, as the only well defined values for 'BOOL' are YES and NO}}
+  r = B > YES;
   r = B > NO;
-  r = B < NO; // expected-warning {{result of comparison of constant NO with expression of type 'BOOL' is always false, as the only well defined values for 'BOOL' are YES and NO}}
+  r = B < NO;
   r = B < YES;
-  r = B >= NO; // expected-warning {{result of comparison of constant NO with expression of type 'BOOL' is always true, as the only well defined values for 'BOOL' are YES and NO}}
+  r = B >= NO;
   r = B <= NO;
 }
Index: clang/test/Sema/atomic-compare.c
===
--- clang/test/Sema/atomic-compare.c
+++ clang/test/Sema/atomic-compare.c
@@ -14,10 +14,10 @@
   if (a > 2) {} // no warning
 
   if (!a > 0) {}  // no warning
-  if (!a > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}}
-  if (!a > 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}}
+  if (!a > 1) {}
+  if (!a > 2) {}
   if (!a > b) {} // no warning
-  if (!a > -1){} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
+  if (!a > -1){}
 }
 
 typedef _Atomic(int) Ty;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13804,6 +13804,16 @@
   if (InRange && IsEnumConstOrFromMacro(S, Constant))
 return false;
 
+  // Don't warn if the comparison involves integral or floating-point types with
+  // the same canonical types.
+  QualType LHSCanonical = Constant->getType().getCanonicalType();
+  QualType RHSCanonical = Other->getType().getCanonicalType();
+  if ((LHSCanonical->isIntegralOrEnumerationType() ||
+   LHSCanonical->isFloatingType()) &&
+  S.Context.hasSameType(LHSCanonical, RHSCanonical)) {
+return false;
+  }
+
   // A comparison of an unsigned bit-field against 0 is really a type problem,
   // even though at the type level the bit-field might promote to 'signed int'.
   if (Other->refersToBitField() && InRange && Value == 0 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
ht

[clang] 2a6cfc4 - [clang][Interp] Try to fix a test on Windows

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-27T08:34:15+02:00
New Revision: 2a6cfc4baa784ff299a81f8c5e7163207c93eafe

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

LOG: [clang][Interp] Try to fix a test on Windows

This seems to fail on Windows:
Interp\literals.cpp Line 946: cast to smaller integer type 'long' from 'char *'

Added: 


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

Removed: 




diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c6f293886f90dc..10e0330daecbda 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -943,6 +943,6 @@ namespace PointerCasts {
   // expected-error {{must be initialized 
by a constant expression}} \
   // expected-note {{cast that performs 
the conversions of a reinterpret_cast}}
 
-  int array[(long)(char*)0]; // ref-warning {{variable length array folded to 
constant array}} \
- // expected-warning {{variable length array 
folded to constant array}}
+  int array[(intptr_t)(char*)0]; // ref-warning {{variable length array folded 
to constant array}} \
+ // expected-warning {{variable length array 
folded to constant array}}
 }



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


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

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

LGTM.




Comment at: llvm/lib/Target/X86/X86.td:1730
+ProcessorFeatures.SRFFeatures, ProcessorFeatures.ADLTuning>;
+foreach P = ["arrowlake-s", "arrowlake_s"] in {
+def : ProcModelhttps://reviews.llvm.org/D156239/new/

https://reviews.llvm.org/D156239

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


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D156394: [Clang][RISCV] Bump rvv intrinsics version to v0.12

2023-07-26 Thread Yueh-Ting (eop) Chen 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 rG20e87e2f7941: [Clang][RISCV] Bump rvv intrinsics version to 
v0.12 (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156394

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Preprocessor/riscv-target-features.c


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -297,7 +297,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -311,7 +311,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -324,7 +324,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64X-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64X-EXT: __riscv_vector 1
 // CHECK-ZVE64X-EXT: __riscv_zve32x 100{{$}}
@@ -335,7 +335,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32F-EXT %s
 // CHECK-ZVE32F-EXT: __riscv_v_elen 32
 // CHECK-ZVE32F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32F-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32F-EXT: __riscv_vector 1
 // CHECK-ZVE32F-EXT: __riscv_zve32f 100{{$}}
@@ -346,7 +346,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32X-EXT %s
 // CHECK-ZVE32X-EXT: __riscv_v_elen 32
 // CHECK-ZVE32X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -196,8 +196,8 @@
 
   if (ISAInfo->hasExtension("zve32x")) {
 Builder.defineMacro("__riscv_vector");
-// Currently we support the v0.11 RISC-V V intrinsics.
-Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 11)));
+// Currently we support the v0.12 RISC-V V intrinsics.
+Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 12)));
   }
 
   auto VScale = getVScaleRange(Opts);


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -297,7 +297,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -311,7 +311,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -324,7 +324,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64X-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64X-EXT: __riscv_vector 1
 // CHECK-ZVE64X-EXT: __riscv_zve32x 100{{$}}
@@ -335,7 +335,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32F-EXT %s
 // CHECK-ZVE32F-EXT: __riscv_v_elen 32
 // CHECK-ZVE32F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 12000{{$}}
 // C

[clang] 20e87e2 - [Clang][RISCV] Bump rvv intrinsics version to v0.12

2023-07-26 Thread via cfe-commits

Author: eopXD
Date: 2023-07-26T22:54:40-07:00
New Revision: 20e87e2f794173deebd1cf8c86684452bb0c989b

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

LOG: [Clang][RISCV] Bump rvv intrinsics version to v0.12

The LLVM now supports v0.12 of the RVV intrinsics. Users can use the macro
riscv_v_intrinsic to distinguish what kind of intrinsics is supported in
the compiler.

Please refer to tag descriptions under

https://github.com/riscv-non-isa/rvv-intrinsic-doc/tags

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
clang/test/Preprocessor/riscv-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 94c894dfec0b86..d55ab76395c827 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -196,8 +196,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   if (ISAInfo->hasExtension("zve32x")) {
 Builder.defineMacro("__riscv_vector");
-// Currently we support the v0.11 RISC-V V intrinsics.
-Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 11)));
+// Currently we support the v0.12 RISC-V V intrinsics.
+Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 12)));
   }
 
   auto VScale = getVScaleRange(Opts);

diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 27c089494de177..edfc26c9dfcf37 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -297,7 +297,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -311,7 +311,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -324,7 +324,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64X-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64X-EXT: __riscv_vector 1
 // CHECK-ZVE64X-EXT: __riscv_zve32x 100{{$}}
@@ -335,7 +335,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32F-EXT %s
 // CHECK-ZVE32F-EXT: __riscv_v_elen 32
 // CHECK-ZVE32F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32F-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32F-EXT: __riscv_vector 1
 // CHECK-ZVE32F-EXT: __riscv_zve32f 100{{$}}
@@ -346,7 +346,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32X-EXT %s
 // CHECK-ZVE32X-EXT: __riscv_v_elen 32
 // CHECK-ZVE32X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}



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


[PATCH] D156221: [RISCV] Support overloaded version ntlh intrinsic function

2023-07-26 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/lib/Headers/riscv_ntlh.h:28
+  __builtin_riscv_ntl_load((PTR), __RISCV_NTLH_ALL)
+#define SELECT_NTL_LOAD(_1, _2, NAME, ...) NAME
+

`__SELECT_NTL_LOAD`



Comment at: clang/lib/Headers/riscv_ntlh.h:39
+  __builtin_riscv_ntl_store((PTR), (VAL), __RISCV_NTLH_ALL)
+#define SELECT_NTL_STORE(_1, _2, _3, NAME, ...) NAME
 

`__SELECT_NTL_STORE`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156221

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


[PATCH] D156394: [Clang][RISCV] Bump rvv intrinsics version to v0.12

2023-07-26 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng 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/D156394/new/

https://reviews.llvm.org/D156394

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


[PATCH] D156357: clang: Add elementwise bitreverse builtin

2023-07-26 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 544610.
bob80905 added a comment.

- remove tests that only test floating point inputs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156357

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -206,3 +206,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_bitreverse() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);  
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -269,6 +269,24 @@
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
 
+void test_builtin_elementwise_bitreverse(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_bitreverse();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_bitreverse(f);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float')}}
+  
+  i = __builtin_elementwise_bitreverse(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_bitreverse(d);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'double')}}
+}
+
 void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_ceil(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -323,6 +323,42 @@
   int_as_one = __builtin_elementwise_min(int_as_one, b);
 }
 
+void test_builtin_elementwise_bitreverse(si8 vi1, si8 vi2,
+  long long int i1, long long int i2, short si,
+  _BitInt(31) bi1, _BitInt(31) bi2) {
+  
+
+  // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
+  // CHECK-NEXT: call i64 @llvm.bitreverse.i64(i64 [[I1]])
+  i2 = __builtin_elementwise_bitreverse(i1);
+
+  // CHECK:  [[VI1:%.+]] = load <8 x i16>, ptr %vi1.addr, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> [[VI1]])
+  vi2 = __builtin_elementwise_bitreverse(vi1);
+
+  // CHECK:  [[CVI2:%.+]] = load <8 x i16>, ptr %cvi2, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> [[CVI2]])
+  const si8 cvi2 = vi2;
+  vi2 = __builtin_elementwise_bitreverse(cvi2);
+
+  // CHECK:  [[BI1:%.+]] = load i31, ptr %bi1.addr, align 4
+  // CHECK-NEXT: call i31 @llvm.bitreverse.i31(i31 [[BI1]])
+  bi2 = __builtin_elementwise_bitreverse(bi1);
+
+  // CHECK:  [[IA1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
+  // CHECK-NEXT: call i32 @llvm.bitreverse.i32(i32 [[IA1]])
+  b = __builtin_elementwise_bitreverse(int_as_one);
+
+  // CHECK:   call i32 @llvm.bitreverse.i32(i32 -10)
+  b = __builtin_elementwise_bitreverse(-10);
+
+  // CHECK:  [[SI:%.+]] = load i16, ptr %si.addr, align 2
+  // CHECK-NEXT: [[SI_EXT:%.+]] = sext i16 [[SI]] to i32
+  // CHECK-NEXT: [[RES:%.+]] = call i32 @llvm.bitreverse.i32(i32 [[SI_EXT]])
+  // CHECK-NEXT: = trunc i32 [[RES]] to i16
+  si = __builtin_elementwise_bitreverse(si);
+}
+
 void test_builtin_elementwise_ceil(float f1, float f2, double d1, double d2,
float4 vf1, float4 vf2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_ceil(
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2700,6 +2700,26 @@
 if (SemaBuiltinElementwiseMath(TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_elementwise_bitreverse: {
+if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+  return ExprError();
+
+const Expr *Arg = TheCall->getArg(0);
+QualType ArgTy = Arg->getType();
+Q

[PATCH] D156394: [Clang][RISCV] Bump rvv intrinsics version to v0.12

2023-07-26 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: asb, craig.topper, kito-cheng.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay.
Herald added a project: clang.

The LLVM now supports v0.12 of the RVV intrinsics. Users can use the macro
riscv_v_intrinsic to distinguish what kind of intrinsics is supported in
the compiler.

Please refer to tag descriptions under

https://github.com/riscv-non-isa/rvv-intrinsic-doc/tags


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156394

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Preprocessor/riscv-target-features.c


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -297,7 +297,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -311,7 +311,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -324,7 +324,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64X-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64X-EXT: __riscv_vector 1
 // CHECK-ZVE64X-EXT: __riscv_zve32x 100{{$}}
@@ -335,7 +335,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32F-EXT %s
 // CHECK-ZVE32F-EXT: __riscv_v_elen 32
 // CHECK-ZVE32F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32F-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32F-EXT: __riscv_vector 1
 // CHECK-ZVE32F-EXT: __riscv_zve32f 100{{$}}
@@ -346,7 +346,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE32X-EXT %s
 // CHECK-ZVE32X-EXT: __riscv_v_elen 32
 // CHECK-ZVE32X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -196,8 +196,8 @@
 
   if (ISAInfo->hasExtension("zve32x")) {
 Builder.defineMacro("__riscv_vector");
-// Currently we support the v0.11 RISC-V V intrinsics.
-Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 11)));
+// Currently we support the v0.12 RISC-V V intrinsics.
+Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 12)));
   }
 
   auto VScale = getVScaleRange(Opts);


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -297,7 +297,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -311,7 +311,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 11000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -324,7 +324,7 @@
 // RUN: | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHEC

[PATCH] D156321: [Clang][RISCV] Remove RVV intrinsics `vread_csr`,`vwrite_csr`

2023-07-26 Thread Yueh-Ting (eop) Chen 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 rG7cb81c1b8ce5: [Clang][RISCV] Remove RVV intrinsics 
`vread_csr`,`vwrite_csr` (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156321

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
-// RUN: | opt -S -O2 | FileCheck  %s
-
-#include 
-
-// CHECK-LABEL: @vwrite_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vstart, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vstart(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VSTART, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxsat, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxsat(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXSAT, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxrm, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxrm(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXRM, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vcsr, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vcsr(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VCSR, value);
-}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
-// RUN: | opt -S -O2 | FileCheck  %s
-
-#include 
-
-// CHECK-LABEL: @vread_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vstart", "=r,~{memory}"() #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vstart(void) {
-  return __riscv_vread_csr(RVV_VSTART);
-}
-
-// CHECK-LABEL: @vread_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vxsat", "=r,~{memory}"() #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxsat(void) {
-  return __riscv_vread_csr(RVV_VXSAT);
-}
-
-// CHECK-LABEL: @vread_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vxrm", "=r,~{memory}"() #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxrm(void) {
-  return __riscv_vread_csr(RVV_VXRM);
-}
-
-// CHECK-LABEL: @vread_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vcsr", "=r,~{memory}"() #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vcsr(void) {
-  return __riscv_vread_csr(RVV_VCSR);
-}
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -990,56 +990,6 @@
   }
 }
 
-// Define vread_csr&vwrite_csr described in RVV intrinsics doc.
-let HeaderCode =
-[{
-enum RVV_CSR {
-  RVV_VSTART = 0,
-  RVV_VXSAT,
-  RVV_VXRM,
-  RVV_VCSR,
-};
-
-static __inline__ __attribute__((__always_inline__, __nodebug__))
-unsigned long __riscv_vread_csr(enum RVV_CSR __csr) {
-  unsigned long __rv = 0;
-  switch (__csr) {
-case RVV_VSTART:
-  __asm__ __volatile__ ("csrr\t%0, vstart" : "=r"(__rv) : : "memory");
-  break;
-case RVV_VXSAT:
-  __asm__ __volatile__ ("csrr\t%0, vxsat" : "=r"(__rv) : : "memory");
-  break;
-case RVV_VXRM:
-  __asm__ __volatile__ ("csrr\t%0, vxrm" : "=r"(__rv) : : "memory");
-  break;
-case RVV_VCSR:

[clang] 7cb81c1 - [Clang][RISCV] Remove RVV intrinsics `vread_csr`,`vwrite_csr`

2023-07-26 Thread via cfe-commits

Author: eopXD
Date: 2023-07-26T22:33:41-07:00
New Revision: 7cb81c1b8ce5012c36bb8ed0eb4da2f94fb4f0fc

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

LOG: [Clang][RISCV] Remove RVV intrinsics `vread_csr`,`vwrite_csr`

As proposed in riscv-non-isa/rvv-intrinsic-doc#249, removing the interface.

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td

Removed: 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c



diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 7e5889812aecc8..5bf1916df117ba 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -990,56 +990,6 @@ multiclass RVVPseudoVNCVTBuiltin
-
-// CHECK-LABEL: @vread_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, 
vstart", "=r,~{memory}"() #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vstart(void) {
-  return __riscv_vread_csr(RVV_VSTART);
-}
-
-// CHECK-LABEL: @vread_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, 
vxsat", "=r,~{memory}"() #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxsat(void) {
-  return __riscv_vread_csr(RVV_VXSAT);
-}
-
-// CHECK-LABEL: @vread_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, 
vxrm", "=r,~{memory}"() #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxrm(void) {
-  return __riscv_vread_csr(RVV_VXRM);
-}
-
-// CHECK-LABEL: @vread_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, 
vcsr", "=r,~{memory}"() #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vcsr(void) {
-  return __riscv_vread_csr(RVV_VCSR);
-}

diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
deleted file mode 100644
index 01da208b7bdcef..00
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone 
-emit-llvm %s -o - \
-// RUN: | opt -S -O2 | FileCheck  %s
-
-#include 
-
-// CHECK-LABEL: @vwrite_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vstart, ${0:z}", 
"rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vstart(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VSTART, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxsat, ${0:z}", 
"rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxsat(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXSAT, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxrm, ${0:z}", 
"rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxrm(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXRM, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vcsr, ${0:z}", 
"rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vcsr(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VCSR, value);
-}



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


[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

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

I think a test verifying that during constant evaluation we still flag the read 
of a local tagged uninitialized as ill-formed would be nice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156337

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


[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

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

Adding clang-language-wg for more visibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156337

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

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

While I am not against the approach, do you think we need similar semantics for 
`-fno-concepts`, `-fno-modules`, etc...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

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

In D156247#4536034 , @tahonermann 
wrote:

>> You are absolutely right, -fno-coroutines would totally work for us, had it 
>> been available.
>
> Good. Gcc handles `-fcoroutines` and `-fno-coroutines` as I would expect 
> (https://godbolt.org/z/7zEMd7cdW), so matching gcc behavior makes sense in 
> any case. I would expect implementation to be quite straight forward, so I 
> recommend we head in that direction.

This feels like a much cleaner solution to me as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D141918: WIP: [Clang] Emit 'unwindabort' when applicable.

2023-07-26 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added inline comments.
Herald added a subscriber: jplehr.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:2021
+  /* Indicates whether we should generate calls using unwindabort, instead of a
+   * terminate landingpad, for the current EH Scope. */
+  bool shouldUseUnwindAbort() const;

Other method docs in the file use `///`-style doxygen comments.



Comment at: clang/test/CodeGenCXX/exceptions.cpp:81
 
-  //   rdar://11904428
-  //   Terminate landing pads should call __cxa_begin_catch first.

FWI(was)W, this radar points at:  https://bugs.llvm.org/show_bug.cgi?id=11893


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141918

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


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 544566.
strimo378 added a comment.

Added additional ctor variants as suggested by the reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156307

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp

Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
 
-// CHECK: struct A {
-struct A {
-  // CHECK-NEXT: A();
-  A();
+// CHECK: struct DelegatingCtor1 {
+struct DelegatingCtor1 {
+  // CHECK-NEXT: DelegatingCtor1();
+  DelegatingCtor1();
 
-  // CHECK-NEXT: A(int) : A() {
-  A(int) : A() {
+  // CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
+  DelegatingCtor1(int) : DelegatingCtor1() {
 // CHECK-NEXT: }
   }
 
@@ -14,33 +14,72 @@
 };
 
 
-// CHECK: struct B {
-struct B {
-  // CHECK-NEXT: template  B(Ty);
-  template  B(Ty);
+// CHECK: struct DelegatingCtor2 {
+struct DelegatingCtor2 {
+  // CHECK-NEXT: template  DelegatingCtor2(Ty);
+  template  DelegatingCtor2(Ty);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK-NEXT: template<> B(float);
+  // CHECK-NEXT: template<> DelegatingCtor2(float);
 
-  // CHECK-NEXT: B(int X) : B((float)X) {
-  B(int X) : B((float)X) {
+  // CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
+  DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
 
-// CHECK: struct C {
-struct C {
+// CHECK: struct DelegatingCtor3 {
+struct DelegatingCtor3 {
   // FIXME: template <> should not be output
-  // CHECK: template <> C(auto);
-  C(auto);
+  // CHECK: template <> DelegatingCtor3(auto);
+  DelegatingCtor3(auto);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK: template<> C(const char *);
+  // CHECK: template<> DelegatingCtor3(const char *);
 
-  // CHECK: C(int) : C("") {
-  C(int) : C("") {
+  // CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
+  DelegatingCtor3(int) : DelegatingCtor3("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct CurlyCtorInit {
+struct CurlyCtorInit {
+  // CHECK-NEXT: struct A {
+  struct A {
+// CHECK-NEXT: int x;
+int x;
+  // CHECK-NEXT: };
+  };
+
+  // CHECK-NEXT: A a;
+  A a;
+  // CHECK-NEXT: int i;
+  int i;
+
+  // FIXME: /*implicit*/(int)0 should not be output
+  // CHECK-NEXT: CurlyCtorInit(int *) : a(), i(/*implicit*/(int)0) {
+  CurlyCtorInit(int *) : a(), i() {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int **) : a{}, i{} {
+  CurlyCtorInit(int **) : a{}, i{} {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int ***) : a({}), i(0) {
+  CurlyCtorInit(int ***) : a({}), i(0) {
+  // CHECK-NEXT: }
+  }
+
+  // FIXME: Implicit this should not be output
+  // CHECK-NEXT: CurlyCtorInit(int ) : a({.x = 0}), i(this->a.x) {
+  CurlyCtorInit(int ) : a({.x = 0}), i(a.x) {
   // CHECK-NEXT: }
   }
 
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -327,11 +327,12 @@
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
 
-Out << "(";
-if (!BMInitializer->getInit()) {
-  // Nothing to print
-} else {
-  Expr *Init = BMInitializer->getInit();
+if (Expr *Init = BMInitializer->getInit()) {
+  bool OutParens = !isa(Init);
+
+  if (OutParens)
+Out << "(";
+
   if (ExprWithCleanups *Tmp = dyn_cast(Init))
 Init = Tmp->getSubExpr();
 
@@ -365,8 +366,13 @@
&Context);
 }
   }
+
+  if (OutParens)
+Out << ")";
+} else {
+  Out << "()";
 }
-Out << ")";
+
 if (BMInitializer->isPackExpansion())
   Out << "...";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

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

This needs a clang/test/Driver test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156325

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


[PATCH] D156357: clang: Add elementwise bitreverse builtin

2023-07-26 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 544563.
bob80905 added a comment.

- remove strictfp test, add cgbuiltin case and update test in codegen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156357

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -206,3 +206,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_bitreverse() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);  
+}
Index: clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_bitreverse_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_bitreverse(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -269,6 +269,24 @@
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
 
+void test_builtin_elementwise_bitreverse(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_bitreverse();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_bitreverse(f);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float')}}
+  
+  i = __builtin_elementwise_bitreverse(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_bitreverse(d);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'double')}}
+}
+
 void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_ceil(f);
Index: clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_bitreverse_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_bitreverse(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -323,6 +323,42 @@
   int_as_one = __builtin_elementwise_min(int_as_one, b);
 }
 
+void test_builtin_elementwise_bitreverse(si8 vi1, si8 vi2,
+  long long int i1, long long int i2, short si,
+  _BitInt(31) bi1, _BitInt(31) bi2) {
+  
+
+  // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
+  // CHECK-NEXT: call i64 @llvm.bitreverse.i64(i64 [[I1]])
+  i2 = __builtin_elementwise_bitreverse(i1);
+
+  // CHECK:  [[VI1:%.+]] = load <8 x i16>, ptr %vi1.addr, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> [[VI1]])
+  vi2 = __builtin_elementwise_bitreverse(vi1);
+
+  // CHECK:  [[CVI2:%.+]] = load <8 x i16>, ptr %cvi2, align 16
+  // CHECK-NEXT: call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> [[CVI2]])
+  const si8 cvi2 = vi2;
+  vi2

[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

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

> (1) UBOR is only triggered when the constant folding performed by the Clang 
> Static Analyzer engine determines that the value of a binary operator 
> expression is undefined

Yes I wholeheartedly agree, these checks are pre-condition checks, they should 
have never been implemented in `checkPostStmt`. Instead they should stop the 
engine from evaluating the statement entirely if they think undefined behavior 
would occur, just like the division by zero checker. Just for that reason I'm 
happy to remove the existing bitshift check in favor of this check, as well as 
remove the `ExprEngine`/`SValBuilder` code that produces `UndefinedVal`s in 
these cases. So, architecturally, this is the step in the right direction and I 
love it!

> (4) UBOR exhibits buggy behavior in code that involves cast expressions

Hmm, what makes your check more resilient to our overall type-incorrectness?




Comment at: clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp:94-98
+void BitwiseShiftValidator::run() {
+  if (isValidShift()) {
+Ctx.addTransition(State, createNoteTag());
+  }
+}

Because `addTransition()` is a very confusing API that's very easy to misuse in 
subtle ways (causing unexpected state splits), I feel anxious when I see 
functions like
```
  bool isValidShift();
  bool isOvershift();
  bool isOperandNegative(OperandSide Side);
  bool isLeftShiftOverflow();
```
that look like boolean getters but in fact call `addTransition()` under the 
hood. If we could at least call them `checkOvershift()` etc., that'd be much 
better. Ideally I wish there was some safeguard against producing redundant 
transitions, like make them return an `ExplodedNode` and chain them, or 
something like that.



Comment at: clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp:301-302
+  pluralSuffix(MaximalAllowedShift));
+R->addNote(LeftNote, PathDiagnosticLocation{LHS, Ctx.getSourceManager(),
+Ctx.getLocationContext()});
+Ctx.emitReport(std::move(R));

Can we just append this to the warning? The `addNote()` is useful for notes 
that need to be placed in code outside of the execution path, but if it's 
always next to the warning, it probably doesn't make sense to display it 
separately.



Comment at: clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp:352-353
+std::make_unique(BT, ShortMsg, Msg, ErrNode);
+bugreporter::trackExpressionValue(ErrNode, Op->getLHS(), *R);
+bugreporter::trackExpressionValue(ErrNode, Op->getRHS(), *R);
+return R;

Props!! Even if they don't do anything, ultimately it's their responsibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156312

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Rashmi Mudduluru 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 rGa6ae740e743a: [-Wunsafe-buffer-usage] Add a facility for 
debugging low fixit coverage (authored by t-rasmud).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D154880?vs=544547&id=544561#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154880

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -verify=expected %s
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -verify=expected,debug %s
+
+// A generic -debug would also enable our notes. This is probably fine.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -mllvm -debug \
+// RUN:-verify=expected,debug %s
+
+// This test file checks the behavior under the assumption that no fixits
+// were emitted for the test cases. If -Wunsafe-buffer-usage is improved
+// to support these cases (thus failing the test), the test should be changed
+// to showcase a different unsupported example.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -fdiagnostics-parseable-fixits %s \
+// RUN:2>&1 | FileCheck %s
+// CHECK-NOT: fix-it:
+
+// This debugging facility is only available in debug builds.
+//
+// REQUIRES: asserts
+
+void foo() {
+  int *x = new int[10]; // expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  x[5] = 10;// expected-note{{used in buffer access here}}
+  int z = x[-1];// expected-note{{used in buffer access here}} \
+// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
+}
+
+void failed_decl() {
+  int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : not a pointer}}
+  
+  for (int i = 0; i < 10; i++) {
+a[i] = i;  // expected-note{{used in buffer access here}}
+  }
+}
+
+void failed_multiple_decl() {
+  int *a = new int[4], b;  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}
+  a[4] = 3;  // expected-note{{used in buffer access here}}
+}
+
+void failed_param_var_decl(int *a =new int[3]) {  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : has default arg}}
+  a[4] = 6;  // expected-note{{used in buffer access here}}
+}
+
+void unclaimed_use() {
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[2] = 9;  // expected-note{{used in buffer access here}}
+  int *b = a++;  // expected-note{{used in pointer arithmetic here}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for 'a' : has an unclaimed use}}
+}
+
+void implied_unclaimed_var(int *b) {  // expected-warning{{'b' is an unsafe pointer used for buffer access}}
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[4] = 7;  // expected-note{{used in buffer access here}}
+  a = b;  // debug-note{{safe buffers debug: gadget 'PointerAssignment' refused to produce a fix}}
+  b++;  // expected-note{{used in pointer arithmetic here}} \
+// debug-note{{safe buffers debug: failed to produce fixit for 'b' : has an unclaimed use}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2276,6 +2276,12 @@
   for (const auto &F : Fixes)
 FD << F;
 }
+
+#ifndef NDEBUG
+if (areDebugNotesRequested())
+  for (const DebugNote &Note: DebugNotesByVar[Variable])
+S.Diag(Note.first, diag::note_safe_buffer_debug_mode) << Note.second;
+#endif
   }
 
   bool isSafeBufferOptOut(const SourceLocation &Loc) const override {
Index: clang/

[clang] a6ae740 - [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage

2023-07-26 Thread Rashmi Mudduluru via cfe-commits

Author: Rashmi Mudduluru
Date: 2023-07-26T17:07:36-07:00
New Revision: a6ae740e743a2241f7104c13152cd0a0582765c5

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

LOG: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage

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

Added: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 6766ba8ec2..13f28076c6f4d7 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "llvm/Support/Debug.h"
 
 namespace clang {
 
@@ -24,6 +25,18 @@ using DefMapTy = llvm::DenseMap>;
 /// The interface that lets the caller handle unsafe buffer usage analysis
 /// results by overriding this class's handle... methods.
 class UnsafeBufferUsageHandler {
+#ifndef NDEBUG
+public:
+  // A self-debugging facility that you can use to notify the user when
+  // suggestions or fixits are incomplete.
+  // Uses std::function to avoid computing the message when it won't
+  // actually be displayed.
+  using DebugNote = std::pair;
+  using DebugNoteList = std::vector;
+  using DebugNoteByVar = std::map;
+  DebugNoteByVar DebugNotesByVar;
+#endif
+
 public:
   UnsafeBufferUsageHandler() = default;
   virtual ~UnsafeBufferUsageHandler() = default;
@@ -43,6 +56,26 @@ class UnsafeBufferUsageHandler {
  const DefMapTy &VarGrpMap,
  FixItList &&Fixes) = 0;
 
+#ifndef NDEBUG
+public:
+  bool areDebugNotesRequested() {
+DEBUG_WITH_TYPE("SafeBuffers", return true);
+return false;
+  }
+
+  void addDebugNoteForVar(const VarDecl *VD, SourceLocation Loc,
+  std::string Text) {
+if (areDebugNotesRequested())
+  DebugNotesByVar[VD].push_back(std::make_pair(Loc, Text));
+  }
+
+  void clearDebugNotes() {
+if (areDebugNotesRequested())
+  DebugNotesByVar.clear();
+  }
+#endif
+
+public:
   /// Returns a reference to the `Preprocessor`:
   virtual bool isSafeBufferOptOut(const SourceLocation &Loc) const = 0;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c88f25209fc0fa..b531babf0449c4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11872,6 +11872,12 @@ def note_unsafe_buffer_variable_fixit_group : Note<
   "change type of %0 to '%select{std::span|std::array|std::span::iterator}1' 
to preserve bounds information%select{|, and change %2 to 
'%select{std::span|std::array|std::span::iterator}1' to propagate bounds 
information between them}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+#ifndef NDEBUG
+// Not a user-facing diagnostic. Useful for debugging false negatives in
+// -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
+def note_safe_buffer_debug_mode : Note<"safe buffers debug: %0">;
+#endif
+
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
 

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 7b1c5107a7e049..781dc13c898d22 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -316,6 +316,15 @@ class Gadget {
 
   Kind getKind() const { return K; }
 
+#ifndef NDEBUG
+  StringRef getDebugName() const {
+switch (K) {
+#define GADGET(x) case Kind::x: return #x;
+#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
+}
+  }
+#endif
+
   virtual bool isWarningGadget() const = 0;
   virtual const Stmt *getBaseStmt() const = 0;
 
@@ -565,7 +574,11 @@ class PointerInitGadget : public FixableGadget {
 
   virtual std::optional getFixits(const Strategy &S) const override;
 
-  virtual const Stmt *getBaseStmt() const override { return nullptr; }
+  virtual const Stmt *getBaseStmt() const override {
+// FIXME: This needs to be the entire DeclStmt, assuming that this method
+// makes sense at all on a FixableGadget.
+return PtrInitRHS;
+  }
 
   virtual DeclUseList getClaimedVarUseSites() const override {
 return DeclUseList{PtrInitRHS};
@@ -613,7 +626,11 @

[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The general approach seems fine.  The multiplier for constexpr vs. constant 
folding can be left for a followup, and we can continue to consider other 
possible improvements elsewhere.

I guess I have one remaining question here: how does this interact with SFINAE? 
 In other words, if we hit the limit analyzing the signature of a function, do 
we print an error, or silently remove the function from the overload list?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[PATCH] D153058: [clang][CFG] Support construction of a weak topological ordering of the CFG.

2023-07-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 5 inline comments as done.
ymandel added a comment.

Thanks for the helpful suggestions!




Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:104
+/// intervals) if and only if it is reducible (its limit flow graph has one
+/// node). Returns `nullop` when `Cfg` is not reducible.
+///

sammccall wrote:
> sammccall wrote:
> > nit: nullopt
> what do we expect to do in practice when the CFG is not reducible? or do we 
> expect that to never happen?
> 
> (mostly wondering if we need a fallback)
good question -- I'm not really sure what to expect. In practice, any 
structured function will yield a reducible graph. But, creative use of goto's 
can undermine that. So, my guess is that we will not encounter these in 
practice, but I don't know for sure.

As for fallback, RPO doesn't rely on reducibility. So, clients are free to use 
that instead when this fails.



Comment at: clang/lib/Analysis/IntervalPartition.cpp:105
+void fillIntervalNode(CFGIntervalGraph &Graph,
+  std::map &Index,
+  std::queue &Successors,

sammccall wrote:
> std::map of pointers is a bit suspicious, densemap?
I went with a vector mapping (implicitly) from Node IDs, like I did for the WTO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153058

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


[PATCH] D153058: [clang][CFG] Support construction of a weak topological ordering of the CFG.

2023-07-26 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 544551.
ymandel marked 2 inline comments as done.
ymandel added a comment.

Addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153058

Files:
  clang/include/clang/Analysis/Analyses/IntervalPartition.h
  clang/lib/Analysis/IntervalPartition.cpp
  clang/unittests/Analysis/IntervalPartitionTest.cpp

Index: clang/unittests/Analysis/IntervalPartitionTest.cpp
===
--- clang/unittests/Analysis/IntervalPartitionTest.cpp
+++ clang/unittests/Analysis/IntervalPartitionTest.cpp
@@ -8,15 +8,109 @@
 
 #include "clang/Analysis/Analyses/IntervalPartition.h"
 #include "CFGBuildResult.h"
+#include "clang/Analysis/CFG.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
-namespace analysis {
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const std::vector &Nodes) {
+  OS << "Blocks{";
+  for (const auto *B : Nodes)
+OS << B->getBlockID() << ", ";
+  OS << "}";
+  return OS;
+}
+
+void PrintTo(const std::vector &Nodes, std::ostream *OS) {
+  std::string Result;
+  llvm::raw_string_ostream StringOS(Result);
+  StringOS << Nodes;
+  *OS << Result;
+}
+
+namespace internal {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const CFGIntervalNode &I) {
+  OS << "Interval{ID = " << I.ID << ", ";
+  OS << "Blocks{";
+  for (const auto *B : I.Nodes)
+OS << B->getBlockID() << ", ";
+  OS << "}, Pre{";
+  for (const auto *P : I.Predecessors)
+OS << P->ID << ",";
+  OS << "}, Succ{";
+  for (const auto *P : I.Successors)
+OS << P->ID << ",";
+  OS << "}}";
+  return OS;
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+  const CFGIntervalGraph &G) {
+  OS << "Intervals{";
+  for (const auto &I : G) {
+OS << I << ", ";
+  }
+  OS << "}";
+  return OS;
+}
+
+void PrintTo(const CFGIntervalNode &I, std::ostream *OS) {
+  std::string Result;
+  llvm::raw_string_ostream StringOS(Result);
+  StringOS << I;
+  *OS << Result;
+}
+
+void PrintTo(const CFGIntervalGraph &G, std::ostream *OS) {
+  *OS << "Intervals{";
+  for (const auto &I : G) {
+PrintTo(I, OS);
+*OS << ", ";
+  }
+  *OS << "}";
+}
+} // namespace internal
+
 namespace {
 
-TEST(BuildInterval, PartitionSimpleOneInterval) {
+using ::clang::analysis::BuildCFG;
+using ::clang::analysis::BuildResult;
+using ::clang::internal::buildInterval;
+using ::clang::internal::partitionIntoIntervals;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::Optional;
+using ::testing::Property;
+using ::testing::UnorderedElementsAre;
+
+MATCHER_P(intervalID, ID, "") { return arg->ID == ID; }
+
+template  auto blockIDs(T... IDs) {
+  return UnorderedElementsAre(Property(&CFGBlock::getBlockID, IDs)...);
+}
+
+template  auto blockOrder(T... IDs) {
+  return ElementsAre(Property(&CFGBlock::getBlockID, IDs)...);
+}
+
+MATCHER_P3(isInterval, ID, Preds, Succs, "") {
+  return testing::Matches(ID)(arg.ID) &&
+ testing::Matches(Preds)(arg.Predecessors) &&
+ testing::Matches(Succs)(arg.Successors);
+}
+
+MATCHER_P4(isInterval, ID, Nodes, Preds, Succs, "") {
+  return testing::Matches(ID)(arg.ID) && testing::Matches(Nodes)(arg.Nodes) &&
+ testing::Matches(Preds)(arg.Predecessors) &&
+ testing::Matches(Succs)(arg.Successors);
+}
 
+TEST(BuildInterval, PartitionSimpleOneInterval) {
   const char *Code = R"(void f() {
   int x = 3;
   int y = 7;
@@ -32,12 +126,11 @@
 
   auto &EntryBlock = cfg->getEntry();
 
-  CFGInterval I = buildInterval(*cfg, EntryBlock);
-  EXPECT_EQ(I.Blocks.size(), 3u);
+  std::vector I = buildInterval(&EntryBlock);
+  EXPECT_EQ(I.size(), 3u);
 }
 
 TEST(BuildInterval, PartitionIfThenOneInterval) {
-
   const char *Code = R"(void f() {
   int x = 3;
   if (x > 3)
@@ -56,14 +149,11 @@
 
   auto &EntryBlock = cfg->getEntry();
 
-  CFGInterval I = buildInterval(*cfg, EntryBlock);
-  EXPECT_EQ(I.Blocks.size(), 6u);
+  std::vector I = buildInterval(&EntryBlock);
+  EXPECT_EQ(I.size(), 6u);
 }
 
-using ::testing::UnorderedElementsAre;
-
 TEST(BuildInterval, PartitionWhileMultipleIntervals) {
-
   const char *Code = R"(void f() {
   int x = 3;
   while (x >= 3)
@@ -80,11 +170,11 @@
   CFGBlock *InitXBlock = *EntryBlock->succ_begin();
   CFGBlock *LoopHeadBlock = *InitXBlock->succ_begin();
 
-  CFGInterval I1 = buildInterval(*cfg, *EntryBlock);
-  EXPECT_THAT(I1.Blocks, UnorderedElementsAre(EntryBlock, InitXBlock));
+  std::vector I1 = buildInterval(EntryBlock);
+  EXPECT_THAT(I1, ElementsAre(EntryBlock, InitXBlock));
 
-  CFGInterval I2 = buildInterval(*cfg, *LoopHeadBlock);
-  EXPECT_EQ(I2.Blocks.size(), 5u);
+

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

2023-07-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> But prior to D151587 , we did that for C++. 
> Why is C special here?  And prior to this patch, we did that for C++ 11+. Why 
> is C++ 03 special here?

I'm trying to avoid regressions.

C++11 made constant evaluation a lot more complicated, so in C++11 we 
evaluate() every global to determine const-ness.  But it's always worked that 
way, so there's no regression.  I'm not exactly happy C++11 made everything 
more expensive, but fixing that is a lot harder, and not a regression.

> So I feel like your feedback is pulling me in opposite directions. You want 
> to avoid the fast path falling back to the slow path, but improvements to the 
> fast path directly result in "complete parallel infrastructure" which you 
> also don't want. Those seem mutually exclusive to me. Is there a third 
> option? Am I attacking a strawman? (Regardless, I don't want to seem 
> unappreciative of the reviews, advice, or discussion).

The primary thing that makes Evaluate/APValue slow is the fact that it has a 
very inefficient representation of structs and arrays.  Using it to evaluate 
simple integer expressions is largely comparable to non-Evaluate() methods.  
The idea is to maintain the parallel infrastructure for structs and arrays, but 
not for other things.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76096

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


[PATCH] D156351: clang driver throws error for -mabi=elfv2 or elfv2

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

> After clang release/16.x there is a regression that -mabi=elfv1 or 
> -mabi=elfv2 are being unused and throws warning.

Please just give the full clang command line and add a test case under 
`test/Driver`. FWIW: `clang --target=powerpc64le-linux-gnu -mabi=elfv1 
-mabi=elfv2 -c a.c` works for me without any warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156351

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


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

2023-07-26 Thread Amy Huang 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 rG27dab4d305ac: Reland "Try to implement lambdas with 
inalloca parameters by forwarding without… (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154007

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

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

[clang] 27dab4d - Reland "Try to implement lambdas with inalloca parameters by forwarding without use of inallocas."t

2023-07-26 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2023-07-26T16:13:36-07:00
New Revision: 27dab4d305acb6e0935e014c061c5317016ae2b3

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

LOG: Reland "Try to implement lambdas with inalloca parameters by forwarding 
without use of inallocas."t

This reverts commit 8ed7aa59f489715d39d32e72a787b8e75cfda151.

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/CodeGen/CGFunctionInfo.h 
b/clang/include/clang/CodeGen/CGFunctionInfo.h
index 39c7a578c8c4e0..b8971d5793f361 100644
--- a/clang/include/clang/CodeGen/CGFunctionInfo.h
+++ b/clang/include/clang/CodeGen/CGFunctionInfo.h
@@ -567,6 +567,10 @@ class CGFunctionInfo final
   /// Whether this is a chain call.
   unsigned ChainCall : 1;
 
+  /// Whether this function is called by forwarding arguments.
+  /// This doesn't support inalloca or varargs.
+  unsigned DelegateCall : 1;
+
   /// Whether this function is a CMSE nonsecure call
   unsigned CmseNSCall : 1;
 
@@ -616,14 +620,11 @@ class CGFunctionInfo final
   CGFunctionInfo() : Required(RequiredArgs::All) {}
 
 public:
-  static CGFunctionInfo *create(unsigned llvmCC,
-bool instanceMethod,
-bool chainCall,
-const FunctionType::ExtInfo &extInfo,
-ArrayRef paramInfos,
-CanQualType resultType,
-ArrayRef argTypes,
-RequiredArgs required);
+  static CGFunctionInfo *
+  create(unsigned llvmCC, bool instanceMethod, bool chainCall,
+ bool delegateCall, const FunctionType::ExtInfo &extInfo,
+ ArrayRef paramInfos, CanQualType resultType,
+ ArrayRef argTypes, RequiredArgs required);
   void operator delete(void *p) { ::operator delete(p); }
 
   // Friending class TrailingObjects is apparently not good enough for MSVC,
@@ -663,6 +664,8 @@ class CGFunctionInfo final
 
   bool isChainCall() const { return ChainCall; }
 
+  bool isDelegateCall() const { return DelegateCall; }
+
   bool isCmseNSCall() const { return CmseNSCall; }
 
   bool isNoReturn() const { return NoReturn; }
@@ -749,6 +752,7 @@ class CGFunctionInfo final
 ID.AddInteger(getASTCallingConvention());
 ID.AddBoolean(InstanceMethod);
 ID.AddBoolean(ChainCall);
+ID.AddBoolean(DelegateCall);
 ID.AddBoolean(NoReturn);
 ID.AddBoolean(ReturnsRetained);
 ID.AddBoolean(NoCallerSavedRegs);
@@ -766,17 +770,16 @@ class CGFunctionInfo final
 for (const auto &I : arguments())
   I.type.Profile(ID);
   }
-  static void Profile(llvm::FoldingSetNodeID &ID,
-  bool InstanceMethod,
-  bool ChainCall,
+  static void Profile(llvm::FoldingSetNodeID &ID, bool InstanceMethod,
+  bool ChainCall, bool IsDelegateCall,
   const FunctionType::ExtInfo &info,
   ArrayRef paramInfos,
-  RequiredArgs required,
-  CanQualType resultType,
+  RequiredArgs required, CanQualType resultType,
   ArrayRef argTypes) {
 ID.AddInteger(info.getCC());
 ID.AddBoolean(InstanceMethod);
 ID.AddBoolean(ChainCall);
+ID.AddBoolean(IsDelegateCall);
 ID.AddBoolean(info.getNoReturn());
 ID.AddBoolean(info.getProducesResult());
 ID.AddBoolean(info.getNoCallerSavedRegs());

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index bd272e016e9267..51f43b0797fd0f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -112,8 +112,7 @@ 
CodeGenTypes::arrangeFreeFunctionType(CanQual FTNP) {
   // When translating an unprototyped function type, always use a
   // variadic type.
   return arrangeLLVMFunctionInfo(FTNP->getReturnType().getUnqualifiedType(),
- /*instanceMethod=*/false,
- /*chainCall=*/false, std::nullopt,
+ FnInfoOpts::None, std::nullopt,
  FTNP->getExtInfo(), {}, RequiredArgs(0));
 }
 
@@ -189,10 +188,10 @@ arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool 
instanceMethod,
   appendParameterTypes(CGT, prefix, paramIn

[PATCH] D156370: [clang-format] Fix bug with parsing of function/variable names.

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

In D156370#4536793 , 
@HazardyKnusperkeks wrote:

> Does this result in a different annotation? Could you add a test for that?

If I understand you correctly, it does, for example:
`$ echo "void __attribute__((naked)) foo(int bar);" | clang-format -style=llvm 
-debug 2>&1 | grep \'foo\'`

Without the change:
 M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=identifier L=31 PPK=2 
FakeLParens= FakeRParens=0 II=0x555d17efdce0 Text='foo'

With the change:
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=identifier L=31 
PPK=2 FakeLParens= FakeRParens=0 II=0x559855502ce0 Text='foo'

I don't how to test for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156370

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud updated this revision to Diff 544547.

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

https://reviews.llvm.org/D154880

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -verify=expected %s
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -verify=expected,debug %s
+
+// A generic -debug would also enable our notes. This is probably fine.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -mllvm -debug \
+// RUN:-verify=expected,debug %s
+
+// This test file checks the behavior under the assumption that no fixits
+// were emitted for the test cases. If -Wunsafe-buffer-usage is improved
+// to support these cases (thus failing the test), the test should be changed
+// to showcase a different unsupported example.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -fdiagnostics-parseable-fixits %s \
+// RUN:2>&1 | FileCheck %s
+// CHECK-NOT: fix-it:
+
+// This debugging facility is only available in debug builds.
+//
+// REQUIRES: asserts
+
+void foo() {
+  int *x = new int[10]; // expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  x[5] = 10;// expected-note{{used in buffer access here}}
+  int z = x[-1];// expected-note{{used in buffer access here}} \
+// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
+}
+
+void failed_decl() {
+  int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : not a pointer}}
+  
+  for (int i = 0; i < 10; i++) {
+a[i] = i;  // expected-note{{used in buffer access here}}
+  }
+}
+
+void failed_multiple_decl() {
+  int *a = new int[4], b;  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}
+  a[4] = 3;  // expected-note{{used in buffer access here}}
+}
+
+void failed_param_var_decl(int *a =new int[3]) {  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : has default arg}}
+  a[4] = 6;  // expected-note{{used in buffer access here}}
+}
+
+void unclaimed_use() {
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[2] = 9;  // expected-note{{used in buffer access here}}
+  int *b = a++;  // expected-note{{used in pointer arithmetic here}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for 'a' : has an unclaimed use}}
+}
+
+void implied_unclaimed_var(int *b) {  // expected-warning{{'b' is an unsafe pointer used for buffer access}}
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[4] = 7;  // expected-note{{used in buffer access here}}
+  a = b;  // debug-note{{safe buffers debug: gadget 'PointerAssignment' refused to produce a fix}}
+  b++;  // expected-note{{used in pointer arithmetic here}} \
+// debug-note{{safe buffers debug: failed to produce fixit for 'b' : has an unclaimed use}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2276,6 +2276,12 @@
   for (const auto &F : Fixes)
 FD << F;
 }
+
+#ifndef NDEBUG
+if (areDebugNotesRequested())
+  for (const DebugNote &Note: DebugNotesByVar[Variable])
+S.Diag(Note.first, diag::note_safe_buffer_debug_mode) << Note.second;
+#endif
   }
 
   bool isSafeBufferOptOut(const SourceLocation &Loc) const override {
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -319,6 +319,15 @@
 
   Kind getKind() const { return K; }
 
+#ifndef NDEBUG
+  StringRef getDebugName() const {
+switch (K) {
+#define GADGET(x) case Kind::x: return #x

[PATCH] D156360: [clang-format] Support function and overloaded operator SpacesInParensOption

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

Add tests and correct function call detection.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156360

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11040,7 +11040,8 @@
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
   Spaces.SpacesInParensOptions.InCStyleCasts = false;
-  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InFunctionDeclarations = true;
+  Spaces.SpacesInParensOptions.InOverloadedOperators = true;
   verifyFormat("Deleted &operator=( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
Spaces);
@@ -13678,6 +13679,7 @@
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
   SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
   SpaceBetweenBraces.SpacesInParensOptions.Other = true;
+  SpaceBetweenBraces.SpacesInParensOptions.InFunctionCalls = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -16753,6 +16755,7 @@
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
   Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  Spaces.SpacesInParensOptions.InFunctionCalls = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16780,7 +16783,7 @@
"}",
Spaces);
   verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
-  verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
+  verifyFormat("void __attribute__( ( x ) ) foo(int y) { return; }", Spaces);
   verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
 
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
@@ -16795,6 +16798,142 @@
   verifyFormat("my_int a = ( my_int )sizeof(int);", Spaces);
   verifyFormat("#define x (( int )-1)", Spaces);
 
+  // Run the first set of tests again with:
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InFunctionDeclarations = true;
+  verifyFormat("do_something(::globalVar);", Spaces);
+  verifyFormat("call(x, y, z);", Spaces);
+  verifyFormat("call();", Spaces);
+  verifyFormat("std::function callback;", Spaces);
+  verifyFormat("void inFunction() { std::function fct; }",
+   Spaces);
+  verifyFormat("while ((bool)1)\n"
+   "  continue;",
+   Spaces);
+  verifyFormat("for (;;)\n"
+   "  continue;",
+   Spaces);
+  verifyFormat("if (true)\n"
+   "  f();\n"
+   "else if (true)\n"
+   "  f();",
+   Spaces);
+  verifyFormat("do {\n"
+   "  do_something((int)i);\n"
+   "} while (something());",
+   Spaces);
+  verifyFormat("switch (x) {\n"
+   "default:\n"
+   "  break;\n"
+   "}",
+   Spaces);
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("void __attribute__((naked)) foo( int bar );", Spaces);
+  verifyFormat("void f( int g ) __attribute__((asdf));", Spaces);
+  verifyFormat("int f();", Spaces);
+  verifyFormat("void f(int a, T b) {}", Spaces);
+  verifyFormat("void __attribute__((asdf)) f(int a, T b) {}", Spaces);
+  verifyFormat("A::A() : a(1) {}", Spaces);
+  verifyFormat("void f( int bar ) __attribute__((asdf));", Spaces);
+  verifyFormat("void __attribute__((asdf)) f( int bar );", Spaces);
+  verifyFormat("#define A(x) x", Spaces);
+  verifyFormat("#define A (x) x", Spaces);
+  verifyFormat("#if defined(x)\n"
+   "#endif",
+   Spaces);
+  verifyFormat("auto i = std::make_unique(5);", Spaces);
+  verifyFormat("size_t x = sizeof(x);", Spaces);
+  verifyFormat("auto f( int x ) -> decltype(x);", Spaces);
+  verifyFormat("auto f( int x ) -> typeof(x);", Spaces);
+  verifyFormat("auto f( int x ) -> _Atomic(x);", Spaces);
+  verifyFormat("auto f( int x ) -> __underlying_type(x);", Spaces);
+  verifyFormat("int f( T x ) noexcept(x.create());", Spaces);
+  verifyFormat("alignas(128) char a[128];", Spaces);
+  verifyFormat("size_t x = alignof(MyType);", Spaces);
+  verifyFormat("static_

[PATCH] D154130: [lit][clang] Avoid realpath on Windows due to MAX_PATH limitations

2023-07-26 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:655
+  SmallString<4096> AbsPathBuf = Name;
+  SmallString<4096> RealPathBuf;
+  if (!FS->makeAbsolute(AbsPathBuf)) {

8k is a lot of stack space. The only reason this was 4k in the first place is 
it was originally using `char[PATH_MAX]` and unix `realpath` directly.  I'd 
suggest just dropping to 128 per path.



Comment at: clang/lib/Basic/FileManager.cpp:663
+} else {
+  llvm::sys::path::remove_dots(AbsPathBuf, /*remove_dot_dot=*/true);
+  CanonicalName = AbsPathBuf.str().copy(CanonicalNameStorage);

Removing .. can change where the path points in the presence of symlinks; is 
this needed?



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:190
 
-StringRef FileName = File->tryGetRealPathName().empty()
- ? File->getName()
- : File->tryGetRealPathName();
+StringRef FileName = SM.getFileManager().getCanonicalName(File);
 

Why is this change needed?


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

https://reviews.llvm.org/D154130

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


[PATCH] D156224: [Clang] use unsigned integer constants in unit-test | fixes build error on ppc64le-lld-multistage-test

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



Comment at: clang/unittests/libclang/LibclangTest.cpp:1232
   ASSERT_TRUE(staticAssertCsr.has_value());
-  size_t argCnt = 0;
+  int argCnt = 0;
   Traverse(*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent) {

Above you used `0u` but here you changed the type to `int`, is there a reason 
why not to use `0u` here as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156224

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

LGTM! I'm excited to learn what this new facility discovers!




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1730-1735
+#ifndef NDEBUG
+#define DEBUG_NOTE_DECL_FAIL(D, Msg)  \
+Handler.addDebugNoteForVar((D), (D)->getBeginLoc(), "failed to produce fixit 
for declaration '" + D->getNameAsString() + "'" + Msg)
+#else
+#define DEBUG_NOTE_DECL_FAIL(D, Msg)
+#endif

An extra bit of paranoia.


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

https://reviews.llvm.org/D154880

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-26 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 544542.
koops added a comment.

Fixing Alexey's suggestions.


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

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/OpenMP/generic_loop_ast_print.cpp
  clang/test/OpenMP/generic_loop_codegen.cpp
  clang/test/OpenMP/loop_bind_codegen.cpp
  clang/test/OpenMP/loop_bind_enclosed.cpp
  clang/test/OpenMP/loop_bind_messages.cpp
  clang/test/OpenMP/nested_loop_codegen.cpp

Index: clang/test/OpenMP/nested_loop_codegen.cpp
===
--- clang/test/OpenMP/nested_loop_codegen.cpp
+++ clang/test/OpenMP/nested_loop_codegen.cpp
@@ -58,6 +58,12 @@
 // CHECK1-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
+// CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IV:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_LB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_UB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
@@ -66,35 +72,27 @@
 // CHECK1-NEXT:store i32 0, ptr [[TMP0]], align 4
 // CHECK1-NEXT:br label [[FOR_COND:%.*]]
 // CHECK1:   for.cond:
-// CHECK1-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 10
-// CHECK1-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END7:%.*]]
 // CHECK1:   for.body:
-// CHECK1-NEXT:store i32 0, ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1:%.*]]
-// CHECK1:   for.cond1:
-// CHECK1-NEXT:[[TMP2:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[CMP2:%.*]] = icmp slt i32 [[TMP2]], 5
-// CHECK1-NEXT:br i1 [[CMP2]], label [[FOR_BODY3:%.*]], label [[FOR_END:%.*]]
-// CHECK1:   for.body3:
-// CHECK1-NEXT:[[TMP3:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC:%.*]] = add nsw i32 [[TMP3]], 1
-// CHECK1-NEXT:store i32 [[INC]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_INC:%.*]]
-// CHECK1:   for.inc:
-// CHECK1-NEXT:[[TMP4:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC4:%.*]] = add nsw i32 [[TMP4]], 1
-// CHECK1-NEXT:store i32 [[INC4]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1]], !llvm.loop [[LOOP3:![0-9]+]]
-// CHECK1:   for.end:
-// CHECK1-NEXT:br label [[FOR_INC5:%.*]]
-// CHECK1:   for.inc5:
-// CHECK1-NEXT:[[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[INC6:%.*]] = add nsw i32 [[TMP5]], 1
-// CHECK1-NEXT:store i32 [[INC6]], ptr [[TMP0]], align 4
-// CHECK1-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP5:![0-9]+]]
-// CHECK1:   for.end7:
-// CHECK1-NEXT:ret void
+// CHECK1-NEXT [[TMP2:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_init_4(ptr @1, i32 [[TMP3]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+//CHECK1 cond.end:
+//CHECK1 omp.inner.for.cond:
+//CHECK1 omp.inner.for.body:
+//CHECK1 omp.body.continue:
+//CHECK1 omp.inner.for.inc:
+//CHECK1 omp.inner.for.end:
+//CHECK1 omp.loop.exit:
+// CHECK1-NEXT [[TMP13:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP14:%.*]] = load i32, ptr [[TMP12]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_fini(ptr @1, i32 [[TMP14]])
+// CHECK1-NEXT [[TMP15:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP16:%.*]] = load i32, ptr [[TMP15]], align 4
+// CHECK1-NEXT call void @__kmpc_barrier(ptr @2, i32 [[TMP16]])
+//CHECK1 for.inc:
+//CHECK1 for.end:
+// CHECK1-NEXT ret void
+//
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@_Z11inline_declv
@@ -114,45 +112,36 @@
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[RES_ADDR:%.*]] = alloca ptr, align 8
-// CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
-// CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
-// CHECK1-NEXT:store ptr [[I]], ptr [[I_ADDR]], align 8
-// CHECK1-NEXT: 

[PATCH] D150946: [clang][Interp] PointerToIntegral casts

2023-07-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

This test is failing on our Windows builders with the following error:

  Script:
  --
  : 'RUN: at line 1';   c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\llvm_build\lib\clang\18\include 
-nostdsysteminc -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++11 -verify 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp
  : 'RUN: at line 2';   c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\llvm_build\lib\clang\18\include 
-nostdsysteminc -fexperimental-new-constant-interpreter -fms-extensions 
-std=c++20 -verify 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp
  : 'RUN: at line 3';   c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\llvm_build\lib\clang\18\include 
-nostdsysteminc -std=c++11 -fms-extensions -verify=ref 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp
  : 'RUN: at line 4';   c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe -cc1 
-internal-isystem c:\b\s\w\ir\x\w\llvm_build\lib\clang\18\include 
-nostdsysteminc -std=c++20 -fms-extensions -verify=ref 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe" "-cc1" "-internal-isystem" 
"c:\b\s\w\ir\x\w\llvm_build\lib\clang\18\include" "-nostdsysteminc" 
"-fexperimental-new-constant-interpreter" "-fms-extensions" "-std=c++11" 
"-verify" "C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp"
  # command stderr:
  error: 'warning' diagnostics seen but not expected: 
File C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\AST\Interp\literals.cpp 
Line 946: cast to smaller integer type 'long' from 'char *'
  1 error generated.
  
  error: command failed with exit status: 1

Would it be possible to either quickly address the issue or revert the change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150946

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


[PATCH] D153623: [clang][Sema] Add fixit for scoped enum format error

2023-07-26 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Sorry for the delayed comment here.

The fix-it is convenient, but is it the best suggestion? It'll end up 
suggesting truncating the enum value instead of using the proper format 
specifier in https://godbolt.org/z/xdhrefG95, for example. More insidiously, 
the `static_cast` might work fine for all enum uses today but silently cause 
issues for future enum values.

Using `std::to_underyling` and matching the format specifier to the underlying 
type would be the best suggestion IMO, but that only works in C++23 and above 
:( I guess `std::underlying_type_t` isn't super ugly either for C++14 and 
above, but bare `std::underlying_type` is pretty rough to use in a cast. All of 
those require the addition of a header though, and I'm not sure if that's 
acceptable for a fix-it.

Would we at least consider suggesting a format specifier and cast based on the 
underlying type of the enum, instead of just casting to whatever type the 
format specifier was using? That won't guard against future changes to the 
enum, but it's better than the status quo IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153623

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


[PATCH] D156366: HIP: Use __builtin_sqrt instead of routing through ocml sqrt for f64

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

63dbe7e808d07bdf25bad85301980bc323b0cd64


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

https://reviews.llvm.org/D156366

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


[PATCH] D156378: [clang][CGExprConstant] handle unary negation on integrals

2023-07-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 544538.
nickdesaulniers added a comment.

- fix oneline class


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156378

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1363,6 +1363,19 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitUnaryOperator(UnaryOperator *U, QualType T) {
+switch (U->getOpcode()) {
+default:
+  break;
+case UO_Minus:
+  if (llvm::Constant *C = Visit(U->getSubExpr(), T))
+if (auto *CI = dyn_cast(C))
+  return llvm::ConstantInt::get(CGM.getLLVMContext(), -CI->getValue());
+  break;
+}
+return nullptr;
+  }
+
   // Utility methods
   llvm::Type *ConvertType(QualType T) {
 return CGM.getTypes().ConvertType(T);


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1363,6 +1363,19 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitUnaryOperator(UnaryOperator *U, QualType T) {
+switch (U->getOpcode()) {
+default:
+  break;
+case UO_Minus:
+  if (llvm::Constant *C = Visit(U->getSubExpr(), T))
+if (auto *CI = dyn_cast(C))
+  return llvm::ConstantInt::get(CGM.getLLVMContext(), -CI->getValue());
+  break;
+}
+return nullptr;
+  }
+
   // Utility methods
   llvm::Type *ConvertType(QualType T) {
 return CGM.getTypes().ConvertType(T);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156378: [clang][CGExprConstant] handle unary negation on integrals

2023-07-26 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Consider the statement:

  int x = -1;

And the following AST:

  `-VarDecl 0x55c4823a7670  col:5 x 'int' cinit
`-UnaryOperator 0x55c4823a7740  'int' prefix '-'
  `-IntegerLiteral 0x55c4823a7720  'int' 1

Return the evaluation of the subexpression negated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156378

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1363,6 +1363,19 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitUnaryOperator(UnaryOperator *U, QualType T) {
+switch (U->getOpcode()) {
+default:
+  break;
+case UO_Minus:
+  if (llvm::Constant *C = Visit(U->getSubExpr(), T))
+if (auto *CI = dyn_cast(C))
+  return llvm::ConstantInt::get(CGM.getLLVMContext(), -CI->getValue());
+  break;
+}
+return nullptr;
+  }
+
   // Utility methods
   llvm::Type *ConvertType(QualType T) {
 return CGM.getTypes().ConvertType(T);


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1363,6 +1363,19 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitUnaryOperator(UnaryOperator *U, QualType T) {
+switch (U->getOpcode()) {
+default:
+  break;
+case UO_Minus:
+  if (llvm::Constant *C = Visit(U->getSubExpr(), T))
+if (auto *CI = dyn_cast(C))
+  return llvm::ConstantInt::get(CGM.getLLVMContext(), -CI->getValue());
+  break;
+}
+return nullptr;
+  }
+
   // Utility methods
   llvm::Type *ConvertType(QualType T) {
 return CGM.getTypes().ConvertType(T);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2023-07-26 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9461-9463
+  bool CorrectSqrt = CGM.getLangOpts().OpenCL
+ ? CGM.getCodeGenOpts().OpenCLCorrectlyRoundedDivSqrt
+ : CGM.getCodeGenOpts().HIPCorrectlyRoundedDivSqrt;

Can we move this into something more proper in LangOpts?



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9467
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);
+  AddGlobal("__oclc_finite_only_opt", FiniteOnly || RelaxedMath, /*Size=*/8);
+  AddGlobal("__oclc_unsafe_math_opt", UnsafeMath || RelaxedMath, /*Size=*/8);

I'd hope you don't have to check relaxed math, finite only should suffice



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9476
+llvm::GlobalValue::LinkOnceODRLinkage);
+  AddGlobal("__oclc_ABI_version",
+CGM.getTarget().getTargetOpts().CodeObjectVersion, /*Size=*/32,

This should probably get an __llvm_amdgcn prefix and be renamed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D156330: [hexagon] restore library path arguments

2023-07-26 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 544533.
bcain added a comment.

Too hasty w/the last update - forgot to remove the `-###`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156330

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,9 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -v -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s 2>&1 \
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   
//
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   
//
   //


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,9 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" "[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -v -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s 2>&1 \
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   //
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   //
   //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2023-07-26 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

We should just do this now. clang shouldn't have to dig around on disk to emit 
a constant definition for a constant it already knows, and we have a clear path 
to removing these globals altogether. I have adequate patches to completely 
delete `__oclc_daz_opt` today. `__oclc_finite_only_opt` should be deleteable as 
soon as nofpclass is inferred by default. Deleting 
`__oclc_correctly_rounded_sqrt32` and `__oclc_unsafe_math_opt` require more 
work, but are basically the same thing and require extending the libcall 
optimizer pass.

It will be easier to delete these from the library as they become unnecessary 
if clang stops enforcing these files exists like it does today, and it's easier 
to just stop using them entirely than to delete them one at a time


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D156330: [hexagon] restore library path arguments

2023-07-26 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 544532.
bcain added a comment.

I misunderstood the previous suggestion about `-fdriver-only -Werror -v` and 
thought I needed to separate the test into two invocations.  Combined these 
back into a single RUN now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156330

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,9 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -v -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   
//
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   
//
   //


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,9 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" "[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -v -L/tmp \
+// RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   //
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   //
   //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156330: [hexagon] restore library path arguments

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

In D156330#4536827 , @bcain wrote:

> Fixed target: `--target=hexagon-unknown-linux` was not correct for testing 
> this bug, it should have been `--target=hexagon-unknown-linux-musl`.
>
> Used `-fdriver-only -Werror` as suggested but it did require separating the 
> tests.
>
> Quoted the library path arg, to make match from `-cc1` command stricter, from 
> review suggestion.
>
> Fixed wrapping.

`-fdriver-only -v -Werror` is preferred because `-###` has a quirk. I hope we 
will fix it in the near future: D156363  :) 
Your change doesn't need to be blocked by that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156330

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


[PATCH] D156330: [hexagon] restore library path arguments

2023-07-26 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 544527.
bcain added a comment.

Fixed target: `--target=hexagon-unknown-linux` was not correct for testing this 
bug, it should have been `--target=hexagon-unknown-linux-musl`.

Used `-fdriver-only -Werror` as suggested but it did require separating the 
tests.

Quoted the library path arg, to make match from `-cc1` command stricter, from 
review suggestion.

Fixed wrapping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156330

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,11 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" 
"[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -L/tmp \
+// RUN: --target=hexagon-unknown-linux-musl %s
+
+// RUN: %clang -Werror -L/tmp --target=hexagon-unknown-linux-musl %s -### 2>&1 
\
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   
//
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   
//
   //


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -119,3 +119,11 @@
 // CHECK009:   "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK009-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK009-SAME: {{^}} "-internal-externc-isystem" "[[INSTALLED_DIR]]/../target/hexagon/include"
+
+// RUN: %clang -fdriver-only -Werror -L/tmp \
+// RUN: --target=hexagon-unknown-linux-musl %s
+
+// RUN: %clang -Werror -L/tmp --target=hexagon-unknown-linux-musl %s -### 2>&1 \
+// RUN:| FileCheck -check-prefix=CHECK010 %s
+// CHECK010:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK010:   "-L/tmp"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -383,7 +383,6 @@
   if (HTC.ShouldLinkCXXStdlib(Args))
 HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
 }
-return;
   }
 
   //
@@ -441,6 +440,7 @@
   const ToolChain::path_list &LibPaths = HTC.getFilePaths();
   for (const auto &LibPath : LibPaths)
 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  Args.ClaimAllArgs(options::OPT_L);
 
   //
   //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156370: [clang-format] Fix bug with parsing of function/variable names.

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

Does this result in a different annotation? Could you add a test for that?




Comment at: clang/lib/Format/TokenAnnotator.cpp:2211-2212
 if (PreviousNotConst->is(tok::r_paren) &&
-PreviousNotConst->is(TT_TypeDeclarationParen)) {
+(PreviousNotConst->is(TT_TypeDeclarationParen) ||
+ PreviousNotConst->is(TT_AttributeParen))) {
   return true;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156370

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


[PATCH] D156363: [Driver] -###: exit with code 1 if hasErrorOccurred

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

@jhuber6 @yaxunl you may want to revise some AMDGPU related tests, e.g. 
`amdgcn-gz-options.cl`.
Some `RUN: %clang` lines currently fail with `error: cannot find ROCm device 
library; provide its path via '--rocm-path' or '--rocm-device-lib-path', or 
pass '-nogpulib' to build without ROCm device library`.
They likely need `-nogpulib` to stop them from depending on the `-###` quirk 
(exit code 0), which is going to be fixed by this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156363

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud updated this revision to Diff 544521.

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

https://reviews.llvm.org/D154880

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -verify=expected %s
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -verify=expected,debug %s
+
+// A generic -debug would also enable our notes. This is probably fine.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -mllvm -debug \
+// RUN:-verify=expected,debug %s
+
+// This test file checks the behavior under the assumption that no fixits
+// were emitted for the test cases. If -Wunsafe-buffer-usage is improved
+// to support these cases (thus failing the test), the test should be changed
+// to showcase a different unsupported example.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -fdiagnostics-parseable-fixits %s \
+// RUN:2>&1 | FileCheck %s
+// CHECK-NOT: fix-it:
+
+// This debugging facility is only available in debug builds.
+//
+// REQUIRES: asserts
+
+void foo() {
+  int *x = new int[10]; // expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  x[5] = 10;// expected-note{{used in buffer access here}}
+  int z = x[-1];// expected-note{{used in buffer access here}} \
+// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
+}
+
+void failed_decl() {
+  int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : not a pointer}}
+  
+  for (int i = 0; i < 10; i++) {
+a[i] = i;  // expected-note{{used in buffer access here}}
+  }
+}
+
+void failed_multiple_decl() {
+  int *a = new int[4], b;  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}
+  a[4] = 3;  // expected-note{{used in buffer access here}}
+}
+
+void failed_param_var_decl(int *a =new int[3]) {  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : has default arg}}
+  a[4] = 6;  // expected-note{{used in buffer access here}}
+}
+
+void unclaimed_use() {
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[2] = 9;  // expected-note{{used in buffer access here}}
+  int *b = a++;  // expected-note{{used in pointer arithmetic here}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for 'a' : has an unclaimed use}}
+}
+
+void implied_unclaimed_var(int *b) {  // expected-warning{{'b' is an unsafe pointer used for buffer access}}
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[4] = 7;  // expected-note{{used in buffer access here}}
+  a = b;  // debug-note{{safe buffers debug: gadget 'PointerAssignment' refused to produce a fix}}
+  b++;  // expected-note{{used in pointer arithmetic here}} \
+// debug-note{{safe buffers debug: failed to produce fixit for 'b' : has an unclaimed use}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2276,6 +2276,12 @@
   for (const auto &F : Fixes)
 FD << F;
 }
+
+#ifndef NDEBUG
+if (areDebugNotesRequested())
+  for (const DebugNote &Note: DebugNotesByVar[Variable])
+S.Diag(Note.first, diag::note_safe_buffer_debug_mode) << Note.second;
+#endif
   }
 
   bool isSafeBufferOptOut(const SourceLocation &Loc) const override {
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -319,6 +319,15 @@
 
   Kind getKind() const { return K; }
 
+#ifndef NDEBUG
+  StringRef getDebugName() const {
+switch (K) {
+#define GADGET(x) case Kind::x: return #x

[PATCH] D153689: [clang][Interp] Handle CXXConstructExprs

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1109
+template 
+bool ByteCodeExprGen::VisitCXXConstructExpr(
+const CXXConstructExpr *E) {

Should we be checking `isElidable()`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153689

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


[PATCH] D156370: [clang-format] Fix bug with parsing of function/variable names.

2023-07-26 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.

Function and variable names are not detected correctly when there is an
__attribute__((x)) preceding the name.

Fixes Github Issue 64137


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156370

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16455,8 +16455,10 @@
 
   verifyFormat("int f ();", SpaceFuncDecl);
   verifyFormat("void f(int a, T b) {}", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f(int a, T b) {}", SpaceFuncDecl);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDecl);
   verifyFormat("void f () __attribute__((asdf));", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f ();", SpaceFuncDecl);
   verifyFormat("#define A(x) x", SpaceFuncDecl);
   verifyFormat("#define A (x) x", SpaceFuncDecl);
   verifyFormat("#if defined(x)\n"
@@ -16490,8 +16492,10 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f (int a, T b) {}", SpaceFuncDef);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f();", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
   verifyFormat("#if defined(x)\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2208,7 +2208,8 @@
 }
 
 if (PreviousNotConst->is(tok::r_paren) &&
-PreviousNotConst->is(TT_TypeDeclarationParen)) {
+(PreviousNotConst->is(TT_TypeDeclarationParen) ||
+ PreviousNotConst->is(TT_AttributeParen))) {
   return true;
 }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16455,8 +16455,10 @@
 
   verifyFormat("int f ();", SpaceFuncDecl);
   verifyFormat("void f(int a, T b) {}", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f(int a, T b) {}", SpaceFuncDecl);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDecl);
   verifyFormat("void f () __attribute__((asdf));", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f ();", SpaceFuncDecl);
   verifyFormat("#define A(x) x", SpaceFuncDecl);
   verifyFormat("#define A (x) x", SpaceFuncDecl);
   verifyFormat("#if defined(x)\n"
@@ -16490,8 +16492,10 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f (int a, T b) {}", SpaceFuncDef);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f();", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
   verifyFormat("#if defined(x)\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2208,7 +2208,8 @@
 }
 
 if (PreviousNotConst->is(tok::r_paren) &&
-PreviousNotConst->is(TT_TypeDeclarationParen)) {
+(PreviousNotConst->is(TT_TypeDeclarationParen) ||
+ PreviousNotConst->is(TT_AttributeParen))) {
   return true;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156330: [hexagon] restore library path arguments

2023-07-26 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

In D156330#4535974 , @MaskRay wrote:

> Tip: use `%clang -fdriver-only -Werror -v` to test that a command produces no 
> warning or error and has an exit code of 0. Without it your 
> `Args.ClaimAllArgs(options::OPT_L);` change is untested.

This test fails on the baseline because of the `CHECK-NOT: warning:` IIRC.  But 
your suggestion sounds like a good one anyways, will do!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156330

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1730-1731
 
+#define DEBUG_NOTE_DECL_FAIL(D, Msg)  \
+Handler.addDebugNoteForVar((D), (D)->getBeginLoc(), "failed to produce fixit 
for declaration '" + D->getNameAsString() + "'" + Msg)
+

Ooo that's actually really nice! Maybe you can go even further and add this 
extra harness, so that to eliminate the need for `#ifndef NDEBUG` at every use.


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

https://reviews.llvm.org/D154880

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud added a comment.

In D154880#4533035 , @ziqingluo-90 
wrote:

> This is a lot of work, thank you @t-rasmud & @NoQ !
>
> I have a minor suggestion: can we use some macros to make the debug stub even 
> shorter?
> The prefix `"failed to produce fixit for declaration"`  is used in many 
> places so probably we do not have to repeat it everywhere.  And, maybe some 
> prefixes could be a bit more blurry so that they can be shared.  For example, 
> we can just replace `"failed to produce fixit for parm var decl"` with 
> `"failed to produce fixit for declaration"`.   We have source location and 
> more specific message attached to the note so we are not losing information I 
> think.
>
> I'm imagining something like this:
>
>   #define DEBUG_NOTE_DECL_FAIL(D, Msg)  \
>   Handler.addDebugNoteForVar((D), (D)->getBeginLoc(),  "failed to produce 
> fixit for declaration "##Msg)
>   
>   #define DEBUG_NOTE_GADGET_FAIL(Gadget, Msg)  ...
>
> Does it make sense to you?

I like this suggestion. I've made changes to replace 
`Handler.addDebugNoteForVar` for declarations. The Gadget case appears just 
once as of now, so I've left it as is.


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

https://reviews.llvm.org/D154880

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


[PATCH] D154880: [-Wunsafe-buffer-usage] Add a facility for debugging low fixit coverage.

2023-07-26 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud updated this revision to Diff 544510.
t-rasmud retitled this revision from "[-Wunsafe-buffer-usage][WIP] Add a 
facility for debugging low fixit coverage." to "[-Wunsafe-buffer-usage] Add a 
facility for debugging low fixit coverage.".

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

https://reviews.llvm.org/D154880

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -verify=expected %s
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -verify=expected,debug %s
+
+// A generic -debug would also enable our notes. This is probably fine.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -mllvm -debug \
+// RUN:-verify=expected,debug %s
+
+// This test file checks the behavior under the assumption that no fixits
+// were emitted for the test cases. If -Wunsafe-buffer-usage is improved
+// to support these cases (thus failing the test), the test should be changed
+// to showcase a different unsupported example.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -fdiagnostics-parseable-fixits %s \
+// RUN:2>&1 | FileCheck %s
+// CHECK-NOT: fix-it:
+
+// This debugging facility is only available in debug builds.
+//
+// REQUIRES: asserts
+
+void foo() {
+  int *x = new int[10]; // expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  x[5] = 10;// expected-note{{used in buffer access here}}
+  int z = x[-1];// expected-note{{used in buffer access here}} \
+// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
+}
+
+void failed_decl() {
+  int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : not a pointer}}
+  
+  for (int i = 0; i < 10; i++) {
+a[i] = i;  // expected-note{{used in buffer access here}}
+  }
+}
+
+void failed_multiple_decl() {
+  int *a = new int[4], b;  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}
+  a[4] = 3;  // expected-note{{used in buffer access here}}
+}
+
+void failed_param_var_decl(int *a =new int[3]) {  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : has default arg}}
+  a[4] = 6;  // expected-note{{used in buffer access here}}
+}
+
+void unclaimed_use() {
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[2] = 9;  // expected-note{{used in buffer access here}}
+  int *b = a++;  // expected-note{{used in pointer arithmetic here}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for 'a' : has an unclaimed use}}
+}
+
+void implied_unclaimed_var(int *b) {  // expected-warning{{'b' is an unsafe pointer used for buffer access}}
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[4] = 7;  // expected-note{{used in buffer access here}}
+  a = b;  // debug-note{{safe buffers debug: gadget 'PointerAssignment' refused to produce a fix}}
+  b++;  // expected-note{{used in pointer arithmetic here}} \
+// debug-note{{safe buffers debug: failed to produce fixit for 'b' : has an unclaimed use}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2276,6 +2276,12 @@
   for (const auto &F : Fixes)
 FD << F;
 }
+
+#ifndef NDEBUG
+if (areDebugNotesRequested())
+  for (const DebugNote &Note: DebugNotesByVar[Variable])
+S.Diag(Note.first, diag::note_safe_buffer_debug_mode) << Note.second;
+#endif
   }
 
   bool isSafeBufferOptOut(const SourceLocation &Loc) const override {
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis

[PATCH] D156368: [OpenMP] Do not always emit unused extern variables

2023-07-26 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, jdoerfert, tianshilei1992, ye-luo, 
RaviNarayanaswamy, ABataev.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

Currently, the precense of the OpenMP target declare metadata requires
that we always codegen a global declaration. This is undesirable in the
case that we could defer or omit this declaration as is common with
unused extern variables. This is important as it allows us, in the
runtime, to rely on static linking semantics to omit unused symbols so
they are not included when the user links it in.

This patch changes the check for always emitting these variables.
Because of this we also need to extend this logic to the generation of
the offloading entries. This has the result of derring the offload entry
generation to the canonical definitoin. So we are effectively assuming
whoever owns the storage for this variable will perform that operation.
This makes an exception for `link` attributes as those require their own
special handling.

Let me know if this is sound in the implementation, I do not have the
largest view of the standards here.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156368

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/OpenMP/declare_target_codegen.cpp


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -29,7 +29,6 @@
 // CHECK-DAG: @flag = protected global i8 undef,
 // CHECK-DAG: @dx = {{protected | }}global i32 0,
 // CHECK-DAG: @dy = {{protected | }}global i32 0,
-// CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb = {{protected | }}global i32 0,
 // CHECK-DAG: weak constant %struct.__tgt_offload_entry { ptr @bbb,
 // CHECK-DAG: @ccc = external global i32,
@@ -80,7 +79,7 @@
 extern int aaa;
 int bbb = 0;
 extern int ccc;
-int ddd = 0;
+int ddd = ccc;
 #pragma omp end declare target
 
 #pragma omp declare target
@@ -260,8 +259,6 @@
 
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}
 
-// CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
-// CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}}
 // CHECK-DAG: !{{{.+}}virtual_foo
 
 #ifdef OMP5
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3605,6 +3605,13 @@
 // Emit declaration of the must-be-emitted declare target variable.
 if (std::optional Res =
 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) {
+
+  // If this variable has external storage and doesn't require special
+  // link handling we defer to its canonical definition.
+  if (VD->hasExternalStorage() &&
+  Res != OMPDeclareTargetDeclAttr::MT_Link)
+return;
+
   bool UnifiedMemoryEnabled =
   getOpenMPRuntime().hasRequiresUnifiedSharedMemory();
   if ((*Res == OMPDeclareTargetDeclAttr::MT_To ||
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10166,6 +10166,13 @@
 
   std::optional Res =
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
+
+  // If this is an 'extern' declaration we defer to the canonical definition 
and
+  // do not emit an offloading entry.
+  if (Res && *Res != OMPDeclareTargetDeclAttr::MT_Link &&
+  VD->hasExternalStorage())
+return;
+
   if (!Res) {
 if (CGM.getLangOpts().OpenMPIsTargetDevice) {
   // Register non-target variables being emitted in device code (debug info


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -29,7 +29,6 @@
 // CHECK-DAG: @flag = protected global i8 undef,
 // CHECK-DAG: @dx = {{protected | }}global i32 0,
 // CHECK-DAG: @dy = {{protected | }}global i32 0,
-// CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb = {{protected | }}global i32 0,
 // CHECK-DAG: weak constant %struct.__tgt_offload_entry { ptr @bbb,
 // CHECK-DAG: @ccc = external global i32,
@@ -80,7 +79,7 @@
 extern int aaa;
 int bbb = 0;
 extern int ccc;
-int ddd = 0;
+int ddd = ccc;
 #pragma omp end declare target
 
 #pragma omp declare target
@@ -260,8 +259,6 @@
 
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}
 
-// CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
-// 

[PATCH] D156366: HIP: Use __builtin_sqrt instead of routing through ocml sqrt for f64

2023-07-26 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

Thanks


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

https://reviews.llvm.org/D156366

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


[PATCH] D153653: [clang][Interp] Make CXXTemporaryObjectExprs leave a value behind

2023-07-26 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D153653

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


[clang] 08247d7 - [Driver][test] Fix continuation lines from debug-options.c

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

Author: Fangrui Song
Date: 2023-07-26T13:47:39-07:00
New Revision: 08247d70711ad9472647ef4f948f1f67139e

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

LOG: [Driver][test] Fix continuation lines from debug-options.c

Without RUN: in the continuation lines, they just test a quirk of -###
that clang returns with 0.

Added: 


Modified: 
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 8617949cea1c87..2e0cca053eaf75 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -217,32 +217,21 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLIO_NO %s
-//
-// RUN: %clang -### -c -grecord-gcc-switches %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD %s
-// RUN: %clang -### -c -gno-record-gcc-switches %s 2>&1 \
-// | FileCheck -check-prefix=GNO_RECORD %s
-// RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches %s 2>&1 \
-// | FileCheck -check-prefix=GNO_RECORD %s/
-// RUN: %clang -### -c -grecord-gcc-switches -o - %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD_O %s
-// RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD_OPT %s
-//
-// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD %s
-// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
-// | FileCheck -check-prefix=GNO_RECORD %s
-// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
-// | FileCheck -check-prefix=GNO_RECORD %s/
-// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD_O %s
-// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
-// | FileCheck -check-prefix=GRECORD_OPT %s
-//
-// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
-// RUN:| FileCheck -check-prefix=GIGNORE %s
-//
+
+// RUN: %clang -### -c -grecord-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches %s 2>&1 
| FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-gcc-switches -o - %s 2>&1 | FileCheck 
-check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 | 
FileCheck -check-prefix=GRECORD_OPT %s
+
+// RUN: %clang -### -c -grecord-command-line %s 2>&1 | FileCheck 
-check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-command-line %s 2>&1 | FileCheck 
-check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 
| FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 | FileCheck 
-check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 | 
FileCheck -check-prefix=GRECORD_OPT %s
+
+// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 | FileCheck 
-check-prefix=GIGNORE %s
+
 // RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GPUB %s
 // RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
@@ -370,15 +359,15 @@
 // GLIO_NO-NOT: -debug-info-kind=
 //
 // GRECORD: "-dwarf-debug-flags"
-// GRECORD: -### -c -grecord-gcc-switches
+// GRECORD: -### -c -grecord-command-line
 //
 // GNO_RECORD-NOT: "-dwarf-debug-flags"
-// GNO_RECORD-NOT: -### -c -grecord-gcc-switches
+// GNO_RECORD-NOT: -### -c -grecord-command-line
 //
 // GRECORD_O: "-dwarf-debug-flags"
-// GRECORD_O: -### -c -grecord-gcc-switches -o -
+// GRECORD_O: -### -c -grecord-command-line -o -
 //
-// GRECORD_OPT: -### -c -O3 -ffunction-sections -grecord-gcc-switches
+// GRECORD_OPT: -### -c -O3 -ffunction-sections -grecord-command-line
 //
 // GIGNORE-NOT: "argument unused during compilation"
 //



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


[PATCH] D153058: [clang][CFG] Support construction of a weak topological ordering of the CFG.

2023-07-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Thanks, this is much simpler!
Just nits & apologies for the delay.




Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:24
 #include "llvm/ADT/DenseSet.h"
+#include 
+#include 

some of these added headers are now unused: map, set, variant



Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:32
 namespace clang {
-
+namespace internal {
 // An interval is a strongly-connected component of the CFG along with a

nit: `namespace internal` should probably be moved below the public API



Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:104
+/// intervals) if and only if it is reducible (its limit flow graph has one
+/// node). Returns `nullop` when `Cfg` is not reducible.
+///

nit: nullopt



Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:104
+/// intervals) if and only if it is reducible (its limit flow graph has one
+/// node). Returns `nullop` when `Cfg` is not reducible.
+///

sammccall wrote:
> nit: nullopt
what do we expect to do in practice when the CFG is not reducible? or do we 
expect that to never happen?

(mostly wondering if we need a fallback)



Comment at: clang/lib/Analysis/IntervalPartition.cpp:36
+
+// Requires: `Node::succs()` and `Node::preds()`.
+template 

Might be more useful to say concretely: Nodes are either CFGBlock or 
CFGIntervalNode



Comment at: clang/lib/Analysis/IntervalPartition.cpp:105
+void fillIntervalNode(CFGIntervalGraph &Graph,
+  std::map &Index,
+  std::queue &Successors,

std::map of pointers is a bit suspicious, densemap?



Comment at: clang/unittests/Analysis/IntervalPartitionTest.cpp:91
+
+MATCHER_P(BlockID, ID, "") { return arg->getBlockID == ID; }
+MATCHER_P(IntervalID, ID, "") { return arg->ID == ID; }

nit: matcher factories are functions and so should be lowerCamelCase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153058

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


[PATCH] D156212: [clang][Interp] Implement remaining strcmp builtins

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



Comment at: clang/test/AST/Interp/builtin-functions.cpp:17
+  static_assert(__builtin_strncmp("abaa", "abba", 1) == 0);
+  static_assert(__builtin_strncmp("abaa", "abba", 0) == 0);
+  static_assert(__builtin_strncmp(0, 0, 0) == 0);

How about `-1` size as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156212

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


[PATCH] D116910: [OpenMP][3/3] Introduce the KernelEnvironment into Clang tests

2023-07-26 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert closed this revision.
jdoerfert added a comment.
Herald added subscribers: jplehr, sunshaoce, mattd.
Herald added a project: All.

Subsumed by  D142569 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116910

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


[PATCH] D155213: [HIP] Add `-fno-offload-uniform-block`

2023-07-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 544491.
yaxunl edited the summary of this revision.
yaxunl added a comment.

make the option generic for offloading languages


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

https://reviews.llvm.org/D155213

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
  clang/test/Driver/hip-options.hip

Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -205,3 +205,27 @@
 
 // RUN: %clang -fdriver-only -Werror --target=x86_64-unknown-linux-gnu -nostdinc -nostdlib -fgpu-approx-transcendentals \
 // RUN:   -x c++ %s 2>&1 | count 0
+/ Check -fno-offload-uniform-block is passed to clang -cc1 but
+// (default) -fno-offload-uniform-block is not.
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -fno-offload-uniform-block \
+// RUN:   --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=NOUNIBLK %s
+
+// NOUNIBLK: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fno-offload-uniform-block"
+// NOUNIBLK: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-fno-offload-uniform-block"
+
+// RUN: %clang -### -nogpuinc -nogpulib -foffload-uniform-block \
+// RUN:   --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=UNIBLK %s
+
+// UNIBLK: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-foffload-uniform-block"
+// UNIBLK: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-foffload-uniform-block"
+
+// RUN: %clang -### -nogpuinc -nogpulib \
+// RUN:   --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=DEFUNIBLK %s
+
+// DEFUNIBLK-NOT: "-f{{(no-)?}}offload-uniform-block"
+
+// Check no warnings for -f[no-]offload-uniform-block.
+
+// RUN: %clang -fdriver-only -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -fno-offload-uniform-block \
+// RUN:   -foffload-uniform-block --cuda-gpu-arch=gfx906 %s 2>&1 | count 0
Index: clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
===
--- clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
+++ clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
@@ -10,10 +10,18 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm \
 // RUN: -verify -o - -x hip %s | FileCheck -check-prefix=NAMD %s
 
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -foffload-uniform-block \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=CHECK,DEFAULT %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fno-offload-uniform-block \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=NOUB %s
+
 #include "Inputs/cuda.h"
 
 __global__ void flat_work_group_size_default() {
 // CHECK: define{{.*}} amdgpu_kernel void @_Z28flat_work_group_size_defaultv() [[FLAT_WORK_GROUP_SIZE_DEFAULT:#[0-9]+]]
+// NOUB: define{{.*}} void @_Z28flat_work_group_size_defaultv() [[NOUB:#[0-9]+]]
 }
 
 __attribute__((amdgpu_flat_work_group_size(32, 64))) // expected-no-diagnostics
@@ -45,3 +53,5 @@
 // CHECK-DAG: attributes [[WAVES_PER_EU_2]] = {{.*}}"amdgpu-waves-per-eu"="2"
 // CHECK-DAG: attributes [[NUM_SGPR_32]] = {{.*}}"amdgpu-num-sgpr"="32"
 // CHECK-DAG: attributes [[NUM_VGPR_64]] = {{.*}}"amdgpu-num-vgpr"="64"
+
+// NOUB-NOT: "uniform-work-group-size"="true"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7264,6 +7264,9 @@
 Args.AddLastArg(CmdArgs, options::OPT_fgpu_default_stream_EQ);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_foffload_uniform_block,
+  options::OPT_fno_offload_uniform_block);
+
   if (IsCudaDevice || IsHIPDevice) {
 StringRef InlineThresh =
 Args.getLastArgValue(options::OPT_fgpu_inline_threshold_EQ);
Index: clang/lib/CodeGen/Targets/AMDGPU.cpp
===
--- clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -401,13 +401,6 @@
   if (FD)
 setFunctionDeclAttributes(FD, F, M);
 
-  const bool IsHIPKernel =
-  M.getLangOpts().HIP && FD && FD->hasAttr();
-
-  // TODO: This should be moved to language specific attributes instead.
-  if (IsHIPKernel)
-F->addFnAttr("uniform-work-group-size", "true");
-
   if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics())
 F->addFnAttr("amdgpu-unsafe-fp-atomics", "true");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2402,6 +2402,10 @@
  

[PATCH] D156360: [clang-format] Support function and overloaded operator SpacesInParensOption

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

You need some tests to show that the new options really apply like intended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156360

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


[PATCH] D156360: [clang-format] Support function and overloaded operator SpacesInParensOption

2023-07-26 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.

This change separates function calls, declarations, definitions, and
overloaded operators from `SpacesInParensOptions.Other` to allow control
over each independently.

Fixes Github Issue \#55428.

Depends on D155529 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156360

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11040,7 +11040,8 @@
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
   Spaces.SpacesInParensOptions.InCStyleCasts = false;
-  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InFunctionDeclarations = true;
+  Spaces.SpacesInParensOptions.InOverloadedOperators = true;
   verifyFormat("Deleted &operator=( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
Spaces);
@@ -13678,6 +13679,7 @@
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
   SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
   SpaceBetweenBraces.SpacesInParensOptions.Other = true;
+  SpaceBetweenBraces.SpacesInParensOptions.InFunctionCalls = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -16749,6 +16751,7 @@
   Spaces.SpacesInParensOptions.Other = true;
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
   Spaces.SpacesInParensOptions.InAttributeSpecifiers = true;
+  Spaces.SpacesInParensOptions.InFunctionCalls = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -23819,6 +23822,7 @@
   Style.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("x = ( _Atomic(uint64_t) )*a;", Style);
   Style.SpacesInParensOptions.InCStyleCasts = false;
+  Style.SpacesInParensOptions.InFunctionCalls = true;
   Style.SpacesInParensOptions.Other = true;
   verifyFormat("x = (_Atomic( uint64_t ))*a;", Style);
   verifyFormat("x = (_Atomic( uint64_t ))&a;", Style);
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -226,6 +226,10 @@
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InFunctionCalls);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InFunctionDeclarations);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InFunctionDefinitions);
+  CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InOverloadedOperators);
   CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, Other);
 }
 
@@ -600,23 +604,23 @@
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions,
-  FormatStyle::SpacesInParensCustom(true, true, false, false,
-  true));
+  FormatStyle::SpacesInParensCustom(true, true, false, false, true,
+true, true, true, true));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions,
   FormatStyle::SpacesInParensCustom(false, true, false, false,
-  false));
+false, false, false, false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions,
   FormatStyle::SpacesInParensCustom(false, false, true, false,
-  false));
+false, false, false, false, false));
   Style.SpacesInParens = FormatStyle::SIPO_Never;
   Style.SpacesInParensOptions = {};
   CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions,
   FormatStyle::SpacesInParensCustom(false, false, false, true,
-  false));
+false, false, false, false, false));
   Style.SpacesInParens = F

[clang] 380dbfd - Revert "Reapply [IR] Mark and/or constant expressions as undesirable"

2023-07-26 Thread Matthew Voss via cfe-commits

Author: Matthew Voss
Date: 2023-07-26T12:54:07-07:00
New Revision: 380dbfd8cab0c48c46c01b519b908c6ef4d6e775

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

LOG: Revert "Reapply [IR] Mark and/or constant expressions as undesirable"

This reverts commit 0cab8d20417c0e2ccc1ffc5505e080126f5de8e6.

Reverted due to an LTO crash. I've put a reduced test case here:
https://github.com/llvm/llvm-project/issues/64114

Added: 


Modified: 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/Constants.cpp
llvm/test/CodeGen/Hexagon/atomic-opaque-basic.ll
llvm/test/Transforms/InstCombine/and-xor-or.ll
llvm/test/Transforms/InstCombine/and.ll
llvm/test/Transforms/InstCombine/bswap-fold.ll
llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
llvm/test/Transforms/InstSimplify/compare.ll

Removed: 




diff  --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c 
b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
index 0e0a9b157464a6..551ccc4810bcd3 100644
--- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
+++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
@@ -303,8 +303,7 @@ char *one_zero(void) {
 char *one_one_OK(void) {
   // CHECK:   define{{.*}} ptr @one_one_OK()
   // CHECK-NEXT:  [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: %[[AND:.*]] = and i1 icmp ne (ptr 
inttoptr (i64 1 to ptr), ptr null), icmp ne (i64 add (i64 sub (i64 ptrtoint 
(ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), 
i64 1), i64 1), i64 0), !nosanitize
-  // CHECK-SANITIZE-C-NEXT: br i1 %[[AND]], label %[[CONT:.*]], 
label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 and (i1 icmp ne (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   br i1 xor (i1 icmp eq (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(ptr @[[LINE_1100]], i64 1, i64 add (i64 
sub (i64 ptrtoint (ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), 
i64 1) to i64), i64 1), i64 1))
@@ -322,8 +321,7 @@ char *one_one_OK(void) {
 char *one_allones_BAD(void) {
   // CHECK:   define{{.*}} ptr @one_allones_BAD()
   // CHECK-NEXT:  [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: %[[AND:.*]] = and i1 icmp ne (ptr 
inttoptr (i64 1 to ptr), ptr null), icmp ne (i64 add (i64 sub (i64 ptrtoint 
(ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), 
i64 1), i64 1), i64 0), !nosanitize
-  // CHECK-SANITIZE-C-NEXT: br i1 %[[AND]], label %[[CONT:.*]], 
label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 and (i1 icmp ne (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   br i1 xor (i1 icmp eq (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(ptr @[[LINE_1200]], i64 1, i64 add (i64 
sub (i64 ptrtoint (ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), 
i64 -1) to i64), i64 1), i64 1))
@@ -392,8 +390,7 @@ char *allones_zero_OK(void) {
 char *allones_one_BAD(void) {
   // CHECK: define{{.*}} ptr @allones_one_BAD()
   // CHECK-NEXT: [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: %[[AND:.*]] = and i1 icmp ne (ptr 
inttoptr (i64 -1 to ptr), ptr null), icmp ne (i64 add (i64 sub (i64 ptrtoint 
(ptr getelementptr inbounds (i8, ptr inttoptr (i64 -1 to ptr), i64 1) to i64), 
i64 -1), i64 -1), i6

[PATCH] D156175: [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr

2023-07-26 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2c26397f76d9: [clang][ConstExprEmitter] handle NullToPointer 
ImplicitCastExpr (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156175

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1131,6 +1131,10 @@
   if (const auto *S = dyn_cast(subExpr))
 return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
   return nullptr;
+case CK_NullToPointer:
+  if (llvm::Constant *C = Visit(subExpr, destType))
+return CGM.EmitNullConstant(destType);
+  return nullptr;
 
 case CK_IntToOCLSampler:
   llvm_unreachable("global sampler variables are not generated");
@@ -1187,7 +1191,6 @@
 case CK_IntegralComplexToFloatingComplex:
 case CK_PointerToIntegral:
 case CK_PointerToBoolean:
-case CK_NullToPointer:
 case CK_IntegralCast:
 case CK_BooleanToSignedIntegral:
 case CK_IntegralToPointer:


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1131,6 +1131,10 @@
   if (const auto *S = dyn_cast(subExpr))
 return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
   return nullptr;
+case CK_NullToPointer:
+  if (llvm::Constant *C = Visit(subExpr, destType))
+return CGM.EmitNullConstant(destType);
+  return nullptr;
 
 case CK_IntToOCLSampler:
   llvm_unreachable("global sampler variables are not generated");
@@ -1187,7 +1191,6 @@
 case CK_IntegralComplexToFloatingComplex:
 case CK_PointerToIntegral:
 case CK_PointerToBoolean:
-case CK_NullToPointer:
 case CK_IntegralCast:
 case CK_BooleanToSignedIntegral:
 case CK_IntegralToPointer:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2c26397 - [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr

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

Author: Nick Desaulniers
Date: 2023-07-26T12:53:02-07:00
New Revision: 2c26397f76d9b8d2a0dc8207eeca5b0d3216f3f0

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

LOG: [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr

Consider the following statement:
void* foo = ((void *)0);

For the sub-AST:
| `-ImplicitCastExpr 'const void *' 
|   `-CStyleCastExpr 'void *' 
| `-IntegerLiteral 'int' 0

If the subexpression of the cast is itself the NULL constant, then
ImplicitCastExpr should emit the NULL pointer constant.

Reviewed By: efriedma

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 88dde7c9178829..9ad07f7d2220a7 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1131,6 +1131,10 @@ class ConstExprEmitter :
   if (const auto *S = dyn_cast(subExpr))
 return CGM.GetAddrOfConstantStringFromLiteral(S).getPointer();
   return nullptr;
+case CK_NullToPointer:
+  if (llvm::Constant *C = Visit(subExpr, destType))
+return CGM.EmitNullConstant(destType);
+  return nullptr;
 
 case CK_IntToOCLSampler:
   llvm_unreachable("global sampler variables are not generated");
@@ -1187,7 +1191,6 @@ class ConstExprEmitter :
 case CK_IntegralComplexToFloatingComplex:
 case CK_PointerToIntegral:
 case CK_PointerToBoolean:
-case CK_NullToPointer:
 case CK_IntegralCast:
 case CK_BooleanToSignedIntegral:
 case CK_IntegralToPointer:



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


[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-07-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


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

https://reviews.llvm.org/D155870

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


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

2023-07-26 Thread Łukasz Anforowicz via Phabricator via cfe-commits
lukasza updated this revision to Diff 544478.
lukasza added a comment.

Rebasing...


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

https://reviews.llvm.org/D155895

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/attr-trivial-abi.cpp

Index: clang/test/SemaCXX/attr-trivial-abi.cpp
===
--- clang/test/SemaCXX/attr-trivial-abi.cpp
+++ clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -fclang-abi-compat=17 -verify %s -std=c++11 -DCLANG_ABI_COMPAT=17
 
 void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
 
@@ -169,3 +170,104 @@
 static_assert(__is_trivially_relocatable(S20), "");
 #endif
 } // namespace deletedCopyMoveConstructor
+
+namespace anonymousUnionsAndStructs {
+  // Test helper:
+  struct [[clang::trivial_abi]] Trivial {
+Trivial() {}
+Trivial(Trivial&& other) {}
+Trivial& operator=(Trivial&& other) { return *this; }
+~Trivial() {}
+  };
+  static_assert(__is_trivially_relocatable(Trivial), "");
+
+  // Test helper:
+  struct Nontrivial {
+Nontrivial() {}
+Nontrivial(Nontrivial&& other) {}
+Nontrivial& operator=(Nontrivial&& other) { return *this; }
+~Nontrivial() {}
+  };
+  static_assert(!__is_trivially_relocatable(Nontrivial), "");
+
+  // Basic smoke test, not yet related to anonymous unions or structs:
+  struct [[clang::trivial_abi]] BasicStruct {
+BasicStruct(BasicStruct&& other) {}
+BasicStruct& operator=(BasicStruct&& other) { return *this; }
+~BasicStruct() {}
+Trivial field;
+  };
+  static_assert(__is_trivially_relocatable(BasicStruct), "");
+
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 17
+  struct [[clang::trivial_abi]] StructWithAnonymousUnion { // expected-warning {{'trivial_abi' cannot be applied to 'StructWithAnonymousUnion'}} expected-note {{trivial_abi' is disallowed on 'StructWithAnonymousUnion' because it has a field of a non-trivial class type}}
+StructWithAnonymousUnion(StructWithAnonymousUnion&& other) {}
+StructWithAnonymousUnion& operator=(StructWithAnonymousUnion&& other) { return *this; }
+~StructWithAnonymousUnion() {}
+union { Trivial field; };
+  };
+  static_assert(!__is_trivially_relocatable(StructWithAnonymousUnion), "");
+#else
+  // `StructWithAnonymousUnion` is like `BasicStruct`, but `field` is wrapped in
+  // an anonymous union, and thus trivial relocatability of `BasicStruct` and
+  // `StructWithAnonymousUnion` should be the same).
+  //
+  // It's impossible to declare a constructor for an anonymous unions so to
+  // support applying `[[clang::trivial_abi]]` to structs containing anonymous
+  // unions, and therefore when processing fields of the struct containing the
+  // anonymous union, the trivial relocatability of the *union* is ignored and
+  // instead the union's fields are recursively inspected in
+  // `checkIllFormedTrivialABIStruct`.
+  struct [[clang::trivial_abi]] StructWithAnonymousUnion {
+StructWithAnonymousUnion(StructWithAnonymousUnion&& other) {}
+StructWithAnonymousUnion& operator=(StructWithAnonymousUnion&& other) { return *this; }
+~StructWithAnonymousUnion() {}
+union { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(StructWithAnonymousUnion), "");
+
+  // `StructWithAnonymousStruct` is like `StructWithAnonymousUnion` but uses an
+  // anonymous `struct` rather than an anonymous `union.
+  struct [[clang::trivial_abi]] StructWithAnonymousStruct {
+StructWithAnonymousStruct(StructWithAnonymousStruct&& other) {}
+StructWithAnonymousStruct& operator=(StructWithAnonymousStruct&& other) { return *this; }
+~StructWithAnonymousStruct() {}
+struct { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(StructWithAnonymousStruct), "");
+
+  // `TrivialAbiAttributeAppliedToAnonymousUnion` is like
+  // `StructWithAnonymousUnion` but with `[[clang::trivial_abi]]` also applied
+  // to the anonymous union.
+  //
+  // The example below shows that it is still *not* okay to explicitly apply
+  // `[[clang::trivial_abi]]` to anonymous unions. Handling this would require
+  // relaxing the `HasNonDeletedCopyOrMoveConstructor` check when
+  // `isAnonymousStructOrUnion` in `checkIllFormedTrivialABIStruct` but when
+  // that check runs `setAnonymousStructOrUnion` hasn't been called yet (i.e. at
+  // this point it's not possible to rely on `RD->isAnonymousStructOrUnion()`).
+  struct [[clang::trivial_abi]] TrivialAbiAttributeAppliedToAnonymousUnion {
+TrivialAbiAttributeAppliedToAnonymousUnion(TrivialAbiAttributeAppliedToAnonymousUnion&& other) {}
+TrivialAbiAttributeAppliedToAnonymousUnion& operator=(TrivialAbiAttributeAppliedToAnonymousUnion&& other) { return *this; 

[PATCH] D156322: Outputs parameter comments using clang-doc and markdown generator

2023-07-26 Thread Arnaud Botella via Phabricator via cfe-commits
BotellaA updated this revision to Diff 544477.
BotellaA added a comment.

Updated the expected result in the MD generator test.


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

https://reviews.llvm.org/D156322

Files:
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -347,9 +347,9 @@
 
  The description continues.
 
-**I** [out]
+**I** [out] is a parameter.
 
-**J**
+**J** is a parameter.
 
 **return**void
 
Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -82,10 +82,14 @@
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);


Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -347,9 +347,9 @@
 
  The description continues.
 
-**I** [out]
+**I** [out] is a parameter.
 
-**J**
+**J** is a parameter.
 
 **return**void
 
Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -82,10 +82,14 @@
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-07-26 Thread Łukasz Anforowicz via Phabricator via cfe-commits
lukasza updated this revision to Diff 544476.
lukasza added a comment.

Added support for `-fclang-abi-compat=17`


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

https://reviews.llvm.org/D155895

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/attr-trivial-abi.cpp

Index: clang/test/SemaCXX/attr-trivial-abi.cpp
===
--- clang/test/SemaCXX/attr-trivial-abi.cpp
+++ clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -fclang-abi-compat=17 -verify %s -std=c++11 -DCLANG_ABI_COMPAT=17
 
 void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
 
@@ -169,3 +170,104 @@
 static_assert(__is_trivially_relocatable(S20), "");
 #endif
 } // namespace deletedCopyMoveConstructor
+
+namespace anonymousUnionsAndStructs {
+  // Test helper:
+  struct [[clang::trivial_abi]] Trivial {
+Trivial() {}
+Trivial(Trivial&& other) {}
+Trivial& operator=(Trivial&& other) { return *this; }
+~Trivial() {}
+  };
+  static_assert(__is_trivially_relocatable(Trivial), "");
+
+  // Test helper:
+  struct Nontrivial {
+Nontrivial() {}
+Nontrivial(Nontrivial&& other) {}
+Nontrivial& operator=(Nontrivial&& other) { return *this; }
+~Nontrivial() {}
+  };
+  static_assert(!__is_trivially_relocatable(Nontrivial), "");
+
+  // Basic smoke test, not yet related to anonymous unions or structs:
+  struct [[clang::trivial_abi]] BasicStruct {
+BasicStruct(BasicStruct&& other) {}
+BasicStruct& operator=(BasicStruct&& other) { return *this; }
+~BasicStruct() {}
+Trivial field;
+  };
+  static_assert(__is_trivially_relocatable(BasicStruct), "");
+
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 17
+  struct [[clang::trivial_abi]] StructWithAnonymousUnion { // expected-warning {{'trivial_abi' cannot be applied to 'StructWithAnonymousUnion'}} expected-note {{trivial_abi' is disallowed on 'StructWithAnonymousUnion' because it has a field of a non-trivial class type}}
+StructWithAnonymousUnion(StructWithAnonymousUnion&& other) {}
+StructWithAnonymousUnion& operator=(StructWithAnonymousUnion&& other) { return *this; }
+~StructWithAnonymousUnion() {}
+union { Trivial field; };
+  };
+  static_assert(!__is_trivially_relocatable(StructWithAnonymousUnion), "");
+#else
+  // `StructWithAnonymousUnion` is like `BasicStruct`, but `field` is wrapped in
+  // an anonymous union, and thus trivial relocatability of `BasicStruct` and
+  // `StructWithAnonymousUnion` should be the same).
+  //
+  // It's impossible to declare a constructor for an anonymous unions so to
+  // support applying `[[clang::trivial_abi]]` to structs containing anonymous
+  // unions, and therefore when processing fields of the struct containing the
+  // anonymous union, the trivial relocatability of the *union* is ignored and
+  // instead the union's fields are recursively inspected in
+  // `checkIllFormedTrivialABIStruct`.
+  struct [[clang::trivial_abi]] StructWithAnonymousUnion {
+StructWithAnonymousUnion(StructWithAnonymousUnion&& other) {}
+StructWithAnonymousUnion& operator=(StructWithAnonymousUnion&& other) { return *this; }
+~StructWithAnonymousUnion() {}
+union { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(StructWithAnonymousUnion), "");
+
+  // `StructWithAnonymousStruct` is like `StructWithAnonymousUnion` but uses an
+  // anonymous `struct` rather than an anonymous `union.
+  struct [[clang::trivial_abi]] StructWithAnonymousStruct {
+StructWithAnonymousStruct(StructWithAnonymousStruct&& other) {}
+StructWithAnonymousStruct& operator=(StructWithAnonymousStruct&& other) { return *this; }
+~StructWithAnonymousStruct() {}
+struct { Trivial field; };
+  };
+  static_assert(__is_trivially_relocatable(StructWithAnonymousStruct), "");
+
+  // `TrivialAbiAttributeAppliedToAnonymousUnion` is like
+  // `StructWithAnonymousUnion` but with `[[clang::trivial_abi]]` also applied
+  // to the anonymous union.
+  //
+  // The example below shows that it is still *not* okay to explicitly apply
+  // `[[clang::trivial_abi]]` to anonymous unions. Handling this would require
+  // relaxing the `HasNonDeletedCopyOrMoveConstructor` check when
+  // `isAnonymousStructOrUnion` in `checkIllFormedTrivialABIStruct` but when
+  // that check runs `setAnonymousStructOrUnion` hasn't been called yet (i.e. at
+  // this point it's not possible to rely on `RD->isAnonymousStructOrUnion()`).
+  struct [[clang::trivial_abi]] TrivialAbiAttributeAppliedToAnonymousUnion {
+TrivialAbiAttributeAppliedToAnonymousUnion(TrivialAbiAttributeAppliedToAnonymousUnion&& other) {}
+TrivialAbiAttributeAppliedToAnonymousUnion& operator=(TrivialAbiAttributeAppliedToAnonymousU

[PATCH] D156277: [Parser][ObjC] Stop parsing on eof

2023-07-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

aaron.ballman wrote:
> rjmccall wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > danix800 wrote:
> > > > > tbaeder wrote:
> > > > > > Why is there a `ConsumeToken()` call at all here? The token is 
> > > > > > already being consumed in line 729.
> > > > > Didn't notice this, thanks for reminding!
> > > > I have the same question as @tbaeder -- what token is this intending to 
> > > > consume? CC @rjmccall for Obj-C expertise
> > > OH! This is consuming the identifier for the implementation/interface 
> > > name itself. e.g.,
> > > ```
> > > @interface Frobble
> > > ```
> > > The consume on line 709 gets the `@`, the consume on line 729 gets the 
> > > `interface`, and the consume on line 749 is getting the `Frobble`. That 
> > > makes sense to me now.
> > > 
> > I don't think any language expertise is required here — just seems like a 
> > straightforward bug on an error path that's probably not exercised all that 
> > often.  Maybe somebody moved the `ConsumeToken` and forgot to fix this case 
> > or something.
> What concerns me about this fix is that we don't typically check whether the 
> token is EOF or not before consuming; that's usually an anti-pattern, isn't 
> it? Wouldn't it make sense for this to use `SkipUntil(tok::identifier)` 
> instead?
Okay, so now I can bring a little language expertise to bear. :)

We're in the middle of parsing an ObjC block (e.g. `@interface`), and we see 
`@interface` or `@implementation`, which starts a new block.  You can never 
nest these ObjC blocks, so the parser is reasonably assuming that the second 
`@keyword` is an attempt to start a new block and the user just forgot to 
terminate the last block with `@end`.  Unfortunately, the actual recovery done 
by the parser doesn't seem to match the diagnostic and the fixit — it's trying 
to swallow `@interface Foo` (or whatever) and then continue the loop as if it 
were part of the current block, which is definitely not the right thing to do.

The right way to recover here is to act like we actually saw `@end` and break 
out of the loop, leaving `Tok` on the `@` so that the parser will pick up 
parsing `@interface` normally after we return.  To do that, we just need to get 
the ObjC keyword by peeking at the next token instead of consuming.

Also, we should take this recovery path on every `@` keyword that's only 
allowed at the top level (so `@class`, `@compatibility_alias`, `@interface`, 
`@implementation`, and `@protocol`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


[PATCH] D138263: [clang-format] Supress aligning of trailing namespace comments

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

In D138263#4535269 , @MyDeveloperDay 
wrote:

> In D138263#3936536 , 
> @HazardyKnusperkeks wrote:
>
>> In D138263#3936007 , @owenpan 
>> wrote:
>>
>>> I suppose it's fairly easy to annotate the `l_brace` of a namespace? If so, 
>>> then wouldn't it be better to do that?
>>
>> But the `r_brace` has no `MatchingParen`, and I didn't want to go into that 
>> hole.
>
> How many times has that caught you out though?I could have used this SO 
> many times to constraint stuff... I wonder how painful a BraceMatchingPass 
> would be, labelling all BraceTypes to Match each others.

Yeah... see D139257  and D139760 
.




Comment at: clang/unittests/Format/FormatTestComments.cpp:3182
+   "} // namespace A\n"
+   "  // Comment", Input, Style);
+

owenpan wrote:
> And put the test case in a `#if 0` block? I don't think it should be aligned 
> with the `namespace` comment.
I thought about it and came to the conclusion, that we (in this change) only 
want to suppress the alignment of namespace comments, not aligning other 
comments to the namespace comment.
But all is fine for me.


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

https://reviews.llvm.org/D138263

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


[PATCH] D156259: Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-07-26 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:263
   State.StartOfStringLiteral = 0;
+  State.NoLineBreak = false;
   State.StartOfLineLevel = 0;

jp4a50 wrote:
> HazardyKnusperkeks wrote:
> > Was this uninitialized?
> It's a new member variable I added as part of this diff.
Sorry, I looked for that, but somehow missed it.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:664-666
+if ((Style.Language == FormatStyle::LK_Cpp ||
+ Style.Language == FormatStyle::LK_ObjC) &&
+!Current.is(tok::comment) && PrevNonComment &&

jp4a50 wrote:
> HazardyKnusperkeks wrote:
> > Could move this out of the lambda.
> Not sure exactly what you're referring to here. Initialization of 
> `PrevNonComment`?
> Not sure exactly what you're referring to here. Initialization of 
> `PrevNonComment`?

No everything in the if before you go into the `PrevNonComment`. It is 
highlighted if you hover the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

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


[PATCH] D154911: Enabling fstack_clash_protection for arm32 bit, thumb and thumb2 mode

2023-07-26 Thread Tamar Christina via Phabricator via cfe-commits
tnfchris added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3460
+  } else if (EffectiveTriple.isArm() || EffectiveTriple.isThumb()) {
+CmdArgs.push_back("-mstack-probe-size=1024");
+  }

efriedma wrote:
> tnfchris wrote:
> > efriedma wrote:
> > > Why 1024?
> > 1024 was experimentally determined by Arm and is part of the ABI for stack 
> > clash (which has not yet been published).  It was determined by examining a 
> > large number of programs and looking at the function stack usages.  1024 
> > covers 80-90% of programs such that we can minimize the number of probes 
> > required in the average cases. 
> There are actually multiple numbers involved here, no?  One is the spacing of 
> probes, i.e. if allocating a large amount of stack, how many times you need 
> to probe; this is basically the page size of the target. the other is how 
> much unprobed space a function is allowed to allocate before calling another 
> function. Referring to the the AArch64 patch, -mstack-probe-size is the 
> former, the hardcoded "1024" is the latter.
I hadn't looked at the patch in detail yet, I thought this was the probing 
offset.  But you're right, what I thought of was `StackClashCallerGuard`,  if 
`stack-probe-size` indeed the guard size itself, then yeah this would be wrong. 
 It seems incorrect to allow it smaller than the page size.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154911

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


[PATCH] D156277: [Parser][ObjC] Stop parsing on eof

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

rjmccall wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > danix800 wrote:
> > > > tbaeder wrote:
> > > > > Why is there a `ConsumeToken()` call at all here? The token is 
> > > > > already being consumed in line 729.
> > > > Didn't notice this, thanks for reminding!
> > > I have the same question as @tbaeder -- what token is this intending to 
> > > consume? CC @rjmccall for Obj-C expertise
> > OH! This is consuming the identifier for the implementation/interface name 
> > itself. e.g.,
> > ```
> > @interface Frobble
> > ```
> > The consume on line 709 gets the `@`, the consume on line 729 gets the 
> > `interface`, and the consume on line 749 is getting the `Frobble`. That 
> > makes sense to me now.
> > 
> I don't think any language expertise is required here — just seems like a 
> straightforward bug on an error path that's probably not exercised all that 
> often.  Maybe somebody moved the `ConsumeToken` and forgot to fix this case 
> or something.
What concerns me about this fix is that we don't typically check whether the 
token is EOF or not before consuming; that's usually an anti-pattern, isn't it? 
Wouldn't it make sense for this to use `SkipUntil(tok::identifier)` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


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

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

Rebase to 18


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155529

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

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

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

2023-07-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:10339-10343
+  if (RT->getDecl()->isAnonymousStructOrUnion()) {
+FieldsToCheck.append(RT->getDecl()->field_begin(),
+ RT->getDecl()->field_end());
+continue;
+  }

Please add a check for `ClangABICompat` here (only do the new thing if 
`getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17`) so that 
people with a stable ABI requirement can use `-fclang-abi-compat=17.0` or 
earlier to turn off this ABI change. This is the first ABI change since we 
branched off the 17.x release, so you'll also need to add the new `Ver17` 
enumerator and parsing support for it; grep for `Ver15` to find the places you 
may need to update.


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

https://reviews.llvm.org/D155895

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


[PATCH] D156357: clang: Add elementwise bitreverse builtin

2023-07-26 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 544463.
bob80905 added a comment.
Herald added subscribers: wangpc, luke, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb.

add attempt 1 commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156357

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
  clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -206,3 +206,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_bitreverse() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);  
+}
Index: clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-bitreverse-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_bitreverse_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_bitreverse(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -269,6 +269,24 @@
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
 
+void test_builtin_elementwise_bitreverse(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_bitreverse();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_bitreverse(f);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float')}}
+  
+  i = __builtin_elementwise_bitreverse(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_bitreverse(d);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'double')}}
+}
+
 void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_ceil(f);
Index: clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-bitreverse-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_bitreverse_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_bitreverse(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
===
--- clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -47,6 +47,16 @@
   return __builtin_elementwise_min(a, b);
 }
 
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_bitreverseDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> @llvm.bitreverse.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[TMP0]]
+//
+float4 strict_elementwise_bitreverse(float4 a, float4 b) {
+  return __builtin_elementwise_bitreverse(a, b);
+}
+
 // CHECK-LABEL: d

[PATCH] D156357: clang: Add elementwise bitreverse builtin

2023-07-26 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add codegen for llvm bitreverse elementwise builtin
The bitreverse elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to integer types only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156357

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-elementwise-math.c


Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -278,13 +278,13 @@
   // expected-error@-1 {{too few arguments to function call, expected 1, have 
0}}
 
   i = __builtin_elementwise_bitreverse(f);
-  // expected-error@-1 {{1st argument must be a integer type (was 'float')}}
-
+  // expected-error@-1 {{1st argument must be a vector of integers (was 
'float')}}
+  
   i = __builtin_elementwise_bitreverse(f, f);
   // expected-error@-1 {{too many arguments to function call, expected 1, have 
2}}
 
   u = __builtin_elementwise_bitreverse(d);
-  // expected-error@-1 {{1st argument must be a integer type (was 'double')}}
+  // expected-error@-1 {{1st argument must be a vector of integers (was 
'double')}}
 }
 
 void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 
iv, unsigned u, unsigned4 uv) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2697,10 +2697,29 @@
 
   case Builtin::BI__builtin_elementwise_min:
   case Builtin::BI__builtin_elementwise_max:
-  case Builtin::BI__builtin_elementwise_bitreverse:
 if (SemaBuiltinElementwiseMath(TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_elementwise_bitreverse: {
+if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+  return ExprError();
+
+const Expr *Arg = TheCall->getArg(0);
+QualType ArgTy = Arg->getType();
+QualType EltTy = ArgTy;
+
+if (auto *VecTy = EltTy->getAs())
+  EltTy = VecTy->getElementType();
+
+if (!EltTy->isIntegerType()) {
+  Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+  << 1 << /* integer ty */ 6 << ArgTy;
+  return ExprError();
+}
+break;
+  }
+
   case Builtin::BI__builtin_elementwise_copysign: {
 if (checkArgCount(*this, TheCall, 2))
   return ExprError();


Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -278,13 +278,13 @@
   // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
 
   i = __builtin_elementwise_bitreverse(f);
-  // expected-error@-1 {{1st argument must be a integer type (was 'float')}}
-
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float')}}
+  
   i = __builtin_elementwise_bitreverse(f, f);
   // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
 
   u = __builtin_elementwise_bitreverse(d);
-  // expected-error@-1 {{1st argument must be a integer type (was 'double')}}
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'double')}}
 }
 
 void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2697,10 +2697,29 @@
 
   case Builtin::BI__builtin_elementwise_min:
   case Builtin::BI__builtin_elementwise_max:
-  case Builtin::BI__builtin_elementwise_bitreverse:
 if (SemaBuiltinElementwiseMath(TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_elementwise_bitreverse: {
+if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+  return ExprError();
+
+const Expr *Arg = TheCall->getArg(0);
+QualType ArgTy = Arg->getType();
+QualType EltTy = ArgTy;
+
+if (auto *VecTy = EltTy->getAs())
+  EltTy = VecTy->getElementType();
+
+if (!EltTy->isIntegerType()) {
+  Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+  << 1 << /* integer ty */ 6 << ArgTy;
+  return ExprError();
+}
+break;
+  }
+
   case Builtin::BI__builtin_elementwise_copysign: {
 if (checkArgCount(*this, TheCall, 2))
   return ExprError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://l

[PATCH] D154130: [lit][clang] Avoid realpath on Windows due to MAX_PATH limitations

2023-07-26 Thread Tristan Labelle via Phabricator via cfe-commits
MrTrillian added a comment.

Ping. Any brave reviewer to help here?


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

https://reviews.llvm.org/D154130

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


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

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

In D76096#4533497 , @efriedma wrote:

> Basically, I don't want order-of-magnitude compile-time regressions with 
> large global variables.  There are basically two components to that:
>
> - That the fast path for emitting globals in C continues be fast.

https://reviews.llvm.org/D76096#4529555 had some numbers for the linux kernel.

Perhaps playing with time to compile programs generated via incbin 
 would be a useful test, too?

> - That we rarely end up using evaluateValue() on large global arrays/structs 
> in C, for reasons other than emitting them.  If we end up calling 
> evaluateValue() on most globals anyway, the codegen fast-path is a lot less 
> useful;

But prior to D151587 , we did that for C++. 
Why is C special here?

And prior to this patch, we did that for C++ 11+. Why is C++ 03 special here?

To find such cases where the CGExprConstant "fast path" is failing, I'm adding 
logging to the two cases from D151587  where 
the fast path fails but the slow path succeeds, then building the Linux kernel:

  diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
  index 9ad07f7d2220..6b618db281bd 100644
  --- a/clang/lib/CodeGen/CGExprConstant.cpp
  +++ b/clang/lib/CodeGen/CGExprConstant.cpp
  @@ -1677,8 +1683,14 @@ llvm::Constant 
*ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
   
 // Try to emit the initializer.  Note that this can allow some things that
 // are not allowed by tryEmitPrivateForMemory alone.
  -  if (APValue *value = D.evaluateValue())
  -return tryEmitPrivateForMemory(*value, destType);
  +  if (APValue *value = D.evaluateValue()) {
  +llvm::Constant *C = tryEmitPrivateForMemory(*value, destType);
  +if (C) {
  +  llvm::dbgs() << "ConstExprEmitted failed (but EvaluateValue 
succeeded):\n";
  +  E->dump();
  +}
  +return C;
  +  }
   
 return nullptr;
   }
  @@ -1760,8 +1772,14 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const 
Expr *E,
 else
   Success = E->EvaluateAsRValue(Result, CGM.getContext(), 
InConstantContext);
   
  -  if (Success && !Result.HasSideEffects)
  -return tryEmitPrivate(Result.Val, destType);
  +  if (Success && !Result.HasSideEffects) {
  +llvm::Constant *C = tryEmitPrivate(Result.Val, destType);
  +if (C) {
  +  llvm::dbgs() << "ConstExprEmitter failed (but Evaluate succeeded):\n";
  +  E->dump();
  +}
  +return C;
  +  }
   
 return nullptr;
   }

There are still a lot of cases that could be improved in the fast path. 
DeclRefExpr seems error prone/more difficult, but there are still lots of 
stupid/simple cases (like `int x = -1;` being a UnaryOperator that currently 
isn't handled, and `long x = 1` having a widening ImplicitCast, `short x = 1` 
having a narrowing implicit cast, IIRC `sizeof` failed in the fast path even 
when not using DeclRefExpr).   But then when I go to improve the "fast path" 
you give me feedback that :

>> We can do a whole bunch of these, but at some point we hit diminishing 
>> returns... bailing out here isn't *that* expensive. Do you have some idea 
>> how far you want to go with this? Adding a couple obvious checks like this 
>> isn't a big deal, but I don't want to build up a complete parallel 
>> infrastructure for scalar expressions here.

So I feel like your feedback is pulling me in opposite directions.  You want to 
avoid the fast path falling back to the slow path, but improvements to the fast 
path directly result in "complete parallel infrastructure" which you also don't 
want.  Those seem mutually exclusive to me. Is there a third option?  Am I 
attacking a strawman? (Regardless, I don't want to seem unappreciative of the 
reviews, advice, or discussion).

> most of the cost of the APValue codepath is generating the APValue, not 
> lowering it.

That is my understanding of the "slow paths" as well.  I think I'll send a 
patch with just comments explaining this (which is really a follow up to 
D151587  more so than this patch).

> This is not quite as concrete as I'd like, but I'm not sure how to describe 
> it.

D151587  is in release/17.x and release/17.x 
has now branched. I'd like to try to get this patch cherry picked back to 
release/17.x, and as such I have marked 
https://github.com/llvm/llvm-project/issues/44502 as part of the release/17.x 
milestone.  Please let me know if you think that's too aggressive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76096

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

[PATCH] D156277: [Parser][ObjC] Stop parsing on eof

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

aaron.ballman wrote:
> danix800 wrote:
> > tbaeder wrote:
> > > Why is there a `ConsumeToken()` call at all here? The token is already 
> > > being consumed in line 729.
> > Didn't notice this, thanks for reminding!
> I have the same question as @tbaeder -- what token is this intending to 
> consume? CC @rjmccall for Obj-C expertise
OH! This is consuming the identifier for the implementation/interface name 
itself. e.g.,
```
@interface Frobble
```
The consume on line 709 gets the `@`, the consume on line 729 gets the 
`interface`, and the consume on line 749 is getting the `Frobble`. That makes 
sense to me now.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


[PATCH] D156277: [Parser][ObjC] Stop parsing on eof

2023-07-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

aaron.ballman wrote:
> danix800 wrote:
> > tbaeder wrote:
> > > Why is there a `ConsumeToken()` call at all here? The token is already 
> > > being consumed in line 729.
> > Didn't notice this, thanks for reminding!
> I have the same question as @tbaeder -- what token is this intending to 
> consume? CC @rjmccall for Obj-C expertise
I don't think any language expertise is required here — just seems like a 
straightforward bug on an error path that's probably not exercised all that 
often.  Maybe somebody moved the `ConsumeToken` and forgot to fix this case or 
something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


[PATCH] D156175: [clang][ConstExprEmitter] handle NullToPointer ImplicitCastExpr

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156175

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


[PATCH] D156274: [NFC] Avoid potential dereferencing of nullptr.

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:1659
   mangleCXXDtorType(Dtor_Complete);
+assert(ND);
 writeAbiTags(ND, AdditionalAbiTags);

efriedma wrote:
> aaron.ballman wrote:
> > This seems incorrect -- if the declaration name is a destructor, then `ND` 
> > should always be null, right?
> Seems okay to me?  ND is the destructor declaration.
Yeah, you're correct -- I was thinking `CXXDestructorDecl` was not a 
`NamedDecl`, but it's a `CXXMethodDecl` without a name, so this is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156274

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


[PATCH] D156274: [NFC] Avoid potential dereferencing of nullptr.

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



Comment at: clang/lib/AST/ItaniumMangle.cpp:1659
   mangleCXXDtorType(Dtor_Complete);
+assert(ND);
 writeAbiTags(ND, AdditionalAbiTags);

aaron.ballman wrote:
> This seems incorrect -- if the declaration name is a destructor, then `ND` 
> should always be null, right?
Seems okay to me?  ND is the destructor declaration.



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:1806
 // Complex types.
+assert(contBB);
 CGF.EmitBlock(contBB);

aaron.ballman wrote:
> Hmmm, is assert the correct approach here? It seems to me that a Complex 
> rvalue will trigger this assertion. I think this deserves some additional 
> thinking rather than silencing the static analysis warning. CC @efriedma 
> @rjmccall who might have ideas.
Yes, if a complex value hit this codepath with a null contBB, it would just 
crash, so the analysis is flagging a real issue.

I'm not sure how to write ObjC code to actually trigger this codepath, though.  
Probably involves a `_Complex _BitInt(128)` or something like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156274

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-26 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:291
+  /// the frontend.
+  OpenMPDirectiveKind prevMappedDirective;
+

OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown;



Comment at: clang/include/clang/AST/StmtOpenMP.h:308
+EndLoc(std::move(EndLoc)),
+prevMappedDirective(llvm::omp::OMPD_unknown) {}
 

Remove initialization of prevMappedDirective with the default value from the 
constructor



Comment at: clang/include/clang/AST/StmtOpenMP.h:616
+
+  OpenMPDirectiveKind getMappedDirective() { return prevMappedDirective; }
+

const member function



Comment at: clang/include/clang/Sema/Sema.h:11476
   StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef Clauses);
   StmtResult ActOnOpenMPExecutableDirective(
   OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,

All these changed functions are called with the default value of this new 
prevMappedDirective paramer. Remove.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6391
 Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, 
EndLoc,
-   VarsWithInheritedDSA);
+   VarsWithInheritedDSA, prevMappedDirective);
 if (LangOpts.OpenMP >= 50)

Can you just use DSAStack->getMappedDirective() instead of prevMappedDirective?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:10544
 
-  setFunctionHasBranchProtectedScope();
-  return OMPForDirective::Create(
+  OMPForDirective *ForDirective = OMPForDirective::Create(
   Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,

`auto *ForDirective`


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

https://reviews.llvm.org/D144634

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


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/ast-print-method-decl.cpp:65
+  // CHECK-NEXT: CurlyCtorInit() : a1({}), a2{}, b{} {
+  CurlyCtorInit() : a1({}), a2{}, b{} {
+  // CHECK-NEXT: }

Can you add another ctor that uses round parens for the member initializers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156307

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


[PATCH] D156352: [OpenMP][Sema] Fix directive name modifier/if-clause/'target teams loop'

2023-07-26 Thread David Pagan 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 rG7cb9698374ac: [OpenMP][Sema] Fix directive name 
modifier/if-clause/'target teams loop' (authored by ddpagan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156352

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_messages.cpp

Index: clang/test/OpenMP/target_teams_generic_loop_messages.cpp
===
--- clang/test/OpenMP/target_teams_generic_loop_messages.cpp
+++ clang/test/OpenMP/target_teams_generic_loop_messages.cpp
@@ -127,6 +127,16 @@
   for (i=0; i<1000; ++i)
 z = i+11;
 
+  // expected-error@+1 {{directive name modifier 'teams' is not allowed for '#pragma omp target teams loop'}}
+  #pragma omp target teams loop if(teams:1)
+  for (i=0; i<1000; ++i)
+z = i+11;
+
+  // expected-error@+1 {{directive name modifier 'parallel' is not allowed for '#pragma omp target teams loop'}}
+  #pragma omp target teams loop if(parallel:0)
+  for (i=0; i<1000; ++i)
+z = i+11;
+
 }
 
 template 
Index: clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
===
--- clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
+++ clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
@@ -48,7 +48,7 @@
 #pragma omp target teams loop
   for(int i = 0 ; i < 100; i++) {}
 
-#pragma omp target teams loop if (parallel: false)
+#pragma omp target teams loop if (target: false)
   for(int i = 0 ; i < 100; i++) {
 gtid_test();
   }
@@ -65,7 +65,7 @@
   for(int i = 0 ; i < 100; i++) {
 fn2();
   }
-#pragma omp target teams loop if (parallel: Arg)
+#pragma omp target teams loop if (target: Arg)
   for(int i = 0 ; i < 100; i++) {
 fn3();
   }
@@ -110,8 +110,6 @@
 // CHECK1-NEXT:  entry:
 // CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[KERNEL_ARGS:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
-// CHECK1-NEXT:[[_TMP1:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[KERNEL_ARGS2:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS]], align 8
 // CHECK1-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
 // CHECK1-NEXT:store i32 2, ptr [[TMP0]], align 4
 // CHECK1-NEXT:[[TMP1:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
@@ -145,39 +143,7 @@
 // CHECK1-NEXT:call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z9gtid_testv_l48() #[[ATTR2:[0-9]+]]
 // CHECK1-NEXT:br label [[OMP_OFFLOAD_CONT]]
 // CHECK1:   omp_offload.cont:
-// CHECK1-NEXT:[[TMP15:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 0
-// CHECK1-NEXT:store i32 2, ptr [[TMP15]], align 4
-// CHECK1-NEXT:[[TMP16:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 1
-// CHECK1-NEXT:store i32 0, ptr [[TMP16]], align 4
-// CHECK1-NEXT:[[TMP17:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 2
-// CHECK1-NEXT:store ptr null, ptr [[TMP17]], align 8
-// CHECK1-NEXT:[[TMP18:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 3
-// CHECK1-NEXT:store ptr null, ptr [[TMP18]], align 8
-// CHECK1-NEXT:[[TMP19:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 4
-// CHECK1-NEXT:store ptr null, ptr [[TMP19]], align 8
-// CHECK1-NEXT:[[TMP20:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 5
-// CHECK1-NEXT:store ptr null, ptr [[TMP20]], align 8
-// CHECK1-NEXT:[[TMP21:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 6
-// CHECK1-NEXT:store ptr null, ptr [[TMP21]], align 8
-// CHECK1-NEXT:[[TMP22:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 7
-// CHECK1-NEXT:store ptr null, ptr [[TMP22]], align 8
-// CHECK1-NEXT:[[TMP23:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 8
-// CHECK1-NEXT:store i64 100, ptr [[TMP23]], align 8
-// CHECK1-NEXT:[[TMP24:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 9
-// CHECK1-NEXT:store i64 0, ptr [[TMP24]], align 8
-// CHECK1-NEXT:[[TMP25:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 10
-// CHECK1-NEXT:store [3 x i32] zeroinitializer, ptr [[TMP25]], align 4
-// CHECK1-NEXT:[[TMP26

[clang] 7cb9698 - [OpenMP][Sema] Fix directive name modifier/if-clause/'target teams loop'

2023-07-26 Thread Dave Pagan via cfe-commits

Author: Dave Pagan
Date: 2023-07-26T13:19:56-05:00
New Revision: 7cb9698374ac2eb4cb01dd1a866339e8aa409834

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

LOG: [OpenMP][Sema] Fix directive name modifier/if-clause/'target teams loop'

The if-clause on 'target teams loop' should only accept "target" as a
directive name modifier. Any other directive name should generate an
error.

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
clang/test/OpenMP/target_teams_generic_loop_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3954bf2ad28041..305ea24383ca0e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6634,6 +6634,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
   case OMPD_target_teams_loop:
 Res = ActOnOpenMPTargetTeamsGenericLoopDirective(
 ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA);
+AllowedNameModifiers.push_back(OMPD_target);
 break;
   case OMPD_parallel_loop:
 Res = ActOnOpenMPParallelGenericLoopDirective(

diff  --git a/clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp 
b/clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
index f00b324b9148d1..4291a405e4baf4 100644
--- a/clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
+++ b/clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
@@ -48,7 +48,7 @@ void gtid_test() {
 #pragma omp target teams loop
   for(int i = 0 ; i < 100; i++) {}
 
-#pragma omp target teams loop if (parallel: false)
+#pragma omp target teams loop if (target: false)
   for(int i = 0 ; i < 100; i++) {
 gtid_test();
   }
@@ -65,7 +65,7 @@ int tmain(T Arg) {
   for(int i = 0 ; i < 100; i++) {
 fn2();
   }
-#pragma omp target teams loop if (parallel: Arg)
+#pragma omp target teams loop if (target: Arg)
   for(int i = 0 ; i < 100; i++) {
 fn3();
   }
@@ -110,8 +110,6 @@ int main() {
 // CHECK1-NEXT:  entry:
 // CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[KERNEL_ARGS:%.*]] = alloca 
[[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
-// CHECK1-NEXT:[[_TMP1:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[KERNEL_ARGS2:%.*]] = alloca 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], align 8
 // CHECK1-NEXT:[[TMP0:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
 // CHECK1-NEXT:store i32 2, ptr [[TMP0]], align 4
 // CHECK1-NEXT:[[TMP1:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
@@ -145,39 +143,7 @@ int main() {
 // CHECK1-NEXT:call void 
@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z9gtid_testv_l48() #[[ATTR2:[0-9]+]]
 // CHECK1-NEXT:br label [[OMP_OFFLOAD_CONT]]
 // CHECK1:   omp_offload.cont:
-// CHECK1-NEXT:[[TMP15:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 0
-// CHECK1-NEXT:store i32 2, ptr [[TMP15]], align 4
-// CHECK1-NEXT:[[TMP16:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 1
-// CHECK1-NEXT:store i32 0, ptr [[TMP16]], align 4
-// CHECK1-NEXT:[[TMP17:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 2
-// CHECK1-NEXT:store ptr null, ptr [[TMP17]], align 8
-// CHECK1-NEXT:[[TMP18:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 3
-// CHECK1-NEXT:store ptr null, ptr [[TMP18]], align 8
-// CHECK1-NEXT:[[TMP19:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 4
-// CHECK1-NEXT:store ptr null, ptr [[TMP19]], align 8
-// CHECK1-NEXT:[[TMP20:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 5
-// CHECK1-NEXT:store ptr null, ptr [[TMP20]], align 8
-// CHECK1-NEXT:[[TMP21:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 6
-// CHECK1-NEXT:store ptr null, ptr [[TMP21]], align 8
-// CHECK1-NEXT:[[TMP22:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 7
-// CHECK1-NEXT:store ptr null, ptr [[TMP22]], align 8
-// CHECK1-NEXT:[[TMP23:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 8
-// CHECK1-NEXT:store i64 100, ptr [[TMP23]], align 8
-// CHECK1-NEXT:[[TMP24:%.*]] = getelementptr inbounds 
[[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS2]], i32 0, i32 9
-// CHECK1-NEXT:store i

[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

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

Maybe add a designated init test in there as well e.g.

  struct A {
  int x {};
  };
  struct B {
  B() : a({.x = 1}) {
  }
  A a;
  };


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156307

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


[PATCH] D156352: [OpenMP][Sema] Fix directive name modifier/if-clause/'target teams loop'

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156352

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

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

In D156247#4536034 , @tahonermann 
wrote:

>> You are absolutely right, -fno-coroutines would totally work for us, had it 
>> been available.
>
> Good. Gcc handles `-fcoroutines` and `-fno-coroutines` as I would expect 
> (https://godbolt.org/z/7zEMd7cdW), so matching gcc behavior makes sense in 
> any case. I would expect implementation to be quite straight forward, so I 
> recommend we head in that direction.

I think we generally want to avoid "congratulatory" diagnostics unless the 
language feature is truly surprising to users in practice. e.g., we have 
`-Wvla` as a diagnostic to tell users when they're using a VLA because of just 
how often people think `const int i = 12; int array[i];` forms a constant-sized 
array when it doesn't (and VLAs can have security implications). There's 
nothing about coroutines that seems like it would surprise users such that they 
need a diagnostic to tell them they're using the feature. So I don't think this 
meets the bar for a diagnostic in Clang.

That said, I think `-fno-coroutines` should work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


  1   2   3   >