[PATCH] D157252: [clang][ExprConst] Handle 0 type size in builtin_memcpy etc.

2023-08-07 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: clang.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157252

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/builtin-memcpy.c


Index: clang/test/Sema/builtin-memcpy.c
===
--- /dev/null
+++ clang/test/Sema/builtin-memcpy.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+/// Zero-sized structs should not crash.
+int b() {
+  struct {  } a[10];
+  __builtin_memcpy(&a[2], a, 2); // expected-warning {{buffer has size 0, but 
size argument is 2}}
+  return 0;
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9509,6 +9509,8 @@
 
 // Figure out how many T's we're copying.
 uint64_t TSize = Info.Ctx.getTypeSizeInChars(T).getQuantity();
+if (TSize == 0)
+  return false;
 if (!WChar) {
   uint64_t Remainder;
   llvm::APInt OrigN = N;


Index: clang/test/Sema/builtin-memcpy.c
===
--- /dev/null
+++ clang/test/Sema/builtin-memcpy.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+/// Zero-sized structs should not crash.
+int b() {
+  struct {  } a[10];
+  __builtin_memcpy(&a[2], a, 2); // expected-warning {{buffer has size 0, but size argument is 2}}
+  return 0;
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9509,6 +9509,8 @@
 
 // Figure out how many T's we're copying.
 uint64_t TSize = Info.Ctx.getTypeSizeInChars(T).getQuantity();
+if (TSize == 0)
+  return false;
 if (!WChar) {
   uint64_t Remainder;
   llvm::APInt OrigN = N;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement

2023-08-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good.




Comment at: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp:81
 
+constexpr int test13() { do {} while (a < 10); return 0; }   // expected-error 
{{use of undeclared identifier}}
+static_assert(test13());  // expected-error {{static assertion expression is 
not an integral constant expression}}

nit: it is better to use the below `TEST_EVALUATE` macro for the test, 
`TEST_EVALUATE(DoWhile2, do {} while (undefined < 10); )`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157195

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


[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement

2023-08-07 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:1897-1898
   if (Cond.isUsable())
-Cond = Actions.CorrectDelayedTyposInExpr(Cond);
+Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr,
+ /*RecoveryUncorrectedTypos*/ 
true);
   else {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157195

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


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-07 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 547660.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D157074

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/Misc/constexpr-source-ranges.cpp


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
   if (RHS.isZero()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+const auto *Op = cast(S.Current->getExpr(OpPC));
+S.FFDiag(Op, diag::note_expr_divide_by_zero)
+<< Op->getRHS()->getSourceRange();
 return false;
   }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2808,9 +2808,9 @@
 }
 
 /// Perform the given binary integer operation.
-static bool handleIntIntBinOp(EvalInfo &Info, const Expr *E, const APSInt &LHS,
-  BinaryOperatorKind Opcode, APSInt RHS,
-  APSInt &Result) {
+static bool handleIntIntBinOp(EvalInfo &Info, const BinaryOperator *E,
+  const APSInt &LHS, APSInt RHS, APSInt &Result) {
+  BinaryOperatorKind Opcode = E->getOpcode();
   bool HandleOverflowResult = true;
   switch (Opcode) {
   default:
@@ -2831,7 +2831,8 @@
   case BO_Div:
   case BO_Rem:
 if (RHS == 0) {
-  Info.FFDiag(E, diag::note_expr_divide_by_zero);
+  Info.FFDiag(E, diag::note_expr_divide_by_zero)
+  << E->getRHS()->getSourceRange();
   return false;
 }
 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports
@@ -3070,8 +3071,8 @@
   else if (BinaryOperator::isComparisonOp(Opcode))
 Success = handleCompareOpForVector(LHSElt, Opcode, RHSElt, EltResult);
   else
-Success = handleIntIntBinOp(Info, E, LHSElt.getInt(), Opcode,
-RHSElt.getInt(), EltResult);
+Success = handleIntIntBinOp(Info, E, LHSElt.getInt(), RHSElt.getInt(),
+EltResult);
 
   if (!Success) {
 Info.FFDiag(E);
@@ -4471,7 +4472,7 @@
 if (RHS.isInt()) {
   APSInt LHS =
   HandleIntToIntCast(Info, E, PromotedLHSType, SubobjType, Value);
-  if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))
+  if (!handleIntIntBinOp(Info, E, LHS, RHS.getInt(), LHS))
 return false;
   Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS);
   return true;
@@ -12891,8 +12892,7 @@
   // FIXME: Don't do this in the cases where we can deduce it.
   APSInt Value(Info.Ctx.getIntWidth(E->getType()),
E->getType()->isUnsignedIntegerOrEnumerationType());
-  if (!handleIntIntBinOp(Info, E, LHSVal.getInt(), E->getOpcode(),
- RHSVal.getInt(), Value))
+  if (!handleIntIntBinOp(Info, E, LHSVal.getInt(), RHSVal.getInt(), Value))
 return false;
   return Success(Value, E, Result);
 }


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -23,3 +23,16 @@
 }
 static_assert(ints(1, div(true, false), 2, div(false, true)) == 1, "");
 // CHECK: constexpr-source-ranges.cpp:24:23:{24:23-24:39}
+
+
+constexpr int zero() {
+  return 0;
+}
+constexpr int divByZero() {
+  return 1 / zero();
+}
+static_assert(divByZero() == 0, "");
+/// We see this twice. Once from sema and once when
+/// evaluating the static_assert above.
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
+// CHECK: constexpr-source-ranges.cpp:32:12:{32:14-32:20}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -152,8 +152,9 @@
 template 
 bool CheckDivRem(InterpState &S, CodePtr OpPC, const T

[PATCH] D157256: [clangd][clang-tidy][std_symbol_map] Add missing symbol.

2023-08-07 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
VitaNuo added a reviewer: kadircet.
Herald added subscribers: carlosgalvezp, arphaman, xazax.hun.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157256

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -363,6 +363,7 @@
 // Symbols missing from the generated symbol map as reported by users.
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
+SYMBOL(any_cast, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -363,6 +363,7 @@
 // Symbols missing from the generated symbol map as reported by users.
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
+SYMBOL(any_cast, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, ..., _N"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:221
 TEST_F(FormatTestCSharp, CSharpFatArrows) {
-  verifyFormat("Task serverTask = Task.Run(async() => {");
+  verifyIncompleteFormat("Task serverTask = Task.Run(async() => {");
   verifyFormat("public override string ToString() => \"{Name}\\{Age}\";");

not sure what changing here and why?



Comment at: clang/unittests/Format/FormatTestJS.cpp:1575
+   "/ /;",
+   getGoogleJSStyleWithColumns(18));
 }

out of interest what happens with  `xx ${variable} 
xx` type strings? can we add a test to show we won't break in the 
middle of a ${vas} even though the column limit might be reached?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D157207: [clangd] Fix typo in comment

2023-08-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

Thanks! LMK if i should land this for you (and an email address to set as 
commit author)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157207

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


[PATCH] D157129: [NFC] Fix unnecessary copy with auto.

2023-08-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

I went over the patch and I found only a single debatable case for taking by 
reference.
To clarify why I would prefer taking by value: value semantics is good for 
local reasoning; thus improves maintainability. We should only deviate from 
that when there is actual benefit for doing so.
Static analysis tools, such as Coverity, have false-positives. Some rules are 
better than others.
As a static analysis tool developer myself, I'd recommend carefully evaluating 
the findings before taking action for resolving them.
And if you find anything interesting, tool vendors are generally happy to 
receive feedback about their tool. I guess, they should as well understand that 
taking a pointer by reference doesn't improve anything.




Comment at: clang/include/clang/Analysis/FlowSensitive/StorageLocation.h:129
 llvm::dbgs() << "Existing children:\n";
-for ([[maybe_unused]] auto [Field, Loc] : Children) {
+for ([[maybe_unused]] const auto &[Field, Loc] : Children) {
   llvm::dbgs() << Field->getNameAsString() << "\n";

This is only 2 pointers. I'd rather take them by value.



Comment at: clang/lib/AST/Interp/ByteCodeEmitter.cpp:64
 
-  for (auto Cap : LC) {
+  for (const auto &Cap : LC) {
 unsigned Offset = R->getField(Cap.second)->Offset;

Only 2 pointers.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:3728
 const CXXRecordDecl *Base = nullptr;
-for (auto I : CXXRD->bases()) {
+for (const auto &I : CXXRD->bases()) {
   if (I.isVirtual())

It's 24 bytes, which is like 3 pointers.



Comment at: clang/lib/Analysis/FlowSensitive/RecordOps.cpp:38
 
-  for (auto [Field, DstFieldLoc] : Dst.children()) {
+  for (const auto &[Field, DstFieldLoc] : Dst.children()) {
 StorageLocation *SrcFieldLoc = Src.getChild(*Field);

2 pointers.



Comment at: clang/lib/Analysis/FlowSensitive/RecordOps.cpp:86
 
-  for (auto [Field, FieldLoc1] : Loc1.children()) {
+  for (const auto &[Field, FieldLoc1] : Loc1.children()) {
 StorageLocation *FieldLoc2 = Loc2.getChild(*Field);

2 pointers.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:305
 // Create masked policy intrinsic.
-for (auto P : SupportedMaskedPolicies) {
+for (const auto &P : SupportedMaskedPolicies) {
   llvm::SmallVector PolicyPrototype =

It's just a single `long`. 8 bytes.
Taking by ref would definitely not help the situation.



Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2621
   CStringLengthTy::Factory &F = state->get_context();
-  for (auto [Reg, Len] : Entries) {
+  for (auto &[Reg, Len] : Entries) {
 if (SymbolRef Sym = Len.getAsSymbol()) {

8 + 16 bytes. Basically 3 pointers.



Comment at: clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp:851-852
   if (const ObjCMethodDecl *OMD = dyn_cast_or_null(D)) {
-for (auto [Idx, FormalParam] : llvm::enumerate(OMD->parameters())) {
+for (const auto &[Idx, FormalParam] :
+ llvm::enumerate(OMD->parameters())) {
   if (isAnnotatedAsTakingLocalized(FormalParam)) {

size_t and a pointer. 16 bytes in total.



Comment at: clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp:534
   if (ReturnSymbol)
-for (auto [Sym, AllocState] : AMap) {
+for (auto &[Sym, AllocState] : AMap) {
   if (ReturnSymbol == AllocState.Region)

8 + 16 bytes.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2821
   ReallocPairsTy RP = state->get();
-  for (auto [Sym, ReallocPair] : RP) {
+  for (auto &[Sym, ReallocPair] : RP) {
 if (SymReaper.isDead(Sym) || SymReaper.isDead(ReallocPair.ReallocatedSym)) 
{

8 + 16 bytes.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:3081
   ReallocPairsTy RP = state->get();
-  for (auto [Sym, ReallocPair] : RP) {
+  for (auto &[Sym, ReallocPair] : RP) {
 // If the symbol is assumed to be NULL, remove it from consideration.

8 + 16 bytes.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:3558
 Out << Sep << "MallocChecker :" << NL;
-for (auto [Sym, Data] : RS) {
+for (auto &[Sym, Data] : RS) {
   const RefState *RefS = State->get(Sym);

8 + 16 bytes.



Comment at: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp:945
   PropertyAccessesMapTy PropertyAccesses = State->get();
-  for (auto [PropKey, PropVal] : PropertyAccesses) {
+  for (auto &[PropKey, PropVal] : PropertyAccesses) {
 if (!PropVal.isConstrainedNonnull) 

[PATCH] D157227: [Clang] Don't add `undef` for `operator new` under -fno-exceptions.

2023-08-07 Thread Nikita Popov via Phabricator via cfe-commits
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

Removing noundef makes no sense to me, because the return value is noundef even 
under fno-exceptions. If we remove something, it should be the nonnull 
attribute, because that's what's actually being violated.

@ldionne Can you give us an ETA on D150610  
please? Do we need to introduce a workaround for this libcxx bug in clang, or 
do you plan to fix this in the near future?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157227

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


[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-08-07 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 accepted this revision.
rogfer01 added a comment.
This revision is now accepted and ready to land.

Thanks for the update @asb. LGTM.


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

https://reviews.llvm.org/D142327

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-07 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/Sema/offsetof.c:79
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+

It probably makes sense to also add a test with static member of a class, like 
Aaron mentioned in GitHub - 
https://github.com/llvm/llvm-project/issues/64154#issuecomment-1653468938 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


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

2023-08-07 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

One of the kernel tests now fails to build for AArch64 and Arm:

  00:00:48 ++ make 
CC=/home/tcwg-buildslave/workspace/tcwg_kernel_0/bin/aarch64-cc 
LD=/home/tcwg-buildslave/workspace/tcwg_kernel_0/llvm-install/bin/ld.lld 
SUBLEVEL=0 EXTRAVERSION=-bisect ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 
HOSTCC=/home/tcwg-buildslave/workspace/tcwg_kernel_0/llvm-install/bin/clang 
-j32 -s -k
  00:08:26 lib/test_scanf.c:661:2: error: implicit conversion from 'int' to 
'unsigned char' changes value from -168 to 88 [-Werror,-Wconstant-conversion]
  00:08:26   661 | test_number_prefix(unsigned char,   "0xA7", 
"%2hhx%hhx", 0, 0xa7, 2, check_uchar);
  00:08:26   | 
^
  00:08:26 lib/test_scanf.c:609:29: note: expanded from macro 
'test_number_prefix'
  00:08:26   609 | T result[2] = {~expect[0], ~expect[1]};  
   \
  00:08:26   |   ~^~
  00:08:27 1 error generated.
  00:08:27 make[3]: *** [scripts/Makefile.build:243: lib/test_scanf.o] Error 1

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/test_scanf.c#n661

Seems like the test should be fixed, though I wonder why this same error isn't 
effecting GCC builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76096

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


[clang] 8a5c0cc - [clangd][clang-tidy][std_symbol_map] Add missing symbol.

2023-08-07 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-08-07T08:41:58Z
New Revision: 8a5c0ccee2938dfec0082024aea664e7338adbe7

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

LOG: [clangd][clang-tidy][std_symbol_map] Add missing symbol.

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

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index aa0bc50445f473..77578baef80a1c 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -363,6 +363,7 @@ SYMBOL(make_integer_sequence, std::, )
 // Symbols missing from the generated symbol map as reported by users.
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
+SYMBOL(any_cast, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"



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


[PATCH] D157256: [clangd][clang-tidy][std_symbol_map] Add missing symbol.

2023-08-07 Thread Viktoriia Bakalova 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 rG8a5c0ccee293: [clangd][clang-tidy][std_symbol_map] Add 
missing symbol. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157256

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -363,6 +363,7 @@
 // Symbols missing from the generated symbol map as reported by users.
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
+SYMBOL(any_cast, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -363,6 +363,7 @@
 // Symbols missing from the generated symbol map as reported by users.
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
+SYMBOL(any_cast, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, ..., _N"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137872: Implement lambdas with inalloca parameters by forwarding to function without inalloca calling convention.

2023-08-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

For those following along, this was relanded in https://reviews.llvm.org/D154007


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137872

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


[clang] 52ac71f - [clang][analyzer] Improve StdCLibraryFunctions socket send/recv functions.

2023-08-07 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-08-07T10:45:09+02:00
New Revision: 52ac71f92d38f75df5cb88e9c090ac5fd5a71548

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

LOG: [clang][analyzer] Improve StdCLibraryFunctions socket send/recv functions.

The modeling of send, recv, sendmsg, recvmsg, sendto, recvfrom is changed:
These functions do not return 0, except if the message length is 0.
(In sendmsg, recvmsg the length is not checkable but it is more likely
that a message with 0 length is invalid for these functions.)

Reviewed By: donat.nagy

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-POSIX.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d18e6f63df4484..f5f6e3a9123768 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -3096,7 +3096,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 auto Recvfrom =
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(0)),
+   ArgumentCondition(2, WithinRange, SingleValue(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
@@ -3123,7 +3126,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 auto Sendto =
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(0)),
+   ArgumentCondition(2, WithinRange, SingleValue(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
@@ -3161,7 +3167,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(0)),
+   ArgumentCondition(2, WithinRange, SingleValue(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
@@ -3179,7 +3188,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 Signature(ArgTypes{IntTy, StructMsghdrPtrTy, IntTy},
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+.Case({ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(
@@ -3191,7 +3200,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 Signature(ArgTypes{IntTy, ConstStructMsghdrPtrTy, IntTy},
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+.Case({ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(
@@ -3233,7 +3242,10 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange

[PATCH] D155715: [clang][analyzer] Improve StdCLibraryFunctions socket send/recv functions.

2023-08-07 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52ac71f92d38: [clang][analyzer] Improve StdCLibraryFunctions 
socket send/recv functions. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155715

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-POSIX.c

Index: clang/test/Analysis/std-c-library-functions-POSIX.c
===
--- clang/test/Analysis/std-c-library-functions-POSIX.c
+++ clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -141,6 +141,8 @@
 
 #include "Inputs/std-c-library-functions-POSIX.h"
 
+void clang_analyzer_eval(int);
+
 void test_open(void) {
   open(0, 0); // \
   // expected-warning{{The 1st argument to 'open' is NULL but should not be NULL}}
@@ -150,3 +152,56 @@
   open(0, 0, 0); // \
   // expected-warning{{The 1st argument to 'open' is NULL but should not be NULL}}
 }
+
+void test_recvfrom(int socket, void *restrict buffer, size_t length, int flags,
+   struct sockaddr *restrict address,
+   socklen_t *restrict address_len) {
+  ssize_t Ret = recvfrom(socket, buffer, length, flags, address, address_len);
+  if (Ret == 0)
+clang_analyzer_eval(length == 0); // expected-warning{{TRUE}}
+  if (Ret > 0)
+clang_analyzer_eval(length > 0); // expected-warning{{TRUE}}
+  if (Ret == -1)
+clang_analyzer_eval(length == 0); // expected-warning{{UNKNOWN}}
+}
+
+void test_sendto(int socket, const void *message, size_t length, int flags,
+ const struct sockaddr *dest_addr, socklen_t dest_len) {
+  ssize_t Ret = sendto(socket, message, length, flags, dest_addr, dest_len);
+  if (Ret == 0)
+clang_analyzer_eval(length == 0); // expected-warning{{TRUE}}
+  if (Ret > 0)
+clang_analyzer_eval(length > 0); // expected-warning{{TRUE}}
+  if (Ret == -1)
+clang_analyzer_eval(length == 0); // expected-warning{{UNKNOWN}}
+}
+
+void test_recv(int sockfd, void *buf, size_t len, int flags) {
+  ssize_t Ret = recv(sockfd, buf, len, flags);
+  if (Ret == 0)
+clang_analyzer_eval(len == 0); // expected-warning{{TRUE}}
+  if (Ret > 0)
+clang_analyzer_eval(len > 0); // expected-warning{{TRUE}}
+  if (Ret == -1)
+clang_analyzer_eval(len == 0); // expected-warning{{UNKNOWN}}
+}
+
+void test_send(int sockfd, void *buf, size_t len, int flags) {
+  ssize_t Ret = send(sockfd, buf, len, flags);
+  if (Ret == 0)
+clang_analyzer_eval(len == 0); // expected-warning{{TRUE}}
+  if (Ret > 0)
+clang_analyzer_eval(len > 0); // expected-warning{{TRUE}}
+  if (Ret == -1)
+clang_analyzer_eval(len == 0); // expected-warning{{UNKNOWN}}
+}
+
+void test_recvmsg(int sockfd, struct msghdr *msg, int flags) {
+  ssize_t Ret = recvmsg(sockfd, msg, flags);
+  clang_analyzer_eval(Ret != 0); // expected-warning{{TRUE}}
+}
+
+void test_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
+  ssize_t Ret = sendmsg(sockfd, msg, flags);
+  clang_analyzer_eval(Ret != 0); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -3096,7 +3096,10 @@
 auto Recvfrom =
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(0)),
+   ArgumentCondition(2, WithinRange, SingleValue(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
@@ -3123,7 +3126,10 @@
 auto Sendto =
 Summary(NoEvalCall)
 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(0)),
+   ArgumentCondition(2, WithinRange, SingleValue(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
@@ -3161,7 +3167,10 @@
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
   

[PATCH] D157227: [Clang] Don't add `undef` for `operator new` under -fno-exceptions.

2023-08-07 Thread DianQK via Phabricator via cfe-commits
DianQK added a comment.

In D157227#4564817 , @nikic wrote:

> Removing noundef makes no sense to me, because the return value is noundef 
> even under fno-exceptions. If we remove something, it should be the nonnull 
> attribute, because that's what's actually being violated.

Return null on nonnull is poison. So I can also think that the noundef 
attribute is violated. I think the reason for keeping nonnull is to match the 
semantics of `operator new`. But that probably doesn't make sense either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157227

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


[PATCH] D157262: [clang-tidy] Add support for in-class initializers in readability-redundant-member-init

2023-08-07 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Support detecting redundant in-class initializers.

Fixes: #62525


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157262

Files:
  clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp
@@ -250,3 +250,55 @@
 S s2;
   };
 };
+
+// Direct in-class initialization with default constructor
+struct D1 {
+  S f1 {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: initializer for member 'f1' is redundant
+  // CHECK-FIXES: S f1;
+};
+
+// Direct in-class initialization with constructor with default argument
+struct D2 {
+  T f2  {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: initializer for member 'f2' is redundant
+  // CHECK-FIXES: T f2;
+};
+
+// Direct in-class initialization with default constructor (assign)
+struct D3 {
+  S f3 = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: initializer for member 'f3' is redundant
+  // CHECK-FIXES: S f3;
+};
+
+// Direct in-class initialization with constructor with default argument (assign)
+struct D4 {
+  T f4 = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: initializer for member 'f4' is redundant
+  // CHECK-FIXES: T f4;
+};
+
+// Templated class independent type
+template 
+struct D5 {
+  S f5 /*comment*/ = S();
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: initializer for member 'f5' is redundant
+  // CHECK-FIXES: S f5 /*comment*/;
+};
+D5 d5i;
+D5 d5s;
+
+struct D6 {
+  UsesCleanup uc2{};
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: initializer for member 'uc2' is redundant
+  // CHECK-FIXES: UsesCleanup uc2;
+};
+
+template
+struct D7 {
+  V f7;
+};
+
+D7 d7i;
+D7 d7s;
Index: clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst
@@ -11,13 +11,14 @@
 
 .. code-block:: c++
 
-  // Explicitly initializing the member s is unnecessary.
+  // Explicitly initializing the member s and v is unnecessary.
   class Foo {
   public:
 Foo() : s() {}
 
   private:
 std::string s;
+std::vector v {};
   };
 
 Options
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 
+- Improved :doc:`readability-redundant-member-init
+  ` check to support
+  in-class initializers.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   ha

[clang] e3c57fd - [clang][RISCV] Fix bug in ABI handling of empty structs with hard FP calling conventions in C++

2023-08-07 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-08-07T10:45:22+01:00
New Revision: e3c57fdd8439ba82c67347629a3c66f293e1f3d0

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

LOG: [clang][RISCV] Fix bug in ABI handling of empty structs with hard FP 
calling conventions in C++

As reported in ,
Clang's handling of empty structs in the case of small structs that may
be eligible to be passed using the hard FP calling convention doesn't
match g++. In general, C++ record fields are never empty unless
[[no_unique_address]] is used, but the RISC-V FP ABI overrides this.

After this patch, fields of structs that contain empty records will be
ignored, even in C++, when considering eligibility for the FP calling
convention ('flattening'). It isn't explicitly noted in the RISC-V
psABI, but arrays of empty records will disqualify a struct for
consideration of using the FP calling convention in g++. This patch
matches that behaviour. The psABI issue
 seeks
to clarify this.

This patch was previously committed but reverted after a bug was found.
This recommit adds additional logic to prevent that bug (adding an extra
check for when a candidate from detectFPCCEligibleStructHelper may not
be valid).

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/ABIInfoImpl.cpp
clang/lib/CodeGen/ABIInfoImpl.h
clang/lib/CodeGen/Targets/RISCV.cpp
clang/test/CodeGen/RISCV/abi-empty-structs.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f03e5231215eb2..4d1ca7afad1f10 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -196,6 +196,9 @@ RISC-V Support
 ^^
 - Unaligned memory accesses can be toggled by ``-m[no-]unaligned-access`` or 
the
   aliases ``-m[no-]strict-align``.
+- An ABI mismatch between GCC and Clang related to the handling of empty
+  structs in C++ parameter passing under the hard floating point calling
+  conventions was fixed.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index 7c30cecfdb9b77..2b20d5a13346d3 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -246,7 +246,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction &CGF, Address 
Addr1,
 }
 
 bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD,
-   bool AllowArrays) {
+   bool AllowArrays, bool AsIfNoUniqueAddr) {
   if (FD->isUnnamedBitfield())
 return true;
 
@@ -280,13 +280,14 @@ bool CodeGen::isEmptyField(ASTContext &Context, const 
FieldDecl *FD,
   // not arrays of records, so we must also check whether we stripped off an
   // array type above.
   if (isa(RT->getDecl()) &&
-  (WasArray || !FD->hasAttr()))
+  (WasArray || (!AsIfNoUniqueAddr && !FD->hasAttr(
 return false;
 
-  return isEmptyRecord(Context, FT, AllowArrays);
+  return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
 }
 
-bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) 
{
+bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
+bool AsIfNoUniqueAddr) {
   const RecordType *RT = T->getAs();
   if (!RT)
 return false;
@@ -297,11 +298,11 @@ bool CodeGen::isEmptyRecord(ASTContext &Context, QualType 
T, bool AllowArrays) {
   // If this is a C++ record, check the bases first.
   if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
 for (const auto &I : CXXRD->bases())
-  if (!isEmptyRecord(Context, I.getType(), true))
+  if (!isEmptyRecord(Context, I.getType(), true, AsIfNoUniqueAddr))
 return false;
 
   for (const auto *I : RD->fields())
-if (!isEmptyField(Context, I, AllowArrays))
+if (!isEmptyField(Context, I, AllowArrays, AsIfNoUniqueAddr))
   return false;
   return true;
 }

diff  --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h
index 5f0cc289af68b3..afde08ba100cf0 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.h
+++ b/clang/lib/CodeGen/ABIInfoImpl.h
@@ -122,13 +122,19 @@ Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,
  llvm::BasicBlock *Block2, const llvm::Twine &Name = "");
 
 /// isEmptyField - Return true iff a the field is "empty", that is it
-/// is an unnamed bit-field or an (array of) empty record(s).
-bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays);
+/// is an unnamed bit-field or an (array of) empty record(s). If
+/// AsIfNoUniqueAddr is true, then C++ record fields are c

[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-08-07 Thread Alex Bradbury via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe3c57fdd8439: [clang][RISCV] Fix bug in ABI handling of 
empty structs with hard FP calling… (authored by asb).

Changed prior to commit:
  https://reviews.llvm.org/D142327?vs=546012&id=547684#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142327

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/abi-empty-structs.c

Index: clang/test/CodeGen/RISCV/abi-empty-structs.c
===
--- clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --full-function-signature --filter "^define |^entry:"
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --filter "^define |^entry:" --version 2
 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
 // RUN:   | FileCheck -check-prefixes=CHECK-C,CHECK32-C %s
 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
@@ -19,8 +19,9 @@
 #include 
 
 // Fields containing empty structs or unions are ignored when flattening
-// structs for the hard FP ABIs, even in C++.
-// FIXME: This isn't currently respected.
+// structs for the hard FP ABIs, even in C++. The rules for arrays of empty
+// structs or unions are subtle and documented in
+// .
 
 struct empty { struct { struct { } e; }; };
 struct s1 { struct empty e; float f; };
@@ -29,13 +30,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s12s1
-// CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s12s1
-// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local float @_Z7test_s12s1
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX:  entry:
 //
 struct s1 test_s1(struct s1 a) {
   return a;
@@ -47,13 +44,9 @@
 // CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s22s2
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S2:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s22s2
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { i32, float } @_Z7test_s22s2
+// CHECK-CXX-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s2 test_s2(struct s2 a) {
   return a;
@@ -65,13 +58,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s32s3
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S3:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s32s3
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s32s3
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s3 test_s3(struct s3 a) {
   return a;
@@ -83,13 +72,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s42s4
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S4:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s42s4
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s42s4
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s4 test_s4(struct s4 a) {
   return a;
@@ -142,7 +127,7 @@
 // CHECK-C:  entry:
 //
 // CHECK-CXX-LABEL: define dso_local float @_Z7test_s72s7
-// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
 // CHECK-CXX:  entry:
 //
 struct s7 test_s7(struct s7 a) {
@@ -156,17 +141,31 @@
 // CHECK-C-SAME: (float [[TMP0:

[PATCH] D155858: Add a concept AST node.

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



Comment at: clang/include/clang/AST/ASTConcept.h:118
 /// template arguments.
-class ConceptReference {
+class ConceptLoc {
 protected:

hokein wrote:
> I'm not sure the  `ConceptLoc` is a reasonable name for this structure.
> 1) In general, classes named `*Loc` in clang AST are tiny, and they are 
> passed by value, so seeing the usage `ConceptLoc *` in the code is a bit 
> wired and inconsistent.
> 2) Unlike other `TemplateArgumentLoc`, `NestedNameSpecifierLoc`, `TypeLoc` 
> (where they all have TemplateArgument/TemplateArgumentLoc split), and we 
> don't have a corresponding split for `ConceptLoc`.
> 
> I think 2) is probably fine, but 1) is a concern, we plan to make it a real 
> AST node, so we will likely add it to the 
> [DynTypedNode](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ASTTypeTraits.h#L508),
>  adding a big class there will increase the `DynTypedNode` a lot (from 40 
> bytes => 80 bytes).  
> 
> One idea is to make this class `ConceptLocInfo`, and create a new wrapper 
> class `ConceptLoc` wrapper which contains a `ConceptLocInfo* pointer`, and a 
> `ConceptDecl* concept`.
> 
> 
Agreed, the name change seems more confusing than anything and not really 
consistent with preexisting names.
It is still unclear to me what is wrong with the current name (and all these 
renamings obfuscate what the patch is actually trying to do)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155858

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


[PATCH] D157074: [clang][ExprConst] Add RHS source range to div by zero diags

2023-08-07 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D157074

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


[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-07 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 547686.
skatrak added a comment.

Declare sets as `inline` inside of header file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157090

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Semantics/openmp-directive-sets.h
  flang/lib/Semantics/check-omp-structure.cpp
  flang/lib/Semantics/check-omp-structure.h
  flang/lib/Semantics/resolve-directives.cpp

Index: flang/lib/Semantics/resolve-directives.cpp
===
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -1345,7 +1345,7 @@
 if (targetIt == dirContext_.rend()) {
   return;
 }
-if (llvm::omp::parallelSet.test(targetIt->directive) ||
+if (llvm::omp::allParallelSet.test(targetIt->directive) ||
 llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
   break;
 }
@@ -1446,7 +1446,7 @@
 return;
   }
   Symbol::Flag ivDSA;
-  if (!llvm::omp::simdSet.test(GetContext().directive)) {
+  if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
 ivDSA = Symbol::Flag::OmpPrivate;
   } else if (level == 1) {
 ivDSA = Symbol::Flag::OmpLinear;
Index: flang/lib/Semantics/check-omp-structure.h
===
--- flang/lib/Semantics/check-omp-structure.h
+++ flang/lib/Semantics/check-omp-structure.h
@@ -17,12 +17,10 @@
 #include "check-directive-structure.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Parser/parse-tree.h"
+#include "flang/Semantics/openmp-directive-sets.h"
 #include "flang/Semantics/semantics.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
-using OmpDirectiveSet = Fortran::common::EnumSet;
-
 using OmpClauseSet =
 Fortran::common::EnumSet;
 
@@ -31,74 +29,6 @@
 
 namespace llvm {
 namespace omp {
-static OmpDirectiveSet parallelSet{Directive::OMPD_distribute_parallel_do,
-Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel,
-Directive::OMPD_parallel_do, Directive::OMPD_parallel_do_simd,
-Directive::OMPD_parallel_sections, Directive::OMPD_parallel_workshare,
-Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet doSet{Directive::OMPD_distribute_parallel_do,
-Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel_do,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_do,
-Directive::OMPD_do_simd, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet doSimdSet{Directive::OMPD_distribute_parallel_do_simd,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_do_simd,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet workShareSet{
-OmpDirectiveSet{Directive::OMPD_workshare,
-Directive::OMPD_parallel_workshare, Directive::OMPD_parallel_sections,
-Directive::OMPD_sections, Directive::OMPD_single} |
-doSet};
-static OmpDirectiveSet taskloopSet{
-Directive::OMPD_taskloop, Directive::OMPD_taskloop_simd};
-static OmpDirectiveSet targetSet{Directive::OMPD_target,
-Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
-Directive::OMPD_target_teams, Directive::OMPD_target_teams_distribute,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_simd};
-static OmpDirectiveSet simdSet{Directive::OMPD_distribute_parallel_do_simd,
-Directive::OMPD_distribute_simd, Directive::OMPD_do_simd,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_simd,
-Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_simd, Directive::OMPD_taskloop_simd,
-Directive::OMPD_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_simd};
-static OmpDirectiveSet teamSet{Directive::OMPD_teams,
-Directive::OMPD_teams_distribute,
-Directive::OMPD_teams_distribute_parallel_do,
-Directive::OMPD_teams_distribute_parallel_do_simd,
-Directive::OMPD_

[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-07 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

`ASTImporter` part looks good, I did not check the generated documentation for 
correctness.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

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


[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-07 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak added a comment.

In D157090#4562088 , 
@kiranchandramohan wrote:

> This looks OK. The only concern is whether we will lose the ability to inline 
> the code for set membership. Can these sets be put in a header file with 
> `inline constexpr`?

Thank you for the suggestion. It's not possible to declare these as `constexpr` 
because `EnumSet::set`, called by the constructor, is not `constexpr` as well. 
But I have made them `const inline` and defined them in the header file. I hope 
that addresses your concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157090

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


[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-07 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

Thanks. LG.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157090

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


[clang] ec70627 - [Flang][Sema] Move directive sets to a shared location

2023-08-07 Thread Sergio Afonso via cfe-commits

Author: Sergio Afonso
Date: 2023-08-07T11:18:43+01:00
New Revision: ec70627dd17703a2a12ce0f28bd3794aa77d2058

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

LOG: [Flang][Sema] Move directive sets to a shared location

This patch moves directive sets defined internally in Semantics to a header
accessible by other stages of the compiler to enable reuse. Some sets are
renamed/rearranged and others are lifted from local definitions to provide
a single source of truth.

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

Added: 
flang/include/flang/Semantics/openmp-directive-sets.h

Modified: 
clang/docs/tools/clang-formatted-files.txt
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/lib/Semantics/resolve-directives.cpp

Removed: 




diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 27aab1e1305245..e22f01e8c150e1 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -2185,6 +2185,8 @@ flang/include/flang/Runtime/time-intrinsic.h
 flang/include/flang/Runtime/transformational.h
 flang/include/flang/Runtime/type-code.h
 flang/include/flang/Semantics/attr.h
+flang/include/flang/Semantics/expression.h
+flang/include/flang/Semantics/openmp-directive-sets.h
 flang/include/flang/Semantics/runtime-type-info.h
 flang/include/flang/Semantics/scope.h
 flang/include/flang/Semantics/semantics.h

diff  --git a/flang/include/flang/Semantics/openmp-directive-sets.h 
b/flang/include/flang/Semantics/openmp-directive-sets.h
new file mode 100644
index 00..5ccd75842b878e
--- /dev/null
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -0,0 +1,283 @@
+//===-- include/flang/Semantics/openmp-directive-sets.h -*- 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
+//
+//===--===//
+
+#ifndef FORTRAN_SEMANTICS_OPENMP_DIRECTIVE_SETS_H_
+#define FORTRAN_SEMANTICS_OPENMP_DIRECTIVE_SETS_H_
+
+#include "flang/Common/enum-set.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+
+using OmpDirectiveSet = Fortran::common::EnumSet;
+
+namespace llvm::omp {
+//===--===//
+// Directive sets for single directives
+//===--===//
+// - topSet: The directive appears alone or as the first in a
+//   combined construct.
+// - allSet: All standalone or combined uses of the directive.
+
+const inline OmpDirectiveSet topParallelSet{
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+};
+
+const inline OmpDirectiveSet allParallelSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_parallel_sections,
+Directive::OMPD_parallel_workshare,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+const inline OmpDirectiveSet topDoSet{
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+};
+
+const inline OmpDirectiveSet allDoSet{
+Directive::OMPD_distribute_parallel_do,
+Directive::OMPD_distribute_parallel_do_simd,
+Directive::OMPD_parallel_do,
+Directive::OMPD_parallel_do_simd,
+Directive::OMPD_do,
+Directive::OMPD_do_simd,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD_target_teams_distribute_parallel_do,
+Directive::OMPD_target_teams_distribute_parallel_do_simd,
+Directive::OMPD_teams_distribute_parallel_do,
+Directive::OMPD_teams_distribute_parallel_do_simd,
+};
+
+const inline OmpDirectiveSet topTaskloopSet{
+Directive::OMPD_taskloop,
+Directive::OMPD_taskloop_simd,
+};
+
+const inline OmpDirectiveSet allTaskloopSet = topTaskloopSet;
+
+const inline OmpDirectiveSet topTargetSet{
+Directive::OMPD_target,
+Directive::OMPD_target_parallel,
+Directive::OMPD_target_parallel_do,
+Directive::OMPD_target_parallel_do_simd,
+Directive::OMPD

[PATCH] D157090: [Flang][Sema] Move directive sets to a shared location

2023-08-07 Thread Sergio Afonso 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 rGec70627dd177: [Flang][Sema] Move directive sets to a shared 
location (authored by skatrak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157090

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Semantics/openmp-directive-sets.h
  flang/lib/Semantics/check-omp-structure.cpp
  flang/lib/Semantics/check-omp-structure.h
  flang/lib/Semantics/resolve-directives.cpp

Index: flang/lib/Semantics/resolve-directives.cpp
===
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -1362,7 +1362,7 @@
 if (targetIt == dirContext_.rend()) {
   return;
 }
-if (llvm::omp::parallelSet.test(targetIt->directive) ||
+if (llvm::omp::allParallelSet.test(targetIt->directive) ||
 llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
   break;
 }
@@ -1463,7 +1463,7 @@
 return;
   }
   Symbol::Flag ivDSA;
-  if (!llvm::omp::simdSet.test(GetContext().directive)) {
+  if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
 ivDSA = Symbol::Flag::OmpPrivate;
   } else if (level == 1) {
 ivDSA = Symbol::Flag::OmpLinear;
Index: flang/lib/Semantics/check-omp-structure.h
===
--- flang/lib/Semantics/check-omp-structure.h
+++ flang/lib/Semantics/check-omp-structure.h
@@ -17,12 +17,10 @@
 #include "check-directive-structure.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Parser/parse-tree.h"
+#include "flang/Semantics/openmp-directive-sets.h"
 #include "flang/Semantics/semantics.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
-using OmpDirectiveSet = Fortran::common::EnumSet;
-
 using OmpClauseSet =
 Fortran::common::EnumSet;
 
@@ -31,74 +29,6 @@
 
 namespace llvm {
 namespace omp {
-static OmpDirectiveSet parallelSet{Directive::OMPD_distribute_parallel_do,
-Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel,
-Directive::OMPD_parallel_do, Directive::OMPD_parallel_do_simd,
-Directive::OMPD_parallel_sections, Directive::OMPD_parallel_workshare,
-Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet doSet{Directive::OMPD_distribute_parallel_do,
-Directive::OMPD_distribute_parallel_do_simd, Directive::OMPD_parallel_do,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_do,
-Directive::OMPD_do_simd, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet doSimdSet{Directive::OMPD_distribute_parallel_do_simd,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_do_simd,
-Directive::OMPD_target_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_parallel_do_simd};
-static OmpDirectiveSet workShareSet{
-OmpDirectiveSet{Directive::OMPD_workshare,
-Directive::OMPD_parallel_workshare, Directive::OMPD_parallel_sections,
-Directive::OMPD_sections, Directive::OMPD_single} |
-doSet};
-static OmpDirectiveSet taskloopSet{
-Directive::OMPD_taskloop, Directive::OMPD_taskloop_simd};
-static OmpDirectiveSet targetSet{Directive::OMPD_target,
-Directive::OMPD_target_parallel, Directive::OMPD_target_parallel_do,
-Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
-Directive::OMPD_target_teams, Directive::OMPD_target_teams_distribute,
-Directive::OMPD_target_teams_distribute_parallel_do,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_simd};
-static OmpDirectiveSet simdSet{Directive::OMPD_distribute_parallel_do_simd,
-Directive::OMPD_distribute_simd, Directive::OMPD_do_simd,
-Directive::OMPD_parallel_do_simd, Directive::OMPD_simd,
-Directive::OMPD_target_parallel_do_simd, Directive::OMPD_target_simd,
-Directive::OMPD_target_teams_distribute_parallel_do_simd,
-Directive::OMPD_target_teams_distribute_simd, Directive::OMPD_taskloop_simd,
-Directive::OMPD_teams_distribute_parallel_do_simd,
-Directive::OMPD_teams_distribute_simd};
-static OmpDirectiveSet teamSet{Directive::OMPD_teams,
-Directive::OMPD_teams_distribute,
-Di

[PATCH] D127762: [Clang][AArch64] Add/implement ACLE keywords for SME.

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 547696.
sdesmalen added a comment.

Added `enum AArch64SMECallConversionKind` to make it explicit when calling
`IsInvalidSMECallConversion` whether or not 'preserves_za' can be dropped
(e.g. in assignment), can be added (e.g. when overriding a parent method)
or must match exactly (e.g. when redefining a function).

I'll post a separate patch for guarding the SME attributes when not
compiling for a target with `sme`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-dump-sme-attributes.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
  clang/test/Modules/aarch64-sme-keywords.cppm
  clang/test/Sema/aarch64-sme-func-attrs.c

Index: clang/test/Sema/aarch64-sme-func-attrs.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sme-func-attrs.c
@@ -0,0 +1,308 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s
+
+// Valid attributes
+
+void sme_arm_streaming(void) __arm_streaming;
+void sme_arm_streaming_compatible(void) __arm_streaming_compatible;
+
+__arm_new_za void sme_arm_new_za(void) {}
+void sme_arm_shared_za(void) __arm_shared_za;
+void sme_arm_preserves_za(void) __arm_preserves_za;
+
+__arm_new_za void sme_arm_streaming_new_za(void) __arm_streaming {}
+void sme_arm_streaming_shared_za(void) __arm_streaming __arm_shared_za;
+void sme_arm_streaming_preserves_za(void) __arm_streaming __arm_preserves_za;
+
+__arm_new_za void sme_arm_sc_new_za(void) __arm_streaming_compatible {}
+void sme_arm_sc_shared_za(void) __arm_streaming_compatible __arm_shared_za;
+void sme_arm_sc_preserves_za(void) __arm_streaming_compatible __arm_preserves_za;
+
+void sme_arm_shared_preserves_za(void) __arm_shared_za __arm_preserves_za;
+
+__arm_locally_streaming void sme_arm_locally_streaming(void) { }
+__arm_locally_streaming void sme_arm_streaming_and_locally_streaming(void) __arm_streaming { }
+__arm_locally_streaming void sme_arm_streaming_and_streaming_compatible(void) __arm_streaming_compatible { }
+
+__arm_locally_streaming __arm_new_za void sme_arm_ls_new_za(void) { }
+__arm_locally_streaming void sme_arm_ls_shared_za(void) __arm_shared_za { }
+__arm_locally_streaming void sme_arm_ls_preserves_za(void) __arm_preserves_za { }
+
+// Valid attributes on function pointers
+
+void streaming_ptr(void) __arm_streaming;
+typedef  void (*fptrty1) (void) __arm_streaming;
+fptrty1 call_streaming_func() { return streaming_ptr; }
+
+void streaming_compatible_ptr(void) __arm_streaming_compatible;
+typedef void (*fptrty2) (void) __arm_streaming_compatible;
+fptrty2 call_sc_func() { return streaming_compatible_ptr; }
+
+void shared_za_ptr(void) __arm_shared_za;
+typedef void (*fptrty3) (void) __arm_shared_za;
+fptrty3 call_shared_za_func() { return shared_za_ptr; }
+
+void preserves_za_ptr(void) __arm_preserves_za;
+typedef void (*fptrty4) (void) __arm_preserves_za;
+fptrty4 call_preserve_za_func() { return preserves_za_ptr; }
+
+void shared_preserves_za_ptr(void) __arm_shared_za __arm_preserves_za;
+typedef void (*fptrty5) (void) __arm_shared_za __arm_preserves_za;
+fptrty5 call_shared_preserve_za_func() { return shared_preserves_za_ptr; }
+
+typedef void (*fptrty6) (void);
+fptrty6 cast_nza_func_to_normal() { return sme_arm_new_za; }
+fptrty6 cast_ls_func_to_normal() { return sme_arm_locally_streaming; }
+
+// Invalid attributes
+
+// expected-cpp-error@+4 {{'__arm_streaming_compatible' and '__arm_streaming' are not compatible}}
+// expected-cpp-note@+3 {{conflicting attribute is here}}
+// expected-error@+2 {{'__arm_streaming_compatible' and '__arm_streaming' are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void streaming_mode(void) __arm_streaming __arm_streaming_compatible;
+
+// expected-cpp-error@+4 {{'__arm_streaming' and '__arm_streaming_compatible' are not compatible}}
+// expected-cpp-note@+3 {{conflicting attribute is here}}
+// expected-error@+2 {{'__arm_streaming' and '__arm_streaming_compatible' are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void streaming_compatible(void) __arm_streaming_compatible __arm_streaming;
+
+// expecte

[PATCH] D157269: [Clang][AArch64] Diagnostics for SME attributes when target doesn't have 'sme'

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: rsandifo-arm, aaron.ballman.
Herald added subscribers: ctetreau, hiraditya, kristof.beyls.
Herald added a project: All.
sdesmalen requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch adds error diagnostics to Clang when code uses the AArch64 SME
attributes without specifying 'sme' as available target attribute.

- Function definitions marked as '__arm_streaming', '__arm_locally_streaming', 
'__arm_shared_za' or '__arm_new_za' will by definition use or require SME 
instructions.
- Calls from non-streaming functions to streaming-functions require the 
compiler to enable/disable streaming-SVE mode around the call-site.

In some cases we can accept the SME attributes without having 'sme' enabled:

- Function declaration can have the SME attributes.
- Definitions can be __arm_streaming_compatible since the generated code should 
execute on processing elements without SME.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157269

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp
  llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
  
llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll

Index: llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc < %s | FileCheck %s
+
+; This that the following code can be compiled without +sme, because if the
+; call is not entered in streaming-SVE mode at runtime, the codepath leading
+; to the smstop/smstart pair will not be executed either.
+
+target triple = "aarch64"
+
+define void @streaming_compatible() #0 {
+; CHECK-LABEL: streaming_compatible:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:stp d15, d14, [sp, #-80]! // 16-byte Folded Spill
+; CHECK-NEXT:stp d13, d12, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT:stp d11, d10, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:stp d9, d8, [sp, #48] // 16-byte Folded Spill
+; CHECK-NEXT:stp x30, x19, [sp, #64] // 16-byte Folded Spill
+; CHECK-NEXT:bl __arm_sme_state
+; CHECK-NEXT:and x19, x0, #0x1
+; CHECK-NEXT:tbz x19, #0, .LBB0_2
+; CHECK-NEXT:  // %bb.1:
+; CHECK-NEXT:msr SVCRSM, #0
+; CHECK-NEXT:  .LBB0_2:
+; CHECK-NEXT:bl non_streaming
+; CHECK-NEXT:tbz x19, #0, .LBB0_4
+; CHECK-NEXT:  // %bb.3:
+; CHECK-NEXT:msr SVCRSM, #1
+; CHECK-NEXT:  .LBB0_4:
+; CHECK-NEXT:ldp x30, x19, [sp, #64] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d11, d10, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d13, d12, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d15, d14, [sp], #80 // 16-byte Folded Reload
+; CHECK-NEXT:ret
+  call void @non_streaming()
+  ret void
+}
+
+declare void @non_streaming()
+
+attributes #0 = { nounwind "aarch64_pstate_sm_compatible" "target-features"="+sve" }
Index: llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
===
--- llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
@@ -154,6 +154,13 @@
   let Inst{11-9} = pstatefield;
   let Inst{8} = imm;
   let Inst{7-5} = 0b011; // op2
+
+  // Rather than only allowing this instruction with '+sme', we also
+  // allow it with '+sve', such that we can still emit the instruction
+  // for streaming-compatible functions which call non-streaming functions.
+  // The SME smstart/smstop will only be executed at runtime if streaming-mode
+  // is enabled, which also means SME must be enabled.
+  let Predicates = [HasSVEorSME];
 }
 
 def : InstAlias<"smstart",(MSRpstatesvcrImm1 0b011, 0b1)>;
@@ -226,11 +233,13 @@
 def : Pat<(AArch64_smstop (i32 svcr_op:$pstate), (i64 0), (i64 1)),   // after call
   (MSRpstatesvcrImm1 svcr_op:$pstate, 0b0)>;
 
+let Predicates = [HasSVEorSME] in {
 // The generic case which gets expanded to a pseudo node.
 def : Pat<(AArch64_smstart (i32 svcr_op:$pstate), (i64 GPR64:$rtpstate), (i64 timm0_1:$expected_pstate)),
   (MSRpstatePseudo svcr_op:$pstate, 0b1, GPR64:$rtpstate, timm0_1:$expected_pstate)>;
 def : Pat<(AArch64_smstop (i32 svcr_op:$pstate), (i64 GPR64:$rtpstate), (i64 timm0_1:$expected_pstate)),
   (MSRpstatePseudo svcr_op:$pstate, 0b0, GPR64:$rtpstate, timm0_1:$expected_pstate)>;
+}
 
 // Read and write TPIDR2_EL0
 def : Pat<(int_aarch64_sme_set_tpidr2 i64:$val),
Index: clang/test/Sema/aarch64-sme-func-attrs-withou

[PATCH] D157270: [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: rsandifo-arm, aaron.ballman.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
sdesmalen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The caller is required to have ZA state if it wants to share it with a callee.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157270

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/aarch64-sme-func-attrs.c


Index: clang/test/Sema/aarch64-sme-func-attrs.c
===
--- clang/test/Sema/aarch64-sme-func-attrs.c
+++ clang/test/Sema/aarch64-sme-func-attrs.c
@@ -178,6 +178,21 @@
 void redecl_nopreserve_za(void) __arm_shared_za;
 void redecl_nopreserve_za(void) __arm_shared_za __arm_preserves_za {}
 
+void non_za_definition(void) {
+  sme_arm_new_za(); // OK
+  // expected-error@+2 {{call to a shared ZA function requires the caller to 
have ZA state}}
+  // expected-cpp-error@+1 {{call to a shared ZA function requires the caller 
to have ZA state}}
+  sme_arm_shared_za();
+}
+
+void shared_za_definition(void) __arm_shared_za {
+  sme_arm_shared_za(); // OK
+}
+
+__arm_new_za void new_za_definition(void) {
+  sme_arm_shared_za(); // OK
+}
+
 #ifdef __cplusplus
 struct S {
   virtual void shared_za_memberfn(void) __arm_shared_za;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -6725,6 +6725,22 @@
 Diag(Loc, diag::err_sme_call_in_non_sme_target);
   }
 }
+
+// If the callee uses AArch64 SME ZA state but the caller doesn't define
+// any, then this is an error.
+if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateZASharedMask) {
+  bool CallerHasZAState = false;
+  if (auto *CallerFD = dyn_cast(CurContext)) {
+if (CallerFD->hasAttr())
+  CallerHasZAState = true;
+else if (const auto *FPT = 
CallerFD->getType()->getAs())
+  CallerHasZAState |= FPT->getExtProtoInfo().AArch64SMEAttributes &
+  FunctionType::SME_PStateZASharedMask;
+  }
+
+  if (!CallerHasZAState)
+Diag(Loc, diag::err_sme_za_call_no_za_state);
+}
   }
 
   if (FDecl && FDecl->hasAttr()) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3626,6 +3626,8 @@
   "function declared %0 was previously declared %1, which has different SME 
function attributes">;
 def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires sme">;
+def err_sme_za_call_no_za_state : Error<
+  "call to a shared ZA function requires the caller to have ZA state">;
 def err_sme_definition_in_non_sme_target : Error<
   "function executed in streaming-SVE mode or using ZA state, requires sme">;
 def err_cconv_change : Error<


Index: clang/test/Sema/aarch64-sme-func-attrs.c
===
--- clang/test/Sema/aarch64-sme-func-attrs.c
+++ clang/test/Sema/aarch64-sme-func-attrs.c
@@ -178,6 +178,21 @@
 void redecl_nopreserve_za(void) __arm_shared_za;
 void redecl_nopreserve_za(void) __arm_shared_za __arm_preserves_za {}
 
+void non_za_definition(void) {
+  sme_arm_new_za(); // OK
+  // expected-error@+2 {{call to a shared ZA function requires the caller to have ZA state}}
+  // expected-cpp-error@+1 {{call to a shared ZA function requires the caller to have ZA state}}
+  sme_arm_shared_za();
+}
+
+void shared_za_definition(void) __arm_shared_za {
+  sme_arm_shared_za(); // OK
+}
+
+__arm_new_za void new_za_definition(void) {
+  sme_arm_shared_za(); // OK
+}
+
 #ifdef __cplusplus
 struct S {
   virtual void shared_za_memberfn(void) __arm_shared_za;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -6725,6 +6725,22 @@
 Diag(Loc, diag::err_sme_call_in_non_sme_target);
   }
 }
+
+// If the callee uses AArch64 SME ZA state but the caller doesn't define
+// any, then this is an error.
+if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateZASharedMask) {
+  bool CallerHasZAState = false;
+  if (auto *CallerFD = dyn_cast(CurContext)) {
+if (CallerFD->hasAttr())
+  CallerHasZAState = true;
+else if (const auto *FPT = CallerFD->getType()->getAs())
+  CallerHasZAState |= FPT->getExtProtoInfo().AArch64SMEAttributes &
+  FunctionType::SME_PStateZASharedMask;
+  }
+
+  if (!CallerHasZAState)
+Diag(Loc, diag::err_sme_za_call_no_za_state);
+

[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm

Maybe we want this for the release/17.x branch too?


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

https://reviews.llvm.org/D157245

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


[PATCH] D128256: [Clang][AArch64] Limit arm_locally_streaming to function definitions only.

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen abandoned this revision.
sdesmalen added a comment.

This patch can be abandoned, since this is now properly implemented in D127762 
 as a declaration attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128256

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-07 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 updated this revision to Diff 547703.
yichi170 added a comment.

updated ReleaseNotes and applied suggestions. The related issue #63443 
 is still not fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/offsetof.c


Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // 
expected-warning{{indirection of non-volatile null pointer}} 
expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16663,6 +16663,9 @@
<< CurrentType);
 RecordDecl *RD = RC->getDecl();
 
+if (OC.isQualifier && RD->getIdentifier() == OC.U.IdentInfo)
+  continue;
+
 // C++ [lib.support.types]p5:
 //   The macro offsetof accepts a restricted set of type arguments in this
 //   International Standard. type shall be a POD structure or a POD union
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2641,10 +2641,13 @@
 
 // FIXME: This loop leaks the index expressions on error.
 while (true) {
-  if (Tok.is(tok::period)) {
+  if (Tok.is(tok::period) || Tok.is(tok::coloncolon)) {
 // offsetof-member-designator: offsetof-member-designator '.' 
identifier
+if (Tok.is(tok::coloncolon))
+  Comps.back().isQualifier = true;
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = false;
+Comps.back().isQualifier = false;
 Comps.back().LocStart = ConsumeToken();
 
 if (Tok.isNot(tok::identifier)) {
@@ -2661,6 +2664,7 @@
 // offsetof-member-designator: offsetof-member-design '[' expression 
']'
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = true;
+Comps.back().isQualifier = false;
 BalancedDelimiterTracker ST(*this, tok::l_square);
 ST.consumeOpen();
 Comps.back().LocStart = ST.getOpenLocation();
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6036,6 +6036,7 @@
   struct OffsetOfComponent {
 SourceLocation LocStart, LocEnd;
 bool isBrackets;  // true if [expr], false if .ident
+bool isQualifier;
 union {
   IdentifierInfo *IdentInfo;
   Expr *E;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -56,6 +56,7 @@
 
 C++ Language Changes
 
+- Improved `__builtin_offsetof` support, allowing qualified name in member 
designator.
 
 C++20 Feature Support
 ^


Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // expected-error{{no member named 'X2'}}
+
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16663,6 +16663,9 @@
<< CurrentType);
 RecordDecl *RD = RC->getDecl();
 
+if (OC.isQualifier && RD->getIdentifier() == OC.U.IdentInfo)
+  continue;
+
 // C++ [lib.support.types]p5:
 //   The macro offsetof accepts a restricted set of type arguments in this
 //   International Standard. type shall be a POD structure or a POD union
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2641,10 +2641,13 @@
 
 // FIXME: This loop leaks the index expressions on error.
 wh

[PATCH] D56644: [clang-tidy] readability-container-size-empty handle std::string length()

2023-08-07 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547704.
PiotrZSL marked 10 inline comments as done.
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

rebase, add support for dependent context, update documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D56644

Files:
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -105,9 +105,13 @@
   std::string str2;
   std::wstring wstr;
   (void)(str.size() + 0);
+  (void)(str.length() + 0);
   (void)(str.size() - 0);
+  (void)(str.length() - 0);
   (void)(0 + str.size());
+  (void)(0 + str.length());
   (void)(0 - str.size());
+  (void)(0 - str.length());
   if (intSet.size() == 0)
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
@@ -124,11 +128,19 @@
   // CHECK-FIXES: {{^  }}if (s_func().empty()){{$}}
   if (str.size() == 0)
 ;
-  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size'
+  // CHECK-FIXES: {{^  }}if (str.empty()){{$}}
+  if (str.length() == 0)
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'length'
   // CHECK-FIXES: {{^  }}if (str.empty()){{$}}
   if ((str + str2).size() == 0)
 ;
-  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size'
+  // CHECK-FIXES: {{^  }}if ((str + str2).empty()){{$}}
+  if ((str + str2).length() == 0)
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'length'
   // CHECK-FIXES: {{^  }}if ((str + str2).empty()){{$}}
   if (str == "")
 ;
@@ -140,7 +152,11 @@
   // CHECK-FIXES: {{^  }}if ((str + str2).empty()){{$}}
   if (wstr.size() == 0)
 ;
-  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size'
+  // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
+  if (wstr.length() == 0)
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'length'
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
   if (wstr == L"")
 ;
@@ -149,7 +165,7 @@
   std::vector vect;
   if (vect.size() == 0)
 ;
-  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size'
   // CHECK-FIXES: {{^  }}if (vect.empty()){{$}}
   if (vect == std::vector())
 ;
@@ -504,6 +520,17 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
   // CHECK-MESSAGES: :33:8: note: method 'TemplatedContainer'::empty() defined here
   // CHECK-FIXES: CHECKSIZE(templated_container);
+  std::basic_string s;
+  if (s.size())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+  // CHECK-MESSAGES: string:28:8: note: method 'basic_string'::empty() defined here
+  // CHECK-FIXES: {{^  }}if (!s.empty()){{$}}
+  if (s.length())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'length' [readability-container-size-empty]
+  // CHECK-MESSAGES: string:28:8: note: method 'basic_string'::empty() defined here
+  // CHECK-FIXES: {{^  }}if (!s.empty()){{$}}
 }
 
 void g() {
@@ -753,7 +780,7 @@
   return value.size() == 0U;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
 // CHECK-FIXES: {{^  }}return value.empty();{{$}}
-// CHECK-MESSAGES: :731:8: note: method 'array'::empty() defined here
+// CHECK-MESSAGES: :[[@LINE-25]]:8: note: method 'array'::empty() defined here
 }
 
 bool testArrayCom

[PATCH] D139028: [RFC][clang] Add attribute-like keywords

2023-08-07 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm abandoned this revision.
rsandifo-arm added a comment.

Superceded by D148700 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139028

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


[PATCH] D56644: [clang-tidy] readability-container-size-empty handle std::string length()

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



Comment at: test/clang-tidy/readability-container-size-empty.cpp:135
+  // CHECK-FIXES: {{^  }}if (str.empty()){{$}}
+  if (str.length() == 0)
+;

MyDeveloperDay wrote:
> could you add a  test that checks if StringRef.str().length() >0 becomes 
> !StringRef.str.empty()
> 
> e.g. 
> 
> 
> ```
> LLVM::StringRef ArgRef;
> 
> return (ArgRef.str().length() > 0) ? ArgRef.str() + ")" : "()";
> ```
No point, should work anyway. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D56644

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


[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-07 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D157238#4565051 , @balazske wrote:

> `ASTImporter` part looks good, I did not check the generated documentation 
> for correctness.

Matcher part will be committed in https://reviews.llvm.org/D157237, these code 
is added here only to support this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

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


[PATCH] D156116: [Clang][LoongArch] Fix ABI handling of empty structs in C++ to match GCC behaviour

2023-08-07 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 547711.
SixWeining added a comment.

add an extra check for when a candidate from detectFAREligibleStructHelper may 
not be valid


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156116

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c

Index: clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
===
--- clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,6 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// FIXME: This isn't currently respected.
 // Fields containing empty structs or unions are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
@@ -16,7 +15,7 @@
 struct s1 { struct empty e; float f; };
 
 // CHECK-C: define{{.*}} float @test_s1(float {{.*}})
-// CHECK-CXX: define{{.*}} i64 @_Z7test_s12s1(i64 {{.*}})
+// CHECK-CXX: define{{.*}} float @_Z7test_s12s1(float {{.*}})
 struct s1 test_s1(struct s1 a) {
   return a;
 }
@@ -24,7 +23,7 @@
 struct s2 { struct empty e; int32_t i; float f; };
 
 // CHECK-C: define{{.*}} { i32, float } @test_s2(i32 {{.*}}, float {{.*}})
-// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s22s2([2 x i64] {{.*}})
+// CHECK-CXX: define{{.*}} { i32, float } @_Z7test_s22s2(i32 {{.*}}, float {{.*}})
 struct s2 test_s2(struct s2 a) {
   return a;
 }
@@ -32,7 +31,7 @@
 struct s3 { struct empty e; float f; float g; };
 
 // CHECK-C: define{{.*}} { float, float } @test_s3(float {{.*}}, float {{.*}})
-// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s32s3([2 x i64] {{.*}})
+// CHECK-CXX: define{{.*}} { float, float } @_Z7test_s32s3(float {{.*}}, float {{.*}})
 struct s3 test_s3(struct s3 a) {
   return a;
 }
@@ -40,7 +39,7 @@
 struct s4 { struct empty e; float __complex__ c; };
 
 // CHECK-C: define{{.*}} { float, float } @test_s4(float {{.*}}, float {{.*}})
-// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s42s4([2 x i64] {{.*}})
+// CHECK-CXX: define{{.*}} { float, float } @_Z7test_s42s4(float {{.*}}, float {{.*}})
 struct s4 test_s4(struct s4 a) {
   return a;
 }
@@ -77,7 +76,14 @@
 struct s8 { struct empty_arr0 e; float f; };
 
 // CHECK-C: define{{.*}} float @test_s8(float {{.*}})
-// CHECK-CXX: define{{.*}} i64 @_Z7test_s82s8(i64 {{.*}})
+// CHECK-CXX: define{{.*}} float @_Z7test_s82s8(float {{.*}})
 struct s8 test_s8(struct s8 a) {
   return a;
 }
+
+// CHECK-C: define{{.*}} void @test_s9()
+// CHECK-CXX: define{{.*}} i64 @_Z7test_s92s9(i64 {{.*}})
+struct s9 { struct empty e; };
+struct s9 test_s9(struct s9 a) {
+  return a;
+}
Index: clang/lib/CodeGen/Targets/LoongArch.cpp
===
--- clang/lib/CodeGen/Targets/LoongArch.cpp
+++ clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -148,6 +148,13 @@
   if (const ConstantArrayType *ATy = getContext().getAsConstantArrayType(Ty)) {
 uint64_t ArraySize = ATy->getSize().getZExtValue();
 QualType EltTy = ATy->getElementType();
+// Non-zero-length arrays of empty records make the struct ineligible to be
+// passed via FARs in C++.
+if (const auto *RTy = EltTy->getAs()) {
+  if (ArraySize != 0 && isa(RTy->getDecl()) &&
+  isEmptyRecord(getContext(), EltTy, true, true))
+return false;
+}
 CharUnits EltSize = getContext().getTypeSizeInChars(EltTy);
 for (uint64_t i = 0; i < ArraySize; ++i) {
   if (!detectFARsEligibleStructHelper(EltTy, CurOff, Field1Ty, Field1Off,
@@ -163,7 +170,7 @@
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true))
+if (isEmptyRecord(getContext(), Ty, true, true))
   return true;
 const RecordDecl *RD = RTy->getDecl();
 // Unions aren't eligible unless they're empty (which is caught above).
@@ -222,6 +229,8 @@
   if (!detectFARsEligibleStructHelper(Ty, CharUnits::Zero(), Field1Ty,
   Field1Off, Field2Ty, Field2Off))
 return false;
+  if (!Field1Ty)
+return false;
   // Not really a candidate if we have a single int but no float.
   if (Field1Ty && !Field2Ty && !Field1Ty->isFloatingPointTy())
 return false;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -192,6 +192,9 @@
 LoongArch Support
 ^
 
+- An ABI mismatch between GCC and Clang related to the handling of empty structs
+  in C+

[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement

2023-08-07 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 547712.
yronglin added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157195

Files:
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -95,6 +95,8 @@
 TEST_EVALUATE(ForRange, for (auto x : !!){}); // expected-error + {{}}
 TEST_EVALUATE(While, while (!!){});   // expected-error + {{}}
 TEST_EVALUATE(DoWhile, do {} while (!!););// expected-error + {{}}
+TEST_EVALUATE(DoWhileCond, do {} while (some_cond < 10););// 
expected-error {{use of undeclared identifier}}  \
+  // 
expected-error {{constexpr variable 'forceEvaluateDoWhileCond' must be 
initialized by a constant expression}}
 TEST_EVALUATE(If, if (!!){};);// expected-error + {{}}
 TEST_EVALUATE(IfInit, if (auto x = !!; 1){};);// expected-error + {{}}
 TEST_EVALUATE(ForInit, if (!!;;){};); // expected-error + {{}}
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -420,3 +420,15 @@
   // CHECK:  RecoveryExpr {{.*}} '' contains-errors lvalue
   // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *'
 }
+
+void RecoveryToDoWhileStmtCond() {
+  // CHECK:   FunctionDecl {{.*}} RecoveryToDoWhileStmtCond
+  // CHECK:   `-DoStmt {{.*}}
+  // CHECK-NEXT:|-CompoundStmt {{.*}}
+  // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors 
'<'
+  // CHECK-NEXT:  |-BinaryOperator {{.*}} '' 
contains-errors '+'
+  // CHECK-NEXT:  | |-RecoveryExpr {{.*}} '' 
contains-errors lvalue
+  // CHECK-NEXT:  | `-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 10
+  do {} while (some_invalid_val + 1 < 10);
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1894,7 +1894,8 @@
   ExprResult Cond = ParseExpression();
   // Correct the typos in condition before closing the scope.
   if (Cond.isUsable())
-Cond = Actions.CorrectDelayedTyposInExpr(Cond);
+Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl=*/nullptr,
+ /*RecoverUncorrectedTypos=*/true);
   else {
 if (!Tok.isOneOf(tok::r_paren, tok::r_square, tok::r_brace))
   SkipUntil(tok::semi);


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -95,6 +95,8 @@
 TEST_EVALUATE(ForRange, for (auto x : !!){}); // expected-error + {{}}
 TEST_EVALUATE(While, while (!!){});   // expected-error + {{}}
 TEST_EVALUATE(DoWhile, do {} while (!!););// expected-error + {{}}
+TEST_EVALUATE(DoWhileCond, do {} while (some_cond < 10););// expected-error {{use of undeclared identifier}}  \
+  // expected-error {{constexpr variable 'forceEvaluateDoWhileCond' must be initialized by a constant expression}}
 TEST_EVALUATE(If, if (!!){};);// expected-error + {{}}
 TEST_EVALUATE(IfInit, if (auto x = !!; 1){};);// expected-error + {{}}
 TEST_EVALUATE(ForInit, if (!!;;){};); // expected-error + {{}}
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -420,3 +420,15 @@
   // CHECK:  RecoveryExpr {{.*}} '' contains-errors lvalue
   // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *'
 }
+
+void RecoveryToDoWhileStmtCond() {
+  // CHECK:   FunctionDecl {{.*}} RecoveryToDoWhileStmtCond
+  // CHECK:   `-DoStmt {{.*}}
+  // CHECK-NEXT:|-CompoundStmt {{.*}}
+  // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<'
+  // CHECK-NEXT:  |-BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT:  | |-RecoveryExpr {{.*}} '' contains-errors lvalue
+  // CHECK-NEXT:  | `-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 10
+  do {} while (some_invalid_val + 1 < 10);
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1894,7 +1894,8 @@
   ExprResult Cond =

[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement

2023-08-07 Thread Yurong via Phabricator via cfe-commits
yronglin marked 2 inline comments as done.
yronglin added a comment.

Thanks for your review! @hokein @tbaeder




Comment at: clang/lib/Parse/ParseStmt.cpp:1897-1898
   if (Cond.isUsable())
-Cond = Actions.CorrectDelayedTyposInExpr(Cond);
+Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr,
+ /*RecoveryUncorrectedTypos*/ 
true);
   else {

tbaeder wrote:
> 
Thanks, done!



Comment at: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp:81
 
+constexpr int test13() { do {} while (a < 10); return 0; }   // expected-error 
{{use of undeclared identifier}}
+static_assert(test13());  // expected-error {{static assertion expression is 
not an integral constant expression}}

hokein wrote:
> nit: it is better to use the below `TEST_EVALUATE` macro for the test, 
> `TEST_EVALUATE(DoWhile2, do {} while (undefined < 10); )`
Thanks, done!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157195

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-07 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 added inline comments.



Comment at: clang/test/Sema/offsetof.c:79
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+

Fznamznon wrote:
> It probably makes sense to also add a test with static member of a class, 
> like Aaron mentioned in GitHub - 
> https://github.com/llvm/llvm-project/issues/64154#issuecomment-1653468938 .
Hi @Fznamznon, I found that clang and clang++ output different errors with the 
following test.
```
struct X2 { int a; static int static_a; };
int x4[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1];
// expected-error{{no member named 'static_a'}}
```
C doesn't allow to have a static member in the struct, so is there any way to 
write the correct comment to make the test pass?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


[clang] 4d3e917 - [Clang] Make __arm_streaming apply only to prototyped functions.

2023-08-07 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2023-08-07T11:31:44Z
New Revision: 4d3e91783938291cc53880a0e6c0689b8f2b2970

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

LOG: [Clang] Make __arm_streaming apply only to prototyped functions.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/test/Parser/c2x-attribute-keywords.c
clang/test/Parser/c2x-attribute-keywords.m
clang/test/Parser/cxx0x-keyword-attributes.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index d5204b28696672..1cd5d8a1f55289 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2435,7 +2435,8 @@ def AArch64SVEPcs: DeclOrTypeAttr {
 
 def ArmStreaming : TypeAttr, TargetSpecificAttr {
   let Spellings = [RegularKeyword<"__arm_streaming">];
-  let Documentation = [ArmStreamingDocs];
+  let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
+  let Documentation = [ArmSmeStreamingDocs];
 }
 
 def Pure : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index cd1d298b0a8ff6..fb7e2ebb0bf2ae 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6581,7 +6581,7 @@ Requirements on Development Tools - Engineering 
Specification Documentation
   }];
 }
 
-def ArmStreamingDocs : Documentation {
+def ArmSmeStreamingDocs : Documentation {
   let Category = DocCatType;
   let Content = [{
 .. Note:: This attribute has not been implemented yet, but once it is
@@ -6598,6 +6598,8 @@ It applies to function types and specifies that the 
function has a
 
 * the function must return in streaming mode
 
+* the function does not have a K&R-style unprototyped function type.
+
 See `Procedure Call Standard for the Arm® 64-bit Architecture (AArch64)
 `_ for more details about
 streaming-interface functions.

diff  --git a/clang/test/Parser/c2x-attribute-keywords.c 
b/clang/test/Parser/c2x-attribute-keywords.c
index 757dc82860110a..d8291b710e6db6 100644
--- a/clang/test/Parser/c2x-attribute-keywords.c
+++ b/clang/test/Parser/c2x-attribute-keywords.c
@@ -1,13 +1,13 @@
 // RUN: %clang_cc1 -fsyntax-only -triple aarch64-none-linux-gnu 
-target-feature +sme -verify=expected,notc2x -Wno-strict-prototypes %s
 // RUN: %clang_cc1 -fsyntax-only -triple aarch64-none-linux-gnu 
-target-feature +sme -verify=expected,c2x %s
 
-enum __arm_streaming E { // expected-error {{'__arm_streaming' cannot be 
applied to a declaration}}
-  One __arm_streaming, // expected-error {{'__arm_streaming' cannot be applied 
to a declaration}}
+enum __arm_streaming E { // expected-error {{'__arm_streaming' only applies to 
non-K&R-style functions}}
+  One __arm_streaming, // expected-error {{'__arm_streaming' only applies to 
non-K&R-style functions}}
   Two,
-  Three __arm_streaming // expected-error {{'__arm_streaming' cannot be 
applied to a declaration}}
+  Three __arm_streaming // expected-error {{'__arm_streaming' only applies to 
non-K&R-style functions}}
 };
 
-enum __arm_streaming { Four }; // expected-error {{'__arm_streaming' cannot be 
applied to a declaration}}
+enum __arm_streaming { Four }; // expected-error {{'__arm_streaming' only 
applies to non-K&R-style functions}}
 __arm_streaming enum E2 { Five }; // expected-error {{misplaced 
'__arm_streaming'}}
 
 // FIXME: this diagnostic can be improved.
@@ -16,7 +16,7 @@ enum { __arm_streaming Six }; // expected-error {{expected 
identifier}}
 // FIXME: this diagnostic can be improved.
 enum E3 __arm_streaming { Seven }; // expected-error {{expected identifier or 
'('}}
 
-struct __arm_streaming S1 { // expected-error {{'__arm_streaming' cannot be 
applied to a declaration}}
+struct __arm_streaming S1 { // expected-error {{'__arm_streaming' only applies 
to non-K&R-style functions}}
   int i __arm_streaming; // expected-error {{'__arm_streaming' only applies to 
function types}}
   int __arm_streaming j; // expected-error {{'__arm_streaming' only applies to 
function types}}
   int k[10] __arm_streaming; // expected-error {{'__arm_streaming' only 
applies to function types}}
@@ -32,20 +32,20 @@ struct __arm_streaming S1 { // expected-error 
{{'__arm_streaming' cannot be appl
 
 __arm_streaming struct S2 { int a; }; // expected-error {{misplaced 
'__arm_streaming'}}
 struct S3 __arm_streaming { int a; }; // expected-error {{'__arm_streaming' 
cannot appear here}} \
- expected-error {{'__arm_streaming' 
cannot be applied to a declaration}}
+ expected-error {{'_

[PATCH] D152141: [Clang] Make __arm_streaming apply only to prototyped functions.

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d3e91783938: [Clang] Make __arm_streaming apply only to 
prototyped functions. (authored by sdesmalen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152141

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/test/Parser/c2x-attribute-keywords.c
  clang/test/Parser/c2x-attribute-keywords.m
  clang/test/Parser/cxx0x-keyword-attributes.cpp

Index: clang/test/Parser/cxx0x-keyword-attributes.cpp
===
--- clang/test/Parser/cxx0x-keyword-attributes.cpp
+++ clang/test/Parser/cxx0x-keyword-attributes.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu %s
+// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu -target-feature +sme %s
 
 // Need std::initializer_list
 namespace std {
@@ -48,10 +48,10 @@
 struct MemberFnOrder {
   virtual void f() const volatile && noexcept __arm_streaming final = 0;
 };
-struct __arm_streaming struct_attr; // expected-error {{'__arm_streaming' cannot be applied to a declaration}}
-class __arm_streaming class_attr {}; // expected-error {{'__arm_streaming' cannot be applied to a declaration}}
-union __arm_streaming union_attr; // expected-error {{'__arm_streaming' cannot be applied to a declaration}}
-enum __arm_streaming E { }; // expected-error {{'__arm_streaming' cannot be applied to a declaration}}
+struct __arm_streaming struct_attr; // expected-error {{'__arm_streaming' only applies to non-K&R-style functions}}
+class __arm_streaming class_attr {}; // expected-error {{'__arm_streaming' only applies to non-K&R-style functions}}
+union __arm_streaming union_attr; // expected-error {{'__arm_streaming' only applies to non-K&R-style functions}}
+enum __arm_streaming E { }; // expected-error {{'__arm_streaming' only applies to non-K&R-style functions}}
 namespace test_misplacement {
 __arm_streaming struct struct_attr2;  // expected-error {{misplaced '__arm_streaming'}}
 __arm_streaming class class_attr2; // expected-error {{misplaced '__arm_streaming'}}
@@ -60,28 +60,28 @@
 }
 
 // Checks attributes placed at wrong syntactic locations of class specifiers.
-class __arm_streaming __arm_streaming // expected-error 2 {{'__arm_streaming' cannot be applied to a declaration}}
+class __arm_streaming __arm_streaming // expected-error 2 {{'__arm_streaming' only applies to non-K&R-style functions}}
   attr_after_class_name_decl __arm_streaming __arm_streaming; // expected-error {{'__arm_streaming' cannot appear here}} \
- expected-error 2 {{'__arm_streaming' cannot be applied to a declaration}}
+ expected-error 2 {{'__arm_streaming' only applies to non-K&R-style functions}}
 
-class __arm_streaming __arm_streaming // expected-error 2 {{'__arm_streaming' cannot be applied to a declaration}}
+class __arm_streaming __arm_streaming // expected-error 2 {{'__arm_streaming' only applies to non-K&R-style functions}}
  attr_after_class_name_definition __arm_streaming __arm_streaming __arm_streaming{}; // expected-error {{'__arm_streaming' cannot appear here}} \
-expected-error 3 {{'__arm_streaming' cannot be applied to a declaration}}
+expected-error 3 {{'__arm_streaming' only applies to non-K&R-style functions}}
 
-class __arm_streaming c {}; // expected-error {{'__arm_streaming' cannot be applied to a declaration}}
+class __arm_streaming c {}; // expected-error {{'__arm_streaming' only applies to non-K&R-style functions}}
 class c __arm_streaming __arm_streaming x; // expected-error 2 {{'__arm_streaming' only applies to function types}}
 class c __arm_streaming __arm_streaming y __arm_streaming __arm_streaming; // expected-error 4 {{'__arm_streaming' only applies to function types}}
 class c final [(int){0}];
 
 class base {};
-class __arm_streaming __arm_streaming final_class // expected-error 2 {{'__arm_streaming' cannot be applied to a declaration}}
+class __arm_streaming __arm_streaming final_class // expected-error 2 {{'__arm_streaming' only applies to non-K&R-style functions}}
   __arm_streaming alignas(float) final // expected-error {{'__arm_streaming' cannot appear here}} \
-  expected-error {{'__arm_streaming' cannot be applied to a declaration}}
+  expected-error {{'__arm_s

[PATCH] D155978: [SPIR-V] Add SPIR-V logical triple.

2023-08-07 Thread Nathan Gauër via Phabricator via cfe-commits
Keenuts created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Keenuts updated this revision to Diff 544701.
Keenuts added a comment.
Herald added a subscriber: pmatos.
Keenuts updated this revision to Diff 544703.
Keenuts updated this revision to Diff 547682.
Keenuts edited the summary of this revision.
Keenuts added reviewers: Anastasia, mpaszkowski.
Keenuts published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Add the SPIRV define in all SPIRV targets.


Keenuts added a comment.

format fix & rebase


Keenuts added a comment.

rebasing


Clang implements SPIR-V with both Physical32 and Physical64 addressing
models. This commit adds a new triple value for the Logical
addressing model.
This will be required to add the graphics part of the SPIR-V backend (targeting 
vulkan for now).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155978

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/SPIR.cpp
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp

Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -325,6 +325,132 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UnknownOS, T.getOS());
 
+  T = Triple("spirv-unknown-shadermodel-pixel");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Pixel, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-vertex");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Vertex, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-geometry");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Geometry, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-library");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Library, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-raygeneration");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::RayGeneration, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-intersection");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Intersection, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-anyhit");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::AnyHit, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-closesthit");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::ClosestHit, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-miss");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Miss, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-callable");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Callable, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-mesh");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Mesh, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-amplification");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::Unk

[PATCH] D155978: [SPIR-V] Add SPIR-V logical triple.

2023-08-07 Thread Nathan Gauër via Phabricator via cfe-commits
Keenuts updated this revision to Diff 547722.
Keenuts added a comment.
Herald added subscribers: wangpc, s.egerton, simoncook, asb, fedor.sergeev, 
aheejin, dschuff, rampitec.

git-clang-format on changed files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155978

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/SPIR.cpp
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp

Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -325,6 +325,132 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UnknownOS, T.getOS());
 
+  T = Triple("spirv-unknown-shadermodel-pixel");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Pixel, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-vertex");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Vertex, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-geometry");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Geometry, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-library");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Library, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-raygeneration");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::RayGeneration, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-intersection");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Intersection, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-anyhit");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::AnyHit, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-closesthit");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::ClosestHit, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-miss");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Miss, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-callable");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Callable, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-mesh");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Mesh, T.getEnvironment());
+
+  T = Triple("spirv-unknown-shadermodel-amplification");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Amplification, T.getEnvironment());
+
+  T = Triple("spirv1.0-unknown-shadermodel-compute");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::SPIRVSubArch_v10, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::ShaderModel, T.getOS());
+  EXPECT_EQ(Triple::Compute, T.getEnvironment());
+
+  T = Triple("spirv1.1-unknown-shadermodel-compute");
+  EXPECT_EQ(Triple::spirv, T.getArch());
+  EXPECT_EQ(Triple::SPIRVSubArch_v11, T.getSubArch());
+  EXPECT_EQ(Triple::UnknownVend

[PATCH] D157229: Fix edge case in declare target initializer expression

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157229

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D157275: [Driver] Select newest GCC installation on Solaris

2023-08-07 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: pengfei, jrtc27, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

As described in Issue #53709 
, since 
28d58d8fe2094af6902dee7b4d68ec30a3e9d737 
 `clang` 
doesn't find the latest of several parallel GCC installations on Solaris, but 
only the first in directory order, which is pretty random.

Since this breaks basic functionality of the Solaris port, this patch restores 
scanning all prefixes for GCC installations.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157275

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0/sparcv8plus/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.4.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/amd64/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/i386-pc-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3/sparcv9/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/32/crtbegin.o
  
clang/test/Driver/Inputs/solaris_multi_gcc_tree/usr/gcc/7/lib/gcc/x86_64-pc-solaris2.11/7.5.0/crtbegin.o
  clang/test/Driver/solaris-multi-gcc-search.test


Index: clang/test/Driver/solaris-multi-gcc-search.test
===
--- /dev/null
+++ clang/test/Driver/solaris-multi-gcc-search.test
@@ -0,0 +1,60 @@
+/// Check that clang uses the latest available Solaris GCC installation.
+
+/// Check sparc-sun-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARC %s
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0
+// CHECK-SPARC-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARC-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARC-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARC-NEXT: Selected multilib: sparcv8plus;@m32
+
+/// Check i386-pc-solaris2.11, 32-bit
+// RUN: %clang -v 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-I386 %s
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/i386-pc-solaris2.11/4.7.3
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/x86_64-pc-solaris2.11/7.5.0
+// CHECK-I386-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386: Selected GCC installation: 
{{.*}}11/lib/gcc/x86_64-pc-solaris2.11/11.4.0
+// CHECK-I386-NEXT: Candidate multilib: .;@m64
+// CHECK-I386-NEXT: Candidate multilib: 32;@m32
+// CHECK-I386-NEXT: Selected multilib: 32;@m32
+
+/// Check sparcv9-sun-solaris2.11, 64-bit
+// RUN: %clang -v 2>&1 --target=sparcv9-sun-solaris2.11 \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/solaris_multi_gcc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-SPARCV9 %s
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}4.7/lib/gcc/sparc-sun-solaris2.11/4.7.3
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}7/lib/gcc/sparcv9-sun-solaris2.11/7.5.0
+// CHECK-SPARCV9-DAG: Found candidate GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9: Selected GCC installation: 
{{.*}}11/lib/gcc/sparcv9-sun-solaris2.11/11.4.0
+// CHECK-SPARCV9-NEXT: Candidate multilib: .;@m64
+// CHECK-SPARCV9-NEXT: Candidate multilib: sparcv8plus;@m32
+// CHECK-SPARCV9-NEXT: Selected multilib: .;@m64
+
+/

[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-08-07 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

I've noticed several shortcoming/limitations of this patch.

1. Function arguments: When we parse the arguments to a function call, the 
callee isn't still resolved, so we don't know whether it's consteval. If the 
callee is consteval, its argument is known to be constant-evaluated regardless 
of its surrounding evaluation context.

e.g.

  consteval int ce(int n){ return n;};
  int f() {
int a = ce(__builtin_is_constant_evaluated()); // tautologically true
  }

2. init-statement of constexpr-if:

The condition is required to be a constant expression, but the init-stmt before 
it isn't.
e.g. Given `if constexpr (InitStmt; Cond) {}`, `InitStmt` is evaluated in the 
surrounding evaluation context.
If the init-statement is a declaration we can push initializer evaluation 
context like we do in other variables. However, if the init-statement is an 
expression, when clang parses the expression, clang doesn't know whether it is 
parsing the init-statement or the condition. 
https://github.com/llvm/llvm-project/blob/e3c57fdd8439ba82c67347629a3c66f293e1f3d0/clang/lib/Parse/ParseExprCXX.cpp#L2102

If we are to handle these cases with perfection, we need to defer warning 
emissions, but I'm skeptical about the value we obtain from this effort.

For the first problem, we can make `IsRuntimeEvaluated` false while parsing 
arguments to avoid emitting incorrect diagnostics although it makes false 
negatives on tautologically-false uses in arguments.
The second problem is difficult because we cannot avoid incorrect diagnostics 
in `InitStmt` expression of constexpr-if with a simple fix. But I think it's 
acceptable for the time being because it would be a pretty rare case to use 
`is_constant_evaluated` there.

@cor3ntin 
BTW, can I separate the initializer evaluation context bug fix part to make 
another PR? Another patch I'm working on locally also suffers from the 
evaluation context bug, and I want to land that part relatively soon.
Also, it might be nice to separate the NFC libc++ test modifications I recently 
uploaded because it's too much despite being NFC. Or we can turn off this 
tautology warning against macros. Do you think it's reasonable?


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

https://reviews.llvm.org/D155064

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


[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-07 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D157238#4565260 , @danix800 wrote:

> In D157238#4565051 , @balazske 
> wrote:
>
>> `ASTImporter` part looks good, I did not check the generated documentation 
>> for correctness.
>
> Matcher part will be committed in https://reviews.llvm.org/D157237, these 
> code is added here only to support this revision.

It is possible to add D157237  as parent 
revision (and upload code here without changes in D157237 
). It is more safe to have the exact same 
code in the review that will be committed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

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



Comment at: clang/test/Sema/offsetof.c:79
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+

yichi170 wrote:
> Fznamznon wrote:
> > It probably makes sense to also add a test with static member of a class, 
> > like Aaron mentioned in GitHub - 
> > https://github.com/llvm/llvm-project/issues/64154#issuecomment-1653468938 .
> Hi @Fznamznon, I found that clang and clang++ output different errors with 
> the following test.
> ```
> struct X2 { int a; static int static_a; };
> int x4[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1];
> // expected-error{{no member named 'static_a'}}
> ```
> C doesn't allow to have a static member in the struct, so is there any way to 
> write the correct comment to make the test pass?
the tests should be in `test/SemaCXX/offsetof.cpp`, where you can use C++


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


[PATCH] D157207: [clangd] Fix typo in comment

2023-08-07 Thread Eymen Ünay via Phabricator via cfe-commits
Eymay added a comment.

Thanks @kadircet. Can you land this patch for me? 
Please use “Eymen Ünay eymenu...@outlook.com" to commit the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157207

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


[clang] 7f00389 - [OpenCL] Fix grammar in test error messages; NFC

2023-08-07 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-08-07T13:45:23+01:00
New Revision: 7f00389e7792d585cdda615324ebc094fa3c4247

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

LOG: [OpenCL] Fix grammar in test error messages; NFC

Added: 


Modified: 
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 15b52ec04e667b..7c4c673cf2ee07 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -233,46 +233,46 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #error "Incorrect cl_ext_float_atomics define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_load_store
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_load_store defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_load_store define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_load_store
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_load_store defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_load_store define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp32_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp32_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp32_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp64_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp64_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp64_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp32_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp32_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp32_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp64_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp64_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp64_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp32_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp32_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp32_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp64_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp64_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp64_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp32_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp32_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp32_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp64_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_image_raw10_raw12
 #error "Incorrect __opencl_c_ext_image_raw10_raw12 define"



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


[PATCH] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-07 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157237

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


[PATCH] D157248: [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

2023-08-07 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157248

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


[PATCH] D156928: [Clang][AMDGPU] Fix handling of -mcode-object-version=none arg

2023-08-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D156928#4562239 , @JonChesterfield 
wrote:

> Or, the front end could define those objects directly, without importing IR 
> files that define the objects with the content clang used to choose the 
> object file. E.g. instead of the argument daz=off (spelled differently) 
> finding a file called daz.off.ll that defines variable called daz with a 
> value 0, that argument could define that variable. I think @jhuber6 has a 
> partial patch trying to do that.
>
> If we were more ambitious, we could use intrinsics that are folded reliably 
> at O0 instead of magic variables that hopefully get constant folded. That 
> would kill a bunch of O0 bugs.
>
> In general though, splicing magic variables in the front end seems unlikely 
> to be performance critical relative to splicing them in at the start of the 
> backend.

I think @saiislam is working on a patch that will handle that. We'll have 
`clang` emit some global that OpenMP uses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156928

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-07 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 547751.
saiislam marked 5 inline comments as done.
saiislam added a comment.

Removed unused cov5 implicitargs fields.
Added comments about EmitAMDGPUWorkGroupSize and ABI-agnostica code emission.
Adressed reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/Driver/ToolChain.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h

Index: openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
+++ openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBufferRef.h"
 
 #include "llvm/Support/YAMLTraits.h"
+using namespace llvm::ELF;
 
 namespace llvm {
 namespace omp {
@@ -32,19 +33,35 @@
 namespace plugin {
 namespace utils {
 
-// The implicit arguments of AMDGPU kernels.
-struct AMDGPUImplicitArgsTy {
-  uint64_t OffsetX;
-  uint64_t OffsetY;
-  uint64_t OffsetZ;
-  uint64_t HostcallPtr;
-  uint64_t Unused0;
-  uint64_t Unused1;
-  uint64_t Unused2;
+enum IMPLICITARGS : uint32_t {
+  COV4_SIZE = 56,
+  COV5_SIZE = 256,
+
+  COV5_BLOCK_COUNT_X_OFFSET = 0,
+  COV5_BLOCK_COUNT_X_SIZE = 4,
+
+  COV5_GROUP_SIZE_X_OFFSET = 12,
+  COV5_GROUP_SIZE_X_SIZE = 2,
+
+  COV5_GROUP_SIZE_Y_OFFSET = 14,
+  COV5_GROUP_SIZE_Y_SIZE = 2,
+
+  COV5_GROUP_SIZE_Z_OFFSET = 16,
+  COV5_GROUP_SIZE_Z_SIZE = 2,
+
+  COV5_GRID_DIMS_OFFSET = 64,
+  COV5_GRID_DIMS_SIZE = 2,
+
+  COV5_HEAPV1_PTR_OFFSET = 96,
+  COV5_HEAPV1_PTR_SIZE = 8,
+
+  // 128 KB
+  PER_DEVICE_PREALLOC_SIZE = 131072
 };
 
-static_assert(sizeof(AMDGPUImplicitArgsTy) == 56,
-  "Unexpected size of implicit arguments");
+uint16_t getImplicitArgsSize(uint16_t Version) {
+  return Version < ELF::ELFABIVERSION_AMDGPU_HSA_V5 ? 56 : 256;
+}
 
 /// Parse a TargetID to get processor arch and feature map.
 /// Returns processor subarch.
@@ -295,7 +312,8 @@
 /// Reads the AMDGPU specific metadata from the ELF file and propagates the
 /// KernelInfoMap
 Error readAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer,
-  StringMap &KernelInfoMap) {
+  StringMap &KernelInfoMap,
+  uint16_t &ELFABIVersion) {
   Error Err = Error::success(); // Used later as out-parameter
 
   auto ELFOrError = object::ELF64LEFile::create(MemBuffer.getBuffer());
@@ -305,6 +323,12 @@
   const object::ELF64LEFile ELFObj = ELFOrError.get();
   ArrayRef Sections = cantFail(ELFObj.sections());
   KernelInfoReader Reader(KernelInfoMap);
+
+  // Read the code object version from ELF image header
+  auto Header = ELFObj.getHeader();
+  ELFABIVersion = (uint8_t)(Header.e_ident[ELF::EI_ABIVERSION]);
+  DP("ELFABIVERSION Version: %u\n", ELFABIVersion);
+
   for (const auto &S : Sections) {
 if (S.sh_type != ELF::SHT_NOTE)
   continue;
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -253,6 +253,13 @@
 return Plugin::check(Status, "Error in hsa_amd_agents_allow_access: %s");
   }
 
+  Error zeroInitializeMemory(void *Ptr, size_t Size) {
+uint64_t Rounded = sizeof(uint32_t) * ((Size + 3) / sizeof(uint32_t));
+hsa_status_t Status =
+hsa_amd_memory_fill(Ptr, 0, Rounded / sizeof(uint32_t));
+return Plugin::check(Status, "Error in hsa_amd_memory_fill: %s");
+  }
+
   /// Get attribute from the memory pool.
   template 
   Error getAttr(hsa_amd_memory_pool_info_t Kind, Ty &Value) const {
@@ -381,6 +388,9 @@
   /// Get the executable.
   hsa_executable_t getExecutable() const { return Executable; }
 
+  /// Get to Code Object Version of the ELF
+  uint16_t getELFABIVersion() const { return ELFABIVersion; }
+
   /// Find an HSA device symbol by its name on the executable.
   Expected
   findDeviceSymbol(GenericDeviceTy &Device, StringRef SymbolName) const;
@@ -401,6 +411,7 @@
   hsa_executable_t Executable;
   hsa_code_object_t CodeObject;
   StringMap KernelInfoMap;
+  uint16_t ELFABIVersion;
 };
 
 /// Class implementing the AMDGPU kernel functionalities which derives from the
@@ -408,8 +419,7 @@
 struct AMDGPUKernelTy : public GenericKernelTy {
   /// Create an AMDGPU kernel with a name and an execution mode.
   AMDGPUKernelTy(const char *Name, OMPTgtExecModeFlags ExecutionMode)
-  : GenericKernelTy(Name, ExecutionMode),
-  

[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-07 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

In D139730#4561622 , @arsenm wrote:

> In D139730#4561619 , @arsenm wrote:
>
>> In D139730#4561575 , @jhuber6 
>> wrote:
>>
>>> In D139730#4561573 , @arsenm 
>>> wrote:
>>>
 In D139730#4561540 , @jhuber6 
 wrote:

> Could you explain briefly what the approach here is? I'm confused as to 
> what's actually changed and how we're handling this difference. I thought 
> if this was just the definition of some builtin function we could just 
> rely on the backend to figure it out. Why do we need to know the code 
> object version inside the device RTL?

 The build is called in the device rtl, so the device RTL needs to contain 
 both implementations. The "backend figuring it out" is dead code 
 elimination
>>>
>>> Okay, do we expect to re-use this interface anywhere? If it's just for 
>>> OpenMP then we should probably copy the approach taken for 
>>> `__omp_rtl_debug_kind`, which is a global created on the GPU by 
>>> `CGOpenMPRuntimeGPU`'s constructor and does more or less the same thing.
>>
>> device libs replicates the same scheme using its own copy of an equivalent 
>> variable. Trying to merge those two together
>
> Although I guess that doesn't really need the builtin changes?

This builtin was already aware about cov4 and cov5. All this patch is changing 
is making it aware about a possibility where both needs to be present.
It is already used by device-libs, deviceRTL, and libc-gpu.
Also, encapsulating ABI related changes in implementation of the builtin allows 
other runtime developers to be agnostic to these lower level changes.




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:17187-17188
+Address(Result, CGF.Int16Ty, CharUnits::fromQuantity(2)));
+  } else {
+if (Cov == clang::TargetOptions::COV_5) {
+  // Indexing the implicit kernarg segment.

jhuber6 wrote:
> nit.
There are a couple of common lines after the inner if-else, in the outer else 
section.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:1752
+// if (auto Err = preAllocateDeviceMemoryPool())
+//   return Err;
+

jhuber6 wrote:
> Leftoever?
No, it is not a left over.
One of the fields in cov5 implicitikernarg is heap_v1 ptr. It should point to a 
128KB zero-initialized block of coarse-grained memory on each device before 
launching the kernel. This code was working a while ago, but right now it is 
failing most likely due to some latest change in devicertl memory handling 
mechanism.
I need to debug it with this patch, otherwise it will cause all target region 
code calling device-malloc to fail.
I will try to fix it before the next revision.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:2542
+  /// Get the address of pointer to the preallocated device memory pool.
+  void **getPreAllocatedDeviceMemoryPool() {
+return &PreAllocatedDeviceMemoryPool;

jhuber6 wrote:
> Why do we need this? The current method shouldn't need to change if all we're 
> doing is allocating memory of greater size.
`PreAllocatedDeviceMemoryPool` is the pointer which stores the intermediate 
value before it is written to heap_v1_ptr field of cov5 implicitkernarg.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:3036
 
+  if (getImplicitArgsSize() < utils::COV5_SIZE) {
+DP("Setting fields of ImplicitArgs for COV4\n");

jhuber6 wrote:
> So we're required to emit some new arguments? I don't have any idea 
> what'schanged between this COV4 and COV5 stuff.
In cov5, we need to set certain fields of the implicit kernel arguments before 
launching the kernel.
Please see [[ 
https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v5
 | AMDHSA Code Object V5 Kernel Argument Metadata Map Additions and Changes]] 
for more details.

Only NumBlocks, NumThreads(XYZ), GridDims, and Heap_V1_ptr are relevant for us, 
so I have simplified code further.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:3037
+  if (getImplicitArgsSize() < utils::COV5_SIZE) {
+DP("Setting fields of ImplicitArgs for COV4\n");
+  } else {

arsenm wrote:
> This isn't doing anything?
Earlier we used to set hostcall_buffer here, but not anymore.
I have left the message in DP just for debug help.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h:36
 
-// The implicit arguments of AMDGPU kernels.
-struct AMDGPUImplicitArgsTy {
-  uint64_t OffsetX;
-  uint64_t OffsetY;
-  uint64_t OffsetZ;
-  uint64_t HostcallPtr;
-  uint64_t Unused0;
-  uint64_t Unused1;
-  uint64_t U

[clang] 4097a24 - [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-08-07 Thread Sandeep Kosuri via cfe-commits

Author: Sunil Kuravinakop
Date: 2023-08-07T07:58:59-05:00
New Revision: 4097a24584121dba562d471fab97d3dfec1b5bff

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

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

Added: 
clang/test/OpenMP/loop_bind_codegen.cpp
clang/test/OpenMP/loop_bind_enclosed.cpp
clang/test/OpenMP/loop_bind_messages.cpp

Modified: 
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/OpenMP/generic_loop_ast_print.cpp
clang/test/OpenMP/generic_loop_codegen.cpp
clang/test/OpenMP/nested_loop_codegen.cpp
clang/test/PCH/pragma-loop.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 2d37fdbf4ca8fb..20cd198f5f0cc5 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -281,6 +281,15 @@ class OMPExecutableDirective : public Stmt {
 return Data->getClauses();
   }
 
+  /// Was this directive mapped from an another directive?
+  /// e.g. 1) omp loop bind(parallel) is mapped to OMPD_for
+  ///  2) omp loop bind(teams) is mapped to OMPD_distribute
+  ///  3) omp loop bind(thread) is mapped to OMPD_simd
+  /// It was necessary to note it down in the Directive because of
+  /// clang::TreeTransform::TransformOMPExecutableDirective() pass in
+  /// the frontend.
+  OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown;
+
 protected:
   /// Data, associated with the directive.
   OMPChildren *Data = nullptr;
@@ -345,6 +354,10 @@ class OMPExecutableDirective : public Stmt {
 return Inst;
   }
 
+  void setMappedDirective(OpenMPDirectiveKind MappedDirective) {
+PrevMappedDirective = MappedDirective;
+  }
+
 public:
   /// Iterates over expressions/statements used in the construct.
   class used_clauses_child_iterator
@@ -598,6 +611,8 @@ class OMPExecutableDirective : public Stmt {
"Expected directive with the associated statement.");
 return Data->getRawStmt();
   }
+
+  OpenMPDirectiveKind getMappedDirective() const { return PrevMappedDirective; 
}
 };
 
 /// This represents '#pragma omp parallel' directive.
@@ -1604,7 +1619,8 @@ class OMPSimdDirective : public OMPLoopDirective {
   SourceLocation EndLoc, unsigned CollapsedNum,
   ArrayRef Clauses,
   Stmt *AssociatedStmt,
-  const HelperExprs &Exprs);
+  const HelperExprs &Exprs,
+  OpenMPDirectiveKind 
ParamPrevMappedDirective);
 
   /// Creates an empty directive with the place
   /// for \a NumClauses clauses.
@@ -1682,7 +1698,8 @@ class OMPForDirective : public OMPLoopDirective {
  SourceLocation EndLoc, unsigned CollapsedNum,
  ArrayRef Clauses,
  Stmt *AssociatedStmt, const HelperExprs 
&Exprs,
- Expr *TaskRedRef, bool HasCancel);
+ Expr *TaskRedRef, bool HasCancel,
+ OpenMPDirectiveKind ParamPrevMappedDirective);
 
   /// Creates an empty directive with the place
   /// for \a NumClauses clauses.
@@ -4406,7 +4423,8 @@ class OMPDistributeDirective : public OMPLoopDirective {
   static OMPDistributeDirective *
   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
  unsigned CollapsedNum, ArrayRef Clauses,
- Stmt *AssociatedStmt, const HelperExprs &Exprs);
+ Stmt *AssociatedStmt, const HelperExprs &Exprs,
+ OpenMPDirectiveKind ParamPrevMappedDirective);
 
   /// Creates an empty directive with the place
   /// for \a NumClauses clauses.

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4979f9f86d236d..5e0aca3c12d3d6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9869,6 +9869,11 @@ def err_break_not_in_loop_or_switch : Error<
 def warn_loop_ctrl_binds_to_inner : Warning<
   "'%0' is bound to current loop, GCC binds it to the enclosing loop">,
   InGroup;
+def err_omp_bind_required_on_loop : Error<
+  "expected 'bind' clause for 'loop' construct without an enclosing OpenMP "
+  "construct">;
+def err_omp_loop_reduction_clause : Error<
+  "'reduction' clause not allowed with '#pr

[PATCH] D156928: [Clang][AMDGPU] Fix handling of -mcode-object-version=none arg

2023-08-07 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

In D156928#4565506 , @jhuber6 wrote:

> In D156928#4562239 , 
> @JonChesterfield wrote:
>
>> Or, the front end could define those objects directly, without importing IR 
>> files that define the objects with the content clang used to choose the 
>> object file. E.g. instead of the argument daz=off (spelled differently) 
>> finding a file called daz.off.ll that defines variable called daz with a 
>> value 0, that argument could define that variable. I think @jhuber6 has a 
>> partial patch trying to do that.
>>
>> If we were more ambitious, we could use intrinsics that are folded reliably 
>> at O0 instead of magic variables that hopefully get constant folded. That 
>> would kill a bunch of O0 bugs.
>>
>> In general though, splicing magic variables in the front end seems unlikely 
>> to be performance critical relative to splicing them in at the start of the 
>> backend.
>
> I think @saiislam is working on a patch that will handle that. We'll have 
> `clang` emit some global that OpenMP uses.

Thanks Joseph.
Yes, I have abandoned this patch and using `-Xclang -mcode-object-version=none` 
option in the patch to enable cov5 support for OpenMP. 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156928

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


[PATCH] D157249: [clang][ASTImporter] Add import of 'ConvertVectorExpr'

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

> Depends on https://reviews.llvm.org/D157248

FWIW, this would usually be done via a "patch stack": 
https://kurtisnusbaum.medium.com/stacked-diffs-keeping-phabricator-diffs-small-d9964f4dcfa6
 so that it's clear which changes are part of this patch and which changes are 
part of the parent patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157249

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


[PATCH] D157200: [clang][Interp] Visit Logical-not operand as bool

2023-08-07 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 with a testing request.




Comment at: clang/test/AST/Interp/c.c:12-13
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
+_Static_assert(!!1.0, "");
+_Static_assert(!!1, "");
 

These tests should also work in C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157200

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


[PATCH] D157174: [clang][Interp] Convert logical binop operands to bool

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:531-534
+  // For C, cast back to integer type.
+  assert(T);
+  if (T != PT_Bool)
+return this->emitCast(PT_Bool, *T, E);

This is casting to boolean type, not integer type -- shouldn't that be emitting 
an int?


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

https://reviews.llvm.org/D157174

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


[PATCH] D157280: [PGO] Enable `-fprofile-update` for `-fprofile-generate`

2023-08-07 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: MaskRay, davidxl, w2yehia.
Herald added subscribers: wlei, ormris, wenlei, hiraditya.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently, the `-fprofile-udpate` is ignored when `-fprofile-generate` is in 
effect. This patch enables `-fprofile-update` for `-fprofile-generate`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157280

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/tsan-instrprof-atomic.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Support/PGOOptions.h
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/lib/Support/PGOOptions.cpp

Index: llvm/lib/Support/PGOOptions.cpp
===
--- llvm/lib/Support/PGOOptions.cpp
+++ llvm/lib/Support/PGOOptions.cpp
@@ -16,13 +16,14 @@
std::string MemoryProfile,
IntrusiveRefCntPtr FS, PGOAction Action,
CSPGOAction CSAction, bool DebugInfoForProfiling,
-   bool PseudoProbeForProfiling)
+   bool PseudoProbeForProfiling, bool AtomicCounterUpdate)
 : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
   ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
   Action(Action), CSAction(CSAction),
   DebugInfoForProfiling(DebugInfoForProfiling ||
 (Action == SampleUse && !PseudoProbeForProfiling)),
-  PseudoProbeForProfiling(PseudoProbeForProfiling), FS(std::move(FS)) {
+  PseudoProbeForProfiling(PseudoProbeForProfiling),
+  AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) {
   // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
   // callback with IRUse action without ProfileFile.
 
Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -724,7 +724,8 @@
 
 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 OptimizationLevel Level, bool RunProfileGen,
-bool IsCS, std::string ProfileFile,
+bool IsCS, bool AtomicCounterUpdate,
+std::string ProfileFile,
 std::string ProfileRemappingFile,
 ThinOrFullLTOPhase LTOPhase,
 IntrusiveRefCntPtr FS) {
@@ -793,13 +794,14 @@
   // Do counter promotion at Level greater than O0.
   Options.DoCounterPromotion = true;
   Options.UseBFIInPromotion = IsCS;
+  Options.Atomic = AtomicCounterUpdate;
   MPM.addPass(InstrProfiling(Options, IsCS));
 }
 
 void PassBuilder::addPGOInstrPassesForO0(
 ModulePassManager &MPM, bool RunProfileGen, bool IsCS,
-std::string ProfileFile, std::string ProfileRemappingFile,
-IntrusiveRefCntPtr FS) {
+bool AtomicCounterUpdate, std::string ProfileFile,
+std::string ProfileRemappingFile, IntrusiveRefCntPtr FS) {
   if (!RunProfileGen) {
 assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
 MPM.addPass(
@@ -819,6 +821,7 @@
   // Do not do counter promotion at O0.
   Options.DoCounterPromotion = false;
   Options.UseBFIInPromotion = IsCS;
+  Options.Atomic = AtomicCounterUpdate;
   MPM.addPass(InstrProfiling(Options, IsCS));
 }
 
@@ -1094,8 +1097,9 @@
PGOOpt->Action == PGOOptions::IRUse)) {
 addPGOInstrPasses(MPM, Level,
   /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
-  /* IsCS */ false, PGOOpt->ProfileFile,
-  PGOOpt->ProfileRemappingFile, Phase, PGOOpt->FS);
+  /* IsCS */ false, PGOOpt->AtomicCounterUpdate,
+  PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, Phase,
+  PGOOpt->FS);
 MPM.addPass(PGOIndirectCallPromotion(false, false));
   }
   if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
@@ -1307,12 +1311,14 @@
   if (!LTOPreLink && PGOOpt) {
 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
   addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true,
-/* IsCS */ true, PGOOpt->CSProfileGenFile,
-PGOOpt->ProfileRemappingFile, LTOPhase, PGOOpt->FS);
+/* IsCS */ true, PGOOpt->AtomicCounterUpdate,
+PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
+LTOPhase, PGOOpt->FS);
 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
   addPGOInstrPasses(MPM, Level, /* RunProfileGen */ false,
-/* IsCS */ true, PGOOpt->ProfileFile,
-   

[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-07 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:17138
+///and use its value for COV_4 or COV_5 approach. It is used for
+///compiling device libraries in ABI-agnostic way.
+///





Comment at: clang/lib/CodeGen/CGBuiltin.cpp:17187-17188
+Address(Result, CGF.Int16Ty, CharUnits::fromQuantity(2)));
+  } else {
+if (Cov == clang::TargetOptions::COV_5) {
+  // Indexing the implicit kernarg segment.

saiislam wrote:
> jhuber6 wrote:
> > nit.
> There are a couple of common lines after the inner if-else, in the outer else 
> section.
You should be able to factor out
```
LD = CGF.Builder.CreateLoad(
Address(Result, CGF.Int16Ty, CharUnits::fromQuantity(2)));
```
from both by making each assign the `Result` to a value.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:2550-2551
+Error Err = retrieveAllMemoryPools();
+if (Err)
+  return Plugin::error("Unable to retieve all memmory pools");
+

This and below isn't correct. You can't discard an `llvm::Error` value like 
this without either doing `consumeError(std::move(Err))` or 
`toString(std::move(Err))`. However, you don't need to consume these in the 
first place, they already contain the error message from the callee and should 
just be forwarded.



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp:1752
+// if (auto Err = preAllocateDeviceMemoryPool())
+//   return Err;
+

saiislam wrote:
> jhuber6 wrote:
> > Leftoever?
> No, it is not a left over.
> One of the fields in cov5 implicitikernarg is heap_v1 ptr. It should point to 
> a 128KB zero-initialized block of coarse-grained memory on each device before 
> launching the kernel. This code was working a while ago, but right now it is 
> failing most likely due to some latest change in devicertl memory handling 
> mechanism.
> I need to debug it with this patch, otherwise it will cause all target region 
> code calling device-malloc to fail.
> I will try to fix it before the next revision.
Do we really need that? We only use a fraction of the existing implicit 
arguments. My understanding is that most of these are more for runtime handling 
for HIP and OpenCL while we would most likely want our own solution. I'm 
assuming that the 128KB is not required for anything we use?



Comment at: openmp/libomptarget/plugins-nextgen/amdgpu/utils/UtilitiesRTL.h:36
 
-// The implicit arguments of AMDGPU kernels.
-struct AMDGPUImplicitArgsTy {
-  uint64_t OffsetX;
-  uint64_t OffsetY;
-  uint64_t OffsetZ;
-  uint64_t HostcallPtr;
-  uint64_t Unused0;
-  uint64_t Unused1;
-  uint64_t Unused2;
+enum IMPLICITARGS : uint32_t {
+  COV4_SIZE = 56,

saiislam wrote:
> jhuber6 wrote:
> > arsenm wrote:
> > > This is getting duplicated a few places, should it move to a support 
> > > header?
> > > 
> > > I don't love the existing APIs for this, I think a struct definition 
> > > makes more sense
> > The other user here is my custom loader, @JonChesterfield has talked about 
> > wanting a common HSA helper header for awhile now.
> > 
> > I agree that the struct definition is much better. Being able to simply 
> > allocate this size and then zero fill it is much cleaner.
> Defining a struct for whole 256 byte of implicitargs in cov5 was becoming a 
> little difficult due to different sizes of various fields (2, 4, 6, 8, 48, 72 
> bytes) along with multiple reserved fields in between. It made sense for cov4 
> because it only had 7 fields of 8 bytes each, where we needed only 4th field 
> in OpenMP runtime (for hostcall_buffer).
> 
> Offset based lookups like the following allows handling/exposing only 
> required fields across generations of ABI.
If we don't use it, just put it as `unused`. It's really hard to read as-is and 
it makes it more difficult to just zero fill.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D157174: [clang][Interp] Convert logical binop operands to bool

2023-08-07 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:531-534
+  // For C, cast back to integer type.
+  assert(T);
+  if (T != PT_Bool)
+return this->emitCast(PT_Bool, *T, E);

aaron.ballman wrote:
> This is casting to boolean type, not integer type -- shouldn't that be 
> emitting an int?
That line is casting from `PT_Bool` to `T`, because we visited the operands as 
bool and now we need to convert back to whatever type we should have.


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

https://reviews.llvm.org/D157174

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


[PATCH] D157174: [clang][Interp] Convert logical binop operands to bool

2023-08-07 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




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:531-534
+  // For C, cast back to integer type.
+  assert(T);
+  if (T != PT_Bool)
+return this->emitCast(PT_Bool, *T, E);

tbaeder wrote:
> aaron.ballman wrote:
> > This is casting to boolean type, not integer type -- shouldn't that be 
> > emitting an int?
> That line is casting from `PT_Bool` to `T`, because we visited the operands 
> as bool and now we need to convert back to whatever type we should have.
Ah!! That makes more sense, thank you.


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

https://reviews.llvm.org/D157174

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


[PATCH] D157269: [Clang][AArch64] Diagnostics for SME attributes when target doesn't have 'sme'

2023-08-07 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

The intent looks good to me, but I'm not in a position to approve.  Very 
pedantic, sorry, but on the description, I think:

> Calls from non-streaming functions to streaming-functions require the 
> compiler to enable/disable streaming-SVE mode around the call-site.

would be more accurate as:

> Calls from non-streaming **mode** to streaming functions…

since it applies to calls from streaming-compatible functions too.  (Which is 
what the patch implements.)




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3629
+  "call to a streaming function requires sme">;
+def err_sme_definition_in_non_sme_target : Error<
+  "function executed in streaming-SVE mode or using ZA state, requires sme">;

Seems like we can easily split this into two and distinguish the cases, since 
the code that gives the error can always tell which case applies.  I think not 
having SME for streaming mode is logically more fundamental than not having SME 
for ZA.

I think `sme` should be SME (if it's referring to the ISA feature) or should be 
quoted (if it's referring to the feature syntax).



Comment at: clang/lib/Sema/SemaChecking.cpp:6631
 
 /// Handles the checks for format strings, non-POD arguments to vararg
 /// functions, NULL arguments passed to non-NULL parameters, and diagnose_if

I don't know the code well enough to know whether this is the right place to 
check this.  if it is, though, I suppose the comment needs to be updated too.

I agree the intention looks right from a spec POV.



Comment at: clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp:29
+
+void streaming_compatible_def2() {
+  non_streaming_decl(); // OK

Looks like this was intended to be `__arm_streaming_compatible`.



Comment at: llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td:158
+
+  // Rather than only allowing this instruction with '+sme', we also
+  // allow it with '+sve', such that we can still emit the instruction

I don't think even SVE is required.  A function like:
```
void foo() __arm_streaming_compatible {
   printf ("Hello, world!\n");
}
```
should be OK for base Armv8-A.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157269

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-07 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 updated this revision to Diff 547764.
yichi170 marked an inline comment as not done.
yichi170 added a comment.

updated test in `test/SemaCXX/offsetof.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/offsetof.c
  clang/test/SemaCXX/offsetof.cpp


Index: clang/test/SemaCXX/offsetof.cpp
===
--- clang/test/SemaCXX/offsetof.cpp
+++ clang/test/SemaCXX/offsetof.cpp
@@ -98,3 +98,7 @@
 B x;
   }, a);
 }
+
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; static int static_a; };
+int x2[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1]; // 
expected-error{{no member named 'static_a'}}
Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // 
expected-warning{{indirection of non-volatile null pointer}} 
expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16663,6 +16663,9 @@
<< CurrentType);
 RecordDecl *RD = RC->getDecl();
 
+if (OC.isQualifier && RD->getIdentifier() == OC.U.IdentInfo)
+  continue;
+
 // C++ [lib.support.types]p5:
 //   The macro offsetof accepts a restricted set of type arguments in this
 //   International Standard. type shall be a POD structure or a POD union
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2641,10 +2641,13 @@
 
 // FIXME: This loop leaks the index expressions on error.
 while (true) {
-  if (Tok.is(tok::period)) {
+  if (Tok.is(tok::period) || Tok.is(tok::coloncolon)) {
 // offsetof-member-designator: offsetof-member-designator '.' 
identifier
+if (Tok.is(tok::coloncolon))
+  Comps.back().isQualifier = true;
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = false;
+Comps.back().isQualifier = false;
 Comps.back().LocStart = ConsumeToken();
 
 if (Tok.isNot(tok::identifier)) {
@@ -2661,6 +2664,7 @@
 // offsetof-member-designator: offsetof-member-design '[' expression 
']'
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = true;
+Comps.back().isQualifier = false;
 BalancedDelimiterTracker ST(*this, tok::l_square);
 ST.consumeOpen();
 Comps.back().LocStart = ST.getOpenLocation();
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6036,6 +6036,7 @@
   struct OffsetOfComponent {
 SourceLocation LocStart, LocEnd;
 bool isBrackets;  // true if [expr], false if .ident
+bool isQualifier;
 union {
   IdentifierInfo *IdentInfo;
   Expr *E;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -56,6 +56,7 @@
 
 C++ Language Changes
 
+- Improved `__builtin_offsetof` support, allowing qualified name in member 
designator.
 
 C++20 Feature Support
 ^


Index: clang/test/SemaCXX/offsetof.cpp
===
--- clang/test/SemaCXX/offsetof.cpp
+++ clang/test/SemaCXX/offsetof.cpp
@@ -98,3 +98,7 @@
 B x;
   }, a);
 }
+
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; static int static_a; };
+int x2[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1]; // expected-error{{no member named 'static_a'}}
Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // expect

[PATCH] D157270: [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.

2023-08-07 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:6737
+else if (const auto *FPT = 
CallerFD->getType()->getAs())
+  CallerHasZAState |= FPT->getExtProtoInfo().AArch64SMEAttributes &
+  FunctionType::SME_PStateZASharedMask;

Very minor, but it looked odd to me to have `|=` in this statement and `=` 
above.



Comment at: clang/test/Sema/aarch64-sme-func-attrs.c:181
 
+void non_za_definition(void) {
+  sme_arm_new_za(); // OK

Would be good to have some tests for indirect function calls too (via function 
pointers), to make sure that the diagnostic still works when no decl is 
available.

I suppose this applies to D157269 too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157270

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


[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

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

Precommit CI found a related issue that should be addressed.




Comment at: clang/www/cxx_dr_status.html:4376
 Can nullptr be passed to an ellipsis?
-Unknown
+Clang 17
   

MitalAshok wrote:
> It may be better to mark this as "Yes", since in old clang versions passing 
> nullptr would work by virtue of it having representation of a null void* 
> pointer, and it only affected diagnostics
I think it's better to use Clang 18, otherwise people will think there's a 
diagnostic bug with earlier versions. We usually use "Yes" to mean "we've 
always supported this correctly, as best we can tell".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

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


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-07 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 547767.
sstwcw marked 2 inline comments as done.
sstwcw added a comment.

- Add tests for code in JavaScript template strings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTestCSharp.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1815,6 +1815,30 @@
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[5], tok::comma, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+
+  // String literals in concatenation.
+  Tokens = Annotate("x = {\"\"};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = {\"\", \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = '{{\"\"}};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  // Cases where the string should not be annotated that type.  Fix the
+  // `TT_Unknown` if needed in the future.
+  Tokens = Annotate("x = {\"\" == \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = {(\"\")};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = '{\"\"};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -1157,6 +1157,66 @@
   verifyFormat("{< Ranges(1, tooling::Range(Offset, Length));
-tooling::Replacements Replaces = reformat(Style, Code, Ranges);
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  static std::string
-  format(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-return format(Code, 0, Code.size(), Style);
+  FormatStyle getDefaultStyle() const override {
+return getGoogleStyle(FormatStyle::LK_Java);
   }
 
   static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
@@ -41,13 +26,6 @@
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
-
-  static void verifyFormat(
-  llvm::StringRef Code,
-  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
-  }
 };
 
 TEST_F(FormatTestJava, NoAlternativeOperatorNames) {
@@ -565,9 +543,9 @@
 }
 
 TEST_F(FormatTestJava, BreaksStringLiterals) {
-  // FIXME: String literal breaking is currently disabled for Java and JS, as it
-  // requires strings to be merged using "+" which we don't support.
-  verifyFormat("\"some text other\";", getStyleWithColumns(14));
+  verifyFormat("x = \"some text \"\n"
+   "+ \"other\";",
+   "x = \"some text other\";", getStyleWithColumns(18));
 }
 
 TEST_F(FormatTestJava, AlignsBlockComments) {
@@ -625,5 +603,7 @@
Style);
 }
 
+} // namespace
+} // namespace test
 } // namespace format
-} // end namespace clang
+} // namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1505,6 +1505,97 @@
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
+
+  // Long strings should be broken.
+  verifyFormat("var literal =\n"
+   "' ' +\n"
+   "'';",
+

[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-07 Thread sstwcw via Phabricator via cfe-commits
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:221
 TEST_F(FormatTestCSharp, CSharpFatArrows) {
-  verifyFormat("Task serverTask = Task.Run(async() => {");
+  verifyIncompleteFormat("Task serverTask = Task.Run(async() => {");
   verifyFormat("public override string ToString() => \"{Name}\\{Age}\";");

MyDeveloperDay wrote:
> not sure what changing here and why?
The brace is not paired.  The old `verifyFormat` function didn't care about it. 
 In `FormatTestBase.h` there is the function `verifyFormat` which requires the 
code to be complete and `verifyIncompleteFormat` which doesn't.



Comment at: clang/unittests/Format/FormatTestJS.cpp:1575
+   "/ /;",
+   getGoogleJSStyleWithColumns(18));
 }

MyDeveloperDay wrote:
> out of interest what happens with  `xx ${variable} 
> xx` type strings? can we add a test to show we won't break in 
> the middle of a ${vas} even though the column limit might be reached?
There can be a break inside the braces.  I added a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[clang] 4cce27d - [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-07 Thread via cfe-commits

Author: dingfei
Date: 2023-08-07T21:50:42+08:00
New Revision: 4cce27d9184ed5a71e296c8a18a603ec3e23b06d

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

LOG: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

Add Matcher dependentSizedExtVectorType for DependentSizedExtVectorType.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 4f2a1f9508baa2..88153436330f43 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2531,6 +2531,19 @@ Node Matchers
 
 
 
+MatcherType>dependentSizedExtVectorTypeMatcherDependentSizedExtVectorType>...
+Matches 
C++ extended vector type where either the type or size is dependent.
+
+Given
+  template
+  class vector {
+typedef T __attribute__((ext_vector_type(Size))) type;
+  };
+dependentSizedExtVectorType
+  matches "T __attribute__((ext_vector_type(Size)))"
+
+
+
 MatcherType>elaboratedTypeMatcherElaboratedType>...
 Matches types 
specified with an elaborated type keyword or with a
 qualified name.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d1ca7afad1f10..b5fcf1b699cd49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -231,6 +231,7 @@ Floating Point Support in Clang
 
 AST Matchers
 
+- Add ``dependentSizedExtVectorType``.
 
 clang-format
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index f49204a3d90626..b522392a32c372 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6938,6 +6938,21 @@ AST_POLYMORPHIC_MATCHER_P(hasSize,
 ///   matches "T data[Size]"
 extern const AstTypeMatcher dependentSizedArrayType;
 
+/// Matches C++ extended vector type where either the type or size is
+/// dependent.
+///
+/// Given
+/// \code
+///   template
+///   class vector {
+/// typedef T __attribute__((ext_vector_type(Size))) type;
+///   };
+/// \endcode
+/// dependentSizedExtVectorType
+///   matches "T __attribute__((ext_vector_type(Size)))"
+extern const AstTypeMatcher
+dependentSizedExtVectorType;
+
 /// Matches C arrays with unspecified size.
 ///
 /// Given

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 3470467112dd5f..dccfec35ea4081 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@ const AstTypeMatcher constantArrayType;
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 1098df032a64b9..b0006483dc7cb0 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -227,6 +227,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentCoawaitExpr);
   REGISTER_MATCHER(dependentSizedArrayType);
+  REGISTER_MATCHER(dependentSizedExtVectorType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
   REGISTER_MATCHER(doStmt);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index d2abd87115b50c..14d3360f5bdc9c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,20 @@ TEST_P(ASTMatchersTest, DependentSizedArrayType) {
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_

[PATCH] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-07 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4cce27d9184e: [clang][ASTMatcher] Add Matcher 
'dependentSizedExtVectorType' (authored by dingfei 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157237

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,20 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) type;"
+  "};",
+  dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int a[] = { 2, 3 };", incompleteArrayType()));
   EXPECT_TRUE(matches("void f(int a[]) {}", incompleteArrayType()));
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -227,6 +227,7 @@
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentCoawaitExpr);
   REGISTER_MATCHER(dependentSizedArrayType);
+  REGISTER_MATCHER(dependentSizedExtVectorType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
   REGISTER_MATCHER(doStmt);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6938,6 +6938,21 @@
 ///   matches "T data[Size]"
 extern const AstTypeMatcher dependentSizedArrayType;
 
+/// Matches C++ extended vector type where either the type or size is
+/// dependent.
+///
+/// Given
+/// \code
+///   template
+///   class vector {
+/// typedef T __attribute__((ext_vector_type(Size))) type;
+///   };
+/// \endcode
+/// dependentSizedExtVectorType
+///   matches "T __attribute__((ext_vector_type(Size)))"
+extern const AstTypeMatcher
+dependentSizedExtVectorType;
+
 /// Matches C arrays with unspecified size.
 ///
 /// Given
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -231,6 +231,7 @@
 
 AST Matchers
 
+- Add ``dependentSizedExtVectorType``.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2531,6 +2531,19 @@
 
 
 
+MatcherType>dependentSizedExtVectorTypeMatcherDependentSizedExtVectorType>...
+Matches C++ extended vector type where either the type or size is dependent.
+
+Given
+  template
+  class vector {
+typedef T __attribute__((ext_vector_type(Size))) type;
+  };
+dependentSizedExtVectorType
+  matches "T __attribute__((ext_vector_type(Size)))"
+
+
+
 MatcherType>elaboratedTypeMatcherElaboratedType>...
 Matches types specified with an elaborated type keyword or with a
 qualified name.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-07 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 547770.
sstwcw added a comment.

- Add tests for code in JavaScript template strings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTestCSharp.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1815,6 +1815,30 @@
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[5], tok::comma, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+
+  // String literals in concatenation.
+  Tokens = Annotate("x = {\"\"};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = {\"\", \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = '{{\"\"}};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  // Cases where the string should not be annotated that type.  Fix the
+  // `TT_Unknown` if needed in the future.
+  Tokens = Annotate("x = {\"\" == \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = {(\"\")};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = '{\"\"};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -1157,6 +1157,66 @@
   verifyFormat("{< Ranges(1, tooling::Range(Offset, Length));
-tooling::Replacements Replaces = reformat(Style, Code, Ranges);
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  static std::string
-  format(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-return format(Code, 0, Code.size(), Style);
+  FormatStyle getDefaultStyle() const override {
+return getGoogleStyle(FormatStyle::LK_Java);
   }
 
   static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
@@ -41,13 +26,6 @@
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
-
-  static void verifyFormat(
-  llvm::StringRef Code,
-  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
-  }
 };
 
 TEST_F(FormatTestJava, NoAlternativeOperatorNames) {
@@ -565,9 +543,9 @@
 }
 
 TEST_F(FormatTestJava, BreaksStringLiterals) {
-  // FIXME: String literal breaking is currently disabled for Java and JS, as it
-  // requires strings to be merged using "+" which we don't support.
-  verifyFormat("\"some text other\";", getStyleWithColumns(14));
+  verifyFormat("x = \"some text \"\n"
+   "+ \"other\";",
+   "x = \"some text other\";", getStyleWithColumns(18));
 }
 
 TEST_F(FormatTestJava, AlignsBlockComments) {
@@ -625,5 +603,7 @@
Style);
 }
 
+} // namespace
+} // namespace test
 } // namespace format
-} // end namespace clang
+} // namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1505,6 +1505,97 @@
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
+
+  // Long strings should be broken.
+  verifyFormat("var literal =\n"
+   "' ' +\n"
+   "'';",
+   "var literal = ' x

[PATCH] D127762: [Clang][AArch64] Add/implement ACLE keywords for SME.

2023-08-07 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm accepted this revision.
rsandifo-arm added a comment.

LGTM too, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[clang] 8baf862 - [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

2023-08-07 Thread via cfe-commits

Author: dingfei
Date: 2023-08-07T21:53:14+08:00
New Revision: 8baf86275639ec332408f1e1fac0066e4f0788d2

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

LOG: [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

Add Matcher convertVectorExpr.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 88153436330f43..d30e151edae05b 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1491,6 +1491,11 @@ Node Matchers
 
 
 
+MatcherStmt>convertVectorExprMatcherConvertVectorExpr>...
+Matches builtin 
function __builtin_convertvector.
+
+
+
 MatcherStmt>coreturnStmtMatcherCoreturnStmt>...
 Matches co_return 
statements.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b5fcf1b699cd49..949e3fe7d2c8d7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -231,6 +231,7 @@ Floating Point Support in Clang
 
 AST Matchers
 
+- Add ``convertVectorExpr``.
 - Add ``dependentSizedExtVectorType``.
 
 clang-format

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index b522392a32c372..620f0cb7872f1f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2519,6 +2519,10 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 chooseExpr;
 
+/// Matches builtin function __builtin_convertvector.
+extern const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index dccfec35ea4081..6a2c85ef2b5176 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -941,6 +941,8 @@ const internal::VariadicDynCastAllOfMatcher
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher chooseExpr;
+const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
 const internal::VariadicDynCastAllOfMatcher
 coawaitExpr;
 const internal::VariadicDynCastAllOfMatcher

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index b0006483dc7cb0..0cd65d4c95cbcd 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -178,6 +178,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(constantExpr);
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
+  REGISTER_MATCHER(convertVectorExpr);
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 14d3360f5bdc9c..bb7d8cc771a349 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@ TEST_P(ASTMatchersTest, ChooseExpr) {
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;



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


[PATCH] D157248: [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

2023-08-07 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8baf86275639: [clang][ASTMatcher] Add Matcher 
'convertVectorExpr' (authored by dingfei ).

Changed prior to commit:
  https://reviews.llvm.org/D157248?vs=547625&id=547771#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157248

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -178,6 +178,7 @@
   REGISTER_MATCHER(constantExpr);
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
+  REGISTER_MATCHER(convertVectorExpr);
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -941,6 +941,8 @@
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher chooseExpr;
+const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
 const internal::VariadicDynCastAllOfMatcher
 coawaitExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2519,6 +2519,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 chooseExpr;
 
+/// Matches builtin function __builtin_convertvector.
+extern const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -231,6 +231,7 @@
 
 AST Matchers
 
+- Add ``convertVectorExpr``.
 - Add ``dependentSizedExtVectorType``.
 
 clang-format
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1491,6 +1491,11 @@
 
 
 
+MatcherStmt>convertVectorExprMatcherConvertVectorExpr>...
+Matches builtin 
function __builtin_convertvector.
+
+
+
 MatcherStmt>coreturnStmtMatcherCoreturnStmt>...
 Matches co_return 
statements.
 


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!Ge

[clang] bb58748 - [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Nico Weber via cfe-commits

Author: zoecarver
Date: 2023-08-07T09:56:25-04:00
New Revision: bb58748e52ebd48a46de20525ef2c594db044a11

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

LOG: [clang/cxx-interop] Teach clang to ignore availability errors that come 
from CF_OPTIONS

This cherry-picks https://github.com/apple/llvm-project/pull/6431
since without it, macOS 14 SDK headers don't compile when targeting
catalyst.

Fixes #64438.

Added: 
clang/test/SemaCXX/suppress-availability-error-cf-options.cpp

Modified: 
clang/lib/Sema/SemaAvailability.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 05ad42780e5006..84c06566387ccb 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -123,6 +123,18 @@ ShouldDiagnoseAvailabilityInContext(Sema &S, 
AvailabilityResult K,
 const NamedDecl *OffendingDecl) {
   assert(K != AR_Available && "Expected an unavailable declaration here!");
 
+  // If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
+  auto DeclLoc = Ctx->getBeginLoc();
+  // This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
+  if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
+  isa(OffendingDecl)) {
+StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
+if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
+MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
+  return false;
+}
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {

diff  --git a/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp 
b/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
new file mode 100644
index 00..c28018464513f9
--- /dev/null
+++ b/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, 
unavailable))) _type _name; enum : _name
+
+__attribute__((availability(macOS, unavailable)))
+typedef CF_OPTIONS(unsigned, TestOptions) {
+  x
+};



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


[PATCH] D152275: Use memory region declaration intrinsic when generating code for array subscripts

2023-08-07 Thread Simeon Krastnikov via Phabricator via cfe-commits
simeon updated this revision to Diff 547763.
simeon added a comment.
Herald added subscribers: llvm-commits, kmitropoulou, ChuanqiXu, pengfei, 
asbirlea, haicheng, hiraditya, jvesely.
Herald added a project: LLVM.

The patch now includes the changes that need to be made to the optimization 
passes we observed to be most negatively affected by the introduction of the 
intrinsic, primarily InstCombine and SROA. However, it is not comprehensive: we 
also observed missed optimization opportunities in other passes such as 
GlobalOpt and MergedLoadStoreMotionPass.

A large number of hand-written unit tests need to be updated by hand but as 
they are very sensitive to the smallest change in the definition of the 
intrinsic, I am postponing this until we have some initial approval.


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

https://reviews.llvm.org/D152275

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/2005-01-02-ConstantInits.c
  clang/test/CodeGen/X86/va-arg-sse.c
  clang/test/CodeGen/builtin-align-array.c
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  llvm/include/llvm/Analysis/PtrUseVisitor.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/IR/InstVisitor.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
  llvm/lib/Analysis/MemoryLocation.cpp
  llvm/lib/Analysis/MemorySSA.cpp
  llvm/lib/Analysis/ObjCARCInstKind.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/IR/Value.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/Transforms/InstCombine/gep-mem-reg-decl.ll
  llvm/test/Transforms/SROA/mem-reg-decl.ll

Index: llvm/test/Transforms/SROA/mem-reg-decl.ll
===
--- /dev/null
+++ llvm/test/Transforms/SROA/mem-reg-decl.ll
@@ -0,0 +1,42 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='sroa' -S | FileCheck %s --check-prefixes=CHECK,CHECK-PRESERVE-CFG
+; RUN: opt < %s -passes='sroa' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG
+
+declare ptr @llvm.memory.region.decl.p0(ptr readnone, i64, i64)
+
+; ensure that SROA can "see through" the intrinsic call
+define i32 @test1() {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:ret i32 1
+;
+entry:
+  %s = alloca { i32 }, align 8
+  store i32 1, ptr %s, align 8
+  %arrayidx.bounded = call ptr @llvm.memory.region.decl.p0(ptr %s, i64 0, i64 8)
+  %0 = load i32, ptr %arrayidx.bounded, align 8
+  ret i32 %0
+}
+
+; variation of the above test
+define i32 @test2() {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[ADD:%.*]] = add nsw i32 undef, undef
+; CHECK-NEXT:ret i32 [[ADD]]
+;
+entry:
+  %s = alloca [1024 x i32], align 4
+  %t = alloca [1024 x i32], align 4
+  %arrayidx.bounded = call ptr @llvm.memory.region.decl.p0(ptr %s, i64 0, i64 4096)
+  %0 = load i32, ptr %arrayidx.bounded, align 4
+  %arrayidx.bounded1 = call ptr @llvm.memory.region.decl.p0(ptr %t, i64 0, i64 4096)
+  %arrayidx2 = getelementptr inbounds i32, ptr %arrayidx.bounded1, i32 1
+  %1 = load i32, ptr %arrayidx2, align 4
+  %add = add nsw i32 %0, %1
+  ret i32 %add
+}
+
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK-MODIFY-CFG: {{.*}}
+; CHECK-PRESERVE-CFG: {{.*}}
Index: llvm/test/Transforms/InstCombine/gep-mem-reg-decl.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/gep-mem-reg-decl.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S < %s -passes=instcombine | FileCheck %s
+
+%struct.S = type { [1024 x i32], [1024 x i32] }
+
+declare ptr @llvm.memory.region.decl.p0(ptr readnone, i64, i64)
+
+; test that a GEP of a GEP can be combined in the presence of
+; intermediate intrinsic calls
+define i32 @test_gep_of_gep(ptr noundef %s, i64 %i) {
+; CHECK-LABEL: @test_gep_of_gep(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[ARRAYIDX21:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr [[S:%.*]], i64 0, i32 1, i64 [[I:%.*]]
+; CHECK-NEXT:[[ARRAYIDX_BOUNDED:%.*]] = call ptr @llvm.memory.region.decl.p0(ptr nonnull [[ARRAYIDX21]], i64 0, i64 4096)
+; CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[ARRAYIDX_BOUNDED]], align 4
+; CHECK-NEXT:ret i32 [[TMP0]]
+;
+entry:
+  %arrayidx.bounded = call ptr @llvm.memory.region.decl.p0(ptr %s, i64 0, i64 4096)
+  %B = getelementptr inbounds %struct.S, ptr %s, i32 0, i32 1
+  %arr

[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-07 Thread Artem Labazov via Phabricator via cfe-commits
artem added a comment.

Ping


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

https://reviews.llvm.org/D156821

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


[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

bb58748e52ebd48a46de20525ef2c594db044a11 



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

https://reviews.llvm.org/D157245

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


[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D157245#4565166 , @hans wrote:

> lgtm

Thanks!

> Maybe we want this for the release/17.x branch too?

Sure, trying that here: https://github.com/llvm/llvm-project/issues/64496


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

https://reviews.llvm.org/D157245

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


[PATCH] D157249: [clang][ASTImporter] Add import of 'ConvertVectorExpr'

2023-08-07 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D157249#4565580 , @aaron.ballman 
wrote:

>> Depends on https://reviews.llvm.org/D157248
>
> FWIW, this would usually be done via a "patch stack": 
> https://kurtisnusbaum.medium.com/stacked-diffs-keeping-phabricator-diffs-small-d9964f4dcfa6
>  so that it's clear which changes are part of this patch and which changes 
> are part of the parent patch.

I'll update this and D157238  to clean state 
since their dependents are both landed.

For future revisions I'll try this "patch stack" if dependency exists.

Thanks for this info.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157249

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


[PATCH] D157283: [clang] Match -isysroot behaviour with system compiler on Darwin

2023-08-07 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: ldionne, dexonsmith, MaskRay.
DmitryPolukhin added a project: clang.
Herald added a project: All.
DmitryPolukhin requested review of this revision.
Herald added a subscriber: cfe-commits.

See discussion in https://reviews.llvm.org/D89001

I updated test to match actual behavior of
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
after that modified upstream to match the test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157283

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-header-search-libcxx.cpp


Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -89,8 +89,8 @@
 // RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
 //
 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 
 // Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the 
toolchain
 // C++ include path and the sysroot one.
@@ -104,9 +104,9 @@
 // RUN: -nostdinc \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
-// RUN:   --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s
+// RUN:   --check-prefix=CHECK-LIBCXX-NOSTDINC %s
 // CHECK-LIBCXX-NOSTDINC: "-cc1"
-// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
+// CHECK-LIBCXX-NOSTDINC: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 // CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
 //
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -157,8 +157,8 @@
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
 // RUN:   --check-prefix=CHECK-LIBCXX-MISSING-BOTH %s
-// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 // CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory 
"[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 
 // Make sure that on Darwin, we use libc++ header search paths by default even 
when
 // -stdlib= isn't passed.
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2463,8 +2463,7 @@
   //Also check whether this is used for setting library search paths.
   ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
 
-  if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
-options::OPT_nostdincxx))
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdincxx))
 return;
 
   llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs);
@@ -2472,8 +2471,8 @@
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
 // On Darwin, libc++ can be installed in one of the following two places:
-// 1. Alongside the compiler in /include/c++/v1
-// 2. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 1. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 2. Alongside the compiler in /include/c++/v1
 //
 // The precendence of paths is as listed above, i.e. we take the first path
 // that exists. Also note that we never include libc++ twice -- we take the
@@ -2481,6 +2480,17 @@
 // include_next could break).
 
 // Check for (1)
+llvm::SmallString<128> SysrootUsr = Sysroot;
+llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+if (getVFS().exists(SysrootUsr)) {
+  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+  return;
+} else if (DriverArgs.hasArg(options::OPT_v)) {
+  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+   << "\"\n";
+}
+
+// Otherwise, check for (2)
 // Get from '/bin' to '/include/c++/v1'.
 // Note that InstallBin can be relative, so we use '..' instead of
 // parent_path.
@@ -2495,17 +2505,6 @@
<< "\"\n";
 }
 
-// Otherwise, check for (2)
-llvm::SmallString<128> SysrootUsr = Sysroot;
-llvm

[PATCH] D152436: [clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha.

2023-08-07 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 54.
balazske added a comment.
Herald added a subscriber: wangpc.

Using the latest version of the checker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152436

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/test/Analysis/PR49642.c
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/conversion.c
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/errno-stdlibraryfunctions.c
  clang/test/Analysis/std-c-library-functions-POSIX-lookup.c
  clang/test/Analysis/std-c-library-functions-POSIX-socket-sockaddr.cpp
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/std-c-library-functions-arg-cstring-dependency.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
  clang/test/Analysis/std-c-library-functions-arg-weakdeps.c
  clang/test/Analysis/std-c-library-functions-eof.c
  clang/test/Analysis/std-c-library-functions-inlined.c
  clang/test/Analysis/std-c-library-functions-lookup.c
  clang/test/Analysis/std-c-library-functions-lookup.cpp
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/std-c-library-functions-restrict.c
  clang/test/Analysis/std-c-library-functions-restrict.cpp
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
  clang/test/Analysis/std-c-library-functions.c
  clang/test/Analysis/std-c-library-functions.cpp
  clang/test/Analysis/std-c-library-posix-crash.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-errno.c
  clang/test/Analysis/stream-noopen.c
  clang/test/Analysis/stream-note.c
  clang/test/Analysis/stream-stdlibraryfunctionargs.c
  clang/test/Analysis/weak-dependencies.c

Index: clang/test/Analysis/weak-dependencies.c
===
--- clang/test/Analysis/weak-dependencies.c
+++ clang/test/Analysis/weak-dependencies.c
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 %s -verify \
-// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=unix.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=core
 
 typedef __typeof(sizeof(int)) size_t;
Index: clang/test/Analysis/stream-stdlibraryfunctionargs.c
===
--- clang/test/Analysis/stream-stdlibraryfunctionargs.c
+++ clang/test/Analysis/stream-stdlibraryfunctionargs.c
@@ -1,11 +1,11 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
-// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,unix.StdCLibraryFunctions,debug.ExprInspection \
+// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
 
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection \
-// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
+// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
 
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
-// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdfunc,any %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.StdCLibraryFunctions,debug.ExprInspection \
+// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdfunc,any %s
 
 #include "Inputs/system-header-simulator.h"
 
Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream -analyzer-output text \
 // RUN:   -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions -analyzer-output text \
-// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=expected,stdargs %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,unix.StdCLibraryFunctions -analyzer-output text \
+// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=expected,stdargs %s
 
 #include "Inputs/system-header-simulator.h"
 
Index: clang/test/Anal

[PATCH] D89001: [clang] Don't look into for C++ headers if they are found alongside the toolchain

2023-08-07 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

@dexonsmith thank you for quick response. I think we need to update upstream 
behaviour to match system compiler behaviour otherwise clang-tools that uses 
path to compiler binary form CDB will not work as expected and extra options 
won't help much because it is not easy to inject in some cases. I sent 
https://reviews.llvm.org/D157283 for review. I got this change by running test 
agains system compiler and fixing it to match the real behaviour, after that I 
guessed how exactly this behaviour could be achieved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89001

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


[PATCH] D157285: [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory

2023-08-07 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93, ccotter.
Herald added subscribers: shchenz, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Implement proper support for lambdas and sub-functions/classes.

Fixes: #59389


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157285

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
@@ -395,3 +395,98 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'A *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
   }
 }
+
+namespace PR59389 {
+  struct S {
+S();
+S(int);
+
+int value = 1;
+  };
+
+  void testLambdaInFunctionNegative() {
+const auto MakeS = []() -> ::gsl::owner {
+  return ::gsl::owner{new S{}};
+};
+  }
+
+  void testLambdaInFunctionPositive() {
+const auto MakeS = []() -> S* {
+  return ::gsl::owner{new S{}};
+  // CHECK-NOTES: [[@LINE-1]]:7: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
+};
+  }
+
+  void testFunctionInFunctionNegative() {
+struct C {
+  ::gsl::owner test() {
+return ::gsl::owner{new S{}};
+  }
+};
+  }
+
+  void testFunctionInFunctionPositive() {
+struct C {
+  S* test() {
+return ::gsl::owner{new S{}};
+// CHECK-NOTES: [[@LINE-1]]:9: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
+  }
+};
+  }
+
+  ::gsl::owner testReverseLambdaNegative() {
+const auto MakeI = [] -> int { return 5; };
+return ::gsl::owner{new S(MakeI())};
+  }
+
+  S* testReverseLambdaPositive() {
+const auto MakeI = [] -> int { return 5; };
+return ::gsl::owner{new S(MakeI())};
+// CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
+  }
+
+  ::gsl::owner testReverseFunctionNegative() {
+struct C {
+  int test() { return 5; }
+};
+return ::gsl::owner{new S(C().test())};
+  }
+
+  S* testReverseFunctionPositive() {
+struct C {
+  int test() { return 5; }
+};
+return ::gsl::owner{new S(C().test())};
+// CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
+  }
+
+  void testLambdaInLambdaNegative() {
+const auto MakeS = []() -> ::gsl::owner {
+  const auto MakeI = []() -> int { return 5; };
+  return ::gsl::owner{new S(MakeI())};
+};
+  }
+
+  void testLambdaInLambdaPositive() {
+const auto MakeS = []() -> S* {
+  const auto MakeI = []() -> int { return 5; };
+  return ::gsl::owner{new S(MakeI())};
+  // CHECK-NOTES: [[@LINE-1]]:7: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
+};
+  }
+
+  void testReverseLambdaInLambdaNegative() {
+const auto MakeI = []() -> int {
+  const auto MakeS = []() -> ::gsl::owner { return new S(); };
+  return 5;
+};
+  }
+
+  void testReverseLambdaInLambdaPositive() {
+const auto MakeI = []() -> int {
+  const auto MakeS = []() -> S* { return new S(); };
+  // CHECK-NOTES: [[@LINE-1]]:39: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
+  return 5;
+};
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   to ignore ``static`` variables declared within the scope of
   ``class``/``struct``.
 
+- Improved :doc:`cppcoreguidelines-owning-memory
+  ` check to properly handle
+  return type in lambdas and in nested functions.
+
 - Improved :doc:`cppcoreguidelines-prefer-member-initializer
   ` check to
   ignore delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguideline

[PATCH] D157249: [clang][ASTImporter] Add import of 'ConvertVectorExpr'

2023-08-07 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 547781.
danix800 added a comment.

Cleanup since D157248  is landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157249

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
@@ -1295,6 +1295,29 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportConvertVectorExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  "typedef double v4double __attribute__((__vector_size__(32)));"
+  "typedef float  v4float  __attribute__((__vector_size__(16)));"
+  "v4float vf;"
+  "void declToImport() { (void)__builtin_convertvector(vf, v4double); }",
+  Lang_CXX03, "", Lang_CXX03);
+
+  auto ToResults =
+  match(convertVectorExpr().bind("convert"), To->getASTContext());
+  auto FromResults =
+  match(convertVectorExpr().bind("convert"), From->getASTContext());
+
+  const ConvertVectorExpr *FromConvertVectorExpr =
+  selectFirst("convert", FromResults);
+  ASSERT_TRUE(FromConvertVectorExpr);
+
+  const ConvertVectorExpr *ToConvertVectorExpr =
+  selectFirst("convert", ToResults);
+  ASSERT_TRUE(ToConvertVectorExpr);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -615,6 +615,7 @@
 ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
 ExpectedStmt VisitChooseExpr(ChooseExpr *E);
+ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
 ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
@@ -7038,6 +7039,21 @@
  ToRParenLoc, CondIsTrue);
 }
 
+ExpectedStmt ASTNodeImporter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
+  Error Err = Error::success();
+  auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
+  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
+  auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
+  auto ToType = importChecked(Err, E->getType());
+  auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
+  if (Err)
+return std::move(Err);
+
+  return new (Importer.getToContext())
+  ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
+E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
+}
+
 ExpectedStmt ASTNodeImporter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
   Error Err = Error::success();
   auto ToRParenLoc = importChecked(Err, E->getRParenLoc());


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1295,6 +1295,29 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportConvertVectorExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  "typedef double v4double __attribute__((__vector_size__(32)));"
+  "typedef float  v4float  __attribute__((__vector_size__(16)));"
+  "v4float vf;"
+  "void declToImport() { (void)__builtin_convertvector(vf, v4double); }",
+  Lang_CXX03, "", Lang_CXX03);
+
+  auto ToResults =
+  match(convertVectorExpr().bind("convert"), To->getASTContext());
+  auto FromResults =
+  match(convertVectorExpr().bind("convert"), From->getASTContext());
+
+  const ConvertVectorExpr *FromConvertVectorExpr =
+  selectFirst("convert", FromResults);
+  ASSERT_TRUE(FromConvertVectorExpr);
+
+  const ConvertVectorExpr *ToConvertVectorExpr =
+  selectFirst("convert", ToResults);
+  ASSERT_TRUE(ToConvertVectorExpr);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -615,6 +615,7 @@
 ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
 ExpectedStmt VisitChooseExpr(ChooseExpr *E);
+ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
 ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitGenericSelectionExpr(Gener

[PATCH] D157269: [Clang][AArch64] Diagnostics for SME attributes when target doesn't have 'sme'

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 547782.
sdesmalen marked 4 inline comments as done.
sdesmalen added a comment.

- Renamed `sme` to `'sme'` to make it clear that it relates to the target 
feature
- Split `function executed in streaming-SVE mode or using ZA state, requires 
sme` into:
  - `function executed in streaming-SVE mode requires 'sme'`
  - `function using ZA state requires 'sme'`
- Removed requirement for SVE being enabled for streaming-compatible functions
- Updated comment of `Sema::checkCall`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157269

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp
  llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  
llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll

Index: llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc < %s | FileCheck %s
+
+; This that the following code can be compiled without +sme, because if the
+; call is not entered in streaming-SVE mode at runtime, the codepath leading
+; to the smstop/smstart pair will not be executed either.
+
+target triple = "aarch64"
+
+define void @streaming_compatible() #0 {
+; CHECK-LABEL: streaming_compatible:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:stp d15, d14, [sp, #-80]! // 16-byte Folded Spill
+; CHECK-NEXT:stp d13, d12, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT:stp d11, d10, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:stp d9, d8, [sp, #48] // 16-byte Folded Spill
+; CHECK-NEXT:stp x30, x19, [sp, #64] // 16-byte Folded Spill
+; CHECK-NEXT:bl __arm_sme_state
+; CHECK-NEXT:and x19, x0, #0x1
+; CHECK-NEXT:tbz x19, #0, .LBB0_2
+; CHECK-NEXT:  // %bb.1:
+; CHECK-NEXT:msr SVCRSM, #0
+; CHECK-NEXT:  .LBB0_2:
+; CHECK-NEXT:bl non_streaming
+; CHECK-NEXT:tbz x19, #0, .LBB0_4
+; CHECK-NEXT:  // %bb.3:
+; CHECK-NEXT:msr SVCRSM, #1
+; CHECK-NEXT:  .LBB0_4:
+; CHECK-NEXT:ldp x30, x19, [sp, #64] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d11, d10, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d13, d12, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT:ldp d15, d14, [sp], #80 // 16-byte Folded Reload
+; CHECK-NEXT:ret
+  call void @non_streaming()
+  ret void
+}
+
+declare void @non_streaming()
+
+attributes #0 = { nounwind "aarch64_pstate_sm_compatible" }
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -446,8 +446,6 @@
 
   assert((!StreamingSVEMode || I->hasSME()) &&
  "Expected SME to be available");
-  assert((!StreamingCompatibleSVEMode || I->hasSVEorSME()) &&
- "Expected SVE or SME to be available");
 
   return I.get();
 }
Index: llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
===
--- llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
@@ -154,6 +154,12 @@
   let Inst{11-9} = pstatefield;
   let Inst{8} = imm;
   let Inst{7-5} = 0b011; // op2
+
+  // We shouldn't require 'sme' to compile streaming-compatible functions which
+  // call non-streaming functions as the SME smstart/smstop will only be
+  // executed at runtime if streaming-mode is enabled, which also means SME must
+  // be enabled.
+  let Predicates = [];
 }
 
 def : InstAlias<"smstart",(MSRpstatesvcrImm1 0b011, 0b1)>;
@@ -226,12 +232,6 @@
 def : Pat<(AArch64_smstop (i32 svcr_op:$pstate), (i64 0), (i64 1)),   // after call
   (MSRpstatesvcrImm1 svcr_op:$pstate, 0b0)>;
 
-// The generic case which gets expanded to a pseudo node.
-def : Pat<(AArch64_smstart (i32 svcr_op:$pstate), (i64 GPR64:$rtpstate), (i64 timm0_1:$expected_pstate)),
-  (MSRpstatePseudo svcr_op:$pstate, 0b1, GPR64:$rtpstate, timm0_1:$expected_pstate)>;
-def : Pat<(AArch64_smstop (i32 svcr_op:$pstate), (i64 GPR64:$rtpstate), (i64 timm0_1:$expected_pstate)),
-  (MSRpstatePseudo svcr_op:$pstate, 0b0, GPR64:$rtpstate, timm0_1:$expected_pstate)>;
-
 // Read and write TPIDR2_EL0
 def : Pat<(int_aarch64_sme_set_tpidr2 i64:$val),
   (MSR 0xde85, GPR64:$val)>;
@@ -243,6 +243,12 @@
   (OBSCURE_COPY GPR64:$idx)>;
 } // End let Predicates = [HasSME]
 
+/

[PATCH] D157283: [clang] Match -isysroot behaviour with system compiler on Darwin

2023-08-07 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith resigned from this revision.
dexonsmith added subscribers: arphaman, jroelofs.
dexonsmith added a comment.

This looks correct to me, but I'd rather have someone at Apple confirm. 
@ldionne (or @arphaman or @jroelofs), can you review and/or help to find the 
right person?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157283

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


[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-07 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 547783.
danix800 added a comment.

Cleanup since D157237  is landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1044,6 +1044,17 @@
  has(fieldDecl(hasType(dependentSizedArrayType(;
 }
 
+TEST_P(ImportExpr, DependentSizedExtVectorType) {
+  MatchVerifier Verifier;
+  testImport("template"
+ "class declToImport {"
+ "  typedef T __attribute__((ext_vector_type(Size))) type;"
+ "};",
+ Lang_CXX03, "", Lang_CXX03, Verifier,
+ classTemplateDecl(has(cxxRecordDecl(
+ has(typedefDecl(hasType(dependentSizedExtVectorType(;
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) {
   Decl *FromTU = getTuDecl(
   "struct A { int operator()() { return 1; } };"
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -260,6 +260,8 @@
  FromAST->getFileManager(), false);
 
 auto FoundNodes = match(SearchMatcher, FromCtx);
+if (FoundNodes.empty())
+  return testing::AssertionFailure() << "No node was found!";
 if (FoundNodes.size() != 1)
   return testing::AssertionFailure()
  << "Multiple potential nodes were found!";
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -381,7 +381,8 @@
 ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T);
 ExpectedType VisitVariableArrayType(const VariableArrayType *T);
 ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType 
*T);
-// FIXME: DependentSizedExtVectorType
+ExpectedType
+VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T);
 ExpectedType VisitVectorType(const VectorType *T);
 ExpectedType VisitExtVectorType(const ExtVectorType *T);
 ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
@@ -1264,6 +1265,18 @@
   T->getIndexTypeCVRQualifiers(), ToBracketsRange);
 }
 
+ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
+const DependentSizedExtVectorType *T) {
+  Error Err = Error::success();
+  QualType ToElementType = importChecked(Err, T->getElementType());
+  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
+  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
+  if (Err)
+return std::move(Err);
+  return Importer.getToContext().getDependentSizedExtVectorType(
+  ToElementType, ToSizeExpr, ToAttrLoc);
+}
+
 ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
   ExpectedType ToElementTypeOrErr = import(T->getElementType());
   if (!ToElementTypeOrErr)


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1044,6 +1044,17 @@
  has(fieldDecl(hasType(dependentSizedArrayType(;
 }
 
+TEST_P(ImportExpr, DependentSizedExtVectorType) {
+  MatchVerifier Verifier;
+  testImport("template"
+ "class declToImport {"
+ "  typedef T __attribute__((ext_vector_type(Size))) type;"
+ "};",
+ Lang_CXX03, "", Lang_CXX03, Verifier,
+ classTemplateDecl(has(cxxRecordDecl(
+ has(typedefDecl(hasType(dependentSizedExtVectorType(;
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) {
   Decl *FromTU = getTuDecl(
   "struct A { int operator()() { return 1; } };"
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -260,6 +260,8 @@
  FromAST->getFileManager(), false);
 
 auto FoundNodes = match(SearchMatcher, FromCtx);
+if (FoundNodes.empty())
+  return testing::AssertionFailure() << "No node was found!";
 if (FoundNodes.size() != 1)
   return testing::AssertionFailure()
  << "Multiple potential nodes were found!";
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -381,7 +381,

[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-07 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D157238#4565442 , @balazske wrote:

> In D157238#4565260 , @danix800 
> wrote:
>
>> In D157238#4565051 , @balazske 
>> wrote:
>>
>>> `ASTImporter` part looks good, I did not check the generated documentation 
>>> for correctness.
>>
>> Matcher part will be committed in https://reviews.llvm.org/D157237, these 
>> code is added here only to support this revision.
>
> It is possible to add D157237  as parent 
> revision (and upload code here without changes in D157237 
> ). It is more safe to have the exact same 
> code in the review that will be committed.

This revision is cleaned up since D157237  is 
already landed. For future revison I'll try these techniques to reduce 
reviewing burden. Thanks for reminding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

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


[PATCH] D157270: [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.

2023-08-07 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/test/Sema/aarch64-sme-func-attrs.c:181
 
+void non_za_definition(void) {
+  sme_arm_new_za(); // OK

rsandifo-arm wrote:
> Would be good to have some tests for indirect function calls too (via 
> function pointers), to make sure that the diagnostic still works when no decl 
> is available.
> 
> I suppose this applies to D157269 too.
I'm not sure that's necessary because D127762 already added tests to ensure the 
attributes propagate on pointer types, which then sets the ExtProtoInfo for 
those values. This patch merely checks the SME attribute fields from 
ExtProtoInfo. i.e. there is already nothing depending on a declaration being 
available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157270

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


[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-07 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

In D157119#4564546 , @vitalybuka 
wrote:

> I suspect one of your recent changes broke 
> https://lab.llvm.org/buildbot/#/builders/168/builds/14944
> Can you please take a look?

Happy to take a look, but there are 28 commits in the blame list for that 
build... what makes you suspect it's the one change that only *adds* build 
dependencies?  ISTM the `clangd` binary should be bit-identical before/after 
this change, right?

I can't reproduce the failure locally. Do we have a way to re-trigger that job 
for specific commits & bisect the blame list?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


[PATCH] D156749: [modules] Fix error about the same module being defined in different .pcm files when using VFS overlays.

2023-08-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

In D156749#4562469 , @vsapsai wrote:

> In D156749#4561803 , @jansvoboda11 
> wrote:
>
>> My suggestion is to use the actual real on-disk path. Not 
>> `FileEntryRef::getName()`, but something that always behaves as if 
>> `use-external-name` was set to `true`. I believe this would handle your 
>> VFS/VFS-use-external-name-true/VFS-use-external-name-false problem. It would 
>> also handle another pitfall: two compilations with distinct VFS overlays 
>> that redirect two different as-requested module map paths into the same 
>> on-disk path.
>
> Do you suggest doing it for the hashing or for ASTWriter or both? We are 
> already doing some module map path canonicalization (added a comment in 
> corresponding place) but it's not pure on-disk path, it takes into account 
> VFS.

I mainly meant in ``. And then make the PCM files VFS-agnostic, which 
would probably require us to do the same thing for all the paths we serialize 
there. But I don't know how feasible that is. Besides, the scanner relies on 
the virtual paths in PCM files.

I think your solution is the most pragmatic. If you're confident this doesn't 
break anything internally, I say go for it. But I think it's good to be aware 
of the pitfall I mentioned, and make sure the build system doesn't trigger that.




Comment at: clang/lib/Serialization/ASTWriter.cpp:1330
 AddPath(WritingModule->PresumedModuleMapFile.empty()
-? Map.getModuleMapFileForUniquing(WritingModule)->getName()
+? Map.getModuleMapFileForUniquing(WritingModule)
+  ->getNameAsRequested()

Can we canonicalize this also? It'd be useful in the scanner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156749

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


[PATCH] D89001: [clang] Don't look into for C++ headers if they are found alongside the toolchain

2023-08-07 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

SGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89001

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


  1   2   3   >