[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D102015#2748441 , @efriedma wrote:

> In D102015#2743634 , @rjmccall 
> wrote:
>
>> Objective-C object types also have aggregate evaluation kind.  Those can 
>> only be used as value types in an old, fragile ObjC ABI, but I believe we 
>> haven't yet formally decided to remove support for that.  Fortunately, 
>> however, there's a much better simplification available: this 
>> `hasAggregateEvaluationKind(Ty)` call is literally doing nothing that 
>> couldn't just be a `getAs()` call, and then we don't need to 
>> worry about it.
>
> If you're confident that only RecordTypes need to be destroyed, sure.

Well, they're the only thing for which `isParamDestroyedInCallee()` is defined. 
 If we generalize that in the future, I think the code in your patch will be 
obvious enough how to modify.

In D102015#2748595 , @efriedma wrote:

> In D102015#2748441 , @efriedma 
> wrote:
>
>>> ...I'm confused about why this code is doing what it's doing with cleanups, 
>>> though.  Why does it only apply when the parameter is indirect?  I believe 
>>> `isParamDestroyedInCallee()` can apply to types that are passed in other 
>>> ways, so where we pushing the destructor for those, and why isn't it good 
>>> enough to handle this case as well?
>>
>> Objects with a non-trivial destructor end up indirect anyway under the 
>> normal ABI rules.  Not sure how it interacts with trivial_abi; I'll look 
>> into it.
>
> Figured it out.  "isIndirect()" here doesn't mean the same thing that it 
> means in ABIArgInfo.  If `hasScalarEvaluationKind(Ty)` is false, the caller 
> ensures the value is "isIndirect()", i.e. on the stack.  It doesn't matter if 
> the value was actually passed in registers.

Ugh.  Well, that's not great, but yeah, I agree we don't need to mess with that 
right now.  Thanks for checking it out.

In D102015#2749212 , @efriedma wrote:

>> Using _Atomic for C structs with non-trivially destructible fields currently 
>> doesn't work, so maybe that should just be disallowed.
>
> I'd prefer to disallow _Atomic on all types that aren't trivially 
> destructible, yes.  Not impossible to support, of course, but I don't really 
> see the value.

I agree that disallowing this is the right way to go.  There are non-trivial C 
structs that can support atomic operations easily enough, but the ones with ARC 
strong references specifically aren't among them.

I guess your test case is testing both the parameter and argument code.  The 
delegate-arg code should be testable with an override thunk with a big atomic 
parameter, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D101915: [clangd][remote-client] Set HasMore to true for failure

2021-05-10 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.

Good catch, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101915

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


[PATCH] D101914: [clangd][index-sever] Limit results in repsonse

2021-05-10 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.

Good point, thanks!

I wonder if this can somehow make the experience worse in _some_ specific cases 
but I can't think of anything on top of my mind, so this should be all good.




Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:152
+if (HasMore)
+  log("[public] Limiting result size for Lookup request.");
 LookupReply LastMessage;

nit (here and elsewhere): maybe add something like `(requested X, sending Y)` 
to the message for clarity. I don't expect this to be common anyway so probably 
verbosity isn't an issue here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101914

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


Re: [clang] e994e74 - [OpenCL] Add clang extension for non-portable kernel parameters.

2021-05-10 Thread Tom Stellard via cfe-commits

On 5/5/21 6:58 AM, Anastasia Stulova via cfe-commits wrote:


Author: Anastasia Stulova
Date: 2021-05-05T14:58:23+01:00
New Revision: e994e74bca49831eb649e7c67955e9de7a1784b6

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

LOG: [OpenCL] Add clang extension for non-portable kernel parameters.

Added __cl_clang_non_portable_kernel_param_types extension that
allows using non-portable types as kernel parameters. This allows
bypassing the portability guarantees from the restrictions specified
in C++ for OpenCL v1.0 s2.4.

Currently this only disables the restrictions related to the data
layout. The programmer should ensure the compiler generates the same
layout for host and device or otherwise the argument should only be
accessed on the device side. This extension could be extended to other
case (e.g. permitting size_t) if desired in the future.

Patch by olestrohm (Ole Strohm)!



Hi Anastasia,


This change broke the clang-sphinx-docs builder:

https://lab.llvm.org/buildbot/#/builders/92/builds/9110

-Tom


https://reviews.llvm.org/D101168

Added:
 


Modified:
 clang/docs/LanguageExtensions.rst
 clang/include/clang/Basic/OpenCLExtensions.def
 clang/lib/Basic/Targets/AMDGPU.h
 clang/lib/Basic/Targets/NVPTX.h
 clang/lib/Sema/SemaDecl.cpp
 clang/test/Misc/amdgcn.languageOptsOpenCL.cl
 clang/test/Misc/nvptx.languageOptsOpenCL.cl
 clang/test/Misc/r600.languageOptsOpenCL.cl
 clang/test/SemaOpenCLCXX/invalid-kernel.clcpp

Removed:
 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 5e5382879e0c8..bdb5b3adf39fb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1813,6 +1813,54 @@ supporting the variadic arguments e.g. majority of CPU 
targets.
#pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
void bar(int a, ...); // error - variadic prototype is not allowed
  
+``__cl_clang_non_portable_kernel_param_types``

+-
+
+With this extension it is possible to enable the use of some restricted types
+in kernel parameters specified in `C++ for OpenCL v1.0 s2.4
+`_.
+The restrictions can be relaxed using regular OpenCL extension pragma mechanism
+detailed in `the OpenCL Extension Specification, section 1.2
+`_.
+
+This is not a conformant behavior and it can only be used when the
+kernel arguments are not accessed on the host side or the data layout/size
+between the host and device is known to be compatible.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  // Plain Old Data type.
+  struct Pod {
+int a;
+int b;
+  };
+
+  // Not POD type because of the constructor.
+  // Standard layout type because there is only one access control.
+  struct OnlySL {
+int a;
+int b;
+NotPod() : a(0), b(0) {}
+  };
+
+  // Not standard layout type because of two
diff erent access controls.
+  struct NotSL {
+int a;
+  private:
+int b;
+  }
+
+  kernel void kernel_main(
+Pod a,
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
+OnlySL b,
+global NotSL *c,
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
+global OnlySL *d,
+  );
+
  Legacy 1.x atomics with generic address space
  -
  


diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 5e2977f478f3a..a0f01a2af9c37 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -87,6 +87,7 @@ OPENCL_EXTENSION(cl_khr_subgroups, true, 200)
  OPENCL_EXTENSION(cl_clang_storage_class_specifiers, true, 100)
  OPENCL_EXTENSION(__cl_clang_function_pointers, true, 100)
  OPENCL_EXTENSION(__cl_clang_variadic_functions, true, 100)
+OPENCL_EXTENSION(__cl_clang_non_portable_kernel_param_types, true, 100)
  
  // AMD OpenCL extensions

  OPENCL_EXTENSION(cl_amd_media_ops, true, 100)

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 8ee0ca30d305d..b2d422ce0bbe9 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -287,6 +287,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
  Opts["cl_clang_storage_class_specifiers"] = true;
  Opts["__cl_clang_variadic_functions"] = true;
  Opts["__cl_clang_function_pointers"] = true;
+Opts["__cl_clang_non_portable_kernel_param_types"] = true;
  
  bool IsAMDGCN = isAMDGCN(getTriple());
  


diff  --git 

[PATCH] D101735: [WebAssembly] Reenable end-to-end test in wasm-eh.cpp

2021-05-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D101735#2749716 , @aheejin wrote:

> @dblaikie I can remove this one. This is not an important test anyway. But 
> where are we supposed to test the arguments clang driver invokes the backend 
> LLVM compilation with? This was mainly to test if `-exception-model=wasm` 
> reaches the backend compilation.

Ah, and that flag is passed down through MCOptions or something like that 
(something purely in the programmatic API, not serialized into IR)? Fair enough 
- this is one of the exceptions to the "no end to end testing" rule - if it's 
the only way to demonstrate that the relevant MCOption was configured 
correctly, end-to-end testing is the best we've got there.

Thanks for the details!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101735

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


[PATCH] D101735: [WebAssembly] Reenable end-to-end test in wasm-eh.cpp

2021-05-10 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

@dblaikie I can remove this one. This is not an important test anyway. But 
where are we supposed to test the arguments clang driver invokes the backend 
LLVM compilation with? This was mainly to test if `-exception-model=wasm` 
reaches the backend compilation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101735

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


[PATCH] D102159: [index][analyzer][ctu] Eliminate white spaces in the CTU lookup name.

2021-05-10 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added a comment.

In D102159#2749033 , @akyrtzi wrote:

> Maybe we could also handle this kind of type instead of leaving it 
> 'unhandled'? What `Type` is it?

The member function pointer type, see the test case.

Although it would be perfect to handle this kind of type, I mean the white 
spaces should still be removed from the USR.
Currently, the white space character is used as the separator between the index 
string and the file path in the output of `clang-extdef-mapping`.
And it is difficult to determine when the index string with white space 
characters ends when parsing the output of `clang-extdef-mapping`.
Therefore, IMO the white space character had better not be used in the index 
string.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102159

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


[PATCH] D101790: [clang-tidy] Aliasing: Add support for passing the variable into a function by reference.

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 344283.
NoQ added a comment.

Rebase on top of D102214  (that patch will 
probably land sooner than this patch and there are test conflicts).


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

https://reviews.llvm.org/D101790

Files:
  clang-tools-extra/clang-tidy/utils/Aliasing.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -968,12 +968,29 @@
   }
   if (tryToExtinguish(onFire) && onFire) {
 if (tryToExtinguishByVal(onFire) && onFire) {
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
+  // NO-MESSAGE: technically tryToExtinguish() may launch
+  // a background thread to extinguish the fire while tryToExtinguishByVal()
+  // may be waiting for that thread to finish.
   scream();
 }
   }
 }
 
+bool _reference(bool ) {
+  return flag;
+}
+
+void test_hidden_reference() {
+  bool onFire = isBurning();
+  bool onFireRef = hidden_reference(onFire);
+  if (onFire) {
+onFireRef = false;
+if (onFire) {
+  // NO-MESSAGE: fire was extinguished by the above assignment
+}
+  }
+}
+
 void negative_reassigned() {
   bool onFire = isBurning();
   if (onFire) {
@@ -993,11 +1010,9 @@
   bool onFire = isBurning();
   if (onFire) {
 if (onFire) {
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
-  // CHECK-FIXES: {{^\ *$}}
+  // FIXME: This should warn.
   scream();
 }
-// CHECK-FIXES: {{^\ *$}}
 tryToExtinguish(onFire);
   }
 }
@@ -1007,11 +1022,9 @@
   if (onFire) {
 if (someOtherCondition()) {
   if (onFire) {
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
-// CHECK-FIXES: {{^\ *$}}
+// FIXME: This should warn.
 scream();
   }
-  // CHECK-FIXES: {{^\ *$}}
 }
 tryToExtinguish(onFire);
   }
@@ -1022,11 +1035,9 @@
   if (onFire) {
 if (someOtherCondition()) {
   if (onFire) {
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
-// CHECK-FIXES: {{^\ *$}}
+// FIXME: This should warn.
 scream();
   }
-  // CHECK-FIXES: {{^\ *$}}
   tryToExtinguish(onFire);
 }
   }
@@ -1036,8 +1047,7 @@
   bool onFire = isBurning();
   if (onFire) {
 if (onFire) {
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
-  // CHECK-FIXES: {{^\ *$}}
+  // FIXME: This should warn.
   tryToExtinguish(onFire);
   scream();
 }
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
@@ -3,6 +3,7 @@
 @interface I
 -(void) instanceMethod;
 +(void) classMethod;
++(int &) hiddenReferenceTo: (int &)x;
 @end
 
 void plainCFunction() {
@@ -14,6 +15,15 @@
   }
 }
 
+void testHiddenReference() {
+  int i = 0;
+  int  = [I hiddenReferenceTo: i];
+  while (i < 10) {
+// No warning. 'j' is a reference to 'i'.
+j++;
+  }
+}
+
 @implementation I
 - (void)instanceMethod {
   int i = 0;
@@ -32,4 +42,8 @@
 j++;
   }
 }
+
++(int &) hiddenReferenceTo: (int &) x {
+  return x;
+}
 @end
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -591,3 +591,28 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (x) are updated in the loop body [bugprone-infinite-loop]
   }
 }
+
+int _reference(int ) {
+  return x;
+}
+
+void test_hidden_reference() {
+  int x = 0;
+  int  = hidden_reference(x);
+  for (; x < 10; ++y) {
+// No warning. The loop is finite because 'y' is a reference to 'x'.
+  }
+}
+
+struct HiddenReference {
+  int 
+  HiddenReference(int ) : y(x) {}
+};
+
+void test_HiddenReference() {
+  int x = 0;
+  int  = HiddenReference(x).y;
+  for (; x < 10; ++y) {
+// No warning. The loop is finite because 'y' is 

[PATCH] D102214: [clang-tidy] bugprone-infinite-loop: forFunction() -> forCallable().

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: alexfh, gribozavr2, aaron.ballman, stephenkelly, 
xazax.hun, vsavchenko.
Herald added subscribers: martong, mgehre, rnkovacs.
NoQ requested review of this revision.
Herald added a project: clang-tools-extra.

This patch takes advantage of the new ASTMatcher added in D102213 
 to fix massive false negatives of the 
infinite loop checker on Objective-C.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D102214

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/clang-tidy/utils/Aliasing.cpp
  clang-tools-extra/clang-tidy/utils/Aliasing.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.mm
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fblocks
+
+@interface I
+-(void) instanceMethod;
++(void) classMethod;
+@end
+
+void plainCFunction() {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+j++;
+  }
+}
+
+@implementation I
+- (void)instanceMethod {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+j++;
+  }
+}
+
++ (void)classMethod {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+j++;
+  }
+}
+@end
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -511,8 +511,7 @@
   bool finished = false;
   auto block = ^() {
 while (!finished) {
-  // FIXME: This should warn. It currently reacts to 
-  // outside the block which ideally shouldn't have any effect.
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none of its condition variables (finished) are updated in the loop body [bugprone-infinite-loop]
   wait();
 }
   };
Index: clang-tools-extra/clang-tidy/utils/Aliasing.h
===
--- clang-tools-extra/clang-tidy/utils/Aliasing.h
+++ clang-tools-extra/clang-tidy/utils/Aliasing.h
@@ -27,7 +27,7 @@
 /// For `f()` and `n` the function returns ``true`` because `p` is a
 /// pointer to `n` created in `f()`.
 
-bool hasPtrOrReferenceInFunc(const FunctionDecl *Func, const VarDecl *Var);
+bool hasPtrOrReferenceInFunc(const Decl *Func, const VarDecl *Var);
 
 } // namespace utils
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/utils/Aliasing.cpp
===
--- clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -78,7 +78,7 @@
   return false;
 }
 
-static bool refersToEnclosingLambdaCaptureByRef(const FunctionDecl *Func,
+static bool refersToEnclosingLambdaCaptureByRef(const Decl *Func,
 const VarDecl *Var) {
   const auto *MD = dyn_cast(Func);
   if (!MD)
@@ -91,7 +91,7 @@
   return capturesByRef(RD, Var);
 }
 
-bool hasPtrOrReferenceInFunc(const FunctionDecl *Func, const VarDecl *Var) {
+bool hasPtrOrReferenceInFunc(const Decl *Func, const VarDecl *Var) {
   return hasPtrOrReferenceInStmt(Func->getBody(), Var) ||
  refersToEnclosingLambdaCaptureByRef(Func, Var);
 }
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -21,6 +21,7 @@
 
 static internal::Matcher
 loopEndingStmt(internal::Matcher Internal) {
+  // FIXME: Cover noreturn ObjC methods (and blocks?).
   return stmt(anyOf(
   mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
   callExpr(Internal, callee(functionDecl(isNoReturn());
@@ -43,9 +44,8 @@
 }
 
 /// Return whether `Cond` is a variable that is possibly changed in `LoopStmt`.
-static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
-   const Stmt *LoopStmt, const Stmt *Cond,
-   ASTContext *Context) {

[PATCH] D102213: [ASTMatchers] Add forCallable(), a generalization of forFunction().

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: alexfh, gribozavr2, aaron.ballman, stephenkelly, 
xazax.hun, vsavchenko.
Herald added subscribers: martong, rnkovacs.
NoQ requested review of this revision.

It additionally covers Objective-C methods and blocks that don't inherit from 
`FunctionDecl`.

I'm open to suggestions here. For instance, it might make sense to have three 
different matchers instead (`forFunction()`, `forBlock()`, `forObjCMethod()`) 
and `anyOf()` them. I don't think it's practical though; most of the time you 
want any callable and if you don't you can always narrow it down with 
`forCallable(functionDecl())` or something like that. I guess it might make 
sense to implement both approaches.

I'm also open to suggestions with respect to the very fact that such matchers 
exist in the first place. From existing use cases it looks to me that most of 
the time (including my use case) they're used to avoid the problem with 
`hasDescendant()` (and similar matchers) digging into nested declarations (eg., 
inspecting the body of a lambda within a function when you only want it to 
inspect the function itself). I would be totally satisfied with a better 
alternative for `hasDescendant()` instead - that only traverses statements; 
that'd probably be faster as well as more precise and concise. @stephenkelly, 
IIRC you've voiced some strong opinions on this subject on the mailing list.


Repository:
  rC Clang

https://reviews.llvm.org/D102213

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5524,6 +5524,47 @@
   EXPECT_TRUE(notMatches(CppString2, returnStmt(forFunction(hasName("F");
 }
 
+TEST(StatementMatcher, ForCallable) {
+  StringRef ObjCString1 = "@interface I"
+  "-(void) foo;"
+  "@end"
+  "@implementation I"
+  "-(void) foo {"
+  "  void (^block)() = ^{ 0x2b | ~0x2b; };"
+  "}"
+  "@end";
+
+  EXPECT_TRUE(
+matchesObjC(
+  ObjCString1,
+  binaryOperator(forCallable(blockDecl();
+
+  EXPECT_TRUE(
+notMatchesObjC(
+  ObjCString1,
+  binaryOperator(forCallable(objcMethodDecl();
+
+  StringRef ObjCString2 = "@interface I"
+  "-(void) foo;"
+  "@end"
+  "@implementation I"
+  "-(void) foo {"
+  "  0x2b | ~0x2b;"
+  "  void (^block)() = ^{};"
+  "}"
+  "@end";
+
+  EXPECT_TRUE(
+matchesObjC(
+  ObjCString2,
+  binaryOperator(forCallable(objcMethodDecl();
+
+  EXPECT_TRUE(
+notMatchesObjC(
+  ObjCString2,
+  binaryOperator(forCallable(blockDecl();
+}
+
 TEST(Matcher, ForEachOverriden) {
   const auto ForEachOverriddenInClass = [](const char *ClassName) {
 return cxxMethodDecl(ofClass(hasName(ClassName)), isVirtual(),
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7543,7 +7543,7 @@
   });
 }
 
-/// Matches declaration of the function the statement belongs to
+/// Matches declaration of the function the statement belongs to.
 ///
 /// Given:
 /// \code
@@ -7559,21 +7559,67 @@
   InnerMatcher) {
   const auto  = Finder->getASTContext().getParents(Node);
 
+  llvm::SmallVector Stack(Parents.begin(), Parents.end());
+  while (!Stack.empty()) {
+const auto  = Stack.back();
+Stack.pop_back();
+if (const auto *FuncDeclNode = CurNode.get()) {
+  if (InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) {
+return true;
+  }
+} else if (const auto *LambdaExprNode = CurNode.get()) {
+  if (InnerMatcher.matches(*LambdaExprNode->getCallOperator(), Finder,
+   Builder)) {
+return true;
+  }
+} else {
+  for (const auto  : Finder->getASTContext().getParents(CurNode))
+Stack.push_back(Parent);
+}
+  }
+  return false;
+}
+
+/// Matches declaration of the function, method, or block
+/// the statement belongs to. Similar to 'forFunction' but additionally covers
+/// Objective-C methods and blocks.
+///
+/// Given:
+/// \code
+/// -(void) foo {
+///   int x = 1;
+///   dispatch_sync(queue, ^{ int y = 2; });
+/// }
+/// \endcode
+/// declStmt(forCallable(objcMethodDecl()))
+///   matches 'int x = 1'
+///   but does not match 'int y = 2'.

[PATCH] D96215: [clang-tidy] Aliasing: Add support for lambda captures.

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/Aliasing.cpp:45-48
+return llvm::any_of(LE->captures(), [Var](const LambdaCapture ) {
+  return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
+ C.getCapturedVar() == Var;
+});

aaron.ballman wrote:
> NoQ wrote:
> > aaron.ballman wrote:
> > > Should this use `capturesByRef()` from https://reviews.llvm.org/D101787?
> > Yes and https://reviews.llvm.org/D101787 already converts this code to use 
> > `capturesByRef()` as soon as it introduces it!
> Ah! It wasn't clear to me that's how this patch was stacking up, thanks for 
> the explanation.
I've been using the phabricator's parent/child revisions feature (aka the Stack 
tab). I guess i should pronounce such relations out loud because it's not super 
apparent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96215

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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

Generally-speaking, we have a plan that I'm happy for us to work towards, and 
I'm happy for our progress towards that plan to be incremental. Even though 
this might not be fully in that direction right now, I think that's OK.


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

https://reviews.llvm.org/D96033

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


[PATCH] D102147: [Clang][Coroutines] Implement P2014R0 Option 1 behind -fcoroutines-aligned-alloc

2021-05-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D102147#2747939 , @ychen wrote:

> In D102147#2747611 , @ChuanqiXu 
> wrote:
>
>> Since D97915  would fix the problem that 
>> the variables in the frame may not be aligned, I think this option 
>> `fcoroutines-aligned-alloc` won't affect normal programmers other than 
>> language lawyers. Do you think so?
>
> I think that's right that if all a user want is alignment, then 
> `fcoroutines-aligned-alloc` may not be necessary. However if they define 
> customed aligned allocators/dealllocators, this is needed to make it work.

I see. The overall idea looks good. I would try to look into the details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102147

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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:226-235
+  if (PP.getLangOpts().DelayedTemplateParsing) {
+// Microsoft-specific:
+// Late parsed templates can leave unswallowed "macro"-like tokens.
+// They will seriously confuse the Parser when entering the next
+// source file. So lex until we are EOF.
+Token Tok;
+do {

What are these tokens, exactly? Are we sure it's safe to discard them rather 
than parsing them?


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

https://reviews.llvm.org/D96033

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


[PATCH] D102070: [AIX][TLS] Diagnose use of unimplemented TLS models

2021-05-10 Thread Victor Huang via Phabricator via cfe-commits
NeHuang updated this revision to Diff 344258.
NeHuang added a comment.

Address review comment for the diagnostic message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102070

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/aix-tls-model.cpp
  clang/test/Sema/aix-attr-tls_model.c

Index: clang/test/Sema/aix-attr-tls_model.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-tls_model.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-cpu pwr8 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-cpu pwr8 -verify -fsyntax-only %s
+
+#if !__has_attribute(tls_model)
+#error "Should support tls_model attribute"
+#endif
+
+static __thread int y __attribute((tls_model("global-dynamic"))); // no-warning
+static __thread int y __attribute((tls_model("local-dynamic"))); // expected-error {{TLS model 'local-dynamic' is not yet supported on AIX}}
+static __thread int y __attribute((tls_model("initial-exec"))); // expected-error {{TLS model 'initial-exec' is not yet supported on AIX}}
+static __thread int y __attribute((tls_model("local-exec"))); // expected-error {{TLS model 'local-exec' is not yet supported on AIX}}
Index: clang/test/CodeGen/aix-tls-model.cpp
===
--- /dev/null
+++ clang/test/CodeGen/aix-tls-model.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
+// RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
+// RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-LD-ERROR
+// RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s -check-prefix=CHECK-IE-ERROR
+// RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -ftls-model=local-exec -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-LE-ERROR
+// RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
+// RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 -ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
+// RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 -ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-LD-ERROR
+// RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 -ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s -check-prefix=CHECK-IE-ERROR
+// RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 -ftls-model=local-exec -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-LE-ERROR
+
+int z1 = 0;
+int z2;
+int __thread x;
+int f() {
+  static int __thread y;
+  return y++;
+}
+
+// CHECK-GD: @z1 ={{.*}} global i32 0
+// CHECK-GD: @z2 ={{.*}} global i32 0
+// CHECK-GD: @x ={{.*}} thread_local global i32 0
+// CHECK-GD: @_ZZ1fvE1y = internal thread_local global i32 0
+// CHECK-LD-ERROR:  error: TLS model 'local-dynamic' is not yet supported on AIX
+// CHECK-IE-ERROR:  error: TLS model 'initial-exec' is not yet supported on AIX
+// CHECK-LE-ERROR:  error: TLS model 'local-exec' is not yet supported on AIX
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1935,6 +1935,12 @@
 return;
   }
 
+  if (S.Context.getTargetInfo().getTriple().isOSAIX() &&
+  Model != "global-dynamic") {
+S.Diag(LiteralLoc, diag::err_aix_attr_unsupported_tls_model) << Model;
+return;
+  }
+
   D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model));
 }
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1808,6 +1808,14 @@
 Opts.ExplicitEmulatedTLS = true;
   }
 
+  if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
+if (T.isOSAIX()) {
+  StringRef Name = A->getValue();
+  if (Name != "global-dynamic")
+Diags.Report(diag::err_aix_unsupported_tls_model) << Name;
+}
+  }
+
   if (Arg *A = Args.getLastArg(OPT_fdenormal_fp_math_EQ)) {
 StringRef Val = A->getValue();
 Opts.FPDenormalMode = llvm::parseDenormalFPAttribute(Val);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- 

[PATCH] D102090: [CMake][ELF] Add -fno-semantic-interposition and -Bsymbolic-functions

2021-05-10 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

+1 to the idea, but I have no idea if this is the right cmake spot

If we've decided to actually care about the shared library build, should we 
also consider using `-fvisibility-inlines-hidden`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102090

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


[PATCH] D101876: [clang] Support -fpic -fno-semantic-interposition for RISCV

2021-05-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 344234.
MaskRay added a comment.

rebase after aarch64 support


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101876

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fsemantic-interposition.c


Index: clang/test/Driver/fsemantic-interposition.c
===
--- clang/test/Driver/fsemantic-interposition.c
+++ clang/test/Driver/fsemantic-interposition.c
@@ -11,6 +11,8 @@
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
 // RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target riscv32 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
@@ -22,7 +24,6 @@
 /// optimizations are allowed but local aliases are not used. If references are
 /// not optimized out, semantic interposition at runtime is possible.
 // RUN: %clang -target ppc64le %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
-// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
 
 // RUN: %clang -target x86_64 %s -Werror -fPIC -c -### 2>&1 | FileCheck 
--check-prefix=HALF %s
 //
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4722,7 +4722,8 @@
  options::OPT_fno_semantic_interposition);
 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
   // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-  bool SupportsLocalAlias = Triple.isAArch64() || Triple.isX86();
+  bool SupportsLocalAlias =
+  Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
   if (!A)
 CmdArgs.push_back("-fhalf-no-semantic-interposition");
   else if (A->getOption().matches(options::OPT_fsemantic_interposition))


Index: clang/test/Driver/fsemantic-interposition.c
===
--- clang/test/Driver/fsemantic-interposition.c
+++ clang/test/Driver/fsemantic-interposition.c
@@ -11,6 +11,8 @@
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
 // RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target riscv32 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
@@ -22,7 +24,6 @@
 /// optimizations are allowed but local aliases are not used. If references are
 /// not optimized out, semantic interposition at runtime is possible.
 // RUN: %clang -target ppc64le %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=HALF %s
-// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=HALF %s
 
 // RUN: %clang -target x86_64 %s -Werror -fPIC -c -### 2>&1 | FileCheck --check-prefix=HALF %s
 //
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4722,7 +4722,8 @@
  options::OPT_fno_semantic_interposition);
 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
   // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-  bool SupportsLocalAlias = Triple.isAArch64() || Triple.isX86();
+  bool SupportsLocalAlias =
+  Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
   if (!A)
 CmdArgs.push_back("-fhalf-no-semantic-interposition");
   else if (A->getOption().matches(options::OPT_fsemantic_interposition))
___
cfe-commits mailing list

[PATCH] D102185: Widen `name` stencil to support `TypeLoc` nodes.

2021-05-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a reviewer: ymandel.
steveire added a comment.

Adding Yitzhak as a reviewer. I notice that at least the name of a 
cxxBaseSpecifier is not supported and I don't know if that (or lack of typeloc 
support) is desired in the Transformer design.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102185

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


[PATCH] D101667: Modules: Remove ModuleLoader::OtherUncachedFailure, NFC

2021-05-10 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Ping! Happy to weaken the commit message to "likely NFC" in case there's some 
way that we get back here after a fatal error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101667

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


[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> Using _Atomic for C structs with non-trivially destructible fields currently 
> doesn't work, so maybe that should just be disallowed.

I'd prefer to disallow _Atomic on all types that aren't trivially destructible, 
yes.  Not impossible to support, of course, but I don't really see the value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D95745: Support unwinding from inline assembly

2021-05-10 Thread Amanieu d'Antras via Phabricator via cfe-commits
Amanieu accepted this revision.
Amanieu added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95745

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


[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Using `_Atomic` for C structs with non-trivially destructible fields currently 
doesn't work, so maybe that should just be disallowed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

C structs with ObjC pointer fields under ARC are non-trivial to destruct too.

  struct foo {
int big[128];
id a;
  };
  
  void test_atomic_array_param(_Atomic(struct foo) a) {
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D101876: [clang] Support -fpic -fno-semantic-interposition for RISCV

2021-05-10 Thread Luís Marques via Phabricator via cfe-commits
luismarques accepted this revision.
luismarques added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101876

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


[PATCH] D100388: [BROKEN][clang] Try to fix thunk function types

2021-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Made a couple suggestions to make this easier to review.

The test changes you've made so far seem reasonable.

Is there some specific section of the code you want feedback on?




Comment at: clang/include/clang/Basic/Thunk.h:1
+//===- Thunk.h - Declarations related to VTable Thunks --*- C++ 
-*-===//
+//

Can you split the new Thunk.h, and the minimal set of changes required to use 
it, into a separate NFC patch?



Comment at: clang/lib/CodeGen/CGVTables.cpp:750
   case VTableComponent::CK_DeletingDtorPointer: {
-GlobalDecl GD;
-
-// Get the right global decl.
-switch (component.getKind()) {
-default:
-  llvm_unreachable("Unexpected vtable component kind");
-case VTableComponent::CK_FunctionPointer:
-  GD = component.getFunctionDecl();
-  break;
-case VTableComponent::CK_CompleteDtorPointer:
-  GD = GlobalDecl(component.getDestructorDecl(), Dtor_Complete);
-  break;
-case VTableComponent::CK_DeletingDtorPointer:
-  GD = GlobalDecl(component.getDestructorDecl(), Dtor_Deleting);
-  break;
-}
+GlobalDecl GD = component.getGlobalDecl();
 

Can land this separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100388

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-10 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

bumping for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D101735: [WebAssembly] Reenable end-to-end test in wasm-eh.cpp

2021-05-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

FWIW - please avoid end-to-end tests where possible (writing separate source to 
LLVM IR (in clang) and LLVM IR to assembly (in LLVM) tests). (recent 
discussions on the wasm simd instructions touched on this issue too)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101735

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


[PATCH] D100388: [BROKEN][clang] Try to fix thunk function types

2021-05-10 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a subscriber: efriedma.
lebedev.ri added a comment.

ping @rsmith / @efriedma - if there are any further thoughts on the problem, i 
would love to hear them


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100388

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


[clang-tools-extra] 1746068 - Clangd Matchers.h: Fix -Wdeprecated-copy by making the defaulted copy ctor and deleted copy assignment operators explicit

2021-05-10 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-05-10T14:31:11-07:00
New Revision: 174606877df46f3e8ce0c60a4c744687d3ee3271

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

LOG: Clangd Matchers.h: Fix -Wdeprecated-copy by making the defaulted copy ctor 
and deleted copy assignment operators explicit

Added: 


Modified: 
clang-tools-extra/clangd/unittests/Matchers.h

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/Matchers.h 
b/clang-tools-extra/clangd/unittests/Matchers.h
index d477cf75e7239..2bd915d83a7a1 100644
--- a/clang-tools-extra/clangd/unittests/Matchers.h
+++ b/clang-tools-extra/clangd/unittests/Matchers.h
@@ -132,6 +132,8 @@ PolySubsequenceMatcher HasSubsequence(Args &&... 
M) {
 template  class OptionalMatcher {
 public:
   explicit OptionalMatcher(const InnerMatcher ) : matcher_(matcher) {}
+  OptionalMatcher(const OptionalMatcher&) = default;
+  OptionalMatcher =(const OptionalMatcher&) = delete;
 
   // This type conversion operator template allows Optional(m) to be
   // used as a matcher for any Optional type whose value type is
@@ -155,6 +157,9 @@ template  class OptionalMatcher {
 explicit Impl(const InnerMatcher )
 : matcher_(::testing::MatcherCast(matcher)) {}
 
+Impl(const Impl&) = default;
+Impl =(const Impl&) = delete;
+
 virtual void DescribeTo(::std::ostream *os) const {
   *os << "has a value that ";
   matcher_.DescribeTo(os);
@@ -177,13 +182,9 @@ template  class OptionalMatcher {
 
   private:
 const Matcher matcher_;
-
-GTEST_DISALLOW_ASSIGN_(Impl);
   };
 
   const InnerMatcher matcher_;
-
-  GTEST_DISALLOW_ASSIGN_(OptionalMatcher);
 };
 
 // Creates a matcher that matches an Optional that has a value



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


[PATCH] D102159: [index][analyzer][ctu] Eliminate white spaces in the CTU lookup name.

2021-05-10 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Maybe we could also handle this kind of type instead of leaving it 'unhandled'? 
What `Type` is it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102159

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


[PATCH] D102196: [NewPM] Add options to PrintPassInstrumentation

2021-05-10 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 344201.
aeubanks added a comment.

assert Indent >= 0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102196

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Driver/debug-pass-structure.c
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/new-pass-manager-cgscc-fct-proxy.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/pass-pipeline-parsing.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -52,9 +52,17 @@
cl::value_desc("filename"));
 } // namespace llvm
 
-static cl::opt
-DebugPM("debug-pass-manager", cl::Hidden,
-cl::desc("Print pass management debugging information"));
+enum class DebugLogging { None, Normal, Verbose };
+
+static cl::opt DebugPM(
+"debug-pass-manager", cl::Hidden, cl::ValueOptional,
+cl::desc("Print pass management debugging information"),
+cl::init(DebugLogging::None),
+cl::values(
+clEnumValN(DebugLogging::Normal, "", ""),
+clEnumValN(
+DebugLogging::Verbose, "verbose",
+"Print extra information about adaptors and pass managers")));
 
 static cl::list
 PassPlugins("load-pass-plugin",
@@ -283,7 +291,10 @@
   ModuleAnalysisManager MAM;
 
   PassInstrumentationCallbacks PIC;
-  StandardInstrumentations SI(DebugPM, VerifyEachPass);
+  PrintPassOptions PrintPassOpts;
+  PrintPassOpts.Verbose = DebugPM == DebugLogging::Verbose;
+  StandardInstrumentations SI(DebugPM != DebugLogging::None, VerifyEachPass,
+  PrintPassOpts);
   SI.registerCallbacks(PIC, );
   DebugifyEachInstrumentation Debugify;
   if (DebugifyEach)
Index: llvm/test/Other/pass-pipeline-parsing.ll
===
--- llvm/test/Other/pass-pipeline-parsing.ll
+++ llvm/test/Other/pass-pipeline-parsing.ll
@@ -142,7 +142,7 @@
 ; RUN: | FileCheck %s --check-prefix=CHECK-NESTED-FP-LP
 ; CHECK-NESTED-FP-LP: Running pass: NoOpLoopPass
 
-; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
+; RUN: opt -disable-output -debug-pass-manager=verbose \
 ; RUN: -passes='module(no-op-function,no-op-loop,no-op-cgscc,cgscc(no-op-function,no-op-loop),function(no-op-loop))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-ADAPTORS
 ; CHECK-ADAPTORS: Running pass: ModuleToFunctionPassAdaptor
@@ -167,7 +167,7 @@
 ; RUN: opt -disable-output -debug-pass-manager \
 ; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS-NO-VERBOSE
-; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
+; RUN: opt -disable-output -debug-pass-manager=verbose \
 ; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS
 ; CHECK-MANAGERS: Running pass: PassManager{{.*}}Function
Index: llvm/test/Other/opt-O3-pipeline.ll
===
--- llvm/test/Other/opt-O3-pipeline.ll
+++ llvm/test/Other/opt-O3-pipeline.ll
@@ -1,5 +1,4 @@
 ; RUN: opt -enable-new-pm=0 -mtriple=x86_64-- -O3 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK,%llvmcheckext %s
-; RUN: opt -enable-new-pm=1 -mtriple=x86_64-- -O3 -debug-pass-structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=NEWPM,%llvmcheckext %s
 
 ; REQUIRES: asserts
 
@@ -336,169 +335,6 @@
 ; CHECK-NEXT: Branch Probability Analysis
 ; CHECK-NEXT: Block Frequency Analysis
 
-; NEWPM:  VerifierPass on [module]
-; NEWPM-NEXT:   VerifierAnalysis analysis on [module]
-; NEWPM-NEXT: Annotation2MetadataPass on [module]
-; NEWPM-NEXT: ForceFunctionAttrsPass on [module]
-; NEWPM-NEXT: InferFunctionAttrsPass on [module]
-; NEWPM-NEXT:   InnerAnalysisManagerProxy<{{.*}}> analysis on [module]
-; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
-; NEWPM-NEXT:   PassManager<{{.*}}> on f
-; NEWPM-NEXT: PreservedCFGCheckerAnalysis analysis on f
-; NEWPM-NEXT: LowerExpectIntrinsicPass on f
-; NEWPM-NEXT: SimplifyCFGPass on f
-; NEWPM-NEXT:   TargetIRAnalysis analysis on f
-; NEWPM-NEXT:   AssumptionAnalysis analysis on f
-; NEWPM-NEXT: SROA on f
-; NEWPM-NEXT:   DominatorTreeAnalysis analysis on f
-; NEWPM-NEXT: EarlyCSEPass on f
-; NEWPM-NEXT:   TargetLibraryAnalysis analysis on f
-; NEWPM-NEXT: CallSiteSplittingPass on f
-; NEWPM-NEXT: OpenMPOptPass on [module]
-; NEWPM-NEXT: IPSCCPPass on [module]
-; NEWPM-NEXT: CalledValuePropagationPass on [module]
-; NEWPM-NEXT: GlobalOptPass on [module]
-; NEWPM-NEXT: 

[PATCH] D101791: [clang-tidy] Aliasing: Add support for aggregates with references.

2021-05-10 Thread Artem Dergachev 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 rG91ca3269a1b5: [clang-tidy] Aliasing: Add support for 
aggregates with references. (authored by dergachev.a).

Changed prior to commit:
  https://reviews.llvm.org/D101791?vs=342568=344197#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101791

Files:
  clang-tools-extra/clang-tidy/utils/Aliasing.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -566,3 +566,29 @@
   }
   return 0;
 }
+
+struct AggregateWithReference {
+  int 
+};
+
+void test_structured_bindings_good() {
+  int x = 0;
+  AggregateWithReference ref { x };
+  auto &[y] = ref;
+  for (; x < 10; ++y) {
+// No warning. The loop is finite because 'y' is a reference to 'x'.
+  }
+}
+
+struct AggregateWithValue {
+  int y;
+};
+
+void test_structured_bindings_bad() {
+  int x = 0;
+  AggregateWithValue val { x };
+  auto &[y] = val;
+  for (; x < 10; ++y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none 
of its condition variables (x) are updated in the loop body 
[bugprone-infinite-loop]
+  }
+}
Index: clang-tools-extra/clang-tidy/utils/Aliasing.cpp
===
--- clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -50,6 +50,13 @@
   } else if (const auto *LE = dyn_cast(S)) {
 // Treat lambda capture by reference as a form of taking a reference.
 return capturesByRef(LE->getLambdaClass(), Var);
+  } else if (const auto *ILE = dyn_cast(S)) {
+return llvm::any_of(ILE->inits(), [Var](const Expr *ChildE) {
+  // If the child expression is a reference to Var, this means that it's
+  // used as an initializer of a reference-typed field. Otherwise
+  // it would have been surrounded with an implicit lvalue-to-rvalue cast.
+  return isAccessForVar(ChildE, Var);
+});
   }
 
   return false;


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -566,3 +566,29 @@
   }
   return 0;
 }
+
+struct AggregateWithReference {
+  int 
+};
+
+void test_structured_bindings_good() {
+  int x = 0;
+  AggregateWithReference ref { x };
+  auto &[y] = ref;
+  for (; x < 10; ++y) {
+// No warning. The loop is finite because 'y' is a reference to 'x'.
+  }
+}
+
+struct AggregateWithValue {
+  int y;
+};
+
+void test_structured_bindings_bad() {
+  int x = 0;
+  AggregateWithValue val { x };
+  auto &[y] = val;
+  for (; x < 10; ++y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (x) are updated in the loop body [bugprone-infinite-loop]
+  }
+}
Index: clang-tools-extra/clang-tidy/utils/Aliasing.cpp
===
--- clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -50,6 +50,13 @@
   } else if (const auto *LE = dyn_cast(S)) {
 // Treat lambda capture by reference as a form of taking a reference.
 return capturesByRef(LE->getLambdaClass(), Var);
+  } else if (const auto *ILE = dyn_cast(S)) {
+return llvm::any_of(ILE->inits(), [Var](const Expr *ChildE) {
+  // If the child expression is a reference to Var, this means that it's
+  // used as an initializer of a reference-typed field. Otherwise
+  // it would have been surrounded with an implicit lvalue-to-rvalue cast.
+  return isAccessForVar(ChildE, Var);
+});
   }
 
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101787: [clang-tidy] Aliasing: Add more support for lambda captures.

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9b292e0edcd4: [clang-tidy] Aliasing: Add more support for 
captures. (authored by dergachev.a).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101787

Files:
  clang-tools-extra/clang-tidy/utils/Aliasing.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1260,6 +1260,71 @@
   }
 }
 
+void mutate_at_any_time(bool *x);
+
+void capture_with_branches_inside_lambda_bad() {
+  bool x = true;
+  accept_callback([=]() {
+if (x) {
+  wait();
+  if (x) {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant condition 'x' [bugprone-redundant-branch-condition]
+  }
+}
+  });
+  mutate_at_any_time();
+}
+
+void capture_with_branches_inside_lambda_good() {
+  bool x = true;
+  accept_callback([&]() {
+if (x) {
+  wait();
+  if (x) {
+  }
+}
+  });
+  mutate_at_any_time();
+}
+
+void capture_with_branches_inside_block_bad() {
+  bool x = true;
+  accept_callback(^{
+if (x) {
+  wait();
+  if (x) {
+ // FIXME: Should warn. It currently reacts to  outside the block
+ // which ideally shouldn't have any effect.
+  }
+}
+  });
+  mutate_at_any_time();
+}
+
+void capture_with_branches_inside_block_bad_simpler() {
+  bool x = true;
+  accept_callback(^{
+if (x) {
+  wait();
+  if (x) {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant condition 'x' [bugprone-redundant-branch-condition]
+  }
+}
+  });
+}
+
+void capture_with_branches_inside_block_good() {
+  __block bool x = true;
+  accept_callback(^{
+if (x) {
+  wait();
+  if (x) {
+  }
+}
+  });
+  mutate_at_any_time();
+}
+
 // GNU Expression Statements
 
 void negative_gnu_expression_statement() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -457,6 +457,92 @@
   }
 }
 
+void finish_at_any_time(bool *finished);
+
+void lambda_capture_with_loop_inside_lambda_bad() {
+  bool finished = false;
+  auto lambda = [=]() {
+while (!finished) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none of its condition variables (finished) are updated in the loop body [bugprone-infinite-loop]
+  wait();
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_bad_init_capture() {
+  bool finished = false;
+  auto lambda = [captured_finished=finished]() {
+while (!captured_finished) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none of its condition variables (captured_finished) are updated in the loop body [bugprone-infinite-loop]
+  wait();
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_good() {
+  bool finished = false;
+  auto lambda = [&]() {
+while (!finished) {
+  wait(); // No warning: the variable may be updated
+  // from outside the lambda.
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_good_init_capture() {
+  bool finished = false;
+  auto lambda = [_finished=finished]() {
+while (!captured_finished) {
+  wait(); // No warning: the variable may be updated
+  // from outside the lambda.
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void block_capture_with_loop_inside_block_bad() {
+  bool finished = false;
+  auto block = ^() {
+while (!finished) {
+  // FIXME: This should warn. It currently reacts to 
+  // outside the block which ideally shouldn't have any effect.
+  wait();
+}
+  };
+  finish_at_any_time();
+  block();
+}
+
+void block_capture_with_loop_inside_block_bad_simpler() {
+  bool finished = false;
+  auto block = ^() {
+while (!finished) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none of its condition variables (finished) are updated in the loop body [bugprone-infinite-loop]
+  wait();
+}
+  };
+  block();
+}
+
+void block_capture_with_loop_inside_block_good() {
+  __block bool finished = false;
+  auto block = ^() {
+while (!finished) {
+  wait(); // No warning: the variable may be updated
+  // from outside the 

[PATCH] D96215: [clang-tidy] Aliasing: Add support for lambda captures.

2021-05-10 Thread Artem Dergachev 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 rG43f4331edfb5: [clang-tidy] Aliasing: Add support for 
captures. (authored by dergachev.a).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96215

Files:
  clang-tools-extra/clang-tidy/utils/Aliasing.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-redundant-branch-condition %t
+// RUN: %check_clang_tidy %s bugprone-redundant-branch-condition %t \
+// RUN:   -- -- -fblocks
 
 extern unsigned peopleInTheBuilding;
 extern unsigned fireFighters;
@@ -1179,6 +1180,86 @@
   }
 }
 
+// Lambda / block captures.
+
+template  void accept_callback(T t) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void accept_block(void (^)(void)) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void wait(void) {
+  // Wait for the previously passed callback to be called.
+}
+
+void capture_and_mutate_by_lambda() {
+  bool x = true;
+  accept_callback([&]() { x = false; });
+  if (x) {
+wait();
+if (x) {
+}
+  }
+}
+
+void lambda_capture_by_value() {
+  bool x = true;
+  accept_callback([x]() { if (x) {} });
+  if (x) {
+wait();
+if (x) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'x' [bugprone-redundant-branch-condition]
+}
+  }
+}
+
+void capture_by_lambda_but_not_mutate() {
+  bool x = true;
+  accept_callback([&]() { if (x) {} });
+  if (x) {
+wait();
+// FIXME: Should warn.
+if (x) {
+}
+  }
+}
+
+void capture_and_mutate_by_block() {
+  __block bool x = true;
+  accept_block(^{ x = false; });
+  if (x) {
+wait();
+if (x) {
+}
+  }
+}
+
+void block_capture_by_value() {
+  bool x = true;
+  accept_block(^{ if (x) {} });
+  if (x) {
+wait();
+if (x) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'x' [bugprone-redundant-branch-condition]
+}
+  }
+}
+
+void capture_by_block_but_not_mutate() {
+  __block bool x = true;
+  accept_callback(^{ if (x) {} });
+  if (x) {
+wait();
+// FIXME: Should warn.
+if (x) {
+}
+  }
+}
+
 // GNU Expression Statements
 
 void negative_gnu_expression_statement() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fexceptions
+// RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
+// RUN:   -- -- -fexceptions -fblocks
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -378,6 +379,84 @@
   } while (i < Limit);
 }
 
+template  void accept_callback(T t) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void accept_block(void (^)(void)) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void wait(void) {
+  // Wait for the previously passed callback to be called.
+}
+
+void lambda_capture_from_outside() {
+  bool finished = false;
+  accept_callback([&]() {
+finished = true;
+  });
+  while (!finished) {
+wait();
+  }
+}
+
+void lambda_capture_from_outside_by_value() {
+  bool finished = false;
+  accept_callback([finished]() {
+if (finished) {}
+  });
+  while (!finished) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (finished) are updated in the loop body [bugprone-infinite-loop]
+wait();
+  }
+}
+
+void lambda_capture_from_outside_but_unchanged() {
+  bool finished = false;
+  accept_callback([]() {
+if (finished) {}
+  });
+  while (!finished) {
+// FIXME: Should warn.
+wait();
+  }
+}
+
+void block_capture_from_outside() {
+  __block bool finished = false;
+  accept_block(^{
+finished = true;
+  });
+  while (!finished) {
+wait();
+  }
+}
+
+void block_capture_from_outside_by_value() {
+  bool finished = false;
+  accept_block(^{
+if (finished) {}
+  });
+  while (!finished) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (finished) are updated in the loop 

[clang-tools-extra] 91ca326 - [clang-tidy] Aliasing: Add support for aggregates with references.

2021-05-10 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-05-10T14:00:31-07:00
New Revision: 91ca3269a1b544db1303b496101fd9d6fe953277

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

LOG: [clang-tidy] Aliasing: Add support for aggregates with references.

When a variable is used in an initializer of an aggregate
for its reference-type field this counts as aliasing.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/Aliasing.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp 
b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
index 12a8ca8185b0f..69aea1145de50 100644
--- a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -50,6 +50,13 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const 
VarDecl *Var) {
   } else if (const auto *LE = dyn_cast(S)) {
 // Treat lambda capture by reference as a form of taking a reference.
 return capturesByRef(LE->getLambdaClass(), Var);
+  } else if (const auto *ILE = dyn_cast(S)) {
+return llvm::any_of(ILE->inits(), [Var](const Expr *ChildE) {
+  // If the child expression is a reference to Var, this means that it's
+  // used as an initializer of a reference-typed field. Otherwise
+  // it would have been surrounded with an implicit lvalue-to-rvalue cast.
+  return isAccessForVar(ChildE, Var);
+});
   }
 
   return false;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
index 5b477130a7b01..2765b181db2c5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -566,3 +566,29 @@ int foo(void) {
   }
   return 0;
 }
+
+struct AggregateWithReference {
+  int 
+};
+
+void test_structured_bindings_good() {
+  int x = 0;
+  AggregateWithReference ref { x };
+  auto &[y] = ref;
+  for (; x < 10; ++y) {
+// No warning. The loop is finite because 'y' is a reference to 'x'.
+  }
+}
+
+struct AggregateWithValue {
+  int y;
+};
+
+void test_structured_bindings_bad() {
+  int x = 0;
+  AggregateWithValue val { x };
+  auto &[y] = val;
+  for (; x < 10; ++y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none 
of its condition variables (x) are updated in the loop body 
[bugprone-infinite-loop]
+  }
+}



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


[clang-tools-extra] 9b292e0 - [clang-tidy] Aliasing: Add more support for captures.

2021-05-10 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-05-10T14:00:30-07:00
New Revision: 9b292e0edcd4e889dbcf4bbaad6c1cc80fffcfd1

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

LOG: [clang-tidy] Aliasing: Add more support for captures.

D96215 takes care of the situation where the variable is captured into
a nearby lambda. This patch takes care of the situation where
the current function is the lambda and the variable is one of its captures
from an enclosing scope.

The analogous problem for ^{blocks} is already handled automagically
by D96215.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/Aliasing.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp 
b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
index f9eb147ce6720..12a8ca8185b0f 100644
--- a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -23,6 +23,13 @@ static bool isAccessForVar(const Stmt *S, const VarDecl 
*Var) {
   return false;
 }
 
+static bool capturesByRef(const CXXRecordDecl *RD, const VarDecl *Var) {
+  return llvm::any_of(RD->captures(), [Var](const LambdaCapture ) {
+return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
+   C.getCapturedVar() == Var;
+  });
+}
+
 /// Return whether \p Var has a pointer or reference in \p S.
 static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
   // Treat block capture by reference as a form of taking a reference.
@@ -42,10 +49,7 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const 
VarDecl *Var) {
   return isAccessForVar(UnOp->getSubExpr(), Var);
   } else if (const auto *LE = dyn_cast(S)) {
 // Treat lambda capture by reference as a form of taking a reference.
-return llvm::any_of(LE->captures(), [Var](const LambdaCapture ) {
-  return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
- C.getCapturedVar() == Var;
-});
+return capturesByRef(LE->getLambdaClass(), Var);
   }
 
   return false;
@@ -67,8 +71,22 @@ static bool hasPtrOrReferenceInStmt(const Stmt *S, const 
VarDecl *Var) {
   return false;
 }
 
+static bool refersToEnclosingLambdaCaptureByRef(const FunctionDecl *Func,
+const VarDecl *Var) {
+  const auto *MD = dyn_cast(Func);
+  if (!MD)
+return false;
+
+  const CXXRecordDecl *RD = MD->getParent();
+  if (!RD->isLambda())
+return false;
+
+  return capturesByRef(RD, Var);
+}
+
 bool hasPtrOrReferenceInFunc(const FunctionDecl *Func, const VarDecl *Var) {
-  return hasPtrOrReferenceInStmt(Func->getBody(), Var);
+  return hasPtrOrReferenceInStmt(Func->getBody(), Var) ||
+ refersToEnclosingLambdaCaptureByRef(Func, Var);
 }
 
 } // namespace utils

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
index d6cb954a3beb6..5b477130a7b01 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -457,6 +457,92 @@ void block_capture_from_outside_but_unchanged() {
   }
 }
 
+void finish_at_any_time(bool *finished);
+
+void lambda_capture_with_loop_inside_lambda_bad() {
+  bool finished = false;
+  auto lambda = [=]() {
+while (!finished) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none 
of its condition variables (finished) are updated in the loop body 
[bugprone-infinite-loop]
+  wait();
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_bad_init_capture() {
+  bool finished = false;
+  auto lambda = [captured_finished=finished]() {
+while (!captured_finished) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: this loop is infinite; none 
of its condition variables (captured_finished) are updated in the loop body 
[bugprone-infinite-loop]
+  wait();
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_good() {
+  bool finished = false;
+  auto lambda = [&]() {
+while (!finished) {
+  wait(); // No warning: the variable may be updated
+  // from outside the lambda.
+}
+  };
+  finish_at_any_time();
+  lambda();
+}
+
+void lambda_capture_with_loop_inside_lambda_good_init_capture() {
+  bool finished = false;
+  auto lambda = [_finished=finished]() {
+while (!captured_finished) {
+  wait(); // No warning: the variable may be updated
+   

[clang-tools-extra] 43f4331 - [clang-tidy] Aliasing: Add support for captures.

2021-05-10 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-05-10T14:00:30-07:00
New Revision: 43f4331edfb595979f6854351d24f9a9219595fa

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

LOG: [clang-tidy] Aliasing: Add support for captures.

The utility function clang::tidy::utils::hasPtrOrReferenceInFunc() scans the
function for pointer/reference aliases to a given variable. It currently scans
for operator & over that variable and for declarations of references to that
variable.

This patch makes it also scan for C++ lambda captures by reference
and for Objective-C block captures.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/Aliasing.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp 
b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
index 3a88126a9ee6a..f9eb147ce6720 100644
--- a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -9,6 +9,7 @@
 #include "Aliasing.h"
 
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 
 namespace clang {
 namespace tidy {
@@ -24,6 +25,10 @@ static bool isAccessForVar(const Stmt *S, const VarDecl 
*Var) {
 
 /// Return whether \p Var has a pointer or reference in \p S.
 static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
+  // Treat block capture by reference as a form of taking a reference.
+  if (Var->isEscapingByref())
+return true;
+
   if (const auto *DS = dyn_cast(S)) {
 for (const Decl *D : DS->getDeclGroup()) {
   if (const auto *LeftVar = dyn_cast(D)) {
@@ -35,6 +40,12 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const 
VarDecl *Var) {
   } else if (const auto *UnOp = dyn_cast(S)) {
 if (UnOp->getOpcode() == UO_AddrOf)
   return isAccessForVar(UnOp->getSubExpr(), Var);
+  } else if (const auto *LE = dyn_cast(S)) {
+// Treat lambda capture by reference as a form of taking a reference.
+return llvm::any_of(LE->captures(), [Var](const LambdaCapture ) {
+  return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
+ C.getCapturedVar() == Var;
+});
   }
 
   return false;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
index 0b1baf04fee2f..d6cb954a3beb6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fexceptions
+// RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
+// RUN:   -- -- -fexceptions -fblocks
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -378,6 +379,84 @@ void lambda_capture() {
   } while (i < Limit);
 }
 
+template  void accept_callback(T t) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void accept_block(void (^)(void)) {
+  // Potentially call the callback.
+  // Possibly on a background thread or something.
+}
+
+void wait(void) {
+  // Wait for the previously passed callback to be called.
+}
+
+void lambda_capture_from_outside() {
+  bool finished = false;
+  accept_callback([&]() {
+finished = true;
+  });
+  while (!finished) {
+wait();
+  }
+}
+
+void lambda_capture_from_outside_by_value() {
+  bool finished = false;
+  accept_callback([finished]() {
+if (finished) {}
+  });
+  while (!finished) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (finished) are updated in the loop body 
[bugprone-infinite-loop]
+wait();
+  }
+}
+
+void lambda_capture_from_outside_but_unchanged() {
+  bool finished = false;
+  accept_callback([]() {
+if (finished) {}
+  });
+  while (!finished) {
+// FIXME: Should warn.
+wait();
+  }
+}
+
+void block_capture_from_outside() {
+  __block bool finished = false;
+  accept_block(^{
+finished = true;
+  });
+  while (!finished) {
+wait();
+  }
+}
+
+void block_capture_from_outside_by_value() {
+  bool finished = false;
+  accept_block(^{
+if (finished) {}
+  });
+  while (!finished) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (finished) are updated in the loop body 
[bugprone-infinite-loop]
+wait();
+  }
+}
+
+void block_capture_from_outside_but_unchanged() {
+  __block bool finished = false;
+  accept_block(^{
+if (finished) {}
+  });
+  while (!finished) {
+// FIXME: Should warn.
+ 

[PATCH] D102196: [NewPM] Add options to PrintPassInstrumentation

2021-05-10 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
Herald added subscribers: nikic, hiraditya.
aeubanks requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

To bring D99599 's implementation in line with 
the existing
PrintPassInstrumentation, and to fix a FIXME, add more customizability
to PrintPassInstrumentation.

Introduce three new options. The first takes over the existing
"-debug-pass-manager-verbose" cl::opt.

The second and third option are specific to -fdebug-pass-structure. They
allow indentation, and also don't print analysis queries.

To avoid more golden file tests than necessary, prune down the
-fdebug-pass-structure tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102196

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Driver/debug-pass-structure.c
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/new-pass-manager-cgscc-fct-proxy.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/pass-pipeline-parsing.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -52,9 +52,17 @@
cl::value_desc("filename"));
 } // namespace llvm
 
-static cl::opt
-DebugPM("debug-pass-manager", cl::Hidden,
-cl::desc("Print pass management debugging information"));
+enum class DebugLogging { None, Normal, Verbose };
+
+static cl::opt DebugPM(
+"debug-pass-manager", cl::Hidden, cl::ValueOptional,
+cl::desc("Print pass management debugging information"),
+cl::init(DebugLogging::None),
+cl::values(
+clEnumValN(DebugLogging::Normal, "", ""),
+clEnumValN(
+DebugLogging::Verbose, "verbose",
+"Print extra information about adaptors and pass managers")));
 
 static cl::list
 PassPlugins("load-pass-plugin",
@@ -283,7 +291,10 @@
   ModuleAnalysisManager MAM;
 
   PassInstrumentationCallbacks PIC;
-  StandardInstrumentations SI(DebugPM, VerifyEachPass);
+  PrintPassOptions PrintPassOpts;
+  PrintPassOpts.Verbose = DebugPM == DebugLogging::Verbose;
+  StandardInstrumentations SI(DebugPM != DebugLogging::None, VerifyEachPass,
+  PrintPassOpts);
   SI.registerCallbacks(PIC, );
   DebugifyEachInstrumentation Debugify;
   if (DebugifyEach)
Index: llvm/test/Other/pass-pipeline-parsing.ll
===
--- llvm/test/Other/pass-pipeline-parsing.ll
+++ llvm/test/Other/pass-pipeline-parsing.ll
@@ -142,7 +142,7 @@
 ; RUN: | FileCheck %s --check-prefix=CHECK-NESTED-FP-LP
 ; CHECK-NESTED-FP-LP: Running pass: NoOpLoopPass
 
-; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
+; RUN: opt -disable-output -debug-pass-manager=verbose \
 ; RUN: -passes='module(no-op-function,no-op-loop,no-op-cgscc,cgscc(no-op-function,no-op-loop),function(no-op-loop))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-ADAPTORS
 ; CHECK-ADAPTORS: Running pass: ModuleToFunctionPassAdaptor
@@ -167,7 +167,7 @@
 ; RUN: opt -disable-output -debug-pass-manager \
 ; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS-NO-VERBOSE
-; RUN: opt -disable-output -debug-pass-manager -debug-pass-manager-verbose \
+; RUN: opt -disable-output -debug-pass-manager=verbose \
 ; RUN: -passes='module(function(no-op-function,loop(no-op-loop,no-op-loop)))' %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefix=CHECK-MANAGERS
 ; CHECK-MANAGERS: Running pass: PassManager{{.*}}Function
Index: llvm/test/Other/opt-O3-pipeline.ll
===
--- llvm/test/Other/opt-O3-pipeline.ll
+++ llvm/test/Other/opt-O3-pipeline.ll
@@ -1,5 +1,4 @@
 ; RUN: opt -enable-new-pm=0 -mtriple=x86_64-- -O3 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK,%llvmcheckext %s
-; RUN: opt -enable-new-pm=1 -mtriple=x86_64-- -O3 -debug-pass-structure < %s -o /dev/null 2>&1 | FileCheck --check-prefixes=NEWPM,%llvmcheckext %s
 
 ; REQUIRES: asserts
 
@@ -336,169 +335,6 @@
 ; CHECK-NEXT: Branch Probability Analysis
 ; CHECK-NEXT: Block Frequency Analysis
 
-; NEWPM:  VerifierPass on [module]
-; NEWPM-NEXT:   VerifierAnalysis analysis on [module]
-; NEWPM-NEXT: Annotation2MetadataPass on [module]
-; NEWPM-NEXT: ForceFunctionAttrsPass on [module]
-; NEWPM-NEXT: InferFunctionAttrsPass on [module]
-; NEWPM-NEXT:   InnerAnalysisManagerProxy<{{.*}}> analysis on [module]
-; NEWPM-NEXT: ModuleToFunctionPassAdaptor on [module]
-; NEWPM-NEXT:   PassManager<{{.*}}> on f
-; NEWPM-NEXT: PreservedCFGCheckerAnalysis analysis on f
-; 

[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma updated this revision to Diff 344193.
efriedma added a comment.

Use isRecordType() instead of checking for an atomic type.  Fix the caller side 
as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/big-atomic-ops.c


Index: clang/test/CodeGen/big-atomic-ops.c
===
--- clang/test/CodeGen/big-atomic-ops.c
+++ clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@
 // Push a destructor cleanup for this parameter if the ABI requires it.
 // Don't push a cleanup in a thunk for a method that will also emit a
 // cleanup.
-if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+if (Ty->isRecordType() && !CurFuncIsThunk &&
 Ty->castAs()->getDecl()->isParamDestroyedInCallee()) {
   if (QualType::DestructionKind DtorKind =
   D.needsDestruction(getContext())) {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3698,7 +3698,7 @@
   }
 
   // Deactivate the cleanup for the callee-destructed param that was pushed.
-  if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
+  if (type->isRecordType() && !CurFuncIsThunk &&
   type->castAs()->getDecl()->isParamDestroyedInCallee() &&
   param->needsDestruction(getContext())) {
 EHScopeStack::stable_iterator cleanup =
@@ -4269,7 +4269,7 @@
   // In the Microsoft C++ ABI, aggregate arguments are destructed by the 
callee.
   // However, we still have to push an EH-only cleanup in case we unwind before
   // we make it to the call.
-  if (HasAggregateEvalKind &&
+  if (type->isRecordType() &&
   type->castAs()->getDecl()->isParamDestroyedInCallee()) {
 // If we're using inalloca, use the argument memory.  Otherwise, use a
 // temporary.


Index: clang/test/CodeGen/big-atomic-ops.c
===
--- clang/test/CodeGen/big-atomic-ops.c
+++ clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@
 // Push a destructor cleanup for this parameter if the ABI requires it.
 // Don't push a cleanup in a thunk for a method that will also emit a
 // cleanup.
-if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+if (Ty->isRecordType() && !CurFuncIsThunk &&
 Ty->castAs()->getDecl()->isParamDestroyedInCallee()) {
   if (QualType::DestructionKind DtorKind =
   D.needsDestruction(getContext())) {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3698,7 +3698,7 @@
   }
 
   // Deactivate the cleanup for the callee-destructed param that was pushed.
-  if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
+  if (type->isRecordType() && !CurFuncIsThunk &&
   type->castAs()->getDecl()->isParamDestroyedInCallee() &&
   param->needsDestruction(getContext())) {
 EHScopeStack::stable_iterator cleanup =
@@ -4269,7 +4269,7 @@
   // In the Microsoft C++ ABI, aggregate arguments are destructed by the callee.
   // However, we still have to push an EH-only cleanup in case we unwind before
   // we make it to the call.
-  if (HasAggregateEvalKind &&
+  if (type->isRecordType() &&
   type->castAs()->getDecl()->isParamDestroyedInCallee()) {
 // If we're using inalloca, use the argument memory.  Otherwise, use a
 // temporary.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99409: [clang] Speedup line offset mapping computation

2021-05-10 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/lib/Basic/SourceManager.cpp:1255
 
-#ifdef __SSE2__
-#include 
-#endif
+// Check if mutli-byte word x has bytes between m and n, included. This may 
also
+// catch bytes equal to n + 1.

Typo: multi-byte.  Also, I think "inclusive" rather than "included" assuming 
you mean the range `[m, n]` rather than `(m, n)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99409

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


[PATCH] D98799: [UniqueLinkageName] Use consistent checks when mangling symbo linkage name and debug linkage name.

2021-05-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names-dwarf.c:34-39
+static int go(a) int a;
+{
+  return glob + a;
+}
+
+

aaron.ballman wrote:
> dblaikie wrote:
> > hoy wrote:
> > > dblaikie wrote:
> > > > dblaikie wrote:
> > > > > hoy wrote:
> > > > > > dblaikie wrote:
> > > > > > > hoy wrote:
> > > > > > > > dblaikie wrote:
> > > > > > > > > hoy wrote:
> > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > hoy wrote:
> > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > hoy wrote:
> > > > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > > > hoy wrote:
> > > > > > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > > > > > Does this need to be down here? Or would the 
> > > > > > > > > > > > > > > > > code be a well exercised if it was up next to 
> > > > > > > > > > > > > > > > > the go declaration above?
> > > > > > > > > > > > > > > > Yes, it needs to be here. Otherwise it will 
> > > > > > > > > > > > > > > > just like the function `bar` above that doesn't 
> > > > > > > > > > > > > > > > get a uniquefied name. I think moving the 
> > > > > > > > > > > > > > > > definition up to right after the declaration 
> > > > > > > > > > > > > > > > hides the declaration.
> > > > > > > > > > > > > > > Not sure I follow - do you mean that if the go 
> > > > > > > > > > > > > > > declaration and go definition were next to each 
> > > > > > > > > > > > > > > other, this test would (mechanically speaking) 
> > > > > > > > > > > > > > > not validate what the patch? Or that it would be 
> > > > > > > > > > > > > > > less legible, but still mechanically correct?
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > I think it would be (assuming it's still 
> > > > > > > > > > > > > > > mechanically correct) more legible to put the 
> > > > > > > > > > > > > > > declaration next to the definition - the comment 
> > > > > > > > > > > > > > > describes why the declaration is significant/why 
> > > > > > > > > > > > > > > the definition is weird, and seeing all that 
> > > > > > > > > > > > > > > together would be clearer to me than spreading it 
> > > > > > > > > > > > > > > out/having to look further away to see what's 
> > > > > > > > > > > > > > > going on.
> > > > > > > > > > > > > > When the `go` declaration and `go` definition were 
> > > > > > > > > > > > > > next to each other, the go function won't get a 
> > > > > > > > > > > > > > uniqufied name at all. The declaration will be 
> > > > > > > > > > > > > > overwritten by the definition. Only when the 
> > > > > > > > > > > > > > declaration is seen by others, such the callsite in 
> > > > > > > > > > > > > > `baz`, the declaration makes a difference by having 
> > > > > > > > > > > > > > the callsite use a uniqufied name.
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > Ah! Interesting, good to know. 
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Is that worth supporting, I wonder? I guess it falls 
> > > > > > > > > > > > > out for free/without significant additional 
> > > > > > > > > > > > > complexity. I worry about the subtlety of the 
> > > > > > > > > > > > > additional declaration changing the behavior here... 
> > > > > > > > > > > > > might be a bit surprising/subtle. But maybe no nice 
> > > > > > > > > > > > > way to avoid it either.
> > > > > > > > > > > > It would be ideal if user never writes code like that. 
> > > > > > > > > > > > Unfortunately it exists with legacy code (such as 
> > > > > > > > > > > > mysql). I think it's worth supporting it from AutoFDO 
> > > > > > > > > > > > point of view to avoid a silent mismatch between debug 
> > > > > > > > > > > > linkage name and real linkage name.
> > > > > > > > > > > Oh, I agree that we shouldn't mismatch debug info and the 
> > > > > > > > > > > actual symbol name - what I meant was whether code like 
> > > > > > > > > > > this should get mangled or not when using 
> > > > > > > > > > > unique-internal-linkage names.
> > > > > > > > > > > 
> > > > > > > > > > > I'm now more curious about this:
> > > > > > > > > > > 
> > > > > > > > > > > > When the `go` declaration and `go` definition were next 
> > > > > > > > > > > > to each other, the go function won't get a uniqufied 
> > > > > > > > > > > > name at all.
> > > > > > > > > > > 
> > > > > > > > > > > This doesn't seem to happen with the 
> > > > > > > > > > > `__attribute__((overloadable))` attribute, for instance - 
> > > > > > > > > > > so any idea what's different about uniquification that's 
> > > > > > > > > > > working differently than overloadable?
> > > > > > > > > > > 
> > > > > > > > > > > ```
> > > > > > > > > > > $ cat test.c
> > > > > > > > > > > __attribute__((overloadable)) static int go(a) int a; {
> > > > > > > > > > >   return 3 + a;
> > > > > > > > > > > }
> > > > > > > > > > > void baz() {
> > > > > > > > > > >   go(2);
> > > > > > > > > > > }
> > > > > > > > > 

[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

2021-05-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Does this cause duplicate DW_TAG_reference_types in the output, if the input IR 
Has both DW_TAG_reference_type and DW_TAG_rvalue_reference_types?




Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:391
+  // version.
+  dwarf::Tag FixedTag = (dwarf::Tag)Tag;
+  if (Asm->TM.Options.DebugStrictDwarf &&

Rather than adding a cast here, perhaps the parameter type could be updated? 
(maybe in a separate preliminary commit, though, so as not to muddy this one)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100630

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


[PATCH] D102191: [PowerPC] Add clang option -m[no-]prefixed

2021-05-10 Thread Lei Huang via Phabricator via cfe-commits
lei created this revision.
lei added reviewers: stefanp, nemanjai, power-llvm-team.
Herald added subscribers: dang, shchenz.
lei requested review of this revision.
Herald added a project: clang.

Add user-facing front end option to turn off power10 prefixed instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102191

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/test/Driver/ppc-prefixed.cpp


Index: clang/test/Driver/ppc-prefixed.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-prefixed.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 
-mprefixed -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-PREFIXED %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 
-mno-prefixed -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOPREFIXED %s
+// CHECK-NOPREFIXED: "-target-feature" "-prefixed"
+// CHECK-PREFIXED: "-target-feature" "+prefixed"
+
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -emit-llvm -S 
%s -o - | grep "attributes.*+prefix-instrs"
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -mprefixed 
-emit-llvm -S %s -o - | grep "attributes.*+prefix-instrs"
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -mno-prefixed 
-emit-llvm -S %s -o - | grep "attributes.*\-prefix-instrs"
+
+int main(int argc, char *argv[]) {
+  return 0;
+}
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -73,6 +73,7 @@
   bool PairedVectorMemops = false;
   bool HasP10Vector = false;
   bool HasPCRelativeMemops = false;
+  bool HasPrefixInstrs = false;
 
 protected:
   std::string ABI;
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -56,6 +56,8 @@
   HasP10Vector = true;
 } else if (Feature == "+pcrelative-memops") {
   HasPCRelativeMemops = true;
+} else if (Feature == "+prefix-instrs") {
+  HasPrefixInstrs = true;
 } else if (Feature == "+spe" || Feature == "+efpu2") {
   HasSPE = true;
   LongDoubleWidth = LongDoubleAlign = 64;
@@ -394,6 +396,7 @@
   Features["mma"] = true;
   Features["power10-vector"] = true;
   Features["pcrelative-memops"] = true;
+  Features["prefix-instrs"] = true;
   return;
 }
 
@@ -419,6 +422,7 @@
   .Case("paired-vector-memops", PairedVectorMemops)
   .Case("power10-vector", HasP10Vector)
   .Case("pcrelative-memops", HasPCRelativeMemops)
+  .Case("prefix-instrs", HasPrefixInstrs)
   .Case("spe", HasSPE)
   .Case("mma", HasMMA)
   .Case("rop-protect", HasROPProtect)
@@ -451,6 +455,8 @@
   Features["power8-vector"] = Features["power9-vector"] = true;
 if (Name == "pcrel")
   Features["pcrelative-memops"] = true;
+else if (Name == "prefixed")
+  Features["prefix-instrs"] = true;
 else
   Features[Name] = true;
   } else {
@@ -471,6 +477,8 @@
   Features["power10-vector"] = false;
 if (Name == "pcrel")
   Features["pcrelative-memops"] = false;
+else if (Name == "prefixed")
+  Features["prefix-instrs"] = false;
 else
   Features[Name] = false;
   }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3254,6 +3254,8 @@
 def mno_altivec : Flag<["-"], "mno-altivec">, Group;
 def mpcrel: Flag<["-"], "mpcrel">, Group;
 def mno_pcrel: Flag<["-"], "mno-pcrel">, Group;
+def mprefixed: Flag<["-"], "mprefixed">, Group;
+def mno_prefixed: Flag<["-"], "mno-prefixed">, Group;
 def mspe : Flag<["-"], "mspe">, Group;
 def mno_spe : Flag<["-"], "mno-spe">, Group;
 def mefpu2 : Flag<["-"], "mefpu2">, Group;


Index: clang/test/Driver/ppc-prefixed.cpp
===
--- /dev/null
+++ clang/test/Driver/ppc-prefixed.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 -mprefixed -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-PREFIXED %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 -mno-prefixed -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOPREFIXED %s
+// CHECK-NOPREFIXED: "-target-feature" "-prefixed"
+// CHECK-PREFIXED: "-target-feature" "+prefixed"
+
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -emit-llvm -S %s -o - | grep "attributes.*+prefix-instrs"
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -mprefixed -emit-llvm -S %s -o - | grep "attributes.*+prefix-instrs"
+// RUN: %clang -target powerpc64-unknown-linux-gnu -mcpu=pwr10 -mno-prefixed -emit-llvm -S %s -o - | grep 

[PATCH] D77598: Integral template argument suffix and cast printing

2021-05-10 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 344161.
reikdas added a comment.

Fix failing test on windows triple and do some code cleanup.


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

https://reviews.llvm.org/D77598

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/StmtDataCollectors.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/Analysis/eval-predefined-exprs.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p12.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p13.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p14.cpp
  clang/test/CodeGenCXX/debug-info-codeview-template-literal.cpp
  clang/test/CodeGenCXX/debug-info-codeview-template-type.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/cxx1z-ast-print.cpp
  clang/test/SemaCXX/matrix-type-builtins.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/test/SemaTemplate/default-arguments-ast-print.cpp
  clang/test/SemaTemplate/delegating-constructors.cpp
  clang/test/SemaTemplate/matrix-type.cpp
  clang/test/SemaTemplate/temp_arg_enum_printing.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/tools/libclang/CIndex.cpp
  
clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
@@ -20,7 +20,7 @@
 llvm::raw_string_ostream Stream(ArgStr);
 const TemplateArgument  = ArgLoc.getArgument();
 
-Arg.print(Context->getPrintingPolicy(), Stream);
+Arg.print(Context->getPrintingPolicy(), Stream, /*IncludeType*/ true);
 Match(Stream.str(), ArgLoc.getLocation());
 return ExpectedLocationVisitor::
   TraverseTemplateArgumentLoc(ArgLoc);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5185,8 +5185,9 @@
 SmallString<128> Str;
 llvm::raw_svector_ostream OS(Str);
 OS << *ClassSpec;
-printTemplateArgumentList(OS, ClassSpec->getTemplateArgs().asArray(),
-  Policy);
+printTemplateArgumentList(
+OS, ClassSpec->getTemplateArgs().asArray(), Policy,
+ClassSpec->getSpecializedTemplate()->getTemplateParameters());
 return cxstring::createDup(OS.str());
   }
 
Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -528,3 +528,33 @@
 x1.f(x2);
   }
 }
+
+namespace TypeSuffix {
+  template  struct A {};
+  template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
+  A<1L>::type a; // expected-error {{no type named 'type' in 'TypeSuffix::A<1L>'; did you mean 'A<1>::type'?}}
+
+  template  struct B {};
+  template <> struct B<1> { using type = int; }; // expected-note {{'B<1>::type' declared here}}
+  B<2>::type b;  // expected-error {{no type named 'type' in 'TypeSuffix::B<2>'; did you mean 'B<1>::type'?}}
+
+  template  struct C {};
+  template <> struct C<'a'> { using type = signed char; }; // expected-note {{'C<'a'>::type' declared here}}
+  C<(signed char)'a'>::type c; // expected-error {{no type named 'type' in 'TypeSuffix::C<(signed char)'a'>'; did you mean 'C<'a'>::type'?}}
+
+  template  struct D {};
+  template <> struct D<'a'> { using type = signed char; }; // expected-note {{'D<'a'>::type' declared here}}
+  D<'b'>::type d;  // expected-error {{no type named 'type' in 'TypeSuffix::D<'b'>'; did you mean 'D<'a'>::type'?}}
+
+  template  struct E {};
+  template <> struct E<'a'> { using type = unsigned char; }; // expected-note {{'E<'a'>::type' declared here}}
+  E<(unsigned char)'a'>::type e; // expected-error {{no type named 'type' in 'TypeSuffix::E<(unsigned char)'a'>'; did you mean 

[PATCH] D102175: [clang-tidy] performance-unnecessary-copy-initialization: Remove the complete statement when the copied variable is unused.

2021-05-10 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 344149.
flx added a comment.

Fix test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102175

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-allowed-types.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -38,60 +38,88 @@
   const auto AutoAssigned = ExpensiveTypeReference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
   // CHECK-FIXES: const auto& AutoAssigned = ExpensiveTypeReference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(ExpensiveTypeReference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveTypeReference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = ExpensiveTypeReference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES:   const ExpensiveToCopyType& VarAssigned = ExpensiveTypeReference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(ExpensiveTypeReference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveTypeReference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType ) {
   const auto AutoAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstParam(const ExpensiveToCopyType Obj) {
   const auto AutoAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstPointerParam(const ExpensiveToCopyType *const Obj) {
   const auto AutoAssigned = Obj->reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj->reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj->reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(Obj->reference());
+  AutoCopyConstructed.constMethod();
+
  

[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

In D102015#2748441 , @efriedma wrote:

>> ...I'm confused about why this code is doing what it's doing with cleanups, 
>> though.  Why does it only apply when the parameter is indirect?  I believe 
>> `isParamDestroyedInCallee()` can apply to types that are passed in other 
>> ways, so where we pushing the destructor for those, and why isn't it good 
>> enough to handle this case as well?
>
> Objects with a non-trivial destructor end up indirect anyway under the normal 
> ABI rules.  Not sure how it interacts with trivial_abi; I'll look into it.

Figured it out.  "isIndirect()" here doesn't mean the same thing that it means 
in ABIArgInfo.  If `hasScalarEvaluationKind(Ty)` is false, the caller ensures 
the value is "isIndirect()", i.e. on the stack.  It doesn't matter if the value 
was actually passed in registers.

It's not immediately obvious to me why the responsibility for creating stack 
temporaries was split this way, but it's not really relevant to this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 344145.
Meinersbur added a comment.

- Remove unused 'this' capture


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/tile_codegen.cpp
  clang/test/OpenMP/tile_codegen_for_dependent.cpp
  clang/test/OpenMP/tile_codegen_for_multiple.cpp

Index: clang/test/OpenMP/tile_codegen_for_multiple.cpp
===
--- /dev/null
+++ clang/test/OpenMP/tile_codegen_for_multiple.cpp
@@ -0,0 +1,248 @@
+// Check code generation
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-pch -o %t %s
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+// expected-no-diagnostics
+
+// Account for multiple transformations of a loop before consumed by
+// #pragma omp for.
+
+#ifndef HEADER
+#define HEADER
+
+// placeholder for loop body code.
+extern "C" void body(...) {}
+
+
+// IR-LABEL: @func(
+// IR-NEXT:  [[ENTRY:.*]]:
+// IR-NEXT:%[[START_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[END_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[STEP_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_1:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_2:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_3:.+]] = alloca i32, align 4
+// IR-NEXT:%[[I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_6:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_8:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_12:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_14:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_LB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_UB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_STRIDE:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IS_LAST:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I18:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP0:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
+// IR-NEXT:store i32 %[[START:.+]], i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[END:.+]], i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[STEP:.+]], i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:%[[TMP1:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP1]], i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[TMP2:.+]] = load i32, i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP2]], i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP3:.+]] = load i32, i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP3]], i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[TMP4:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP5:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[SUB:.+]] = sub i32 %[[TMP4]], %[[TMP5]]
+// IR-NEXT:%[[SUB4:.+]] = sub i32 %[[SUB]], 1
+// IR-NEXT:%[[TMP6:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[ADD:.+]] = add i32 %[[SUB4]], %[[TMP6]]
+// IR-NEXT:%[[TMP7:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP7]]
+// IR-NEXT:%[[SUB5:.+]] = sub i32 %[[DIV]], 1
+// IR-NEXT:store i32 %[[SUB5]], i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[TMP8:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP8]], i32* %[[I]], align 4
+// IR-NEXT:%[[TMP9:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[ADD7:.+]] = add i32 %[[TMP9]], 1
+// IR-NEXT:store i32 %[[ADD7]], i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[TMP10:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[SUB9:.+]] = sub i32 %[[TMP10]], -3
+// IR-NEXT:%[[DIV10:.+]] = udiv i32 %[[SUB9]], 4
+// IR-NEXT:%[[SUB11:.+]] = sub i32 %[[DIV10]], 1
+// IR-NEXT:store i32 %[[SUB11]], i32* %[[DOTCAPTURE_EXPR_8]], align 4
+// IR-NEXT:store i32 0, i32* 

[PATCH] D102086: [RISCV] Validate the SEW and LMUL operands to __builtin_rvv_vsetvli(max)

2021-05-10 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG18f3a14e1328: [RISCV] Validate the SEW and LMUL operands to 
__builtin_rvv_vsetvli(max) (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102086

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvv_errors.c


Index: clang/test/CodeGen/RISCV/rvv_errors.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv_errors.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -triple=riscv64 -target-feature +experimental-v 
-fsyntax-only -verify
+
+void test() {
+  __builtin_rvv_vsetvli(1, 7, 0); // expected-error {{argument value 7 is 
outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvlimax(-1, 0); // expected-error {{argument value 
18446744073709551615 is outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvli(1, 0, 4); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvlimax(0, 4); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvli(1, 0, 8); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvlimax(0, -1); // expected-error {{LMUL argument must be 
in the range [0,3] or [5,7]}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3417,6 +3417,26 @@
   return false;
 }
 
+bool Sema::CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum) {
+  llvm::APSInt Result;
+
+  // We can't check the value of a dependent argument.
+  Expr *Arg = TheCall->getArg(ArgNum);
+  if (Arg->isTypeDependent() || Arg->isValueDependent())
+return false;
+
+  // Check constant-ness first.
+  if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
+return true;
+
+  int64_t Val = Result.getSExtValue();
+  if ((Val >= 0 && Val <= 3) || (Val >= 5 && Val <= 7))
+return false;
+
+  return Diag(TheCall->getBeginLoc(), diag::err_riscv_builtin_invalid_lmul)
+ << Arg->getSourceRange();
+}
+
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo ,
  unsigned BuiltinID,
  CallExpr *TheCall) {
@@ -3448,7 +3468,19 @@
 << TheCall->getSourceRange() << StringRef(FeatureStr);
   }
 
-  return FeatureMissing;
+  if (FeatureMissing)
+return true;
+
+  switch (BuiltinID) {
+  case RISCV::BI__builtin_rvv_vsetvli:
+return SemaBuiltinConstantArgRange(TheCall, 1, 0, 3) ||
+   CheckRISCVLMUL(TheCall, 2);
+  case RISCV::BI__builtin_rvv_vsetvlimax:
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 3) ||
+   CheckRISCVLMUL(TheCall, 1);
+  }
+
+  return false;
 }
 
 bool Sema::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12539,6 +12539,7 @@
   bool CheckPPCBuiltinFunctionCall(const TargetInfo , unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo , unsigned BuiltinID,
  CallExpr *TheCall);
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11267,4 +11267,6 @@
 // RISC-V builtin required extension warning
 def err_riscv_builtin_requires_extension : Error<
   "builtin requires '%0' extension support to be enabled">;
+def err_riscv_builtin_invalid_lmul : Error<
+  "LMUL argument must be in the range [0,3] or [5,7]">;
 } // end of sema component.


Index: clang/test/CodeGen/RISCV/rvv_errors.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv_errors.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -triple=riscv64 -target-feature +experimental-v -fsyntax-only -verify
+
+void test() {
+  __builtin_rvv_vsetvli(1, 7, 0); // expected-error {{argument value 7 is outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvlimax(-1, 0); // expected-error {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvli(1, 0, 4); // expected-error {{LMUL argument must be in the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvlimax(0, 4); // expected-error {{LMUL argument must be in the range [0,3] or [5,7]}}
+  

[clang] 18f3a14 - [RISCV] Validate the SEW and LMUL operands to __builtin_rvv_vsetvli(max)

2021-05-10 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2021-05-10T12:11:13-07:00
New Revision: 18f3a14e1328c813fa5dbacc9bb931d22f0669cd

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

LOG: [RISCV] Validate the SEW and LMUL operands to __builtin_rvv_vsetvli(max)

These are required to be constants, this patch makes sure they
are in the accepted range of values.

These are usually created by wrappers in the riscv_vector.h header
which should always be correct. This patch protects against a user
using the builtin directly.

Reviewed By: khchen

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

Added: 
clang/test/CodeGen/RISCV/rvv_errors.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 99b41692688e7..f78940a6e6fad 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11267,4 +11267,6 @@ def warn_tcb_enforcement_violation : Warning<
 // RISC-V builtin required extension warning
 def err_riscv_builtin_requires_extension : Error<
   "builtin requires '%0' extension support to be enabled">;
+def err_riscv_builtin_invalid_lmul : Error<
+  "LMUL argument must be in the range [0,3] or [5,7]">;
 } // end of sema component.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d2a07450d9361..53ff0f1e634df 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12539,6 +12539,7 @@ class Sema final {
   bool CheckPPCBuiltinFunctionCall(const TargetInfo , unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo , unsigned BuiltinID,
  CallExpr *TheCall);
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index fec02b85a03b3..f3f1ccd775285 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3417,6 +3417,26 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   return false;
 }
 
+bool Sema::CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum) {
+  llvm::APSInt Result;
+
+  // We can't check the value of a dependent argument.
+  Expr *Arg = TheCall->getArg(ArgNum);
+  if (Arg->isTypeDependent() || Arg->isValueDependent())
+return false;
+
+  // Check constant-ness first.
+  if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
+return true;
+
+  int64_t Val = Result.getSExtValue();
+  if ((Val >= 0 && Val <= 3) || (Val >= 5 && Val <= 7))
+return false;
+
+  return Diag(TheCall->getBeginLoc(), diag::err_riscv_builtin_invalid_lmul)
+ << Arg->getSourceRange();
+}
+
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo ,
  unsigned BuiltinID,
  CallExpr *TheCall) {
@@ -3448,7 +3468,19 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo ,
 << TheCall->getSourceRange() << StringRef(FeatureStr);
   }
 
-  return FeatureMissing;
+  if (FeatureMissing)
+return true;
+
+  switch (BuiltinID) {
+  case RISCV::BI__builtin_rvv_vsetvli:
+return SemaBuiltinConstantArgRange(TheCall, 1, 0, 3) ||
+   CheckRISCVLMUL(TheCall, 2);
+  case RISCV::BI__builtin_rvv_vsetvlimax:
+return SemaBuiltinConstantArgRange(TheCall, 0, 0, 3) ||
+   CheckRISCVLMUL(TheCall, 1);
+  }
+
+  return false;
 }
 
 bool Sema::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,

diff  --git a/clang/test/CodeGen/RISCV/rvv_errors.c 
b/clang/test/CodeGen/RISCV/rvv_errors.c
new file mode 100644
index 0..40ec544d0b76b
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/rvv_errors.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -triple=riscv64 -target-feature +experimental-v 
-fsyntax-only -verify
+
+void test() {
+  __builtin_rvv_vsetvli(1, 7, 0); // expected-error {{argument value 7 is 
outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvlimax(-1, 0); // expected-error {{argument value 
18446744073709551615 is outside the valid range [0, 3]}}
+  __builtin_rvv_vsetvli(1, 0, 4); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvlimax(0, 4); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvli(1, 0, 8); // expected-error {{LMUL argument must be in 
the range [0,3] or [5,7]}}
+  __builtin_rvv_vsetvlimax(0, -1); // expected-error {{LMUL argument must be 
in the 

[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:8975
+}
+return false;
   }))

No need for `return false;`



Comment at: clang/lib/Sema/SemaOpenMP.cpp:12607
+  PreInits.push_back(C);
+return false;
   }))

Same, no need for `return`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

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


[PATCH] D100509: Support GCC's -fstack-usage flag

2021-05-10 Thread Pengxuan Zheng via Phabricator via cfe-commits
pzheng marked 2 inline comments as done.
pzheng added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:110
 CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when -fstack-size-section is 
enabled.
+CODEGENOPT(StackUsage, 1, 0) ///< Set when -fstack-usage is enabled.
 CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is

MaskRay wrote:
> Unneeded
I tried removing this line, but TableGen doesn't seem to generate the 
fstack_usage flag anymore. Looks like this needs to be kept. Thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100509

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


[PATCH] D102122: Support warn_unused_result on typedefs

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

In D102122#2748271 , @dblaikie wrote:

> In D102122#2748206 , @aaron.ballman 
> wrote:
>
>> Let me start off by saying: thanks, I think this is really useful 
>> functionality. As a ridiculously obvious example, Annex K has an integer 
>> type alias `errno_t` and it would incredibly handy to be able to mark that 
>> as `[[nodiscard]]` to strongly encourage checking for errors for functions 
>> that return that type (not that we support Annex K, but the general idea 
>> extends to any integer-based error type).
>>
>> That said, there are multiple different ways to spell the same semantic 
>> attribute, and it's not clear to me that we want to change them all the same 
>> way.
>>
>> `[[clang::warn_unused_result]]` is ours to do with as we please, so there's 
>> no issue changing that behavior.
>>
>> `__attribute__((warn_unused_result))` and `[[gnu::warn_unused_result]]` are 
>> governed by GCC and we try to be compatible with their behavior. GCC does 
>> not appear to support the attribute on typedefs from my testing, so we'd 
>> want to coordinate with the GCC folks to see if there's an appetite for the 
>> change.
>
> FWIW, looks like we already diverge from GCC's behavior - GCC doesn't seem to 
> support this attribute on types at all: https://godbolt.org/z/8YjqnE4cv (but 
> does support [[nodiscard]] in that place)

Whomp whomp! :-(

>> `[[nodiscard]]` is governed by both the C++ and C standards and we should 
>> not be changing its behavior without some extra diagnostics about extensions 
>> (and, preferably, some sort of attempt to standardize the behavior with 
>> WG14/WG21).
>
> Might be a compatible extension, though - to use a standard attribute in a 
> non-standard context? (at least clang and gcc only warn on putting 
> [[nodiscard]] in non-standard places, they don't error)

It's a bit unclear -- there's a list of things the attribute applies to, and 
typedef is not on the list, so it would be reasonable to think that means the 
attribute can't be written on anything else. But because the standard doesn't 
say what happens if you DO apply it to a typedef, perhaps that's sufficiently 
undefined to allow us to call it a conforming extension. Given that you're fine 
trying to get this standardized and it seems like it shouldn't be contentious, 
I think we aren't behaving badly if we accept `[[nodiscard]]` on a typedef so 
long as we give an extension warning.

>> Do you have an appetite to talk to the GCC and standards folks?
>
> Medium interest.
>
>> If not, then I think the safest bet is to only change the behavior for the 
>> `[[clang::warn_unused_result]]` and to leave the other forms alone for now.
>
> Happy to go either way.
>
> Is there an easy/recommended way to split these things up? Duplicate the 
> records in the td/come up with separate names, etc?)

Given that we already diverge from GCC for `warn_unused_result`, and because 
you're willing to give the standardization bit a shot and that seems highly 
likely to succeed, I say let's try to keep the same semantic effects for all of 
the spellings in terms of what the attribute does. If that's reasonable to 
everyone, then in SemaDeclAttr.cpp, when we see the standard spelling on a 
typedef declaration (`using` as well as `typedef`), we can issue a Clang 
extension warning on that particular use so that it's clear this is not yet 
standardized behavior for that spelling.

Btw, if you ever find yourself needing to distinguish between various spellings 
for the semantics of an attribute, you can use an `Accessors` list in the .td 
file (e.g., 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Attr.td#L665).

>> In D102122#2746426 , @dblaikie 
>> wrote:
>>
>>> Fixes for a few other test cases (though I wonder if these tests are 
>>> overconstrained - do we need to be testing the list of things this 
>>> attribute can be applied to in so many places?)
>>
>> If the semantics of the attribute are identical regardless of how it's 
>> spelled, then we probably don't need the tests all spread out in multiple 
>> files. However, I don't think there's an intention to keep all of the 
>> spellings with identical semantics, so the different tests might still make 
>> sense (but could perhaps be cleaned up).
>>
>> In D102122#2746424 , @dblaikie 
>> wrote:
>>
>>> Oh, one question: If we do move forward with this patch, how would we 
>>> detect that the compiler supports this new use of warn_unused_result? (so 
>>> that the feature detection macros in LLVM properly make the attribute a 
>>> no-op unless we have a version of clang that supports it)
>>
>> `__has_[c|cpp]_attribute` returns a value, so we'd likely wind up using that 
>> return value to distinguish between versions.
>
> Hmm - what if 

[PATCH] D100509: Support GCC's -fstack-usage flag

2021-05-10 Thread Pengxuan Zheng via Phabricator via cfe-commits
pzheng updated this revision to Diff 344135.
pzheng added a comment.

Address a few more comments from @MaskRay.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100509

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/stack-usage.c
  clang/test/Driver/stack-usage.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1185,6 +1185,37 @@
   OutStreamer->PopSection();
 }
 
+void AsmPrinter::emitStackUsage(const MachineFunction ) {
+  auto OutputFilename = MF.getTarget().Options.StackUsageOutput;
+
+  // OutputFilename empty implies -fstack-usage is not passed.
+  if (OutputFilename.empty())
+return;
+
+  const MachineFrameInfo  = MF.getFrameInfo();
+  uint64_t StackSize = FrameInfo.getStackSize();
+
+  if (StackUsageStream == nullptr) {
+std::error_code EC;
+StackUsageStream =
+std::make_unique(OutputFilename, EC, sys::fs::OF_Text);
+if (EC) {
+  errs() << "Could not open file: " << EC.message();
+  return;
+}
+  }
+
+  *StackUsageStream << MF.getFunction().getParent()->getName();
+  if (const DISubprogram *DSP = MF.getFunction().getSubprogram())
+*StackUsageStream << ':' << DSP->getLine();
+
+  *StackUsageStream << ':' << MF.getName() << '\t' << StackSize << '\t';
+  if (FrameInfo.hasVarSizedObjects())
+*StackUsageStream << "dynamic\n";
+  else
+*StackUsageStream << "static\n";
+}
+
 static bool needFuncLabelsForEHOrDebugInfo(const MachineFunction ) {
   MachineModuleInfo  = MF.getMMI();
   if (!MF.getLandingPads().empty() || MF.hasEHFunclets() || MMI.hasDebugInfo())
@@ -1469,6 +1500,9 @@
   // Emit section containing stack size metadata.
   emitStackSizeSection(*MF);
 
+  // Emit .su file containing function stack size information.
+  emitStackUsage(*MF);
+
   emitPatchableFunctionEntries();
 
   if (isVerbose())
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -337,6 +337,11 @@
 /// Stack protector guard reg to use, e.g. usually fs or gs in X86.
 std::string StackProtectorGuardReg = "None";
 
+/// Name of the stack usage file (i.e., .su file) if user passes
+/// -fstack-usage. If empty, it can be implied that -fstack-usage is not
+/// passed on the command line.
+std::string StackUsageOutput;
+
 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
 /// on the command line. This setting may either be Default, Soft, or Hard.
 /// Default selects the target's default behavior. Soft selects the ABI for
Index: llvm/include/llvm/CodeGen/AsmPrinter.h
===
--- llvm/include/llvm/CodeGen/AsmPrinter.h
+++ llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -182,6 +182,9 @@
   /// Emit comments in assembly output if this is true.
   bool VerboseAsm;
 
+  /// Output stream for the stack usage file (i.e., .su file).
+  std::unique_ptr StackUsageStream;
+
   static char ID;
 
 protected:
@@ -358,6 +361,8 @@
 
   void emitStackSizeSection(const MachineFunction );
 
+  void emitStackUsage(const MachineFunction );
+
   void emitBBAddrMapSection(const MachineFunction );
 
   void emitPseudoProbe(const MachineInstr );
Index: clang/test/Driver/stack-usage.c
===
--- /dev/null
+++ clang/test/Driver/stack-usage.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target aarch64-unknown %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ABSENT
+// CHECK-ABSENT-NOT: -fstack-usage
+
+// RUN: %clang -target aarch64-unknown -fstack-usage %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PRESENT
+// CHECK-PRESENT: "-fstack-usage"
+
+int foo() { return 42; }
Index: clang/test/CodeGen/stack-usage.c
===
--- /dev/null
+++ clang/test/CodeGen/stack-usage.c
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -triple aarch64-unknown -fstack-usage -emit-obj %s -o %t/b.o
+// RUN: FileCheck %s < %t/b.su
+
+// CHECK: stack-usage.c:[[#@LINE+1]]:foo	{{[0-9]+}}	static
+int foo() {
+  char a[8];
+
+  return 0;
+}
+
+// CHECK: stack-usage.c:[[#@LINE+1]]:bar	{{[0-9]+}}	dynamic
+int bar(int len) {
+  char a[len];
+
+  return 1;
+}
Index: 

[PATCH] D101630: [HIP] Fix device-only compilation

2021-05-10 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D101630#2744861 , @yaxunl wrote:

> [snip] it is the convention for compiler to have one output. 
> The compilation is like a pipeline. If we break it into stages, users would 
> expect to use the output from one stage as input for the next stage. This is 
> possible only if there is one output. 
> Also, when users do not want the output to be bundled, it is usually for 
> debugging or special purposes. Users need to know the naming convention of 
> the multiple outputs. I think it is justifiable to enable this by an option.

So in the end it's a trade-off between tools like ccache working out of the box 
vs additional option that would need to be used by users we do need specific 
intermediate output. 
Considering that intermediate output already need special handling, I'll agree 
that bundling by default is likely more useful.

Now the question is how to make it work without breaking existing users.

There are some tools that rely on clang `--cuda-host-only` and 
`--cuda-device-only` to work as if it was a regular C++ compilation. E.g. 
godbolt.org. 
It may be useful to do bundling **only** if we're dealing with multiple 
outputs. 
On the other hand, it may puzzle users why they get a bundle with `clang -S 
--offload_arch=X --offload_arch=Y` but plain text assembly with `clang -S 
--offload_arch=X`.

How about this:
If the user explicitly specified `--cuda-host-only` or `--cuda-device-only`, 
then by default only allow producing the natural output format, unless a 
bundled output is requested by an option. This should keep existing users 
working.
If the compilation is done without explicitly requested sub-compilation(s), 
then bundle the output by default. This should keep the GPU-unaware tools like 
ccache happy as they would always get the single output they expect.

WDYT?


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

https://reviews.llvm.org/D101630

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


[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 344134.
Meinersbur added a comment.

- Don't return false for void lambda


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/tile_codegen.cpp
  clang/test/OpenMP/tile_codegen_for_dependent.cpp
  clang/test/OpenMP/tile_codegen_for_multiple.cpp

Index: clang/test/OpenMP/tile_codegen_for_multiple.cpp
===
--- /dev/null
+++ clang/test/OpenMP/tile_codegen_for_multiple.cpp
@@ -0,0 +1,248 @@
+// Check code generation
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-pch -o %t %s
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+// expected-no-diagnostics
+
+// Account for multiple transformations of a loop before consumed by
+// #pragma omp for.
+
+#ifndef HEADER
+#define HEADER
+
+// placeholder for loop body code.
+extern "C" void body(...) {}
+
+
+// IR-LABEL: @func(
+// IR-NEXT:  [[ENTRY:.*]]:
+// IR-NEXT:%[[START_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[END_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[STEP_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_1:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_2:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_3:.+]] = alloca i32, align 4
+// IR-NEXT:%[[I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_6:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_8:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_12:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_14:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_LB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_UB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_STRIDE:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IS_LAST:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I18:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP0:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
+// IR-NEXT:store i32 %[[START:.+]], i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[END:.+]], i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[STEP:.+]], i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:%[[TMP1:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP1]], i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[TMP2:.+]] = load i32, i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP2]], i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP3:.+]] = load i32, i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP3]], i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[TMP4:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP5:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[SUB:.+]] = sub i32 %[[TMP4]], %[[TMP5]]
+// IR-NEXT:%[[SUB4:.+]] = sub i32 %[[SUB]], 1
+// IR-NEXT:%[[TMP6:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[ADD:.+]] = add i32 %[[SUB4]], %[[TMP6]]
+// IR-NEXT:%[[TMP7:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP7]]
+// IR-NEXT:%[[SUB5:.+]] = sub i32 %[[DIV]], 1
+// IR-NEXT:store i32 %[[SUB5]], i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[TMP8:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP8]], i32* %[[I]], align 4
+// IR-NEXT:%[[TMP9:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[ADD7:.+]] = add i32 %[[TMP9]], 1
+// IR-NEXT:store i32 %[[ADD7]], i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[TMP10:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[SUB9:.+]] = sub i32 %[[TMP10]], -3
+// IR-NEXT:%[[DIV10:.+]] = udiv i32 %[[SUB9]], 4
+// IR-NEXT:%[[SUB11:.+]] = sub i32 %[[DIV10]], 1
+// IR-NEXT:store i32 %[[SUB11]], i32* %[[DOTCAPTURE_EXPR_8]], align 4
+// IR-NEXT:store i32 0, i32* 

[PATCH] D102185: Widen `name` stencil to support `TypeLoc` nodes.

2021-05-10 Thread Weston Carvalho via Phabricator via cfe-commits
SilensAngelusNex updated this revision to Diff 344132.
SilensAngelusNex added a comment.

Fix typo in `name`'s doc comment and add `TypeLoc` to the list of expected 
types in `name`'s `typeError`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102185

Files:
  clang/include/clang/Tooling/Transformer/RangeSelector.h
  clang/lib/Tooling/Transformer/RangeSelector.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp


Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -457,6 +457,35 @@
   EXPECT_THAT_EXPECTED(select(name(Init), Match), HasValue("field"));
 }
 
+TEST(RangeSelectorTest, NameOpTypeLoc) {
+  StringRef Code = R"cc(
+namespace ns {
+struct Foo {
+  Foo();
+  Foo(int);
+  Foo(int, int);
+};
+}  // namespace ns
+
+ns::Foo a;
+auto b = ns::Foo(3);
+auto c = ns::Foo(1, 2);
+  )cc";
+  const char *CtorTy = "ctor_ty";
+  // Matches declaration of `a`
+  TestMatch MatchA = matchCode(
+  Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchA), HasValue("Foo"));
+  // Matches call of Foo(int)
+  TestMatch MatchB = matchCode(
+  Code, cxxFunctionalCastExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchB), HasValue("Foo"));
+  // Matches call of Foo(int, int)
+  TestMatch MatchC = matchCode(
+  Code, cxxTemporaryObjectExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchC), HasValue("Foo"));
+}
+
 TEST(RangeSelectorTest, NameOpErrors) {
   EXPECT_THAT_EXPECTED(selectFromTrivial(name("unbound_id")),
Failed(withUnboundNodeMessage()));
Index: clang/lib/Tooling/Transformer/RangeSelector.cpp
===
--- clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Transformer/RangeSelector.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
@@ -228,8 +229,16 @@
   SourceLocation L = I->getMemberLocation();
   return CharSourceRange::getTokenRange(L, L);
 }
+if (const auto *T = Node.get()) {
+  TypeLoc Loc = *T;
+  auto ET = T->getAs();
+  if (!ET.isNull()) {
+Loc = ET.getNamedTypeLoc();
+  }
+  return CharSourceRange::getTokenRange(Loc.getSourceRange());
+}
 return typeError(ID, Node.getNodeKind(),
- "DeclRefExpr, NamedDecl, CXXCtorInitializer");
+ "DeclRefExpr, NamedDecl, CXXCtorInitializer, TypeLoc");
   };
 }
 
Index: clang/include/clang/Tooling/Transformer/RangeSelector.h
===
--- clang/include/clang/Tooling/Transformer/RangeSelector.h
+++ clang/include/clang/Tooling/Transformer/RangeSelector.h
@@ -73,9 +73,9 @@
 /// binding in the match result.
 RangeSelector member(std::string ID);
 
-/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr or \c
-/// CxxCtorInitializer) selects the name's token.  Only selects the final
-/// identifier of a qualified name, but not any qualifiers or template
+/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr, \c
+/// CxxCtorInitializer, and \c TypeLoc) selects the name's token.  Only selects
+/// the final identifier of a qualified name, but not any qualifiers or 
template
 /// arguments.  For example, for `::foo::bar::baz` and `::foo::bar::baz`,
 /// it selects only `baz`.
 ///


Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -457,6 +457,35 @@
   EXPECT_THAT_EXPECTED(select(name(Init), Match), HasValue("field"));
 }
 
+TEST(RangeSelectorTest, NameOpTypeLoc) {
+  StringRef Code = R"cc(
+namespace ns {
+struct Foo {
+  Foo();
+  Foo(int);
+  Foo(int, int);
+};
+}  // namespace ns
+
+ns::Foo a;
+auto b = ns::Foo(3);
+auto c = ns::Foo(1, 2);
+  )cc";
+  const char *CtorTy = "ctor_ty";
+  // Matches declaration of `a`
+  TestMatch MatchA = matchCode(
+  Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchA), HasValue("Foo"));
+  // Matches call of Foo(int)
+  TestMatch MatchB = matchCode(
+  Code, cxxFunctionalCastExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchB), HasValue("Foo"));
+  // Matches call of Foo(int, int)
+  TestMatch MatchC 

[PATCH] D101479: [Driver] Support libc++ in MSVC

2021-05-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D101479#2748189 , @amccarth wrote:

> In D101479#2733354 , @mstorsjo 
> wrote:
>
>> Not sure if we want the desicion between static and shared libc++ be coupled 
>> with `/MT` and `/MD`, as one can quite plausibly want to use e.g. a static 
>> libc++ with `/MD`.
>
> I don't understand this.  When would someone want to use `/MD` and not get 
> the DLL version of the run-time libraries?

Whether one wants to link against the CRT statically or dynamically, and libc++ 
statically or dynamically, are two entirely separate things. I would e.g. 
expect that Chrome is built with a statically linked libc++ but linked against 
the dynamic CRT.

In any case, as the libc++ headers supply autolinking directives that match the 
declarations (whether they're doing dllimport or not), the driver shouldn't 
really need to decide, but it's all up to the libc++ installation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101479

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


[PATCH] D101790: [clang-tidy] Aliasing: Add support for passing the variable into a function by reference.

2021-05-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I completely agree with that as well, these are 100% true positives, which is 
why I left them as fixmes. The reason why I think we can't have them is that we 
don't have an appropriate alias analysis implemented. Namely, we have two 
analyses, one inside the checker that leaves out false positives like the one 
in `negative_by_val()`, the other is the universal/reusable analysis in Utils 
that i'm patching up that doesn't support happens-before relation.

I believe the right way forward is to unify these analysis by making the 
analysis in Utils account for happens-before relation. Ideally this means 
re-implementing it over the CFG which probably isn't even that hard, it's just 
a simple graph traversal problem. I may look into it in June or so.


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

https://reviews.llvm.org/D101790

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


[PATCH] D102185: Widen `name` stencil to support `TypeLoc` nodes.

2021-05-10 Thread Weston Carvalho via Phabricator via cfe-commits
SilensAngelusNex created this revision.
SilensAngelusNex requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102185

Files:
  clang/include/clang/Tooling/Transformer/RangeSelector.h
  clang/lib/Tooling/Transformer/RangeSelector.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp


Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -457,6 +457,35 @@
   EXPECT_THAT_EXPECTED(select(name(Init), Match), HasValue("field"));
 }
 
+TEST(RangeSelectorTest, NameOpTypeLoc) {
+  StringRef Code = R"cc(
+namespace ns {
+struct Foo {
+  Foo();
+  Foo(int);
+  Foo(int, int);
+};
+}  // namespace ns
+
+ns::Foo a;
+auto b = ns::Foo(3);
+auto c = ns::Foo(1, 2);
+  )cc";
+  const char *CtorTy = "ctor_ty";
+  // Matches declaration of `a`
+  TestMatch MatchA = matchCode(
+  Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchA), HasValue("Foo"));
+  // Matches call of Foo(int)
+  TestMatch MatchB = matchCode(
+  Code, cxxFunctionalCastExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchB), HasValue("Foo"));
+  // Matches call of Foo(int, int)
+  TestMatch MatchC = matchCode(
+  Code, cxxTemporaryObjectExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchC), HasValue("Foo"));
+}
+
 TEST(RangeSelectorTest, NameOpErrors) {
   EXPECT_THAT_EXPECTED(selectFromTrivial(name("unbound_id")),
Failed(withUnboundNodeMessage()));
Index: clang/lib/Tooling/Transformer/RangeSelector.cpp
===
--- clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/Transformer/RangeSelector.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
@@ -228,6 +229,14 @@
   SourceLocation L = I->getMemberLocation();
   return CharSourceRange::getTokenRange(L, L);
 }
+if (const auto *T = Node.get()) {
+  TypeLoc Loc = *T;
+  auto ET = T->getAs();
+  if (!ET.isNull()) {
+Loc = ET.getNamedTypeLoc();
+  }
+  return CharSourceRange::getTokenRange(Loc.getSourceRange());
+}
 return typeError(ID, Node.getNodeKind(),
  "DeclRefExpr, NamedDecl, CXXCtorInitializer");
   };
Index: clang/include/clang/Tooling/Transformer/RangeSelector.h
===
--- clang/include/clang/Tooling/Transformer/RangeSelector.h
+++ clang/include/clang/Tooling/Transformer/RangeSelector.h
@@ -73,9 +73,9 @@
 /// binding in the match result.
 RangeSelector member(std::string ID);
 
-/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr or \c
-/// CxxCtorInitializer) selects the name's token.  Only selects the final
-/// identifier of a qualified name, but not any qualifiers or template
+/// Given a node with a "name", (like \c NamedDecl, \c DeclRefExpr, \c
+/// CxxCtorInitializer, and \c TypeLoc) selects the name's token.  Only 
selects\
+/// the final identifier of a qualified name, but not any qualifiers or 
template
 /// arguments.  For example, for `::foo::bar::baz` and `::foo::bar::baz`,
 /// it selects only `baz`.
 ///


Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -457,6 +457,35 @@
   EXPECT_THAT_EXPECTED(select(name(Init), Match), HasValue("field"));
 }
 
+TEST(RangeSelectorTest, NameOpTypeLoc) {
+  StringRef Code = R"cc(
+namespace ns {
+struct Foo {
+  Foo();
+  Foo(int);
+  Foo(int, int);
+};
+}  // namespace ns
+
+ns::Foo a;
+auto b = ns::Foo(3);
+auto c = ns::Foo(1, 2);
+  )cc";
+  const char *CtorTy = "ctor_ty";
+  // Matches declaration of `a`
+  TestMatch MatchA = matchCode(
+  Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchA), HasValue("Foo"));
+  // Matches call of Foo(int)
+  TestMatch MatchB = matchCode(
+  Code, cxxFunctionalCastExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchB), HasValue("Foo"));
+  // Matches call of Foo(int, int)
+  TestMatch MatchC = matchCode(
+  Code, cxxTemporaryObjectExpr(hasTypeLoc(typeLoc().bind(CtorTy;
+  EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchC), HasValue("Foo"));
+}
+
 

[PATCH] D102030: [clang][Fuchsia] Introduce compat multilibs

2021-05-10 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Driver/ToolChains/Fuchsia.cpp:245
   .flag("+fno-exceptions"));
+  // Use the default Itanium C++ ABI.
+  Multilibs.push_back(Multilib("compat", {}, {}, 
12).flag("+fc++-abi=itanium"));




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102030

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


[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

In D102015#2743634 , @rjmccall wrote:

> Objective-C object types also have aggregate evaluation kind.  Those can only 
> be used as value types in an old, fragile ObjC ABI, but I believe we haven't 
> yet formally decided to remove support for that.  Fortunately, however, 
> there's a much better simplification available: this 
> `hasAggregateEvaluationKind(Ty)` call is literally doing nothing that 
> couldn't just be a `getAs()` call, and then we don't need to 
> worry about it.

If you're confident that only RecordTypes need to be destroyed, sure.

Did some grepping, and there's some other places using 
isParamDestroyedInCallee(); I'll make sure they're also okay.

> ...I'm confused about why this code is doing what it's doing with cleanups, 
> though.  Why does it only apply when the parameter is indirect?  I believe 
> `isParamDestroyedInCallee()` can apply to types that are passed in other 
> ways, so where we pushing the destructor for those, and why isn't it good 
> enough to handle this case as well?

Objects with a non-trivial destructor end up indirect anyway under the normal 
ABI rules.  Not sure how it interacts with trivial_abi; I'll look into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

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


[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 344119.
Meinersbur added a comment.

- Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/tile_codegen.cpp
  clang/test/OpenMP/tile_codegen_for_dependent.cpp
  clang/test/OpenMP/tile_codegen_for_multiple.cpp

Index: clang/test/OpenMP/tile_codegen_for_multiple.cpp
===
--- /dev/null
+++ clang/test/OpenMP/tile_codegen_for_multiple.cpp
@@ -0,0 +1,248 @@
+// Check code generation
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-pch -o %t %s
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+// expected-no-diagnostics
+
+// Account for multiple transformations of a loop before consumed by
+// #pragma omp for.
+
+#ifndef HEADER
+#define HEADER
+
+// placeholder for loop body code.
+extern "C" void body(...) {}
+
+
+// IR-LABEL: @func(
+// IR-NEXT:  [[ENTRY:.*]]:
+// IR-NEXT:%[[START_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[END_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[STEP_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_1:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_2:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_3:.+]] = alloca i32, align 4
+// IR-NEXT:%[[I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_6:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_8:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_12:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_14:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_LB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_UB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_STRIDE:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IS_LAST:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I18:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP0:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
+// IR-NEXT:store i32 %[[START:.+]], i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[END:.+]], i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[STEP:.+]], i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:%[[TMP1:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP1]], i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[TMP2:.+]] = load i32, i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP2]], i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP3:.+]] = load i32, i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP3]], i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[TMP4:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP5:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[SUB:.+]] = sub i32 %[[TMP4]], %[[TMP5]]
+// IR-NEXT:%[[SUB4:.+]] = sub i32 %[[SUB]], 1
+// IR-NEXT:%[[TMP6:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[ADD:.+]] = add i32 %[[SUB4]], %[[TMP6]]
+// IR-NEXT:%[[TMP7:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP7]]
+// IR-NEXT:%[[SUB5:.+]] = sub i32 %[[DIV]], 1
+// IR-NEXT:store i32 %[[SUB5]], i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[TMP8:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP8]], i32* %[[I]], align 4
+// IR-NEXT:%[[TMP9:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_3]], align 4
+// IR-NEXT:%[[ADD7:.+]] = add i32 %[[TMP9]], 1
+// IR-NEXT:store i32 %[[ADD7]], i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[TMP10:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_6]], align 4
+// IR-NEXT:%[[SUB9:.+]] = sub i32 %[[TMP10]], -3
+// IR-NEXT:%[[DIV10:.+]] = udiv i32 %[[SUB9]], 4
+// IR-NEXT:%[[SUB11:.+]] = sub i32 %[[DIV10]], 1
+// IR-NEXT:store i32 %[[SUB11]], i32* %[[DOTCAPTURE_EXPR_8]], align 4
+// IR-NEXT:store i32 0, i32* %[[DOTFLOOR_0_IV_I]], 

[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: clang/lib/AST/StmtOpenMP.cpp:128-129
+llvm::function_ref Callback,
+llvm::function_ref
+OnTransformationCallback) {
   CurStmt = CurStmt->IgnoreContainers();

ABataev wrote:
> Do we need `bool` return in the callback? I see that it returns `false` 
> always.
I added it to be consistent with the other callback. Going to remove it.



Comment at: clang/lib/AST/StmtOpenMP.cpp:132-140
+while (true) {
+  if (auto *Dir = dyn_cast(CurStmt)) {
+if (OnTransformationCallback(Dir))
+  return false;
+CurStmt = Dir->getTransformedStmt();
+continue;
+  }

ABataev wrote:
> ```
> while (auto *Dir = dyn_cast(CurStmt)) {
>   if (OnTransformationCallback(Dir))
> return false;
>   CurStmt = Dir->getTransformedStmt();
> }
> ```
With OMPUnrollDirective added, there are two conditions of the while loop. Of 
course, I can change the structure again with the unroll patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

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


[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/AST/StmtOpenMP.cpp:128-129
+llvm::function_ref Callback,
+llvm::function_ref
+OnTransformationCallback) {
   CurStmt = CurStmt->IgnoreContainers();

Do we need `bool` return in the callback? I see that it returns `false` always.



Comment at: clang/lib/AST/StmtOpenMP.cpp:132-140
+while (true) {
+  if (auto *Dir = dyn_cast(CurStmt)) {
+if (OnTransformationCallback(Dir))
+  return false;
+CurStmt = Dir->getTransformedStmt();
+continue;
+  }

```
while (auto *Dir = dyn_cast(CurStmt)) {
  if (OnTransformationCallback(Dir))
return false;
  CurStmt = Dir->getTransformedStmt();
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102180

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


[PATCH] D102180: [Clang][OpenMP] Emit dependent PreInits before directive.

2021-05-10 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur created this revision.
Meinersbur added a reviewer: ABataev.
Meinersbur added projects: OpenMP, clang.
Herald added subscribers: guansong, yaxunl.
Meinersbur requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

The PreInits of a loop transformation (atm moment only tile) include the 
computation of the trip count. The trip count is needed by any loop-associated 
directives that consumes the transformation-generated loop. Hence, we must 
ensure that the PreInits of consumed loop transformations are emitted with the 
consuming directive.

This is done by addinging the inner loop transformation's PreInits to the outer 
loop-directive's PreInits. The outer loop-directive will consume the de-sugared 
AST such that the inner PreInits are not emitted twice. The PreInits of a loop 
transformation are still emitted directly if its generated loop(s) are not 
associated with another loop-associated directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102180

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/tile_codegen.cpp
  clang/test/OpenMP/tile_codegen_for_dependent.cpp
  clang/test/OpenMP/tile_codegen_for_multiple.cpp

Index: clang/test/OpenMP/tile_codegen_for_multiple.cpp
===
--- /dev/null
+++ clang/test/OpenMP/tile_codegen_for_multiple.cpp
@@ -0,0 +1,248 @@
+// Check code generation
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -emit-pch -o %t %s
+// RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
+// expected-no-diagnostics
+
+// Account for multiple transformations of a loop before consumed by
+// #pragma omp for.
+
+#ifndef HEADER
+#define HEADER
+
+// placeholder for loop body code.
+extern "C" void body(...) {}
+
+
+// IR-LABEL: @func(
+// IR-NEXT:  [[ENTRY:.*]]:
+// IR-NEXT:%[[START_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[END_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[STEP_ADDR:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_1:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_2:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_3:.+]] = alloca i32, align 4
+// IR-NEXT:%[[I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_6:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_8:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_12:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTCAPTURE_EXPR_14:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_LB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_UB:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_STRIDE:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTOMP_IS_LAST:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTFLOOR_0_IV__FLOOR_0_IV_I18:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV__FLOOR_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[DOTTILE_0_IV_I:.+]] = alloca i32, align 4
+// IR-NEXT:%[[TMP0:.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
+// IR-NEXT:store i32 %[[START:.+]], i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[END:.+]], i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[STEP:.+]], i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:%[[TMP1:.+]] = load i32, i32* %[[START_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP1]], i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[TMP2:.+]] = load i32, i32* %[[END_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP2]], i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP3:.+]] = load i32, i32* %[[STEP_ADDR]], align 4
+// IR-NEXT:store i32 %[[TMP3]], i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[TMP4:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_1]], align 4
+// IR-NEXT:%[[TMP5:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_]], align 4
+// IR-NEXT:%[[SUB:.+]] = sub i32 %[[TMP4]], %[[TMP5]]
+// IR-NEXT:%[[SUB4:.+]] = sub i32 %[[SUB]], 1
+// IR-NEXT:%[[TMP6:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[ADD:.+]] = add i32 %[[SUB4]], %[[TMP6]]
+// IR-NEXT:%[[TMP7:.+]] = load i32, i32* %[[DOTCAPTURE_EXPR_2]], align 4
+// IR-NEXT:%[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP7]]
+// IR-NEXT:

[PATCH] D102122: Support warn_unused_result on typedefs

2021-05-10 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D102122#2748206 , @aaron.ballman 
wrote:

> Let me start off by saying: thanks, I think this is really useful 
> functionality. As a ridiculously obvious example, Annex K has an integer type 
> alias `errno_t` and it would incredibly handy to be able to mark that as 
> `[[nodiscard]]` to strongly encourage checking for errors for functions that 
> return that type (not that we support Annex K, but the general idea extends 
> to any integer-based error type).
>
> That said, there are multiple different ways to spell the same semantic 
> attribute, and it's not clear to me that we want to change them all the same 
> way.
>
> `[[clang::warn_unused_result]]` is ours to do with as we please, so there's 
> no issue changing that behavior.
>
> `__attribute__((warn_unused_result))` and `[[gnu::warn_unused_result]]` are 
> governed by GCC and we try to be compatible with their behavior. GCC does not 
> appear to support the attribute on typedefs from my testing, so we'd want to 
> coordinate with the GCC folks to see if there's an appetite for the change.

FWIW, looks like we already diverge from GCC's behavior - GCC doesn't seem to 
support this attribute on types at all: https://godbolt.org/z/8YjqnE4cv (but 
does support [[nodiscard]] in that place)

> `[[nodiscard]]` is governed by both the C++ and C standards and we should not 
> be changing its behavior without some extra diagnostics about extensions 
> (and, preferably, some sort of attempt to standardize the behavior with 
> WG14/WG21).

Might be a compatible extension, though - to use a standard attribute in a 
non-standard context? (at least clang and gcc only warn on putting 
[[nodiscard]] in non-standard places, they don't error)

> Do you have an appetite to talk to the GCC and standards folks?

Medium interest.

> If not, then I think the safest bet is to only change the behavior for the 
> `[[clang::warn_unused_result]]` and to leave the other forms alone for now.

Happy to go either way.

Is there an easy/recommended way to split these things up? Duplicate the 
records in the td/come up with separate names, etc?)

> In D102122#2746426 , @dblaikie 
> wrote:
>
>> Fixes for a few other test cases (though I wonder if these tests are 
>> overconstrained - do we need to be testing the list of things this attribute 
>> can be applied to in so many places?)
>
> If the semantics of the attribute are identical regardless of how it's 
> spelled, then we probably don't need the tests all spread out in multiple 
> files. However, I don't think there's an intention to keep all of the 
> spellings with identical semantics, so the different tests might still make 
> sense (but could perhaps be cleaned up).
>
> In D102122#2746424 , @dblaikie 
> wrote:
>
>> Oh, one question: If we do move forward with this patch, how would we detect 
>> that the compiler supports this new use of warn_unused_result? (so that the 
>> feature detection macros in LLVM properly make the attribute a no-op unless 
>> we have a version of clang that supports it)
>
> `__has_[c|cpp]_attribute` returns a value, so we'd likely wind up using that 
> return value to distinguish between versions.

Hmm - what if we end up with different behavior for the different spellings of 
the attribute (as GCC does)? Can we check them separately?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

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


[PATCH] D100798: [clangd][ObjC] Fix issue completing a method decl by name

2021-05-10 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

Friendly ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100798

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


[PATCH] D102122: Support warn_unused_result on typedefs

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Let me start off by saying: thanks, I think this is really useful 
functionality. As a ridiculously obvious example, Annex K has an integer type 
alias `errno_t` and it would incredibly handy to be able to mark that as 
`[[nodiscard]]` to strongly encourage checking for errors for functions that 
return that type (not that we support Annex K, but the general idea extends to 
any integer-based error type).

That said, there are multiple different ways to spell the same semantic 
attribute, and it's not clear to me that we want to change them all the same 
way.

`[[clang::warn_unused_result]]` is ours to do with as we please, so there's no 
issue changing that behavior.

`__attribute__((warn_unused_result))` and `[[gnu::warn_unused_result]]` are 
governed by GCC and we try to be compatible with their behavior. GCC does not 
appear to support the attribute on typedefs from my testing, so we'd want to 
coordinate with the GCC folks to see if there's an appetite for the change.

`[[nodiscard]]` is governed by both the C++ and C standards and we should not 
be changing its behavior without some extra diagnostics about extensions (and, 
preferably, some sort of attempt to standardize the behavior with WG14/WG21).

Do you have an appetite to talk to the GCC and standards folks? If not, then I 
think the safest bet is to only change the behavior for the 
`[[clang::warn_unused_result]]` and to leave the other forms alone for now.

In D102122#2746426 , @dblaikie wrote:

> Fixes for a few other test cases (though I wonder if these tests are 
> overconstrained - do we need to be testing the list of things this attribute 
> can be applied to in so many places?)

If the semantics of the attribute are identical regardless of how it's spelled, 
then we probably don't need the tests all spread out in multiple files. 
However, I don't think there's an intention to keep all of the spellings with 
identical semantics, so the different tests might still make sense (but could 
perhaps be cleaned up).

In D102122#2746424 , @dblaikie wrote:

> Oh, one question: If we do move forward with this patch, how would we detect 
> that the compiler supports this new use of warn_unused_result? (so that the 
> feature detection macros in LLVM properly make the attribute a no-op unless 
> we have a version of clang that supports it)

`__has_[c|cpp]_attribute` returns a value, so we'd likely wind up using that 
return value to distinguish between versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

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


[PATCH] D101873: [clang] Support clang -fpic -fno-semantic-interposition for AArch64

2021-05-10 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG68a20c7f36d1: [clang] Support -fpic 
-fno-semantic-interposition for AArch64 (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101873

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fsemantic-interposition.c


Index: clang/test/Driver/fsemantic-interposition.c
===
--- clang/test/Driver/fsemantic-interposition.c
+++ clang/test/Driver/fsemantic-interposition.c
@@ -10,6 +10,7 @@
 
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
+// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
@@ -20,8 +21,8 @@
 /// local aliases, use the traditional half-baked behavor: interprocedural
 /// optimizations are allowed but local aliases are not used. If references are
 /// not optimized out, semantic interposition at runtime is possible.
-// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
 // RUN: %clang -target ppc64le %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
 
 // RUN: %clang -target x86_64 %s -Werror -fPIC -c -### 2>&1 | FileCheck 
--check-prefix=HALF %s
 //
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4722,7 +4722,7 @@
  options::OPT_fno_semantic_interposition);
 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
   // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-  bool SupportsLocalAlias = Triple.isX86();
+  bool SupportsLocalAlias = Triple.isAArch64() || Triple.isX86();
   if (!A)
 CmdArgs.push_back("-fhalf-no-semantic-interposition");
   else if (A->getOption().matches(options::OPT_fsemantic_interposition))


Index: clang/test/Driver/fsemantic-interposition.c
===
--- clang/test/Driver/fsemantic-interposition.c
+++ clang/test/Driver/fsemantic-interposition.c
@@ -10,6 +10,7 @@
 
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
+// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
@@ -20,8 +21,8 @@
 /// local aliases, use the traditional half-baked behavor: interprocedural
 /// optimizations are allowed but local aliases are not used. If references are
 /// not optimized out, semantic interposition at runtime is possible.
-// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=HALF %s
 // RUN: %clang -target ppc64le %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=HALF %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=HALF %s
 
 // RUN: %clang -target x86_64 %s -Werror -fPIC -c -### 2>&1 | FileCheck --check-prefix=HALF %s
 //
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4722,7 +4722,7 @@
  options::OPT_fno_semantic_interposition);
 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
   // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-  bool SupportsLocalAlias = Triple.isX86();
+  bool SupportsLocalAlias = Triple.isAArch64() || Triple.isX86();
   if (!A)
 CmdArgs.push_back("-fhalf-no-semantic-interposition");
   else if (A->getOption().matches(options::OPT_fsemantic_interposition))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 68a20c7 - [clang] Support -fpic -fno-semantic-interposition for AArch64

2021-05-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-05-10T09:43:33-07:00
New Revision: 68a20c7f36d1d51cc46c0bd17384c16bc7818fa2

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

LOG: [clang] Support -fpic -fno-semantic-interposition for AArch64

-fno-semantic-interposition (only effective with -fpic) can optimize default
visibility external linkage (non-ifunc-non-COMDAT) variable access and function
calls to avoid GOT/PLT, by using local aliases, e.g.
```
int var;
__attribute__((optnone)) int fun(int x) { return x * x; }
int test() { return fun(var); }
```

-fpic (var and fun are dso_preemptable)
```
test:   // @test
adrpx8, :got:var
ldr x8, [x8, :got_lo12:var]
ldr w0, [x8]
// fun is preemptible by default in ld -shared mode. ld will create a PLT.
b   fun
```

vs -fpic -fno-semantic-interposition (var and fun are dso_local)
```
test:   // @test
.Ltest$local:
adrpx8, .Lvar$local
ldr w0, [x8, :lo12:.Lvar$local]
// The assembler either resolves .Lfun$local at assembly time, or produces a
// relocation referencing a non-preemptible section symbol (which can avoid 
PLT).
b   .Lfun$local
```

Note: Clang's default -fpic is more aggressive than GCC -fpic: interprocedural
optimizations (including inlining) are available but local aliases are not used.
-fpic -fsemantic-interposition can disable interprocedural optimizations.

Depends on D101872

Reviewed By: peter.smith

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fsemantic-interposition.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 97a92e69419fa..c4ea67ea93660 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4722,7 +4722,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
  options::OPT_fno_semantic_interposition);
 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
   // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-  bool SupportsLocalAlias = Triple.isX86();
+  bool SupportsLocalAlias = Triple.isAArch64() || Triple.isX86();
   if (!A)
 CmdArgs.push_back("-fhalf-no-semantic-interposition");
   else if (A->getOption().matches(options::OPT_fsemantic_interposition))

diff  --git a/clang/test/Driver/fsemantic-interposition.c 
b/clang/test/Driver/fsemantic-interposition.c
index af76daf7e1be4..3060e8a49b20a 100644
--- a/clang/test/Driver/fsemantic-interposition.c
+++ b/clang/test/Driver/fsemantic-interposition.c
@@ -10,6 +10,7 @@
 
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
+// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
@@ -20,8 +21,8 @@
 /// local aliases, use the traditional half-baked behavor: interprocedural
 /// optimizations are allowed but local aliases are not used. If references are
 /// not optimized out, semantic interposition at runtime is possible.
-// RUN: %clang -target aarch64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
 // RUN: %clang -target ppc64le %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c 
-### 2>&1 | FileCheck --check-prefix=HALF %s
 
 // RUN: %clang -target x86_64 %s -Werror -fPIC -c -### 2>&1 | FileCheck 
--check-prefix=HALF %s
 //



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


[PATCH] D101479: [Driver] Support libc++ in MSVC

2021-05-10 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth added a comment.

In D101479#2733354 , @mstorsjo wrote:

> Not sure if we want the desicion between static and shared libc++ be coupled 
> with `/MT` and `/MD`, as one can quite plausibly want to use e.g. a static 
> libc++ with `/MD`.

I don't understand this.  When would someone want to use `/MD` and not get the 
DLL version of the run-time libraries?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101479

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


[PATCH] D100509: Support GCC's -fstack-usage flag

2021-05-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:110
 CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when -fstack-size-section is 
enabled.
+CODEGENOPT(StackUsage, 1, 0) ///< Set when -fstack-usage is enabled.
 CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is

Unneeded



Comment at: clang/test/CodeGen/stack-usage.c:7
+
+// CHECK: stack-usage.c:8:foo  {{[0-9]+}}  static
+int foo() {

`8` -> `[[#@LINE+1]]`



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1212
+
+  *StackUsageStream << ":" << MF.getName() << "\t" << StackSize << "\t";
+  if (FrameInfo.hasVarSizedObjects())

`""` -> `''`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100509

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


[PATCH] D102094: [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

2021-05-10 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA marked an inline comment as done.
ZarkoCA added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1854
 const Option  = A->getOption();
-if (O.matches(OPT_mabi_EQ_vec_default))
-  Diags.Report(diag::err_aix_default_altivec_abi)
-  << A->getSpelling() << T.str();
-else {
-  assert(O.matches(OPT_mabi_EQ_vec_extabi));
+if (O.matches(OPT_mabi_EQ_vec_extabi))
   Opts.EnableAIXExtendedAltivecABI = 1;

jansvoboda11 wrote:
> Can we simplify this to `Opts.EnableAIXExtendedAltivecABI = 
> O.matches(OPT_mabi_EQ_vec_extabi);`?
Thanks, that works well. 


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

https://reviews.llvm.org/D102094

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


[PATCH] D102094: [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

2021-05-10 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 344080.
ZarkoCA added a comment.

- Fix previous diff


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

https://reviews.llvm.org/D102094

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/altivec.c
  clang/test/Driver/aix-vec-extabi.c
  clang/test/Preprocessor/aix-vec_extabi.c

Index: clang/test/Preprocessor/aix-vec_extabi.c
===
--- clang/test/Preprocessor/aix-vec_extabi.c
+++ clang/test/Preprocessor/aix-vec_extabi.c
@@ -2,11 +2,11 @@
 // RUN:   | FileCheck %s -check-prefix=EXTABI
 // RUN: %clang  -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-extabi %s -o - 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=EXTABI
-// RUN: not %clang  -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
+// RUN: %clang  -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DFLTABI
-// RUN: not %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -E -dM -maltivec -mabi=vec-default %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DFLTABI
 
 
-// EXTABI:  #define __EXTABI__
-// DFLTABI: The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' for the extended Altivec ABI
+// EXTABI:  #define __EXTABI__
+// DFLTABI-NOT: #define __EXTABI__
Index: clang/test/Driver/aix-vec-extabi.c
===
--- clang/test/Driver/aix-vec-extabi.c
+++ clang/test/Driver/aix-vec-extabi.c
@@ -1,10 +1,11 @@
 // RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-extabi %s 2>&1 | \
-// RUN:  FileCheck %s
-
-// CHECK: "-cc1"
-// CHECK-SAME: "-mabi=vec-extabi"
-
+// RUN:  FileCheck %s --check-prefix=EXTABI
 // RUN:  %clang -### -target powerpc-unknown-aix -S -maltivec -mabi=vec-default %s 2>&1 | \
-// RUN:  FileCheck %s --check-prefix=ERROR
+// RUN:  FileCheck %s --check-prefix=DFLTABI
+
+// EXTABI:   "-cc1"
+// EXTABI-SAME:  "-mabi=vec-extabi"
 
-// ERROR: The default Altivec ABI on AIX is not yet supported, use '-mabi=vec-extabi' for the extended Altivec ABI
+// DFLTABI:  "-cc1"
+// DFLTABI-SAME: "-mabi=vec-default"
+// DFLTABI-NOT:  "-mabi=vec-default"
Index: clang/test/CodeGen/altivec.c
===
--- clang/test/CodeGen/altivec.c
+++ clang/test/CodeGen/altivec.c
@@ -4,12 +4,12 @@
 // RUN: %clang_cc1 -target-feature +altivec -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 -triple powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang_cc1 -target-feature +altivec -mabi=vec-extabi -target-cpu pwr8 -triple powerpc64-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: not %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc64-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target powerpc-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 -target powerpc64-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: not %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 -triple powerpc-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
-// RUN: not %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 -triple powerpc64-unknown-aix -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=AIX-ERROR
+// RUN: %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang_cc1 -target-feature +altivec -mabi=vec-default -target-cpu pwr8 -triple powerpc64-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 --target=powerpc-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-extabi -mcpu=pwr8 --target=powerpc64-unknown-aix %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -S -emit-llvm -maltivec -mabi=vec-default -mcpu=pwr8 --target=powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: 

[PATCH] D102094: [AIX][PowerPC] Remove error when specifying mabi=vec-default on AIX

2021-05-10 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 344078.
ZarkoCA edited the summary of this revision.
ZarkoCA added a comment.

- Simplify option logic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102094

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1851,12 +1851,7 @@
   << A->getSpelling() << T.str();
 
 const Option  = A->getOption();
-if (O.matches(OPT_mabi_EQ_vec_extabi))
-  Opts.EnableAIXExtendedAltivecABI = 1;
-else if (O.matches(OPT_mabi_EQ_vec_default))
-  Opts.EnableAIXExtendedAltivecABI = 0;
-else
-  Opts.EnableAIXExtendedAltivecABI = 0;
+Opts.EnableAIXExtendedAltivecABI = O.matches(OPT_mabi_EQ_vec_extabi);
   }
 
   bool NeedLocTracking = false;


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1851,12 +1851,7 @@
   << A->getSpelling() << T.str();
 
 const Option  = A->getOption();
-if (O.matches(OPT_mabi_EQ_vec_extabi))
-  Opts.EnableAIXExtendedAltivecABI = 1;
-else if (O.matches(OPT_mabi_EQ_vec_default))
-  Opts.EnableAIXExtendedAltivecABI = 0;
-else
-  Opts.EnableAIXExtendedAltivecABI = 0;
+Opts.EnableAIXExtendedAltivecABI = O.matches(OPT_mabi_EQ_vec_extabi);
   }
 
   bool NeedLocTracking = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102164: [NFC] Syndicate reserved identifier code between macro and variables / symbols

2021-05-10 Thread serge 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 rG91a919e8994a: [NFC] Synchronize reserved identifier code 
between macro and variables / symbols (authored by serge-sans-paille).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102164

Files:
  clang/lib/Lex/PPDirectives.cpp


Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -100,26 +100,6 @@
   MD_ReservedMacro  //> #define of #undef reserved id, disabled by default
 };
 
-/// Checks if the specified identifier is reserved in the specified
-/// language.
-/// This function does not check if the identifier is a keyword.
-static bool isReservedId(StringRef Text, const LangOptions ) {
-  // C++ [macro.names], C11 7.1.3:
-  // All identifiers that begin with an underscore and either an uppercase
-  // letter or another underscore are always reserved for any use.
-  if (Text.size() >= 2 && Text[0] == '_' &&
-  (isUppercase(Text[1]) || Text[1] == '_'))
-  return true;
-  // C++ [global.names]
-  // Each name that contains a double underscore ... is reserved to the
-  // implementation for any use.
-  if (Lang.CPlusPlus) {
-if (Text.find("__") != StringRef::npos)
-  return true;
-  }
-  return false;
-}
-
 // The -fmodule-name option tells the compiler to textually include headers in
 // the specified module, meaning clang won't build the specified module. This 
is
 // useful in a number of situations, for instance, when building a library that
@@ -141,9 +121,9 @@
 
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
+  StringRef Text = II->getName();
   if (II->isKeyword(Lang))
 return MD_KeywordDef;
   if (Lang.CPlusPlus11 && (Text.equals("override") || Text.equals("final")))
@@ -153,9 +133,8 @@
 
 static MacroDiag shouldWarnOnMacroUndef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
   // Do not warn on keyword undef.  It is generally harmless and widely used.
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
   return MD_NoWarn;
 }


Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -100,26 +100,6 @@
   MD_ReservedMacro  //> #define of #undef reserved id, disabled by default
 };
 
-/// Checks if the specified identifier is reserved in the specified
-/// language.
-/// This function does not check if the identifier is a keyword.
-static bool isReservedId(StringRef Text, const LangOptions ) {
-  // C++ [macro.names], C11 7.1.3:
-  // All identifiers that begin with an underscore and either an uppercase
-  // letter or another underscore are always reserved for any use.
-  if (Text.size() >= 2 && Text[0] == '_' &&
-  (isUppercase(Text[1]) || Text[1] == '_'))
-  return true;
-  // C++ [global.names]
-  // Each name that contains a double underscore ... is reserved to the
-  // implementation for any use.
-  if (Lang.CPlusPlus) {
-if (Text.find("__") != StringRef::npos)
-  return true;
-  }
-  return false;
-}
-
 // The -fmodule-name option tells the compiler to textually include headers in
 // the specified module, meaning clang won't build the specified module. This is
 // useful in a number of situations, for instance, when building a library that
@@ -141,9 +121,9 @@
 
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
+  StringRef Text = II->getName();
   if (II->isKeyword(Lang))
 return MD_KeywordDef;
   if (Lang.CPlusPlus11 && (Text.equals("override") || Text.equals("final")))
@@ -153,9 +133,8 @@
 
 static MacroDiag shouldWarnOnMacroUndef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
   // Do not warn on keyword undef.  It is generally harmless and widely used.
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
   return MD_NoWarn;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 91a919e - [NFC] Synchronize reserved identifier code between macro and variables / symbols

2021-05-10 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-05-10T17:46:51+02:00
New Revision: 91a919e8994a2c47b3feaf906f83122776ae2cae

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

LOG: [NFC] Synchronize reserved identifier code between macro and variables / 
symbols

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

Added: 


Modified: 
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index d5cb46f75aec3..469c4e48525cc 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -100,26 +100,6 @@ enum MacroDiag {
   MD_ReservedMacro  //> #define of #undef reserved id, disabled by default
 };
 
-/// Checks if the specified identifier is reserved in the specified
-/// language.
-/// This function does not check if the identifier is a keyword.
-static bool isReservedId(StringRef Text, const LangOptions ) {
-  // C++ [macro.names], C11 7.1.3:
-  // All identifiers that begin with an underscore and either an uppercase
-  // letter or another underscore are always reserved for any use.
-  if (Text.size() >= 2 && Text[0] == '_' &&
-  (isUppercase(Text[1]) || Text[1] == '_'))
-  return true;
-  // C++ [global.names]
-  // Each name that contains a double underscore ... is reserved to the
-  // implementation for any use.
-  if (Lang.CPlusPlus) {
-if (Text.find("__") != StringRef::npos)
-  return true;
-  }
-  return false;
-}
-
 // The -fmodule-name option tells the compiler to textually include headers in
 // the specified module, meaning clang won't build the specified module. This 
is
 // useful in a number of situations, for instance, when building a library that
@@ -141,9 +121,9 @@ static bool isForModuleBuilding(Module *M, StringRef 
CurrentModule,
 
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
+  StringRef Text = II->getName();
   if (II->isKeyword(Lang))
 return MD_KeywordDef;
   if (Lang.CPlusPlus11 && (Text.equals("override") || Text.equals("final")))
@@ -153,9 +133,8 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor , 
IdentifierInfo *II) {
 
 static MacroDiag shouldWarnOnMacroUndef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
-  StringRef Text = II->getName();
   // Do not warn on keyword undef.  It is generally harmless and widely used.
-  if (isReservedId(Text, Lang))
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved)
 return MD_ReservedMacro;
   return MD_NoWarn;
 }



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


[PATCH] D102175: [clang-tidy] performance-unnecessary-copy-initialization: Remove the complete statement when the copied variable is unused.

2021-05-10 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: aaron.ballman, ymandel, hokein.
Herald added a subscriber: xazax.hun.
flx requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

It is not useful to keep the statement around and can lead to compiler
warnings when -Wall (-Wunused-variable specifically) turned on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102175

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -38,60 +38,88 @@
   const auto AutoAssigned = ExpensiveTypeReference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
   // CHECK-FIXES: const auto& AutoAssigned = ExpensiveTypeReference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(ExpensiveTypeReference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveTypeReference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = ExpensiveTypeReference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES:   const ExpensiveToCopyType& VarAssigned = ExpensiveTypeReference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(ExpensiveTypeReference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveTypeReference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType ) {
   const auto AutoAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstParam(const ExpensiveToCopyType Obj) {
   const auto AutoAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
   // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+  AutoCopyConstructed.constMethod();
+
   const ExpensiveToCopyType VarAssigned = Obj.reference();
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
   // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+  VarAssigned.constMethod();
+
   const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
   // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
   // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+  VarCopyConstructed.constMethod();
 }
 
 void PositiveMethodCallConstPointerParam(const ExpensiveToCopyType *const Obj) {
   const auto AutoAssigned = Obj->reference();
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
   // CHECK-FIXES: const auto& AutoAssigned = Obj->reference();
+  AutoAssigned.constMethod();
+
   const auto AutoCopyConstructed(Obj->reference());
   // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 

[PATCH] D99903: [Clang][Sema] better -Wcast-function-type diagnose for pointer parameters and parameters with cv-qualifiers

2021-05-10 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99903

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


Re: [clang] 4a47da2 - [Sema] turns -Wfree-nonheap-object on by default

2021-05-10 Thread David Blaikie via cfe-commits
Christopher - had a chance to look into this any further?

Roman - I'm OK either way on that. I don't think it's the most costly
false positive - not too much code is probably freeing via a reference
(rather than a pointer) to allocated memory.


On Fri, Apr 30, 2021 at 10:08 AM Roman Lebedev  wrote:
>
> Should the diagnostic be backed out until then?
>
> Roman
>
> On Fri, Apr 30, 2021 at 7:52 PM Christopher Di Bella via cfe-commits
>  wrote:
> >
> > Sorry, not yet. I'll talk with my TL to see if I can get some time allotted 
> > for this in the next few weeks.
> >
> > On Thu, 29 Apr 2021 at 16:13, David Blaikie  wrote:
> >>
> >> Ping on this - have you had a chance to look at this false positive?
> >>
> >> On Sat, Apr 3, 2021 at 4:29 PM David Blaikie  wrote:
> >> >
> >> > Looks like this has a false positive (that's firing on some mlir code,
> >> > committed a workaround in  499571ea835daf786626a0db1e12f890b6cd8f8d )
> >> > like this:
> >> >
> >> > $ cat test.cpp
> >> > #include 
> >> > void f1(int & x) { free(); }
> >> > int main() { f1(*(int*)malloc(sizeof(int))); }
> >> >
> >> > Could you fix that? (& then revert the workaround)
> >> >
> >> > On Fri, Jan 15, 2021 at 1:44 PM Christopher Di Bella via cfe-commits
> >> >  wrote:
> >> > >
> >> > >
> >> > > Author: Christopher Di Bella
> >> > > Date: 2021-01-15T21:38:47Z
> >> > > New Revision: 4a47da2cf440c2f2006d9b04acfef4292de1e263
> >> > >
> >> > > URL: 
> >> > > https://github.com/llvm/llvm-project/commit/4a47da2cf440c2f2006d9b04acfef4292de1e263
> >> > > DIFF: 
> >> > > https://github.com/llvm/llvm-project/commit/4a47da2cf440c2f2006d9b04acfef4292de1e263.diff
> >> > >
> >> > > LOG: [Sema] turns -Wfree-nonheap-object on by default
> >> > >
> >> > > We'd discussed adding the warning to -Wall in D89988. This patch 
> >> > > honours that.
> >> > >
> >> > > Added:
> >> > >
> >> > >
> >> > > Modified:
> >> > > clang/include/clang/Basic/DiagnosticGroups.td
> >> > > clang/include/clang/Basic/DiagnosticSemaKinds.td
> >> > > clang/test/Analysis/NewDelete-intersections.mm
> >> > > clang/test/Analysis/free.c
> >> > >
> >> > > Removed:
> >> > >
> >> > >
> >> > >
> >> > > 
> >> > > diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
> >> > > b/clang/include/clang/Basic/DiagnosticGroups.td
> >> > > index d500ab321058..04ba89aa457e 100644
> >> > > --- a/clang/include/clang/Basic/DiagnosticGroups.td
> >> > > +++ b/clang/include/clang/Basic/DiagnosticGroups.td
> >> > > @@ -110,6 +110,7 @@ def FloatConversion :
> >> > >   FloatZeroConversion]>;
> >> > >
> >> > >  def FrameAddress : DiagGroup<"frame-address">;
> >> > > +def FreeNonHeapObject : DiagGroup<"free-nonheap-object">;
> >> > >  def DoublePromotion : DiagGroup<"double-promotion">;
> >> > >  def EnumTooLarge : DiagGroup<"enum-too-large">;
> >> > >  def UnsupportedNan : DiagGroup<"unsupported-nan">;
> >> > >
> >> > > diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
> >> > > b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> >> > > index 7d36397a7993..e93657898f58 100644
> >> > > --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> >> > > +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> >> > > @@ -7609,7 +7609,7 @@ def err_no_typeid_with_fno_rtti : Error<
> >> > >  def err_no_dynamic_cast_with_fno_rtti : Error<
> >> > >"use of dynamic_cast requires -frtti">;
> >> > >  def warn_no_dynamic_cast_with_rtti_disabled: Warning<
> >> > > -  "dynamic_cast will not work since RTTI data is disabled by "
> >> > > +  "dynamic_cast will not work since RTTI data is disabled by "
> >> > >"%select{-fno-rtti-data|/GR-}0">, InGroup;
> >> > >  def warn_no_typeid_with_rtti_disabled: Warning<
> >> > >"typeid will not work since RTTI data is disabled by "
> >> > > @@ -7625,8 +7625,7 @@ def warn_condition_is_assignment : 
> >> > > Warning<"using the result of an "
> >> > >InGroup;
> >> > >  def warn_free_nonheap_object
> >> > >: Warning<"attempt to call %0 on non-heap object %1">,
> >> > > -InGroup>,
> >> > > -DefaultIgnore; // FIXME: add to -Wall after sufficient testing
> >> > > +InGroup;
> >> > >
> >> > >  // Completely identical except off by default.
> >> > >  def warn_condition_is_idiomatic_assignment : Warning<"using the 
> >> > > result "
> >> > >
> >> > > diff  --git a/clang/test/Analysis/NewDelete-intersections.mm 
> >> > > b/clang/test/Analysis/NewDelete-intersections.mm
> >> > > index f01d62f8d365..6f81034ee349 100644
> >> > > --- a/clang/test/Analysis/NewDelete-intersections.mm
> >> > > +++ b/clang/test/Analysis/NewDelete-intersections.mm
> >> > > @@ -24,9 +24,6 @@
> >> > >  extern "C" void free(void *);
> >> > >
> >> > >  void testMallocFreeNoWarn() {
> >> > > -  int i;
> >> > > -  free(); // no warn
> >> > > -
> >> > >int *p1 = (int *)malloc(sizeof(int));
> >> > >free(++p1); // no warn
> >> > >
> >> > > @@ -51,7 +48,7 @@ void 

[PATCH] D102070: [AIX][TLS] Diagnose use of unimplemented TLS models

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from the single quotes in the diagnostic.




Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:548
 
+def err_aix_unsupported_tls_model : Error<"The tls model %0 is not yet 
supported on AIX">;
+

aaron.ballman wrote:
> This neatly avoids the problem of diagnostics not starting with a capital 
> letter (it looks like we have other diagnostics to update, but that's not 
> your problem to deal with).
Can you also add the single quotes around the %0 so that the diagnostic is 
properly quoted?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3154
 
+def err_aix_attr_unsupported_tls_model : Error<"The tls model %0 is not yet 
supported on AIX">;
+

aaron.ballman wrote:
> 
Same here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102070

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


[PATCH] D102164: [NFC] Syndicate reserved identifier code between macro and variables / symbols

2021-05-10 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! You probably should change `Syndicate` to `Synchronize` in the commit 
message when you land it, though.


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

https://reviews.llvm.org/D102164

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


[PATCH] D100853: [clang][AArch32] Correctly align HA arguments when passed on the stack

2021-05-10 Thread Momchil Velikov 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 rG5c7b43aa8298: [clang][AArch32] Correctly align HA arguments 
when passed on the stack (authored by chill).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100853

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm-ha-alignstack.c
  llvm/lib/Target/ARM/ARMCallingConv.cpp
  llvm/test/CodeGen/ARM/ha-alignstack-call.ll
  llvm/test/CodeGen/ARM/ha-alignstack.ll

Index: llvm/test/CodeGen/ARM/ha-alignstack.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARM/ha-alignstack.ll
@@ -0,0 +1,190 @@
+; RUN: llc --mtriple armv7-eabihf %s -o - | FileCheck %s
+
+%struct.S0 = type { [4 x float] }
+%struct.S1 = type { [2 x float] }
+%struct.S2 = type { [4 x float] }
+%struct.D0 = type { [2 x double] }
+%struct.D1 = type { [2 x double] }
+%struct.D2 = type { [4 x double] }
+
+; pass in registers
+define dso_local float @f0_0(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, %struct.S0 %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S0 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f0_0:
+; CHECK:   vmov.f32 s0, s12
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, no memory/regs split
+define dso_local float @f0_1(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, float %x, %struct.S0 %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S0 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f0_1:
+; CHECK:   vldr s0, [sp]
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, alignment 4
+define dso_local float @f0_2(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, double %d6, double %d7, float %x, %struct.S0 %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S0 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f0_2:
+; CHECK:   vldr s0, [sp, #4]
+; CHECK-NEXT:  bx   lr
+
+; pass in registers
+define dso_local float @f1_0(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, double %d6, %struct.S1 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S1 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f1_0:
+; CHECK:   vmov.f32 s0, s14
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, no memory/regs split
+define dso_local float @f1_1(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, double %d6, float %x, %struct.S1 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S1 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f1_1:
+; CHECK:   vldr s0, [sp]
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, alignment 8
+define dso_local float @f1_2(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, double %d6, double %d7, float %x, %struct.S1 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S1 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f1_2:
+; CHECK:   vldr s0, [sp, #8]
+; CHECK-NEXT:  bx   lr
+
+; pass in registers
+define dso_local float @f2_0(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, %struct.S2 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S2 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f2_0:
+; CHECK:   vmov.f32 s0, s12
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, no memory/regs split
+define dso_local float @f2_1(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, float %x, %struct.S2 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S2 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f2_1:
+; CHECK:   vldr s0, [sp]
+; CHECK-NEXT:  bx   lr
+
+; pass in memory, alignment 8
+define dso_local float @f2_2(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, double %d6, double %d7, float %x, %struct.S2 alignstack(8) %s.coerce) local_unnamed_addr #0 {
+entry:
+  %s.coerce.fca.0.0.extract = extractvalue %struct.S2 %s.coerce, 0, 0
+  ret float %s.coerce.fca.0.0.extract
+}
+; CHECK-LABEL: f2_2:
+; CHECK:   vldr s0, [sp, #8]
+; CHECK-NEXT:  bx   lr
+
+; pass in registers
+define dso_local double @g0_0(double %d0, double %d1, double %d2, double %d3, double %d4, double %d5, %struct.D0 %s.coerce) local_unnamed_addr #0 {
+entry:
+  

[clang] 5c7b43a - [clang][AArch32] Correctly align HA arguments when passed on the stack

2021-05-10 Thread Momchil Velikov via cfe-commits

Author: Momchil Velikov
Date: 2021-05-10T16:28:46+01:00
New Revision: 5c7b43aa8298a389b906d72c792941a0ce57782e

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

LOG: [clang][AArch32] Correctly align HA arguments when passed on the stack

Analogously to https://reviews.llvm.org/D98794 this patch uses the
`alignstack` attribute to fix incorrect passing of homogeneous
aggregate (HA) arguments on AArch32. The EABI/AAPCS was recently
updated to clarify how VFP co-processor candidates are aligned:
https://github.com/ARM-software/abi-aa/commit/4488e34998514dc7af5507236f279f6881eede62

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

Added: 
clang/test/CodeGen/arm-ha-alignstack.c
llvm/test/CodeGen/ARM/ha-alignstack-call.ll
llvm/test/CodeGen/ARM/ha-alignstack.ll

Modified: 
clang/lib/CodeGen/TargetInfo.cpp
llvm/lib/Target/ARM/ARMCallingConv.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 633b963965ed6..af516bbc8d312 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -6440,7 +6440,16 @@ ABIArgInfo 
ARMABIInfo::classifyHomogeneousAggregate(QualType Ty,
   return ABIArgInfo::getDirect(Ty, 0, nullptr, false);
 }
   }
-  return ABIArgInfo::getDirect(nullptr, 0, nullptr, false);
+  unsigned Align = 0;
+  if (getABIKind() == ARMABIInfo::AAPCS ||
+  getABIKind() == ARMABIInfo::AAPCS_VFP) {
+// For alignment adjusted HFAs, cap the argument alignment to 8, leave it
+// default otherwise.
+Align = getContext().getTypeUnadjustedAlignInChars(Ty).getQuantity();
+unsigned BaseAlign = getContext().getTypeAlignInChars(Base).getQuantity();
+Align = (Align > BaseAlign && Align >= 8) ? 8 : 0;
+  }
+  return ABIArgInfo::getDirect(nullptr, 0, nullptr, false, Align);
 }
 
 ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,

diff  --git a/clang/test/CodeGen/arm-ha-alignstack.c 
b/clang/test/CodeGen/arm-ha-alignstack.c
new file mode 100644
index 0..a4f7e4af2f13a
--- /dev/null
+++ b/clang/test/CodeGen/arm-ha-alignstack.c
@@ -0,0 +1,114 @@
+// RUN: %clang_cc1 -triple armv7-eabi
-emit-llvm %s -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SOFT
+// RUN: %clang_cc1 -triple armv7-eabi -target-abi aapcs -mfloat-abi hard 
-emit-llvm %s -o - | \
+// RUN:FileCheck %s --check-prefixes=CHECK,CHECK-HARD
+// REQUIRES: arm-registered-target
+
+// CHECK: %struct.S0 = type { [4 x float] }
+// CHECK: %struct.S1 = type { [2 x float] }
+// CHECK: %struct.S2 = type { [4 x float] }
+// CHECK: %struct.D0 = type { [2 x double] }
+// CHECK: %struct.D1 = type { [2 x double] }
+// CHECK: %struct.D2 = type { [4 x double] }
+
+typedef struct {
+  float v[4];
+} S0;
+
+float f0(S0 s) {
+// CHECK-SOFT: define{{.*}} float @f0([4 x i32]  %s.coerce)
+// CHECK-HARD: define{{.*}} arm_aapcs_vfpcc float @f0(%struct.S0 %s.coerce)
+  return s.v[0];
+}
+
+float f0call() {
+  S0 s = {0.0f, };
+  return f0(s);
+// CHECK-SOFT: call float @f0([4 x i32]
+// CHECK-HARD: call arm_aapcs_vfpcc float @f0(%struct.S0
+}
+
+typedef struct {
+  __attribute__((aligned(8))) float v[2];
+} S1;
+
+float f1(S1 s) {
+// CHECK-SOFT: define{{.*}} float @f1([1 x i64]
+// CHECK-HARD: define{{.*}} arm_aapcs_vfpcc float @f1(%struct.S1 alignstack(8)
+  return s.v[0];
+}
+
+float f1call() {
+  S1 s = {0.0f, };
+  return f1(s);
+// CHECK-SOFT: call float @f1([1 x i64
+// CHECK-HARD: call arm_aapcs_vfpcc float @f1(%struct.S1 alignstack(8)
+}
+
+typedef struct {
+  __attribute__((aligned(16))) float v[4];
+} S2;
+
+float f2(S2 s) {
+// CHECK-SOFT: define{{.*}} float @f2([2 x i64]
+// CHECK-HARD: define{{.*}} arm_aapcs_vfpcc float @f2(%struct.S2 alignstack(8)
+  return s.v[0];
+}
+
+float f2call() {
+  S2 s = {0.0f, };
+  return f2(s);
+// CHECK-SOFT: call float @f2([2 x i64]
+// CHECK-HARD: call arm_aapcs_vfpcc float @f2(%struct.S2 alignstack(8)
+}
+
+typedef struct {
+  double v[2];
+} D0;
+
+double g0(D0 d) {
+// CHECK-SOFT: define{{.*}} double @g0([2 x i64]
+// CHECK-HARD: define{{.*}} arm_aapcs_vfpcc double @g0(%struct.D0 %d.coerce
+  return d.v[0];
+}
+
+double g0call() {
+  D0 d = {0.0, };
+  return g0(d);
+// CHECK-SOFT: call double @g0([2 x i64]
+// CHECK-HARD: call arm_aapcs_vfpcc double @g0(%struct.D0 %1
+}
+
+typedef struct {
+  __attribute__((aligned(16))) double v[2];
+} D1;
+
+double g1(D1 d) {
+// CHECK-SOFT: define{{.*}} double @g1([2 x i64]
+// CHECK-HARD: define{{.*}} arm_aapcs_vfpcc double @g1(%struct.D1 alignstack(8)
+  return d.v[0];
+}
+
+double g1call() {
+  D1 d = {0.0, };
+  return g1(d);
+// CHECK-SOFT: call double @g1([2 x i64]
+// CHECK-HARD: call arm_aapcs_vfpcc double @g1(%struct.D1 alignstack(8)
+}
+
+typedef 

[PATCH] D102147: [Clang][Coroutines] Implement P2014R0 Option 1 behind -fcoroutines-aligned-alloc

2021-05-10 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D102147#2747611 , @ChuanqiXu wrote:

> Since D97915  would fix the problem that the 
> variables in the frame may not be aligned, I think this option 
> `fcoroutines-aligned-alloc` won't affect normal programmers other than 
> language lawyers. Do you think so?

I think that's right that if all a user want is alignment, then 
`fcoroutines-aligned-alloc` may not be necessay. However if they define 
customed aligned allocators/dealllocators, this is needed to make it work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102147

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


[PATCH] D102164: [NFC] Syndicate reserved identifier code between macro and variables / symbols

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: cfe-commits.
aaron.ballman added a comment.

Adding cfe-commits


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

https://reviews.llvm.org/D102164

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


[PATCH] D102168: Use an allow list on reserved macro identifiers

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Lex/PPDirectives.cpp:125
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved) {
+static constexpr std::array ReservedMacro = {
+"_ATFILE_SOURCE",   "_BSD_SOURCE","_FILE_OFFSET_BITS",

aaron.ballman wrote:
> 
Can you add a comment that this list is required to remain in alphabetical 
order (due to the use of `binary_search`) and list the identifiers in long-form 
rather than columns of three (this makes it easier for folks inserting new 
elements into the list)?


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

https://reviews.llvm.org/D102168

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


[PATCH] D102168: Use an allow list on reserved macro identifiers

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Some additional ones to allow from MSDN: `_CRT_SECURE_NO_WARNINGS`, 
`_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES`, `_CRT_NONSTDC_NO_WARNINGS`,  
(https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160).




Comment at: clang/lib/Lex/PPDirectives.cpp:125
+  if (II->isReserved(Lang) != ReservedIdentifierStatus::NotReserved) {
+static constexpr std::array ReservedMacro = {
+"_ATFILE_SOURCE",   "_BSD_SOURCE","_FILE_OFFSET_BITS",




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

https://reviews.llvm.org/D102168

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


[PATCH] D102168: Use an allow list on reserved macro identifiers

2021-05-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a subscriber: cfe-commits.
aaron.ballman added a comment.

Adding cfe-commits.


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

https://reviews.llvm.org/D102168

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


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-05-10 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:369
+def err_opencl_extension_and_feature_differs : Error<
+  "Options %0 and %1 are set to different values which is illegal in OpenCL C 
3.0">;
 }

We don't normally start from the upper case:

`Options` -> `options`

I am thinking we could drop "which is illegal in OpenCL C 3.0" because the fact 
that compiler gives an error indicates that it is illegal. So I find it a bit 
redundant.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:121
 def warn_double_const_requires_fp64 : Warning<
-  "double precision constant requires cl_khr_fp64, casting to single 
precision">;
+  "double precision constant requires %select{cl_khr_fp64|__opencl_c_fp64}0, "
+  "casting to single precision">;

I am thinking that in OpenCL 3 both `cl_khr_fp64` and `__opencl_c_fp64` are 
required. Maybe we should re-word this as follows?




Comment at: clang/lib/Sema/Sema.cpp:306
+// Set conditionally to provide correct diagnostics for 'double' type
+llvm::StringRef FP64Feature(
+getLangOpts().OpenCLVersion >= 300 ? "__opencl_c_fp64" : 
"cl_khr_fp64");

Technically both "__opencl_c_fp64" and "cl_khr_fp64" are required in OpenCL, 
perhaps we should report both in OpenCL 3?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

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


[PATCH] D101775: Fix for Bug 50033 - -fno-temp-file is not respected when creating a pch in clang 12

2021-05-10 Thread Zachary Henkel via Phabricator via cfe-commits
zahen added a comment.

> If no one has ideas in the next few days, I'll "accept" and commit for you. 
> (Feel free to ping me; there's a good chance I'll lose track of this 
> otherwise; usual ping rate is 1x/week, but happy for you to ping me sooner on 
> this...)

@dexonsmith Ping as requested.  Unfortunately I haven't come up with any way to 
get this tested in a cross-platform manner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101775

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


[PATCH] D101911: [OPENMP]Fix PR48851: the locals are not globalized in SPMD mode.

2021-05-10 Thread Alexey Bataev 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 rG230953d5771f: [OPENMP]Fix PR48851: the locals are not 
globalized in SPMD mode. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101911

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp


Index: clang/test/OpenMP/nvptx_SPMD_codegen.cpp
===
--- clang/test/OpenMP/nvptx_SPMD_codegen.cpp
+++ clang/test/OpenMP/nvptx_SPMD_codegen.cpp
@@ -120,10 +120,7 @@
 // CHECK-DAG: [[DISTR_LIGHT]]
 // CHECK-DAG: [[FOR_LIGHT]]
 // CHECK-DAG: [[LIGHT]]
-// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0)
-// CHECK-DAG: [[DISTR_LIGHT]]
-// CHECK-DAG: [[FOR_LIGHT]]
-// CHECK-DAG: [[LIGHT]]
+// CHECK: call void @__kmpc_kernel_init(
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 1)
 // CHECK-DAG: [[DISTR_FULL]]
 // CHECK-DAG: [[FULL]]
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6561,7 +6561,7 @@
 continue;
   // Analyze declarations.
   if (const auto *DS = dyn_cast(S)) {
-if (llvm::all_of(DS->decls(), [](const Decl *D) {
+if (llvm::all_of(DS->decls(), [](const Decl *D) {
   if (isa(D) || isa(D) ||
   isa(D) || isa(D) ||
   isa(D) || isa(D) ||
@@ -6572,10 +6572,7 @@
   const auto *VD = dyn_cast(D);
   if (!VD)
 return false;
-  return VD->isConstexpr() ||
- ((VD->getType().isTrivialType(Ctx) ||
-   VD->getType()->isReferenceType()) &&
-  (!VD->hasInit() || isTrivial(Ctx, VD->getInit(;
+  return VD->hasGlobalStorage() || !VD->isUsed();
 }))
   continue;
   }


Index: clang/test/OpenMP/nvptx_SPMD_codegen.cpp
===
--- clang/test/OpenMP/nvptx_SPMD_codegen.cpp
+++ clang/test/OpenMP/nvptx_SPMD_codegen.cpp
@@ -120,10 +120,7 @@
 // CHECK-DAG: [[DISTR_LIGHT]]
 // CHECK-DAG: [[FOR_LIGHT]]
 // CHECK-DAG: [[LIGHT]]
-// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0)
-// CHECK-DAG: [[DISTR_LIGHT]]
-// CHECK-DAG: [[FOR_LIGHT]]
-// CHECK-DAG: [[LIGHT]]
+// CHECK: call void @__kmpc_kernel_init(
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 1)
 // CHECK-DAG: [[DISTR_FULL]]
 // CHECK-DAG: [[FULL]]
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6561,7 +6561,7 @@
 continue;
   // Analyze declarations.
   if (const auto *DS = dyn_cast(S)) {
-if (llvm::all_of(DS->decls(), [](const Decl *D) {
+if (llvm::all_of(DS->decls(), [](const Decl *D) {
   if (isa(D) || isa(D) ||
   isa(D) || isa(D) ||
   isa(D) || isa(D) ||
@@ -6572,10 +6572,7 @@
   const auto *VD = dyn_cast(D);
   if (!VD)
 return false;
-  return VD->isConstexpr() ||
- ((VD->getType().isTrivialType(Ctx) ||
-   VD->getType()->isReferenceType()) &&
-  (!VD->hasInit() || isTrivial(Ctx, VD->getInit(;
+  return VD->hasGlobalStorage() || !VD->isUsed();
 }))
   continue;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 230953d - [OPENMP]Fix PR48851: the locals are not globalized in SPMD mode.

2021-05-10 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-05-10T06:34:11-07:00
New Revision: 230953d5771f6f3ce6bf86b8bb6ae4d5eb75a218

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

LOG: [OPENMP]Fix PR48851: the locals are not globalized in SPMD mode.

Follow the more general patch for now, do not try to SPMDize the kernel
if the variable is used and local.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/nvptx_SPMD_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 38341cb3288e..fc315b24687c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6561,7 +6561,7 @@ const Stmt 
*CGOpenMPRuntime::getSingleCompoundChild(ASTContext ,
 continue;
   // Analyze declarations.
   if (const auto *DS = dyn_cast(S)) {
-if (llvm::all_of(DS->decls(), [](const Decl *D) {
+if (llvm::all_of(DS->decls(), [](const Decl *D) {
   if (isa(D) || isa(D) ||
   isa(D) || isa(D) ||
   isa(D) || isa(D) ||
@@ -6572,10 +6572,7 @@ const Stmt 
*CGOpenMPRuntime::getSingleCompoundChild(ASTContext ,
   const auto *VD = dyn_cast(D);
   if (!VD)
 return false;
-  return VD->isConstexpr() ||
- ((VD->getType().isTrivialType(Ctx) ||
-   VD->getType()->isReferenceType()) &&
-  (!VD->hasInit() || isTrivial(Ctx, VD->getInit(;
+  return VD->hasGlobalStorage() || !VD->isUsed();
 }))
   continue;
   }

diff  --git a/clang/test/OpenMP/nvptx_SPMD_codegen.cpp 
b/clang/test/OpenMP/nvptx_SPMD_codegen.cpp
index 6c54818e23d5..e000c818c9c2 100644
--- a/clang/test/OpenMP/nvptx_SPMD_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_SPMD_codegen.cpp
@@ -120,10 +120,7 @@ int a;
 // CHECK-DAG: [[DISTR_LIGHT]]
 // CHECK-DAG: [[FOR_LIGHT]]
 // CHECK-DAG: [[LIGHT]]
-// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0)
-// CHECK-DAG: [[DISTR_LIGHT]]
-// CHECK-DAG: [[FOR_LIGHT]]
-// CHECK-DAG: [[LIGHT]]
+// CHECK: call void @__kmpc_kernel_init(
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 1)
 // CHECK-DAG: [[DISTR_FULL]]
 // CHECK-DAG: [[FULL]]



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


[PATCH] D99646: [clang-tidy] misc-avoid-std-io-outside-main: a new check

2021-05-10 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 344043.
mgartmann added a comment.

Revert `ReleaseNotes.rst` to a point where the build worked.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99646

Files:
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.cpp
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.h
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-avoid-std-io-outside-main.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp
@@ -0,0 +1,138 @@
+// RUN: %check_clang_tidy %s misc-avoid-std-io-outside-main %t
+
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+
+struct Ostream {
+  Ostream <<(string Message);
+};
+
+struct Istream {
+  Istream >>(string Message);
+};
+
+Ostream cout{}, wcout{}, cerr{}, wcerr{};
+Istream cin{}, wcin{};
+
+int printf(const char *Format, ...);
+int vprintf(const char *const, ...);
+int puts(const char *Str);
+int putchar(int Character);
+int scanf(const char *Format, ...);
+int getchar(void);
+char *gets(char *Str);
+} // namespace std
+
+int printf(const char *Format, ...);
+int vprintf(const char *const, ...);
+int puts(const char *Str);
+int putchar(int Character);
+int scanf(const char *Format, ...);
+int getchar(void);
+char *gets(char *Str);
+
+namespace arbitrary_namespace {
+std::Ostream cout{};
+std::Istream cin{};
+} // namespace arbitrary_namespace
+
+void anyNonMainFunction() {
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cout << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcout << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cerr << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcerr << "This should trigger the check";
+
+  arbitrary_namespace::cout << "This should not trigger the check"; // OK
+
+  std::string Foo{"bar"};
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cin >> Foo;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcin >> Foo;
+
+  arbitrary_namespace::cin >> Foo; // OK
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::printf("This should trigger the check");
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  printf("This should trigger the check");
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::puts("This should trigger the check");
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  puts("This should trigger the check");
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::putchar('m');
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  putchar('m');
+
+  char Input[5];
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::scanf("%s", Input);
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  scanf("%s", Input);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::getchar();
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be 

[PATCH] D101616: [clangd] Fix data type of WorkDoneProgressReport::percentage

2021-05-10 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

No problem, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101616

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


[PATCH] D101616: [clangd] Fix data type of WorkDoneProgressReport::percentage

2021-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

done, sorry for the delay!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101616

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


[PATCH] D101616: [clangd] Fix data type of WorkDoneProgressReport::percentage

2021-05-10 Thread Kadir Cetinkaya 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 rGf088af37e6b5: [clangd] Fix data type of 
WorkDoneProgressReport::percentage (authored by ckandeler, committed by 
kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101616

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/Protocol.h


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -631,7 +631,7 @@
   ///
   /// The value should be steadily rising. Clients are free to ignore values
   /// that are not following this rule.
-  llvm::Optional percentage;
+  llvm::Optional percentage;
 };
 llvm::json::Value toJSON(const WorkDoneProgressReport &);
 //
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1606,7 +1606,7 @@
 if (Stats.Completed < Stats.Enqueued) {
   assert(Stats.Enqueued > Stats.LastIdle);
   WorkDoneProgressReport Report;
-  Report.percentage = 100.0 * (Stats.Completed - Stats.LastIdle) /
+  Report.percentage = 100 * (Stats.Completed - Stats.LastIdle) /
   (Stats.Enqueued - Stats.LastIdle);
   Report.message =
   llvm::formatv("{0}/{1}", Stats.Completed - Stats.LastIdle,


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -631,7 +631,7 @@
   ///
   /// The value should be steadily rising. Clients are free to ignore values
   /// that are not following this rule.
-  llvm::Optional percentage;
+  llvm::Optional percentage;
 };
 llvm::json::Value toJSON(const WorkDoneProgressReport &);
 //
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1606,7 +1606,7 @@
 if (Stats.Completed < Stats.Enqueued) {
   assert(Stats.Enqueued > Stats.LastIdle);
   WorkDoneProgressReport Report;
-  Report.percentage = 100.0 * (Stats.Completed - Stats.LastIdle) /
+  Report.percentage = 100 * (Stats.Completed - Stats.LastIdle) /
   (Stats.Enqueued - Stats.LastIdle);
   Report.message =
   llvm::formatv("{0}/{1}", Stats.Completed - Stats.LastIdle,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f088af3 - [clangd] Fix data type of WorkDoneProgressReport::percentage

2021-05-10 Thread Kadir Cetinkaya via cfe-commits

Author: Christian Kandeler
Date: 2021-05-10T14:57:20+02:00
New Revision: f088af37e6b570dd070ae4e6fc14e22d21cda3be

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

LOG: [clangd] Fix data type of WorkDoneProgressReport::percentage

According to the specification, this should be an unsigned integer.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 913c5c3219a5..c25195cd338f 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1606,7 +1606,7 @@ void ClangdLSPServer::onBackgroundIndexProgress(
 if (Stats.Completed < Stats.Enqueued) {
   assert(Stats.Enqueued > Stats.LastIdle);
   WorkDoneProgressReport Report;
-  Report.percentage = 100.0 * (Stats.Completed - Stats.LastIdle) /
+  Report.percentage = 100 * (Stats.Completed - Stats.LastIdle) /
   (Stats.Enqueued - Stats.LastIdle);
   Report.message =
   llvm::formatv("{0}/{1}", Stats.Completed - Stats.LastIdle,

diff  --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index 2ae60910639e..f0d46ab8a010 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -631,7 +631,7 @@ struct WorkDoneProgressReport {
   ///
   /// The value should be steadily rising. Clients are free to ignore values
   /// that are not following this rule.
-  llvm::Optional percentage;
+  llvm::Optional percentage;
 };
 llvm::json::Value toJSON(const WorkDoneProgressReport &);
 //



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


[PATCH] D99646: [clang-tidy] misc-avoid-std-io-outside-main: a new check

2021-05-10 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 344030.
mgartmann added a comment.

Change encoding of patch to UTF-8 in order to fix build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99646

Files:
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.cpp
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.h
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-avoid-std-io-outside-main.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-avoid-std-io-outside-main.cpp
@@ -0,0 +1,138 @@
+// RUN: %check_clang_tidy %s misc-avoid-std-io-outside-main %t
+
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+
+struct Ostream {
+  Ostream <<(string Message);
+};
+
+struct Istream {
+  Istream >>(string Message);
+};
+
+Ostream cout{}, wcout{}, cerr{}, wcerr{};
+Istream cin{}, wcin{};
+
+int printf(const char *Format, ...);
+int vprintf(const char *const, ...);
+int puts(const char *Str);
+int putchar(int Character);
+int scanf(const char *Format, ...);
+int getchar(void);
+char *gets(char *Str);
+} // namespace std
+
+int printf(const char *Format, ...);
+int vprintf(const char *const, ...);
+int puts(const char *Str);
+int putchar(int Character);
+int scanf(const char *Format, ...);
+int getchar(void);
+char *gets(char *Str);
+
+namespace arbitrary_namespace {
+std::Ostream cout{};
+std::Istream cin{};
+} // namespace arbitrary_namespace
+
+void anyNonMainFunction() {
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cout << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcout << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cerr << "This should trigger the check";
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcerr << "This should trigger the check";
+
+  arbitrary_namespace::cout << "This should not trigger the check"; // OK
+
+  std::string Foo{"bar"};
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::cin >> Foo;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: predefined standard stream objects should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::wcin >> Foo;
+
+  arbitrary_namespace::cin >> Foo; // OK
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::printf("This should trigger the check");
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  printf("This should trigger the check");
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::puts("This should trigger the check");
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  puts("This should trigger the check");
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::putchar('m');
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  putchar('m');
+
+  char Input[5];
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::scanf("%s", Input);
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  scanf("%s", Input);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: cstdio functions should not be used outside the main function [misc-avoid-std-io-outside-main]
+  std::getchar();
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: cstdio functions should not be used 

[clang] 08de6e3 - clang: Fix tests after 7f78e409d028 if clang is not called clang-13

2021-05-10 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-05-10T08:49:26-04:00
New Revision: 08de6e3adaf6e991f5a40357f4634e5b70ec3fde

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

LOG: clang: Fix tests after 7f78e409d028 if clang is not called clang-13

We might release a new version at some point after all.
In fact, use the same pattern the other CHECK lines in this test
use, for consistency.

Added: 


Modified: 
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 12067c4c0739..e4b89dcedf01 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -73,4 +73,4 @@
 // CHECK-C: "x86_64-unknown-linux-gnu" - "offload bundler"
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
-// CHECK-EMIT-LLVM-IR: {{.*}}clang-13" "-cc1" "-triple" 
"amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
+// CHECK-EMIT-LLVM-IR: clang{{.*}}"-cc1"{{.*}}"-triple" 
"amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"



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


  1   2   >