[PATCH] D95808: [test] Use host platform specific error message substitution in lit tests - continued

2021-03-30 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

@ASDenysPetrov, I think you need to mark this patch as Accepted so that someone 
can close this review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95808

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-30 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Sema/SemaCast.cpp:2236
+}
+  }
+

The expected semantics for this conversion are not the ordinary 
bitwise-reinterpretation semantics of `reinterpret_cast`, so this really should 
not be allowed as a `reinterpret_cast`.  Allowing it as a `static_cast` seems 
appropriate.



Comment at: clang/lib/Sema/SemaExpr.cpp:7315
+/// is not a scalar type.
+bool Sema::areCompatibleMatrixTypes(QualType srcTy, QualType destTy) {
+  assert(destTy->isMatrixType() && srcTy->isMatrixType());

"Compatible" has a specific meaning in the C standard, so if you aren't 
intending to invoke that concept of compatibility, you should find a new word.

It looks like this kind of cast is supposed to be doing an elementwise 
conversion.  I guess all the types you can have matrices of are 
interconvertible, so there are no restrictions on the element types.  But you 
definitely need this to produce a new `CastKind` for elementwise conversion 
instead of using `CK_BitCast`, which does a bitwise reinterpretation, which is 
not what you want.

Matrix element types already have to be scalar types, so those checks aren't 
doing anything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99489: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

2021-03-30 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius updated this revision to Diff 334064.
curdeius marked 2 inline comments as done.
curdeius added a comment.

- Clean up tests.
- Fix grammar comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99489

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx-concepts-requires-clause.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/Parser/cxx2b-lambdas.cpp

Index: clang/test/Parser/cxx2b-lambdas.cpp
===
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -18,13 +18,14 @@
 auto L10 = [] noexcept { return true; };
 auto L11 = [] -> bool { return true; };
 auto L12 = [] consteval {};
-auto L13 = [] requires requires() { true; }
-{};
-auto L15 = [] [[maybe_unused]]{};
+auto L13 = []() requires true {};
+auto L14 = [] requires true() requires true {};
+auto L15 = [] requires true noexcept {};
+auto L16 = [] [[maybe_unused]]{};
 
 auto XL0 = [] mutable constexpr mutable {};// expected-error{{cannot appear multiple times}}
 auto XL1 = [] constexpr mutable constexpr {};  // expected-error{{cannot appear multiple times}}
-auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body}}
+auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body of lambda expression}}
 auto XL3 = []( constexpr mutable constexpr {}; // expected-error{{invalid storage class specifier}} \
// expected-error{{function parameter cannot be constexpr}} \
// expected-error{{C++ requires}} \
@@ -32,3 +33,8 @@
// expected-note{{to match this '('}} \
// expected-error{{expected body}} \
// expected-warning{{duplicate 'constexpr'}}
+
+// http://llvm.org/PR49736
+auto XL4 = [] requires true {}; // expected-error{{expected body}}
+auto XL5 = [] requires true requires true {}; // expected-error{{expected body}}
+auto XL6 = [] requires true noexcept requires true {}; // expected-error{{expected body}}
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -7,3 +7,28 @@
 auto L2 = [](T1 arg1, T2 arg2) -> T1 { };
 auto L3 = [](auto arg) { T t; };
 auto L4 = []() { };
+
+// http://llvm.org/PR49736
+auto L5 = [](){};
+auto L6 = []{};
+auto L7 = []() noexcept {};
+auto L8 = [] noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L9 = [] requires true {};
+auto L10 = [] requires true(){};
+auto L11 = [] requires true() noexcept {};
+auto L12 = [] requires true noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L13 = []() noexcept requires true {};
+auto L14 = [] requires true() noexcept requires true {};
+
+auto XL0 = [] noexcept requires true {};   // expected-error {{expected body of lambda expression}}
+auto XL1 = [] requires true noexcept requires true {}; // expected-error {{expected body}}
+#if __cplusplus <= 202002L
+// expected-warning@-3 {{lambda without a parameter clause is a C++2b extension}}
+// expected-warning@-3 {{is a C++2b extension}}
+#endif
Index: clang/test/Parser/cxx-concepts-requires-clause.cpp
===
--- clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -154,7 +154,9 @@
 
 auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 1) { return 0; };
 
-auto lambda3 = [] requires (sizeof(char) == 1) { };
+auto lambda3 = [] requires(sizeof(char) == 1){};
+
+auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected body of lambda expression}}
 #if __cplusplus <= 202002L
-// expected-warning@-2{{is a C++2b extension}}
+// expected-warning@-2{{lambda without a parameter clause is a C++2b extension}}
 #endif
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -690,7 +690,7 @@
 ///   lambda-expression:
 /// lambda-introducer lambda-declarator compound-statement
 /// lambda-introducer '<' template-parameter-list '>'
-/// lambda-declarator compound-statement
+/// requires-clause[opt] lambda-declarator compound-statement
 ///
 ///   lambda-introducer:
 /// '[' lambda-capture[opt] ']'
@@ -1392,12 +1392,6 @@
 /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, D,
 TrailingReturnType, TrailingReturnTypeLoc,

[PATCH] D99489: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

2021-03-30 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/test/Parser/cxx2a-template-lambdas.cpp:17
+#endif
+auto L7 = [] requires true {}; // ?
+auto L8 = [] requires true noexcept {};

aaron.ballman wrote:
> This seems grammatically valid to me, was there a reason for the `// ?`?
Ooops, a WIP remnant.



Comment at: clang/test/Parser/cxx2a-template-lambdas.cpp:25-29
+auto L11 = [] requires true(){};
+auto L12 = [] requires true() noexcept {};
+auto L13 = [] requires true() noexcept requires true {};
+auto L14 = []() noexcept requires true {};
+auto L15 = [] requires true(){};

rsmith wrote:
> I'd find these examples easier to read with a space between `true` and `()`.
I've just clang-formatted the code. Isn't it the way to go?
I can format manually if desired though.



Comment at: clang/test/Parser/cxx2a-template-lambdas.cpp:33-36
+#if __cplusplus <= 202002L
+// expected-warning@-3 {{is a C++2b extension}}
+// expected-warning@-3 {{is a C++2b extension}}
+#endif

aaron.ballman wrote:
> It seems odd to warn the user about use of an extension they're not really 
> using, but I don't think this is strictly wrong as opposed to just not being 
> ideal. I don't think this will be trivial to improve the behavior, so I think 
> it's fine for the moment.
I agree that having an error **and** a warning is strange, but IMO the 
extension is used here.
Without the extension, you couldn't have `noexcept` without `()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99489

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-30 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7315
+/// is not a scalar type.
+bool Sema::areCompatibleMatrixTypes(QualType srcTy, QualType destTy) {
+  assert(destTy->isMatrixType() && srcTy->isMatrixType());

rjmccall wrote:
> "Compatible" has a specific meaning in the C standard, so if you aren't 
> intending to invoke that concept of compatibility, you should find a new word.
> 
> It looks like this kind of cast is supposed to be doing an elementwise 
> conversion.  I guess all the types you can have matrices of are 
> interconvertible, so there are no restrictions on the element types.  But you 
> definitely need this to produce a new `CastKind` for elementwise conversion 
> instead of using `CK_BitCast`, which does a bitwise reinterpretation, which 
> is not what you want.
> 
> Matrix element types already have to be scalar types, so those checks aren't 
> doing anything.
I see, so we need a new `CK_MatrixCast`, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-03-30 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1642
+Group, Flags<[CoreOption, HelpHidden]>,
+HelpText<"Enable transforming aligned vector move instruction to "
+ "unaligned vector move.">;

As far the user is concerned this isn’t a transform. From their perspective 
it’s always use unaligned move instructions.



Comment at: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll:6
+define <8 x i32> @test_256_1(i8 * %addr) {
+; CHECK-LABEL: test_256_1:
+; CHECK:   # %bb.0:

CHECK isn’t a valid prefix for this file



Comment at: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll:21
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 1
+  ret <8 x i32>%res

What are the tests with align 1 intended to show?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-03-30 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

The only use I could really see for this is to prevent a developers code from 
crashing when it’s distributed to someone else. For paranoia because it’s 
possible you have a bug and got lucky with alignment in your internal testing 
before you shipped.

If you need this your code has undefined behavior which should be fixed. You 
should not use this to make a known runtime exception go away.

Your code could still be miscompiled. For example, llvm really likes to replace 
ADD with OR when the bits don’t overlap. So it would be very easy to have your 
pointer arithmetic miscompiled because llvm believes a pointer is aligned but 
really isn’t.

Your code would not be portable to SSE. If your application does dynamic 
dispatch most of your users may get the AVX code path, but the smaller 
percentage on older hardware or cheaper hardware that doesn’t have AVX still 
get the exceptions.

I think you need to be very careful with how this feature is communicated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D52050: [Driver] Fix architecture triplets and search paths for Linux x32

2021-03-30 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:90
   return "x86_64-linux-android";
-// We don't want this for x32, otherwise it will match x86_64 libs
-if (TargetEnvironment != llvm::Triple::GNUX32 &&
-D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
-  return "x86_64-linux-gnu";
+if (TargetEnvironment == llvm::Triple::GNUX32) {
+  if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))

MaskRay wrote:
> I have cleaned up the code a bit. You may need to rebase.
Yeah, I have done that but not uploaded my latest diff yet (which doesn't work 
on x32, unfortunately). I will do that now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D52050: WIP: [Driver] Fix architecture triplets and search paths for Linux x32

2021-03-30 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz updated this revision to Diff 334071.
glaubitz retitled this revision from "[Driver] Fix architecture triplets and 
search paths for Linux x32" to "WIP: [Driver] Fix architecture triplets and 
search paths for Linux x32".
glaubitz added a comment.

Updated version which unfortunately still fails.

One of the problems is that I don't know how to detect a native x32 system
in getOSLibDir() in clang/lib/Driver/ToolChains/Linux.cpp.

On a native x32 system, libraries are not in /libx32.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -87,6 +87,8 @@
   case llvm::Triple::x86_64:
 if (IsAndroid)
   return "x86_64-linux-android";
+if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))
+  return "x86_64-linux-gnux32";
 // We don't want this for x32, otherwise it will match x86_64 libs
 if (TargetEnvironment != llvm::Triple::GNUX32 &&
 D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
@@ -210,7 +212,10 @@
 
   if (Triple.getArch() == llvm::Triple::x86_64 &&
   Triple.getEnvironment() == llvm::Triple::GNUX32)
-return "libx32";
+if (getDriver().getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))
+  return "lib32";
+else
+  return "libx32";
 
   if (Triple.getArch() == llvm::Triple::riscv32)
 return "lib32";
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2105,8 +2105,10 @@
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
   "x86_64-slackware-linux", "x86_64-unknown-linux",
-  "x86_64-amazon-linux","x86_64-linux-android"};
-  static const char *const X32LibDirs[] = {"/libx32"};
+  "x86_64-amazon-linux","x86_64-linux-android",
+  "x86_64-linux-gnux32","x86_64-unknown-linux-gnux32",
+  "x86_64-pc-linux-gnux32"};
+  static const char *const X32LibDirs[] = {"/libx32", "/lib"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
   "i686-linux-gnu","i686-pc-linux-gnu",  "i386-redhat-linux6E",


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -87,6 +87,8 @@
   case llvm::Triple::x86_64:
 if (IsAndroid)
   return "x86_64-linux-android";
+if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))
+  return "x86_64-linux-gnux32";
 // We don't want this for x32, otherwise it will match x86_64 libs
 if (TargetEnvironment != llvm::Triple::GNUX32 &&
 D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
@@ -210,7 +212,10 @@
 
   if (Triple.getArch() == llvm::Triple::x86_64 &&
   Triple.getEnvironment() == llvm::Triple::GNUX32)
-return "libx32";
+if (getDriver().getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))
+  return "lib32";
+else
+  return "libx32";
 
   if (Triple.getArch() == llvm::Triple::riscv32)
 return "lib32";
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2105,8 +2105,10 @@
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
   "x86_64-slackware-linux", "x86_64-unknown-linux",
-  "x86_64-amazon-linux","x86_64-linux-android"};
-  static const char *const X32LibDirs[] = {"/libx32"};
+  "x86_64-amazon-linux","x86_64-linux-android",
+  "x86_64-linux-gnux32","x86_64-unknown-linux-gnux32",
+  "x86_64-pc-linux-gnux32"};
+  static const char *const X32LibDirs[] = {"/libx32", "/lib"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
   "i686-linux-gnu","i686-pc-linux-gnu",  "i386-redhat-linux6E",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-03-30 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1642
+Group, Flags<[CoreOption, HelpHidden]>,
+HelpText<"Enable transforming aligned vector move instruction to "
+ "unaligned vector move.">;

craig.topper wrote:
> As far the user is concerned this isn’t a transform. From their perspective 
> it’s always use unaligned move instructions.
How about "Always emit unaligned move instructions." ? Do you have any 
suggestion here?



Comment at: llvm/lib/Target/X86/X86MCInstLower.cpp:2708
+  // enabled.
+  if (EnableX86UnalignedVecMove) {
+for (const auto Pair : AlignedMovToUnalignedMovTable) {

Forgot to check the SSE level. I will add in next patch.



Comment at: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll:6
+define <8 x i32> @test_256_1(i8 * %addr) {
+; CHECK-LABEL: test_256_1:
+; CHECK:   # %bb.0:

craig.topper wrote:
> CHECK isn’t a valid prefix for this file
Thanks for reminding. I forgot to delete the these. I will remove these in next 
patch.



Comment at: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll:21
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 1
+  ret <8 x i32>%res

craig.topper wrote:
> What are the tests with align 1 intended to show?
This is to distinguish the unaligned-mov converted from aligned-move and the 
original unaligned-move. See the difference between line12 and line28.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D99320: [RISCV] [1/2] Add intrinsic for Zbb extension

2021-03-30 Thread LevyHsu via Phabricator via cfe-commits
LevyHsu updated this revision to Diff 334072.
LevyHsu added a comment.

1. llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  - Fixed mishandling on op0
2. clang/include/clang/Basic/BuiltinsRISCV.def clang/lib/CodeGen/CGBuiltin.cpp
  - Reduce port to 2 versions for 32/64 only.
3. clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c 
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  - Remove extra tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99320

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll

Index: llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IB
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbb -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IBB
+
+declare i32 @llvm.riscv.orc.b.i32(i32)
+
+define i32 @orcb32(i32 %a) nounwind {
+; RV64IB-LABEL: orcb32:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:orc.b a0, a0
+; RV64IB-NEXT:ret
+;
+; RV64IBB-LABEL: orcb32:
+; RV64IBB:   # %bb.0:
+; RV64IBB-NEXT:orc.b a0, a0
+; RV64IBB-NEXT:ret
+  %tmp = call i32 @llvm.riscv.orc.b.i32(i32 %a)
+ ret i32 %tmp
+}
+
+declare i64 @llvm.riscv.orc.b.i64(i64)
+
+define i64 @orcb64(i64 %a) nounwind {
+; RV64IB-LABEL: orcb64:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:orc.b a0, a0
+; RV64IB-NEXT:ret
+;
+; RV64IBB-LABEL: orcb64:
+; RV64IBB:   # %bb.0:
+; RV64IBB-NEXT:orc.b a0, a0
+; RV64IBB-NEXT:ret
+  %tmp = call i64 @llvm.riscv.orc.b.i64(i64 %a)
+ ret i64 %tmp
+}
Index: llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IB
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IBB
+
+declare i32 @llvm.riscv.orc.b.i32(i32)
+
+define i32 @orcb(i32 %a) nounwind {
+; RV32IB-LABEL: orcb:
+; RV32IB:   # %bb.0:
+; RV32IB-NEXT:orc.b a0, a0
+; RV32IB-NEXT:ret
+;
+; RV32IBB-LABEL: orcb:
+; RV32IBB:   # %bb.0:
+; RV32IBB-NEXT:orc.b a0, a0
+; RV32IBB-NEXT:ret
+  %tmp = call i32 @llvm.riscv.orc.b.i32(i32 %a)
+ ret i32 %tmp
+}
Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -897,3 +897,7 @@
(srl (and GPR:$rs1, 0x), (i64 16,
   (PACKUW GPR:$rs1, GPR:$rs2)>;
 } // Predicates = [HasStdExtZbp, IsRV64]
+
+let Predicates = [HasStdExtZbb] in {
+def : PatGpr;
+} // Predicates = [HasStdExtZbb]
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -831,6 +831,8 @@
 
 /// Generic pattern classes
 
+class PatGpr
+: Pat<(OpNode GPR:$rs1), (Inst GPR:$rs1)>;
 class PatGprGpr
 : Pat<(OpNode GPR:$rs1, GPR:$rs2), (Inst GPR:$rs1, GPR:$rs2)>;
 class PatGprSimm12
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -198,6 +198,9 @@
 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
   }
 
+  if (Subtarget.hasStdExtZbb() && Subtarget.is64Bit())
+setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i32, Custom);
+
   if (Subtarget.is64Bit()) {
 setOperationAction(ISD::ADD, MVT::i32, Custom);
 setOperationAction(ISD::SUB, MVT::i32, Custom);
@@ -4168,6 +4171,14 @@
 default:
   llvm_unreachable(
   "Don't know how to custom type legalize this intrinsic!");
+case Intrinsic::riscv_orc_b: {
+  SDValue Newop1 =
+  DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
+  

[PATCH] D99319: [RISCV] [2/2] Add intrinsic for Zbb extension

2021-03-30 Thread LevyHsu via Phabricator via cfe-commits
LevyHsu updated this revision to Diff 334073.
LevyHsu added a comment.

1. clang/lib/Headers/riscv_zbb_intrin.h
  - Remove extra ports. now orc_b handles xlen op,
  - _rv64_orc_b and _rv32_orc_b for RV64
  - _rv32_orc_b for RV32


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99319

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_zbb_intrin.h
  clang/lib/Headers/rvintrin.h
  clang/test/Headers/rvintrin.c

Index: clang/test/Headers/rvintrin.c
===
--- /dev/null
+++ clang/test/Headers/rvintrin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple riscv32 -fsyntax-only \
+// RUN:   -target-feature +experimental-zbb %s
+// RUN: %clang_cc1 -triple riscv64 -fsyntax-only \
+// RUN:   -target-feature +experimental-zbb %s
+
+#include 
Index: clang/lib/Headers/rvintrin.h
===
--- /dev/null
+++ clang/lib/Headers/rvintrin.h
@@ -0,0 +1,28 @@
+/* === rvintrin.h --===
+ *
+ * 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 __RVINTRIN_H
+#define __RVINTRIN_H
+
+// Long is 32 bit on riscv32 and 64 bit on riscv64 according to calling 
+// convention.
+#define int_xlen_t long
+#define uint_xlen_t unsigned int_xlen_t
+
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __artificial__, __nodebug__))
+
+#if defined(__riscv_zbb)
+#include "riscv_zbb_intrin.h"
+#endif
+
+#undef __DEFAULT_FN_ATTRS
+#undef uint_xlen_t
+#undef int_xlen_t
+#endif // __RVINTRIN_H
Index: clang/lib/Headers/riscv_zbb_intrin.h
===
--- /dev/null
+++ clang/lib/Headers/riscv_zbb_intrin.h
@@ -0,0 +1,52 @@
+/* === riscv_zbb_intrin.h --===
+ *
+ * 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 __RVINTRIN_H  
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __RISCV_ZBB_INTRIN_H
+#define __RISCV_ZBB_INTRIN_H
+
+#include 
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+// Zbb
+
+// RV32/64 ORC_B_32
+static __inline__ int32_t __DEFAULT_FN_ATTRS _rv32_orc_b(int32_t rs1) {
+  return __builtin_riscv_orc_b_32(rs1);
+}
+
+// RV32 ORC_B
+#if __riscv_xlen == 32
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b_32(rs1);
+}
+#endif // if __riscv_xlen == 32
+
+// RV64 ORC_B and ORC_B_64
+#if __riscv_xlen == 64
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b_64(rs1);
+}
+
+static __inline__ int64_t __DEFAULT_FN_ATTRS _rv64_orc_b(int64_t rs1) {
+  return __builtin_riscv_orc_b_64(rs1);
+}
+#endif // if __riscv_xlen == 64
+
+#if defined(__cplusplus)
+}
+#endif // if defined(__cplusplus)
+
+#endif // __RISCV_ZBB_INTRIN_H
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -97,6 +97,8 @@
   ptwriteintrin.h
   rdseedintrin.h
   rtmintrin.h
+  rvintrin.h
+  riscv_zbb_intrin.h
   serializeintrin.h
   sgxintrin.h
   s390intrin.h
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -152,6 +152,8 @@
   {"include/prfchwintrin.h", ""},
   {"include/rdseedintrin.h", ""},
   {"include/rtmintrin.h", ""},
+  {"include/rvintrin.h", ""},
+  {"include/riscv_zbb_i

[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1958-1959
+   EnableNullFPSuppression);
+  } else { // Track only the LHS of divisions.
+if (LHSV.isZeroConstant())
+  trackExpressionValue(InputNode, BO->getLHS(), report, TKind,

Both divisions and modulo operations can flow here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

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


[PATCH] D99489: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

2021-03-30 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius updated this revision to Diff 334075.
curdeius added a comment.

- Rebase to fix CI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99489

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx-concepts-requires-clause.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/Parser/cxx2b-lambdas.cpp

Index: clang/test/Parser/cxx2b-lambdas.cpp
===
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -18,13 +18,14 @@
 auto L10 = [] noexcept { return true; };
 auto L11 = [] -> bool { return true; };
 auto L12 = [] consteval {};
-auto L13 = [] requires requires() { true; }
-{};
-auto L15 = [] [[maybe_unused]]{};
+auto L13 = []() requires true {};
+auto L14 = [] requires true() requires true {};
+auto L15 = [] requires true noexcept {};
+auto L16 = [] [[maybe_unused]]{};
 
 auto XL0 = [] mutable constexpr mutable {};// expected-error{{cannot appear multiple times}}
 auto XL1 = [] constexpr mutable constexpr {};  // expected-error{{cannot appear multiple times}}
-auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body}}
+auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body of lambda expression}}
 auto XL3 = []( constexpr mutable constexpr {}; // expected-error{{invalid storage class specifier}} \
// expected-error{{function parameter cannot be constexpr}} \
// expected-error{{C++ requires}} \
@@ -32,3 +33,8 @@
// expected-note{{to match this '('}} \
// expected-error{{expected body}} \
// expected-warning{{duplicate 'constexpr'}}
+
+// http://llvm.org/PR49736
+auto XL4 = [] requires true {}; // expected-error{{expected body}}
+auto XL5 = [] requires true requires true {}; // expected-error{{expected body}}
+auto XL6 = [] requires true noexcept requires true {}; // expected-error{{expected body}}
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -7,3 +7,28 @@
 auto L2 = [](T1 arg1, T2 arg2) -> T1 { };
 auto L3 = [](auto arg) { T t; };
 auto L4 = []() { };
+
+// http://llvm.org/PR49736
+auto L5 = [](){};
+auto L6 = []{};
+auto L7 = []() noexcept {};
+auto L8 = [] noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L9 = [] requires true {};
+auto L10 = [] requires true(){};
+auto L11 = [] requires true() noexcept {};
+auto L12 = [] requires true noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L13 = []() noexcept requires true {};
+auto L14 = [] requires true() noexcept requires true {};
+
+auto XL0 = [] noexcept requires true {};   // expected-error {{expected body of lambda expression}}
+auto XL1 = [] requires true noexcept requires true {}; // expected-error {{expected body}}
+#if __cplusplus <= 202002L
+// expected-warning@-3 {{lambda without a parameter clause is a C++2b extension}}
+// expected-warning@-3 {{is a C++2b extension}}
+#endif
Index: clang/test/Parser/cxx-concepts-requires-clause.cpp
===
--- clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -154,7 +154,9 @@
 
 auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 1) { return 0; };
 
-auto lambda3 = [] requires (sizeof(char) == 1) { };
+auto lambda3 = [] requires(sizeof(char) == 1){};
+
+auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected body of lambda expression}}
 #if __cplusplus <= 202002L
-// expected-warning@-2{{is a C++2b extension}}
+// expected-warning@-2{{lambda without a parameter clause is a C++2b extension}}
 #endif
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -690,7 +690,7 @@
 ///   lambda-expression:
 /// lambda-introducer lambda-declarator compound-statement
 /// lambda-introducer '<' template-parameter-list '>'
-/// lambda-declarator compound-statement
+/// requires-clause[opt] lambda-declarator compound-statement
 ///
 ///   lambda-introducer:
 /// '[' lambda-capture[opt] ']'
@@ -1392,12 +1392,6 @@
 /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, D,
 TrailingReturnType, TrailingReturnTypeLoc, &DS),
 std::move(Attr), DeclEndLoc);
-
-// 

[PATCH] D94355: [Passes] Add relative lookup table converter pass

2021-03-30 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

It looks like this is breaking the Windows/ARM(64) target - it doesn't produce 
the right relative relocations for symbol differences. It can be reproduced 
with a testcase like this:

  $ cat test.s
  .text
  func1:
  ret
  func2:
  ret
  
  .section.rdata,"dr"
  .p2align2
  table:
  .long   func1-table
  .long   func2-table
  $ clang -target aarch64-windows -c -o - test.s | llvm-objdump -r -s -
  
  :file format coff-arm64
  
  RELOCATION RECORDS FOR [.rdata]:
  OFFSET   TYPE VALUE
   IMAGE_REL_ARM64_ADDR32   func1
  0004 IMAGE_REL_ARM64_ADDR32   func2
  
  Contents of section .text:
    c0035fd6 c0035fd6.._..._.
  Contents of section .rdata: 
     0400

Those relocations would need to be IMAGE_REL_ARM64_REL32. It looks like the 
arm/windows target has got the same issue as well.

Would you be ok with reverting this change until I can sort that out, or can we 
disable the pass for those targets until then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

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


[PATCH] D99568: [clang][invocation] Fix copy constructor, add copy assignment to CompilerInvocation

2021-03-30 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The `CompilerInvocationBase` class factors out members of `CompilerInvocation` 
that need special handling (initialization or copy constructor), so that 
`CompilerInvocation` can be implemented as a simple value object.

Currently, the `AnalyzerOpts` member of `CompilerInvocation` violates that 
setup. This patch extracts the member to `CompilerInvocationBase` and handles 
it in the copy constructor the same way other it handles other members.

Moreover, this patch adds a copy-assignment operator to 
`CompilerInvocationBase`, making the whole `CompilerInvocation` 
copy-assignable. This will prove useful in a follow-up patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99568

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -97,6 +97,29 @@
   ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
 }
 
+// Copy constructor/assignment do a deep copy of reference-counted pointers.
+
+TEST(CompilerInvocationTest, DeepCopyConstructor) {
+  CompilerInvocation A;
+  A.getAnalyzerOpts()->Config["Foo"] = "Original";
+
+  CompilerInvocation B(A);
+  B.getAnalyzerOpts()->Config["Foo"] = "New";
+
+  ASSERT_EQ(A.getAnalyzerOpts()->Config["Foo"], "Original");
+}
+
+TEST(CompilerInvocationTest, DeepCopyAssignment) {
+  CompilerInvocation A;
+  A.getAnalyzerOpts()->Config["Foo"] = "Original";
+
+  CompilerInvocation B;
+  B = A;
+  B.getAnalyzerOpts()->Config["Foo"] = "New";
+
+  ASSERT_EQ(A.getAnalyzerOpts()->Config["Foo"], "Original");
+}
+
 // Boolean option with a keypath that defaults to true.
 // The only flag with a negative spelling can set the keypath to false.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -113,14 +113,28 @@
 : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()),
   DiagnosticOpts(new DiagnosticOptions()),
   HeaderSearchOpts(new HeaderSearchOptions()),
-  PreprocessorOpts(new PreprocessorOptions()) {}
+  PreprocessorOpts(new PreprocessorOptions()),
+  AnalyzerOpts(new AnalyzerOptions()) {}
 
 CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X)
 : LangOpts(new LangOptions(*X.getLangOpts())),
   TargetOpts(new TargetOptions(X.getTargetOpts())),
   DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())),
   HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())),
-  PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {}
+  PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())),
+  AnalyzerOpts(new AnalyzerOptions(*X.getAnalyzerOpts())) {}
+
+CompilerInvocationBase &
+CompilerInvocationBase::operator=(CompilerInvocationBase X) {
+  LangOpts.swap(X.LangOpts);
+  TargetOpts.swap(X.TargetOpts);
+  DiagnosticOpts.swap(X.DiagnosticOpts);
+  HeaderSearchOpts.swap(X.HeaderSearchOpts);
+  PreprocessorOpts.swap(X.PreprocessorOpts);
+  AnalyzerOpts.swap(X.AnalyzerOpts);
+
+  return *this;
+}
 
 CompilerInvocationBase::~CompilerInvocationBase() = default;
 
Index: clang/include/clang/Frontend/CompilerInvocation.h
===
--- clang/include/clang/Frontend/CompilerInvocation.h
+++ clang/include/clang/Frontend/CompilerInvocation.h
@@ -78,9 +78,12 @@
   /// Options controlling the preprocessor (aside from \#include handling).
   std::shared_ptr PreprocessorOpts;
 
+  /// Options controlling the static analyzer.
+  AnalyzerOptionsRef AnalyzerOpts;
+
   CompilerInvocationBase();
   CompilerInvocationBase(const CompilerInvocationBase &X);
-  CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete;
+  CompilerInvocationBase &operator=(CompilerInvocationBase X);
   ~CompilerInvocationBase();
 
   LangOptions *getLangOpts() { return LangOpts.get(); }
@@ -110,6 +113,8 @@
   const PreprocessorOptions &getPreprocessorOpts() const {
 return *PreprocessorOpts;
   }
+
+  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
 };
 
 /// Helper class for holding the data necessary to invoke the compiler.
@@ -118,9 +123,6 @@
 /// compiler, including data such as the include paths, the code generation
 /// options, the warning flags, and so on.
 class CompilerInvocation : public CompilerInvocationBase {
-  /// Options controlling the static analyzer.
-  AnalyzerOptionsRef Analyzer

[PATCH] D98499: [clangd] Introduce ASTHooks to FeatureModules

2021-03-30 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 334079.
kadircet added a comment.

- Have 2 separate hooks for preamble and mainfile ASTs, as they are produced 
async.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98499

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -25,6 +25,7 @@
 #include "support/Path.h"
 #include "llvm/ADT/StringMap.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +77,8 @@
   // to eliminate this option some day.
   bool OverlayRealFileSystemForModules = false;
 
+  std::vector> Hooks;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   // The result will always have getDiagnostics() populated.
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -36,6 +36,8 @@
   FS.Files[ImportThunk] = ThunkContents;
 
   ParseInputs Inputs;
+  Inputs.PreambleHooks = Hooks;
+  Inputs.MainFileHooks = Hooks;
   auto &Argv = Inputs.CompileCommand.CommandLine;
   Argv = {"clang"};
   // FIXME: this shouldn't need to be conditional, but it breaks a
@@ -97,6 +99,7 @@
   MockFS FS;
   auto Inputs = inputs(FS);
   StoreDiags Diags;
+  Diags.setASTHooks(Inputs.MainFileHooks);
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
   if (OverlayRealFileSystemForModules)
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1346,6 +1346,24 @@
  });
 }
 
+TEST(ParsedASTTest, ModuleSawDiag) {
+  static constexpr const llvm::StringLiteral KDiagMsg = "StampedDiag";
+  struct Hooks : public FeatureModule::ASTListener {
+void sawDiagnostic(const clang::Diagnostic &Info,
+   clangd::Diag &Diag) override {
+  Diag.Message = KDiagMsg.str();
+}
+  };
+
+  Annotations Code("[[test]]; /* error-ok */");
+  TestTU TU;
+  TU.Code = Code.code().str();
+  TU.Hooks.emplace_back(new Hooks);
+
+  auto AST = TU.build();
+  EXPECT_THAT(*AST.getDiagnostics(),
+  testing::Contains(Diag(Code.range(), KDiagMsg.str(;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -365,6 +365,27 @@
   // And immediately shut down. FeatureModule destructor verifies we blocked.
 }
 
+TEST_F(LSPTest, DiagModuleTest) {
+  static constexpr llvm::StringLiteral DiagMsg = "DiagMsg";
+  class DiagModule final : public FeatureModule {
+struct DiagHooks : public ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &, clangd::Diag &D) override {
+D.Message = DiagMsg.str();
+  }
+};
+
+  public:
+std::unique_ptr astHooks() override {
+  return std::make_unique();
+}
+  };
+  FeatureModules.add(std::make_unique());
+
+  auto &Client = start();
+  Client.didOpen("foo.cpp", "test;");
+  EXPECT_THAT(Client.diagnostics("foo.cpp"),
+  llvm::ValueIs(testing::ElementsAre(DiagMessage(DiagMsg;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -46,6 +46,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Path.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -119,13 +120,18 @@
   }
 
   // Prepare inputs and build CompilerInvocation (parsed compile command).
-  bool buildInvocation(const Threa

[clang] 1cbba53 - [ObjC][CodeGen] Fix missing debug info in situations where an instance and class property have the same identifier

2021-03-30 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2021-03-30T11:07:16+02:00
New Revision: 1cbba533ec93864caab8ad2f3fd4293a56723307

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

LOG: [ObjC][CodeGen] Fix missing debug info in situations where an instance and 
class property have the same identifier

Since the introduction of class properties in Objective-C it is possible to 
declare a class and an instance
property with the same identifier in an interface/protocol.

Right now Clang just generates debug information for whatever property comes 
first in the source file.
The second property is ignored as it's filtered out by the set of already 
emitted properties (which is just
using the identifier of the property to check for equivalence).  I don't think 
generating debug info in this case
was never supported as the identifier filter is in place since 
7123bca7fb6e1dde51be8329cfb523d2bb9ffadf
(which precedes the introduction of class properties).

This patch expands the filter to take in account identifier + whether the 
property is class/instance. This
ensures that both properties are emitted in this special situation.

Reviewed By: aprantl

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

Added: 
clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index c80249a9c9fc..3fe56346088c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2740,16 +2740,26 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const 
ObjCInterfaceType *Ty,
 EltTys.push_back(PropertyNode);
   };
   {
-llvm::SmallPtrSet PropertySet;
+// Use 'char' for the isClassProperty bit as DenseSet requires space for
+// empty/tombstone keys in the data type (and bool is too small for that).
+typedef std::pair IsClassAndIdent;
+/// List of already emitted properties. Two distinct class and instance
+/// properties can share the same identifier (but not two instance
+/// properties or two class properties).
+llvm::DenseSet PropertySet;
+/// Returns the IsClassAndIdent key for the given property.
+auto GetIsClassAndIdent = [](const ObjCPropertyDecl *PD) {
+  return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
+};
 for (const ObjCCategoryDecl *ClassExt : ID->known_extensions())
   for (auto *PD : ClassExt->properties()) {
-PropertySet.insert(PD->getIdentifier());
+PropertySet.insert(GetIsClassAndIdent(PD));
 AddProperty(PD);
   }
 for (const auto *PD : ID->properties()) {
   // Don't emit duplicate metadata for properties that were already in a
   // class extension.
-  if (!PropertySet.insert(PD->getIdentifier()).second)
+  if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
 continue;
   AddProperty(PD);
 }

diff  --git 
a/clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m 
b/clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
new file mode 100644
index ..68423fc07f8a
--- /dev/null
+++ b/clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -S -emit-llvm -debug-info-kind=limited %s -o - | FileCheck 
%s
+
+// Both properties should be emitted as having a class and an instance property
+// with the same name is allowed.
+@interface I1
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property int p1;
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property(class) int p1;
+@end
+
+@implementation I1
+@synthesize p1;
+@end
+
+void foo(I1 *iptr) {}



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


[PATCH] D99512: [ObjC][CodeGen] Fix missing debug info in situations where an instance and class property have the same identifier

2021-03-30 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1cbba533ec93: [ObjC][CodeGen] Fix missing debug info in 
situations where an instance and… (authored by teemperor).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99512

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m


Index: clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -S -emit-llvm -debug-info-kind=limited %s -o - | FileCheck 
%s
+
+// Both properties should be emitted as having a class and an instance property
+// with the same name is allowed.
+@interface I1
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property int p1;
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property(class) int p1;
+@end
+
+@implementation I1
+@synthesize p1;
+@end
+
+void foo(I1 *iptr) {}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2740,16 +2740,26 @@
 EltTys.push_back(PropertyNode);
   };
   {
-llvm::SmallPtrSet PropertySet;
+// Use 'char' for the isClassProperty bit as DenseSet requires space for
+// empty/tombstone keys in the data type (and bool is too small for that).
+typedef std::pair IsClassAndIdent;
+/// List of already emitted properties. Two distinct class and instance
+/// properties can share the same identifier (but not two instance
+/// properties or two class properties).
+llvm::DenseSet PropertySet;
+/// Returns the IsClassAndIdent key for the given property.
+auto GetIsClassAndIdent = [](const ObjCPropertyDecl *PD) {
+  return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
+};
 for (const ObjCCategoryDecl *ClassExt : ID->known_extensions())
   for (auto *PD : ClassExt->properties()) {
-PropertySet.insert(PD->getIdentifier());
+PropertySet.insert(GetIsClassAndIdent(PD));
 AddProperty(PD);
   }
 for (const auto *PD : ID->properties()) {
   // Don't emit duplicate metadata for properties that were already in a
   // class extension.
-  if (!PropertySet.insert(PD->getIdentifier()).second)
+  if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
 continue;
   AddProperty(PD);
 }


Index: clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/debug-info-property-class-instance-same-name.m
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -S -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+// Both properties should be emitted as having a class and an instance property
+// with the same name is allowed.
+@interface I1
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property int p1;
+// CHECK: !DIObjCProperty(name: "p1"
+// CHECK-SAME:line: [[@LINE+1]]
+@property(class) int p1;
+@end
+
+@implementation I1
+@synthesize p1;
+@end
+
+void foo(I1 *iptr) {}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2740,16 +2740,26 @@
 EltTys.push_back(PropertyNode);
   };
   {
-llvm::SmallPtrSet PropertySet;
+// Use 'char' for the isClassProperty bit as DenseSet requires space for
+// empty/tombstone keys in the data type (and bool is too small for that).
+typedef std::pair IsClassAndIdent;
+/// List of already emitted properties. Two distinct class and instance
+/// properties can share the same identifier (but not two instance
+/// properties or two class properties).
+llvm::DenseSet PropertySet;
+/// Returns the IsClassAndIdent key for the given property.
+auto GetIsClassAndIdent = [](const ObjCPropertyDecl *PD) {
+  return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
+};
 for (const ObjCCategoryDecl *ClassExt : ID->known_extensions())
   for (auto *PD : ClassExt->properties()) {
-PropertySet.insert(PD->getIdentifier());
+PropertySet.insert(GetIsClassAndIdent(PD));
 AddProperty(PD);
   }
 for (const auto *PD : ID->properties()) {
   // Don't emit duplicate metadata for properties that were already in a
   // class extension.
-  if (!PropertySet.insert(PD->getIdentifier()).second)
+  if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
 contin

[clang-tools-extra] 6d2fb3c - [clangd] Perform merging for stale symbols in MergeIndex

2021-03-30 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-03-30T11:09:51+02:00
New Revision: 6d2fb3cefba618be0326bb3da85d7568a72fefc4

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

LOG: [clangd] Perform merging for stale symbols in MergeIndex

Clangd drops symbols from static index whenever the dynamic index is
authoritative for the file. This results in regressions when static and
dynamic index contains different set of information, e.g.
IncludeHeaders.

After this patch, we'll choose to merge symbols from static index with
dynamic one rather than just dropping. This implies correctness problems
when the definition/documentation of the symbol is deleted. But seems
like it is worth having in more cases.

We still drop symbols if dynamic index owns the file and didn't report
the symbol, which means symbol is deleted.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Index.h
clang-tools-extra/clangd/index/Merge.cpp
clang-tools-extra/clangd/unittests/IndexTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Index.h 
b/clang-tools-extra/clangd/index/Index.h
index 91f7990312c7..04e67bc8df54 100644
--- a/clang-tools-extra/clangd/index/Index.h
+++ b/clang-tools-extra/clangd/index/Index.h
@@ -149,8 +149,9 @@ class SymbolIndex {
 
   /// Returns function which checks if the specified file was used to build 
this
   /// index or not. The function must only be called while the index is alive.
-  virtual llvm::unique_function
-  indexedFiles() const = 0;
+  using IndexedFiles =
+  llvm::unique_function;
+  virtual IndexedFiles indexedFiles() const = 0;
 
   /// Returns estimated size of index (in bytes).
   virtual size_t estimateMemoryUsage() const = 0;

diff  --git a/clang-tools-extra/clangd/index/Merge.cpp 
b/clang-tools-extra/clangd/index/Merge.cpp
index 54793cf566e8..54bb1ee06a05 100644
--- a/clang-tools-extra/clangd/index/Merge.cpp
+++ b/clang-tools-extra/clangd/index/Merge.cpp
@@ -22,6 +22,19 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Returns true if file defining/declaring \p S is covered by \p Index.
+bool isIndexAuthoritative(const SymbolIndex::IndexedFiles &Index,
+  const Symbol &S) {
+  // We expect the definition to see the canonical declaration, so it seems to
+  // be enough to check only the definition if it exists.
+  const char *OwningFile =
+  S.Definition ? S.Definition.FileURI : S.CanonicalDeclaration.FileURI;
+  return (Index(OwningFile) & IndexContents::Symbols) != IndexContents::None;
+}
+} // namespace
+
 bool MergedIndex::fuzzyFind(
 const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const {
@@ -37,36 +50,44 @@ bool MergedIndex::fuzzyFind(
   unsigned DynamicCount = 0;
   unsigned StaticCount = 0;
   unsigned MergedCount = 0;
+  // Number of results ignored due to staleness.
+  unsigned StaticDropped = 0;
   More |= Dynamic->fuzzyFind(Req, [&](const Symbol &S) {
 ++DynamicCount;
 DynB.insert(S);
   });
   SymbolSlab Dyn = std::move(DynB).build();
 
-  llvm::DenseSet SeenDynamicSymbols;
+  llvm::DenseSet ReportedDynSymbols;
   {
 auto DynamicContainsFile = Dynamic->indexedFiles();
 More |= Static->fuzzyFind(Req, [&](const Symbol &S) {
-  // We expect the definition to see the canonical declaration, so it seems
-  // to be enough to check only the definition if it exists.
-  if ((DynamicContainsFile(S.Definition ? S.Definition.FileURI
-: S.CanonicalDeclaration.FileURI) &
-   IndexContents::Symbols) != IndexContents::None)
-return;
-  auto DynS = Dyn.find(S.ID);
   ++StaticCount;
-  if (DynS == Dyn.end())
-return Callback(S);
-  ++MergedCount;
-  SeenDynamicSymbols.insert(S.ID);
-  Callback(mergeSymbol(*DynS, S));
+  auto DynS = Dyn.find(S.ID);
+  // If symbol also exist in the dynamic index, just merge and report.
+  if (DynS != Dyn.end()) {
+++MergedCount;
+ReportedDynSymbols.insert(S.ID);
+return Callback(mergeSymbol(*DynS, S));
+  }
+
+  // Otherwise, if the dynamic index owns the symbol's file, it means 
static
+  // index is stale just drop the symbol.
+  if (isIndexAuthoritative(DynamicContainsFile, S)) {
+++StaticDropped;
+return;
+  }
+
+  // If not just report the symbol from static index as is.
+  return Callback(S);
 });
   }
   SPAN_ATTACH(Tracer, "dynamic", DynamicCount);
   SPAN_ATTACH(Tracer, "static", StaticCount);
+  SPAN_ATTACH(Tracer, "static_dropped", StaticDropped);
   SPAN_ATTACH(Tracer, "merged", MergedCount);
   for (const Symbol &S : Dyn)
-if (!SeenDynamicSymbols.count(S.ID))
+if (!ReportedDynSymbols.co

[PATCH] D98538: [clangd] Perform merging for stale symbols in MergeIndex

2021-03-30 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6d2fb3cefba6: [clangd] Perform merging for stale symbols in 
MergeIndex (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98538

Files:
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp

Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Annotations.h"
+#include "SyncAPI.h"
 #include "TestIndex.h"
 #include "TestTU.h"
 #include "index/FileIndex.h"
@@ -17,6 +18,7 @@
 #include "clang/Index/IndexSymbol.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 using ::testing::_;
 using ::testing::AllOf;
@@ -312,16 +314,28 @@
   AST = Test.build();
   DynamicIndex.updateMain(testPath(Test.Filename), AST);
 
-  // Merged index should not return the symbol definition if this definition
-  // location is inside a file from the dynamic index.
+  // Even though the definition is actually deleted in the newer version of the
+  // file, we still chose to merge with information coming from static index.
+  // This seems wrong, but is generic behavior we want for e.g. include headers
+  // which are always missing from the dynamic index
   LookupRequest LookupReq;
   LookupReq.IDs = {Foo.ID};
   unsigned SymbolCounter = 0;
   Merge.lookup(LookupReq, [&](const Symbol &Sym) {
 ++SymbolCounter;
-EXPECT_FALSE(Sym.Definition);
+EXPECT_TRUE(Sym.Definition);
   });
   EXPECT_EQ(SymbolCounter, 1u);
+
+  // Drop the symbol completely.
+  Test.Code = "class Bar {};";
+  AST = Test.build();
+  DynamicIndex.updateMain(testPath(Test.Filename), AST);
+
+  // Now we don't expect to see the symbol at all.
+  SymbolCounter = 0;
+  Merge.lookup(LookupReq, [&](const Symbol &Sym) { ++SymbolCounter; });
+  EXPECT_EQ(SymbolCounter, 0u);
 }
 
 TEST(MergeIndexTest, FuzzyFind) {
@@ -585,6 +599,44 @@
IncludeHeaderWithRef("new", 1u)));
 }
 
+TEST(MergeIndexTest, IncludeHeadersMerged) {
+  auto S = symbol("Z");
+  S.Definition.FileURI = "unittest:///foo.cc";
+
+  SymbolSlab::Builder DynB;
+  S.IncludeHeaders.clear();
+  DynB.insert(S);
+  SymbolSlab DynSymbols = std::move(DynB).build();
+  RefSlab DynRefs;
+  auto DynSize = DynSymbols.bytes() + DynRefs.bytes();
+  auto DynData = std::make_pair(std::move(DynSymbols), std::move(DynRefs));
+  llvm::StringSet<> DynFiles = {S.Definition.FileURI};
+  MemIndex DynIndex(std::move(DynData.first), std::move(DynData.second),
+RelationSlab(), std::move(DynFiles), IndexContents::Symbols,
+std::move(DynData), DynSize);
+
+  SymbolSlab::Builder StaticB;
+  S.IncludeHeaders.push_back({"", 0});
+  StaticB.insert(S);
+  auto StaticIndex =
+  MemIndex::build(std::move(StaticB).build(), RefSlab(), RelationSlab());
+  MergedIndex Merge(&DynIndex, StaticIndex.get());
+
+  EXPECT_THAT(runFuzzyFind(Merge, S.Name),
+  ElementsAre(testing::Field(
+  &Symbol::IncludeHeaders,
+  ElementsAre(IncludeHeaderWithRef("", 0u);
+
+  LookupRequest Req;
+  Req.IDs = {S.ID};
+  std::string IncludeHeader;
+  Merge.lookup(Req, [&](const Symbol &S) {
+EXPECT_TRUE(IncludeHeader.empty());
+ASSERT_EQ(S.IncludeHeaders.size(), 1u);
+IncludeHeader = S.IncludeHeaders.front().IncludeHeader.str();
+  });
+  EXPECT_EQ(IncludeHeader, "");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/Merge.cpp
===
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -22,6 +22,19 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Returns true if file defining/declaring \p S is covered by \p Index.
+bool isIndexAuthoritative(const SymbolIndex::IndexedFiles &Index,
+  const Symbol &S) {
+  // We expect the definition to see the canonical declaration, so it seems to
+  // be enough to check only the definition if it exists.
+  const char *OwningFile =
+  S.Definition ? S.Definition.FileURI : S.CanonicalDeclaration.FileURI;
+  return (Index(OwningFile) & IndexContents::Symbols) != IndexContents::None;
+}
+} // namespace
+
 bool MergedIndex::fuzzyFind(
 const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const {
@@ -37,36 +50,44 @@
   unsigned DynamicCount = 0;
   unsigned StaticCount = 0;
   unsigned MergedCount = 0;
+  // Number of results ignored due to staleness.
+  unsigned StaticDropped = 0;
   More |= Dynamic->fuzzyFind(Req, [

[PATCH] D99421: [ASTImporter] Import member specialization/instantiation of enum decls

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 334086.
martong added a comment.

- Add check for specialization kind


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99421

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
@@ -6236,6 +6236,28 @@
   EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+enum tagname { enumerator };
+  };
+  template struct A;
+  )",
+  Lang_CXX03);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, enumDecl(hasName("tagname"),
+   hasParent(classTemplateSpecializationDecl(;
+  ASSERT_TRUE(FromD);
+  ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+  auto *ToD = Import(FromD, Lang_CXX03);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
+ToD->getTemplateSpecializationKind());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@
   D2->setBraceRange(ToBraceRange);
   D2->setAccess(D->getAccess());
   D2->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(D2);
+  addDeclToContexts(D, D2);
+
+  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = 
MemberInfo->getTemplateSpecializationKind();
+EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+if (Expected ToInstOrErr = import(FromInst))
+  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+  D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
+  }
 
   // Import the definition
   if (D->isCompleteDefinition())


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6236,6 +6236,28 @@
   EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+enum tagname { enumerator };
+  };
+  template struct A;
+  )",
+  Lang_CXX03);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, enumDecl(hasName("tagname"),
+   hasParent(classTemplateSpecializationDecl(;
+  ASSERT_TRUE(FromD);
+  ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+  auto *ToD = Import(FromD, Lang_CXX03);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
+ToD->getTemplateSpecializationKind());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@
   D2->setBraceRange(ToBraceRange);
   D2->setAccess(D->getAccess());
   D2->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(D2);
+  addDeclToContexts(D, D2);
+
+  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
+TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
+EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+if (Expected ToInstOrErr = import(FromInst))
+  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+  D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
+  }
 
   // Import the definition
   if (D->isCompleteDefinition())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52050: WIP: [Driver] Fix architecture triplets and search paths for Linux x32

2021-03-30 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

I may be missing something, but I do not understand the problem. What systems, 
other than Debian multi-arch, are you looking to also add support for? My own 
native x32 system uses `(/usr)/libx32` for x32 libraries. Debian uses 
`(/usr)/lib/x86_64-linux-gnux32`. I can understand if some people might use 
`(/usr)/lib` without any `x32` suffix, though I am not aware of anyone doing 
this. Where does `lib32` come from, though? What other systems are you trying 
to account for?

I may have some spare time soon, I can take a look and do some testing as well.




Comment at: clang/lib/Driver/ToolChains/Linux.cpp:217
+  return "lib32";
+else
+  return "libx32";

x86_64-linux-gnux32 never uses `lib32`, does it? It might use `lib` (mostly 
theoretical), or it might use `libx32`. Leaving this unmodified, always 
returning `libx32` for x32, looks to me like it matches x86_64-linux-gnu, which 
always returns `lib64` even though some people put libraries for that in `/lib` 
too.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:90
   return "x86_64-linux-android";
-// We don't want this for x32, otherwise it will match x86_64 libs
-if (TargetEnvironment != llvm::Triple::GNUX32 &&
-D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
-  return "x86_64-linux-gnu";
+if (TargetEnvironment == llvm::Triple::GNUX32) {
+  if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))

glaubitz wrote:
> MaskRay wrote:
> > I have cleaned up the code a bit. You may need to rebase.
> Yeah, I have done that but not uploaded my latest diff yet (which doesn't 
> work on x32, unfortunately). I will do that now.
This should have a `TargetEnvironment == llvm::Triple::GNUX32` check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D52050: WIP: [Driver] Fix architecture triplets and search paths for Linux x32

2021-03-30 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D52050#2657952 , @hvdijk wrote:

> I may be missing something, but I do not understand the problem. What 
> systems, other than Debian multi-arch, are you looking to also add support 
> for? My own native x32 system uses `(/usr)/libx32` for x32 libraries. Debian 
> uses `(/usr)/lib/x86_64-linux-gnux32`. I can understand if some people might 
> use `(/usr)/lib` without any `x32` suffix, though I am not aware of anyone 
> doing this. Where does `lib32` come from, though? What other systems are you 
> trying to account for?

I have tried all kinds of variants of this patch on Debian x32 with MultiArch 
and can't get it to work because it uses the wrong search-paths for the 
libraries.
I am still convinced the problem is that LLVM does not understand `x32` as a 
real distinct architecture unlike `i386` which is why we cannot apply the same
logic for `x32` and `i386`.

When the compiler tests `TargetEnvironment == llvm::Triple::GNUX32`, it does 
not know whether it's in a native `x32` environment or just on an `x86_64`
system where the target triplet is set to `x86_64-linux-gnux32` and I think 
that's the problem.

> I may have some spare time soon, I can take a look and do some testing as 
> well.

If you have a working fix for Debian x32, I would be happy to see it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D52050

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


[PATCH] D98574: [Sparc] Define the same macros for -mcpu=v9 as GCC on Linux and the BSDs

2021-03-30 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D98574#2654686 , @joerg wrote:

> The NetBSD part looks ok, but also lacks proper testing. I'm not sure anyone 
> but Linux cares at all otherwise as they lack 32bit SPARC support.

Well, there were no tests for NetBSD before, so I didn't change anything in 
this regard. I only changed clang to behave as gcc on SPARC and I
think that's the reasonable thing to do to avoid any compatibility issues when 
building with clang instead of gcc on any SPARC target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98574

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-03-30 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D99565#2657813 , @craig.topper 
wrote:

> The only use I could really see for this is to prevent a developers code from 
> crashing when it’s distributed to someone else. For paranoia because it’s 
> possible you have a bug and got lucky with alignment in your internal testing 
> before you shipped.
>
> If you need this your code has undefined behavior which should be fixed. You 
> should not use this to make a known runtime exception go away.
>
> Your code could still be miscompiled. For example, llvm really likes to 
> replace ADD with OR when the bits don’t overlap. So it would be very easy to 
> have your pointer arithmetic miscompiled because llvm believes a pointer is 
> aligned but really isn’t.
>
> Your code would not be portable to SSE. If your application does dynamic 
> dispatch most of your users may get the AVX code path, but the smaller 
> percentage on older hardware or cheaper hardware that doesn’t have AVX still 
> get the exceptions.

+ your code won't be portable to other compilers.

> I think you need to be very careful with how this feature is communicated.

+1, i have already wrote all that in the previous revision.
I really don't think this should go in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[clang] 98f6cbd - [ASTImporter] Import member specialization/instantiation of enum decls

2021-03-30 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-03-30T11:57:46+02:00
New Revision: 98f6cbd68eba04764f318d467abb10feca713776

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

LOG: [ASTImporter] Import member specialization/instantiation of enum decls

We do the import of the member enum specialization similarly to as we do
with member CXXRecordDecl specialization.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index ef7a3ea8a66c..dd11e3662148 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) 
{
   D2->setBraceRange(ToBraceRange);
   D2->setAccess(D->getAccess());
   D2->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(D2);
+  addDeclToContexts(D, D2);
+
+  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = 
MemberInfo->getTemplateSpecializationKind();
+EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+if (Expected ToInstOrErr = import(FromInst))
+  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+  D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
+  }
 
   // Import the definition
   if (D->isCompleteDefinition())

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index fdbf811c94dc..9f2b348905b5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6236,6 +6236,28 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportOfCapturedVLAType) {
   EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+enum tagname { enumerator };
+  };
+  template struct A;
+  )",
+  Lang_CXX03);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, enumDecl(hasName("tagname"),
+   hasParent(classTemplateSpecializationDecl(;
+  ASSERT_TRUE(FromD);
+  ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+  auto *ToD = Import(FromD, Lang_CXX03);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
+ToD->getTemplateSpecializationKind());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 



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


[PATCH] D99421: [ASTImporter] Import member specialization/instantiation of enum decls

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98f6cbd68eba: [ASTImporter] Import member 
specialization/instantiation of enum decls (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99421

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
@@ -6236,6 +6236,28 @@
   EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+enum tagname { enumerator };
+  };
+  template struct A;
+  )",
+  Lang_CXX03);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, enumDecl(hasName("tagname"),
+   hasParent(classTemplateSpecializationDecl(;
+  ASSERT_TRUE(FromD);
+  ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+  auto *ToD = Import(FromD, Lang_CXX03);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
+ToD->getTemplateSpecializationKind());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@
   D2->setBraceRange(ToBraceRange);
   D2->setAccess(D->getAccess());
   D2->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(D2);
+  addDeclToContexts(D, D2);
+
+  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = 
MemberInfo->getTemplateSpecializationKind();
+EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+if (Expected ToInstOrErr = import(FromInst))
+  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+  D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
+  }
 
   // Import the definition
   if (D->isCompleteDefinition())


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6236,6 +6236,28 @@
   EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template  struct A {
+enum tagname { enumerator };
+  };
+  template struct A;
+  )",
+  Lang_CXX03);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, enumDecl(hasName("tagname"),
+   hasParent(classTemplateSpecializationDecl(;
+  ASSERT_TRUE(FromD);
+  ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+  auto *ToD = Import(FromD, Lang_CXX03);
+  EXPECT_TRUE(ToD);
+  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
+ToD->getTemplateSpecializationKind());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@
   D2->setBraceRange(ToBraceRange);
   D2->setAccess(D->getAccess());
   D2->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(D2);
+  addDeclToContexts(D, D2);
+
+  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
+TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
+EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+if (Expected ToInstOrErr = import(FromInst))
+  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+  D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
+  }
 
   // Import the definition
   if (D->isCompleteDefinition())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99421: [ASTImporter] Import member specialization/instantiation of enum decls

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the review guys! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99421

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


[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 334093.
martong added a comment.

- Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/division-by-zero-track-zero.c
  clang/test/Analysis/division-by-zero-track-zero.cpp
  clang/test/Analysis/nullptr.cpp

Index: clang/test/Analysis/nullptr.cpp
===
--- clang/test/Analysis/nullptr.cpp
+++ clang/test/Analysis/nullptr.cpp
@@ -64,7 +64,7 @@
 
 typedef __INTPTR_TYPE__ intptr_t;
 void zoo1multiply() {
-  char **p = 0; // FIXME-should-be-note:{{'p' initialized to a null pointer value}}
+  char **p = 0; // expected-note{{'p' initialized to a null pointer value}}
   delete *((char **)((intptr_t)p * 2)); // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
 }
Index: clang/test/Analysis/division-by-zero-track-zero.cpp
===
--- /dev/null
+++ clang/test/Analysis/division-by-zero-track-zero.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+namespace test_tracking_of_lhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = p0 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_lhs_multiplier
+
+namespace test_tracking_of_rhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y * p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_rhs_multiplier
+
+namespace test_tracking_of_nested_multiplier {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y*z*p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_nested_multiplier
+
+namespace test_tracking_through_multiple_stmts {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}}
+bool p1 = p0 ? 0 : 1; // expected-note {{'p0' is false}} \
+  // expected-note {{'?' condition is false}}
+bool p2 = 1 - p1; // expected-note {{'p2' initialized to 0}}
+int div = p2 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_through_multiple_stmts
+
+namespace test_tracking_both_lhs_and_rhs {
+  int f(int x, int y) {
+bool p0 = x < 0;   // expected-note {{Assuming 'x' is >= 0}} \
+   // expected-note {{'p0' initialized to 0}}
+bool p1 = y < 0;   // expected-note {{Assuming 'y' is >= 0}} \
+   // expected-note {{'p1' initialized to 0}}
+int div = p0 * p1; // expected-note {{'div' initialized to 0}}
+return 1 / div;// expected-note {{Division by zero}} \
+   // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_both_lhs_and_rhs
+
+namespace test_tracking_of_multiplier_and_parens {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = y*(z*p0); // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_multiplier_and_parens
+
+namespace test_tracking_of_divisible {
+  int f(int x, int y) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = p0 / y;   // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_divisible
+
+namespace test_tracking_of_modulo {
+  int f(int x, int y) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+  

[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1958-1959
+   EnableNullFPSuppression);
+  } else { // Track only the LHS of divisions.
+if (LHSV.isZeroConstant())
+  trackExpressionValue(InputNode, BO->getLHS(), report, TKind,

steakhal wrote:
> Both divisions and modulo operations can flow here.
Ok, I updated the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

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


[PATCH] D94355: [Passes] Add relative lookup table converter pass

2021-03-30 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D94355#2657881 , @mstorsjo wrote:

> It looks like this is breaking the Windows/ARM(64) target - it doesn't 
> produce the right relative relocations for symbol differences. It can be 
> reproduced with a testcase like this:
>
> [...]
>
> Those relocations would need to be IMAGE_REL_ARM64_REL32. It looks like the 
> arm/windows target has got the same issue as well.
>
> Would you be ok with reverting this change until I can sort that out, or can 
> we disable the pass for those targets until then?

It turned out to not be all that hard to fix actually, see D99572 
 for such a fix. If I can get that landed 
soon, I think we might not need to act on this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

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


[PATCH] D99576: [ASTImporter][NFC] Improve test coverage

2021-03-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: martong, teemperor, shafik, balazske, a.sidorin.
Herald added subscribers: whisperity, rnkovacs, kristof.beyls.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

All three cases were imported //correctly//.
For BlockDecls, //correctly// means that we don't support importing them, thus 
an error is the expected behaviour.

- BlockDecls were not yet covered. I know that they are not imported but the 
test at least documents it.
- Default values for ParmVarDecls were also uncovered.
- Importing bitfield FieldDecls were imported correctly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99576

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3064,6 +3064,65 @@
   EXPECT_EQ(ToF1, ToF2);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBitfields) {
+  Decl *FromTU = getTuDecl("struct A { unsigned x : 3; };", Lang_CXX03);
+  auto *FromF =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("x")));
+
+  ASSERT_TRUE(FromF->isBitField());
+  ASSERT_EQ(3u, FromF->getBitWidthValue(FromTU->getASTContext()));
+  auto *ToField = Import(FromF, Lang_CXX03);
+  auto *ToTU = ToField->getTranslationUnitDecl();
+
+  EXPECT_TRUE(ToField->isBitField());
+  EXPECT_EQ(3u, ToField->getBitWidthValue(ToTU->getASTContext()));
+}
+
+struct ImportBlock : ASTImporterOptionSpecificTestBase {};
+const internal::VariadicDynCastAllOfMatcher blockDecl;
+TEST_P(ImportBlock, ImportBlocksAreUnsupported) {
+  const auto *Code = R"(
+void test_block__capture_null() {
+  int *p = 0;
+  ^(){
+*p = 1;
+  }();
+})";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX03);
+  auto *FromBlock = FirstDeclMatcher().match(FromTU, blockDecl());
+  ASSERT_TRUE(FromBlock);
+
+  auto ToBlockOrError = importOrError(FromBlock, Lang_CXX03);
+
+  const auto ExpectUnsupportedConstructError = [](const ImportError &Error) {
+EXPECT_EQ(ImportError::UnsupportedConstruct, Error.Error);
+  };
+  llvm::handleAllErrors(ToBlockOrError.takeError(),
+ExpectUnsupportedConstructError);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl) {
+  const auto *Code = R"(
+template  struct Wrapper {
+  Wrapper(T Value = {}) {}
+};
+template class Wrapper;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromVar = FirstDeclMatcher().match(
+  FromTU, parmVarDecl(hasType(asString("int";
+  ASSERT_TRUE(FromVar);
+  ASSERT_TRUE(FromVar->hasUninstantiatedDefaultArg());
+  ASSERT_TRUE(FromVar->getUninstantiatedDefaultArg());
+
+  const auto *ToVar = Import(FromVar, Lang_CXX11);
+  EXPECT_TRUE(ToVar);
+  EXPECT_TRUE(ToVar->hasUninstantiatedDefaultArg());
+  EXPECT_TRUE(ToVar->getUninstantiatedDefaultArg());
+  EXPECT_NE(FromVar->getUninstantiatedDefaultArg(),
+ToVar->getUninstantiatedDefaultArg());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportOfNonEquivalentField) {
   Decl *ToF1;
   {
@@ -6250,6 +6309,11 @@
   std::vector{
   "-ffixed-point"}), );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportBlock,
+ExtendWithOptions(DefaultTestArrayForRunOptions,
+  std::vector{
+  "-fblocks"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3064,6 +3064,65 @@
   EXPECT_EQ(ToF1, ToF2);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBitfields) {
+  Decl *FromTU = getTuDecl("struct A { unsigned x : 3; };", Lang_CXX03);
+  auto *FromF =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("x")));
+
+  ASSERT_TRUE(FromF->isBitField());
+  ASSERT_EQ(3u, FromF->getBitWidthValue(FromTU->getASTContext()));
+  auto *ToField = Import(FromF, Lang_CXX03);
+  auto *ToTU = ToField->getTranslationUnitDecl();
+
+  EXPECT_TRUE(ToField->isBitField());
+  EXPECT_EQ(3u, ToField->getBitWidthValue(ToTU->getASTContext()));
+}
+
+struct ImportBlock : ASTImporterOptionSpecificTestBase {};
+const internal::VariadicDynCastAllOfMatcher blockDecl;
+TEST_P(ImportBlock, ImportBlocksAreUnsupported) {
+  const auto *Code = R"(
+void test_block__capture_null() {
+  int *p = 0;
+  ^(){
+*p = 1;
+  }();
+})";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX03);
+  auto *FromBlock = FirstDeclMatcher().match(FromTU, blockDecl());
+  ASSERT_TRUE(FromBlock);
+

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked 3 inline comments as done.
AntonBikineev added inline comments.



Comment at: clang/lib/Lex/LiteralSupport.cpp:640
 isFloat16 = true;
 continue;
   }

rsmith wrote:
> Looks like this might fix [[ https://godbolt.org/z/9Pe4qr1c7 | incorrect 
> acceptance ]] of `1.0f16f` and `1.0f16L` in CUDA mode too :)
Nice!



Comment at: clang/lib/Sema/SemaExpr.cpp:3895
   // be an unsigned int.
   bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
 

I now begin to think that we should probably also prohibit things like 0x1234z 
to be implicitly interpreted as unsigned. Wdyt?



Comment at: clang/lib/Sema/SemaExpr.cpp:3997
   // does not fit in a signed long long, but has no U suffix.
   if (Ty.isNull()) {
 Diag(Tok.getLocation(), 
diag::ext_integer_literal_too_large_for_signed);

I think this branch should also be covered, since we probably don't want 
promotion from size_t to ULL but instead have a separate diagnostic that size_t 
is out-of-range. I've added another diagnostic and branch here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334102.
AntonBikineev marked an inline comment as done.
AntonBikineev added a comment.

Address comments. Also:

- always issue a new diagnostic if size_t/ssize_t is out of range;
- prohibit numbers with 'z' suffix and non-10-radix to be interpreted as 
unsigned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8";>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-linux -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++2b -triple i686-linux -fsyntax-only -verify=cxx2b-32 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void oor() {
+#if __i386__
+  (void)3'000'000'000z; // cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)3'000'000'000uz;
+  (void)5'000'000'000uz; // cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+
+  (void)0x8000z; //cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)0x8000uz;
+  (void)0x18000uz; //cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+#endif
+}
+
+#else
+
+void f() {
+  (void

[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-03-30 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:143
+  f_est_noexcept_dependent_used();
+}

balazske wrote:
> aaron.ballman wrote:
> > You have tests for placement new with `nothrow_t`, but I think other forms 
> > of placement new are also very interesting to test as those typically don't 
> > throw.
> > 
> > Additionally, perhaps tests where the allocation functions have been 
> > replaced by the user (such as a class allocation function)?
> I realized that the case of user-defined constructor or allocation function 
> allows to throw any kind of exception. So the check should be improved to 
> handle this case: Not rely on the syntax of new expression, instead check if 
> the called allocation function or the called constructor may throw, and if 
> yes, check what exceptions are possible. What is your opinion, is it a better 
> approach?
> (And a function to collect all possible exceptions called from a function is 
> needed, `ExceptionAnalyzer` seems usable.)
It looks like that the user is free to define custom `operator new` and any 
constructor called that may throw any exception. Even in the "nothrow" case it 
is possible to use a constructor that may throw? If we would analyze every 
possible throwable exception that may come out from a new-expression, the 
checker would end up almost in a general checker that checks for uncaught 
exceptions. At least it is easy to extend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97196

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


[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

land it




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1938
+  ProgramStateRef RVState = RVNode->getState();
+  SVal V = RVState->getSValAsScalarOrLoc(E, RVNode->getLocationContext());
+  const auto *BO = dyn_cast(E);

This note is not strictly for this patch.

At first, it wasn't clear to me why you call `getSValAsScalarOrLoc()`.
That just returns `unknown` if the Region is not boundable. Unfortunately, the 
`MemRegion::isBoundable()` has no documentation. IMO all virtual call deserves 
documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

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


[PATCH] D99577: [RFC][OpenCL][PoC] Testing TableGen with diffing

2021-03-30 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: svenvh, Anastasia.
Herald added subscribers: ldrumm, yaxunl.
azabaznov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds an option string to clang-check to ignore certain AST node types
in order to achive suitable printing policy for comparison with output
generated from TableGen. Header-like TablGen generation is based on 
https://reviews.llvm.org/D97869.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99577

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Frontend/ASTConsumers.h
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/Frontend/ASTConsumers.cpp
  clang/test/SemaOpenCL/compare-header-and-tablegen.cl
  clang/tools/clang-check/ClangCheck.cpp
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -123,6 +123,8 @@
 
 void EmitClangOpenCLBuiltins(llvm::RecordKeeper &Records,
  llvm::raw_ostream &OS);
+void EmitClangOpenCLBuiltinHeader(llvm::RecordKeeper &Records,
+  llvm::raw_ostream &OS);
 
 void EmitClangDataCollectors(llvm::RecordKeeper &Records,
  llvm::raw_ostream &OS);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -63,6 +63,7 @@
   GenClangCommentCommandInfo,
   GenClangCommentCommandList,
   GenClangOpenCLBuiltins,
+  GenClangOpenCLBuiltinHeader,
   GenArmNeon,
   GenArmFP16,
   GenArmBF16,
@@ -195,6 +196,9 @@
"documentation comments"),
 clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
"Generate OpenCL builtin declaration handlers"),
+clEnumValN(GenClangOpenCLBuiltinHeader,
+   "gen-clang-opencl-builtin-header",
+   "Generate OpenCL builtin header from TableGen file"),
 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
 clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"),
 clEnumValN(GenArmBF16, "gen-arm-bf16", "Generate arm_bf16.h for clang"),
@@ -375,6 +379,9 @@
   case GenClangOpenCLBuiltins:
 EmitClangOpenCLBuiltins(Records, OS);
 break;
+  case GenClangOpenCLBuiltinHeader:
+EmitClangOpenCLBuiltinHeader(Records, OS);
+break;
   case GenClangSyntaxNodeList:
 EmitClangSyntaxNodeList(Records, OS);
 break;
Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -228,6 +228,63 @@
   // same entry ().
   MapVector SignatureListMap;
 };
+
+// OpenCL builtin header emitter.  This class processes the same TableGen input
+// as BuiltinNameEmitter, but generates a header-like output of all the
+// declarations which are contained in TableGen file
+class OpenCLBuiltinHeaderEmitter {
+public:
+  OpenCLBuiltinHeaderEmitter(RecordKeeper &Records, raw_ostream &OS)
+  : Records(Records), OS(OS) {}
+
+  // Entrypoint to generate the header
+  void Emit();
+
+private:
+  struct TypeFlags {
+TypeFlags() : IsConst(false), IsVolatile(false), IsPointer(false) {}
+bool IsConst : 1;
+bool IsVolatile : 1;
+bool IsPointer : 1;
+StringRef AddrSpace;
+  };
+
+  // Return a string representation of the given type, such that it can be
+  // used as a type in OpenCL C code.
+  std::string getTypeString(const Record *Type, TypeFlags Flags,
+int VectorSize) const;
+
+  // Return the type(s) and vector size(s) for the given type.  For
+  // non-GenericTypes, the resulting vectors will contain 1 element.  For
+  // GenericTypes, the resulting vectors typically contain multiple elements.
+  void getTypeLists(Record *Type, TypeFlags &Flags,
+std::vector &TypeList,
+std::vector &VectorList) const;
+
+  // Expand the TableGen Records representing a builtin function signature into
+  // one or more function signatures.  Return them as a vector of a vector of
+  // strings, with each string containing an OpenCL C type and optional
+  // qualifiers.
+  //
+  // The Records may contain GenericTypes, which expand into multiple
+  // signatures.  Repeated occurrences of GenericType in a signature expand to
+  // the same types.  For example [char, FGenType, FGenType] expands to:
+  //   [char, float, float]
+  //   [char, float2, float2]
+  //   [char, float3, float3]
+  //   ...
+  void
+  expandTypesInSignature

[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-30 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a subscriber: shafik.
aprantl added a comment.

> If LLDB actually does _not_ have behavior change based on dialect, then we 
> might as well control language codes based on DWARF version, and the patch 
> should proceed.

@shafik Can you think of situations where LLDB is sensitive to the C++ version 
number as encoded in DWARF?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-30 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D99250#2657390 , @aprantl wrote:

>> If LLDB actually does _not_ have behavior change based on dialect, then we 
>> might as well control language codes based on DWARF version, and the patch 
>> should proceed.
>
> @shafik Can you think of situations where LLDB is sensitive to the C++ 
> version number as encoded in DWARF?

No, we are not sensitive to language version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-30 Thread EsmeYi via Phabricator via cfe-commits
Esme updated this revision to Diff 334057.
Esme added a comment.

Addressed Zheng's comments.
Thank you all for your comments. 
Since no DWARF consumers has dialect-specific behavior, the patch will proceed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-programming-language.cpp
  clang/test/Modules/ModuleDebugInfo.cpp


Index: clang/test/Modules/ModuleDebugInfo.cpp
===
--- clang/test/Modules/ModuleDebugInfo.cpp
+++ clang/test/Modules/ModuleDebugInfo.cpp
@@ -23,7 +23,7 @@
 // CHECK-MOD: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
 
 // CHECK: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
-// CHECK-CXX: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_11,
+// CHECK-CXX: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
 // CHECK-SAME:isOptimized: false,
 // CHECK-NOT: splitDebugFilename:
 // CHECK-SAME:dwoId:
Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
+// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+
+int main() {
+  return 0;
+}
+
+// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
+// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -567,9 +567,9 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14)
+else if (LO.CPlusPlus14 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
+else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;


Index: clang/test/Modules/ModuleDebugInfo.cpp
===
--- clang/test/Modules/ModuleDebugInfo.cpp
+++ clang/test/Modules/ModuleDebugInfo.cpp
@@ -23,7 +23,7 @@
 // CHECK-MOD: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
 
 // CHECK: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
-// CHECK-CXX: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_11,
+// CHECK-CXX: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
 // CHECK-SAME:isOptimized: false,
 // CHECK-NOT: splitDebugFilename:
 // CHECK-SAME:dwoId:
Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
+// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+
+int main() {
+  return 0;
+}
+
+// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
+// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -567,9 +567,9 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14)
+else if (LO.CPlusPlus14 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
+else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
___

[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-30 Thread EsmeYi via Phabricator via cfe-commits
Esme added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:572
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
+else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;

shchenz wrote:
> Seems we miss to handle `DW_LANG_C_plus_plus_03` which is also a DWARF 5 
> language name value? We always generate `DW_LANG_C_plus_plus` for 
> `-std=c++03` even at `-gdwarf-5`? If so, maybe we also need to fix this in 
> another patch.
How about we just do that in this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D98502: [clang][Checkers] Extend PthreadLockChecker state dump (NFC).

2021-03-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Everything looks fine.
I like that regexp matcher so much. <3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98502

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


[PATCH] D98377: [clangd] Show padding following a field on field hover.

2021-03-30 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.
Herald added a project: clang-tools-extra.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98377

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


[PATCH] D99425: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

Thanks for  the patch! Sorry for the delay

Can you please elaborate on what issue you are trying to resolve with this fix? 
You're trying to emit diagnostics for `cl_khr_3d_image_writes` for OpenCL C 3.0?

FYI `cl_khr_3d_image_writes` should have no effect in `-cl-ext` option for 
OpenCL C 3.0 as there exist `__opencl_c_3d_image_writes`,  I think it was 
discussed in some previous reviews


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99425

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


[PATCH] D99489: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

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

LGTM aside from the test case commenting nit. Thank you!




Comment at: clang/test/Parser/cxx2a-template-lambdas.cpp:17
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif

Please spell out the full diagnostic wording in this instance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99489

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


[PATCH] D99426: [Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text

2021-03-30 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 334110.
abhina.sreeskantharajan edited the summary of this revision.
abhina.sreeskantharajan added a comment.

Set OF_Text for llvm/tools/dsymutil/DwarfLinkerForBinary.cpp instead of 
OF_TextWithCRLF. This was also another file I recently changed to text from 
binary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99426

Files:
  clang-tools-extra/clang-move/tool/ClangMove.cpp
  clang-tools-extra/modularize/ModuleAssistant.cpp
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/lib/ARCMigrate/PlistReporter.cpp
  clang/lib/Driver/Compilation.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/HeaderIncludeGen.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/tools/clang-refactor/ClangRefactor.cpp
  clang/tools/driver/cc1as_main.cpp
  flang/lib/Frontend/CompilerInstance.cpp
  lld/COFF/DriverUtils.cpp
  lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
  lldb/include/lldb/Utility/ReproducerProvider.h
  lldb/source/Utility/GDBRemote.cpp
  lldb/source/Utility/ReproducerProvider.cpp
  lldb/tools/lldb-server/LLDBServerUtilities.cpp
  llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
  llvm/include/llvm/Support/FileSystem.h
  llvm/lib/CodeGen/RegAllocPBQP.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/LLVMRemarkStreamer.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/MC/MCParser/DarwinAsmParser.cpp
  llvm/lib/ProfileData/GCOV.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/FileCollector.cpp
  llvm/lib/Support/MemoryBuffer.cpp
  llvm/lib/Support/TimeProfiler.cpp
  llvm/lib/Support/Timer.cpp
  llvm/lib/Support/Unix/Program.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/lib/Support/Windows/Program.inc
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/lib/Transforms/Utils/Debugify.cpp
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
  llvm/tools/llvm-dis/llvm-dis.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
  llvm/tools/llvm-link/llvm-link.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-mca/llvm-mca.cpp
  llvm/tools/llvm-opt-report/OptReport.cpp
  llvm/tools/llvm-profdata/llvm-profdata.cpp
  llvm/tools/llvm-xray/xray-account.cpp
  llvm/tools/llvm-xray/xray-converter.cpp
  llvm/tools/llvm-xray/xray-extract.cpp
  llvm/tools/llvm-xray/xray-graph-diff.cpp
  llvm/tools/llvm-xray/xray-graph.cpp
  llvm/tools/opt/opt.cpp
  llvm/tools/verify-uselistorder/verify-uselistorder.cpp
  llvm/unittests/Support/Path.cpp
  polly/lib/Exchange/JSONExporter.cpp

Index: polly/lib/Exchange/JSONExporter.cpp
===
--- polly/lib/Exchange/JSONExporter.cpp
+++ polly/lib/Exchange/JSONExporter.cpp
@@ -178,7 +178,7 @@
 
   // Write to file.
   std::error_code EC;
-  ToolOutputFile F(FileName, EC, llvm::sys::fs::OF_Text);
+  ToolOutputFile F(FileName, EC, llvm::sys::fs::OF_TextWithCRLF);
 
   std::string FunctionName = S.getFunction().getName().str();
   errs() << "Writing JScop '" << S.getNameStr() << "' in function '"
Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1253,7 +1253,7 @@
   path::append(FilePathname, "test");
 
   {
-raw_fd_ostream File(FilePathname, EC, sys::fs::OF_Text);
+raw_fd_ostream File(FilePathname, EC, sys::fs::OF_TextWithCRLF);
 ASSERT_NO_ERROR(EC);
 File << '\n';
   }
Index: llvm/tools/verify-uselistorder/verify-uselistorder.cpp
===
--- llvm/tools/verify-uselistorder/verify-uselistorder.cpp
+++ llvm/tools/verify-uselistorder/verify-uselistorder.cpp
@@ -136,7 +136,7 @@
 bool TempFile::writeAssembly(const Module &M) const {
   LLVM_DEBUG(dbgs() << " - write assembly\n");
   std::error_code EC;
-  raw_fd_ostream OS(Filename, EC, sys::fs::OF_Text);
+  raw_fd_ostream OS(Filename, EC, sys::fs::OF_TextWithCRLF);
   if (EC) {
 errs() << "verify-uselistorder: error: " << EC.message() << "\n";
 return true;
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -700,8 +700,8 @@
   OutputFilename = "-";
 
 std::error_code EC;
-sys::fs::OpenFlags Flags = OutputAssembly ? sys::fs::OF_Text
-  : sys::fs::OF_Non

[clang] a99b8ae - [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

2021-03-30 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2021-03-30T13:53:55+02:00
New Revision: a99b8ae3909106d831d880c1647dabe92f470290

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

LOG: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause 
and no parameter list

This fixes http://llvm.org/PR49736 caused by implementing 
http://wg21.link/P1102 
(https://reviews.llvm.org/rG0620e6f4b76a9725dbd82454d58c5a68a7e47074), by 
correctly allowing requires-clause only:
1) directly after template-parameter-list
2) after lambda-specifiers iff parameter-declaration-clause is present (2nd 
kind of lambda-declarator)

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Parser/cxx-concepts-requires-clause.cpp
clang/test/Parser/cxx2a-template-lambdas.cpp
clang/test/Parser/cxx2b-lambdas.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index c2e74b5a7bbd..644df55bf46e 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -690,7 +690,7 @@ ExprResult Parser::ParseCXXIdExpression(bool 
isAddressOfOperand) {
 ///   lambda-expression:
 /// lambda-introducer lambda-declarator compound-statement
 /// lambda-introducer '<' template-parameter-list '>'
-/// lambda-declarator compound-statement
+/// requires-clause[opt] lambda-declarator compound-statement
 ///
 ///   lambda-introducer:
 /// '[' lambda-capture[opt] ']'
@@ -1392,12 +1392,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, D,
 TrailingReturnType, TrailingReturnTypeLoc, &DS),
 std::move(Attr), DeclEndLoc);
-
-// Parse requires-clause[opt].
-if (Tok.is(tok::kw_requires))
-  ParseTrailingRequiresClause(D);
-
-WarnIfHasCUDATargetAttr();
   };
 
   if (Tok.is(tok::l_paren)) {
@@ -1433,6 +1427,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 // Parse lambda-specifiers.
 ParseLambdaSpecifiers(LParenLoc, /*DeclEndLoc=*/T.getCloseLocation(),
   ParamInfo, EllipsisLoc);
+
+// Parse requires-clause[opt].
+if (Tok.is(tok::kw_requires))
+  ParseTrailingRequiresClause(D);
   } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
  tok::kw_constexpr, tok::kw_consteval,
  tok::kw___private, tok::kw___global, tok::kw___local,
@@ -1453,6 +1451,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   EmptyParamInfo, /*EllipsisLoc=*/NoLoc);
   }
 
+  WarnIfHasCUDATargetAttr();
+
   // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
   // it.
   unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope |

diff  --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 4d6d166d6fef..68f1af8b12cc 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -154,7 +154,9 @@ auto lambda1 = [] (auto x) requires (sizeof(decltype(x)) == 
1) { };
 
 auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 
1) { return 0; };
 
-auto lambda3 = [] requires (sizeof(char) == 1) { };
+auto lambda3 = [] requires(sizeof(char) == 1){};
+
+auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected 
body of lambda expression}}
 #if __cplusplus <= 202002L
-// expected-warning@-2{{is a C++2b extension}}
+// expected-warning@-2{{lambda without a parameter clause is a C++2b 
extension}}
 #endif

diff  --git a/clang/test/Parser/cxx2a-template-lambdas.cpp 
b/clang/test/Parser/cxx2a-template-lambdas.cpp
index 2a2305b5530c..f85280f7ece5 100644
--- a/clang/test/Parser/cxx2a-template-lambdas.cpp
+++ b/clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -7,3 +7,28 @@ auto L1 = [] { };
 auto L2 = [](T1 arg1, T2 arg2) -> T1 { };
 auto L3 = [](auto arg) { T t; };
 auto L4 = []() { };
+
+// http://llvm.org/PR49736
+auto L5 = [](){};
+auto L6 = []{};
+auto L7 = []() noexcept {};
+auto L8 = [] noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{lambda without a parameter clause is a C++2b 
extension}}
+#endif
+auto L9 = [] requires true {};
+auto L10 = [] requires true(){};
+auto L11 = [] requires true() noexcept {};
+auto L12 = [] requires true noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L13 = []() noexcept requires true {};
+auto L14 = [] requires true() noexcept requires true {};
+
+au

[PATCH] D99489: [clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list

2021-03-30 Thread Marek Kurdej 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 rGa99b8ae39091: [clang] [PR49736] [C++2b] Correctly reject 
lambdas with requires clause and no… (authored by curdeius).

Changed prior to commit:
  https://reviews.llvm.org/D99489?vs=334075&id=334111#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99489

Files:
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx-concepts-requires-clause.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/Parser/cxx2b-lambdas.cpp

Index: clang/test/Parser/cxx2b-lambdas.cpp
===
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -18,13 +18,14 @@
 auto L10 = [] noexcept { return true; };
 auto L11 = [] -> bool { return true; };
 auto L12 = [] consteval {};
-auto L13 = [] requires requires() { true; }
-{};
-auto L15 = [] [[maybe_unused]]{};
+auto L13 = []() requires true {};
+auto L14 = [] requires true() requires true {};
+auto L15 = [] requires true noexcept {};
+auto L16 = [] [[maybe_unused]]{};
 
 auto XL0 = [] mutable constexpr mutable {};// expected-error{{cannot appear multiple times}}
 auto XL1 = [] constexpr mutable constexpr {};  // expected-error{{cannot appear multiple times}}
-auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body}}
+auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body of lambda expression}}
 auto XL3 = []( constexpr mutable constexpr {}; // expected-error{{invalid storage class specifier}} \
// expected-error{{function parameter cannot be constexpr}} \
// expected-error{{C++ requires}} \
@@ -32,3 +33,8 @@
// expected-note{{to match this '('}} \
// expected-error{{expected body}} \
// expected-warning{{duplicate 'constexpr'}}
+
+// http://llvm.org/PR49736
+auto XL4 = [] requires true {}; // expected-error{{expected body}}
+auto XL5 = [] requires true requires true {}; // expected-error{{expected body}}
+auto XL6 = [] requires true noexcept requires true {}; // expected-error{{expected body}}
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -7,3 +7,28 @@
 auto L2 = [](T1 arg1, T2 arg2) -> T1 { };
 auto L3 = [](auto arg) { T t; };
 auto L4 = []() { };
+
+// http://llvm.org/PR49736
+auto L5 = [](){};
+auto L6 = []{};
+auto L7 = []() noexcept {};
+auto L8 = [] noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{lambda without a parameter clause is a C++2b extension}}
+#endif
+auto L9 = [] requires true {};
+auto L10 = [] requires true(){};
+auto L11 = [] requires true() noexcept {};
+auto L12 = [] requires true noexcept {};
+#if __cplusplus <= 202002L
+// expected-warning@-2 {{is a C++2b extension}}
+#endif
+auto L13 = []() noexcept requires true {};
+auto L14 = [] requires true() noexcept requires true {};
+
+auto XL0 = [] noexcept requires true {};   // expected-error {{expected body of lambda expression}}
+auto XL1 = [] requires true noexcept requires true {}; // expected-error {{expected body}}
+#if __cplusplus <= 202002L
+// expected-warning@-3 {{is a C++2b extension}}
+// expected-warning@-3 {{is a C++2b extension}}
+#endif
Index: clang/test/Parser/cxx-concepts-requires-clause.cpp
===
--- clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -154,7 +154,9 @@
 
 auto lambda2 = [] (auto x) constexpr -> int requires (sizeof(decltype(x)) == 1) { return 0; };
 
-auto lambda3 = [] requires (sizeof(char) == 1) { };
+auto lambda3 = [] requires(sizeof(char) == 1){};
+
+auto lambda4 = [] requires(sizeof(char) == 1){}; // expected-error {{expected body of lambda expression}}
 #if __cplusplus <= 202002L
-// expected-warning@-2{{is a C++2b extension}}
+// expected-warning@-2{{lambda without a parameter clause is a C++2b extension}}
 #endif
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -690,7 +690,7 @@
 ///   lambda-expression:
 /// lambda-introducer lambda-declarator compound-statement
 /// lambda-introducer '<' template-parameter-list '>'
-/// lambda-declarator compound-statement
+/// requires-clause[opt] lambda-declarator compound-statement
 ///
 ///   lambda-introducer:
 ///  

[PATCH] D99363: [Windows] Turn off text mode in TableGen and Rewriter to stop CRLF translation

2021-03-30 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

In D99363#2656913 , @aganea wrote:

> In D99363#2653476 , 
> @abhina.sreeskantharajan wrote:
>
>> There were a lot of similar patches so reverting all of them might be more 
>> work than isolating the change that caused it and reverting that. It seems 
>> that the patch you initially commented on did not contain the problematic 
>> change since reverting the change doesn't fix your issue. I created the 
>> following patch https://reviews.llvm.org/D99426 based on @rnk suggestion. I 
>> created a new flag for OF_TextWithCRLF on Windows and made sure my most 
>> recent text changes use the OF_Text flag while all other uses were changed 
>> to OF_TextWithCRLF. This should solve any CRLF issues that were introduced 
>> recently by my patches. If you have time, would you be able to test if that 
>> patch fixes your issue?
>
> I've applied https://reviews.llvm.org/D99426#2656738 over 
> rGc4d5b956170dd85941c1c2787abaa2e01575234c 
>  but I'm 
> still seeing the issue in https://reviews.llvm.org/D96363#2650460.

Ok, I missed the change in llvm/tools/dsymutil/DwarfLinkerForBinary.cpp.

In D99363#2656913 , @aganea wrote:

> In D99363#2653476 , 
> @abhina.sreeskantharajan wrote:
>
>> There were a lot of similar patches so reverting all of them might be more 
>> work than isolating the change that caused it and reverting that. It seems 
>> that the patch you initially commented on did not contain the problematic 
>> change since reverting the change doesn't fix your issue. I created the 
>> following patch https://reviews.llvm.org/D99426 based on @rnk suggestion. I 
>> created a new flag for OF_TextWithCRLF on Windows and made sure my most 
>> recent text changes use the OF_Text flag while all other uses were changed 
>> to OF_TextWithCRLF. This should solve any CRLF issues that were introduced 
>> recently by my patches. If you have time, would you be able to test if that 
>> patch fixes your issue?
>
> I've applied https://reviews.llvm.org/D99426#2656738 over 
> rGc4d5b956170dd85941c1c2787abaa2e01575234c 
>  but I'm 
> still seeing the issue in https://reviews.llvm.org/D96363#2650460.

Sorry, I realized the change for DwarfLinkerForBinary.cpp was missing. This was 
only other file from https://reviews.llvm.org/D96363 that was using 
OF_TextWithCRLF instead of OF_Text. Please let me know if this latest patch 
https://reviews.llvm.org/file/data/2jljo4tfl5aiisvwpzg2/PHID-FILE-egbpcbhz3t7b7a2tcjka/D99426.diff
 fixes your issue. If not, I will revert the remaining changes in my old commit 
to unblock you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99363

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


[PATCH] D99580: [CLANG] [DebugInfo] Convert File name to native format

2021-03-30 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui created this revision.
kamleshbhalui added reviewers: dblaikie, aprantl.
kamleshbhalui added a project: LLVM.
Herald added a subscriber: mstorsjo.
kamleshbhalui requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang emits duplicate file entry in object file on windows platform(when 
windows style path appended with posix style path or vice versa).
which becomes problem for some debugger(not able to put break point on the file 
which has duplicate entry).

By making sure it's native path before creating DIFile above problem goes away.

Testcase Demonstration of problem on llvm-dev:
https://lists.llvm.org/pipermail/llvm-dev/2021-March/149501.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99580

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-mingw.c


Index: clang/test/CodeGen/debug-info-mingw.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-mingw.c
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t/UNIQUE_DIR && mkdir -p %t/UNIQUE_DIR
+// RUN: cp %s %t/UNIQUE_DIR/debug-info-mingw.c
+// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -debug-info-kind=limited 
-main-file-name debug-info-mingw.c %t/UNIQUE_DIR/debug-info-mingw.c -emit-llvm 
-o - | FileCheck %s
+int main() {
+}
+// CHECK: !DIFile(filename: "{{.+}}\\UNIQUE_DIR\\debug-info-mingw.c",
+// UNSUPPORTED: !system-windows
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -443,6 +443,10 @@
 Optional Source) {
   StringRef Dir;
   StringRef File;
+  // Convert FileName to native path
+  SmallString<128> NativePath = FileName;
+  llvm::sys::path::native(NativePath);
+  FileName = NativePath.str();
   std::string RemappedFile = remapDIPath(FileName);
   std::string CurDir = remapDIPath(getCurrentDirname());
   SmallString<128> DirBuf;
@@ -558,7 +562,10 @@
 MainFile->getName().rsplit('.').second)
 .isPreprocessed())
   MainFileName = CGM.getModule().getName().str();
-
+// Convert MainFileName to native path
+SmallString<128> NativePath = (StringRef)MainFileName;
+llvm::sys::path::native(NativePath);
+MainFileName = (std::string)NativePath.str();
 CSKind = computeChecksum(SM.getMainFileID(), Checksum);
   }
 


Index: clang/test/CodeGen/debug-info-mingw.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-mingw.c
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t/UNIQUE_DIR && mkdir -p %t/UNIQUE_DIR
+// RUN: cp %s %t/UNIQUE_DIR/debug-info-mingw.c
+// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -debug-info-kind=limited -main-file-name debug-info-mingw.c %t/UNIQUE_DIR/debug-info-mingw.c -emit-llvm -o - | FileCheck %s
+int main() {
+}
+// CHECK: !DIFile(filename: "{{.+}}\\UNIQUE_DIR\\debug-info-mingw.c",
+// UNSUPPORTED: !system-windows
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -443,6 +443,10 @@
 Optional Source) {
   StringRef Dir;
   StringRef File;
+  // Convert FileName to native path
+  SmallString<128> NativePath = FileName;
+  llvm::sys::path::native(NativePath);
+  FileName = NativePath.str();
   std::string RemappedFile = remapDIPath(FileName);
   std::string CurDir = remapDIPath(getCurrentDirname());
   SmallString<128> DirBuf;
@@ -558,7 +562,10 @@
 MainFile->getName().rsplit('.').second)
 .isPreprocessed())
   MainFileName = CGM.getModule().getName().str();
-
+// Convert MainFileName to native path
+SmallString<128> NativePath = (StringRef)MainFileName;
+llvm::sys::path::native(NativePath);
+MainFileName = (std::string)NativePath.str();
 CSKind = computeChecksum(SM.getMainFileID(), Checksum);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2b30bd2 - clang-format: [JS] do not collapse - - to --.

2021-03-30 Thread Martin Probst via cfe-commits

Author: Martin Probst
Date: 2021-03-30T14:31:24+02:00
New Revision: 2b30bd2be0a898d0e7cb9eb3f2cf0e0efeaa83e9

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

LOG: clang-format: [JS] do not collapse - - to --.

In JavaScript, `- -1;` is legal syntax, the language allows unary minus.
However the two tokens must not collapse together: `--1` is prefix
decrement, i.e. different syntax.

Before:

- -1; ==> --1;

After:

- -1; ==> - -1;

This change makes no attempt to format this "nicely", given by all
likelihood this represents a programming mistake by the user, or odd
generated code.

The check is not guarded by language: this appears to be a problem in
Java as well, and will also be beneficial when formatting syntactically
incorrect C++ (e.g. during editing).

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 34c291ecc492..5177dca751d9 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3370,6 +3370,12 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
  Style.BitFieldColonSpacing == FormatStyle::BFCS_Before;
 return true;
   }
+  // Do not merge "- -" into "--".
+  if ((Left.isOneOf(tok::minus, tok::minusminus) &&
+   Right.isOneOf(tok::minus, tok::minusminus)) ||
+  (Left.isOneOf(tok::plus, tok::plusplus) &&
+   Right.isOneOf(tok::plus, tok::plusplus)))
+return true;
   if (Left.is(TT_UnaryOperator)) {
 if (!Right.is(tok::l_paren)) {
   // The alternative operators for ~ and ! are "compl" and "not".

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 8963c9f19024..91a98bf64c5c 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -276,6 +276,12 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
   // ES6 spread operator.
   verifyFormat("someFunction(...a);");
   verifyFormat("var x = [1, ...a, 2];");
+
+  // "- -1" is legal JS syntax, but must not collapse into "--".
+  verifyFormat("- -1;", " - -1;");
+  verifyFormat("-- -1;", " -- -1;");
+  verifyFormat("+ +1;", " + +1;");
+  verifyFormat("++ +1;", " ++ +1;");
 }
 
 TEST_F(FormatTestJS, UnderstandsAmpAmp) {



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


[PATCH] D99495: clang-format: [JS] do not collapse - - to --.

2021-03-30 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b30bd2be0a8: clang-format: [JS] do not collapse - - to --. 
(authored by mprobst).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99495

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


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -276,6 +276,12 @@
   // ES6 spread operator.
   verifyFormat("someFunction(...a);");
   verifyFormat("var x = [1, ...a, 2];");
+
+  // "- -1" is legal JS syntax, but must not collapse into "--".
+  verifyFormat("- -1;", " - -1;");
+  verifyFormat("-- -1;", " -- -1;");
+  verifyFormat("+ +1;", " + +1;");
+  verifyFormat("++ +1;", " ++ +1;");
 }
 
 TEST_F(FormatTestJS, UnderstandsAmpAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3370,6 +3370,12 @@
  Style.BitFieldColonSpacing == FormatStyle::BFCS_Before;
 return true;
   }
+  // Do not merge "- -" into "--".
+  if ((Left.isOneOf(tok::minus, tok::minusminus) &&
+   Right.isOneOf(tok::minus, tok::minusminus)) ||
+  (Left.isOneOf(tok::plus, tok::plusplus) &&
+   Right.isOneOf(tok::plus, tok::plusplus)))
+return true;
   if (Left.is(TT_UnaryOperator)) {
 if (!Right.is(tok::l_paren)) {
   // The alternative operators for ~ and ! are "compl" and "not".


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -276,6 +276,12 @@
   // ES6 spread operator.
   verifyFormat("someFunction(...a);");
   verifyFormat("var x = [1, ...a, 2];");
+
+  // "- -1" is legal JS syntax, but must not collapse into "--".
+  verifyFormat("- -1;", " - -1;");
+  verifyFormat("-- -1;", " -- -1;");
+  verifyFormat("+ +1;", " + +1;");
+  verifyFormat("++ +1;", " ++ +1;");
 }
 
 TEST_F(FormatTestJS, UnderstandsAmpAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3370,6 +3370,12 @@
  Style.BitFieldColonSpacing == FormatStyle::BFCS_Before;
 return true;
   }
+  // Do not merge "- -" into "--".
+  if ((Left.isOneOf(tok::minus, tok::minusminus) &&
+   Right.isOneOf(tok::minus, tok::minusminus)) ||
+  (Left.isOneOf(tok::plus, tok::plusplus) &&
+   Right.isOneOf(tok::plus, tok::plusplus)))
+return true;
   if (Left.is(TT_UnaryOperator)) {
 if (!Right.is(tok::l_paren)) {
   // The alternative operators for ~ and ! are "compl" and "not".
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1696b8a - [OPENMP]Fix PR48740: OpenMP declare reduction in C does not require an initializer

2021-03-30 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-03-30T05:38:20-07:00
New Revision: 1696b8ae96b2d8bcbf90894bd344a8a090f43c84

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

LOG: [OPENMP]Fix PR48740: OpenMP declare reduction in C does not require an 
initializer

If no initializer-clause is specified, the private variables will be
initialized following the rules for initialization of objects with static
storage duration.

Need to adjust the implementation to the current version of the
standard.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_reduction_ast_print.c
clang/test/OpenMP/declare_reduction_codegen.c
clang/test/OpenMP/declare_reduction_messages.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 95859e6e94a7..4ec216a42188 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -655,9 +655,13 @@ static void 
emitInitWithReductionInitializer(CodeGenFunction &CGF,
   InitRVal =
   RValue::getComplex(CGF.EmitLoadOfComplex(LV, DRD->getLocation()));
   break;
-case TEK_Aggregate:
-  InitRVal = RValue::getAggregate(LV.getAddress(CGF));
-  break;
+case TEK_Aggregate: {
+  OpaqueValueExpr OVE(DRD->getLocation(), Ty, VK_LValue);
+  CodeGenFunction::OpaqueValueMapping OpaqueMap(CGF, &OVE, LV);
+  CGF.EmitAnyExprToMem(&OVE, Private, Ty.getQualifiers(),
+   /*IsInitializer=*/false);
+  return;
+}
 }
 OpaqueValueExpr OVE(DRD->getLocation(), Ty, VK_RValue);
 CodeGenFunction::OpaqueValueMapping OpaqueMap(CGF, &OVE, InitRVal);

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 54c824c4a759..fcb95e3a8442 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -16567,8 +16567,7 @@ static bool actOnOMPReductionKindClause(
 }
 if (RHSVD->isInvalidDecl())
   continue;
-if (!RHSVD->hasInit() &&
-(DeclareReductionRef.isUnset() || !S.LangOpts.CPlusPlus)) {
+if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) {
   S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible)
   << Type << ReductionIdRange;
   bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==

diff  --git a/clang/test/OpenMP/declare_reduction_ast_print.c 
b/clang/test/OpenMP/declare_reduction_ast_print.c
index 37b722e5f8ca..a421886dd3fe 100644
--- a/clang/test/OpenMP/declare_reduction_ast_print.c
+++ b/clang/test/OpenMP/declare_reduction_ast_print.c
@@ -47,13 +47,18 @@ int main() {
   : omp_out = omp_out > omp_in ? omp_in : omp_out) 
\
 initializer(omp_priv = 2147483647)
 
+#pragma omp declare reduction(mymin\
+  : struct SSS \
+  : omp_out = omp_out.field > omp_in.field ? 
omp_in : omp_out)
+
 int foo(int argc, char **argv) {
   int x;
-#pragma omp parallel for reduction(mymin : x)
+  struct SSS ss;
+#pragma omp parallel for reduction(mymin : x, ss)
   for (int i = 0; i < 1000; i++)
 ;
   return 0;
 }
 
-// CHECK: #pragma omp parallel for reduction(mymin: x)
+// CHECK: #pragma omp parallel for reduction(mymin: x,ss)
 #endif

diff  --git a/clang/test/OpenMP/declare_reduction_codegen.c 
b/clang/test/OpenMP/declare_reduction_codegen.c
index f5695ffaac34..c5b5d1dfa5a4 100644
--- a/clang/test/OpenMP/declare_reduction_codegen.c
+++ b/clang/test/OpenMP/declare_reduction_codegen.c
@@ -17,6 +17,9 @@
 // CHECK: [[SSS_INT:.+]] = type { i32 }
 // CHECK-LOAD: [[SSS_INT:.+]] = type { i32 }
 
+// CHECK-DAG: [[SSS_INIT:@.+]] = private constant %struct.SSS zeroinitializer
+// CHECK-DAG: [[INT_INIT:@.+]] = private constant i32 0
+
 #pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias %0, i32* noalias 
%1)
 // CHECK: [[MUL:%.+]] = mul nsw i32
@@ -163,4 +166,27 @@ int main() {
 // OMP45-LOAD-NEXT: store i8 [[TRUNC]], i8*
 // OMP45-LOAD-NEXT: ret void
 // OMP45-LOAD-NEXT: }
+
+// CHECK-LABEL: bar
+struct SSS ss;
+int in;
+void bar() {
+  // CHECK: [[SS_PRIV:%.+]] = alloca %struct.SSS,
+  // CHECK: [[IN_PRIV:%.+]] = alloca i32,
+  // CHECK: [[BC:%.+]] = bitcast %struct.SSS* [[SS_PRIV]] to i8*
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[BC]], i8* align 
4 bitcast (%struct.SSS* [[SSS_INIT]] to i8*), i64 4, i1 false)
+  // CHECK: [[IN_VAL:%.+]] = load i32, i32* [[INT_INIT]],
+  // CHECK: store i32 [[IN_VAL]], i32* [[IN_PRIV]],
+  // CHECK: call void @__kmpc_for_static_init_4(
+#pragma omp declare reduction(+\
+  

[PATCH] D99539: [OPENMP]Fix PR48740: OpenMP declare reduction in C does not require an initializer

2021-03-30 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1696b8ae96b2: [OPENMP]Fix PR48740: OpenMP declare reduction 
in C does not require an… (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99539

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_reduction_ast_print.c
  clang/test/OpenMP/declare_reduction_codegen.c
  clang/test/OpenMP/declare_reduction_messages.c

Index: clang/test/OpenMP/declare_reduction_messages.c
===
--- clang/test/OpenMP/declare_reduction_messages.c
+++ clang/test/OpenMP/declare_reduction_messages.c
@@ -49,9 +49,9 @@
 #pragma omp declare reduction(|: struct S: omp_out.s += omp_in.s) initializer(omp_priv = { 0 })
 
 int fun(int arg) {
-  struct S s;// expected-note {{'s' defined here}}
+  struct S s;
   s.s = 0;
-#pragma omp parallel for reduction(+ : s) // expected-error {{list item of type 'struct S' is not valid for specified reduction operation: unable to provide default initialization value}}
+#pragma omp parallel for reduction(+ : s)
   for (arg = 0; arg < 10; ++arg)
 s.s += arg;
 #pragma omp declare reduction(red : int : omp_out++)
Index: clang/test/OpenMP/declare_reduction_codegen.c
===
--- clang/test/OpenMP/declare_reduction_codegen.c
+++ clang/test/OpenMP/declare_reduction_codegen.c
@@ -17,6 +17,9 @@
 // CHECK: [[SSS_INT:.+]] = type { i32 }
 // CHECK-LOAD: [[SSS_INT:.+]] = type { i32 }
 
+// CHECK-DAG: [[SSS_INIT:@.+]] = private constant %struct.SSS zeroinitializer
+// CHECK-DAG: [[INT_INIT:@.+]] = private constant i32 0
+
 #pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias %0, i32* noalias %1)
 // CHECK: [[MUL:%.+]] = mul nsw i32
@@ -163,4 +166,27 @@
 // OMP45-LOAD-NEXT: store i8 [[TRUNC]], i8*
 // OMP45-LOAD-NEXT: ret void
 // OMP45-LOAD-NEXT: }
+
+// CHECK-LABEL: bar
+struct SSS ss;
+int in;
+void bar() {
+  // CHECK: [[SS_PRIV:%.+]] = alloca %struct.SSS,
+  // CHECK: [[IN_PRIV:%.+]] = alloca i32,
+  // CHECK: [[BC:%.+]] = bitcast %struct.SSS* [[SS_PRIV]] to i8*
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[BC]], i8* align 4 bitcast (%struct.SSS* [[SSS_INIT]] to i8*), i64 4, i1 false)
+  // CHECK: [[IN_VAL:%.+]] = load i32, i32* [[INT_INIT]],
+  // CHECK: store i32 [[IN_VAL]], i32* [[IN_PRIV]],
+  // CHECK: call void @__kmpc_for_static_init_4(
+#pragma omp declare reduction(+\
+  : struct SSS \
+  : omp_out = omp_in)
+#pragma omp declare reduction(+ \
+  : int \
+  : omp_out = omp_in)
+#pragma omp for reduction(+ \
+  : ss, in)
+  for (int i = 0; i < 10; ++i)
+;
+}
 #endif
Index: clang/test/OpenMP/declare_reduction_ast_print.c
===
--- clang/test/OpenMP/declare_reduction_ast_print.c
+++ clang/test/OpenMP/declare_reduction_ast_print.c
@@ -47,13 +47,18 @@
   : omp_out = omp_out > omp_in ? omp_in : omp_out) \
 initializer(omp_priv = 2147483647)
 
+#pragma omp declare reduction(mymin\
+  : struct SSS \
+  : omp_out = omp_out.field > omp_in.field ? omp_in : omp_out)
+
 int foo(int argc, char **argv) {
   int x;
-#pragma omp parallel for reduction(mymin : x)
+  struct SSS ss;
+#pragma omp parallel for reduction(mymin : x, ss)
   for (int i = 0; i < 1000; i++)
 ;
   return 0;
 }
 
-// CHECK: #pragma omp parallel for reduction(mymin: x)
+// CHECK: #pragma omp parallel for reduction(mymin: x,ss)
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -16567,8 +16567,7 @@
 }
 if (RHSVD->isInvalidDecl())
   continue;
-if (!RHSVD->hasInit() &&
-(DeclareReductionRef.isUnset() || !S.LangOpts.CPlusPlus)) {
+if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) {
   S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible)
   << Type << ReductionIdRange;
   bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -655,9 +655,13 @@
   InitRVal =
   RValue::getComplex(CGF.EmitLoadOfComplex(LV, DRD->getLocation()));
   break;
-case TEK_Aggregate:
-  InitRVal = RValue::getAggregate(LV.getAddress(CGF));
-  break;
+case TEK_Aggregate: {
+  OpaqueValueEx

[PATCH] D99500: [analyzer] Support allocClassWithName in OSObjectCStyleCast checker

2021-03-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D99500#2657675 , @NoQ wrote:

> LGTM! Thanks for formatting ^.^
>
> WDYT about a heuristic that literally matches the source code of the casted 
> expression as plain text to see if it mentions the type? Like, regardless of 
> `allocClassWithName()`, if it mentions the type it probably has something to 
> do with that type.

This idea sounds good in general, but it feels like it can backfire in some 
cases.  As any regex-like solution, it will have ridiculous corner cases when 
the name of the type is too generic and can appear as a sub-word.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99500

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


[PATCH] D99425: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Kévin Petit via Phabricator via cfe-commits
kpet added a comment.

@azabaznov Without this change, `opencl-c.h` cannot be parsed with 
`-cl-std=CL3.0` as the `write_only image3d_t` type is not enabled. The type is 
currently enabled via `cl_khr_3d_image_writes`. See 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/OpenCLImageTypes.def#L68.
 It may be that we want to redesign this such that the type be enabled by the 
feature macro (or via another mechanism) and have the extension enable the 
feature macro internally but this would require more thinking and is probably 
best done as a follow-up IMHO (maybe as part of https://reviews.llvm.org/D92004 
or a pre-requisite thereof?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99425

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


[clang] efa7df1 - [Analyzer] Track RValue expressions

2021-03-30 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-03-30T14:48:38+02:00
New Revision: efa7df1682c2859dabe3646ee7dc01e68629417f

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

LOG: [Analyzer] Track RValue expressions

It makes sense to track rvalue expressions in the case of special
concrete integer values. The most notable special value is zero (later
we may find other values). By tracking the origin of 0, we can provide a
better explanation for users e.g. in case of division by 0 warnings.
When the divisor is a product of a multiplication then now we can show
which operand (or both) was (were) zero and why.

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

Added: 
clang/test/Analysis/division-by-zero-track-zero.c
clang/test/Analysis/division-by-zero-track-zero.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/test/Analysis/nullptr.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 0edd6e3f731b6..fd334b0bc9c36 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1924,6 +1924,44 @@ static const ExplodedNode* findNodeForExpression(const 
ExplodedNode *N,
   return N;
 }
 
+/// Attempts to add visitors to track an RValue expression back to its point of
+/// origin. Works similarly to trackExpressionValue, but accepts only RValues.
+static void trackRValueExpression(const ExplodedNode *InputNode, const Expr *E,
+  PathSensitiveBugReport &report,
+  bugreporter::TrackingKind TKind,
+  bool EnableNullFPSuppression) {
+  assert(E->isRValue() && "The expression is not an rvalue!");
+  const ExplodedNode *RVNode = findNodeForExpression(InputNode, E);
+  if (!RVNode)
+return;
+  ProgramStateRef RVState = RVNode->getState();
+  SVal V = RVState->getSValAsScalarOrLoc(E, RVNode->getLocationContext());
+  const auto *BO = dyn_cast(E);
+  if (!BO)
+return;
+  if (!V.isZeroConstant())
+return;
+  if (!BO->isMultiplicativeOp())
+return;
+
+  SVal RHSV = RVState->getSVal(BO->getRHS(), RVNode->getLocationContext());
+  SVal LHSV = RVState->getSVal(BO->getLHS(), RVNode->getLocationContext());
+
+  // Track both LHS and RHS of a multiplication.
+  if (BO->getOpcode() == BO_Mul) {
+if (LHSV.isZeroConstant())
+  trackExpressionValue(InputNode, BO->getLHS(), report, TKind,
+   EnableNullFPSuppression);
+if (RHSV.isZeroConstant())
+  trackExpressionValue(InputNode, BO->getRHS(), report, TKind,
+   EnableNullFPSuppression);
+  } else { // Track only the LHS of a division or a modulo.
+if (LHSV.isZeroConstant())
+  trackExpressionValue(InputNode, BO->getLHS(), report, TKind,
+   EnableNullFPSuppression);
+  }
+}
+
 bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
const Expr *E,
PathSensitiveBugReport &report,
@@ -2069,6 +2107,11 @@ bool bugreporter::trackExpressionValue(const 
ExplodedNode *InputNode,
 loc::MemRegionVal(RegionRVal), /*assumption=*/false));
 }
   }
+
+  if (Inner->isRValue())
+trackRValueExpression(LVNode, Inner, report, TKind,
+  EnableNullFPSuppression);
+
   return true;
 }
 

diff  --git a/clang/test/Analysis/division-by-zero-track-zero.c 
b/clang/test/Analysis/division-by-zero-track-zero.c
new file mode 100644
index 0..f6b2a78ed7017
--- /dev/null
+++ b/clang/test/Analysis/division-by-zero-track-zero.c
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+int track_mul_lhs_0(int x, int y) {
+  int p0 = x < 0;   // expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+  int div = p0 * y; // expected-note {{'div' initialized to 0}}
+  return 1 / div;   // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+}

diff  --git a/clang/test/Analysis/division-by-zero-track-zero.cpp 
b/clang/test/Analysis/division-by-zero-track-zero.cpp
new file mode 100644
index 0..c4b9550c76c0f
--- /dev/null
+++ b/clang/test/Analysis/division-by-zero-track-zero.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+namespace test_tracking_of_lhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0

[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rGefa7df1682c2: [Analyzer] Track RValue expressions (authored 
by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/division-by-zero-track-zero.c
  clang/test/Analysis/division-by-zero-track-zero.cpp
  clang/test/Analysis/nullptr.cpp

Index: clang/test/Analysis/nullptr.cpp
===
--- clang/test/Analysis/nullptr.cpp
+++ clang/test/Analysis/nullptr.cpp
@@ -64,7 +64,7 @@
 
 typedef __INTPTR_TYPE__ intptr_t;
 void zoo1multiply() {
-  char **p = 0; // FIXME-should-be-note:{{'p' initialized to a null pointer value}}
+  char **p = 0; // expected-note{{'p' initialized to a null pointer value}}
   delete *((char **)((intptr_t)p * 2)); // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
 }
Index: clang/test/Analysis/division-by-zero-track-zero.cpp
===
--- /dev/null
+++ clang/test/Analysis/division-by-zero-track-zero.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+namespace test_tracking_of_lhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = p0 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_lhs_multiplier
+
+namespace test_tracking_of_rhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y * p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_rhs_multiplier
+
+namespace test_tracking_of_nested_multiplier {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y*z*p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_nested_multiplier
+
+namespace test_tracking_through_multiple_stmts {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}}
+bool p1 = p0 ? 0 : 1; // expected-note {{'p0' is false}} \
+  // expected-note {{'?' condition is false}}
+bool p2 = 1 - p1; // expected-note {{'p2' initialized to 0}}
+int div = p2 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_through_multiple_stmts
+
+namespace test_tracking_both_lhs_and_rhs {
+  int f(int x, int y) {
+bool p0 = x < 0;   // expected-note {{Assuming 'x' is >= 0}} \
+   // expected-note {{'p0' initialized to 0}}
+bool p1 = y < 0;   // expected-note {{Assuming 'y' is >= 0}} \
+   // expected-note {{'p1' initialized to 0}}
+int div = p0 * p1; // expected-note {{'div' initialized to 0}}
+return 1 / div;// expected-note {{Division by zero}} \
+   // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_both_lhs_and_rhs
+
+namespace test_tracking_of_multiplier_and_parens {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = y*(z*p0); // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_multiplier_and_parens
+
+namespace test_tracking_of_divisible {
+  int f(int x, int y) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = p0 / y;   // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_divisible
+
+namespace test_tracking_of

[clang] 9037730 - [analyzer] Support allocClassWithName in OSObjectCStyleCast checker

2021-03-30 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-03-30T15:58:06+03:00
New Revision: 90377308de6cac8239bc1a1dcd32b57b9ec91444

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

LOG: [analyzer] Support allocClassWithName in OSObjectCStyleCast checker

`allocClassWithName` allocates an object with the given type.
The type is actually provided as a string argument (type's name).
This creates a possibility for not particularly useful warnings
from the analyzer.

In order to combat with those, this patch checks for casts of the
`allocClassWithName` results to types mentioned directly as its
argument.  All other uses of this method should be reasoned about
as before.

rdar://72165694

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
clang/test/Analysis/os_object_base.h
clang/test/Analysis/osobjectcstylecastchecker_test.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp 
b/clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
index 270b66dab020..0a8379d9ab99 100644
--- a/clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
@@ -32,7 +32,21 @@ class OSObjectCStyleCastChecker : public 
Checker {
   void checkASTCodeBody(const Decl *D, AnalysisManager &AM,
 BugReporter &BR) const;
 };
+} // namespace
+
+namespace clang {
+namespace ast_matchers {
+AST_MATCHER_P(StringLiteral, mentionsBoundType, std::string, BindingID) {
+  return Builder->removeBindings([this, &Node](const BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  return ND->getName() != Node.getString();
+}
+return true;
+  });
 }
+} // end namespace ast_matchers
+} // end namespace clang
 
 static void emitDiagnostics(const BoundNodes &Nodes,
 BugReporter &BR,
@@ -63,22 +77,41 @@ static decltype(auto) hasTypePointingTo(DeclarationMatcher 
DeclM) {
   return hasType(pointerType(pointee(hasDeclaration(DeclM;
 }
 
-void OSObjectCStyleCastChecker::checkASTCodeBody(const Decl *D, 
AnalysisManager &AM,
+void OSObjectCStyleCastChecker::checkASTCodeBody(const Decl *D,
+ AnalysisManager &AM,
  BugReporter &BR) const {
 
   AnalysisDeclContext *ADC = AM.getAnalysisDeclContext(D);
 
   auto DynamicCastM = callExpr(callee(functionDecl(hasName("safeMetaCast";
-
-  auto OSObjTypeM = 
hasTypePointingTo(cxxRecordDecl(isDerivedFrom("OSMetaClassBase")));
+  // 'allocClassWithName' allocates an object with the given type.
+  // The type is actually provided as a string argument (type's name).
+  // This makes the following pattern possible:
+  //
+  // Foo *object = (Foo *)allocClassWithName("Foo");
+  //
+  // While OSRequiredCast can be used here, it is still not a useful warning.
+  auto AllocClassWithNameM = callExpr(
+  callee(functionDecl(hasName("allocClassWithName"))),
+  // Here we want to make sure that the string argument matches the
+  // type in the cast expression.
+  hasArgument(0, stringLiteral(mentionsBoundType(WarnRecordDecl;
+
+  auto OSObjTypeM =
+  hasTypePointingTo(cxxRecordDecl(isDerivedFrom("OSMetaClassBase")));
   auto OSObjSubclassM = hasTypePointingTo(
-cxxRecordDecl(isDerivedFrom("OSObject")).bind(WarnRecordDecl));
-
-  auto CastM = cStyleCastExpr(
-  allOf(hasSourceExpression(allOf(OSObjTypeM, unless(DynamicCastM))),
-  OSObjSubclassM)).bind(WarnAtNode);
-
-  auto Matches = match(stmt(forEachDescendant(CastM)), *D->getBody(), 
AM.getASTContext());
+  cxxRecordDecl(isDerivedFrom("OSObject")).bind(WarnRecordDecl));
+
+  auto CastM =
+  cStyleCastExpr(
+  allOf(OSObjSubclassM,
+hasSourceExpression(
+allOf(OSObjTypeM,
+  unless(anyOf(DynamicCastM, AllocClassWithNameM))
+  .bind(WarnAtNode);
+
+  auto Matches =
+  match(stmt(forEachDescendant(CastM)), *D->getBody(), AM.getASTContext());
   for (BoundNodes Match : Matches)
 emitDiagnostics(Match, BR, ADC, this);
 }

diff  --git a/clang/test/Analysis/os_object_base.h 
b/clang/test/Analysis/os_object_base.h
index 4698185f2b3c..c3d5d6271d48 100644
--- a/clang/test/Analysis/os_object_base.h
+++ b/clang/test/Analysis/os_object_base.h
@@ -66,6 +66,7 @@ struct OSObject : public OSMetaClassBase {
 
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
+  static OSObject * allocClassWithName(const char * name);
   virtual ~OSMetaClass(){}
 };
 

diff  --git a/clang/test/Analysis/osobjectcstylecastche

[PATCH] D99500: [analyzer] Support allocClassWithName in OSObjectCStyleCast checker

2021-03-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90377308de6c: [analyzer] Support allocClassWithName in 
OSObjectCStyleCast checker (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99500

Files:
  clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobjectcstylecastchecker_test.cpp

Index: clang/test/Analysis/osobjectcstylecastchecker_test.cpp
===
--- clang/test/Analysis/osobjectcstylecastchecker_test.cpp
+++ clang/test/Analysis/osobjectcstylecastchecker_test.cpp
@@ -37,3 +37,12 @@
   return b->getCount();
 }
 
+unsigned no_warn_alloc_class_with_name() {
+  OSArray *a = (OSArray *)OSMetaClass::allocClassWithName("OSArray"); // no warning
+  return a->getCount();
+}
+
+unsigned warn_alloc_class_with_name() {
+  OSArray *a = (OSArray *)OSMetaClass::allocClassWithName("OSObject"); // expected-warning{{C-style cast of an OSObject is prone to type confusion attacks; use 'OSRequiredCast' if the object is definitely of type 'OSArray', or 'OSDynamicCast' followed by a null check if unsure}}
+  return a->getCount();
+}
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -66,6 +66,7 @@
 
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
+  static OSObject * allocClassWithName(const char * name);
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
+++ clang/lib/StaticAnalyzer/Checkers/OSObjectCStyleCast.cpp
@@ -32,7 +32,21 @@
   void checkASTCodeBody(const Decl *D, AnalysisManager &AM,
 BugReporter &BR) const;
 };
+} // namespace
+
+namespace clang {
+namespace ast_matchers {
+AST_MATCHER_P(StringLiteral, mentionsBoundType, std::string, BindingID) {
+  return Builder->removeBindings([this, &Node](const BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  return ND->getName() != Node.getString();
+}
+return true;
+  });
 }
+} // end namespace ast_matchers
+} // end namespace clang
 
 static void emitDiagnostics(const BoundNodes &Nodes,
 BugReporter &BR,
@@ -63,22 +77,41 @@
   return hasType(pointerType(pointee(hasDeclaration(DeclM;
 }
 
-void OSObjectCStyleCastChecker::checkASTCodeBody(const Decl *D, AnalysisManager &AM,
+void OSObjectCStyleCastChecker::checkASTCodeBody(const Decl *D,
+ AnalysisManager &AM,
  BugReporter &BR) const {
 
   AnalysisDeclContext *ADC = AM.getAnalysisDeclContext(D);
 
   auto DynamicCastM = callExpr(callee(functionDecl(hasName("safeMetaCast";
-
-  auto OSObjTypeM = hasTypePointingTo(cxxRecordDecl(isDerivedFrom("OSMetaClassBase")));
+  // 'allocClassWithName' allocates an object with the given type.
+  // The type is actually provided as a string argument (type's name).
+  // This makes the following pattern possible:
+  //
+  // Foo *object = (Foo *)allocClassWithName("Foo");
+  //
+  // While OSRequiredCast can be used here, it is still not a useful warning.
+  auto AllocClassWithNameM = callExpr(
+  callee(functionDecl(hasName("allocClassWithName"))),
+  // Here we want to make sure that the string argument matches the
+  // type in the cast expression.
+  hasArgument(0, stringLiteral(mentionsBoundType(WarnRecordDecl;
+
+  auto OSObjTypeM =
+  hasTypePointingTo(cxxRecordDecl(isDerivedFrom("OSMetaClassBase")));
   auto OSObjSubclassM = hasTypePointingTo(
-cxxRecordDecl(isDerivedFrom("OSObject")).bind(WarnRecordDecl));
-
-  auto CastM = cStyleCastExpr(
-  allOf(hasSourceExpression(allOf(OSObjTypeM, unless(DynamicCastM))),
-  OSObjSubclassM)).bind(WarnAtNode);
-
-  auto Matches = match(stmt(forEachDescendant(CastM)), *D->getBody(), AM.getASTContext());
+  cxxRecordDecl(isDerivedFrom("OSObject")).bind(WarnRecordDecl));
+
+  auto CastM =
+  cStyleCastExpr(
+  allOf(OSObjSubclassM,
+hasSourceExpression(
+allOf(OSObjTypeM,
+  unless(anyOf(DynamicCastM, AllocClassWithNameM))
+  .bind(WarnAtNode);
+
+  auto Matches =
+  match(stmt(forEachDescendant(CastM)), *D->getBody(), AM.getASTContext());
   for (BoundNodes Match : Matches)
 emitDiagnostics(Match, BR, ADC, this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailm

[clang] af7e1f0 - [analyzer] Fix crash when reasoning about C11 atomics (PR49422)

2021-03-30 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-03-30T16:04:19+03:00
New Revision: af7e1f07ac03074647897498358aaec165c1aaea

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

LOG: [analyzer] Fix crash when reasoning about C11 atomics (PR49422)

rdar://75020762

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
clang/test/Analysis/atomics.c

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
index 9f464e82304f4..f59b254094db8 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -139,6 +139,12 @@ class BasicValueFactory {
 
   /// Returns the type of the APSInt used to store values of the given 
QualType.
   APSIntType getAPSIntType(QualType T) const {
+// For the purposes of the analysis and constraints, we treat atomics
+// as their underlying types.
+if (const AtomicType *AT = T->getAs()) {
+  T = AT->getValueType();
+}
+
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());

diff  --git a/clang/test/Analysis/atomics.c b/clang/test/Analysis/atomics.c
index b3d2d352a2283..ef1a216c7d577 100644
--- a/clang/test/Analysis/atomics.c
+++ b/clang/test/Analysis/atomics.c
@@ -93,3 +93,11 @@ void test_atomic_compare_exchange_weak(struct 
RefCountedStruct *s) {
   clang_analyzer_eval(s->refCount == 3); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(expected == 2); // expected-warning {{UNKNOWN}}
 }
+
+// PR49422
+void test_atomic_compare(int input) {
+  _Atomic(int) x = input;
+  if (x > 0) {
+// no crash
+  }
+}



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


[PATCH] D99274: [analyzer] Fix crash when reasoning about C11 atomics (PR49422)

2021-03-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf7e1f07ac03: [analyzer] Fix crash when reasoning about C11 
atomics (PR49422) (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99274

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/test/Analysis/atomics.c


Index: clang/test/Analysis/atomics.c
===
--- clang/test/Analysis/atomics.c
+++ clang/test/Analysis/atomics.c
@@ -93,3 +93,11 @@
   clang_analyzer_eval(s->refCount == 3); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(expected == 2); // expected-warning {{UNKNOWN}}
 }
+
+// PR49422
+void test_atomic_compare(int input) {
+  _Atomic(int) x = input;
+  if (x > 0) {
+// no crash
+  }
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -139,6 +139,12 @@
 
   /// Returns the type of the APSInt used to store values of the given 
QualType.
   APSIntType getAPSIntType(QualType T) const {
+// For the purposes of the analysis and constraints, we treat atomics
+// as their underlying types.
+if (const AtomicType *AT = T->getAs()) {
+  T = AT->getValueType();
+}
+
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());


Index: clang/test/Analysis/atomics.c
===
--- clang/test/Analysis/atomics.c
+++ clang/test/Analysis/atomics.c
@@ -93,3 +93,11 @@
   clang_analyzer_eval(s->refCount == 3); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(expected == 2); // expected-warning {{UNKNOWN}}
 }
+
+// PR49422
+void test_atomic_compare(int input) {
+  _Atomic(int) x = input;
+  if (x > 0) {
+// no crash
+  }
+}
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -139,6 +139,12 @@
 
   /// Returns the type of the APSInt used to store values of the given QualType.
   APSIntType getAPSIntType(QualType T) const {
+// For the purposes of the analysis and constraints, we treat atomics
+// as their underlying types.
+if (const AtomicType *AT = T->getAs()) {
+  T = AT->getValueType();
+}
+
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
 return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95845: [ObjC] Add a command line flag that disables recognition of objc_direct for testability

2021-03-30 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 334136.
erik.pilkington added a comment.

- Use the new marshaling infrastructure
- Fix a few places in Sema where we manually checked for `ObjCDirectAttr` 
instead of using `isDirectMethod`


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

https://reviews.llvm.org/D95845

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/test/CodeGenObjC/disable-direct-method.m
  clang/test/Driver/clang_f_opts.c
  clang/test/SemaObjC/disable-direct-method.m

Index: clang/test/SemaObjC/disable-direct-method.m
===
--- /dev/null
+++ clang/test/SemaObjC/disable-direct-method.m
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -fobjc-disable-direct-methods-for-testing %s
+
+// expected-no-diagnostics
+
+#define DIRECT __attribute__((objc_direct))
+#define DIRECT_MEMBERS __attribute__((objc_direct_members))
+
+__attribute__((objc_root_class))
+@interface X
+-(void)direct_method DIRECT;
+@end
+
+@implementation X
+-(void)direct_method DIRECT {}
+@end
+
+__attribute__((objc_root_class))
+DIRECT_MEMBERS
+@interface Y
+-(void)direct_method2;
+@end
+
+@implementation Y
+-(void)direct_method2 {}
+@end
+
+__attribute__((objc_root_class))
+@interface Z
+@property (direct) int direct_property;
+@end
+
+@implementation Z @end
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -576,3 +576,8 @@
 
 // RUN: %clang -### -S -fno-temp-file %s 2>&1 | FileCheck -check-prefix=CHECK-NO-TEMP-FILE %s
 // CHECK-NO-TEMP-FILE: "-fno-temp-file"
+
+// RUN: %clang -### -xobjective-c -fobjc-disable-direct-methods-for-testing %s 2>&1 | FileCheck -check-prefix=CHECK_DISABLE_DIRECT %s
+// RUN: %clang -### -xobjective-c %s 2>&1 | FileCheck -check-prefix=CHECK_NO_DISABLE_DIRECT %s
+// CHECK_DISABLE_DIRECT: -fobjc-disable-direct-methods-for-testing
+// CHECK_NO_DISABLE_DIRECT-NOT: -fobjc-disable-direct-methods-for-testing
Index: clang/test/CodeGenObjC/disable-direct-method.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/disable-direct-method.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 -fobjc-disable-direct-methods-for-testing %s -o - | FileCheck %s
+
+@interface Y
+@property (direct) int direct_property;
+@end
+@implementation Y @end
+
+// CHECK: @OBJC_PROP_NAME_ATTR_ = private unnamed_addr constant [16 x i8] c"direct_property\00"
+// CHECK: @"_OBJC_$_PROP_LIST_Y" =
+// CHECK-SAME: @OBJC_PROP_NAME_ATTR_,
+
+@interface X
+-(void)m __attribute__((objc_direct));
+@end
+
+// CHECK-LABEL: define void @f
+void f(X *x) {
+  [x m];
+
+  // CHECK: call void bitcast ({{.*}} @objc_msgSend to {{.*}})
+}
Index: clang/lib/Sema/SemaDeclObjC.cpp
===
--- clang/lib/Sema/SemaDeclObjC.cpp
+++ clang/lib/Sema/SemaDeclObjC.cpp
@@ -4407,10 +4407,12 @@
 
 void Sema::CheckObjCMethodDirectOverrides(ObjCMethodDecl *method,
   ObjCMethodDecl *overridden) {
-  if (const auto *attr = overridden->getAttr()) {
+  if (overridden->isDirectMethod()) {
+const auto *attr = overridden->getAttr();
 Diag(method->getLocation(), diag::err_objc_override_direct_method);
 Diag(attr->getLocation(), diag::note_previous_declaration);
-  } else if (const auto *attr = method->getAttr()) {
+  } else if (method->isDirectMethod()) {
+const auto *attr = method->getAttr();
 Diag(attr->getLocation(), diag::err_objc_direct_on_override)
 << isa(overridden->getDeclContext());
 Diag(overridden->getLocation(), diag::note_previous_declaration);
@@ -4856,7 +4858,8 @@
 // the canonical declaration.
 if (!ObjCMethod->isDirectMethod()) {
   const ObjCMethodDecl *CanonicalMD = ObjCMethod->getCanonicalDecl();
-  if (const auto *attr = CanonicalMD->getAttr()) {
+  if (CanonicalMD->isDirectMethod()) {
+const auto *attr = CanonicalMD->getAttr();
 ObjCMethod->addAttr(
 ObjCDirectAttr::CreateImplicit(Context, attr->getLocation()));
   }
@@ -4901,14 +4904,16 @@
 Diag(IMD->getLocation(), diag::note_previous_declaration);
   };
 
-  if (const auto *attr = ObjCMethod->getAttr()) {
+  if (ObjCMethod->isDirectMethod()) {
+const auto *attr = ObjCMethod->getAttr();
 if (ObjCMethod->getCanonicalDecl() != IMD) {
   diagContainerMismatch();
 } else if (!IMD->isDirectMethod()) {
   Diag(attr->getLocation(), diag::err_objc_direct_missing_on_decl);
   Diag(IMD->getLocation(), diag::note_previous_declaration);
 }

[PATCH] D98128: [clang][clangd] Avoid inconsistent target creation

2021-03-30 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT added a comment.

ping.

After some investigation, I think it is quite hard to add tests to avoid 
inconsistency between clang and clangd. Maybe I could add some tests for CUDA, 
OpenMP if needed.

WDYT


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98128

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


[PATCH] D99260: [analyzer] Fix false positives in inner pointer checker (PR49628)

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/inner-pointer.cpp:23
+
+char *data(std::string &c);
+

Seems like all test are exercising with std::string, this looks like a legacy 
in this Checker.
Still, I miss a bit at least one test for the other overloads of `std::data`, 
maybe in a follow up patch?



Comment at: clang/test/Analysis/inner-pointer.cpp:378-392
+void func_addressof() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  addressof(s);
+  consume(c); // no-warning
+}

So these are the FP cases that you are trying to solve?
Would be nice to see more details about the bug report (rdar://73463300) if 
that is not proprietary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260

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


[PATCH] D99482: [PoC][Clang][CodeGen] Do not use getelementptr for scalable struct.

2021-03-30 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 334145.
HsiangKai edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99482

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1298,10 +1298,14 @@
  bool DestIsVolatile) {
   // Prefer scalar stores to first-class aggregate stores.
   if (llvm::StructType *STy = dyn_cast(Val->getType())) {
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  Address EltPtr = Builder.CreateStructGEP(Dest, i);
-  llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
-  Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
+if (STy->containsScalableVectorType())
+  Builder.CreateStore(Val, Dest, DestIsVolatile);
+else {
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+Address EltPtr = Builder.CreateStructGEP(Dest, i);
+llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
+Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
+  }
 }
   } else {
 Builder.CreateStore(Val, Dest, DestIsVolatile);
@@ -2857,11 +2861,21 @@
 }
 
 assert(STy->getNumElements() == NumIRArgs);
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  auto AI = Fn->getArg(FirstIRArg + i);
-  AI->setName(Arg->getName() + ".coerce" + Twine(i));
-  Address EltPtr = Builder.CreateStructGEP(AddrToStoreInto, i);
-  Builder.CreateStore(AI, EltPtr);
+if (STy->containsScalableVectorType()) {
+  llvm::Value *Val = llvm::UndefValue::get(STy);
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+auto AI = Fn->getArg(FirstIRArg + i);
+AI->setName(Arg->getName() + ".coerce" + Twine(i));
+Val = Builder.CreateInsertValue(Val, AI, i);
+  }
+  Builder.CreateStore(Val, AddrToStoreInto);
+} else {
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+auto AI = Fn->getArg(FirstIRArg + i);
+AI->setName(Arg->getName() + ".coerce" + Twine(i));
+Address EltPtr = Builder.CreateStructGEP(AddrToStoreInto, i);
+Builder.CreateStore(AI, EltPtr);
+  }
 }
 
 if (SrcSize > DstSize) {
@@ -4920,10 +4934,18 @@
 }
 
 assert(NumIRArgs == STy->getNumElements());
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  Address EltPtr = Builder.CreateStructGEP(Src, i);
-  llvm::Value *LI = Builder.CreateLoad(EltPtr);
-  IRCallArgs[FirstIRArg + i] = LI;
+if (STy->containsScalableVectorType()) {
+  llvm::Value *Val = Builder.CreateLoad(Src);
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+llvm::Value *LI = Builder.CreateExtractValue(Val, i);
+IRCallArgs[FirstIRArg + i] = LI;
+  }
+} else {
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+Address EltPtr = Builder.CreateStructGEP(Src, i);
+llvm::Value *LI = Builder.CreateLoad(EltPtr);
+IRCallArgs[FirstIRArg + i] = LI;
+  }
 }
   } else {
 // In the simple case, just pass the coerced loaded value.


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1298,10 +1298,14 @@
  bool DestIsVolatile) {
   // Prefer scalar stores to first-class aggregate stores.
   if (llvm::StructType *STy = dyn_cast(Val->getType())) {
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  Address EltPtr = Builder.CreateStructGEP(Dest, i);
-  llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
-  Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
+if (STy->containsScalableVectorType())
+  Builder.CreateStore(Val, Dest, DestIsVolatile);
+else {
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+Address EltPtr = Builder.CreateStructGEP(Dest, i);
+llvm::Value *Elt = Builder.CreateExtractValue(Val, i);
+Builder.CreateStore(Elt, EltPtr, DestIsVolatile);
+  }
 }
   } else {
 Builder.CreateStore(Val, Dest, DestIsVolatile);
@@ -2857,11 +2861,21 @@
 }
 
 assert(STy->getNumElements() == NumIRArgs);
-for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
-  auto AI = Fn->getArg(FirstIRArg + i);
-  AI->setName(Arg->getName() + ".coerce" + Twine(i));
-  Address EltPtr = Builder.CreateStructGEP(AddrToStoreInto, i);
-  Builder.CreateStore(AI, EltPt

[PATCH] D99590: [Clang] Do not use memcpy for struct copy.

2021-03-30 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai created this revision.
HsiangKai added reviewers: craig.topper, frasercrmck, rogfer01.
Herald added a subscriber: StephenFan.
HsiangKai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For scalable struct types, we do not know the exact size of the struct. Do not 
use memcpy for struct copy. We use extractvalue and insertvalue for the purpose.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99590

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGExprAgg.cpp


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -2077,6 +2077,23 @@
 }
   }
 
+  // Aggregate assignment turns into element-by-element copy.
+  if (const RecordType *RecordTy = Ty->getAs()) {
+if (RecordTy->hasSizelessFields()) {
+  RecordDecl *Record = RecordTy->getDecl();
+  llvm::Value *SrcVec = Builder.CreateLoad(SrcPtr);
+  llvm::Value *DestVec = llvm::UndefValue::get(ConvertType(Ty));
+  llvm::Value *Vec;
+  for (unsigned I = 0;
+   I < getContext().getASTRecordLayout(Record).getFieldCount(); ++I) {
+Vec = Builder.CreateExtractValue(SrcVec, I);
+DestVec = Builder.CreateInsertValue(DestVec, Vec, I);
+  }
+  Builder.CreateStore(DestVec, DestPtr);
+  return;
+}
+  }
+
   // Aggregate assignment turns into llvm.memcpy.  This is almost valid per
   // C99 6.5.16.1p3, which states "If the value being stored in an object is
   // read from another object that overlaps in anyway the storage of the first
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3510,6 +3510,28 @@
   return false;
 }
 
+bool RecordType::hasSizelessFields() const {
+  std::vector RecordTypeList;
+  RecordTypeList.push_back(this);
+  unsigned NextToCheckIndex = 0;
+
+  while (RecordTypeList.size() > NextToCheckIndex) {
+for (FieldDecl *FD :
+ RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
+  QualType FieldTy = FD->getType();
+  if (FieldTy.getTypePtr()->isSizelessType())
+return true;
+  FieldTy = FieldTy.getCanonicalType();
+  if (const auto *FieldRecTy = FieldTy->getAs()) {
+if (llvm::find(RecordTypeList, FieldRecTy) == RecordTypeList.end())
+  RecordTypeList.push_back(FieldRecTy);
+  }
+}
+++NextToCheckIndex;
+  }
+  return false;
+}
+
 bool AttributedType::isQualifier() const {
   // FIXME: Generate this with TableGen.
   switch (getAttrKind()) {
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -4623,6 +4623,10 @@
   /// is declared const, return true. Otherwise, return false.
   bool hasConstFields() const;
 
+  /// Recursively check all fields in the record for sizeless. If any field
+  /// is sizeless type, return true. Otherwise, return false.
+  bool hasSizelessFields() const;
+
   bool isSugared() const { return false; }
   QualType desugar() const { return QualType(this, 0); }
 


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -2077,6 +2077,23 @@
 }
   }
 
+  // Aggregate assignment turns into element-by-element copy.
+  if (const RecordType *RecordTy = Ty->getAs()) {
+if (RecordTy->hasSizelessFields()) {
+  RecordDecl *Record = RecordTy->getDecl();
+  llvm::Value *SrcVec = Builder.CreateLoad(SrcPtr);
+  llvm::Value *DestVec = llvm::UndefValue::get(ConvertType(Ty));
+  llvm::Value *Vec;
+  for (unsigned I = 0;
+   I < getContext().getASTRecordLayout(Record).getFieldCount(); ++I) {
+Vec = Builder.CreateExtractValue(SrcVec, I);
+DestVec = Builder.CreateInsertValue(DestVec, Vec, I);
+  }
+  Builder.CreateStore(DestVec, DestPtr);
+  return;
+}
+  }
+
   // Aggregate assignment turns into llvm.memcpy.  This is almost valid per
   // C99 6.5.16.1p3, which states "If the value being stored in an object is
   // read from another object that overlaps in anyway the storage of the first
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3510,6 +3510,28 @@
   return false;
 }
 
+bool RecordType::hasSizelessFields() const {
+  std::vector RecordTypeList;
+  RecordTypeList.push_back(this);
+  unsigned NextToCheckIndex = 0;
+
+  while (RecordTypeList.size() > NextToCheckIndex) {
+for (FieldDecl *FD :
+ RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
+  QualType FieldTy = FD->getType();
+  if (FieldTy.getTypePtr()->isSizelessType(

[PATCH] D99592: [PoC][Clang] Use TypeSize instead of uint64_t for getTypeAllocSize().

2021-03-30 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai created this revision.
HsiangKai added reviewers: craig.topper, frasercrmck, rogfer01.
Herald added a subscriber: StephenFan.
HsiangKai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The return type of getTypeAllocSize() is TypeSize. We do not rely on the 
implicit conversion to uint64_t. The return value may be scalable values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99592

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp


Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -159,7 +159,8 @@
 return Context.toCharUnitsFromBits(BitOffset);
   }
   CharUnits getSize(llvm::Type *Type) {
-return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type));
+return CharUnits::fromQuantity(
+DataLayout.getTypeAllocSize(Type).getKnownMinValue());
   }
   CharUnits getAlignment(llvm::Type *Type) {
 return CharUnits::fromQuantity(DataLayout.getABITypeAlignment(Type));
@@ -929,7 +930,8 @@
   const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D);
 
   uint64_t TypeSizeInBits = getContext().toBits(Layout.getSize());
-  assert(TypeSizeInBits == getDataLayout().getTypeAllocSizeInBits(Ty) &&
+  assert(TypeSizeInBits ==
+ getDataLayout().getTypeAllocSizeInBits(Ty).getKnownMinValue() &&
  "Type size mismatch!");
 
   if (BaseTy) {
@@ -938,9 +940,10 @@
 uint64_t AlignedNonVirtualTypeSizeInBits =
   getContext().toBits(NonVirtualSize);
 
-assert(AlignedNonVirtualTypeSizeInBits ==
-   getDataLayout().getTypeAllocSizeInBits(BaseTy) &&
-   "Type size mismatch!");
+assert(
+AlignedNonVirtualTypeSizeInBits ==
+getDataLayout().getTypeAllocSizeInBits(BaseTy).getKnownMinValue() 
&&
+"Type size mismatch!");
   }
 
   // Verify that the LLVM and AST field offsets agree.
@@ -960,7 +963,8 @@
 // AST offset.
 if (!FD->isBitField()) {
   unsigned FieldNo = RL->getLLVMFieldNo(FD);
-  assert(AST_RL.getFieldOffset(i) == SL->getElementOffsetInBits(FieldNo) &&
+  assert(AST_RL.getFieldOffset(i) ==
+ SL->getElementOffsetInBits(FieldNo).getKnownMinSize() &&
  "Invalid field offset!");
   continue;
 }
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2848,12 +2848,12 @@
   llvm::StructType *STy = 
dyn_cast(ArgI.getCoerceToType());
   if (ArgI.isDirect() && ArgI.getCanBeFlattened() && STy &&
   STy->getNumElements() > 1) {
-uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
+llvm::TypeSize SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
 llvm::Type *DstTy = Ptr.getElementType();
-uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
+llvm::TypeSize DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
 
 Address AddrToStoreInto = Address::invalid();
-if (SrcSize <= DstSize) {
+if (llvm::TypeSize::isKnownLE(SrcSize, DstSize)) {
   AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
 } else {
   AddrToStoreInto =
@@ -2878,7 +2878,7 @@
   }
 }
 
-if (SrcSize > DstSize) {
+if (llvm::TypeSize::isKnownGT(SrcSize, DstSize)) {
   Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
 }
 
@@ -4915,18 +4915,18 @@
 dyn_cast(ArgInfo.getCoerceToType());
   if (STy && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) {
 llvm::Type *SrcTy = Src.getElementType();
-uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
-uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
+llvm::TypeSize SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
+llvm::TypeSize DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
 
 // If the source type is smaller than the destination type of the
 // coerce-to logic, copy the source value into a temp alloca the size
 // of the destination type to allow loading all of it. The bits past
 // the source value are left undef.
-if (SrcSize < DstSize) {
+if (llvm::TypeSize::isKnownLT(SrcSize, DstSize)) {
   Address TempAlloca
 = CreateTempAlloca(STy, Src.getAlignment(),
Src.getName() + ".coerce");
-  Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
+  Builder.CreateMemCpy(TempAlloca, Src, SrcSize.getKnownMinSize());
   Src = TempAlloca;
 } else {
   Src = Builder.CreateBitCast(Src,


Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
==

[PATCH] D97264: [RISCV] Define types for Zvlsseg.

2021-03-30 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 334150.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97264

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/RISCVVTypes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/Sema/riscv-types.c

Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -133,4 +133,10 @@
 
   // CHECK: __rvv_int8mf2_t x43;
   __rvv_int8mf2_t x43;
+
+  // CHECK: __rvv_int8mf2x2_t x44;
+  __rvv_int8mf2x2_t x44;
+
+  // CHECK: __rvv_int8m2x2_t x45;
+  __rvv_int8m2x2_t x45;
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -400,6 +400,8 @@
   if (Context.getTargetInfo().hasRISCVVTypes()) {
 #define RVV_TYPE(Name, Id, SingletonId)\
   addImplicitTypedef(Name, Context.SingletonId);
+#define RVV_TUPLE(Name, ElemId, Id, SingletonId, NumEls, ElBits, NF, IsSigned, IsFP) \
+  addImplicitTypedef(Name, Context.SingletonId);
 #include "clang/Basic/RISCVVTypes.def"
   }
 
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1440,6 +1440,8 @@
   if (Target.hasRISCVVTypes()) {
 #define RVV_TYPE(Name, Id, SingletonId)\
   InitBuiltinType(SingletonId, BuiltinType::Id);
+#define RVV_TUPLE(Name, ElemId, Id, SingletonId, NE, EB, NF, IsSigned, IsFP)   \
+  InitRVVTupleType(SingletonId, Name, BuiltinType::ElemId, NF);
 #include "clang/Basic/RISCVVTypes.def"
   }
 
@@ -1479,6 +1481,36 @@
   }
 }
 
+void ASTContext::InitRVVTupleType(QualType &R, StringRef Name,
+  BuiltinType::Kind K, unsigned NF) {
+  auto TypeIter = llvm::find_if(Types, [&K](Type *Ty) {
+ if (Ty->isBuiltinType()) {
+   return cast(Ty)->getKind() == K;
+ }
+ return false;
+   });
+
+  if (TypeIter != Types.end()) {
+RecordDecl *RD = buildImplicitRecord(Name);
+RD->startDefinition();
+for (unsigned I = 0; I < NF; ++I) {
+  SmallVector FieldNameStorage;
+  FieldDecl *Field = FieldDecl::Create(*this, RD, SourceLocation(),
+   SourceLocation(),
+   &Idents.get(
+ (Twine("v") + Twine(I)).toStringRef(FieldNameStorage)),
+   QualType(*TypeIter, 0), nullptr, nullptr, false,
+   ICIS_NoInit);
+  Field->setAccess(AS_public);
+  RD->addDecl(Field);
+}
+RD->completeDefinition();
+
+TypedefDecl *TD = buildImplicitTypedef(getTagDeclType(RD), Name);
+R = getTypedefType(TD);
+  }
+}
+
 DiagnosticsEngine &ASTContext::getDiagnostics() const {
   return SourceMgr.getDiagnostics();
 }
@@ -2181,8 +2213,7 @@
 Align = Size;  \
 break;
 #include "clang/Basic/PPCTypes.def"
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, NF, IsSigned,   \
-IsFP)  \
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, IsSigned, IsFP) \
   case BuiltinType::Id:\
 Width = 0; \
 Align = ElBits;\
@@ -3837,15 +3868,14 @@
 return SVE_ELTTY(BFloat16Ty, 8, 3);
   case BuiltinType::SveBFloat16x4:
 return SVE_ELTTY(BFloat16Ty, 8, 4);
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
-IsSigned)  \
+#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, IsSigned)   \
   case BuiltinType::Id:\
 return {getIntTypeForBitwidth(ElBits, IsSigned),   \
-llvm::ElementCount::getScalable(NumEls), NF};
-#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)   \
+llvm::ElementCount::getScalable(NumEls), 1};
+#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits)   \
   case BuiltinType::Id:\
 return {ElBits == 16 ? HalfTy : (ElBits == 32 ? FloatTy : DoubleTy),   \
-llvm::ElementCount::getScalable(NumEls), NF};
+llvm::ElementCount::getScalable(NumEls), 1};
 #define RVV

[PATCH] D99593: [Clang][RISCV] Implement vlseg builtins.

2021-03-30 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai created this revision.
HsiangKai added reviewers: craig.topper, frasercrmck, rogfer01.
Herald added subscribers: StephenFan, vkmr, dexonsmith, evandro, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, 
niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
HsiangKai requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Implement vlseg builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99593

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlseg.c
  clang/utils/TableGen/RISCVVEmitter.cpp

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


[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-03-30 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 334156.
balazske added a comment.

Use `mayThrow`, improve test (user and class-specific cases).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97196

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
@@ -0,0 +1,194 @@
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-unhandled-exception-at-new %t
+
+namespace std {
+typedef __typeof__(sizeof(0)) size_t;
+enum class align_val_t : std::size_t {};
+class exception {};
+class bad_alloc : public exception {};
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+} // namespace std
+
+void *operator new(std::size_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, void *) noexcept;
+
+class A {};
+typedef std::bad_alloc badalloc1;
+using badalloc2 = std::bad_alloc;
+using badalloc3 = std::bad_alloc &;
+
+void *operator new(std::size_t, int, int);
+void *operator new(std::size_t, int, int, int) noexcept;
+
+struct ClassSpecificNew {
+  void *operator new(std::size_t);
+  void *operator new(std::size_t, std::align_val_t);
+  void *operator new(std::size_t, int, int) noexcept;
+  void *operator new(std::size_t, int, int, int);
+};
+
+struct ConstructorTest {
+  ConstructorTest();
+  ConstructorTest(int) noexcept;
+};
+
+void f1() noexcept {
+  int *I1 = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  try {
+int *I2 = new int;
+try {
+  int *I3 = new int;
+} catch (A) {
+}
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc2) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc3) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (std::bad_alloc *) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (A) {
+  }
+}
+
+void f2() noexcept {
+  try {
+int *I = new int;
+  } catch (A) {
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (...) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::exception &) {
+  }
+}
+
+void f_new_nothrow() noexcept {
+  int *I1 = new (std::nothrow) int;
+  int *I2 = new (static_cast(1), std::nothrow) int;
+}
+
+void f_new_placement() noexcept {
+  char buf[100];
+  int *I = new (buf) int;
+}
+
+void f_new_user_defined() noexcept {
+  int *I1 = new (1, 2) int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  int *I2 = new (1, 2, 3) int;
+}
+
+void f_class_specific() noexcept {
+  ClassSpecificNew *N1 = new ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+  ClassSpecificNew *N2 = new (static_cast(1)) ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+  ClassSpecificNew *N3 = new (1, 2) ClassSpecificNew;
+  ClassSpecificNew *N4 = new (1, 2, 3) ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_constructor() noexcept {
+  ConstructorTest *T1 = new ConstructorTest;
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: missing exception handler for allocation failure at 'new'
+  ConstructorTest *T2 = new ConstructorTest{1};
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: missing exception handler for allocation failure at 'new'
+  ConstructorTest *T3 = new (std::nothrow) ConstructorTest;
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: missing exception handler for alloca

[PATCH] D99262: [analyzer] Fix dead store checker false positive

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:420-421
+  // We should also allow defensive initialization of structs.
+  if (const auto *ILE =
+  dyn_cast(E->IgnoreParenCasts())) {
+// We can use exactly the same logic here.

What about nested InitListExpr's?
```
std::array a1{ {1, 2, 3} };
```

```
VarDecl 0x561b200333a0  col:20 a1 
'std::array':'std::array' listinit
`-InitListExpr 0x561b20036d78  'std::array':'std::array'
  `-InitListExpr 0x561b20036dc0  'typename 
_AT_Type::_Type':'int [3]'
|-IntegerLiteral 0x561b20033408  'int' 1
|-IntegerLiteral 0x561b20033428  'int' 2
`-IntegerLiteral 0x561b20033448  'int' 3
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99262

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


[PATCH] D99517: Implemented [[clang::musttail]] attribute for guaranteed tail calls.

2021-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1356
+def MustTail : StmtAttr {
+  let Spellings = [Clang<"musttail">];
+  let Documentation = [MustTailDocs];

You should add a `Subjects` list here.



Comment at: clang/include/clang/Basic/AttrDocs.td:449
+  let Content = [{
+If a return statement is marked ``musttail``, this indicates that the
+compiler must generate a tail call for the program to be correct, even when





Comment at: clang/include/clang/Basic/AttrDocs.td:454
+
+``clang::musttail`` can only be applied to a return statement whose value is a
+function call (even functions returning void must use 'return', although no





Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2826-2827
   InGroup;
+def err_musttail_only_on_return : Error<
+  "%0 attribute can only be applied to a return statement">;
+def err_musttail_needs_call : Error<

This error should not be necessary if you add the correct subject line to 
Attr.td



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2829-2830
+def err_musttail_needs_call : Error<
+  "%0 attribute requires that the return value is a function call, which must "
+  "not create or destroy any temporaries.">;
+def err_musttail_only_from_function : Error<





Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2832
+def err_musttail_only_from_function : Error<
+  "%0 attribute can only be used from a regular function.">;
+def err_musttail_return_type_mismatch : Error<

What is a "regular function?"



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2837
+def err_musttail_no_destruction : Error<
+  "%0 attribute does not allow any variables in scope that require destruction"
+  >;

All automatic variables require destruction when leaving the scope, so this 
diagnostic reads oddly to me. Perhaps you mean that the variables must all be 
trivially destructible?



Comment at: clang/include/clang/Sema/ScopeInfo.h:121
 
+  /// Whether this function contains any statement marked with \c [musttail].
+  bool HasMustTail : 1;





Comment at: clang/lib/CodeGen/CGCall.cpp:5315-5317
+// TODO(haberman): insert checks/assertions to verify that this early exit
+// is safe. We tried to verify this in Sema but we should double-check
+// here.

Are you planning to handle this TODO in the patch? If not, can you switch to a 
FIXME without a name associated with it?



Comment at: clang/lib/CodeGen/CGCall.cpp:5318-5322
+if (RetTy->isVoidType()) {
+  Builder.CreateRetVoid();
+} else {
+  Builder.CreateRet(CI);
+}





Comment at: clang/lib/CodeGen/CGExpr.cpp:4828
  ReturnValueSlot ReturnValue) {
+  SaveAndRestore save_musttail(InMustTailCallExpr, E == MustTailCall);
+





Comment at: clang/lib/CodeGen/CGStmt.cpp:655-658
+  const ReturnStmt *R = dyn_cast(Sub);
+  assert(R && "musttail should only be on ReturnStmt");
+  musttail = dyn_cast(R->getRetValue());
+  assert(musttail && "musttail must return CallExpr");





Comment at: clang/lib/Sema/JumpDiagnostics.cpp:1005-1011
+  for (const auto *A : AS->getAttrs()) {
+if (A->getKind() == attr::MustTail) {
+  return A;
+}
+  }
+
+  return nullptr;





Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

This functionality belongs in SemaStmtAttr.cpp, I think.



Comment at: clang/lib/Sema/SemaStmt.cpp:578-582
+  if (!R) {
+Diag(St->getBeginLoc(), diag::err_musttail_only_on_return)
+<< MTA.getSpelling();
+return false;
+  }

This check should not be necessary once the code moves to SemaStmtAttr.cpp and 
Attr.td gets a correct subjects line.



Comment at: clang/lib/Sema/SemaStmt.cpp:584-591
+  const Expr *Ex = R->getRetValue();
+
+  // We don't actually support tail calling through an implicit cast (we 
require
+  // the return types to match), but getting the actual function call will let
+  // us give a better error message about the return type mismatch.
+  if (const ImplicitCastExpr *ICE = dyn_cast(Ex)) {
+Ex = ICE->getSubExpr();

I think you want to ignore parens and implicit casts here. e.g., there's no 
reason to diagnose code like:
```
int foo();
int bar() {
  [[clang::musttail]] return (bar());
}
```



Comment at: clang/lib/Se

[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-30 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:572
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
+else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;

Esme wrote:
> shchenz wrote:
> > Seems we miss to handle `DW_LANG_C_plus_plus_03` which is also a DWARF 5 
> > language name value? We always generate `DW_LANG_C_plus_plus` for 
> > `-std=c++03` even at `-gdwarf-5`? If so, maybe we also need to fix this in 
> > another patch.
> How about we just do that in this patch?
I don't think anyone will stop you. :)



Comment at: clang/test/CodeGenCXX/debug-info-programming-language.cpp:9
+// RUN:   -O0 -disable-llvm-passes \
+// RUN:   -debug-info-kind=standalone \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s

shchenz wrote:
> is limited debug info kind enough for this test?
Yes, limited is enough (and is the default).  "Limited" in this context mostly 
means unused type info will not be emitted; the language is a CU attribute, and 
the CU is always emitted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-03-30 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 334152.
Ericson2314 added a comment.

include(GNUInstallDirs) in each project unconditionally

Before projects that might not be built standalone only included it when they
were, but then we got into a situation where no project included it, and
things broke. There module is designed so that it's inclusion is idempotent,
so we just always include it.

We split the `if` for separate projects however to ensure that any conditional
initialization code after declaring the project that might need these variables
had them. `CMAKE_INSTALL_DOCDIR` depends on the project name so I don't think
it's a good idea to include before the project declaration. That left splitting
the `if`s as the safest option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/lib/Headers/CMakeLists.txt
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/Modules/AddCompilerRT.cmake
  compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/include/CMakeLists.txt
  compiler-rt/lib/dfsan/CMakeLists.txt
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/tools/f18/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  libc/CMakeLists.txt
  libc/lib/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxx/include/CMakeLists.txt
  libcxx/src/CMakeLists.txt
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  lld/CMakeLists.txt
  lld/cmake/modules/AddLLD.cmake
  lld/tools/lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/tools/intel-features/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/AddOCaml.cmake
  llvm/cmake/modules/AddSphinxTarget.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  llvm/docs/CMake.rst
  llvm/examples/Bye/CMakeLists.txt
  llvm/include/llvm/CMakeLists.txt
  llvm/tools/llvm-config/BuildVariables.inc.in
  llvm/tools/llvm-config/llvm-config.cpp
  llvm/tools/lto/CMakeLists.txt
  llvm/tools/opt-viewer/CMakeLists.txt
  llvm/tools/remarks-shlib/CMakeLists.txt
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/plugins/ve/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/cmake/polly_macros.cmake
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -81,15 +83,15 @@
 install(EXPORT ParallelSTLTargets
 FILE ParallelSTLTargets.cmake
 NAMESPACE pstl::
-DESTINATION lib/cmake/ParallelSTL)
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ParallelSTL)
 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
-DESTINATION lib/cmake/ParallelSTL)
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt

[PATCH] D99524: [RISCV][Clang] Add some RVV Integer intrinsic functions.

2021-03-30 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 334164.
khchen added a comment.

1. Address Craig's comments.
2. I didn't add common class for shift instruction. I will add it when we add

other shift instruction which have the same argments. Does it make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99524

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vdiv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vrem.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vrsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsll.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsra.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsrl.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vxor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vand.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vdiv.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmax.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmin.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmul.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsac.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vnmsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vor.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vrem.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vrsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsll.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsra.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsrl.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vxor.c

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


[PATCH] D99425: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov accepted this revision.
azabaznov added a comment.

Looks good to me. Thanks!

> Without this change, opencl-c.h cannot be parsed with -cl-std=CL3.0 as the 
> write_only image3d_t type is not enabled.

This should be fixed in the following up patches to check for 
`__opencl_c_3d_image_writes` feature or either for both:  
`__opencl_c_3d_image_writes`  and  `cl_khr_3d_image_writes`  (in OpenCL C 3.0 
mode). But I think it's OK to have this check for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99425

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


[PATCH] D99425: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Kévin Petit via Phabricator via cfe-commits
kpet added a comment.

Thanks! I'll commit the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99425

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


[clang] bd334c7 - [OPENMP]Fix test checks for 32bit targets, NFC.

2021-03-30 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-03-30T07:45:12-07:00
New Revision: bd334c790f2e43e72270b8044f08303e1c2f283b

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

LOG: [OPENMP]Fix test checks for 32bit targets, NFC.

Added: 


Modified: 
clang/test/OpenMP/declare_reduction_codegen.c

Removed: 




diff  --git a/clang/test/OpenMP/declare_reduction_codegen.c 
b/clang/test/OpenMP/declare_reduction_codegen.c
index c5b5d1dfa5a4..71f4be57f7c5 100644
--- a/clang/test/OpenMP/declare_reduction_codegen.c
+++ b/clang/test/OpenMP/declare_reduction_codegen.c
@@ -174,7 +174,7 @@ void bar() {
   // CHECK: [[SS_PRIV:%.+]] = alloca %struct.SSS,
   // CHECK: [[IN_PRIV:%.+]] = alloca i32,
   // CHECK: [[BC:%.+]] = bitcast %struct.SSS* [[SS_PRIV]] to i8*
-  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[BC]], i8* align 
4 bitcast (%struct.SSS* [[SSS_INIT]] to i8*), i64 4, i1 false)
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{64|32}}(i8* {{.*}}[[BC]], i8* 
{{.*}}bitcast (%struct.SSS* [[SSS_INIT]] to i8*), i{{64|32}} 4, i1 false)
   // CHECK: [[IN_VAL:%.+]] = load i32, i32* [[INT_INIT]],
   // CHECK: store i32 [[IN_VAL]], i32* [[IN_PRIV]],
   // CHECK: call void @__kmpc_for_static_init_4(



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


[PATCH] D99576: [ASTImporter][NFC] Improve test coverage

2021-03-30 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99576

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


[clang] 9d25ce7 - [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Kevin Petit via cfe-commits

Author: Kevin Petit
Date: 2021-03-30T16:17:46+01:00
New Revision: 9d25ce743a95a9ad03c0a4b3a705f85c2de52398

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

LOG: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

Ensure that the cl_khr_3d_image_writes pragma is enabled by making
cl_khr_3d_image_writes an optional core feature in CL 3.0 in addition
to being an available extension in 1.0 onwards and a core feature in
CL 2.0.

https://reviews.llvm.org/D99425

Signed-off-by: Kevin Petit 

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/test/Headers/opencl-c-header.cl
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index c5352dadc0de..5e2977f478f3 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -68,7 +68,7 @@ OPENCL_OPTIONALCOREFEATURE(cl_khr_fp64, true, 100, OCL_C_12P)
 OPENCL_EXTENSION(cl_khr_fp16, true, 100)
 OPENCL_EXTENSION(cl_khr_int64_base_atomics, true, 100)
 OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
-OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
+OPENCL_GENERIC_EXTENSION(cl_khr_3d_image_writes, true, 100, OCL_C_20, OCL_C_30)
 
 // EMBEDDED_PROFILE
 OPENCL_EXTENSION(cles_khr_int64, true, 110)

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 432c5e461d55..f72cea61fcd9 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 
| FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 
| FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ 
| FileCheck %s --check-prefix=CHECK20
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 
| FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -81,7 +82,7 @@ void test_atomics(__generic volatile unsigned int* a) {
 #endif
 
 // Verify that ATOMIC_VAR_INIT is defined.
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
 global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 // CHECK-MOD: Reading modules

diff  --git a/clang/test/SemaOpenCL/extension-version.cl 
b/clang/test/SemaOpenCL/extension-version.cl
index 64c8590d9b20..d135970b8b02 100644
--- a/clang/test/SemaOpenCL/extension-version.cl
+++ b/clang/test/SemaOpenCL/extension-version.cl
@@ -93,12 +93,12 @@
 // expected-warning@-2{{OpenCL extension 'cl_khr_fp64' is core feature or 
supported optional core feature - ignoring}}
 #endif
 
-//Core feature in CL 2.0
+//Core feature in CL 2.0, optional core feature in CL 3.0
 #ifndef cl_khr_3d_image_writes
 #error "Missing cl_khr_3d_image_writes define"
 #endif
 #pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
-#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) && 
defined TEST_CORE_FEATURES
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200 || 
__OPENCL_C_VERSION__ == 300) && defined TEST_CORE_FEATURES
 // expected-warning@-2{{OpenCL extension 'cl_khr_3d_image_writes' is core 
feature or supported optional core feature - ignoring}}
 #endif
 



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


[clang] bc4b0fc - [clang-format] Fix east const pointer alignment of operators

2021-03-30 Thread Marek Kurdej via cfe-commits

Author: Nico Rieck
Date: 2021-03-30T17:18:32+02:00
New Revision: bc4b0fc53e47e08a244df6ee3de52226e49ce37e

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

LOG: [clang-format] Fix east const pointer alignment of operators

This patch fixes left pointer alignment after pointer qualifiers of
operators. Currently "operator void const*()" is formatted with a space between
const and pointer despite setting PointerAlignment to Left.

AFAICS this has been broken since clang-format 10.

Reviewed By: MyDeveloperDay, curdeius

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 5177dca751d9..e42f28ed55cd 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2957,6 +2957,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 // Space between the type and the * in:
 //   operator void*()
 //   operator char*()
+//   operator void const*()
+//   operator void volatile*()
 //   operator /*comment*/ const char*()
 //   operator volatile /*comment*/ char*()
 //   operator Foo*()
@@ -2964,11 +2966,15 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 //   operator std::Foo*()
 //   operator C::D*()
 // dependent on PointerAlignment style.
-if (Previous &&
-(Previous->endsSequence(tok::kw_operator) ||
- Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
- Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
-  return (Style.PointerAlignment != FormatStyle::PAS_Left);
+if (Previous) {
+  if (Previous->endsSequence(tok::kw_operator))
+return (Style.PointerAlignment != FormatStyle::PAS_Left);
+  if (Previous->is(tok::kw_const) || Previous->is(tok::kw_volatile))
+return (Style.PointerAlignment != FormatStyle::PAS_Left) ||
+   (Style.SpaceAroundPointerQualifiers ==
+FormatStyle::SAPQ_After) ||
+   (Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both);
+}
   }
   const auto SpaceRequiredForArrayInitializerLSquare =
   [](const FormatToken &LSquareTok, const FormatStyle &Style) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 1dd287f71ce1..9e5e67d3b97d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12731,6 +12731,27 @@ TEST_F(FormatTest, 
ConfigurableSpaceAroundPointerQualifiers) {
   verifyQualifierSpaces("void * const *x = NULL;", PAS_Right, SAPQ_Both);
   verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Both);
 
+  verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, 
SAPQ_Default);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
+SAPQ_Default);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_Default);
+
+  verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, SAPQ_Before);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
+SAPQ_Before);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_Before);
+
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_After);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, 
SAPQ_After);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_After);
+
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_Both);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, SAPQ_Both);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle, 
SAPQ_Both);
+
 #undef verifyQualifierSpaces
 
   FormatStyle Spaces = getLLVMStyle();
@@ -18735,6 +18756,10 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("Foo::operator void **();", Style);
   verifyFormat("Foo::operator void *&();", Style);
   verifyFormat("Foo::operator void *&&();", Style);
+  verifyFormat("Foo::operator void const *();", Style);
+  verifyFormat("Foo::operator void const **();", Style);
+  verifyFormat("Foo::operator void const *&();", Style);
+  verifyFormat("Foo::operator void const *&&();", Style);
   verifyFormat("Foo::operator()(void *);", Style);
   verifyFormat("Foo::operator*(void *);", Style);
   verifyFormat("Foo::operator*();", Style);
@@ -18756,6 +18781,7 @@ TEST_F(FormatTest, OperatorSpacing) {
 
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator vo

[PATCH] D99458: [clang-format] Fix east const pointer alignment of operators

2021-03-30 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc4b0fc53e47: [clang-format] Fix east const pointer 
alignment of operators (authored by nrieck, committed by curdeius).

Changed prior to commit:
  https://reviews.llvm.org/D99458?vs=333678&id=334173#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99458

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12731,6 +12731,27 @@
   verifyQualifierSpaces("void * const *x = NULL;", PAS_Right, SAPQ_Both);
   verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Both);
 
+  verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, SAPQ_Default);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
+SAPQ_Default);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_Default);
+
+  verifyQualifierSpaces("Foo::operator void const*();", PAS_Left, SAPQ_Before);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right,
+SAPQ_Before);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_Before);
+
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_After);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, SAPQ_After);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle,
+SAPQ_After);
+
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Left, SAPQ_Both);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Right, SAPQ_Both);
+  verifyQualifierSpaces("Foo::operator void const *();", PAS_Middle, SAPQ_Both);
+
 #undef verifyQualifierSpaces
 
   FormatStyle Spaces = getLLVMStyle();
@@ -18735,6 +18756,10 @@
   verifyFormat("Foo::operator void **();", Style);
   verifyFormat("Foo::operator void *&();", Style);
   verifyFormat("Foo::operator void *&&();", Style);
+  verifyFormat("Foo::operator void const *();", Style);
+  verifyFormat("Foo::operator void const **();", Style);
+  verifyFormat("Foo::operator void const *&();", Style);
+  verifyFormat("Foo::operator void const *&&();", Style);
   verifyFormat("Foo::operator()(void *);", Style);
   verifyFormat("Foo::operator*(void *);", Style);
   verifyFormat("Foo::operator*();", Style);
@@ -18756,6 +18781,7 @@
 
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator void &();", Style);
+  verifyFormat("Foo::operator void const &();", Style);
   verifyFormat("Foo::operator()(void &);", Style);
   verifyFormat("Foo::operator&(void &);", Style);
   verifyFormat("Foo::operator&();", Style);
@@ -18764,6 +18790,7 @@
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("Foo::operator**();", Style);
   verifyFormat("Foo::operator void &&();", Style);
+  verifyFormat("Foo::operator void const &&();", Style);
   verifyFormat("Foo::operator()(void &&);", Style);
   verifyFormat("Foo::operator&&(void &&);", Style);
   verifyFormat("Foo::operator&&();", Style);
@@ -18784,6 +18811,11 @@
   verifyFormat("Foo::operator void*();", Style);
   verifyFormat("Foo::operator void**();", Style);
   verifyFormat("Foo::operator void*&();", Style);
+  verifyFormat("Foo::operator void*&&();", Style);
+  verifyFormat("Foo::operator void const*();", Style);
+  verifyFormat("Foo::operator void const**();", Style);
+  verifyFormat("Foo::operator void const*&();", Style);
+  verifyFormat("Foo::operator void const*&&();", Style);
   verifyFormat("Foo::operator/*comment*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
   verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
@@ -18805,6 +18837,7 @@
 
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator void&();", Style);
+  verifyFormat("Foo::operator void const&();", Style);
   verifyFormat("Foo::operator/*comment*/ void&();", Style);
   verifyFormat("Foo::operator/*a*/ const /*b*/ void&();", Style);
   verifyFormat("Foo::operator/*a*/ volatile /*b*/ void&();", Style);
@@ -18815,6 +18848,7 @@
 
   verifyFormat("Foo::operator&&();", Style);
   verifyFormat("Foo::operator void&&();", Style);
+  verifyFormat("Foo::operator void const&&();", Style);
   verifyFormat("Foo::operator/*comment*/ void&&();", Style);
   verifyFormat("Foo::operator/*a*/ const /*b*/ void&&();", Style);
   verifyFormat("Foo::operator/*a*/ volatile /*b*/ void&&();", Style);
@@ -18850,6 +18884,7 @@
 
   verifyFormat("Foo::operator&();", Style);
   verifyFormat("Foo::operator void &();", Style);
+  verifyFormat("Foo::operator void const &();", Style);
   verifyFormat("Foo::operator()(void &);", Style)

[PATCH] D99425: [OpenCL] Fix parsing of opencl-c.h in CL 3.0

2021-03-30 Thread Kévin Petit via Phabricator via cfe-commits
kpet closed this revision.
kpet added a comment.

Committed as 
https://github.com/llvm/llvm-project/commit/9d25ce743a95a9ad03c0a4b3a705f85c2de52398.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99425

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-03-30 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/cmake/modules/AddClang.cmake:127
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

For the initial change, Id leave this off.  `CMAKE_INSTALL_LIBDIR` sometimes 
already deals with the bit suffix, so you can end up with two instances of `32` 
or `64`.  I think that cleaning that up separately, while focusing on the 
details of cleaning up how to handle `LLVM_LIBDIR_SUFFIX` is the right thing to 
do.  The same applies to the rest of the patch.



Comment at: compiler-rt/cmake/base-config-ix.cmake:72
+  set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
+"Prefix where built compiler-rt artifacts should be installed, comes 
before CMAKE_INSTALL_PREFIX.")
   option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit 
tests." OFF)

Please don't change the descriptions of the options as part of the 
`GNUInstallDirs` handling.  The change to `COMPILER_RT_INSTALL_PATH` looks 
incorrect.  Can you explain this change please?



Comment at: libcxx/CMakeLists.txt:32
+
+include(GNUInstallDirs)
 

Does this need to come here?  Why not push this to after the if block 
completes?  The same applies through out the rest of the patch.



Comment at: libcxx/cmake/Modules/HandleLibCXXABI.cmake:66
   install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
-DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir}
+DESTINATION 
${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir}
 COMPONENT cxx-headers

@ldionne - how is the `LIBCXX_INSTALL_HEADER_PREFIX` used?  Can altering the 
value of `CMAKE_INSTALL_INCLUDEDIR` serve the purpose?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

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


[PATCH] D99278: [clang][parser] Allow GNU-style attributes in struct declarations

2021-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D99278#2657664 , @tbaeder wrote:

> This (and https://reviews.llvm.org/D99338) are both NFC changes once 
> https://reviews.llvm.org/D97362 lands (they need the three-parameter version 
> of `ProhibitCXX11Attributes()`). I can merge the three into one patch if you 
> prefer.

Thanks for verifying! I think they should probably be rolled up into one patch 
(it'd be easier for me to review in this case).


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

https://reviews.llvm.org/D99278

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


[PATCH] D99526: [RISCV][Clang] Add RVV Widening Integer Add/Subtract intrinsic functions.

2021-03-30 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 334178.
khchen added a comment.

Create a common class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99526

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwsub.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwsub.c

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


[PATCH] D93095: Introduce -Wreserved-identifier

2021-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/Decl.h:82
+enum ReservedIdentifierReason {
+  StartsWithUnderscoreAtGlobalScope,
+  StartsWithDoubleUnderscore,

serge-sans-paille wrote:
> aaron.ballman wrote:
> > Because this is not a scoped enum, should these enumerators get an `RIR_` 
> > prefix added to them?
> I used a class enum with a stream operator instead. Not a big fan of prefixed 
> enum ;-)
Totally fine by me, thank you!



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:383
+  "identifier %0 is reserved because %select{"
+  "|"
+  "it starts with '_' at global scope|"

You may want to add a comment here to alert people to the fact that passing 0 
for %1 is not valid but the `|` exists to make the enum order match the 
diagnostic. Otherwise it looks like it's possible to get a diagnostic 
`identifier 'whatever' is reserved because `.



Comment at: clang/lib/AST/Decl.cpp:1105-
+if (Name[1] == '_') {
+  return ReservedIdentifierStatus::StartsWithDoubleUnderscore;
+}
+if ('A' <= Name[1] && Name[1] <= 'Z') {
+  return ReservedIdentifierStatus::
+  StartsWithUnderscoreFollowedByCapitalLetter;
+}





Comment at: clang/lib/AST/Decl.cpp:1118-1120
+  if (isa(DC)) {
+return ReservedIdentifierStatus::StartsWithUnderscoreAtGlobalScope;
+  }





Comment at: clang/lib/AST/Decl.cpp:1125-1127
+  if (LangOpts.CPlusPlus && Name.contains("__")) {
+return ReservedIdentifierStatus::ContainsDoubleUnderscore;
+  }





Comment at: clang/lib/Sema/SemaDecl.cpp:5554
+  // Avoid warning twice on the same identifier, and don't warn on 
redeclaration
+  // of system decl
+  if (D->getPreviousDecl())

aaron.ballman wrote:
> 
Still missing a full stop at the end of the comment here.



Comment at: clang/lib/Sema/SemaDecl.cpp:5557-5558
+return;
+  if (!Context.getSourceManager().isInSystemHeader(D->getLocation()) &&
+  D->isReserved(getLangOpts()))
+Diag(D->getLocation(), diag::warn_reserved_identifier) << D;

rsmith wrote:
> Swap the order of these checks; the "is reserved" check is faster and will 
> usually allow us to short-circuit, whereas we're probably usually not in a 
> system header and that check involves nontrivial work recursively decomposing 
> the given source location.
Richard's comment is still unaddressed as well.



Comment at: clang/lib/Sema/SemaDecl.cpp:13640
 
+  warnOnReservedIdentifier(New);
+

rsmith wrote:
> serge-sans-paille wrote:
> > serge-sans-paille wrote:
> > > rsmith wrote:
> > > > Is there somewhere more central you can do this, rather than repeating 
> > > > it once for each kind of declaration? (Eg, `PushOnScopeChains`)
> > > That would be sane. I'll check that.
> > I tried PushOnScopeChains, and this does not capture all the required 
> > declarations. I failed to find another place :-/
> What cases is it missing? Can we add calls to `PushOnScopeChains` to those 
> cases (perhaps with a new flag to say "don't actually push it into scope"?) 
> I'm not super happy about adding a new thing that all places that create 
> declarations and add them to scope need to remember to do, to drive this 
> warning. Cases are going to get forgotten that way.
I'm still wondering about this as well.



Comment at: clang/lib/Sema/SemaStmt.cpp:545
+  if (!Context.getSourceManager().isInSystemHeader(IdentLoc)) {
+ReservedIdentifierStatus Status = TheDecl->isReserved(getLangOpts());
+if (Status != ReservedIdentifierStatus::NotReserved)

This check should be reversed as well.


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

https://reviews.llvm.org/D93095

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


[PATCH] D97362: [clang][parser] Allow attributes in explicit template instantiations

2021-03-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 334179.
tbaeder added a comment.

Added the changes from https://reviews.llvm.org/D99338 and 
https://reviews.llvm.org/D99278


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

https://reviews.llvm.org/D97362

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/cxx0x-attributes.cpp


Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -179,6 +179,7 @@
 struct [[]] Template t; // expected-error {{an attribute list cannot 
appear here}}
 struct [[]] ::template Template u; // expected-error {{an attribute list 
cannot appear here}}
 template struct [[]] Template; // expected-error {{an attribute list 
cannot appear here}}
+template struct __attribute__((pure)) Template; // We still allow 
GNU-style attributes here
 template <> struct [[]] Template;
 
 enum [[]] E1 {};
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1836,7 +1836,8 @@
 } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation 
&&
 TUK == Sema::TUK_Declaration) {
   // This is an explicit instantiation of a class template.
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+  /*DiagnoseEmptyAttrs=*/true);
 
   TagOrTempResult = Actions.ActOnExplicitInstantiation(
   getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
@@ -1932,7 +1933,8 @@
TemplateParams ? TemplateParams->size() : 0));
   } else {
 if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+  /* DiagnoseEmptyAttrs=*/true);
 
 if (TUK == Sema::TUK_Definition &&
 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1607,7 +1607,30 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
- unsigned DiagID) {
+ unsigned DiagID, bool DiagnoseEmptyAttrs) 
{
+
+  if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
+// An attribute list has been parsed, but it was empty.
+// This is the case for [[]].
+const auto &LangOpts = getLangOpts();
+auto &SM = PP.getSourceManager();
+Token FirstLSquare;
+Lexer::getRawToken(Attrs.Range.getBegin(), FirstLSquare, SM, LangOpts);
+
+if (FirstLSquare.is(tok::l_square)) {
+  llvm::Optional SecondLSquare =
+  Lexer::findNextToken(FirstLSquare.getLocation(), SM, LangOpts);
+
+  if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
+// The attribute range starts with [[, but is empty. So this must
+// be [[]], which we are supposed to diagnose because
+// DiagnoseEmptyAttrs is true.
+Diag(Attrs.Range.getBegin(), DiagID) << Attrs.Range;
+return;
+  }
+}
+  }
+
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
@@ -4630,7 +4653,8 @@
   // or opaque-enum-declaration anywhere.
   if (IsElaboratedTypeSpecifier && !getLangOpts().MicrosoftExt &&
   !getLangOpts().ObjC) {
-ProhibitAttributes(attrs);
+ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+/*DiagnoseEmptyAttrs=*/true);
 if (BaseType.isUsable())
   Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
   << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2639,7 +2639,8 @@
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
   void ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
-   unsigned DiagID);
+   unsigned DiagID,
+   bool DiagnoseEmptyAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -179,6 +179,7 @@
 struct [[]

[PATCH] D99278: [clang][parser] Allow GNU-style attributes in struct declarations

2021-03-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Abandoning in favor of https://reviews.llvm.org/D97362


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

https://reviews.llvm.org/D99278

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


[PATCH] D99338: [clang][parser] Allow GNU-style attributes in enum specifiers

2021-03-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Abandoning in favor of https://reviews.llvm.org/D97362


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

https://reviews.llvm.org/D99338

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


[PATCH] D99601: [-Wcompletion-handler] Don't recognize init methods as conventional

2021-03-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added a reviewer: NoQ.
Herald added a subscriber: Charusso.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://75704162


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99601

Files:
  clang/lib/Analysis/CalledOnceCheck.cpp
  clang/test/SemaObjC/warn-called-once.m


Index: clang/test/SemaObjC/warn-called-once.m
===
--- clang/test/SemaObjC/warn-called-once.m
+++ clang/test/SemaObjC/warn-called-once.m
@@ -13,6 +13,7 @@
 @protocol NSObject
 @end
 @interface NSObject 
+- (instancetype)init;
 - (id)copy;
 - (id)class;
 - autorelease;
@@ -1235,4 +1236,13 @@
   handler(); // expected-warning{{completion handler is called twice}}
 }
 
+- (void)initWithAdditions:(int)cond
+   withCompletion:(void (^)(void))handler {
+  self = [self init];
+  if (self) {
+escape(handler);
+  }
+  // no-warning
+}
+
 @end
Index: clang/lib/Analysis/CalledOnceCheck.cpp
===
--- clang/lib/Analysis/CalledOnceCheck.cpp
+++ clang/lib/Analysis/CalledOnceCheck.cpp
@@ -57,6 +57,7 @@
 "WithReplyTo", "WithReply"};
 constexpr llvm::StringLiteral CONVENTIONAL_CONDITIONS[] = {
 "error", "cancel", "shouldCall", "done", "OK", "success"};
+constexpr llvm::StringLiteral INIT_PREFIX = "init";
 
 struct KnownCalledOnceParameter {
   llvm::StringLiteral FunctionName;
@@ -1011,11 +1012,16 @@
 return llvm::None;
   }
 
+  /// Return true if the specified selector represents init method.
+  static bool isInitMethod(Selector MethodSelector) {
+return MethodSelector.getNameForSlot(0).startswith_lower(INIT_PREFIX);
+  }
+
   /// Return true if the specified selector piece matches conventions.
   static bool isConventionalSelectorPiece(Selector MethodSelector,
   unsigned PieceIndex,
   QualType PieceType) {
-if (!isConventional(PieceType)) {
+if (!isConventional(PieceType) || isInitMethod(MethodSelector)) {
   return false;
 }
 


Index: clang/test/SemaObjC/warn-called-once.m
===
--- clang/test/SemaObjC/warn-called-once.m
+++ clang/test/SemaObjC/warn-called-once.m
@@ -13,6 +13,7 @@
 @protocol NSObject
 @end
 @interface NSObject 
+- (instancetype)init;
 - (id)copy;
 - (id)class;
 - autorelease;
@@ -1235,4 +1236,13 @@
   handler(); // expected-warning{{completion handler is called twice}}
 }
 
+- (void)initWithAdditions:(int)cond
+   withCompletion:(void (^)(void))handler {
+  self = [self init];
+  if (self) {
+escape(handler);
+  }
+  // no-warning
+}
+
 @end
Index: clang/lib/Analysis/CalledOnceCheck.cpp
===
--- clang/lib/Analysis/CalledOnceCheck.cpp
+++ clang/lib/Analysis/CalledOnceCheck.cpp
@@ -57,6 +57,7 @@
 "WithReplyTo", "WithReply"};
 constexpr llvm::StringLiteral CONVENTIONAL_CONDITIONS[] = {
 "error", "cancel", "shouldCall", "done", "OK", "success"};
+constexpr llvm::StringLiteral INIT_PREFIX = "init";
 
 struct KnownCalledOnceParameter {
   llvm::StringLiteral FunctionName;
@@ -1011,11 +1012,16 @@
 return llvm::None;
   }
 
+  /// Return true if the specified selector represents init method.
+  static bool isInitMethod(Selector MethodSelector) {
+return MethodSelector.getNameForSlot(0).startswith_lower(INIT_PREFIX);
+  }
+
   /// Return true if the specified selector piece matches conventions.
   static bool isConventionalSelectorPiece(Selector MethodSelector,
   unsigned PieceIndex,
   QualType PieceType) {
-if (!isConventional(PieceType)) {
+if (!isConventional(PieceType) || isInitMethod(MethodSelector)) {
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99483: [clang][AIX] Define __STDC_NO_ATOMICS__ for c11 and above

2021-03-30 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:727
+// The AIX library implementation of C11 atomics is not yet complete.
+if (Opts.C11 || Opts.C17 || Opts.C2x) {
+  Builder.defineMacro("__STDC_NO_ATOMICS__");

Checking `Opts.C11` might be sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99483

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


[PATCH] D98237: [clang-format] Option for empty lines after an access modifier.

2021-03-30 Thread Max Sagebaum via Phabricator via cfe-commits
Max_S updated this revision to Diff 334186.
Max_S added a comment.

Cleanup of tests and additonal logic for modifiers at the end of a class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98237

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9179,6 +9179,555 @@
Style);
 }
 
+TEST_F(FormatTest, FormatsAfterAccessModifiers) {
+
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.EmptyLineAfterAccessModifier, FormatStyle::ELAAMS_Never);
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+
+  // Check if lines are removed
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "private:\n"
+   "\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+
+  Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always;
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+
+  // Check if lines are added
+  verifyFormat("struct foo {\n"
+   "private:\n"
+   "\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "\n"
+   "  int j;\n"
+   "};\n",
+   "struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style);
+
+  // Leave tests rely on the code layout, test::messUp can not be used.
+  Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Leave;
+  Style.MaxEmptyLinesToKeep = 0u;
+  EXPECT_EQ("struct foo {\n"
+"private:\n"
+"  void f() {}\n"
+"private:\n"
+"  int i;\n"
+"protected:\n"
+"  int j;\n"
+"};\n",
+format("struct foo {\n"
+   "private:\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "  int j;\n"
+   "};\n",
+   Style));
+
+  // Check if MaxEmptyLinesToKeep is adhered
+  EXPECT_EQ("struct foo {\n"
+"private:\n"
+"  void f() {}\n"
+"private:\n"
+"  int i;\n"
+"protected:\n"
+"  int j;\n"
+"};\n",
+format("struct foo {\n"
+   "private:\n"
+   "\n\n\n"
+   "  void f() {}\n"
+   "\n"
+   "private:\n"
+   "\n\n\n"
+   "  int i;\n"
+   "\n"
+   "protected:\n"
+   "\n\n\n"
+   "  int j;\n"
+   "};\n",
+   Style));
+
+  Style.MaxEmptyLinesToKeep = 1u;
+  EXPECT_EQ("struct foo {\n"
+"private:\n"
+"\n"
+"  void f() {}\n"
+"\n"
+"private:\n"
+"\n"
+"  int i;\n"
+"\n"
+"protected:\n"
+"\n"
+"  int j;\n"
+"};\n",
+format("struct foo {\n"
+   "private:\n"
+   "\n"
+   "  void f() {}\n"
+   "\n"
+   "priv

[PATCH] D99528: [RISCV][Clang] Add more RVV Integer intrinsic functions.

2021-03-30 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 334188.
khchen added a comment.

Create a common class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99528

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmseq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmslt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vmsne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vwmacc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmadc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmseq.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsgt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmslt.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vmsne.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vsbc.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vwmacc.c

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


[PATCH] D98657: [flang][driver] Add options for -Werror

2021-03-30 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I really like how you split your tests into two files:

- `werror_scan.f` captures warning generated by the prescanner
- `werror.f` captures warnings from the semantic analysis

In every case you added multiple RUN lines to make sure that the behavior is 
consistent across multiple actions. I think that that's very useful. Ideally, 
we'd have one central switch for turning warnings into errors and this would be 
unnecessary. But we're not there yet. In the meantime, could you add a comment 
explaining **why** multiple RUN lines are used?

I have 2 more suggestions:

- add yet another file for warnings from the parser
- rename `werror.f` as ``werror_sema.f`

These are non-blockers for me.




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:360
+res.SetWarnAsErr(true);
+  }
+}

AFAIK, no other option is allowed in `-W`. Perhaps throw a diagnostic 
here?



Comment at: flang/test/Driver/werror.f90:2
+! Ensure argument -Werror work as expected.
+! TODO: Modify test cases in test/Semantics/ related to f18 when -std= is 
upstreamed
+

[nit] This comment is not directly related to what's in this file (i.e. it 
doesn't really help understand it, does it)? I would remove it. Same in 
`werror_scan.f`.



Comment at: flang/test/Driver/werror.f90:4-6
+!--
+! FLANG DRIVER (flang-new)
+!--

DELETEME



Comment at: flang/test/Driver/werror_scan.f:5-7
+!--
+! FLANG DRIVER (flang-new)
+!--

DELETEME



Comment at: flang/test/Driver/werror_scan.f:9-11
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-

This is going to be either `flang-new -fc1` or `f18`. I think that we can start 
skipping this part of the comment to make it more generic.


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

https://reviews.llvm.org/D98657

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


[PATCH] D99426: [Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text

2021-03-30 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth added a comment.

I like the composability enabled by making `OF_Text` and `OF_CRLF` independent. 
 I wonder, though, if there's a chokepoint where we could/should assert if the 
caller uses `OF_CRLF` without `OF_Text`, which would be suspicious.

I'm not concerned by the number of files touched, since it's mostly a 
mechanical refactor.  If anyone's worried that the mechanical changes obscure 
the behavior change, this _could_ be broken into an NFC refactor patch for the 
renaming followed by a patch that implements the behavioral distinction.  But 
I'm not going to insist on that.




Comment at: llvm/include/llvm/Support/FileSystem.h:746
   /// The file should be opened in text mode on platforms that make this
   /// distinction.
   OF_Text = 1,

Don't be shy to give examples in the comments, as they can illuminate the 
motivation for the design.

```
... on platforms, like SystemZ, that distinguish between text and binary files.
```



Comment at: llvm/include/llvm/Support/FileSystem.h:757
+  /// OF_TextWithCRLF = OF_Text | OF_CRLF
+  OF_TextWithCRLF = 3,
+

Nit:  If it were me, I'd put the `OF_Text | OF_CRLF` directly in the code (in 
place of the `3`) instead of in the comment.



Comment at: llvm/lib/Support/Windows/Path.inc:1086
 
-  if (Flags & OF_Text)
+  if (Flags & OF_CRLF)
 CrtOpenFlags |= _O_TEXT;

I assume it would be weird to set `OF_CRLF` without also setting `OF_Text`, so 
this change seems right for correctness.  But maybe this Windows-only code 
would better express the intent if it were written:

```
if (Flags & (OF_CRLF | OF_Text))
```

Another idea would be to assert if `OF_CRLF` is set but `OF_Text` is not.

Or maybe it's fine as it is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99426

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


[PATCH] D99606: [clang][cli] Fix round-trip of OPT_plugin_arg

2021-03-30 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: jansvoboda11, dexonsmith, Bigcheese.
john.brawn requested review of this revision.
Herald added a project: clang.

The test Frontend/plugin-delayed-template.cpp is failing when asserts are 
enabled because it hits an assertion in denormalizeStringImpl when trying to 
round-trip OPT_plugin_arg. Fix this by adjusting how the option is handled, as 
the first part is joined to -plugin-arg and the second is separate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99606

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -211,6 +211,7 @@
   switch (OptClass) {
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
+  case Option::JoinedAndSeparateClass:
 Args.push_back(Spelling);
 Args.push_back(SA(Value));
 break;
@@ -2477,9 +2478,13 @@
 
   GenerateProgramAction();
 
-  for (const auto &PluginArgs : Opts.PluginArgs)
+  for (const auto &PluginArgs : Opts.PluginArgs) {
+Option Opt = getDriverOptTable().getOption(OPT_plugin_arg);
+const char *Spelling =
+SA(Opt.getPrefix() + Opt.getName() + PluginArgs.first);
 for (const auto &PluginArg : PluginArgs.second)
-  GenerateArg(Args, OPT_plugin_arg, PluginArgs.first + PluginArg, SA);
+  denormalizeString(Args, Spelling, SA, Opt.getKind(), 0, PluginArg);
+  }
 
   for (const auto &Ext : Opts.ModuleFileExtensions)
 if (auto *TestExt = dyn_cast_or_null(Ext.get()))


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -211,6 +211,7 @@
   switch (OptClass) {
   case Option::SeparateClass:
   case Option::JoinedOrSeparateClass:
+  case Option::JoinedAndSeparateClass:
 Args.push_back(Spelling);
 Args.push_back(SA(Value));
 break;
@@ -2477,9 +2478,13 @@
 
   GenerateProgramAction();
 
-  for (const auto &PluginArgs : Opts.PluginArgs)
+  for (const auto &PluginArgs : Opts.PluginArgs) {
+Option Opt = getDriverOptTable().getOption(OPT_plugin_arg);
+const char *Spelling =
+SA(Opt.getPrefix() + Opt.getName() + PluginArgs.first);
 for (const auto &PluginArg : PluginArgs.second)
-  GenerateArg(Args, OPT_plugin_arg, PluginArgs.first + PluginArg, SA);
+  denormalizeString(Args, Spelling, SA, Opt.getKind(), 0, PluginArg);
+  }
 
   for (const auto &Ext : Opts.ModuleFileExtensions)
 if (auto *TestExt = dyn_cast_or_null(Ext.get()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98237: [clang-format] Option for empty lines after an access modifier.

2021-03-30 Thread Max Sagebaum via Phabricator via cfe-commits
Max_S marked 9 inline comments as done.
Max_S added a comment.

In the last update I fixed now everything and changed the tests.

The tests use now verify format when possible. A bug here, kept me from doing 
it in a few places. I submitted a bug report for this: 
https://bugs.llvm.org/show_bug.cgi?id=49772

I hope this is now fine and can be merged into the master.




Comment at: clang/include/clang/Format/Format.h:1912
+/// Keep existing empty lines after access modifiers.
+/// MaxEmptyLinesToKeep is applied instead.
+ELAAMS_Leave,

curdeius wrote:
> Shouldn't we put the same comment in `ELBAMS_Leave`?
> That goes outside the scope of this patch if it ELBAMS doesn't behave this 
> way.
I submitted a bug report about this, since the behavior is different.

https://bugs.llvm.org/show_bug.cgi?id=49757


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98237

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


  1   2   3   >