[PATCH] D119319: [AArch64] Emit TBAA metadata for SVE load/store intrinsics

2022-02-11 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp:888
   if (isAllActivePredicate(Pred)) {
-Builder.CreateStore(VecOp, VecPtr);
+auto *Store = Builder.CreateStore(VecOp, VecPtr);
+Store->copyMetadata(II);

paulwalker-arm wrote:
> If I'm nit picking you use `auto` here but then choose the explicit return 
> type (i.e. `CallInst`) for the MaskedStore local. Is there a reason for this 
> or just muscle memory?
> Is there a reason for this or just muscle memory?
I initially assumed the IRBuilder's result was a `Value*` because that's what 
most of its methods return, so wrote `auto *Store = 
cast(Builder.CreateStore(...))`. When I realised it wasn't required, 
I remove the cast, but not the `auto`. I changed the code for LD1 after fixing 
ST1, hence the inconsistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119319

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: aaron.ballman.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a missing test, covering the different kinds of floating-point
literals, like hexadecimal floats, and testing extreme cases & normal cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119319: [AArch64] Emit TBAA metadata for SVE load/store intrinsics

2022-02-11 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b41238ae7f9: [AArch64] Emit TBAA metadata for SVE 
load/store intrinsics (authored by sdesmalen).

Changed prior to commit:
  https://reviews.llvm.org/D119319?vs=407060&id=407804#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119319

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-loadstore.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-loadstore.ll
===
--- llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-loadstore.ll
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-loadstore.ll
@@ -6,24 +6,24 @@
 define  @combine_ld1(i32* %ptr) #0 {
 ; CHECK-LABEL: @combine_ld1(
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[PTR:%.*]] to *
-; CHECK-NEXT:[[TMP2:%.*]] = load , * [[TMP1]], align 16
+; CHECK-NEXT:[[TMP2:%.*]] = load , * [[TMP1]], align 16, !annotation !0
 ; CHECK-NEXT:ret  [[TMP2]]
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
-  %2 = call  @llvm.aarch64.sve.ld1.nxv4i32( %1, i32* %ptr)
+  %2 = call  @llvm.aarch64.sve.ld1.nxv4i32( %1, i32* %ptr), !annotation !0
   ret  %2
 }
 
 define  @combine_ld1_casted_predicate(i32* %ptr) #0 {
 ; CHECK-LABEL: @combine_ld1_casted_predicate(
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[PTR:%.*]] to *
-; CHECK-NEXT:[[TMP2:%.*]] = load , * [[TMP1]], align 16
+; CHECK-NEXT:[[TMP2:%.*]] = load , * [[TMP1]], align 16, !annotation !0
 ; CHECK-NEXT:ret  [[TMP2]]
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
   %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
   %3 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %2)
-  %4 = call  @llvm.aarch64.sve.ld1.nxv4i32( %3, i32* %ptr)
+  %4 = call  @llvm.aarch64.sve.ld1.nxv4i32( %3, i32* %ptr), !annotation !0
   ret  %4
 }
 
@@ -31,11 +31,11 @@
 ; CHECK-LABEL: @combine_ld1_masked(
 ; CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 16)
 ; CHECK-NEXT:[[TMP2:%.*]] = bitcast i32* [[PTR:%.*]] to *
-; CHECK-NEXT:[[TMP3:%.*]] = call  @llvm.masked.load.nxv4i32.p0nxv4i32(* [[TMP2]], i32 1,  [[TMP1]],  zeroinitializer)
+; CHECK-NEXT:[[TMP3:%.*]] = call  @llvm.masked.load.nxv4i32.p0nxv4i32(* [[TMP2]], i32 1,  [[TMP1]],  zeroinitializer), !annotation !0
 ; CHECK-NEXT:ret  [[TMP3]]
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 16)
-  %2 = call  @llvm.aarch64.sve.ld1.nxv4i32( %1, i32* %ptr)
+  %2 = call  @llvm.aarch64.sve.ld1.nxv4i32( %1, i32* %ptr), !annotation !0
   ret  %2
 }
 
@@ -45,37 +45,37 @@
 ; CHECK-NEXT:[[TMP2:%.*]] = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( [[TMP1]])
 ; CHECK-NEXT:[[TMP3:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[TMP2]])
 ; CHECK-NEXT:[[TMP4:%.*]] = bitcast i16* [[PTR:%.*]] to *
-; CHECK-NEXT:[[TMP5:%.*]] = call  @llvm.masked.load.nxv8i16.p0nxv8i16(* [[TMP4]], i32 1,  [[TMP3]],  zeroinitializer)
+; CHECK-NEXT:[[TMP5:%.*]] = call  @llvm.masked.load.nxv8i16.p0nxv8i16(* [[TMP4]], i32 1,  [[TMP3]],  zeroinitializer), !annotation !0
 ; CHECK-NEXT:ret  [[TMP5]]
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
   %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
   %3 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %2)
-  %4 = call  @llvm.aarch64.sve.ld1.nxv8i16( %3, i16* %ptr)
+  %4 = call  @llvm.aarch64.sve.ld1.nxv8i16( %3, i16* %ptr), !annotation !0
   ret  %4
 }
 
 define void @combine_st1( %vec, i32* %ptr) #0 {
 ; CHECK-LABEL: @combine_st1(
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[PTR:%.*]] to *
-; CHECK-NEXT:store  [[VEC:%.*]], * [[TMP1]], align 16
+; CHECK-NEXT:store  [[VEC:%.*]], * [[TMP1]], align 16, !annotation !0
 ; CHECK-NEXT:ret void
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv4i1(i32 31)
-  call void @llvm.aarch64.sve.st1.nxv4i32( %vec,  %1, i32* %ptr)
+  call void @llvm.aarch64.sve.st1.nxv4i32( %vec,  %1, i32* %ptr), !annotation !0
   ret void
 }
 
 define void @combine_st1_casted_predicate( %vec, i32* %ptr) #0 {
 ; CHECK-LABEL: @combine_st1_casted_predicate(
 ; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[PTR:%.*]] to *
-; CHECK-NEXT:store  [[VEC:%.*]], * [[TMP1]], align 16
+; CHECK-NEXT:store  [[VEC:%.*]], * [[TMP1]], align 16, !annotation !0
 ; CHECK-NEXT:ret void
 ;
   %1 = tail call  @llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
   %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
   %3 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %2)
-  call void @llvm.aarch64.sve.st1.nxv4i32( %vec,  %3, i32* %ptr)
+  call void @llvm.aarch64.sve.st1.nxv4i32( %vec,  %3, i32* %ptr), !annotation !0
   re

[clang] 0b41238 - [AArch64] Emit TBAA metadata for SVE load/store intrinsics

2022-02-11 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2022-02-11T09:00:29Z
New Revision: 0b41238ae7f91bcc907a577377caa70721ffc400

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

LOG: [AArch64] Emit TBAA metadata for SVE load/store intrinsics

In Clang we can attach TBAA metadata based on the load/store intrinsics
based on the operation's element type.

This also contains changes to InstCombine where the AArch64-specific
intrinsics are transformed into generic LLVM load/store operations,
to ensure that all metadata is transferred to the new instruction.

There will be some further work after this patch to also emit TBAA
metadata for SVE's gather/scatter- and struct load/store intrinsics.

Reviewed By: paulwalker-arm

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-loadstore.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 310a1ea583ce..9705c118246f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9028,7 +9028,10 @@ Value *CodeGenFunction::EmitSVEMaskedLoad(const CallExpr 
*E,
 
   BasePtr = Builder.CreateBitCast(BasePtr, MemEltTy->getPointerTo());
   Function *F = CGM.getIntrinsic(BuiltinID, MemoryTy);
-  Value *Load = Builder.CreateCall(F, {Predicate, BasePtr});
+  auto *Load =
+  cast(Builder.CreateCall(F, {Predicate, BasePtr}));
+  auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  CGM.DecorateInstructionWithTBAA(Load, TBAAInfo);
 
   return IsZExtReturn ? Builder.CreateZExt(Load, VectorTy)
  : Builder.CreateSExt(Load, VectorTy);
@@ -9056,7 +9059,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
 
   BasePtr = Builder.CreateBitCast(BasePtr, MemEltTy->getPointerTo());
   Function *F = CGM.getIntrinsic(BuiltinID, MemoryTy);
-  return Builder.CreateCall(F, {Val, Predicate, BasePtr});
+  auto *Store =
+  cast(Builder.CreateCall(F, {Val, Predicate, 
BasePtr}));
+  auto TBAAInfo = CGM.getTBAAAccessInfo(LangPTy->getPointeeType());
+  CGM.DecorateInstructionWithTBAA(Store, TBAAInfo);
+  return Store;
 }
 
 // Limit the usage of scalable llvm IR generated by the ACLE by using the

diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
index 0fde476e9fe0..4620c0e28c69 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
@@ -17,7 +17,7 @@
 // CHECK-LABEL: @test_svld1_s8(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast i8* [[BASE:%.*]] to *
-// CHECK-NEXT:[[TMP1:%.*]] = call  
@llvm.masked.load.nxv16i8.p0nxv16i8(* [[TMP0]], i32 1, 
 [[PG:%.*]],  zeroinitializer)
+// CHECK-NEXT:[[TMP1:%.*]] = call  
@llvm.masked.load.nxv16i8.p0nxv16i8(* [[TMP0]], i32 1, 
 [[PG:%.*]],  zeroinitializer), !tbaa 
![[CHAR:[0-9]+]]
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z13test_svld1_s8u10__SVBool_tPKa(
@@ -35,7 +35,7 @@ svint8_t test_svld1_s8(svbool_t pg, const int8_t *base)
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PG:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast i16* [[BASE:%.*]] to *
-// CHECK-NEXT:[[TMP2:%.*]] = call  
@llvm.masked.load.nxv8i16.p0nxv8i16(* [[TMP1]], i32 1, 
 [[TMP0]],  zeroinitializer)
+// CHECK-NEXT:[[TMP2:%.*]] = call  
@llvm.masked.load.nxv8i16.p0nxv8i16(* [[TMP1]], i32 1, 
 [[TMP0]],  zeroinitializer), !tbaa 
![[SHORT:[0-9]+]]
 // CHECK-NEXT:ret  [[TMP2]]
 //
 // CPP-CHECK-LABEL: @_Z14test_svld1_s16u10__SVBool_tPKs(
@@ -54,7 +54,7 @@ svint16_t test_svld1_s16(svbool_t pg, const int16_t *base)
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PG:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[BASE:%.*]] to *
-// CHECK-NEXT:[[TMP2:%.*]] = call  
@llvm.masked.load.nxv4i32.p0nxv4i32(* [[TMP1]], i32 1, 
 [[TMP0]],  zeroinitializer)
+// CHECK-NEXT:[[TMP2:%.*]] = call  
@llvm.masked.load.nxv4i32.p0nxv4i32(* [[TMP1]], i32 1, 
 [[TMP0]],  zeroinitializer), !tbaa 
![[INT:[0-9]+]]
 // CHECK-NEXT:ret  [[TMP2]]
 //
 // CPP-CHECK-LABEL: @_Z14test_svld1_s32u10__SVBool_tPKi(
@@ -73,7 +73,7 @@ svint32_t test_svld1_s32(svbool_t pg, const int32_t *base)
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PG:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast i64* [[BASE:%.*]] to *
-// CHECK-NEXT:[[TMP2:%.*]] 

[PATCH] D106888: [RISC-V] Implement jump tables for CFI-icall

2022-02-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Needs a test in llvm/test/Transforms/LowerTypeTests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106888

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


[clang] abc8736 - [analyzer] Restrict CallDescription fuzzy builtin matching

2022-02-11 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-02-11T10:45:18+01:00
New Revision: abc873694ff7cde3def6860564521e059cb542f8

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

LOG: [analyzer] Restrict CallDescription fuzzy builtin matching

`CallDescriptions` for builtin functions relaxes the match rules
somewhat, so that the `CallDescription` will match for calls that have
some prefix or suffix. This was achieved by doing a `StringRef::contains()`.
However, this is somewhat problematic for builtins that are substrings
of each other.

Consider the following:

`CallDescription{ builtin, "memcpy"}` will match for
`__builtin_wmemcpy()` calls, which is unfortunate.

This patch addresses/works around the issue by checking if the
characters around the function's name are not part of the 'name'
semantically. In other words, to accept a match for `"memcpy"` the call
should not have alphanumeric (`[a-zA-Z]`) characters around the 'match'.

So, `CallDescription{ builtin, "memcpy"}` will not match on:

 - `__builtin_wmemcpy: there is a `w` alphanumeric character before the match.
 - `__builtin_memcpyFOoBar_inline`: there is a `F` character after the match.
 - `__builtin_memcpyX_inline`: there is an `X` character after the match.

But it will still match for:
 - `memcpy`: exact match
 - `__builtin_memcpy`: there is an _ before the match
 - `__builtin_memcpy_inline`: there is an _ after the match
 - `memcpy_inline_builtinFooBar`: there is an _ after the match

Reviewed By: NoQ

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp 
b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
index 4c684c3ffd9bf..73d5d9489cb78 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -55,8 +55,29 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl 
*FD,
 if (Name.empty())
   return true;
 StringRef BName = FD->getASTContext().BuiltinInfo.getName(BId);
-if (BName.contains(Name))
-  return true;
+size_t start = BName.find(Name);
+if (start != StringRef::npos) {
+  // Accept exact match.
+  if (BName.size() == Name.size())
+return true;
+
+  //v-- match starts here
+  // ...x...
+  //   _x_
+  //   ^ ^ lookbehind and lookahead characters
+
+  const auto MatchPredecessor = [=]() -> bool {
+return start <= 0 || !llvm::isAlpha(BName[start - 1]);
+  };
+  const auto MatchSuccessor = [=]() -> bool {
+std::size_t LookbehindPlace = start + Name.size();
+return LookbehindPlace >= BName.size() ||
+   !llvm::isAlpha(BName[LookbehindPlace]);
+  };
+
+  if (MatchPredecessor() && MatchSuccessor())
+return true;
+}
   }
 
   const IdentifierInfo *II = FD->getIdentifier();

diff  --git a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp 
b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
index 98c8eb27516f6..f2d85b3bc17c7 100644
--- a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
@@ -487,6 +487,60 @@ TEST(CallDescription, MatchBuiltins) {
   "  __builtin___memset_chk(&x, 0, sizeof(x),"
   " __builtin_object_size(&x, 0));"
   "}"));
+
+  {
+SCOPED_TRACE("multiple similar builtins");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(new CallDescriptionAction<>(
+{{{CDF_MaybeBuiltin, "memcpy", 3}, false},
+ {{CDF_MaybeBuiltin, "wmemcpy", 3}, true}})),
+R"(void foo(wchar_t *x, wchar_t *y) {
+__builtin_wmemcpy(x, y, sizeof(wchar_t));
+  })"));
+  }
+  {
+SCOPED_TRACE("multiple similar builtins reversed order");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(new CallDescriptionAction<>(
+{{{CDF_MaybeBuiltin, "wmemcpy", 3}, true},
+ {{CDF_MaybeBuiltin, "memcpy", 3}, false}})),
+R"(void foo(wchar_t *x, wchar_t *y) {
+__builtin_wmemcpy(x, y, sizeof(wchar_t));
+  })"));
+  }
+  {
+SCOPED_TRACE("lookbehind and lookahead mismatches");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(
+new CallDescriptionAction<>({{{CDF_MaybeBuiltin, "func"}, 
false}})),
+R"(
+  void funcXXX();
+  void XXXfunc();
+  void XXXfuncXXX();
+  void test() {
+funcXXX();
+XXXfunc();
+XXXfuncXXX();
+  })"));
+  }
+  {
+SCOPED_TRACE("lookbehind and lookahead matches");
+EXPEC

[PATCH] D118388: [analyzer] Restrict CallDescription fuzzy builtin matching

2022-02-11 Thread Balázs Benics 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 rGabc873694ff7: [analyzer] Restrict CallDescription fuzzy 
builtin matching (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118388

Files:
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

Index: clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
===
--- clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
+++ clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
@@ -487,6 +487,60 @@
   "  __builtin___memset_chk(&x, 0, sizeof(x),"
   " __builtin_object_size(&x, 0));"
   "}"));
+
+  {
+SCOPED_TRACE("multiple similar builtins");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(new CallDescriptionAction<>(
+{{{CDF_MaybeBuiltin, "memcpy", 3}, false},
+ {{CDF_MaybeBuiltin, "wmemcpy", 3}, true}})),
+R"(void foo(wchar_t *x, wchar_t *y) {
+__builtin_wmemcpy(x, y, sizeof(wchar_t));
+  })"));
+  }
+  {
+SCOPED_TRACE("multiple similar builtins reversed order");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(new CallDescriptionAction<>(
+{{{CDF_MaybeBuiltin, "wmemcpy", 3}, true},
+ {{CDF_MaybeBuiltin, "memcpy", 3}, false}})),
+R"(void foo(wchar_t *x, wchar_t *y) {
+__builtin_wmemcpy(x, y, sizeof(wchar_t));
+  })"));
+  }
+  {
+SCOPED_TRACE("lookbehind and lookahead mismatches");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(
+new CallDescriptionAction<>({{{CDF_MaybeBuiltin, "func"}, false}})),
+R"(
+  void funcXXX();
+  void XXXfunc();
+  void XXXfuncXXX();
+  void test() {
+funcXXX();
+XXXfunc();
+XXXfuncXXX();
+  })"));
+  }
+  {
+SCOPED_TRACE("lookbehind and lookahead matches");
+EXPECT_TRUE(tooling::runToolOnCode(
+std::unique_ptr(
+new CallDescriptionAction<>({{{CDF_MaybeBuiltin, "func"}, true}})),
+R"(
+  void func();
+  void func_XXX();
+  void XXX_func();
+  void XXX_func_XXX();
+
+  void test() {
+func(); // exact match
+func_XXX();
+XXX_func();
+XXX_func_XXX();
+  })"));
+  }
 }
 
 } // namespace
Index: clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -55,8 +55,29 @@
 if (Name.empty())
   return true;
 StringRef BName = FD->getASTContext().BuiltinInfo.getName(BId);
-if (BName.contains(Name))
-  return true;
+size_t start = BName.find(Name);
+if (start != StringRef::npos) {
+  // Accept exact match.
+  if (BName.size() == Name.size())
+return true;
+
+  //v-- match starts here
+  // ...x...
+  //   _x_
+  //   ^ ^ lookbehind and lookahead characters
+
+  const auto MatchPredecessor = [=]() -> bool {
+return start <= 0 || !llvm::isAlpha(BName[start - 1]);
+  };
+  const auto MatchSuccessor = [=]() -> bool {
+std::size_t LookbehindPlace = start + Name.size();
+return LookbehindPlace >= BName.size() ||
+   !llvm::isAlpha(BName[LookbehindPlace]);
+  };
+
+  if (MatchPredecessor() && MatchSuccessor())
+return true;
+}
   }
 
   const IdentifierInfo *II = FD->getIdentifier();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a218706 - [clang-format] Add tests for spacing between ref-qualifier and `noexcept`. NFC.

2022-02-11 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-11T10:50:05+01:00
New Revision: a218706cba90248be0c60bd6a8f10dbcf0270955

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

LOG: [clang-format] Add tests for spacing between ref-qualifier and `noexcept`. 
NFC.

Cf. https://github.com/llvm/llvm-project/issues/44542.
Cf. 
https://github.com/llvm/llvm-project/commit/ae1b7859cbd61d2284d9690bc53482d0b6a46f63.

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8639a72eceb12..aa50d73499d04 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9589,8 +9589,11 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
 }
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
+  verifyFormat("void A::b() && {}");
+  verifyFormat("void A::b() &&noexcept {}");
   verifyFormat("Deleted &operator=(const Deleted &) & = default;");
   verifyFormat("Deleted &operator=(const Deleted &) && = delete;");
+  verifyFormat("Deleted &operator=(const Deleted &) &noexcept = default;");
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;");
   verifyFormat("SomeType MemberFunction(const Deleted &) && = delete;");
   verifyFormat("Deleted &operator=(const Deleted &) &;");
@@ -9600,8 +9603,10 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   verifyFormat("SomeType MemberFunction(const Deleted &) && {}");
   verifyFormat("SomeType MemberFunction(const Deleted &) && final {}");
   verifyFormat("SomeType MemberFunction(const Deleted &) && override {}");
+  verifyFormat("SomeType MemberFunction(const Deleted &) &&noexcept {}");
   verifyFormat("void Fn(T const &) const &;");
   verifyFormat("void Fn(T const volatile &&) const volatile &&;");
+  verifyFormat("void Fn(T const volatile &&) const volatile &&noexcept;");
   verifyFormat("template \n"
"void F(T) && = delete;",
getGoogleStyle());
@@ -9609,7 +9614,10 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   FormatStyle AlignLeft = getLLVMStyle();
   AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("void A::b() && {}", AlignLeft);
+  verifyFormat("void A::b() && noexcept {}", AlignLeft);
   verifyFormat("Deleted& operator=(const Deleted&) & = default;", AlignLeft);
+  verifyFormat("Deleted& operator=(const Deleted&) & noexcept = default;",
+   AlignLeft);
   verifyFormat("SomeType MemberFunction(const Deleted&) & = delete;",
AlignLeft);
   verifyFormat("Deleted& operator=(const Deleted&) &;", AlignLeft);
@@ -9620,6 +9628,29 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   verifyFormat("auto Function(T) & -> void;", AlignLeft);
   verifyFormat("void Fn(T const&) const&;", AlignLeft);
   verifyFormat("void Fn(T const volatile&&) const volatile&&;", AlignLeft);
+  verifyFormat("void Fn(T const volatile&&) const volatile&& noexcept;",
+   AlignLeft);
+
+  FormatStyle AlignMiddle = getLLVMStyle();
+  AlignMiddle.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat("void A::b() && {}", AlignMiddle);
+  verifyFormat("void A::b() && noexcept {}", AlignMiddle);
+  verifyFormat("Deleted & operator=(const Deleted &) & = default;",
+   AlignMiddle);
+  verifyFormat("Deleted & operator=(const Deleted &) & noexcept = default;",
+   AlignMiddle);
+  verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;",
+   AlignMiddle);
+  verifyFormat("Deleted & operator=(const Deleted &) &;", AlignMiddle);
+  verifyFormat("SomeType MemberFunction(const Deleted &) &;", AlignMiddle);
+  verifyFormat("auto Function(T t) & -> void {}", AlignMiddle);
+  verifyFormat("auto Function(T... t) & -> void {}", AlignMiddle);
+  verifyFormat("auto Function(T) & -> void {}", AlignMiddle);
+  verifyFormat("auto Function(T) & -> void;", AlignMiddle);
+  verifyFormat("void Fn(T const &) const &;", AlignMiddle);
+  verifyFormat("void Fn(T const volatile &&) const volatile &&;", AlignMiddle);
+  verifyFormat("void Fn(T const volatile &&) const volatile && noexcept;",
+   AlignMiddle);
 
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInCStyleCastParentheses = true;



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


[PATCH] D118388: [analyzer] Restrict CallDescription fuzzy builtin matching

2022-02-11 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I decided to land it as-is.
I tried to refactor the rest of the `isCLibraryFunction()` to reuse the new 
detection logic, but I run into issues by doing that.
BTW I'm not sure if we should support anything besides the builtins defined in 
`clang/include/clang/Basic/Builtins*.def` files.
Given that the parser should recognize these and use the appropriate Builtin 
for the FunctionDecl, `getBuiltinID()` should return the given `ID`.
Anyway. I decided to take it slowly and fix only the issue causing the crashes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118388

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


[PATCH] D116155: [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-11 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D116155#3303622 , @balazske wrote:

> @martong Ping
> We do not have possibility currently to check all LLDB tests. I think we can 
> commit this and observe the buildbots for failure.

I agree. Let's see if it works out. I don't think we shall wait for longer.
This should be already better than crashing time-to-time.
We can always revert if necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116155

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


[clang] 50f8abb - [OpenCL] Add OpenCL 3.0 atomics to -fdeclare-opencl-builtins

2022-02-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-11T10:14:14Z
New Revision: 50f8abb9f40a6c4974ec71e760773a711732648f

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

LOG: [OpenCL] Add OpenCL 3.0 atomics to -fdeclare-opencl-builtins

Add the atomic overloads for the `global` and `local` address spaces,
which are new in OpenCL 3.0.  Ensure the preexisting `generic`
overloads are guarded by the generic address space feature macro.

Ensure a subset of the atomic builtins are guarded by the
`__opencl_c_atomic_order_seq_cst` and `__opencl_c_atomic_scope_device`
feature macros, and enable those macros for SPIR/SPIR-V targets in
`opencl-c-base.h`.

Also guard the `cl_ext_float_atomics` builtins with the atomic order
and scope feature macros.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index ad276dc0f6aae..5191c41bcd057 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -67,6 +67,8 @@
 #if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 // For the SPIR and SPIR-V target all features are supported.
 #if defined(__SPIR__) || defined(__SPIRV__)
+#define __opencl_c_atomic_order_seq_cst 1
+#define __opencl_c_atomic_scope_device 1
 #define __opencl_c_atomic_scope_all_devices 1
 #define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 4d36df352d5ec..ab30553005729 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -57,6 +57,23 @@ class FunctionExtension : 
AbstractExtension<_Ext>;
 // disabled.
 class TypeExtension : AbstractExtension<_Ext>;
 
+// Concatenate zero or more space-separated extensions in NewExts to Base and
+// return the resulting FunctionExtension in ret.
+class concatExtension {
+  FunctionExtension ret = FunctionExtension<
+!cond(
+  // Return Base extension if NewExts is empty,
+  !empty(NewExts) : Base.ExtName,
+
+  // otherwise, return NewExts if Base extension is empty,
+  !empty(Base.ExtName) : NewExts,
+
+  // otherwise, concatenate NewExts to Base.
+  true : Base.ExtName # " " # NewExts
+)
+  >;
+}
+
 // TypeExtension definitions.
 def NoTypeExt   : TypeExtension<"">;
 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
@@ -1043,40 +1060,57 @@ let Extension = FuncExtOpenCLCxx in {
 // OpenCL v2.0 s6.13.11 - Atomic Functions.
 
 // An atomic builtin with 2 additional _explicit variants.
-multiclass BuiltinAtomicExplicit Types> {
+multiclass BuiltinAtomicExplicit Types, 
FunctionExtension BaseExt> {
   // Without explicit MemoryOrder or MemoryScope.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With an explicit MemoryOrder argument.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With explicit MemoryOrder and MemoryScope arguments.
-  def : Builtin;
+  let Extension = BaseExt in {
+def : Builtin;
+  }
 }
 
 // OpenCL 2.0 atomic functions that have a pointer argument in a given address 
space.
-multiclass OpenCL2Atomics {
+multiclass OpenCL2Atomics {
   foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
   [AtomicLong, Long], [AtomicULong, ULong],
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
 def : Builtin<"atomic_init",
 [Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_store",
-[Void, PointerType, addrspace>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]], BaseExt>;
 defm : BuiltinAtomicExplicit<"atomic_load",
-[TypePair[1], PointerType, addrspace>]>;
+[TypePair[1], PointerType, addrspace>], 
BaseExt>;
 defm : BuiltinAtomicExplicit<"atomic_exchange",
-[TypePair[1], PointerType, addrspace>, 
TypePair[1]]>;
+[TypePair[1], PointerType, addrspace>, 
TypePair[1]], BaseExt>;
 foreach Variant = ["weak", "strong"] in {
-  def : Builtin<"atomic_compare_exchange_" # Variant,
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1]]>;
-  def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
-  def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
+ 

[PATCH] D119420: [OpenCL] Add OpenCL 3.0 atomics to -fdeclare-opencl-builtins

2022-02-11 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50f8abb9f40a: [OpenCL] Add OpenCL 3.0 atomics to 
-fdeclare-opencl-builtins (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D119420?vs=407432&id=407813#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119420

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -9,6 +9,7 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++2021 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -cl-ext=-cl_khr_fp64 -DNO_FP64
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header -DNO_ATOMSCOPE
 
 // Test the -fdeclare-opencl-builtins option.  This is not a completeness
 // test, so it should not test for all builtins defined by OpenCL.  Instead
@@ -80,6 +81,11 @@
 #define __opencl_c_read_write_images 1
 #endif
 
+#if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
+#define __opencl_c_atomic_order_seq_cst 1
+#define __opencl_c_atomic_scope_device 1
+#endif
+
 #define __opencl_c_named_address_space_builtins 1
 #endif
 
@@ -98,6 +104,7 @@
 #if !defined(NO_HEADER) && (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 kernel void test_enum_args(volatile global atomic_int *global_p, global int *expected) {
   int desired;
+  atomic_work_item_fence(CLK_GLOBAL_MEM_FENCE, memory_order_acq_rel, memory_scope_device);
   atomic_compare_exchange_strong_explicit(global_p, expected, desired,
   memory_order_acq_rel,
   memory_order_relaxed,
@@ -156,6 +163,27 @@
 }
 #endif // !defined(NO_HEADER) && __OPENCL_C_VERSION__ >= 200
 
+#if defined(NO_ATOMSCOPE) && __OPENCL_C_VERSION__ >= 300
+// Disable the feature by undefining the feature macro.
+#undef __opencl_c_atomic_scope_device
+
+// Test that only the overload with explicit order and scope arguments is
+// available when the __opencl_c_atomic_scope_device feature is disabled.
+void test_atomics_without_scope_device(volatile __generic atomic_int *a_int) {
+  int d;
+
+  atomic_exchange(a_int, d);
+  // expected-error@-1{{implicit declaration of function 'atomic_exchange' is invalid in OpenCL}}
+
+  atomic_exchange_explicit(a_int, d, memory_order_seq_cst);
+  // expected-error@-1{{no matching function for call to 'atomic_exchange_explicit'}}
+  // expected-note@-2 + {{candidate function not viable}}
+
+  atomic_exchange_explicit(a_int, d, memory_order_seq_cst, memory_scope_work_group);
+}
+
+#endif
+
 // Test old atomic overloaded with generic address space in C++ for OpenCL.
 #if __OPENCL_C_VERSION__ >= 200
 void test_legacy_atomics_cpp(__generic volatile unsigned int *a) {
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -57,6 +57,23 @@
 // disabled.
 class TypeExtension : AbstractExtension<_Ext>;
 
+// Concatenate zero or more space-separated extensions in NewExts to Base and
+// return the resulting FunctionExtension in ret.
+class concatExtension {
+  FunctionExtension ret = FunctionExtension<
+!cond(
+  // Return Base extension if NewExts is empty,
+  !empty(NewExts) : Base.ExtName,
+
+  // otherwise, return NewExts if Base extension is empty,
+  !empty(Base.ExtName) : NewExts,
+
+  // otherwise, concatenate NewExts to Base.
+  true : Base.ExtName # " " # NewExts
+)
+  >;
+}
+
 // TypeExtension definitions.
 def NoTypeExt   : TypeExtension<"">;
 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
@@ -1043,40 +1060,57 @@
 // OpenCL v2.0 s6.13.11 - Atomic Functions.
 
 // An atomic builtin with 2 additional _explicit variants.
-multiclass BuiltinAtomicExplicit Types> {
+multiclass BuiltinAtomicExplicit Types, FunctionExtension BaseExt> {
   // Without explicit MemoryOrder or MemoryScope.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With an explicit MemoryOrder argument.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With explicit MemoryOrder and MemoryScope 

[PATCH] D116155: [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-11 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Well, I've just recognized that the "Build Status" of this latest diff shows 
that it crashes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116155

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2022-02-11 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely marked 14 inline comments as done and an inline comment as not done.
futogergely added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:41-42
+
+  // Matching the `gets` deprecated function without replacement.
+  auto DeprecatedFunctionNamesMatcher = hasAnyName("::gets");
+

whisperity wrote:
> whisperity wrote:
> > futogergely wrote:
> > > aaron.ballman wrote:
> > > > This comment is not accurate. `gets_s()` is a secure replacement for 
> > > > `gets()`.
> > > If gets is removed from C11, and gets_s is introduced in C11, then gets_s 
> > > cannot be a replacement or? Maybe fgets?
> > > 
> > > Also I was wondering if we would like to disable this check for C99, 
> > > maybe we should remove the check for gets all together.
> > Yes, it's strange territory. If I make my code safer but //stay// pre-C11, 
> > I actually can't, because the new function isn't there yet. If I also 
> > //upgrade// then I'll **have to** make my code "safer", because the old 
> > function is now missing...
> > 
> > Given how brutally dangerous `gets` is (you very rarely see a documentation 
> > page just going **`Never use gets()!`**), I would suggest keeping at least 
> > the warning.
> > 
> > Although even the CERT rule mentions `gets_s()`. We could have some wiggle 
> > room here: do the warning for `gets()`, and suggest two alternatives: 
> > `fgets()`, or `gets_s()` + Annex K? `fgets(stdin, ...)` is also safe, if 
> > the buffer's size is given appropriately.
> CERT mentions C99 TC3, which //seems to be// available here: 
> https://webstore.iec.ch/p-corrigenda/isoiec9899-cor3%7Bed2.0%7Den.pdf . I'm 
> not sure how normative this source is (`iec.ch` seems legit to me that this 
> isn't just a random WGML draft!), and on page 8, in point 46 it says: //"Add 
> new paragraph after paragraph 1: The `gets` function is obsolescent, and is 
> deprecated."//.
> 
> This seems like nitpicking, but maybe CppReference is outdated as it never 
> indicated the "deprecation" period?
> 
> (FYI: http://www.iso.org/standard/50510.html does not offer any purchase of 
> the older version of the standard, or this errata.)
I don't use 'deprecated' in the warning message, I issue 'is insecure, and it 
is removed from C11' for gets instead.

I added the following replacement suggestions for gets: gets_s if Annex K is 
available, fgets if Annex K is not available.



Comment at: 
clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:49-59
+  "::asctime", "::bsearch", "::ctime", "::fopen", "::fprintf", "::freopen",
+  "::fscanf", "::fwprintf", "::fwscanf", "::getenv", "::gmtime",
+  "::localtime", "::mbsrtowcs", "::mbstowcs", "::memcpy", "::memmove",
+  "::printf", "::qsort", "::snprintf", "::sprintf", "::sscanf", "::strcat",
+  "::strcpy", "::strerror", "::strncat", "::strncpy", "::strtok",
+  "::swprintf", "::swscanf", "::vfprintf", "::vfscanf", "::vfwprintf",
+  "::vfwscanf", "::vprintf", "::vscanf", "::vsnprintf", "::vsprintf",

futogergely wrote:
> aaron.ballman wrote:
> > This list appears to be missing quite a few functions with secure 
> > replacements in Annex K. For example: `tmpfile_s`, `tmpnam_s`, 
> > `strerrorlen_s`, `strlen_s`... can you check the list against the actual 
> > Annex K, as it seems the CERT recommendation is still out of date.
> Missing functions added: tmpfile/tmpfile_s, tmpnam/tmpnam_s, memset/memset_s, 
> scanf, strlen, wcslen
strlen/strnlen_s, wcslen/wcsnlen_s, memset/memset_s, scanf/scanf_s has been 
added.

I did not add tmpfile/tmpfile_s, tmpnam/tmpnam_s because there is a separate 
CERT rule for it: 
https://wiki.sei.cmu.edu/confluence/display/c/FIO21-C.+Do+not+create+temporary+files+in+shared+directories.


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

https://reviews.llvm.org/D91000

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


[clang] 9ece72c - [clang] VisitCastExpr - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

2022-02-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-11T10:51:34Z
New Revision: 9ece72c159720d1c771249f5a565f6ca39a31ae3

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

LOG: [clang] VisitCastExpr - use cast<> instead of dyn_cast<> to avoid 
dereference of nullptr

The pointer is always dereferenced, so assert the cast is correct (which it 
should be as we just created that ScalableVectorType) instead of returning 
nullptr

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 705e50b58324..59d0bd08d33d 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2093,7 +2093,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 if (ScalableDst == PredType &&
 FixedSrc->getElementType() == Builder.getInt8Ty()) {
   DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
-  ScalableDst = dyn_cast(DstTy);
+  ScalableDst = cast(DstTy);
   NeedsBitCast = true;
 }
 if (FixedSrc->getElementType() == ScalableDst->getElementType()) {
@@ -2119,7 +2119,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 if (ScalableSrc == PredType &&
 FixedDst->getElementType() == Builder.getInt8Ty()) {
   SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
-  ScalableSrc = dyn_cast(SrcTy);
+  ScalableSrc = cast(SrcTy);
   Src = Builder.CreateBitCast(Src, SrcTy);
 }
 if (ScalableSrc->getElementType() == FixedDst->getElementType()) {



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


[PATCH] D116155: [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 407822.
balazske added a comment.

Fix of test failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116155

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6809,7 +6809,8 @@
  bool MinimalImport,
  const std::shared_ptr &SharedState) {
   return new ASTImporter(ToContext, ToFileManager, FromContext,
- FromFileManager, MinimalImport,
+ // Use minimal import for these tests.
+ FromFileManager, /*MinimalImport=*/true,
  // We use the regular lookup.
  /*SharedState=*/nullptr);
 };
@@ -7475,6 +7476,57 @@
 ToDGOther);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExpr) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct A {
+int idx;
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout can be obtained without
+  // crash.
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExprDifferentRecord) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct B;
+  struct A {
+int idx;
+B *b;
+  };
+  struct B {
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout (of 'A') can be obtained
+  // without crash. It is not possible to have all of the fields of 'A' imported
+  // at that time (without big code changes).
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2012,6 +2012,14 @@
   }
 
   To->startDefinition();
+  // Set the definition to complete even if it is really not complete during
+  // import. Some AST constructs (expressions) require the record layout
+  // to be calculated (see 'clang::computeDependence') at the time they are
+  // constructed. Import of such AST node is possible during import of the
+  // same record, there is no way to have a completely defined record (all
+  // fields imported) at that time without multiple AST import passes.
+  if (!Importer.isMinimalImport())
+To->setCompleteDefinition(true);
   // Complete the definition even if error is returned.
   // The RecordDecl may be already part of the AST so it is better to
   // have it in complete state even if something is wrong with it.
@@ -2076,9 +2084,10 @@
   ToCXX->setBases(Bases.data(), Bases.size());
   }
 
-  if (shouldForceImportDeclContext(Kind))
+  if (shouldForceImportDeclContext(Kind)) {
 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
   return Err;
+  }
 
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 326cb51 - [clang-format] Simplify conditions in spaceRequiredBetween. NFC.

2022-02-11 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-11T12:01:24+01:00
New Revision: 326cb51b147a1de17ba0157c41c37243d3cbc0ff

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

LOG: [clang-format] Simplify conditions in spaceRequiredBetween. NFC.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 28b244b9c59f1..ef4ce3483fcff 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3093,14 +3093,15 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 Right.Next->is(TT_RangeBasedForLoopColon))
   return getTokenPointerOrReferenceAlignment(Left) !=
  FormatStyle::PAS_Right;
-return !Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
-  tok::l_paren) &&
-   (getTokenPointerOrReferenceAlignment(Left) !=
-FormatStyle::PAS_Right &&
-!Line.IsMultiVariableDeclStmt) &&
-   Left.Previous &&
-   !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
-   tok::l_square);
+if (Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
+  tok::l_paren))
+  return false;
+if (getTokenPointerOrReferenceAlignment(Left) == FormatStyle::PAS_Right)
+  return false;
+if (Line.IsMultiVariableDeclStmt)
+  return false;
+return Left.Previous && !Left.Previous->isOneOf(
+tok::l_paren, tok::coloncolon, tok::l_square);
   }
   // Ensure right pointer alignment with ellipsis e.g. int *...P
   if (Left.is(tok::ellipsis) && Left.Previous &&



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


[clang] fd16eee - [clang-format] Assert default style instead of commenting. NFC.

2022-02-11 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-11T12:01:25+01:00
New Revision: fd16eeea9d16150e35cadae1d77cee831b8cf510

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

LOG: [clang-format] Assert default style instead of commenting. NFC.

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index aa50d73499d0..06b2fe5c650c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1975,9 +1975,8 @@ TEST_F(FormatTest, ElseIf) {
 
 TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   FormatStyle Style = getLLVMStyle();
-  // Check first the default LLVM style
-  // Style.PointerAlignment = FormatStyle::PAS_Right;
-  // Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  EXPECT_EQ(Style.PointerAlignment, FormatStyle::PAS_Right);
+  EXPECT_EQ(Style.ReferenceAlignment, FormatStyle::RAS_Pointer);
   verifyFormat("int *f1(int *a, int &b, int &&c);", Style);
   verifyFormat("int &f2(int &&c, int *a, int &b);", Style);
   verifyFormat("int &&f3(int &b, int &&c, int *a);", Style);



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


[PATCH] D91000: [clang-tidy] Add cert-msc24-msc33-c checker.

2022-02-11 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely updated this revision to Diff 407819.
futogergely marked an inline comment as done.
futogergely retitled this revision from "[clang-tidy] Add cert-msc24-c 
checker." to "[clang-tidy] Add cert-msc24-msc33-c checker.".
futogergely edited the summary of this revision.
futogergely added a comment.

I changed the class name: ObsolescentFunctionsCheck->UnsafeFunctionsCheck.
Since MSC33-C is also included, I changed the checker name to 
cert-msc24-msc33-c.
I added the following functions from CheckSecuritySyntaxOnly under option 
'ReportMoreUnsafeFunctions': bcmp, bcopy, bzero, getpw, vfork. Since there is a 
replacement suggested there, I added the replacement suggestions also.
I did not add tmpnam, tmpfile, mktemp, mkstemp, rand..() to the checker, 
because there are separate CERT rules for these.


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

https://reviews.llvm.org/D91000

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/UnsafeFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/cert/UnsafeFunctionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-msc24-msc33-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-msc24-msc33-c.c

Index: clang-tools-extra/test/clang-tidy/checkers/cert-msc24-msc33-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-msc24-msc33-c.c
@@ -0,0 +1,153 @@
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K%s cert-msc24-msc33-c %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-msc33-c %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-msc33-c %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-msc33-c %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K-CERT-ONLY  %s cert-msc24-msc33-c %t -- \
+// RUN:   -config="{CheckOptions: [{key: cert-msc24-msc33-c.ReportMoreUnsafeFunctions, value: false}]}" \
+// RUN: -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+
+typedef __SIZE_TYPE__ size_t;
+typedef char wchar_t;
+
+char *gets(char *s);
+size_t strlen(const char *s);
+size_t wcslen(const wchar_t *s);
+
+void f1(char *s) {
+  gets(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'gets_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'gets_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:3: warning: function 'gets' is insecure, and it is removed from C11; 'fgets' should be used instead
+
+  strlen(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'strlen' is not bounds-checking; 'strnlen_s' should be used instead
+  // no-warning WITHOUT-ANNEX-K
+
+  wcslen(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'wcslen' is not bounds-checking; 'wcsnlen_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'wcslen' is not bounds-checking; 'wcsnlen_s' should be used instead
+  // no-warning WITHOUT-ANNEX-K
+}
+
+struct tm;
+char *asctime(const struct tm *timeptr);
+
+void f2(const struct tm *timeptr) {
+  asctime(timeptr);
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:3: warning: function 'asctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
+
+  char *(*f_ptr1)(const struct tm *) = asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K:   :[[@LINE-1]]:40: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:40: warning: function 'asctime' is not bounds-checking and non-reentrant; 'asctime_s' should be used instead
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K::[[@LINE-3]]:40: warning: function 'asctime' is not bounds-checking and n

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 407823.
azabaznov added a comment.

Rename language mode for device side enqueue builtins; add the comment that 
device side enqueue builtins are not supported until OpenCL 2.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: nridge.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This makes hover/go-to-definition/expand-auto etc work for auto params in many
common cases.
This includes when a generic lambda is passed to a function accepting
std::function. (The tests don't use this case, it requires a lot of setup).

Note that this doesn't affect the AST of the function body itself, cause its
nodes not to be dependent, improve code completion etc.
(These sort of improvements seem possible, in a similar "if there's a single
instantiation, traverse it instead of the primary template" way).

Fixes https://github.com/clangd/clangd/issues/493
Fixes https://github.com/clangd/clangd/issues/1015


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119537

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -80,8 +80,16 @@
   EXPECT_THAT(apply("template  void x() { ^auto y = T::z(); }"),
   StartsWith("fail: Could not deduce type for 'auto' type"));
 
-  ExtraArgs.push_back("-std=c++17");
+  ExtraArgs.push_back("-std=c++20");
   EXPECT_UNAVAILABLE("template  class Y;");
+
+  EXPECT_THAT(apply("auto X = [](^auto){};"),
+  StartsWith("fail: Could not deduce"));
+  EXPECT_EQ(apply("auto X = [](^auto){return 0;}; int Y = X(42);"),
+"auto X = [](int){return 0;}; int Y = X(42);");
+  // FIXME: should work on constrained auto params, once SourceRange is fixed.
+  EXPECT_UNAVAILABLE("template concept C = true;"
+ "auto X = [](C ^auto *){return 0;};");
 }
 
 } // namespace
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -815,6 +815,12 @@
 }
   )cpp",
 
+  R"cpp(// auto lambda param where there's a single instantiation
+struct [[Bar]] {};
+auto Lambda = [](^auto){ return 0; };
+int x = Lambda(Bar{});
+  )cpp",
+
   R"cpp(// decltype(auto) in function return
 struct [[Bar]] {};
 ^decltype(auto) test() {
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -179,20 +179,76 @@
   )cpp",
   "Bar",
   },
+  {
+  R"cpp(
+// Generic lambda param.
+struct Foo{};
+auto Generic = [](^auto x) { return 0; };
+int m = Generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, matching deduction.
+struct Foo{};
+using Bar = Foo;
+auto Generic = [](^auto x, auto y) { return 0; };
+int m = Generic(Bar{}, "one");
+int n = Generic(Foo{}, 2);
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, conflicting deduction.
+struct Foo{};
+auto Generic = [](^auto y) { return 0; };
+int m = Generic("one");
+int n = Generic(2);
+  )cpp",
+  nullptr,
+  },
+  {
+  R"cpp(
+// Generic function param.
+struct Foo{};
+int generic(^auto x) { return 0; }
+int m = generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// More complicated param type involving auto.
+template  concept C = true;
+struct Foo{};
+int generic(C ^auto *x) { return 0; }
+const Foo *Ptr = nullptr;
+int m = generic(Ptr);
+  )cpp",
+  "const struct Foo",
+  },
   };
   for (Test T : Tests) {
 Annotations File(T.AnnotatedCode);
-auto AST = TestTU::withCode(File.code()).build();
+auto TU = TestTU::withCode(File.code());
+TU.ExtraArgs.push_back("-std=c++20");
+auto AST = TU.build();
 SourceManagerForFile SM("foo.cpp", File.code());
 
-SCOPED_TRACE(File.code());
+SCOPED_TRACE(T.AnnotatedCode);
 EXPECT_FALSE(File.points

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> There are tests checking for this (e.g. clang/test/Frontend/opencl.cl), so we 
> need this check to preserve the existing behavior indeed.

Thanks. The other test is `SemaOpenCL/clang-builtin-version.cl`.

> But it might be worth asking someone outside of the OpenCL community whether 
> it's desirable to use the LanguageID enum in this way.

I personally think this looks good now, for OpenCL in particularly, as it 
became version-agnostic (except for DSE). But we still are querying language 
options only, and we expect language options for generic AS, pipes and DSE to 
be immutable at this point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

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


[clang] 87c32be - [clang][dataflow] Include terminator statements in buildStmtToBasicBlockMap

2022-02-11 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-02-11T11:15:29Z
New Revision: 87c32be023d293e159e699bf46c821fe931cc223

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

LOG: [clang][dataflow] Include terminator statements in buildStmtToBasicBlockMap

This will be necessary later when we add support for evaluating logic
expressions such as && and ||.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 3ad2ed640cc1c..c0b8119038f2d 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -38,6 +38,8 @@ buildStmtToBasicBlockMap(const CFG &Cfg) {
 
   StmtToBlock[Stmt.getValue().getStmt()] = Block;
 }
+if (const Stmt *TerminatorStmt = Block->getTerminatorStmt())
+  StmtToBlock[TerminatorStmt] = Block;
   }
   return StmtToBlock;
 }



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


[PATCH] D119447: [clang][dataflow] Include terminator statements in buildStmtToBasicBlockMap

2022-02-11 Thread Stanislav Gatev 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 rG87c32be023d2: [clang][dataflow] Include terminator 
statements in buildStmtToBasicBlockMap (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119447

Files:
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -38,6 +38,8 @@
 
   StmtToBlock[Stmt.getValue().getStmt()] = Block;
 }
+if (const Stmt *TerminatorStmt = Block->getTerminatorStmt())
+  StmtToBlock[TerminatorStmt] = Block;
   }
   return StmtToBlock;
 }


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -38,6 +38,8 @@
 
   StmtToBlock[Stmt.getValue().getStmt()] = Block;
 }
+if (const Stmt *TerminatorStmt = Block->getTerminatorStmt())
+  StmtToBlock[TerminatorStmt] = Block;
   }
   return StmtToBlock;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119210: [RISCV] Recover the implication between Zve* extensions and the V extension.

2022-02-11 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD accepted this revision.
eopXD added a comment.
This revision is now accepted and ready to land.

LGTM.
For the record the implication in this patch correspond to the note under 
v-spec 
:

> As is the case with other RISC-V extensions, it is valid to include 
> overlapping extensions in the same ISA string. For example, RV64GCV and 
> RV64GCV_Zve64f are both valid and equivalent ISA strings, as is 
> RV64GCV_Zve64f_Zve32x_Zvl128b.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119210

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-msc33-c checker.

2022-02-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Now it would be better to have a checker called `UnsafeFunctionsCheck` 
(probably in bugprone) and add the cert checkers "msc24-c" and "msc33-c" as 
aliases. This makes the check extendable if more (CERT rule related or not) 
cases for unsafe functions are added.


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

https://reviews.llvm.org/D91000

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


[PATCH] D113336: [RISCV] Imply extensions in RISCVTargetInfo::initFeatureMap

2022-02-11 Thread JunMa via Phabricator via cfe-commits
junparser added a comment.
Herald added a subscriber: pcwang-thead.

@eopXD, hi, this patch make us lost +relax and  -save-restore  by default, 
would you please fix it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113336

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


[PATCH] D113336: [RISCV] Imply extensions in RISCVTargetInfo::initFeatureMap

2022-02-11 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD added a comment.

In D113336#3313909 , @junparser wrote:

> @eopXD, hi, this patch make us lost +relax and  -save-restore  by default, 
> would you please fix it?

Sure, let me look into it.
Do you have an existing test case for your situation? (Or I will make one while 
fixing)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113336

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


[PATCH] D119199: replace clang LLVM_ENABLE_PLUGINS -> CLANG_PLUGIN_SUPPORT in tests

2022-02-11 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

Hi. This commit seems to have broken the following cmake command, on Windows 
(with HEAD pointing at 76cad51ba700233d6e3492eddcbb466b6adbc2eb 
):

  cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON 
..\llvm-project\llvm

The symptom is the same as @cristian.adam shows above:

  -- SampleAnalyzerPlugin ignored -- Loadable modules not supported on this 
platform.
  CMake Error at [...]/llvm-project/clang/cmake/modules/AddClang.cmake:185 
(target_link_libraries):
Utility target "SampleAnalyzerPlugin" must not be used as the target of a
target_link_libraries call.
  Call Stack (most recent call first):

[...]/llvm-project/clang/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:8 
(clang_target_link_libraries)

With HEAD pointing at the previous commit, 
`clang/lib/Analysis/plugins/CMakeLists.txt` does not add the `SampleAnalyzer` 
subdirectory at all, because `LLVM_ENABLE_PLUGINS` has the value `OFF`. But 
`CLANG_PLUGIN_SUPPORT` is `ON`, so now it does, and the above error happens.

If I try to work around this by setting `CLANG_PLUGIN_SUPPORT` to `OFF` as well 
...

  cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON 
-DCLANG_PLUGIN_SUPPORT=OFF ..\llvm-project\llvm

... then this error happens instead:

  CMake Error at cmake/modules/AddLLVM.cmake:676 (target_link_libraries):
Target "clang" of type EXECUTABLE may not be linked into another target.
One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
executables with the ENABLE_EXPORTS property set.
  Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:808 (llvm_add_library)
[...]/llvm-project/clang/examples/PrintFunctionNames/CMakeLists.txt:12 
(add_llvm_library)

So, either way, the build fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119199

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


[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-isa features back after implication

2022-02-11 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: junparser, craig.topper, asb, frasercrmck.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, 
psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, simoncook, 
johnrusso, rbar.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Previously D113336  makes 
RISCVTargetInfo::initFeatureMap return the results
processed by RISCVISAInfo, which only consists of ISA features and misses
non-ISA features like `relax` and `save-restore`.

This patch fixes the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119541

Files:
  clang/lib/Basic/Targets/RISCV.cpp


Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.


Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D118605#3313859 , @azabaznov wrote:

>> There are tests checking for this (e.g. clang/test/Frontend/opencl.cl), so 
>> we need this check to preserve the existing behavior indeed.
>
> Thanks. The other test is `SemaOpenCL/clang-builtin-version.cl`.
>
>> But it might be worth asking someone outside of the OpenCL community whether 
>> it's desirable to use the LanguageID enum in this way.
>
> I personally think this looks good now, for OpenCL in particularly, as it 
> became version-agnostic (except for DSE). But we still are querying language 
> options only, and we expect language options for generic AS, pipes and DSE to 
> be immutable at this point.

Note that this `LanguageID` is intended for Builtins use because there are 
other `LanguageID`s used elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

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


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

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


[clang] bee4bd7 - [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via cfe-commits

Author: Anton Zabaznov
Date: 2022-02-11T15:53:44+03:00
New Revision: bee4bd70f76952b2c6296feb46a087b497322376

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

LOG: [OpenCL] Add support of language builtins for OpenCL C 3.0

OpenCL C 3.0 introduces optionality to some builtins, in particularly
to those which are conditionally supported with pipe, device enqueue
and generic address space features.

The idea is to conditionally support such builtins depending on the language 
options
being set for a certain feature. This allows users to define functions with 
names
of those optional builtins in OpenCL (as such names are not reserved).

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/Builtins.h
clang/lib/Basic/Builtins.cpp
clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
clang/test/CodeGenOpenCL/pipe_types.cl
clang/test/CodeGenOpenCL/to_addr_builtin.cl
clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
clang/test/SemaOpenCL/clang-builtin-version.cl
clang/test/SemaOpenCL/to_addr_builtin.cl

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 66c20e1c691de..62e82cd36321d 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1627,50 +1627,50 @@ LANGBUILTIN(__builtin_coro_suspend, "cIb", "n", 
COR_LANG)
 
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
-LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(write_pipe, "i.", "tn", OCLC20_LANG)
+LANGBUILTIN(read_pipe, "i.", "tn", OCL_PIPE)
+LANGBUILTIN(write_pipe, "i.", "tn", OCL_PIPE)
 
-LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC20_LANG)
+LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCL_PIPE)
+LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCL_PIPE)
 
-LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC20_LANG)
-LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC20_LANG)
+LANGBUILTIN(commit_write_pipe, "v.", "tn", OCL_PIPE)
+LANGBUILTIN(commit_read_pipe, "v.", "tn", OCL_PIPE)
 
-LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
+LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCL_PIPE)
+LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCL_PIPE)
 
-LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
-LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
+LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCL_PIPE)
+LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCL_PIPE)
 
-LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
+LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCL_PIPE)
+LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCL_PIPE)
 
-LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
-LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
+LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCL_PIPE)
+LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCL_PIPE)
 
-LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC20_LANG)
+LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCL_PIPE)
+LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCL_PIPE)
 
 // OpenCL v2.0 s6.13.17 - Enqueue kernel functions.
 // Custom builtin check allows to perform special check of passed block 
arguments.
-LANGBUILTIN(enqueue_kernel, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", 
OCLC20_LANG)
-LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", 
OCLC20_LANG)
-LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
+LANGBUILTIN(enqueue_kernel, "i.", "tn", OCL_DSE)
+LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCL_DSE)
+LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", 
OCL_DSE)
+LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", OCL_DSE)
+LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCL_DSE)
 
 // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
 // FIXME: Pointer parameters of OpenCL builtins should have their address space
 // requirement defined.
-LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
-LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
-LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
+LANGBUILTIN(to_global, "v*v*

[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbee4bd70f769: [OpenCL] Add support of language builtins for 
OpenCL C 3.0 (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/lib/Basic/Builtins.cpp
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/to_addr_builtin.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/clang-builtin-version.cl
  clang/test/SemaOpenCL/to_addr_builtin.cl

Index: clang/test/SemaOpenCL/to_addr_builtin.cl
===
--- clang/test/SemaOpenCL/to_addr_builtin.cl
+++ clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
 
 void test(void) {
   global int *glob;
@@ -11,7 +13,7 @@
   const_int_ty *con_typedef;
 
   glob = to_global(glob, loc);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
@@ -20,28 +22,28 @@
 
   int x;
   glob = to_global(x);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   loc = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
@@ -49,7 +51,7 @@
 #endif
 
   loc = to_private(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
 #else
@@ -58,17 +60,17 @@
 #endif
 
   loc = to_local(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
   // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *__private' from 'int'}}
   // expected-note@-4{{did you mean 'to_global'}}
-  // expected-note@13{{'to_global' declared here}}
+  // expected-note@15{{'to_global' declared here}}
 #else
   // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
 #endif
 
   priv = to_global(glob);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_

[PATCH] D117681: [RISCV] Add the policy operand for some masked RVV ternary IR intrinsics.

2022-02-11 Thread Zakk 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 rGd224be3b999a: [RISCV] Add the policy operand for some masked 
RVV ternary IR intrinsics. (authored by khchen).

Changed prior to commit:
  https://reviews.llvm.org/D117681?vs=403117&id=407849#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117681

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfwnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslidedown.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslideup.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwnmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfwnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslidedown.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslideup.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwmacc.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
  llvm/test/CodeGen/RISCV/rvv/vfmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfmadd.ll
  llvm/test/CodeGen/RISCV/rvv/vfmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfmsub.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmadd.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfnmsub.ll
  llvm/test/CodeGen/RISCV/rvv/vfwmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfwmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vfwnmacc.ll
  llvm/test/CodeGen/RISCV/rvv/vfwnmsac.ll
  llvm/test/CodeGen/RISCV/rvv/vmacc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmacc-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vmadd-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vmadd-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsac-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsac-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsub-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vnmsub-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vslidedown-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vslidedown-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vslideup-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vslideup-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmacc-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmacc-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccsu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccsu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccu-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccu-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccus-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vwmaccus-rv64.ll

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


[PATCH] D119351: Update all LLVM documentation mentioning runtimes in LLVM_ENABLE_PROJECTS

2022-02-11 Thread Arfrever Frehtes Taifersar Arahesis via Phabricator via cfe-commits
Arfrever added inline comments.



Comment at: llvm/docs/GettingStarted.rst:1225
 
+* -DLLVM_ENABLE_RUNTIMES
+   Set this equal to the runtimes you wish to compile (e.g. libcxx, libcxxabi, 
etc.)

One space is missing before `*`, so currently this part of this page is 
rendered incorrectly. See 
https://github.com/llvm/llvm-project/blob/main/llvm/docs/GettingStarted.rst 
(close to the end).

(When you fix it, please also backport fix to branch `release/14.x`.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119351

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


[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication

2022-02-11 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 407852.
eopXD added a comment.

Add testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119541

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Driver/riscv-default-features.c


Index: clang/test/Driver/riscv-default-features.c
===
--- /dev/null
+++ clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.


Index: clang/test/Driver/riscv-default-features.c
===
--- /dev/null
+++ clang/test/Driver/riscv-default-features.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV32
+
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+
+// Dummy function
+int foo(){
+  return  3;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -232,8 +232,16 @@
 return false;
   }
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU,
-(*ParseResult)->toFeatureVector());
+  // RISCVISAInfo makes implications for ISA features
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  // Add non-ISA features like `relax` and `save-restore` back
+  for (std::string Feature : FeaturesVec) {
+if (std::find(begin(ImpliedFeatures), end(ImpliedFeatures), Feature) ==
+end(ImpliedFeatures))
+  ImpliedFeatures.push_back(Feature);
+  }
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures);
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-11 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence marked an inline comment as done.
achieveartificialintelligence added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:557
+
+let RegInfos = RegInfoByHwMode<[RV64], [RegInfo<64, 64, 64>]> in
+def GPRPF64 : RegisterClass<"RISCV", [f64], 64, (add

Jim wrote:
> Is register pair only on RV32 for used as f64?
Yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 407856.
azabaznov added a comment.

Use existing diagnostics; add the comment that device can support extension but 
not the feature. Will follow up if we need explicit mention in the language 
spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118999

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= 
-cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -241,12 +241,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,15 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
+  // OpenCL device can support extension but not the feature as extension
+  // requires subgroup independent forward progress, but subgroup independent
+  // forward progress is optional in OpenCL C 3.0 __opencl_c_subgroups feature.
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+<< 1 << Call->getDirectCallee()
+<< "cl_khr_subgroups or __opencl_c_subgroups";
 return true;
   }
   return false;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -t

[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D119525#3313554 , @tbaeder wrote:

> This is a pretty big gotcha at best and I feel like `getArraySize()` should 
> return `None` in that case instead... thoughts?

I think it is a gotcha -- some places protect against a null pointer 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/TreeTransform.h#L11923
 and 
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L2138)
 while other places assume the pointer isn't null 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprCXX.cpp#L731
 and 
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L9431).
 So I think a better approach is to fix up the interface so it doesn't return 
nullptr rather than play whack-a-mole forever with the API (and fix up the 
places currently checking for nullptr explicitly).


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

https://reviews.llvm.org/D119525

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


[PATCH] D118605: [OpenCL] Add support of language builtins for OpenCL C 3.0

2022-02-11 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D118605#3313990 , @Anastasia wrote:

> In D118605#3313859 , @azabaznov 
> wrote:
>
>>> There are tests checking for this (e.g. clang/test/Frontend/opencl.cl), so 
>>> we need this check to preserve the existing behavior indeed.
>>
>> Thanks. The other test is `SemaOpenCL/clang-builtin-version.cl`.
>>
>>> But it might be worth asking someone outside of the OpenCL community 
>>> whether it's desirable to use the LanguageID enum in this way.
>>
>> I personally think this looks good now, for OpenCL in particularly, as it 
>> became version-agnostic (except for DSE). But we still are querying language 
>> options only, and we expect language options for generic AS, pipes and DSE 
>> to be immutable at this point.
>
> Note that this `LanguageID` is intended for Builtins use because there are 
> other `LanguageID`s used elsewhere.

Fair enough.  Just in case someone disagrees, there's always the option of 
giving the builtins a reserved name and providing a macro in `opencl-c-base.h` 
that maps the real name to the builtin, conditionalized on feature macros.  But 
macros have the drawback of less beautiful diagnostics, so if nobody objects we 
should keep what we have done currently I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118605

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/warn-literal-range.c:25
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}

I think we should probably have test coverage for `long double` as well, but I 
also wonder whether it makes sense to add coverage for the small floating-point 
types (like `_Float16`) as well, or whether we already have coverage for those 
elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D116155: [clang][AST][ASTImporter] Set record to complete during import of its members.

2022-02-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 407860.
balazske added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116155

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6809,7 +6809,8 @@
  bool MinimalImport,
  const std::shared_ptr &SharedState) {
   return new ASTImporter(ToContext, ToFileManager, FromContext,
- FromFileManager, MinimalImport,
+ // Use minimal import for these tests.
+ FromFileManager, /*MinimalImport=*/true,
  // We use the regular lookup.
  /*SharedState=*/nullptr);
 };
@@ -7475,6 +7476,57 @@
 ToDGOther);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExpr) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct A {
+int idx;
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout can be obtained without
+  // crash.
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecordWithLayoutRequestingExprDifferentRecord) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  struct B;
+  struct A {
+int idx;
+B *b;
+  };
+  struct B {
+static void foo(A x) {
+  (void)&"text"[x.idx];
+}
+  };
+  )",
+  Lang_CXX11);
+
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+
+  // Test that during import of 'foo' the record layout (of 'A') can be obtained
+  // without crash. It is not possible to have all of the fields of 'A' imported
+  // at that time (without big code changes).
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_TRUE(ToA->isCompleteDefinition());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2012,6 +2012,14 @@
   }
 
   To->startDefinition();
+  // Set the definition to complete even if it is really not complete during
+  // import. Some AST constructs (expressions) require the record layout
+  // to be calculated (see 'clang::computeDependence') at the time they are
+  // constructed. Import of such AST node is possible during import of the
+  // same record, there is no way to have a completely defined record (all
+  // fields imported) at that time without multiple AST import passes.
+  if (!Importer.isMinimalImport())
+To->setCompleteDefinition(true);
   // Complete the definition even if error is returned.
   // The RecordDecl may be already part of the AST so it is better to
   // have it in complete state even if something is wrong with it.
@@ -2076,9 +2084,10 @@
   ToCXX->setBases(Bases.data(), Bases.size());
   }
 
-  if (shouldForceImportDeclContext(Kind))
+  if (shouldForceImportDeclContext(Kind)) {
 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
   return Err;
+  }
 
   return Error::success();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119351: Update all LLVM documentation mentioning runtimes in LLVM_ENABLE_PROJECTS

2022-02-11 Thread Louis Dionne via Phabricator via cfe-commits
ldionne marked an inline comment as done.
ldionne added inline comments.



Comment at: llvm/docs/GettingStarted.rst:1225
 
+* -DLLVM_ENABLE_RUNTIMES
+   Set this equal to the runtimes you wish to compile (e.g. libcxx, libcxxabi, 
etc.)

Arfrever wrote:
> One space is missing before `*`, so currently this part of this page is 
> rendered incorrectly. See 
> https://github.com/llvm/llvm-project/blob/main/llvm/docs/GettingStarted.rst 
> (close to the end).
> 
> (When you fix it, please also backport fix to branch `release/14.x`.)
Thanks, good catch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119351

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


[clang] 23f2785 - [clang-format] Avoid multiple calls to FormatToken::getNextNonComment(). NFC.

2022-02-11 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-11T15:20:11+01:00
New Revision: 23f27850b1e00e66ba19fc844ad8f2bd70268536

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

LOG: [clang-format] Avoid multiple calls to FormatToken::getNextNonComment(). 
NFC.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 871194f93f20..93d409118128 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1221,10 +1221,17 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
   if (Current.is(TT_ArraySubscriptLSquare) &&
   State.Stack.back().StartOfArraySubscripts == 0)
 State.Stack.back().StartOfArraySubscripts = State.Column;
-  if (Current.is(TT_ConditionalExpr) && Current.is(tok::question) &&
-  ((Current.MustBreakBefore) ||
-   (Current.getNextNonComment() &&
-Current.getNextNonComment()->MustBreakBefore)))
+
+  auto IsWrappedConditional = [](const FormatToken &Tok) {
+if (!(Tok.is(TT_ConditionalExpr) && Tok.is(tok::question)))
+  return false;
+if (Tok.MustBreakBefore)
+  return true;
+
+const FormatToken *Next = Tok.getNextNonComment();
+return Next && Next->MustBreakBefore;
+  };
+  if (IsWrappedConditional(Current))
 State.Stack.back().IsWrappedConditional = true;
   if (Style.BreakBeforeTernaryOperators && Current.is(tok::question))
 State.Stack.back().QuestionColumn = State.Column;

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ef4ce3483fcf..70f92c26fa8d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3598,7 +3598,8 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
   if (Right.is(tok::colon)) {
 if (Line.First->isOneOf(tok::kw_default, tok::kw_case))
   return Style.SpaceBeforeCaseColon;
-if (!Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
+const FormatToken *Next = Right.getNextNonComment();
+if (!Next || Next->is(tok::semi))
   return false;
 if (Right.is(TT_ObjCMethodExpr))
   return false;

diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 9f49410f741a..88efda487eeb 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -700,9 +700,13 @@ class LineJoiner {
 
 if (Line.Last->is(tok::l_brace)) {
   FormatToken *Tok = I[1]->First;
-  if (Tok->is(tok::r_brace) && !Tok->MustBreakBefore &&
-  (Tok->getNextNonComment() == nullptr ||
-   Tok->getNextNonComment()->is(tok::semi))) {
+  auto ShouldMerge = [Tok]() {
+if (Tok->isNot(tok::r_brace) || Tok->MustBreakBefore)
+  return false;
+const FormatToken *Next = Tok->getNextNonComment();
+return !Next || Next->is(tok::semi);
+  };
+  if (ShouldMerge()) {
 // We merge empty blocks even if the line exceeds the column limit.
 Tok->SpacesRequiredBefore = Style.SpaceInEmptyBlock ? 1 : 0;
 Tok->CanBreakBefore = true;



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


[clang] 0104f5e - [clang-format] Mark FormatToken::getNextNonComment() nodiscard. NFC.

2022-02-11 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-11T15:20:11+01:00
New Revision: 0104f5efede22890c356810f992162a84cd615dd

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

LOG: [clang-format] Mark FormatToken::getNextNonComment() nodiscard. NFC.

Added: 


Modified: 
clang/lib/Format/FormatToken.h

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 6586ababd1e7b..4c03f436dde3e 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -687,7 +687,7 @@ struct FormatToken {
   }
 
   /// Returns the next token ignoring comments.
-  const FormatToken *getNextNonComment() const {
+  LLVM_NODISCARD const FormatToken *getNextNonComment() const {
 const FormatToken *Tok = Next;
 while (Tok && Tok->is(tok::comment))
   Tok = Tok->Next;



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


[PATCH] D119221: [clang][lexer] Allow u8 character literal prefixes in C2x

2022-02-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: tahonermann.
aaron.ballman added a comment.

Can you also add a release note for the new feature, and update the 
`clang/www/c_status.html` page as well?




Comment at: clang/test/Lexer/utf8-char-literal.cpp:23
+char f = u8'ab';// expected-error {{Unicode character literals may 
not contain multiple characters}}
+char g = u8'\x80';  // expected-warning {{implicit conversion from 
'int' to 'char' changes value from 128 to -128}}
 #endif

One more test I'd like to see added, just to make sure we're covering 6.4.4.4p9 
properly:
```
_Static_assert(
  _Generic(u8'a',
   default: 0,
   unsigned char : 1),
  "Surprise!");  
```
We expect the type of a u8 character literal to be `unsigned char` at the 
moment, which is different from a u8 string literal, which uses `char`.

However, WG14 is also going to be considering 
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm for C2x at our 
meeting next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119221

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


[PATCH] D118196: [syntax][pseudo] Implement LR parsing table.

2022-02-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 407862.
hokein marked 10 inline comments as done.
hokein added a comment.
Herald added a subscriber: mgrang.

- rebase, rescope the patch to LRTable
- refine the Action class interfaces, and nameing;
- use a more compact Index, reduce LRTable from 660KB => 335KB;
- address review comments;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118196

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
  clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h
  clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp
  clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
  clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
  clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp
  clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/unittests/Tooling/Syntax/Pseudo/LRGraphTest.cpp
  clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp

Index: clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp
@@ -0,0 +1,57 @@
+//===--- LRTableTest.cpp - ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Pseudo/LRTable.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Tooling/Syntax/Pseudo/Grammar.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace syntax {
+namespace pseudo {
+namespace {
+
+using testing::IsEmpty;
+using testing::UnorderedElementsAre;
+using Action = LRTable::Action;
+
+TEST(LRTable, Builder) {
+  LRTable::Builder Build;
+  GrammarTable GTable;
+  initTerminals(GTable.Terminals);
+
+  //   eof   semi  ...
+  // +---++---+---
+  // |state0 || s0,r0 |...
+  // |state1 | acc|   |...
+  // |state2 ||  r1   |...
+  // +---++---+---
+  Build.insert(/* State */ 0, tokenSymbol(tok::semi), Action::shift(0));
+  Build.insert(/* State */ 0, tokenSymbol(tok::semi), Action::reduce(0));
+  Build.insert(/* State */ 1, tokenSymbol(tok::eof), Action::accept());
+  Build.insert(/* State */ 2, tokenSymbol(tok::semi), Action::reduce(1));
+
+  LRTable T = std::move(Build).build(GTable);
+  EXPECT_THAT(T.find(0, tokenSymbol(tok::eof)), IsEmpty());
+  EXPECT_THAT(T.find(0, tokenSymbol(tok::semi)),
+  UnorderedElementsAre(Action::shift(0), Action::reduce(0)));
+  EXPECT_THAT(T.find(1, tokenSymbol(tok::eof)),
+  UnorderedElementsAre(Action::accept()));
+  EXPECT_THAT(T.find(1, tokenSymbol(tok::semi)), IsEmpty());
+  EXPECT_THAT(T.find(2, tokenSymbol(tok::semi)),
+  UnorderedElementsAre(Action::reduce(1)));
+  // Verify the behaivor for other non-available-actions terminals.
+  EXPECT_THAT(T.find(2, tokenSymbol(tok::kw_int)), IsEmpty());
+}
+
+} // namespace
+} // namespace pseudo
+} // namespace syntax
+} // namespace clang
Index: clang/unittests/Tooling/Syntax/Pseudo/LRGraphTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/LRGraphTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/LRGraphTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/Syntax/Pseudo/LRGraph.h"
+#include "clang/Tooling/Syntax/Pseudo/LRTable.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -20,14 +21,16 @@
   struct TestCase {
 llvm::StringRef BNF;
 llvm::StringRef ExpectedStates;
+llvm::StringRef ExpectedTables;
   };
 
-  TestCase Cases[] = {{
-  R"bnf(
+  TestCase Cases[] = {
+  {
+  R"bnf(
 _ := expr
 expr := IDENTIFIER
   )bnf",
-  R"(States:
+  R"(States:
 State 0
 _ :=  • expr
 expr :=  • IDENTIFIER
@@ -37,15 +40,25 @@
 expr := IDENTIFIER • 
 0 ->[expr] 1
 0 ->[IDENTIFIER] 2
-)"},
-  {// A grammar with a S/R conflict in SLR table:
-   // (id-id)-id, or id-(id-id).
-   R"bnf(
+)",
+  R"(LRTable:
+State 0
+'IDENTIFIER': shift state 2
+'expr': go to state 1
+State 1
+'EOF': accept
+State 2
+'EOF': reduce by rule 1 'expr := IDENTIFIER'
+)",
+  },
+  {// A grammar with a S/R conflict in SLR table:
+   // (id-id)-id, or id-(id-id).
+   R"bnf(
 _ := expr
 expr := expr - expr  # S/R conflict at state 4 on '-' token
 expr := IDENTIFIER
-  )bnf",
-   R"(States:
+ )bnf",
+   R"(States:
 State 0
 _ :=  • expr
 expr :=  â€

[PATCH] D118196: [syntax][pseudo] Implement LR parsing table.

2022-02-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:84
+
+Kind K = Kind::Error;
+// Value

sammccall wrote:
> This action struct can be squeezed to 16 bits.
> 
> Kind only needs 3 bits (I suspect it can be 2: Error and Accept aren't 
> heavily used).
> RuleID is 12 bits, StateID would fit within 11 and 12 should be safe.
> 
> Combined with the optimization suggested below, this should get the whole 
> table down to  335KB.
squeezed to 16 bits (3 bits for Kind, and 13 bits for the Value).



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:105
+auto Goto = find({From, NonTerminal});
+assert(Goto.size() == 1 && Goto.front().isGoTo());
+return Goto.front().goTo();

sammccall wrote:
> Why is this assertion valid? Is it a precondition of the function that some 
> item in From can advance over NonTerminal?
This is guaranteed by a DFA (a node can not have two out edges with a same 
label), the same reason why we don't have shift/shift conflicts. 



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:121
+private:
+  struct IndexKey {
+StateID From;

sammccall wrote:
> I think there's an even more compact representation:
> Basically sort the index keys as symbol-major, but then don't store the 
> actual symbol there but rather store the range for the symbol in an external 
> array:
> 
> ```
> // index is lookahead tok::TokenKind. Values are indices into Index: the 
> range for tok is StateIdx[TokenIdx[tok]...TokenIdx[tok+1]]
> vector TokenIdx;
> 
> // index is nonterminal SymbolID. Values are  indices into Index: the range 
> for sym is StateIdx[NontermIdx[sym]...NontermIdx[sym+1]].
> vector NontermIdx;
> 
> // parallel to actions, value is the from state. Only subranges are sorted.
> vector StateIdx;
> 
> vector Actions;
> ```
> 
> This should be 4 * (392 + 245) + (2 + 4) * 83k ~= 500k. And the one extra 
> indirection should save 5-10 steps of binary search.
> 
> This is equivalent to 2 * `vector` + `vector Action>>` but keeping the searched index compact is probably a good thing.
This looks like a nice improvement, though the implementation is a little 
tricky -- we reduced the binary-search space from 2 dimension (State, Symbol) 
to 1 dimension Symbol.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118196

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


[PATCH] D119040: Fix LookupTest where it was missing an assertion

2022-02-11 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a reviewer: kadircet.
probinson added a subscriber: kadircet.
probinson added a comment.

Ping; +@kadircet


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

https://reviews.llvm.org/D119040

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


[clang] 8fee667 - [pseudo] NFC, fix some typos.

2022-02-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-02-11T15:35:11+01:00
New Revision: 8fee667d31f6af9a8a6b44b120164fff4f65d198

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

LOG: [pseudo] NFC, fix some typos.

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h 
b/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
index c6e2f09d5fb47..a7ecfea902b6d 100644
--- a/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
+++ b/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
@@ -83,7 +83,7 @@ struct Rule {
 
   // We occupy 4 bits for the sequence, in theory, it can be at most 2^4 tokens
   // long, however, we're stricter in order to reduce the size, we limit the 
max
-  // lenth to 9 (this is the longest sequence in cxx grammar).
+  // length to 9 (this is the longest sequence in cxx grammar).
   static constexpr unsigned SizeBits = 4;
   static constexpr unsigned MaxElements = 9;
   static_assert(MaxElements <= (1 << SizeBits), "Exceeds the maximum limit");
@@ -167,7 +167,7 @@ struct GrammarTable {
   // The rules are sorted (and thus grouped) by target symbol.
   // RuleID is the index of the vector.
   std::vector Rules;
-  // A table of terminals (aka tokens). It correspond to the clang::Token.
+  // A table of terminals (aka tokens). It corresponds to the clang::Token.
   // clang::tok::TokenKind is the index of the table.
   std::vector Terminals;
   // A table of nonterminals, sorted by name.

diff  --git a/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h 
b/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h
index 8a4bdb76e49e8..1de15b79ee40f 100644
--- a/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h
+++ b/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h
@@ -18,7 +18,7 @@
 //
 //  LRGraph can be constructed for any context-free grammars.
 //  Even for a LR-ambiguous grammar, we can construct a deterministic FSA, but
-//  interpretation of the FSA is nondeterminsitic -- we might in a state where
+//  interpretation of the FSA is nondeterministic -- we might in a state where
 //  we can continue searching an handle and identify a handle (called
 //  shift/reduce conflicts), or identify more than one handle (callled
 //  reduce/reduce conflicts).
@@ -116,7 +116,7 @@ struct State {
 //
 // Intuitively, an LR automaton is a transition graph. The graph has a
 // collection of nodes, called States. Each state corresponds to a particular
-// item set, which represents a condition that could occur duing the process of
+// item set, which represents a condition that could occur during the process 
of
 // parsing a production. Edges are directed from one state to another. Each 
edge
 // is labeled by a grammar symbol (terminal or nonterminal).
 //



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


[PATCH] D112916: Confusable identifiers detection

2022-02-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: tahonermann, cor3ntin.
aaron.ballman added a comment.

Personally, I'm uncomfortable with this check because it's not really covering 
homoglyphs in general, it's covering homoglyphs outside of the usual Latin 
character set. For example, there's no attempt to catch other problematic 
homoglyph attack vectors like `1` vs `l` vs `I` or `O` vs `0`. The result is: 
this comes across feeling like it targets non-Latin character scripts as being 
dangerous but Latin character scripts are fine when that's not really accurate. 
That's not a path I feel comfortable walking down because it treats programmers 
differently depending on what their native language is (at least, as used 
within source code).

Adding some folks from the WG21 Unicode study group (SG16) as they may also 
have interesting input and advice.


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

https://reviews.llvm.org/D112916

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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118999

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread Bhramar Vatsa via Phabricator via cfe-commits
Bhramar.vatsa added a comment.

Sorry, but I can only add a bit more confusion: https://godbolt.org/z/dzYhhxbz4
There are two cases, only differing in terms of user-defined constructor.

Gcc and clang differs in the two cases. Gcc at least packs the second case 
(without user defined constructor), but clang doesn't.

Uncomment/define macro 'PROPS' to check that the type-traits indicate in both 
cases that it can be considered POD.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[clang] bfb1a33 - [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anton Zabaznov via cfe-commits

Author: Anton Zabaznov
Date: 2022-02-11T17:40:24+03:00
New Revision: bfb1a33bec7c88170b0809b8a7c9cb860e7cc19b

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

LOG: [OpenCL] Adjust diagnostic for subgroup support.

OpenCL C 3.0 __opencl_c_subgroups feature is slightly different
then other equivalent features and extensions (fp64 and 3d image writes):
OpenCL C 3.0 device can support the extension but not the feature.
cl_khr_subgroups requires subgroup independent forward progress.

This patch adjusts the check which is used when translating language
builtins to check either the extension or feature is supported.

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaOpenCL/cl20-device-side-enqueue.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index fe704792ce0b0..575181a6b61cb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,15 @@ static bool checkOpenCLBlockArgs(Sema &S, Expr 
*BlockArg) {
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
+  // OpenCL device can support extension but not the feature as extension
+  // requires subgroup independent forward progress, but subgroup independent
+  // forward progress is optional in OpenCL C 3.0 __opencl_c_subgroups feature.
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+<< 1 << Call->getDirectCallee()
+<< "cl_khr_subgroups or __opencl_c_subgroups";
 return true;
   }
   return false;

diff  --git a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl 
b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
index 9c375b2603ac1..344297ebbe0ca 100644
--- a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= 
-cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -241,12 +241,12 @@ kernel void bar(global unsigned int *buf)
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 #endif // ifdef cl_khr_subgroups



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


[PATCH] D118999: [OpenCL] Adjust diagnostic for subgroup support.

2022-02-11 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfb1a33bec7c: [OpenCL] Adjust diagnostic for subgroup 
support. (authored by azabaznov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118999

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= 
-cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -241,12 +241,12 @@
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups support}}
+  buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // 
expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' 
requires cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 
 kernel void bar1(global unsigned int *buf)
 {
   ndrange_t n;
-  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
+  buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups or __opencl_c_subgroups support}}
 }
 #endif // ifdef cl_khr_subgroups
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1042,9 +1042,15 @@
 }
 
 static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
-  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
+  // OpenCL device can support extension but not the feature as extension
+  // requires subgroup independent forward progress, but subgroup independent
+  // forward progress is optional in OpenCL C 3.0 __opencl_c_subgroups feature.
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts()) &&
+  !S.getOpenCLOptions().isSupported("__opencl_c_subgroups",
+S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
-<< 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+<< 1 << Call->getDirectCallee()
+<< "cl_khr_subgroups or __opencl_c_subgroups";
 return true;
   }
   return false;


Index: clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-o

[PATCH] D116261: [Clang][OpenMP] Add support for compare capture in parser

2022-02-11 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 407868.
tianshilei1992 added a comment.

fix errors


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116261

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -958,3 +958,16 @@
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
 }
+
+#ifdef OMP51
+int compare_capture() {
+  int a, b, c, x;
+// omp51-error@+1 {{atomic compare capture is not supported for now}}
+#pragma omp atomic compare capture
+  {
+x = a;
+if (a == b)
+  a = c;
+  }
+}
+#endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -35,6 +35,7 @@
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/PointerEmbeddedInt.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Frontend/OpenMP/OMPAssume.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
@@ -11315,14 +11316,18 @@
   SourceLocation AtomicKindLoc;
   OpenMPClauseKind MemOrderKind = OMPC_unknown;
   SourceLocation MemOrderLoc;
+  bool MutexClauseEncountered = false;
+  llvm::SmallSet EncounteredAtomicKinds;
   for (const OMPClause *C : Clauses) {
 switch (C->getClauseKind()) {
 case OMPC_read:
 case OMPC_write:
 case OMPC_update:
+  MutexClauseEncountered = true;
+  LLVM_FALLTHROUGH;
 case OMPC_capture:
 case OMPC_compare: {
-  if (AtomicKind != OMPC_unknown) {
+  if (AtomicKind != OMPC_unknown && MutexClauseEncountered) {
 Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses)
 << SourceRange(C->getBeginLoc(), C->getEndLoc());
 Diag(AtomicKindLoc, diag::note_omp_previous_mem_order_clause)
@@ -11330,6 +11335,7 @@
   } else {
 AtomicKind = C->getClauseKind();
 AtomicKindLoc = C->getBeginLoc();
+EncounteredAtomicKinds.insert(C->getClauseKind());
   }
   break;
 }
@@ -11357,6 +11363,12 @@
   llvm_unreachable("unknown clause is encountered");
 }
   }
+  bool IsCompareCapture = false;
+  if (EncounteredAtomicKinds.contains(OMPC_compare) &&
+  EncounteredAtomicKinds.contains(OMPC_capture)) {
+IsCompareCapture = true;
+AtomicKind = OMPC_compare;
+  }
   // OpenMP 5.0, 2.17.7 atomic Construct, Restrictions
   // If atomic-clause is read then memory-order-clause must not be acq_rel or
   // release.
@@ -11775,17 +11787,26 @@
 if (CurContext->isDependentContext())
   UE = V = E = X = nullptr;
   } else if (AtomicKind == OMPC_compare) {
-OpenMPAtomicCompareChecker::ErrorInfoTy ErrorInfo;
-OpenMPAtomicCompareChecker Checker(*this);
-if (!Checker.checkStmt(Body, ErrorInfo)) {
-  Diag(ErrorInfo.ErrorLoc, diag::err_omp_atomic_compare)
-  << ErrorInfo.ErrorRange;
-  Diag(ErrorInfo.NoteLoc, diag::note_omp_atomic_compare)
-  << ErrorInfo.Error << ErrorInfo.NoteRange;
-  return StmtError();
+if (IsCompareCapture) {
+  // TODO: For now we emit an error here and in emitOMPAtomicExpr we ignore
+  // code gen.
+  unsigned DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "atomic compare capture is not supported for now");
+  Diag(AtomicKindLoc, DiagID);
+} else {
+  OpenMPAtomicCompareChecker::ErrorInfoTy ErrorInfo;
+  OpenMPAtomicCompareChecker Checker(*this);
+  if (!Checker.checkStmt(Body, ErrorInfo)) {
+Diag(ErrorInfo.ErrorLoc, diag::err_omp_atomic_compare)
+<< ErrorInfo.ErrorRange;
+Diag(ErrorInfo.NoteLoc, diag::note_omp_atomic_compare)
+<< ErrorInfo.Error << ErrorInfo.NoteRange;
+return StmtError();
+  }
+  // TODO: We don't set X, D, E, etc. here because in code gen we will emit
+  // error directly.
 }
-// TODO: We don't set X, D, E, etc. here because in code gen we will emit
-// error directly.
   }
 
   setFunctionHasBranchProtectedScope();
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -24,6 +24,7 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/PrettyStackTrace.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
@@ -6015,7 +6016,7 @@
   llvm::AtomicOrdering AO, bool IsPostfixUpdate,
 

[clang] b2936ca - [clang] inheritance fix for nomerge attribute

2022-02-11 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-11T15:51:08+01:00
New Revision: b2936caf77e00fdb97814960eb1355c2a36c1e70

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

LOG: [clang] inheritance fix for nomerge attribute

Discussed here: https://reviews.llvm.org/D119061#3310822

Reviewed By: aaron.ballman

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

Added: 
clang/test/Sema/attr-nomerge-ast.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/stmt-attributes.c
clang/test/Parser/stmt-attributes.m
clang/test/Sema/attr-nomerge.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5156b6b5615b..8e8b7bc16e3b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1390,7 +1390,6 @@ def : MutualExclusions<[Likely, Unlikely]>;
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
-  let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
  "functions and statements">;
   let SimpleHandler = 1;

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 4f2977f89ce1..63c6fa391459 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -202,7 +202,7 @@ static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 
   if (!CEF.foundCallExpr()) {
 S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
-<< NMA.getSpelling();
+<< A;
 return nullptr;
   }
 

diff  --git a/clang/test/Parser/stmt-attributes.c 
b/clang/test/Parser/stmt-attributes.c
index 52061afd7bc1..86c9255fd47e 100644
--- a/clang/test/Parser/stmt-attributes.c
+++ b/clang/test/Parser/stmt-attributes.c
@@ -80,7 +80,7 @@ void foobar(void) {
   __attribute__((nomerge, unused)) bar(); // expected-error {{expected 
identifier or '('}}
   __attribute__((nomerge(1, 2))) bar();   // expected-error {{'nomerge' 
attribute takes no arguments}}
   int x;
-  __attribute__((nomerge)) x = 10; // expected-warning {{nomerge attribute is 
ignored because there exists no call expression inside the statement}}
+  __attribute__((nomerge)) x = 10; // expected-warning {{'nomerge' attribute 
is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) label : bar(); // expected-error {{'nomerge' 
attribute only applies to functions and statements}}
 }

diff  --git a/clang/test/Parser/stmt-attributes.m 
b/clang/test/Parser/stmt-attributes.m
index a138580d6717..227ea9dc2fac 100644
--- a/clang/test/Parser/stmt-attributes.m
+++ b/clang/test/Parser/stmt-attributes.m
@@ -29,13 +29,13 @@ - (void)bar {
   // expected-error@-3 {{expected identifier or '('}}
   // expected-note@-4 {{to match this '['}}
   __attribute__((nomerge)) [self foo];
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
   __attribute__((nomerge)) [getTest() foo];
 
   __attribute__(()) ^{};
   // expected-error@-1 {{expected identifier or '('}}
   __attribute__((nomerge)) ^{};
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
   __attribute__((nomerge)) ^{ [self foo]; }();
 
   __attribute__(()) @try {
@@ -49,9 +49,9 @@ - (void)bar {
   }
 
   __attribute__((nomerge)) (__bridge void *)self;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
 
   __attribute__((nomerge)) self.hasFoobar;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
 }
 @end

diff  --git a/clang/test/Sema/attr-nomerge-ast.cpp 
b/clang/test/Sema/attr-nomerge-ast.cpp
new file mode 100644
index ..c440cf760b16
--- /dev/null
+++ b/clang/test/Sema/attr-nomerge-ast.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+[[clang::nomerge]] void func();
+[[clang::nomerge]] void func();
+void func();
+[[clang::nomerge]] void func() {}
+
+// CHECK: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// 

[PATCH] D119451: [clang] inheritance fix for nomerge attribute

2022-02-11 Thread Dávid Bolvanský 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 rGb2936caf77e0: [clang] inheritance fix for nomerge attribute 
(authored by xbolva00).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119451

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/Parser/stmt-attributes.c
  clang/test/Parser/stmt-attributes.m
  clang/test/Sema/attr-nomerge-ast.cpp
  clang/test/Sema/attr-nomerge.cpp

Index: clang/test/Sema/attr-nomerge.cpp
===
--- clang/test/Sema/attr-nomerge.cpp
+++ clang/test/Sema/attr-nomerge.cpp
@@ -6,7 +6,7 @@
   [[clang::nomerge]] bar();
   [[clang::nomerge(1, 2)]] bar(); // expected-error {{'nomerge' attribute takes no arguments}}
   int x;
-  [[clang::nomerge]] x = 10; // expected-warning {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::nomerge]] x = 10; // expected-warning {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   [[clang::nomerge]] label: bar(); // expected-error {{'nomerge' attribute only applies to functions and statements}}
 
Index: clang/test/Sema/attr-nomerge-ast.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-nomerge-ast.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+[[clang::nomerge]] void func();
+[[clang::nomerge]] void func();
+void func();
+[[clang::nomerge]] void func() {}
+
+// CHECK: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr {{.*}} Inherited
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: NoMergeAttr
Index: clang/test/Parser/stmt-attributes.m
===
--- clang/test/Parser/stmt-attributes.m
+++ clang/test/Parser/stmt-attributes.m
@@ -29,13 +29,13 @@
   // expected-error@-3 {{expected identifier or '('}}
   // expected-note@-4 {{to match this '['}}
   __attribute__((nomerge)) [self foo];
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
   __attribute__((nomerge)) [getTest() foo];
 
   __attribute__(()) ^{};
   // expected-error@-1 {{expected identifier or '('}}
   __attribute__((nomerge)) ^{};
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
   __attribute__((nomerge)) ^{ [self foo]; }();
 
   __attribute__(()) @try {
@@ -49,9 +49,9 @@
   }
 
   __attribute__((nomerge)) (__bridge void *)self;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) self.hasFoobar;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 }
 @end
Index: clang/test/Parser/stmt-attributes.c
===
--- clang/test/Parser/stmt-attributes.c
+++ clang/test/Parser/stmt-attributes.c
@@ -80,7 +80,7 @@
   __attribute__((nomerge, unused)) bar(); // expected-error {{expected identifier or '('}}
   __attribute__((nomerge(1, 2))) bar();   // expected-error {{'nomerge' attribute takes no arguments}}
   int x;
-  __attribute__((nomerge)) x = 10; // expected-warning {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  __attribute__((nomerge)) x = 10; // expected-warning {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) label : bar(); // expected-error {{'nomerge' attribute only applies to functions and statements}}
 }
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -202,7 +202,7 @@
 
   if (!CEF.foundCallExpr()) {
 S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
-<< NMA.getS

[PATCH] D116261: [Clang][OpenMP] Add support for compare capture in parser

2022-02-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11790-11797
+if (IsCompareCapture) {
+  // TODO: For now we emit an error here and in emitOMPAtomicExpr we ignore
+  // code gen.
+  unsigned DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "atomic compare capture is not supported for now");
+  Diag(AtomicKindLoc, DiagID);

Better not to emit error here, if possible. What's prevent this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116261

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


[PATCH] D112916: Confusable identifiers detection

2022-02-11 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aaron.ballman Thanks for the ping.

One one hand, I agree with you, on the other hand, this tries to stick to TR39, 
and I think we should stick with that. It might be worth checking with the 
Unicode consortium what they think of i/l as confusable.

I think this is a rather good approach as a clang-tidy plugin (and we can gain 
experience from it to iterate).

I'm however rather concern that we are not following the spec in that there is 
no NFD decomposition happening (and I am aware this increases the workload a 
lot for the author).
But as it stands, composed characters may not be confusable even if the 
decomposed form would be, and the prescribed algorithm actually do 2 passed of 
decomposition, which is certainly necessary (I would need to think more about 
it)
The reasonable approach is certainly to stick to the algorithm to the letter, 
unless we have good motivation not to.




Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:35
+ * described in http://www.unicode.org/reports/tr39/#def-skeleton
+ */
+std::string Homoglyph::skeleton(StringRef Name) {

This does not seem to do NFD decomposition, so at the very least it is not 
consistent with TR39
Identifiers in C++ are mandated to be NFC.

This means that in the presence of composed characters ( for example digraphs 
), the algorithms will simply not work.



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:38
+  std::string SName = Name.str();
+  std::string Skeleton;
+  Skeleton.reserve(1 + Name.size());

It's probably more efficient to keep Skeleton as a sequence of char32_t, to 
avoid multiple round of conversions



Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:82
+
+void Homoglyph::check(const ast_matchers::MatchFinder::MatchResult &Result) {
+  if (const auto *ND = Result.Nodes.getNodeAs("nameddecl")) {

I think i like this idea of only complaining if there similar-looking 
identifiers


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

https://reviews.llvm.org/D112916

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


[clang] f162036 - [clang] RewriteModernObjC::SynthBlockInitExpr - remove block nullptr check

2022-02-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-11T15:09:44Z
New Revision: f162036fcd065d34a7f0e2c9279bc79bf7db0f14

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

LOG: [clang] RewriteModernObjC::SynthBlockInitExpr - remove block nullptr check

All paths have already dereferenced the block pointer

Added: 


Modified: 
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index b4487f0047155..1eb6b835e2d01 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -5356,16 +5356,15 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr 
*Exp,
   Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
   VK_LValue, SourceLocation());
   bool isNestedCapturedVar = false;
-  if (block)
-for (const auto &CI : block->captures()) {
-  const VarDecl *variable = CI.getVariable();
-  if (variable == ND && CI.isNested()) {
-assert (CI.isByRef() &&
-"SynthBlockInitExpr - captured block variable is not 
byref");
-isNestedCapturedVar = true;
-break;
-  }
+  for (const auto &CI : block->captures()) {
+const VarDecl *variable = CI.getVariable();
+if (variable == ND && CI.isNested()) {
+  assert(CI.isByRef() &&
+ "SynthBlockInitExpr - captured block variable is not byref");
+  isNestedCapturedVar = true;
+  break;
 }
+  }
   // captured nested byref variable has its address passed. Do not take
   // its address again.
   if (!isNestedCapturedVar)



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


[clang] 5fb1807 - [clang][sema] ActOnExplicitInstantiation - remove Prev nullptr check

2022-02-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-11T15:09:44Z
New Revision: 5fb180704c17dc66dfc7f052abe47524fdf8811f

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

LOG: [clang][sema] ActOnExplicitInstantiation - remove Prev nullptr check

All paths have already dereferenced the Prev pointer

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 64a0b45feb98..acaa5b294aa2 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -10116,7 +10116,7 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
 }
 
 // Check the new variable specialization against the parsed input.
-if (PrevTemplate && Prev && !Context.hasSameType(Prev->getType(), R)) {
+if (PrevTemplate && !Context.hasSameType(Prev->getType(), R)) {
   Diag(T->getTypeLoc().getBeginLoc(),
diag::err_invalid_var_template_spec_type)
   << 0 << PrevTemplate << R << Prev->getType();



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


[clang] 1e64590 - [clang][sema] - remove CodeCompleter nullptr checks

2022-02-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-11T15:09:44Z
New Revision: 1e6459004177c8f5830e1ea5a5a62820fa6a333f

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

LOG: [clang][sema] - remove CodeCompleter nullptr checks

All paths have already dereferenced the CodeCompleter pointer in the 
ResultBuilder constructor

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 01fdf51c60c3..0c9bcf546da7 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -9787,7 +9787,7 @@ void Sema::CodeCompletePreprocessorMacroName(bool 
IsDefinition) {
 CodeCompleter->getCodeCompletionTUInfo(),
 IsDefinition ? CodeCompletionContext::CCC_MacroName
  : 
CodeCompletionContext::CCC_MacroNameUse);
-  if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) {
+  if (!IsDefinition && CodeCompleter->includeMacros()) {
 // Add just the names of macros, not their arguments.
 CodeCompletionBuilder Builder(Results.getAllocator(),
   Results.getCodeCompletionTUInfo());
@@ -9814,9 +9814,8 @@ void Sema::CodeCompletePreprocessorExpression() {
 CodeCompleter->getCodeCompletionTUInfo(),
 CodeCompletionContext::CCC_PreprocessorExpression);
 
-  if (!CodeCompleter || CodeCompleter->includeMacros())
-AddMacroResults(PP, Results,
-!CodeCompleter || CodeCompleter->loadExternal(), true);
+  if (CodeCompleter->includeMacros())
+AddMacroResults(PP, Results, CodeCompleter->loadExternal(), true);
 
   // defined ()
   Results.EnterNewScope();



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


[PATCH] D119216: [AMDGPU] replace hostcall module flag with function attribute

2022-02-11 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

Attributor use looks good. @arsenm will need to look at the rest.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119216

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


[PATCH] D116261: [Clang][OpenMP] Add support for compare capture in parser

2022-02-11 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11790-11797
+if (IsCompareCapture) {
+  // TODO: For now we emit an error here and in emitOMPAtomicExpr we ignore
+  // code gen.
+  unsigned DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "atomic compare capture is not supported for now");
+  Diag(AtomicKindLoc, DiagID);

ABataev wrote:
> Better not to emit error here, if possible. What's prevent this?
I put it here because I think we don't have Sema support yet, so it is not good 
to move it to later phase like codegen because that will implicitly mean Sema 
has already passed but apparently it doesn't. Of course like atomic compare, 
I'll move it to codegen in the Sema patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116261

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


[PATCH] D116261: [Clang][OpenMP] Add support for compare capture in parser

2022-02-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Add ast print with serialization/deserialization tests.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:11320
+  bool MutexClauseEncountered = false;
+  llvm::SmallSet EncounteredAtomicKinds;
   for (const OMPClause *C : Clauses) {

SmallVector with 2 elements should be enough, no need to use SmallSet here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116261

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


[PATCH] D23934: Add a -ffixed-date-time= flag that sets the initial value of __DATE__, __TIME__, __TIMESTAMP__

2022-02-11 Thread Anmol P. Paralkar via Phabricator via cfe-commits
appcs added a comment.
Herald added a subscriber: dang.

Hello, Will this feature be committed? Thanks!


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

https://reviews.llvm.org/D23934

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


[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 407885.

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

https://reviews.llvm.org/D119525

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/issue53742.cpp

Index: clang/test/AST/issue53742.cpp
===
--- /dev/null
+++ clang/test/AST/issue53742.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+struct Data {
+  char *a;
+  char *b;
+  bool *c;
+};
+
+int main() {
+  Data in;
+  in.a = new char[](); // expected-error {{cannot determine allocated array size from initializer}}
+  in.c = new bool[100]();
+  in.b = new char[100]();
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -11918,9 +11918,9 @@
 
   // Transform the size of the array we're allocating (if any).
   Optional ArraySize;
-  if (Optional OldArraySize = E->getArraySize()) {
+  if (E->isArray()) {
 ExprResult NewArraySize;
-if (*OldArraySize) {
+if (Optional OldArraySize = E->getArraySize()) {
   NewArraySize = getDerived().TransformExpr(*OldArraySize);
   if (NewArraySize.isInvalid())
 return ExprError();
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -2132,10 +2132,10 @@
   if (E->isParenTypeId())
 OS << "(";
   std::string TypeS;
-  if (Optional Size = E->getArraySize()) {
+  if (E->isArray()) {
 llvm::raw_string_ostream s(TypeS);
 s << '[';
-if (*Size)
+if (Optional Size = E->getArraySize())
   (*Size)->printPretty(s, Helper, Policy);
 s << ']';
   }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9427,7 +9427,7 @@
   bool ValueInit = false;
 
   QualType AllocType = E->getAllocatedType();
-  if (Optional ArraySize = E->getArraySize()) {
+  if (Optional ArraySize = E->getArraySize()) {
 const Expr *Stripped = *ArraySize;
 for (; auto *ICE = dyn_cast(Stripped);
  Stripped = ICE->getSubExpr())
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -2261,15 +2261,32 @@
 
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
+  /// This might return None even if isArray() returns true,
+  /// since there might not be an array size expression.
+  /// If the result is not-None, it will never wrap a nullptr.
   Optional getArraySize() {
 if (!isArray())
   return None;
-return cast_or_null(getTrailingObjects()[arraySizeOffset()]);
+
+if (auto Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))
+  return Result;
+
+return None;
   }
+
+  /// This might return None even if isArray() returns true,
+  /// since there might not be an array size expression.
+  /// If the result is not-None, it will never wrap a nullptr.
   Optional getArraySize() const {
 if (!isArray())
   return None;
-return cast_or_null(getTrailingObjects()[arraySizeOffset()]);
+
+if (auto Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))
+  return Result;
+
+return None;
   }
 
   unsigned getNumPlacementArgs() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/StmtPrinter.cpp:2135
   std::string TypeS;
-  if (Optional Size = E->getArraySize()) {
+  if (E->isArray()) {
 llvm::raw_string_ostream s(TypeS);

I changed this just for clarity, not doing it did not cause any tests to fail. 
Not sure if this is tested at all.


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

https://reviews.llvm.org/D119525

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:508
+int ParamIndex = paramIndex(*FTD, *Auto.getDecl());
+if (ParamIndex < 0)
+  return true;

out of curiosity: when would this happen?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D117929: [XRay] Add support for RISCV

2022-02-11 Thread Ashwin Poduval via Phabricator via cfe-commits
ashwin98 added a comment.

In D117929#3299751 , @dberris wrote:

> In D117929#3276843 , @ashwin98 
> wrote:
>
>> Fixed another lint issue, they should all be done for now hopefully.
>>
>> @dberris Sorry, I'm a little confused, do you mean I need to update some of 
>> the clang tests for XRay instrumentation to test compilation and linking, or 
>> add new ones for the llvm-xray tool under llvm/test/tools?
>
> Yes to both. :)
>
> There are already some tests that ensure the supported triples build with 
> XRay instrumentation and that we can get the instrumentation map with the 
> tooling on binaries generated with clang+lld. Extending those to support 
> risc64 and ensure we're able to find the instrumentation with the tooling 
> gives us higher confidence that this will work when the patch is accepted.

Before running the tests, I've been testing some of the subcommands with the 
generated logs. When xray account or stack was run directly on the log file, 
the data for the instrumented functions was output (I believe the XRay tool 
recognizes it as a YAML file and processes it as such). However, when passing 
the --instr_map flag, issues crop up. I originally ran into an error about the 
executable not being an ELF binary. I confirmed that clang was generating ELF 
binaries. There was a test checking the triple architecture in 
InstrumentationMap.cpp that seemed to be causing this.

On including RISCV64 to the check, I see new issues while reading the 
instrumentation map. How do I verify that the instrumentation map is being 
generated correctly (or if there is a problem with it), and where is the code 
that is responsible for the generation of the instrumentation map (is it in 
xray_init.cpp)? I'm not sure if this is a RISCV compatibility issue with the 
xray tool, or if I've missed something while initializing the instrumentation 
map.


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

https://reviews.llvm.org/D117929

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:508
+int ParamIndex = paramIndex(*FTD, *Auto.getDecl());
+if (ParamIndex < 0)
+  return true;

avogelsgesang wrote:
> out of curiosity: when would this happen?
I think it probably can't happen.
In principle there may be several sets of implicit TTPs in scope (generic 
lambda nested in generic lambda) but `auto` would always refer to the 
immediately enclosing set.

Added an assert, but I lack the courage to make this `llvm_unreachable()` and 
crash horribly in production if I'm wrong :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 407891.
sammccall added a comment.

Assert on presumed-impossible case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -80,8 +80,16 @@
   EXPECT_THAT(apply("template  void x() { ^auto y = T::z(); }"),
   StartsWith("fail: Could not deduce type for 'auto' type"));
 
-  ExtraArgs.push_back("-std=c++17");
+  ExtraArgs.push_back("-std=c++20");
   EXPECT_UNAVAILABLE("template  class Y;");
+
+  EXPECT_THAT(apply("auto X = [](^auto){};"),
+  StartsWith("fail: Could not deduce"));
+  EXPECT_EQ(apply("auto X = [](^auto){return 0;}; int Y = X(42);"),
+"auto X = [](int){return 0;}; int Y = X(42);");
+  // FIXME: should work on constrained auto params, once SourceRange is fixed.
+  EXPECT_UNAVAILABLE("template concept C = true;"
+ "auto X = [](C ^auto *){return 0;};");
 }
 
 } // namespace
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -815,6 +815,12 @@
 }
   )cpp",
 
+  R"cpp(// auto lambda param where there's a single instantiation
+struct [[Bar]] {};
+auto Lambda = [](^auto){ return 0; };
+int x = Lambda(Bar{});
+  )cpp",
+
   R"cpp(// decltype(auto) in function return
 struct [[Bar]] {};
 ^decltype(auto) test() {
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -179,20 +179,76 @@
   )cpp",
   "Bar",
   },
+  {
+  R"cpp(
+// Generic lambda param.
+struct Foo{};
+auto Generic = [](^auto x) { return 0; };
+int m = Generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, matching deduction.
+struct Foo{};
+using Bar = Foo;
+auto Generic = [](^auto x, auto y) { return 0; };
+int m = Generic(Bar{}, "one");
+int n = Generic(Foo{}, 2);
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, conflicting deduction.
+struct Foo{};
+auto Generic = [](^auto y) { return 0; };
+int m = Generic("one");
+int n = Generic(2);
+  )cpp",
+  nullptr,
+  },
+  {
+  R"cpp(
+// Generic function param.
+struct Foo{};
+int generic(^auto x) { return 0; }
+int m = generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// More complicated param type involving auto.
+template  concept C = true;
+struct Foo{};
+int generic(C ^auto *x) { return 0; }
+const Foo *Ptr = nullptr;
+int m = generic(Ptr);
+  )cpp",
+  "const struct Foo",
+  },
   };
   for (Test T : Tests) {
 Annotations File(T.AnnotatedCode);
-auto AST = TestTU::withCode(File.code()).build();
+auto TU = TestTU::withCode(File.code());
+TU.ExtraArgs.push_back("-std=c++20");
+auto AST = TU.build();
 SourceManagerForFile SM("foo.cpp", File.code());
 
-SCOPED_TRACE(File.code());
+SCOPED_TRACE(T.AnnotatedCode);
 EXPECT_FALSE(File.points().empty());
 for (Position Pos : File.points()) {
   auto Location = sourceLocationInMainFile(SM.get(), Pos);
   ASSERT_TRUE(!!Location) << llvm::toString(Location.takeError());
   auto DeducedType = getDeducedType(AST.getASTContext(), *Location);
-  ASSERT_TRUE(DeducedType);
-  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+  if (T.DeducedType == nullptr) {
+EXPECT_FALSE(DeducedType);
+  } else {
+ASSERT_TRUE(DeducedType);
+EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+  }
 }
   }
 }
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-

[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

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

LGTM aside from some minor nits. Can you also add a release note for the change?




Comment at: clang/include/clang/AST/ExprCXX.h:2271
+
+if (auto Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))





Comment at: clang/include/clang/AST/ExprCXX.h:2285
+
+if (auto Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))





Comment at: clang/lib/AST/StmtPrinter.cpp:2135
   std::string TypeS;
-  if (Optional Size = E->getArraySize()) {
+  if (E->isArray()) {
 llvm::raw_string_ostream s(TypeS);

tbaeder wrote:
> I changed this just for clarity, not doing it did not cause any tests to 
> fail. Not sure if this is tested at all.
-ast-print is... pretty terrible (I've had half a mind to put up an RFC asking 
if we should remove it entirely, that's how unmaintained it is), so I suspect 
it's not tested.


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

https://reviews.llvm.org/D119525

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added a comment.

code looks good to me, but I don't know the code base well enough for a "LGTM"

Thanks for implementing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D118977: [NVPTX] Add more FMA intriniscs/builtins

2022-02-11 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda updated this revision to Diff 407904.
jchlanda added a comment.

PTX/sm version tidy up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118977

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
  llvm/test/CodeGen/NVPTX/math-intrins-sm53-ptx42.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70-instcombine.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll

Index: llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
===
--- llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
+++ llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
@@ -36,6 +36,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f16
 define half @fmin_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -43,6 +44,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f16
 define half @fmin_ftz_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.ftz.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -50,6 +52,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_f16
 define half @fmin_nan_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.nan.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -57,6 +60,7 @@
 
 ; CHECK-LABEL: fmin_ftz_nan_xorsign_abs_f16
 define half @fmin_ftz_nan_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.NaN.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.ftz.nan.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -64,6 +68,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f16x2
 define <2 x half> @fmin_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -71,6 +76,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f16x2
 define <2 x half> @fmin_ftz_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.ftz.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -78,6 +84,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_f16x2
 define <2 x half> @fmin_nan_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.nan.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -85,6 +92,7 @@
 
 ; CHECK-LABEL: fmin_ftz_nan_xorsign_abs_f16x2
 define <2 x half> @fmin_ftz_nan_xorsign_abs_f16x2(<2 x half> %0, <2 x half> %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.NaN.xorsign.abs.f16x2
   %res = call <2 x half> @llvm.nvvm.fmin.ftz.nan.xorsign.abs.f16x2(<2 x half> %0, <2 x half> %1)
   ret <2 x half> %res
@@ -92,6 +100,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_bf16
 define i16 @fmin_xorsign_abs_bf16(i16 %0, i16 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.bf16
   %res = call i16 @llvm.nvvm.fmin.xorsign.abs.bf16(i16 %0, i16 %1)
   ret i16 %res
@@ -99,6 +108,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_bf16
 define i16 @fmin_nan_xorsign_abs_bf16(i16 %0, i16 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.bf16
   %res = call i16 @llvm.nvvm.fmin.nan.xorsign.abs.bf16(i16 %0, i16 %1)
   ret i16 %res
@@ -106,6 +116,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_bf16x2
 define i32 @fmin_xorsign_abs_bf16x2(i32 %0, i32 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.bf16x2
   %res = call i32 @llvm.nvvm.fmin.xorsign.abs.bf16x2(i32 %0, i32 %1)
   ret i32 %res
@@ -113,6 +124,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_bf16x2
 define i32 @fmin_nan_xorsign_abs_bf16x2(i32 %0, i32 %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.bf16x2
   %res = call i32 @llvm.nvvm.fmin.nan.xorsign.abs.bf16x2(i32 %0, i32 %1)
   ret i32 %res
@@ -120,6 +132,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f
 define float @fmin_xorsign_abs_f(float %0, float %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f
   %res = call float @llvm.nvvm.fmin.xorsign.abs.f(float %0, float %1)
   ret float %res
@@ -127,6 +140,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f
 define float @fmin_ftz_xorsign_abs_f(float %0, float %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f
   %res = call float @llvm.nvvm.fmin.ftz.xorsign.abs.f(float %0, float %1)
   ret float %res
@@ -134,6 +148,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_ab

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added a comment.

Should this be added to the Release Notes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[clang] d8f99bb - [AMDGPU] replace hostcall module flag with function attribute

2022-02-11 Thread Sameer Sahasrabuddhe via cfe-commits

Author: Sameer Sahasrabuddhe
Date: 2022-02-11T22:51:56+05:30
New Revision: d8f99bb6e0641474b6bc1728295b40a8fa279f9a

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

LOG: [AMDGPU] replace hostcall module flag with function attribute

The module flag to indicate use of hostcall is insufficient to catch
all cases where hostcall might be in use by a kernel. This is now
replaced by a function attribute that gets propagated to top-level
kernel functions via their respective call-graph.

If the attribute "amdgpu-no-hostcall-ptr" is absent on a kernel, the
default behaviour is to emit kernel metadata indicating that the
kernel uses the hostcall buffer pointer passed as an implicit
argument.

The attribute may be placed explicitly by the user, or inferred by the
AMDGPU attributor by examining the call-graph. The attribute is
inferred only if the function is not being sanitized, and the
implictarg_ptr does not result in a load of any byte in the hostcall
pointer argument.

Reviewed By: jdoerfert, arsenm, kpyzhov

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

Added: 
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-v3.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-v5.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/amdgpu-asan.cu
llvm/lib/Target/AMDGPU/AMDGPUAttributes.def
llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
llvm/test/CodeGen/AMDGPU/addrspacecast-constantexpr.ll
llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll
llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
llvm/test/CodeGen/AMDGPU/direct-indirect-call.ll
llvm/test/CodeGen/AMDGPU/duplicate-attribute-indirect.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-enqueue-kernel-v3.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-enqueue-kernel.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args-v3.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args-v5.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
llvm/test/CodeGen/AMDGPU/propagate-flat-work-group-size.ll
llvm/test/CodeGen/AMDGPU/simple-indirect-call.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-attribute-missing.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-multistep.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-nested-function-calls.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-prevent-attribute-propagation.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll
llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll
mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp

Removed: 
clang/test/CodeGenCUDA/amdgpu-asan-printf.cu
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-absent-v3.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-absent.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present.ll



diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8a7345a9f494a..0d89cb723c76b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -566,9 +566,6 @@ void CodeGenModule::Release() {
   "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
   llvm::GlobalVariable::NotThreadLocal);
   addCompilerUsedGlobal(Var);
-  if (!getModule().getModuleFlag("amdgpu_hostcall")) {
-getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 
1);
-  }
 }
 // Emit amdgpu_code_object_version module flag, which is code object 
version
 // times 100.

diff  --git a/clang/test/CodeGenCUDA/amdgpu-asan-printf.cu 
b/clang/test/CodeGenCUDA/amdgpu-asan-printf.cu
deleted file mode 100644
index 69246f9ce7af1..0
--- a/clang/test/CodeGenCUDA/amdgpu-asan-printf.cu
+++ /dev/null
@@ -1,17 +0,0 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
-// RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
-// RUN:   -O3 -x hip | FileCheck -check-prefixes=MFCHECK %s
-
-// MFCHECK: !{{.*}} = !{i32 4, !"amdgpu_hostcall", i32 1}
-
-// Test to check hostcall module flag metadata is generated correctly
-// when a program has printf call and compiled with -fsanitize=address.
-#include "Inputs/cuda.h"
-__device__ void non_kernel() {
-  printf("sanitized device function");
-}
-
-__global_

[PATCH] D119216: [AMDGPU] replace hostcall module flag with function attribute

2022-02-11 Thread Sameer Sahasrabuddhe 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 rGd8f99bb6e064: [AMDGPU] replace hostcall module flag with 
function attribute (authored by sameerds).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119216

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/amdgpu-asan-printf.cu
  clang/test/CodeGenCUDA/amdgpu-asan.cu
  llvm/lib/Target/AMDGPU/AMDGPUAttributes.def
  llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
  llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
  llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
  llvm/test/CodeGen/AMDGPU/addrspacecast-constantexpr.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll
  llvm/test/CodeGen/AMDGPU/direct-indirect-call.ll
  llvm/test/CodeGen/AMDGPU/duplicate-attribute-indirect.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-enqueue-kernel-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-enqueue-kernel.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args-v5.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hidden-args.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-absent-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-absent.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-v3.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-v5.ll
  llvm/test/CodeGen/AMDGPU/propagate-flat-work-group-size.ll
  llvm/test/CodeGen/AMDGPU/simple-indirect-call.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-attribute-missing.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-multistep.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-nested-function-calls.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-prevent-attribute-propagation.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll
  llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll
  mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp

Index: mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
===
--- mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
+++ mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
@@ -307,11 +307,6 @@
 }
   }
 
-  // Set amdgpu_hostcall if host calls have been linked, as needed by newer LLVM
-  // FIXME: Is there a way to set this during printf() lowering that makes sense
-  if (ret->getFunction("__ockl_hostcall_internal"))
-if (!ret->getModuleFlag("amdgpu_hostcall"))
-  ret->addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
   return ret;
 }
 
Index: llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll
===
--- llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll
+++ llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll
@@ -61,5 +61,5 @@
 
 attributes #0 = { "uniform-work-group-size"="false" }
 ;.
-; CHECK: attributes #[[ATTR0]] = { "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "uniform-work-group-size"="false" }
+; CHECK: attributes #[[ATTR0]] = { "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "uniform-work-group-size"="false" }
 ;.
Index: llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll
===
--- llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll
+++ llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll
@@ -101,7 +101,7 @@
 attributes #0 = { nounwind readnone }
 attributes #1 = { "uniform-work-group-size"="true" }
 ;.
-; CHECK: attributes #[[ATTR0]] = { nounwind readnone "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "uniform-work-group-size"="false" }
-; CHECK: attributes #[[ATTR1]] = { nounwind readnone "amdgpu-no-dispatch-id" "amdgpu-

[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 407912.

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

https://reviews.llvm.org/D119525

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/issue53742.cpp

Index: clang/test/AST/issue53742.cpp
===
--- /dev/null
+++ clang/test/AST/issue53742.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+struct Data {
+  char *a;
+  char *b;
+  bool *c;
+};
+
+int main() {
+  Data in;
+  in.a = new char[](); // expected-error {{cannot determine allocated array size from initializer}}
+  in.c = new bool[100]();
+  in.b = new char[100]();
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -11918,9 +11918,9 @@
 
   // Transform the size of the array we're allocating (if any).
   Optional ArraySize;
-  if (Optional OldArraySize = E->getArraySize()) {
+  if (E->isArray()) {
 ExprResult NewArraySize;
-if (*OldArraySize) {
+if (Optional OldArraySize = E->getArraySize()) {
   NewArraySize = getDerived().TransformExpr(*OldArraySize);
   if (NewArraySize.isInvalid())
 return ExprError();
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -2132,10 +2132,10 @@
   if (E->isParenTypeId())
 OS << "(";
   std::string TypeS;
-  if (Optional Size = E->getArraySize()) {
+  if (E->isArray()) {
 llvm::raw_string_ostream s(TypeS);
 s << '[';
-if (*Size)
+if (Optional Size = E->getArraySize())
   (*Size)->printPretty(s, Helper, Policy);
 s << ']';
   }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9427,7 +9427,7 @@
   bool ValueInit = false;
 
   QualType AllocType = E->getAllocatedType();
-  if (Optional ArraySize = E->getArraySize()) {
+  if (Optional ArraySize = E->getArraySize()) {
 const Expr *Stripped = *ArraySize;
 for (; auto *ICE = dyn_cast(Stripped);
  Stripped = ICE->getSubExpr())
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -2261,15 +2261,32 @@
 
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
+  /// This might return None even if isArray() returns true,
+  /// since there might not be an array size expression.
+  /// If the result is not-None, it will never wrap a nullptr.
   Optional getArraySize() {
 if (!isArray())
   return None;
-return cast_or_null(getTrailingObjects()[arraySizeOffset()]);
+
+if (auto *Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))
+  return Result;
+
+return None;
   }
+
+  /// This might return None even if isArray() returns true,
+  /// since there might not be an array size expression.
+  /// If the result is not-None, it will never wrap a nullptr.
   Optional getArraySize() const {
 if (!isArray())
   return None;
-return cast_or_null(getTrailingObjects()[arraySizeOffset()]);
+
+if (auto *Result =
+cast_or_null(getTrailingObjects()[arraySizeOffset()]))
+  return Result;
+
+return None;
   }
 
   unsigned getNumPlacementArgs() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

2022-02-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 3 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/StmtPrinter.cpp:2135
   std::string TypeS;
-  if (Optional Size = E->getArraySize()) {
+  if (E->isArray()) {
 llvm::raw_string_ostream s(TypeS);

aaron.ballman wrote:
> tbaeder wrote:
> > I changed this just for clarity, not doing it did not cause any tests to 
> > fail. Not sure if this is tested at all.
> -ast-print is... pretty terrible (I've had half a mind to put up an RFC 
> asking if we should remove it entirely, that's how unmaintained it is), so I 
> suspect it's not tested.
Alright, I'll leave it at that then. I briefly tried to test the code but 
didn't succeed.


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

https://reviews.llvm.org/D119525

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


[PATCH] D119199: replace clang LLVM_ENABLE_PLUGINS -> CLANG_PLUGIN_SUPPORT in tests

2022-02-11 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added inline comments.



Comment at: clang/tools/driver/CMakeLists.txt:53
 # Support plugins.
 if(CLANG_PLUGIN_SUPPORT)
   export_executable_symbols_for_plugins(clang)

I think we've managed to fix our build by changing this line so that it tests
```if(CLANG_PLUGIN_SUPPORT OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)```
because that fixes the cmake complaint that you can't link against an 
executable that didn't have `ENABLE_EXPORTS`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119199

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


[PATCH] D118196: [syntax][pseudo] Implement LR parsing table.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This is really nice, mostly nits.




Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h:177
 };
+void initTerminals(std::vector &Terminals);
 

why is this exposed/required rather than being initialized by the GrammarTable 
constructor?
Since this is essentially static (must always correspond to tok::TokenKind) it 
seems that GrammarTable could just have an ArrayRef and it could be initialized 
by a lazy-init singleton:

```
// in Grammar.cpp
static ArrayRef getTerminalNames() {
  static std::vector *TerminalNames = []{

  };
  return *TerminalNames;
}
```

(I know eventually we'd like GrammarTable to be generated and have very minimal 
dynamic init, but there are lots of other details needed e.g. we can't 
statically initialize `vector` either, so we should cross that bridge 
when we come to it)



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:28
+//  LRTable is *performance-critial* as it is consulted frequently during a
+//  parse. In general, LRTable is very sprase (most of the entries are empty).
+//  For example, for the C++ language, the SLR table has ~1500 states and 650

space -> sparse



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:58
+// Unlike A typical LR parsing table allows at most one available action per
+// entry, conflicted actions are allowed in LRTable.
+class LRTable {

Maybe mention relation to GLR: GLR can execute these in parallel?



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:67
+enum Kind : uint8_t {
+  // Terminal actions, corresponding to entries of ACTION table.
+  Error = 0,

nit: I think you want this to be a comment on the section rather than on Error, 
leave a blank line?



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:68
+  // Terminal actions, corresponding to entries of ACTION table.
+  Error = 0,
+  // Shift to state n: move forward with the lookahead, and push state n

Error seems like an action we'd dynamically handle, rather than an unreachable 
sentinel.

I'd prefer to call this sentinel and llvm_unreachable() on it in the relevant 
places. Even if we do plan dynamic error actions, we have enough spare bits to 
keep these two cases separate.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:80
+  // Nonterminal actions, corresponding to entry of GOTO table.
+  // Go to state n: pust state n onto the state stack.
+  // Similar to Shift, but it is a nonterminal forward transition.

again blank line between "nonterminal actions" and "go to state n"



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:80
+  // Nonterminal actions, corresponding to entry of GOTO table.
+  // Go to state n: pust state n onto the state stack.
+  // Similar to Shift, but it is a nonterminal forward transition.

sammccall wrote:
> again blank line between "nonterminal actions" and "go to state n"
pust -> push?

I thought goto replaces the top of the stack rather than being pushed onto it.

e.g.
stack is { stmt := . expr ; }, lookahead is IDENT, action is shift "expr := 
IDENT ."
stack is { stmt := . expr ; | expr := IDENT . }, lookahead is semi, action is 
reduce
stack is { stmt := . expr ; }, reduced symbol is expr, goto is state "stmt := 
expr . ;"
stack is { stmt := expr . ;}, lookahead is semi...

Line 3=>4 doesn't seem like a push
 




Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:106
+bool operator==(const Action &L) const { return value() == L.value(); }
+uint16_t value() const { return K << ValueBits | Value; };
+

maybe value()=>opaque() or asInteger()?

Partly to give a hint a bit more at the purpose, partly to avoid confusion of 
`Value != value()`



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:114
+// Either StateID or RuleID, depending on the Kind.
+uint16_t Value : ValueBits;
+  };

static assert RuleBits <= ValueBits, and I think we want a StateBits above plus 
some assertions on the number of states when building



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:114
+// Either StateID or RuleID, depending on the Kind.
+uint16_t Value : ValueBits;
+  };

sammccall wrote:
> static assert RuleBits <= ValueBits, and I think we want a StateBits above 
> plus some assertions on the number of states when building
FWIW I've mostly seen just `unsigned` as the field type for bitfields. It seems 
a little confusing to explicitly specify the size both as 16 and 13 bits.

Up to you, but if you change this one also consider the Kind enum.



Comment at: clang/include/clang/Tooling/Synt

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D119537#3314509 , @avogelsgesang 
wrote:

> Should this be added to the Release Notes?

We usually go back over the git log around the time of a release cut.
It started as laziness but I think it's a good system: less work writing notes 
for stuff that doesn't end up landing, and gives us a chance to group and 
summarize related changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

And thanks for taking a look, and filing bugs - sorry we can't get to 
everything :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog created this revision.
Herald added a subscriber: carlosgalvezp.
kesyog requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

D90110  modified the behavior of 
`run-clang-tidy` to always pass the
`--use-color` option to clang-tidy, which enabled colored diagnostics
output regardless of TTY status or .clang-tidy settings. This left the
user with no option to disable the colored output.

This presents an issue when trying to parse the output of run-clang-tidy
programmaticall, as the output is polluted with ANSI escape characters.

This PR fixes this issue in two ways:

1. It restores the default behavior of `run-clang-tidy` to let `clang-tidy` 
decide whether to color output. This allows the user to configure color via the 
`UseColor` option in a .clang-tidy file.
2. It adds mutually exclusive, optional `-use-color` and `-no-use-color` 
argument flags that let the user explicitly set the color option via the 
invocation.

After this change the default behavior of `run-clang-tidy` when no
.clang-tidy file is available is now to show no color, presumably
because `clang-tidy` detects that the output is being piped and defaults
to not showing colored output. This seems like an acceptable tradeoff
to respect .clang-tidy configurations, as users can still use the
`-use-color` option to explicitly enable color.

Fixes #49441 (50097 in Bugzilla)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119562

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,19 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color:
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +172,8 @@
  tmpdir, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 
 proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
 output, err = proc.communicate()
@@ -231,6 +236,16 @@
   'after applying fixes')
   parser.add_argument('-style', default='file', help='The style of reformat '
   'code after applying fixes')
+  color_group = parser.add_mutually_exclusive_group()
+  color_group.add_argument('-use-color', action='store_true', dest='use_color',
+   help='Use colors in diagnostics, overriding 
clang-tidy\'s default '
+   'behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  color_group.add_argument('-no-use-color', action='store_false', 
dest='use_color',
+   help='Do not use colors in diagnostics, overriding 
clang-tidy\'s default'
+   ' behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  parser.set_defaults(use_color=None)
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
@@ -258,7 +273,8 @@
  None, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 invocation.append('-list-checks')
 invocation.ap

[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-11 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D110869#3313443 , @void wrote:

> In D110869#3312360 , @RKSimon wrote:
>
>> @void This buildbot appears to be still broken due to this change: 
>> https://lab.llvm.org/buildbot/#/builders/110/builds/10271
>
> Strange...This is the first time seeing something like this. I'll fix it 
> quickly.

It's fixed now. Sorry about the failure!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D119367: [HWASan] Allow no_sanitize(..) and change metadata passing.

2022-02-11 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

You might want to update Bitcode writer/reader as well, otherwise nosanitize 
will be lost after a trip through .bc/.ii.




Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:50
+  f()[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
+  return 0;

did you mean to do it twice?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119367

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Shouldn't it be just `else:`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Eugene.Zelenko wrote:
> Shouldn't it be just `else:`?
There are three cases:

| Argument  | `use_color` | Behavior |
| `-use-color` | `True` | `--use-color` is passed to clang-tidy, force enabling 
color |
| `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
force disabling color |
| (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy follows 
its default coloring behavior |

The case on the highlighted line is the second row of the table, and we have to 
check that `use_color` is not `None` to exclude the case of the third row.

I was trying to avoid the extra nesting of something like below, but maybe the 
intent would be clearer?
```
if use_color is not None:
  if use_color:
start.append('--use-color')
  else:
start.append('--use-color=false')
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

kesyog wrote:
> Eugene.Zelenko wrote:
> > Shouldn't it be just `else:`?
> There are three cases:
> 
> | Argument  | `use_color` | Behavior |
> | `-use-color` | `True` | `--use-color` is passed to clang-tidy, force 
> enabling color |
> | `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
> force disabling color |
> | (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy follows 
> its default coloring behavior |
> 
> The case on the highlighted line is the second row of the table, and we have 
> to check that `use_color` is not `None` to exclude the case of the third row.
> 
> I was trying to avoid the extra nesting of something like below, but maybe 
> the intent would be clearer?
> ```
> if use_color is not None:
>   if use_color:
> start.append('--use-color')
>   else:
> start.append('--use-color=false')
> ```
I think you implementation is incorrect. You should check for not `None` first 
and than set proper value for `--use-color`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[clang] 87dd3d3 - [clang][OpaquePtr] Remove call to getPointerElementType() in CodeGenModule::GetAddrOfGlobalTemporary()

2022-02-11 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2022-02-11T10:39:49-08:00
New Revision: 87dd3d350c4ce0115b2cdf91d85ddd05ae2661aa

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

LOG: [clang][OpaquePtr] Remove call to getPointerElementType() in 
CodeGenModule::GetAddrOfGlobalTemporary()

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0d89cb723c76b..772059a436d17 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5670,9 +5670,11 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   getModule(), Type, false, llvm::GlobalVariable::InternalLinkage,
   nullptr);
 }
-return ConstantAddress(
-InsertResult.first->second,
-InsertResult.first->second->getType()->getPointerElementType(), Align);
+return ConstantAddress(InsertResult.first->second,
+   llvm::cast(
+   InsertResult.first->second->stripPointerCasts())
+   ->getValueType(),
+   Align);
   }
 
   // FIXME: If an externally-visible declaration extends multiple temporaries,



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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog updated this revision to Diff 407950.
kesyog added a comment.

Refactor tri-state logic for readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,20 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color is not None:
+if use_color:
+  start.append('--use-color')
+else:
+  start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +173,8 @@
  tmpdir, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 
 proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
 output, err = proc.communicate()
@@ -231,6 +237,16 @@
   'after applying fixes')
   parser.add_argument('-style', default='file', help='The style of reformat '
   'code after applying fixes')
+  color_group = parser.add_mutually_exclusive_group()
+  color_group.add_argument('-use-color', action='store_true', dest='use_color',
+   help='Use colors in diagnostics, overriding 
clang-tidy\'s default '
+   'behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  color_group.add_argument('-no-use-color', action='store_false', 
dest='use_color',
+   help='Do not use colors in diagnostics, overriding 
clang-tidy\'s default'
+   ' behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  parser.set_defaults(use_color=None)
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
@@ -258,7 +274,8 @@
  None, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 invocation.append('-list-checks')
 invocation.append('-')
 if args.quiet:


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,20 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color is not None:
+if use_color:
+  start.append('--use-color')
+else:
+  start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +173,8 @@
  tmpdir, build_pat

[PATCH] D112730: [clang-tidy] Add AUTOSAR module

2022-02-11 Thread Tanya Lattner via Phabricator via cfe-commits
tonic added a comment.

Unfortunately our legal counsel has advised that this patch should not be 
included into LLVM because the exact patent burden is not disclosed. Therefore, 
we can not accept this patch into LLVM. I am very sorry to have to report this 
disappointing news.


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

https://reviews.llvm.org/D112730

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog marked an inline comment as done.
kesyog added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Eugene.Zelenko wrote:
> kesyog wrote:
> > Eugene.Zelenko wrote:
> > > Shouldn't it be just `else:`?
> > There are three cases:
> > 
> > | Argument  | `use_color` | Behavior |
> > | `-use-color` | `True` | `--use-color` is passed to clang-tidy, force 
> > enabling color |
> > | `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
> > force disabling color |
> > | (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy 
> > follows its default coloring behavior |
> > 
> > The case on the highlighted line is the second row of the table, and we 
> > have to check that `use_color` is not `None` to exclude the case of the 
> > third row.
> > 
> > I was trying to avoid the extra nesting of something like below, but maybe 
> > the intent would be clearer?
> > ```
> > if use_color is not None:
> >   if use_color:
> > start.append('--use-color')
> >   else:
> > start.append('--use-color=false')
> > ```
> I think you implementation is incorrect. You should check for not `None` 
> first and than set proper value for `--use-color`.
fixed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[clang] b3b2538 - [lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:

2022-02-11 Thread Nico Weber via cfe-commits

Author: Peter Kasting
Date: 2022-02-11T13:55:18-05:00
New Revision: b3b2538df100ec7f6587b0ee70819a3c8ee2c27e

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

LOG: [lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:

Makes lld-link work in a non-MSVC shell by autodetecting MSVC toolchain. Also
adds support for /winsysroot and a few other switches.

All this is done by refactoring to share code with clang-cl's existing support
for the same.

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

Added: 
lld/test/COFF/winsysroot.test
llvm/include/llvm/Support/MSVCPaths.h
llvm/include/llvm/Support/MSVCSetupApi.h
llvm/lib/Support/MSVCPaths.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/Options.td
lld/COFF/SymbolTable.cpp
lld/docs/ReleaseNotes.rst
llvm/lib/Support/CMakeLists.txt
llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Removed: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index c7defa9cd88c6..5666ad499d791 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -285,7 +285,6 @@ clang/lib/Driver/ToolChains/InterfaceStubs.h
 clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
-clang/lib/Driver/ToolChains/MSVCSetupApi.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp
 clang/lib/Driver/ToolChains/PPCFreeBSD.h
 clang/lib/Driver/ToolChains/PPCLinux.h
@@ -5150,6 +5149,8 @@ llvm/include/llvm/Support/MemoryBufferRef.h
 llvm/include/llvm/Support/MSP430AttributeParser.h
 llvm/include/llvm/Support/MSP430Attributes.h
 llvm/include/llvm/Support/MSVCErrorWorkarounds.h
+llvm/include/llvm/Support/MSVCPaths.h
+llvm/include/llvm/Support/MSVCSetupApi.h
 llvm/include/llvm/Support/Parallel.h
 llvm/include/llvm/Support/PGOOptions.h
 llvm/include/llvm/Support/PointerLikeTypeTraits.h
@@ -5840,6 +5841,7 @@ llvm/lib/Support/Memory.cpp
 llvm/lib/Support/MemoryBufferRef.cpp
 llvm/lib/Support/MSP430AttributeParser.cpp
 llvm/lib/Support/MSP430Attributes.cpp
+llvm/lib/Support/MSVCPaths.cpp
 llvm/lib/Support/Optional.cpp
 llvm/lib/Support/Parallel.cpp
 llvm/lib/Support/Program.cpp

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 9f4751167ac12..36e190f69154b 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/MSVCPaths.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -40,91 +41,12 @@
   #include 
 #endif
 
-#ifdef _MSC_VER
-// Don't support SetupApi on MinGW.
-#define USE_MSVC_SETUP_API
-
-// Make sure this comes before MSVCSetupApi.h
-#include 
-
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
-#endif
-#include "MSVCSetupApi.h"
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-#include "llvm/Support/COM.h"
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
-#endif
-
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-// Windows SDKs and VC Toolchains group their contents into subdirectories 
based
-// on the target architecture. This function converts an llvm::Triple::ArchType
-// to the corresponding subdirectory name.
-static const char *llvmArchToWindowsSDKArch(llvm::Triple::ArchType Arch) {
-  using ArchType = llvm::Triple::ArchType;
-  switch (Arch) {
-  case ArchType::x86:
-return "x86";
-  case ArchType::x86_64:
-return "x64";
-  case ArchType::arm:
-return "arm";
-  case ArchType::aarch64:
-return "arm64";
-  default:
-return "";
-  }
-}
-
-// Similar to the above function, but for Visual Studios before VS2017.
-static const char *llvmArchToLegacyVCArch(llvm::Triple::ArchType Arch) {
-  using ArchType = llvm::Triple::ArchType;
-  switch (Arch) {
-  case ArchType::x86:
- 

[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber 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 rGb3b2538df100: [lld/coff] Make lld-link work in a non-MSVC 
shell, add /winsysroot: (authored by pkasting, committed by thakis).

Changed prior to commit:
  https://reviews.llvm.org/D118070?vs=406570&id=407955#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MSVCSetupApi.h
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h
  lld/COFF/Options.td
  lld/COFF/SymbolTable.cpp
  lld/docs/ReleaseNotes.rst
  lld/test/COFF/winsysroot.test
  llvm/include/llvm/Support/MSVCPaths.h
  llvm/include/llvm/Support/MSVCSetupApi.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/MSVCPaths.cpp
  llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1310,9 +1310,6 @@
 "lib/Driver/ToolChains/Arch/*.cpp",
 "lib/Driver/ToolChains/Arch/*.h",
 ],
-exclude = [
-"lib/Driver/ToolChains/MSVCSetupApi.h",
-],
 ),
 hdrs = glob([
 "include/clang/Driver/*.h",
Index: llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
@@ -98,6 +98,7 @@
 "MD5.cpp",
 "MSP430AttributeParser.cpp",
 "MSP430Attributes.cpp",
+"MSVCPaths.cpp",
 "ManagedStatic.cpp",
 "MathExtras.cpp",
 "MemAlloc.cpp",
Index: llvm/lib/Support/MSVCPaths.cpp
===
--- /dev/null
+++ llvm/lib/Support/MSVCPaths.cpp
@@ -0,0 +1,709 @@
+//===-- MSVCPaths.cpp - MSVC path-parsing helpers -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/MSVCPaths.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/VersionTuple.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include 
+#endif
+
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#include "llvm/Support/COM.h"
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+#include "llvm/Support/MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+#endif
+
+static std::string
+getHighestNumericTupleInDirectory(llvm::vfs::FileSystem &VFS,
+  llvm::StringRef Directory) {
+  std::string Highest;
+  llvm::VersionTuple HighestTuple;
+
+  std::error_code EC;
+  for (llvm::vfs::directory_iterator DirIt = VFS.dir_begin(Directory, EC),
+ DirEnd;
+   !EC && DirIt != DirEnd; DirIt.increment(EC)) {
+auto Status = VFS.status(DirIt->path());
+if (!Status || !Status->isDirectory())
+  continue;
+llvm::StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+llvm::VersionTuple Tuple;
+if (Tuple.tryParse(CandidateName)) // tryParse() returns true on error.
+  continue;
+if (Tuple > HighestTuple) {
+  HighestTuple = Tuple;
+  Highest = CandidateName.str();
+}
+  }
+
+  return Highest;
+}
+
+static bool getWindows10

[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I went ahead and landed this for now. It's easy to move the 3 new files to 
their own library later on if we decide it's something we want to do.

Thanks for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119165: [clang-tidy] Add processing lambda captures at bugprone-use-after-move check

2022-02-11 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:416
 
+  auto CallMoveMatcherLambda = lambdaExpr(
+  forEachLambdaCapture(lambdaCapture(capturesVar(varDecl(

sammccall wrote:
> sammccall wrote:
> > do we want to bind the lambda itself as `moving-call`?
> we should probably have a comment explaining *why* lambdas get handled 
> specially.
> 
> If I understand right:
> - the normal matcher would already match
> - but either MovingCall or ContainingLambda (which?) point at unhelpful nodes 
> and
> - we end up doing the analysis inside the lambda rather than in the enclosing 
> function
> - so never find the following use
> 
> (I wonder if it's possible to fix this slightly more directly by tweaking the 
> MovingCall or ContainingLambda logic)
> If I understand right:

There are some troubles with the original matcher. The most obvious one is 
correctly described at your comment :
The original matcher
```
callExpr(callee(functionDecl(hasName("::std::move"))),
   ... hasAncestor(lambdaExpr().bind("containing-lambda")),
   ...
```
applied to the code
```
auto []() { // lambda_1
   int a = 0;
   ...
   auto [](aa = std::move(a)) { // lambda_2
   }
}
```
will return *lambda_2* binded to the "containing-lambda" but we expect it to be 
*lambda_1*



> (I wonder if it's possible to fix this slightly more directly by tweaking the 
> MovingCall or ContainingLambda logic)
It would be good to find it if it's possible



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1356
+int lambdaCaptures() {
+  int a = 0;
+  int b = 0;

sammccall wrote:
> It's pretty interesting that use-after-move fires for ints!
> 
> Someone might decide to "fix" that though, so probably best to use A like the 
> other tests.
There is also another case that I want to address as a separate patch.
```
void autoCapture() {
  auto var = [](auto &&res) {
auto f = [blk = std::move(res)]() {};
return std::move(res);
  };
}
```
This one is matched as `UnresolvedLookupExpr` and requires another modified 
matcher


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119165

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


  1   2   >