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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336316.
haberman added a comment.

- Rename and refine IgnoreElidableImplicitConstructorSingleStep().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

Files:
  clang/include/clang/AST/IgnoreExpr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-musttail.cpp
  clang/test/Sema/attr-musttail.c
  clang/test/Sema/attr-musttail.cpp
  clang/test/Sema/attr-musttail.m

Index: clang/test/Sema/attr-musttail.m
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.m
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
+
+void TestObjcBlock(void) {
+  void (^x)(void) = ^(void) {
+__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
+  };
+  __attribute__((musttail)) return x();
+}
+
+void ReturnsVoid(void);
+void TestObjcBlockVar(void) {
+  __block int i = 0;  // expected-note{{jump exits scope of __block variable}}
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{cannot perform a tail call from this return statement}}
+}
+
+__attribute__((objc_root_class))
+@interface TestObjcClass
+@end
+
+@implementation TestObjcClass
+
+- (void)testObjCMethod {
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
+}
+
+@end
Index: clang/test/Sema/attr-musttail.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.cpp
@@ -0,0 +1,201 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fms-extensions -fcxx-exceptions -fopenmp %s
+
+int ReturnsInt1();
+int Func1() {
+  [[clang::musttail]] ReturnsInt1();  // expected-error {{'musttail' attribute only applies to return statements}}
+  [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
+  [[clang::musttail]] return 5;   // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+  [[clang::musttail]] return ReturnsInt1();
+}
+
+void NoFunctionCall() {
+  [[clang::musttail]] return; // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+}
+
+[[clang::musttail]] static int int_val = ReturnsInt1(); // expected-error {{'musttail' attribute cannot be applied to a declaration}}
+
+void NoParams(); // expected-note {{target function has different number of parameters (expected 1 but has 0)}}
+void TestParamArityMismatch(int x) {
+  [[clang::musttail]] return NoParams(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
+void TestParamTypeMismatch(int x) {
+  [[clang::musttail]] return LongParam(x); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+long ReturnsLong(); // expected-note {{target function has different return type ('int' expected but has 'long')}}
+int TestReturnTypeMismatch() {
+  [[clang::musttail]] return ReturnsLong(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+struct Struct1 {
+  void MemberFunction(); // expected-note {{target function is a member of different class (expected 'void' but has 'Struct1')}}
+};
+void TestNonMemberToMember() {
+  Struct1 st;
+  [[clang::musttail]] return st.MemberFunction(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void ReturnsVoid(); // expected-note {{target function is a member of different class (expected 'Struct2' but has 'void')}}
+struct Struct2 {
+  void TestMemberToNonMember() {
+[[clang::musttail]] return ReturnsVoid(); // expected-error{{'musttail' attribute requires that caller and callee have compatible function signatures}}
+  }
+};
+
+class HasNonTrivialDestructor {
+public:
+  ~HasNonTrivialDestructor() {}
+  int ReturnsInt();
+};
+
+void ReturnsVoid2();
+void TestNonTrivialDestructorInScope() {
+  

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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2828-2829
+  "%0 attribute requires that the return value, all parameters, and any "
+  "temporaries created by the expression are trivially destructible and "
+  "do not require ARC">;
+def err_musttail_needs_call : Error<

rsmith wrote:
> Can we somehow avoid talking about ARC where it's not relevant? While it'd be 
> nice to be more precise here, my main concern is that we shouldn't be 
> mentioning ARC to people for whom it's not a meaningful term (eg, when not 
> compiling Objective-C or Objective-C++). Perhaps the simplest approach would 
> be to only mention ARC if `getLangOpts().ObjCAutoRefCount` is set?
I implemented this but I couldn't figure out how to actually trigger the ARC 
case, so I just removed that part of the diagnostic text for now.



Comment at: clang/lib/AST/AttrImpl.cpp:221-226
+  // Elide constructors even if this is disabled with -fno-elide-constructors
+  // because 'musttail' is a more local setting.
+  if (CCE && CCE->isElidable()) {
+assert(CCE->getNumArgs() == 1); // Copy or move constructor.
+Ex = CCE->getArg(0);
+  }

rsmith wrote:
> `IgnoreImplicitAsWritten` should already skip over implicit elidable 
> constructors, so I would imagine this is skipping over elidable //explicit// 
> constructor calls (eg, `[[musttail]] return T(make());` would perform a 
> tail-call to `make()`). Is that what we want?
As discussed offline, it appears that `IgnoreImplicitAsWritten()` was not 
skipping the implicit constructor in this case. Per our discussion, I created a 
new version of `IgnoreImplicitAsWritten()` that does, with a FIXME to land it 
in `Expr`, and I made it skip implicit constructors only (and added tests for 
this case).



Comment at: clang/lib/CodeGen/CGStmt.cpp:665
+  SaveAndRestore save_musttail(MustTailCall, musttail);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }

rsmith wrote:
> In the case where we're forcibly eliding a constructor, we'll need to emit a 
> return statement that returns `musttail` call expression here rather than 
> emitting the original substatement. Otherwise the tail call we emit will be 
> initializing a local temporary rather than initializing our return slot. Eg, 
> given:
> 
> ```
> struct A {
>   A(const A&);
>   ~A();
>   char data[32];
> };
> A f();
> A g() {
>   [[clang::musttail]] return f();
> }
> ```
> under `-fno-elide-constructors` when targeting C++11, say, we'll normally 
> lower that into something like:
> ```
> void f(A *return_slot);
> void g(A *return_slot) {
>   A temporary; //uninitialized
>   f(); // call f
>   A::A(return_slot, temporary); // call copy constructor to copy into return 
> slot
> }
> ```
> ... and with the current patch, it looks like we'll add a 'ret void' after 
> the call to `f`, leaving `g`'s return slot uninitialized and passing an 
> address into `f` that refers to a variable that will no longer exist once `f` 
> is called. We need to instead lower to:
> ```
> void f(A *return_slot);
> void g(A *return_slot) {
>   f(return_slot); // call f
> }
> ```
> Probably the easiest way to do this would be to change the return value on 
> the `ReturnStmt` to be the tail-called `CallExpr` when attaching the 
> attribute.
Done.

I had to change your test case to remove the destructor, otherwise it fails the 
trivial destruction check.

Take a look at the CodeGen tests and see if the output looks correct to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336310.
haberman marked 3 inline comments as done.
haberman added a comment.

- Refined the implicit constructor skipping code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

Files:
  clang/include/clang/AST/IgnoreExpr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-musttail.cpp
  clang/test/Sema/attr-musttail.c
  clang/test/Sema/attr-musttail.cpp
  clang/test/Sema/attr-musttail.m

Index: clang/test/Sema/attr-musttail.m
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.m
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
+
+void TestObjcBlock(void) {
+  void (^x)(void) = ^(void) {
+__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
+  };
+  __attribute__((musttail)) return x();
+}
+
+void ReturnsVoid(void);
+void TestObjcBlockVar(void) {
+  __block int i = 0;  // expected-note{{jump exits scope of __block variable}}
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{cannot perform a tail call from this return statement}}
+}
+
+__attribute__((objc_root_class))
+@interface TestObjcClass
+@end
+
+@implementation TestObjcClass
+
+- (void)testObjCMethod {
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
+}
+
+@end
Index: clang/test/Sema/attr-musttail.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.cpp
@@ -0,0 +1,201 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fms-extensions -fcxx-exceptions -fopenmp %s
+
+int ReturnsInt1();
+int Func1() {
+  [[clang::musttail]] ReturnsInt1();  // expected-error {{'musttail' attribute only applies to return statements}}
+  [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
+  [[clang::musttail]] return 5;   // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+  [[clang::musttail]] return ReturnsInt1();
+}
+
+void NoFunctionCall() {
+  [[clang::musttail]] return; // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+}
+
+[[clang::musttail]] static int int_val = ReturnsInt1(); // expected-error {{'musttail' attribute cannot be applied to a declaration}}
+
+void NoParams(); // expected-note {{target function has different number of parameters (expected 1 but has 0)}}
+void TestParamArityMismatch(int x) {
+  [[clang::musttail]] return NoParams(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
+void TestParamTypeMismatch(int x) {
+  [[clang::musttail]] return LongParam(x); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+long ReturnsLong(); // expected-note {{target function has different return type ('int' expected but has 'long')}}
+int TestReturnTypeMismatch() {
+  [[clang::musttail]] return ReturnsLong(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+struct Struct1 {
+  void MemberFunction(); // expected-note {{target function is a member of different class (expected 'void' but has 'Struct1')}}
+};
+void TestNonMemberToMember() {
+  Struct1 st;
+  [[clang::musttail]] return st.MemberFunction(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void ReturnsVoid(); // expected-note {{target function is a member of different class (expected 'Struct2' but has 'void')}}
+struct Struct2 {
+  void TestMemberToNonMember() {
+[[clang::musttail]] return ReturnsVoid(); // expected-error{{'musttail' attribute requires that caller and callee have compatible function signatures}}
+  }
+};
+
+class HasNonTrivialDestructor {
+public:
+  ~HasNonTrivialDestructor() {}
+  int ReturnsInt();
+};
+
+void ReturnsVoid2();
+void 

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

2021-04-08 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In D97264#2663082 , @rogfer01 wrote:

> I was under the impression we didn't want to use class-member access syntax 
> for vector tuples (see 
> https://github.com/riscv/rvv-intrinsic-doc/issues/17#issuecomment-628998077 ) 
> so we don't need a record type, do we?
>
> Perhaps it is possible to model them like opaque entities similar to what we 
> do with RVV vectors where they are expanded in `CodegenTypes.cpp`?
>
> Access to fields would have to be through intrinsics, though I think this 
> didn't scale very well, did it?

Do you mean treat the Zvlsseg types as kind of builtin types? I want to avoid 
to add too much builtin types in Clang. That is why I use implicit defined 
RecordType for Zvlsseg types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97264

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

Hi @craig.topper and @skan , THX for review! I tested that deleting sgx indeed 
leads to not generating "+sgx" in 'target-features', didn't know before:)

  '+sgx' is not a recognized feature for this target (ignoring feature)  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 336303.
FreddyYe added a comment.

revert clang-format and revert deleting FeatureSGX def.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -38,6 +38,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cooperlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cannonlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-client 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=rocketlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-server 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=tigerlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sapphirerapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -653,8 +653,7 @@
   list SKLAdditionalFeatures = [FeatureAES,
   FeatureXSAVEC,
   FeatureXSAVES,
-  FeatureCLFLUSHOPT,
-  FeatureSGX];
+  FeatureCLFLUSHOPT];
   list SKLTuning = [FeatureHasFastGather,
   FeatureMacroFusion,
   FeatureSlow3OpsLEA,
@@ -754,7 +753,7 @@
   list ICXFeatures =
 !listconcat(ICLFeatures, ICXAdditionalFeatures);
 
-  //Tigerlake
+  // Tigerlake
   list TGLAdditionalFeatures = [FeatureVP2INTERSECT,
   FeatureMOVDIRI,
   FeatureMOVDIR64B,
@@ -763,7 +762,7 @@
   list TGLFeatures =
 !listconcat(ICLFeatures, TGLAdditionalFeatures );
 
-  //Sapphirerapids
+  // Sapphirerapids
   list SPRAdditionalFeatures = [FeatureAMXTILE,
   FeatureAMXINT8,
   FeatureAMXBF16,
@@ -845,8 +844,7 @@
 
   // Goldmont Plus
   list GLPAdditionalFeatures = [FeaturePTWRITE,
-  FeatureRDPID,
-  FeatureSGX];
+  FeatureRDPID];
   list GLPTuning = [FeatureUseGLMDivSqrtCosts,
   FeatureSlowTwoMemOps,
   FeatureSlowLEA,
@@ -1307,6 +1305,8 @@
 ProcessorFeatures.CNLFeatures, ProcessorFeatures.CNLTuning>;
 def : ProcModel<"icelake-client", SkylakeServerModel,
 ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
+def : ProcModel<"rocketlake", SkylakeServerModel,
+ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
 def : ProcModel<"icelake-server", SkylakeServerModel,
 ProcessorFeatures.ICXFeatures, ProcessorFeatures.ICXTuning>;
 def : ProcModel<"tigerlake", SkylakeServerModel,
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -194,6 +194,7 @@
 FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 |
 FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureCLWB | FeatureGFNI |
 FeatureRDPID | FeatureVAES | FeatureVPCLMULQDQ;
+constexpr FeatureBitset FeaturesRocketlake = FeaturesICLClient & ~FeatureSGX;
 constexpr FeatureBitset FeaturesICLServer =
 FeaturesICLClient | FeaturePCONFIG | FeatureWBNOINVD;
 constexpr FeatureBitset 

[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 336301.
FreddyYe added a comment.

cancel the clang-format in constexpr ProcInfo Processors[] = {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -38,6 +38,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cooperlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cannonlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-client 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=rocketlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-server 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=tigerlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sapphirerapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -268,8 +268,6 @@
  "Pad short functions">;
 def FeatureINVPCID : SubtargetFeature<"invpcid", "HasINVPCID", "true",
   "Invalidate Process-Context Identifier">;
-def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true",
-  "Enable Software Guard Extensions">;
 def FeatureCLFLUSHOPT : SubtargetFeature<"clflushopt", "HasCLFLUSHOPT", "true",
   "Flush A Cache Line Optimized">;
 def FeatureCLWB: SubtargetFeature<"clwb", "HasCLWB", "true",
@@ -653,8 +651,7 @@
   list SKLAdditionalFeatures = [FeatureAES,
   FeatureXSAVEC,
   FeatureXSAVES,
-  FeatureCLFLUSHOPT,
-  FeatureSGX];
+  FeatureCLFLUSHOPT];
   list SKLTuning = [FeatureHasFastGather,
   FeatureMacroFusion,
   FeatureSlow3OpsLEA,
@@ -754,7 +751,7 @@
   list ICXFeatures =
 !listconcat(ICLFeatures, ICXAdditionalFeatures);
 
-  //Tigerlake
+  // Tigerlake
   list TGLAdditionalFeatures = [FeatureVP2INTERSECT,
   FeatureMOVDIRI,
   FeatureMOVDIR64B,
@@ -763,7 +760,7 @@
   list TGLFeatures =
 !listconcat(ICLFeatures, TGLAdditionalFeatures );
 
-  //Sapphirerapids
+  // Sapphirerapids
   list SPRAdditionalFeatures = [FeatureAMXTILE,
   FeatureAMXINT8,
   FeatureAMXBF16,
@@ -845,8 +842,7 @@
 
   // Goldmont Plus
   list GLPAdditionalFeatures = [FeaturePTWRITE,
-  FeatureRDPID,
-  FeatureSGX];
+  FeatureRDPID];
   list GLPTuning = [FeatureUseGLMDivSqrtCosts,
   FeatureSlowTwoMemOps,
   FeatureSlowLEA,
@@ -1307,6 +1303,8 @@
 ProcessorFeatures.CNLFeatures, ProcessorFeatures.CNLTuning>;
 def : ProcModel<"icelake-client", SkylakeServerModel,
 ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
+def : ProcModel<"rocketlake", SkylakeServerModel,
+ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
 def : ProcModel<"icelake-server", SkylakeServerModel,
 ProcessorFeatures.ICXFeatures, ProcessorFeatures.ICXTuning>;
 def : ProcModel<"tigerlake", SkylakeServerModel,
Index: 

[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:271-273
-def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true",
-  "Enable Software Guard Extensions">;
 def FeatureCLFLUSHOPT : SubtargetFeature<"clflushopt", "HasCLFLUSHOPT", "true",

skan wrote:
> craig.topper wrote:
> > Clang still puts it in target-features attribute so you can’t delete this 
> > or you’ll get a warning that the feature doesn’t exist.
> If you delete the definition of FeatureSGX, you need to remove the related 
> code in X86Subtarget.h too.  BTW, I don't think "there are no IR intrinsics 
> for a feature" is a good reason to remove a feature.
I only said to remove it from the CPUs because for  llc -march=skylake it 
doesn’t matter if we enable SGX because there’s nothing you can test from llc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100161: Redistribute energy for Corpus

2021-04-08 Thread taotao gu via Phabricator via cfe-commits
gtt1995 created this revision.
gtt1995 added reviewers: 01alchemist, 0b01.
gtt1995 requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Divide the corpus into n parts according to size. Each job executes each corpus 
in turn, Job one executes the corpus with the smallest size, Job two executes 
the relatively larger corpus,...Job N executes the seed of the largest corpus, 
in turn,. i.e. each job choose some seeds from corpus 1, corpus2 2,..., corpus 
N, corpus1,corpus2...corpus N .
that is, allocate more energy to the small seeds, trigger the common path in 
advance, and prefer to keep the small seeds.
In my experiment , It is found that the bugs rate is greatly accelerated, the 
cov is greatly increased (equal to the effect of entropic improvement), and the 
size of the newly generated interesting seeds is very small.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100161

Files:
  clang/tools/clang-format/clang-format.py
  compiler-rt/lib/fuzzer/FuzzerDriver.cpp
  compiler-rt/lib/fuzzer/FuzzerFlags.def
  compiler-rt/lib/fuzzer/FuzzerFork.cpp
  compiler-rt/lib/fuzzer/FuzzerFork.h

Index: compiler-rt/lib/fuzzer/FuzzerFork.h
===
--- compiler-rt/lib/fuzzer/FuzzerFork.h
+++ compiler-rt/lib/fuzzer/FuzzerFork.h
@@ -18,7 +18,7 @@
 namespace fuzzer {
 void FuzzWithFork(Random , const FuzzingOptions ,
   const Vector ,
-  const Vector , int NumJobs);
+  const Vector , int NumJobs, int NumCorpuses);
 } // namespace fuzzer
 
 #endif // LLVM_FUZZER_FORK_H
Index: compiler-rt/lib/fuzzer/FuzzerFork.cpp
===
--- compiler-rt/lib/fuzzer/FuzzerFork.cpp
+++ compiler-rt/lib/fuzzer/FuzzerFork.cpp
@@ -114,7 +114,7 @@
 .count();
   }
 
-  FuzzJob *CreateNewJob(size_t JobId) {
+  FuzzJob *CreateNewJob(size_t JobId, int NumCorpuses) {
 Command Cmd(Args);
 Cmd.removeFlag("fork");
 Cmd.removeFlag("runs");
@@ -135,11 +135,23 @@
 std::string Seeds;
 if (size_t CorpusSubsetSize =
 std::min(Files.size(), (size_t)sqrt(Files.size() + 2))) {
+  size_t AverageSize = Files.size()/NumCorpuses +1;
   auto Time1 = std::chrono::system_clock::now();
+  size_t StartIndex = ((JobId-1)%NumCorpuses) *  AverageSize;
+  printf("\n Job %d Choose Corpus  %d ",JobId,(JobId)%NumCorpuses);
   for (size_t i = 0; i < CorpusSubsetSize; i++) {
-auto  = Files[Rand->SkewTowardsLast(Files.size())];
-Seeds += (Seeds.empty() ? "" : ",") + SF;
-CollectDFT(SF);
+size_t j = Rand->SkewTowardsLast(AverageSize);
+size_t m = j + StartIndex;
+if (m < Files.size()) {
+auto  = Files[m];
+Seeds += (Seeds.empty() ? "" : ",") + SF;
+CollectDFT(SF);
+}
+else  {
+auto  = Files[Rand->SkewTowardsLast(Files.size())];
+Seeds += (Seeds.empty() ? "" : ",") + SF;
+CollectDFT(SF);
+}
   }
   auto Time2 = std::chrono::system_clock::now();
   auto DftTimeInSeconds = duration_cast(Time2 - Time1).count();
@@ -284,7 +296,7 @@
 // This is just a skeleton of an experimental -fork=1 feature.
 void FuzzWithFork(Random , const FuzzingOptions ,
   const Vector ,
-  const Vector , int NumJobs) {
+  const Vector , int NumJobs, int NumCorpuses) {
   Printf("INFO: -fork=%d: fuzzing in separate process(s)\n", NumJobs);
 
   GlobalEnv Env;
@@ -341,8 +353,9 @@
   Vector Threads;
   for (int t = 0; t < NumJobs; t++) {
 Threads.push_back(std::thread(WorkerThread, , ));
-FuzzQ.Push(Env.CreateNewJob(JobId++));
+FuzzQ.Push(Env.CreateNewJob(JobId++, NumCorpuses));
   }
+  //printf("\n 创建%d个jobs\n",NumJobs);
 
   while (true) {
 std::unique_ptr Job(MergeQ.Pop());
@@ -399,7 +412,7 @@
   break;
 }
 
-FuzzQ.Push(Env.CreateNewJob(JobId++));
+FuzzQ.Push(Env.CreateNewJob(JobId++, NumCorpuses));
   }
 
   for (auto  : Threads)
Index: compiler-rt/lib/fuzzer/FuzzerFlags.def
===
--- compiler-rt/lib/fuzzer/FuzzerFlags.def
+++ compiler-rt/lib/fuzzer/FuzzerFlags.def
@@ -56,6 +56,7 @@
 FUZZER_FLAG_INT(max_total_time, 0, "If positive, indicates the maximal total "
"time in seconds to run the fuzzer.")
 FUZZER_FLAG_INT(help, 0, "Print help.")
+FUZZER_FLAG_INT(NumCorpuses, 1, "Divide the corpus into N parts according to size.")
 FUZZER_FLAG_INT(fork, 0, "Experimental mode where fuzzing happens "
 "in a subprocess")
 FUZZER_FLAG_INT(ignore_timeouts, 1, "Ignore timeouts in fork mode")
Index: compiler-rt/lib/fuzzer/FuzzerDriver.cpp
===
--- 

[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:271-273
-def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true",
-  "Enable Software Guard Extensions">;
 def FeatureCLFLUSHOPT : SubtargetFeature<"clflushopt", "HasCLFLUSHOPT", "true",

craig.topper wrote:
> Clang still puts it in target-features attribute so you can’t delete this or 
> you’ll get a warning that the feature doesn’t exist.
If you delete the definition of FeatureSGX, you need to remove the related code 
in X86Subtarget.h too.  BTW, I don't think "there are no IR intrinsics for a 
feature" is a good reason to remove a feature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D97669: [clang][AVR] Add avr-libc/include to clang system include paths

2021-04-08 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

In D97669#2676826 , @Anastasia wrote:

> In D97669#2665865 , @benshi001 wrote:
>
>> In D97669#2661560 , @Anastasia 
>> wrote:
>>
>>> Is `stdio.h`  used by anything?
>>
>> No. `stdio.h` is not used. But if I do `#include `, then 
>> `-I /usr/lib/avr/include` must be specified in the command line option. 
>> While avr-gcc does not reqiures that.
>>
>> I would like to keep clang & avr-gcc in the behaviour.
>
> Ok, do you plan to use it later? Then perhaps you should be adding it in the 
> subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers 
and libs) and avr specific headers and libs. This patch fixes all of these 
issues. Both standard libc and avr platform specific libs can be used without 
any explict command line option, just like avr-gcc does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97669

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:271
   "Invalidate Process-Context Identifier">;
-def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true",
-  "Enable Software Guard Extensions">;

Clang still puts it in target-features attribute so you can’t delete this or 
you’ll get a warning that the feature doesn’t exist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: llvm/lib/Support/X86TargetParser.cpp:293-301
+// Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
+{{""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B},
+// i386-generation processors.
+{{"i386"}, CK_i386, ~0U, FeatureX87},
+// i486-generation processors.
+{{"i486"}, CK_i486, ~0U, FeatureX87},
+{{"winchip-c6"}, CK_WinChipC6, ~0U, FeaturesPentiumMMX},

It's not correct to format here in this patch and do not mix tab with space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 336295.
FreddyYe added a comment.

delete FeatureSGX in the backend since there are no IR intrinsics for SGX.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -38,6 +38,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cooperlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=cannonlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-client 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=rocketlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=icelake-server 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=tigerlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sapphirerapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -268,8 +268,6 @@
  "Pad short functions">;
 def FeatureINVPCID : SubtargetFeature<"invpcid", "HasINVPCID", "true",
   "Invalidate Process-Context Identifier">;
-def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true",
-  "Enable Software Guard Extensions">;
 def FeatureCLFLUSHOPT : SubtargetFeature<"clflushopt", "HasCLFLUSHOPT", "true",
   "Flush A Cache Line Optimized">;
 def FeatureCLWB: SubtargetFeature<"clwb", "HasCLWB", "true",
@@ -653,8 +651,7 @@
   list SKLAdditionalFeatures = [FeatureAES,
   FeatureXSAVEC,
   FeatureXSAVES,
-  FeatureCLFLUSHOPT,
-  FeatureSGX];
+  FeatureCLFLUSHOPT];
   list SKLTuning = [FeatureHasFastGather,
   FeatureMacroFusion,
   FeatureSlow3OpsLEA,
@@ -754,7 +751,7 @@
   list ICXFeatures =
 !listconcat(ICLFeatures, ICXAdditionalFeatures);
 
-  //Tigerlake
+  // Tigerlake
   list TGLAdditionalFeatures = [FeatureVP2INTERSECT,
   FeatureMOVDIRI,
   FeatureMOVDIR64B,
@@ -763,7 +760,7 @@
   list TGLFeatures =
 !listconcat(ICLFeatures, TGLAdditionalFeatures );
 
-  //Sapphirerapids
+  // Sapphirerapids
   list SPRAdditionalFeatures = [FeatureAMXTILE,
   FeatureAMXINT8,
   FeatureAMXBF16,
@@ -845,8 +842,7 @@
 
   // Goldmont Plus
   list GLPAdditionalFeatures = [FeaturePTWRITE,
-  FeatureRDPID,
-  FeatureSGX];
+  FeatureRDPID];
   list GLPTuning = [FeatureUseGLMDivSqrtCosts,
   FeatureSlowTwoMemOps,
   FeatureSlowLEA,
@@ -1307,6 +1303,8 @@
 ProcessorFeatures.CNLFeatures, ProcessorFeatures.CNLTuning>;
 def : ProcModel<"icelake-client", SkylakeServerModel,
 ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
+def : ProcModel<"rocketlake", SkylakeServerModel,
+ProcessorFeatures.ICLFeatures, ProcessorFeatures.ICLTuning>;
 def : ProcModel<"icelake-server", SkylakeServerModel,
 ProcessorFeatures.ICXFeatures, ProcessorFeatures.ICXTuning>;
 def : ProcModel<"tigerlake", SkylakeServerModel,
Index: 

[clang] ca55f05 - [clang][SourceManager] Fix -Wparentheses warning (NFC)

2021-04-08 Thread Yang Fan via cfe-commits

Author: Yang Fan
Date: 2021-04-09T10:22:56+08:00
New Revision: ca55f0511698e5b64538e02eff9f6b2280282b15

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

LOG: [clang][SourceManager] Fix -Wparentheses warning (NFC)

GCC warning:
```
/llvm-project/clang/lib/Basic/SourceManager.cpp: In instantiation of ‘constexpr 
T likelyhasbetween(T, unsigned char, unsigned char) [with T = long unsigned 
int]’:
/llvm-project/clang/lib/Basic/SourceManager.cpp:1292:52:   required from here
/llvm-project/clang/lib/Basic/SourceManager.cpp:1264:48: warning: suggest 
parentheses around ‘+’ in operand of ‘&’ [-Wparentheses]
 1264 |   (x & ~static_cast(0) / 255 * 127) +
  |   ~^
 1265 |   (~static_cast(0) / 255 * (127 - (m - 1 &
  |   
```

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 438525b1ee13..2c8036aaf36a 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1261,8 +1261,8 @@ template 
 static constexpr inline T likelyhasbetween(T x, unsigned char m,
unsigned char n) {
   return ((x - ~static_cast(0) / 255 * (n + 1)) & ~x &
-  (x & ~static_cast(0) / 255 * 127) +
-  (~static_cast(0) / 255 * (127 - (m - 1 &
+  ((x & ~static_cast(0) / 255 * 127) +
+   (~static_cast(0) / 255 * (127 - (m - 1) &
  ~static_cast(0) / 255 * 128;
 }
 



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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:767
+  // Rocketlake
+  list RKLAdditionalFeatures = [FeatureAES,
+  FeatureXSAVEC,

craig.topper wrote:
> FreddyYe wrote:
> > craig.topper wrote:
> > > Is this list this long because SKL includes SGX but RKL doesn't?
> > Yes. And I don't know any simple ways to exclude SGX here, any suggestions?
> Nothing pretty. Guess it depends on if SGX is going to not appear in more 
> future CPUs or if this is a one off case. If it's going to continue then we 
> could remove it from the inheritance and just give it to SKL, ICL, CNL, etc. 
> individually.
> 
> Or we could just not default SGX on for any CPU. It's probably not all that 
> useful in the backend anyway. Clang will put it in the target-feature 
> attribute anyway. Having it in the backend feature lists doesn't really do 
> anything since I don't think we have any IR intrinsics for SGX.
Agree. Like we did in https://reviews.llvm.org/D88006. SGX is also not useful 
in the backend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:790
+  FeatureFSRM];
+  list RKLTuning = ICLTuning;
+  list RKLFeatures =

RKSimon wrote:
> Using ICLTuning suggests we should still be avoiding 512-bit ops 
> (FeaturePrefer256Bit) - is this still true for RKL (or anything past CNL...)?
> 
> I posted PR48336 but never got any response, but from what others have 
> reported (Travis Downs, Phoronix etc) its mainly a power issue these days, 
> not a perf issue due to big freq drops.
We need more tests on such as SPEC to see whether we can default enable 
FeaturePrefer512bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D99790: [CGCall] Annotate `this` argument with alignment

2021-04-08 Thread Brooks Moses via Phabricator via cfe-commits
brooksmoses added a comment.

In D99790#2677919 , @lebedev.ri wrote:

> In D99790#2677917 , @brooksmoses 
> wrote:
>
>> As a heads up, I'm seeing segfaults on internal code as a result of this 
>> change, as well as errors in Eigen's unalignedassert.cpp test (specifically, 
>> this line asserts: 
>> https://github.com/madlib/eigen/blob/master/test/unalignedassert.cpp#L151).
>
> Would be good to have a small standalone reproducer.
> Not really sure how we can end up with a misaligned `this`, but it sounds 
> like UB.

Indeed, it's looking like all of the various segfaults are resulting from 
undefined behavior, just like the Eigen assert was (per @jyknight's comment).  
One of the segfaults is in the OpenJDK runtime -- albeit our internal copy, so 
it's possible it might not be in the external versions -- so that's fun.  
Luckily it shows up in the bootstrapping part of the build, rather than lying 
in wait to bite people after it's deployed.

In any case, thanks for the quick reply, and I'll figure out a small reproducer 
if we find something that isn't UB.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99790

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


[clang] eb8a28e - DebugInfo: Include inline namespaces in template specialization parameter names

2021-04-08 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-04-08T17:37:55-07:00
New Revision: eb8a28e2cf033f2bfbfe33a0bd0d9e75a12e2679

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

LOG: DebugInfo: Include inline namespaces in template specialization parameter 
names

This ensures these types have distinct names if they are distinct types
(eg: if one is an instantiation with a type in one inline namespace, and
another from a type with the same simple name, but in a different inline
namespace).

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-template.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3fe56346088c7..42a5ea6d2 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -305,6 +305,7 @@ StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
 llvm::raw_svector_ostream OS(Name);
 PrintingPolicy PP = getPrintingPolicy();
 PP.PrintCanonicalTypes = true;
+PP.SuppressInlineNamespace = false;
 RD->getNameForDiagnostic(OS, PP,
  /*Qualified*/ false);
 

diff  --git a/clang/test/CodeGenCXX/debug-info-template.cpp 
b/clang/test/CodeGenCXX/debug-info-template.cpp
index a6edd59171b29..4342b3e27a0b2 100644
--- a/clang/test/CodeGenCXX/debug-info-template.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template.cpp
@@ -179,3 +179,11 @@ ClassTemplateArgRefTemplate 
ClassTemplateArgRefObj;
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"ClassTemplateArgRefTemplate< 
>", {{.*}}, templateParams: ![[CLASS_TEMP_REF_ARGS:[0-9]*]],
 // CHECK: ![[CLASS_TEMP_REF_ARGS]] = !{![[CLASS_TEMP_REF_ARG:[0-9]*]]}
 // CHECK: ![[CLASS_TEMP_REF_ARG]] = !DITemplateValueParameter(type: 
![[CLASS_TEMP_ARG_CONST_REF_TYPE]], value: %{{.*}}* 
@_ZTAXtl16ClassTemplateArgLi1ELf4000EEE)
+
+inline namespace inl {
+  struct t1 { };
+}
+template struct ClassTemplateInlineNamespaceArg {
+};
+ClassTemplateInlineNamespaceArg ClassTemplateInlineNamespaceArgObj;
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"ClassTemplateInlineNamespaceArg",



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


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman updated this revision to Diff 336274.
Holman set the repository for this revision to rG LLVM Github Monorepo.
Holman added a comment.

Add a test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/pgo.ll

Index: llvm/test/DebugInfo/COFF/pgo.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/pgo.ll
@@ -0,0 +1,165 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s
+
+; CHECK: Compile3Sym {
+; CHECK:   Flags [ (0x4)
+; CHECK: PGO (0x4)
+
+; CHECK: DisplayName: foo
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: foo2
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: bar
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: main
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK-NOT:   ProfileGuidedOptimization (0x4)
+; CHECK-NOT:   ValidProfileCounts (0x8)
+
+source_filename = "pgo.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.28.29912"
+
+define dso_local i32 @"?foo@@YAHH@Z"(i32 %b) local_unnamed_addr #1 !dbg !43 !prof !49 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %b, metadata !48, metadata !DIExpression()), !dbg !50
+  %mul = mul nsw i32 %b, 10, !dbg !51
+  ret i32 %mul, !dbg !51
+}
+
+define dso_local i32 @"?foo2@@YAHH@Z"(i32 %a) local_unnamed_addr #1 !dbg !52 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !54, metadata !DIExpression()), !dbg !56
+  %mul = mul nsw i32 %a, 5, !dbg !57
+  ret i32 %mul, !dbg !57
+}
+
+define dso_local i32 @"?bar@@YAHH@Z"(i32 %num) local_unnamed_addr #1 !dbg !58 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 undef, metadata !60, metadata !DIExpression()), !dbg !61
+  %call = tail call i32 @"?foo@@YAHH@Z"(i32 1) #1, !dbg !62
+  %call1 = tail call i32 @"?foo2@@YAHH@Z"(i32 2) #1, !dbg !62
+  %mul = mul nsw i32 %call1, %call, !dbg !62
+  %call2 = tail call i32 @"?foo2@@YAHH@Z"(i32 3) #1, !dbg !62
+  %mul3 = mul nsw i32 %mul, %call2, !dbg !62
+  ret i32 %mul3, !dbg !62
+}
+
+define dso_local i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #1 !dbg !63 !annotation !72 {
+entry:
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !70, metadata !DIExpression()), !dbg !73
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !71, metadata !DIExpression()), !dbg !73
+  %cmp = icmp eq i32 %argc, 2, !dbg !74
+  br i1 %cmp, label %return, label %if.end, !dbg !74
+
+if.end:   ; preds = %entry
+  %cmp1 = icmp slt i32 %argc, 5, !dbg !75
+  br i1 %cmp1, label %if.then2, label %if.else, !dbg !75
+
+if.then2: ; preds = %if.end
+  %call = tail call i32 @"?bar@@YAHH@Z"(i32 undef) #1, !dbg !76
+  br label %return, !dbg !76
+
+if.else:  ; preds = %if.end
+  %call3 = tail call i32 @"?foo@@YAHH@Z"(i32 %argc) #1, !dbg !79
+  br label %return, !dbg !79
+
+return:   ; preds = %entry, %if.else, %if.then2
+  %retval.0 = phi i32 [ %call, %if.then2 ], [ %call3, %if.else ], [ 0, %entry ], !dbg !73
+  ret i32 %retval.0, !dbg !81
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #3
+
+attributes #1 = { optsize }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6, !7, !8, !9, !38}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "pgo.cpp", directory: "")
+!2 = !{}
+!5 = !{i32 2, !"CodeView", i32 1}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"wchar_size", i32 2}
+!8 = !{i32 7, !"PIC Level", i32 2}
+!9 = !{i32 1, !"ProfileSummary", !10}
+!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}
+!11 = !{!"ProfileFormat", !"InstrProf"}
+!12 = !{!"TotalCount", i64 2}
+!13 = !{!"MaxCount", i64 1}
+!14 = !{!"MaxInternalCount", i64 1}
+!15 = !{!"MaxFunctionCount", i64 1}
+!16 = !{!"NumCounts", i64 5}
+!17 = !{!"NumFunctions", i64 4}
+!18 = !{!"IsPartialProfile", i64 0}
+!19 = !{!"PartialProfileRatio", double 0.00e+00}
+!20 = !{!"DetailedSummary", !21}
+!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
+!22 = !{i32 1, i64 0, i32 0}
+!23 = !{i32 10, i64 0, i32 0}
+!24 = !{i32 20, i64 0, i32 0}
+!25 = !{i32 30, i64 0, 

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

2021-04-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2828-2829
+  "%0 attribute requires that the return value, all parameters, and any "
+  "temporaries created by the expression are trivially destructible and "
+  "do not require ARC">;
+def err_musttail_needs_call : Error<

Can we somehow avoid talking about ARC where it's not relevant? While it'd be 
nice to be more precise here, my main concern is that we shouldn't be 
mentioning ARC to people for whom it's not a meaningful term (eg, when not 
compiling Objective-C or Objective-C++). Perhaps the simplest approach would be 
to only mention ARC if `getLangOpts().ObjCAutoRefCount` is set?



Comment at: clang/lib/AST/AttrImpl.cpp:221-226
+  // Elide constructors even if this is disabled with -fno-elide-constructors
+  // because 'musttail' is a more local setting.
+  if (CCE && CCE->isElidable()) {
+assert(CCE->getNumArgs() == 1); // Copy or move constructor.
+Ex = CCE->getArg(0);
+  }

`IgnoreImplicitAsWritten` should already skip over implicit elidable 
constructors, so I would imagine this is skipping over elidable //explicit// 
constructor calls (eg, `[[musttail]] return T(make());` would perform a 
tail-call to `make()`). Is that what we want?



Comment at: clang/lib/CodeGen/CGStmt.cpp:665
+  SaveAndRestore save_musttail(MustTailCall, musttail);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }

In the case where we're forcibly eliding a constructor, we'll need to emit a 
return statement that returns `musttail` call expression here rather than 
emitting the original substatement. Otherwise the tail call we emit will be 
initializing a local temporary rather than initializing our return slot. Eg, 
given:

```
struct A {
  A(const A&);
  ~A();
  char data[32];
};
A f();
A g() {
  [[clang::musttail]] return f();
}
```
under `-fno-elide-constructors` when targeting C++11, say, we'll normally lower 
that into something like:
```
void f(A *return_slot);
void g(A *return_slot) {
  A temporary; //uninitialized
  f(); // call f
  A::A(return_slot, temporary); // call copy constructor to copy into return 
slot
}
```
... and with the current patch, it looks like we'll add a 'ret void' after the 
call to `f`, leaving `g`'s return slot uninitialized and passing an address 
into `f` that refers to a variable that will no longer exist once `f` is 
called. We need to instead lower to:
```
void f(A *return_slot);
void g(A *return_slot) {
  f(return_slot); // call f
}
```
Probably the easiest way to do this would be to change the return value on the 
`ReturnStmt` to be the tail-called `CallExpr` when attaching the attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-04-08 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f181086b5cb: [ASTMatchers] Add `cxxBaseSpecifier` matcher 
(non-top-level) (authored by nick, committed by stephenkelly).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69218

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -297,6 +297,17 @@
   EXPECT_TRUE(matches("int b[7];", M));
 }
 
+TEST_F(RegistryTest, CXXBaseSpecifier) {
+  // TODO: rewrite with top-level cxxBaseSpecifier matcher when available
+  DeclarationMatcher ClassHasAnyDirectBase =
+  constructMatcher("cxxRecordDecl",
+   constructMatcher("hasDirectBase",
+constructMatcher("cxxBaseSpecifier")))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(notMatches("class X {};", ClassHasAnyDirectBase));
+}
+
 TEST_F(RegistryTest, CXXCtorInitializer) {
   Matcher CtorDecl = constructMatcher(
   "cxxConstructorDecl",
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -320,6 +320,15 @@
 varDecl(hasType(pointsTo(ClassX);
 }
 
+TEST(HasType, TakesQualTypeMatcherAndMatchesCXXBaseSpecifier) {
+  TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X")));
+  CXXBaseSpecifierMatcher BaseClassX = cxxBaseSpecifier(hasType(ClassX));
+  DeclarationMatcher ClassHasBaseClassX =
+  cxxRecordDecl(hasDirectBase(BaseClassX));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}
+
 TEST(HasType, TakesDeclMatcherAndMatchesExpr) {
   DeclarationMatcher ClassX = recordDecl(hasName("X"));
   EXPECT_TRUE(
@@ -337,6 +346,15 @@
 notMatches("class X {}; void y() { X *x; }", varDecl(hasType(ClassX;
 }
 
+TEST(HasType, TakesDeclMatcherAndMatchesCXXBaseSpecifier) {
+  DeclarationMatcher ClassX = recordDecl(hasName("X"));
+  CXXBaseSpecifierMatcher BaseClassX = cxxBaseSpecifier(hasType(ClassX));
+  DeclarationMatcher ClassHasBaseClassX =
+  cxxRecordDecl(hasDirectBase(BaseClassX));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}
+
 TEST(HasType, MatchesTypedefDecl) {
   EXPECT_TRUE(matches("typedef int X;", typedefDecl(hasType(asString("int");
   EXPECT_TRUE(matches("typedef const int T;",
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -4400,6 +4400,13 @@
 return;
   }
 
+  DeclarationMatcher ClassHasAnyDirectBase =
+  cxxRecordDecl(hasDirectBase(cxxBaseSpecifier()));
+  EXPECT_TRUE(notMatches("class X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(matches("class X {}; class Y : public virtual X {};",
+  ClassHasAnyDirectBase));
+
   EXPECT_TRUE(matches(
   R"cc(
 class Base {};
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -175,6 +175,7 @@
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coyieldExpr);
   REGISTER_MATCHER(cudaKernelCallExpr);
+  REGISTER_MATCHER(cxxBaseSpecifier);
   REGISTER_MATCHER(cxxBindTemporaryExpr);
   REGISTER_MATCHER(cxxBoolLiteral);
   REGISTER_MATCHER(cxxCatchStmt);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -756,6 +756,7 @@
 const internal::VariadicDynCastAllOfMatcher parmVarDecl;
 const internal::VariadicDynCastAllOfMatcher
 

[clang] 2f18108 - [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-04-08 Thread Stephen Kelly via cfe-commits

Author: Nikita Kniazev
Date: 2021-04-09T00:05:36+01:00
New Revision: 2f181086b5cbbe83c4492aa44484a77ed06ec812

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

LOG: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

Required for capturing base specifier in matchers:
  `cxxRecordDecl(hasDirectBase(cxxBaseSpecifier().bind("base")))`

Reviewed By: steveire, aaron.ballman

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index b8fb27b126fc1..ab36402e4bca5 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -573,6 +573,15 @@ Node Matchers
 Return 
typeNameParameters
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html;>CXXBaseSpecifiercxxBaseSpecifierMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html;>CXXBaseSpecifier...
+Matches class 
bases.
+
+Examples matches public virtual B.
+  class B {};
+  class C : public virtual B {};
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html;>CXXCtorInitializercxxCtorInitializerMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html;>CXXCtorInitializer...
 Matches 
constructor initializers.
 
@@ -6144,8 +6153,8 @@ AST Traversal Matchers
 
 
 
-Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html;>CXXBaseSpecifierhasTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl 
InnerMatcher
-Overloaded to match the 
declaration of the expression's or value
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html;>CXXBaseSpecifierhasTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl 
InnerMatcher
+Overloaded to match the 
declaration of the expression's or value
 declaration's type.
 
 In case of a value declaration (for example a variable declaration),
@@ -6157,9 +6166,12 @@ AST Traversal Matchers
 Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
 and friend class X (matcher = friendDecl(hasType("X"))
+and public virtual X (matcher = cxxBaseSpecifier(hasType(
+  cxxRecordDecl(hasName("X"
  class X {};
  void y(X x) { x; X z; }
  class Y { friend class X; };
+ class Z : public virtual X {};
 
 Example matches class Derived
 (matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))
@@ -6171,6 +6183,24 @@ AST Traversal Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html;>CXXBaseSpecifierhasTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualType
 InnerMatcher
+Matches if the expression's 
or declaration's type matches a type
+matcher.
+
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
+and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
+and U (matcher = typedefDecl(hasType(asString("int")))
+and friend class X (matcher = friendDecl(hasType("X"))
+and public virtual X (matcher = cxxBaseSpecifier(hasType(
+  asString("class X")))
+ class X {};
+ void y(X x) { x; X z; }
+ typedef int U;
+ class Y { friend class X; };
+ class Z : public virtual X {};
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExprforEachArgumentWithParamMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr 
ArgMatcher, Matcherhttps://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html;>ParmVarDecl
 ParamMatcher
 Matches 
all arguments and their respective ParmVarDecl.
 
@@ -7282,8 +7312,8 @@ AST Traversal Matchers
 
 
 
-Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprhasTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl 
InnerMatcher
-Overloaded to match the 
declaration of the expression's or value
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprhasTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl 
InnerMatcher
+Overloaded to match the 
declaration of the expression's or value
 declaration's type.
 
 In case of a value declaration (for 

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

2021-04-08 Thread Sergey Maslov via Phabricator via cfe-commits
smaslov added a comment.

> Sergey, remind me, does icc always emit unaligned loads/stores? Is there any 
> option to control it?

There was a control to emit aligned opcodes, yes, but I don't think anyone ever 
used it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D100150: [Sanitizers] Add a flag -f[no-]sanitize-merge-traps

2021-04-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added reviewers: pcc, phosek, rsmith, zequanwu.
Herald added subscribers: jansvoboda11, dexonsmith, dang.
rnk requested review of this revision.
Herald added a project: clang.

Without this flag, enabling optimizations causes clang to emit a single
ubsantrap for every check failure of a particular kind. Adding this flag
allows the user to control this behavior separately, so they can choose
to have increased code size in exchange for more debuggable code.

A Chrome developer requested this feature here:
https://crbug.com/1185451

I made this change in such a way that it doesn't litter the cc1 line
with redundant flags: if the user does not pass the positive or negative
version if this flag, it is not forwarded to the cc1 invocation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100150

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/catch-undef-behavior.c
  clang/test/CodeGen/cfi-nomerge.c
  clang/test/CodeGen/trapv-nomerge.c
  clang/test/Driver/sanitize-merge-traps.c

Index: clang/test/Driver/sanitize-merge-traps.c
===
--- /dev/null
+++ clang/test/Driver/sanitize-merge-traps.c
@@ -0,0 +1,8 @@
+// RUN: %clang -c %s -fsanitize=cfi -flto -O2 -fno-sanitize-merge-traps -### 2>&1 | FileCheck %s --check-prefix=NOMERGE
+// RUN: %clang -c %s -fsanitize=cfi -flto -O0 -fsanitize-merge-traps -### 2>&1 | FileCheck %s --check-prefix=MERGE
+// RUN: %clang -c %s -fsanitize=cfi -flto -O2 -### 2>&1 | FileCheck %s --check-prefix=NONE
+// RUN: %clang -c %s -fsanitize=cfi -flto -O0 -### 2>&1 | FileCheck %s --check-prefix=NONE
+
+// NOMERGE: "-fno-sanitize-merge-traps"
+// MERGE: "-fsanitize-merge-traps"
+// NONE-NOT: "-f{{(no-)?}}sanitize-merge-traps"
Index: clang/test/CodeGen/trapv-nomerge.c
===
--- /dev/null
+++ clang/test/CodeGen/trapv-nomerge.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -O2 -triple x86_64-apple-darwin10 -ftrapv -fno-sanitize-merge-traps %s -emit-llvm -o - | FileCheck %s --check-prefix=NOMERGE
+// RUN: %clang_cc1 -O2 -triple x86_64-apple-darwin10 -ftrapv -fsanitize-merge-traps %s -emit-llvm -o - | FileCheck %s --check-prefix=MERGE
+
+unsigned int ui, uj, uk;
+int i, j, k;
+
+int twoChecks() {
+  ++i;
+  ++j;
+  return 42;
+}
+
+// NOMERGE-LABEL: define i32 @twoChecks()
+// NOMERGE:  call void @llvm.ubsantrap(i8 0) #[[ATTR:[0-9]+]]
+// NOMERGE-NEXT: unreachable
+// NOMERGE:  call void @llvm.ubsantrap(i8 0) #[[ATTR]]
+// NOMERGE-NEXT: unreachable
+
+// NOMERGE: #[[ATTR]] = { nomerge noreturn nounwind }
+
+// MERGE-LABEL: define i32 @twoChecks()
+// MERGE:  call void @llvm.ubsantrap(i8 0)
+// MERGE-NEXT: unreachable
+// MERGE-NOT: llvm.ubsantrap
+// MERGE: ret i32 42
Index: clang/test/CodeGen/cfi-nomerge.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-nomerge.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - %s -fsanitize-merge-traps | FileCheck --check-prefix=MERGE %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - %s -fno-sanitize-merge-traps | FileCheck --check-prefix=NOMERGE %s
+
+int twoChecks(void (*f)(), void (*g)()) {
+  f();
+  g();
+  return 42;
+}
+
+// NOMERGE-LABEL: define dso_local i32 @twoChecks(
+// NOMERGE:  call void @llvm.ubsantrap(i8 2) #[[ATTR:[0-9]+]]
+// NOMERGE-NEXT: unreachable
+// NOMERGE:  call void @llvm.ubsantrap(i8 2) #[[ATTR]]
+// NOMERGE-NEXT: unreachable
+
+// NOMERGE: #[[ATTR]] = { nomerge noreturn nounwind }
+
+// MERGE-LABEL: define dso_local i32 @twoChecks(
+// MERGE:  call void @llvm.ubsantrap(i8 2)
+// MERGE-NEXT: unreachable
+// MERGE-NOT: llvm.ubsantrap
+// MERGE: ret i32 42
Index: clang/test/CodeGen/catch-undef-behavior.c
===
--- clang/test/CodeGen/catch-undef-behavior.c
+++ clang/test/CodeGen/catch-undef-behavior.c
@@ -387,4 +387,4 @@
 
 // CHECK-UBSAN: ![[WEIGHT_MD]] = !{!"branch_weights", i32 1048575, i32 1}
 
-// CHECK-TRAP: attributes [[NR_NUW]] = { noreturn nounwind }
+// CHECK-TRAP: attributes [[NR_NUW]] = { nomerge noreturn nounwind }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1935,6 +1935,13 @@
   Args.getAllArgValues(OPT_fsanitize_trap_EQ), Diags,
   Opts.SanitizeTrap);
 
+  // Merging sanitizer traps saves code size, but makes debugging harder. By
+  // default, merge 

[PATCH] D100148: [Driver] Fix compiler-rt lookup for x32

2021-04-08 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk created this revision.
hvdijk added a reviewer: glaubitz.
hvdijk added a project: clang.
Herald added subscribers: pengfei, dberris.
hvdijk requested review of this revision.
Herald added a subscriber: cfe-commits.

x86_64-linux-gnu and x86_64-linux-gnux32 use different ABIs and objects built 
for one cannot be used for the other. In order to build and use compiler-rt for 
x32, we need to treat x32 as a new arch there. This updates the driver to 
search using the new arch name.

This is a prerequisite for @glaubitz's D99988  
and is not useful on its own. It should be submitted together with that when 
that is ready.

The arch name used here is "x32" to match D99988 
. If that should turn out to not be specific 
enough, it could be changed to something like "x86_64_x32".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100148

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -283,25 +283,25 @@
 // CHECK-MSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.msan
 
 // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // RUN: %clang -fsanitize=float-divide-by-zero %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN: -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // CHECK-UBSAN-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.asan
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.ubsan_standalone_cxx
-// CHECK-UBSAN-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.ubsan_standalone-i386.a" "--no-whole-archive"
+// CHECK-UBSAN-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.ubsan_standalone-x32.a" "--no-whole-archive"
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.asan
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.ubsan_standalone_cxx
 // CHECK-UBSAN-LINUX-NOT: "-lstdc++"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -383,6 +383,10 @@
   if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
 return "i686";
 
+  if (TC.getArch() == llvm::Triple::x86_64 &&
+  Triple.getEnvironment() == llvm::Triple::GNUX32)
+return "x32";
+
   return llvm::Triple::getArchTypeName(TC.getArch());
 }
 


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -283,25 +283,25 @@
 // CHECK-MSAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.msan
 
 // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // RUN: %clang -fsanitize=float-divide-by-zero %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
-// RUN: -target i386-unknown-linux -fuse-ld=ld \
-// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -target x86_64-unknown-linux-gnux32 -fuse-ld=ld \
+// RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree \
 // RUN: -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-LINUX %s
 
 // CHECK-UBSAN-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.asan
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.ubsan_standalone_cxx
-// CHECK-UBSAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.ubsan_standalone-i386.a" "--no-whole-archive"
+// CHECK-UBSAN-LINUX: "--whole-archive" 

[PATCH] D99368: [compiler-rt][hwasan] Add C++17 new/delete operators with alignment

2021-04-08 Thread Leonard Chan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
leonardchan marked an inline comment as done.
Closed by commit rGa7b51d8a4fc8: [compiler-rt][hwasan] Add C++17 new/delete 
operators with alignment (authored by leonardchan).

Changed prior to commit:
  https://reviews.llvm.org/D99368?vs=88=336247#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99368

Files:
  compiler-rt/lib/hwasan/hwasan_new_delete.cpp


Index: compiler-rt/lib/hwasan/hwasan_new_delete.cpp
===
--- compiler-rt/lib/hwasan/hwasan_new_delete.cpp
+++ compiler-rt/lib/hwasan/hwasan_new_delete.cpp
@@ -27,6 +27,12 @@
   void *res = hwasan_malloc(size, );\
   if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, );\
   return res
+#define OPERATOR_NEW_ALIGN_BODY(nothrow)\
+  GET_MALLOC_STACK_TRACE;   \
+  void *res = hwasan_aligned_alloc(static_cast(align), size, ); \
+  if (!nothrow && UNLIKELY(!res))   \
+ReportOutOfMemory(size, );\
+  return res
 
 #define OPERATOR_DELETE_BODY \
   GET_MALLOC_STACK_TRACE; \
@@ -50,6 +56,7 @@
 // Fake std::nothrow_t to avoid including .
 namespace std {
   struct nothrow_t {};
+  enum class align_val_t : size_t {};
 }  // namespace std
 
 
@@ -66,6 +73,22 @@
 void *operator new[](size_t size, std::nothrow_t const&) {
   OPERATOR_NEW_BODY(true /*nothrow*/);
 }
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new(
+size_t size, std::align_val_t align) {
+  OPERATOR_NEW_ALIGN_BODY(false /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new[](
+size_t size, std::align_val_t align) {
+  OPERATOR_NEW_ALIGN_BODY(false /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new(
+size_t size, std::align_val_t align, std::nothrow_t const &) {
+  OPERATOR_NEW_ALIGN_BODY(true /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new[](
+size_t size, std::align_val_t align, std::nothrow_t const &) {
+  OPERATOR_NEW_ALIGN_BODY(true /*nothrow*/);
+}
 
 INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
 void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
@@ -77,5 +100,21 @@
 void operator delete[](void *ptr, std::nothrow_t const&) {
   OPERATOR_DELETE_BODY;
 }
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete(
+void *ptr, std::align_val_t align) NOEXCEPT {
+  OPERATOR_DELETE_BODY;
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete[](
+void *ptr, std::align_val_t) NOEXCEPT {
+  OPERATOR_DELETE_BODY;
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete(
+void *ptr, std::align_val_t, std::nothrow_t const &) NOEXCEPT {
+  OPERATOR_DELETE_BODY;
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete[](
+void *ptr, std::align_val_t, std::nothrow_t const &) NOEXCEPT {
+  OPERATOR_DELETE_BODY;
+}
 
 #endif // OPERATOR_NEW_BODY


Index: compiler-rt/lib/hwasan/hwasan_new_delete.cpp
===
--- compiler-rt/lib/hwasan/hwasan_new_delete.cpp
+++ compiler-rt/lib/hwasan/hwasan_new_delete.cpp
@@ -27,6 +27,12 @@
   void *res = hwasan_malloc(size, );\
   if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, );\
   return res
+#define OPERATOR_NEW_ALIGN_BODY(nothrow)\
+  GET_MALLOC_STACK_TRACE;   \
+  void *res = hwasan_aligned_alloc(static_cast(align), size, ); \
+  if (!nothrow && UNLIKELY(!res))   \
+ReportOutOfMemory(size, );\
+  return res
 
 #define OPERATOR_DELETE_BODY \
   GET_MALLOC_STACK_TRACE; \
@@ -50,6 +56,7 @@
 // Fake std::nothrow_t to avoid including .
 namespace std {
   struct nothrow_t {};
+  enum class align_val_t : size_t {};
 }  // namespace std
 
 
@@ -66,6 +73,22 @@
 void *operator new[](size_t size, std::nothrow_t const&) {
   OPERATOR_NEW_BODY(true /*nothrow*/);
 }
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new(
+size_t size, std::align_val_t align) {
+  OPERATOR_NEW_ALIGN_BODY(false /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new[](
+size_t size, std::align_val_t align) {
+  OPERATOR_NEW_ALIGN_BODY(false /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new(
+size_t size, std::align_val_t align, std::nothrow_t const &) {
+  OPERATOR_NEW_ALIGN_BODY(true /*nothrow*/);
+}
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new[](
+size_t size, std::align_val_t align, 

[PATCH] D100144: [AMDGPU] Allow relaxed/consume memory order for atomic inc/dec

2021-04-08 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Nice. Thank you for fixing the oversight.


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

https://reviews.llvm.org/D100144

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


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

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I think I wouldn't mind if we just didn't emit aligned loads/store instructions 
for AVX/AVX512 from isel and other places in the compiler in the first place. 
As noted, if the load gets folded the alignment check doesn't happen. That 
would reduce the size of the isel tables and remove branches, reducing 
complexity of the compiler. Adding a new step and a command line to undo the 
earlier decision increases complexity.

The counter argument to that is that the alignment check has found bugs in the 
vectorizer on more than one occasion that I know of.

Sergey, remind me, does icc always emit unaligned loads/stores? Is there any 
option to control it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith 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/D100136/new/

https://reviews.llvm.org/D100136

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


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

2021-04-08 Thread Sergey Maslov via Phabricator via cfe-commits
smaslov added a comment.

> I really don't think this should go in.

Here are more arguments for why, I think, this is an useful option in my 
opinion, in arbitrary order:

1. This was requested by and added for users of Intel Compiler. Having similar 
option in LLVM would make the two compilers more compatible and ease the 
transition of new customers to LLVM.
2. This fixes an inconsistency in optimization; suppose a load operation was 
merged into another instruction  (e.g., load and add becomes `add [memop]'). If 
a misaligned pointer is passed to the two-instruction sequence, it will raise 
an exception. If the same pointer is passed to the memop instruction, it will 
work. Thus, the behavior of misalignment depends upon what optimization levels 
and passes are applied, and small source changes could cause issues to appear 
and disappear. It's better for the user to consistently use unaligned 
load/store to improve the debug experience.
3. Makes good use of HW that is capable of handling misaligned data gracefully. 
It is not necessarily a bug in users code but a third-part library. For example 
it would allow using a library built in old ages where stack alignment was 
4-byte only.

If you still think this can hinder the raise of a desired exception for a 
mis-aligned access (I'd argue that "going slower" is better than "raising 
exception"), then let's consider adding this as an option that is OFF by 
default.
This would give the most flexibility to everyone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99565

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


[PATCH] D99790: [CGCall] Annotate `this` argument with alignment

2021-04-08 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D99790#2677917 , @brooksmoses wrote:

> As a heads up, I'm seeing segfaults on internal code as a result of this 
> change, as well as errors in Eigen's unalignedassert.cpp test (specifically, 
> this line asserts: 
> https://github.com/madlib/eigen/blob/master/test/unalignedassert.cpp#L151).

Eigen's case is UB -- the test case is verifying that the constructor of the 
Matrix type throws an exception if called on an under-aligned instance, I think 
in an effort to make the UB noisier for their users. It already didn't work in 
GCC, and they had a "workaround", here, 
https://github.com/madlib/eigen/blob/fa14b05455c9d9737ae577f686188ef358df9020/Eigen/src/Core/DenseStorage.h#L63

It's unsurprising that this change in Clang causes the same code to fail in 
Clang, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99790

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


[PATCH] D100144: [AMDGPU] Allow relaxed/consume memory order for atomic inc/dec

2021-04-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: JonChesterfield.
Herald added subscribers: jfb, t-tye, tpr, dstuttard, jvesely, kzhuravl.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

https://reviews.llvm.org/D100144

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl

Index: clang/test/SemaOpenCL/builtins-amdgcn-error.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-error.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-error.cl
@@ -148,7 +148,8 @@
 void test_atomic_inc32() {
   uint val = 17;
   val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
-  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_RELAXED, "workgroup");
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_CONSUME, "workgroup");
   val = __builtin_amdgcn_atomic_inc32(4);// expected-error {{too few arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_inc32(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_inc32(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
@@ -162,7 +163,8 @@
 void test_atomic_inc64() {
   __UINT64_TYPE__ val = 17;
   val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
-  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_RELAXED, "workgroup");
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_CONSUME, "workgroup");
   val = __builtin_amdgcn_atomic_inc64(4);// expected-error {{too few arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_inc64(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_inc64(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
@@ -176,7 +178,8 @@
 void test_atomic_dec32() {
   uint val = 17;
   val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
-  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_RELAXED, "workgroup");
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_CONSUME, "workgroup");
   val = __builtin_amdgcn_atomic_dec32(4);// expected-error {{too few arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_dec32(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_dec32(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
@@ -190,7 +193,8 @@
 void test_atomic_dec64() {
   __UINT64_TYPE__ val = 17;
   val = __builtin_amdgcn_atomic_dec64(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
-  val = __builtin_amdgcn_atomic_dec64(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec64(, val, __ATOMIC_RELAXED, "workgroup");
+  val = __builtin_amdgcn_atomic_dec64(, val, __ATOMIC_CONSUME, "workgroup");
   val = __builtin_amdgcn_atomic_dec64(4);// expected-error {{too few arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_dec64(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
   val = __builtin_amdgcn_atomic_dec64(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
Index: clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
===
--- 

[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Sema/SemaAttr.cpp:896
+  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
+  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
+if (llvm::any_of(StrictSubjectMatchRuleSet,

rsmith wrote:
> Does this need to be a loop? (Can we have a grandparent matcher rule?)
No. We currently have two levels of tablegen classes: 
`AttrSubjectMatcherRule subrules>` and 
`AttrSubjectMatcherSubRule` does not allow further nesting.



Comment at: clang/test/Sema/pragma-attribute-strict-subjects.c:59
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(enum_constant, function, record(unless(is_union)), variable, 
variable(is_parameter)))
 // FIXME: comma in this diagnostic is wrong.
+// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant'}}

rsmith wrote:
> The FIXME here is "fixed" now. Please can you add another example that shows 
> the incorrect comma and move the FIXME there?
Added another matcher to preserve the comma in the diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100136

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


[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 336236.
tra added a comment.

Addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100136

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Sema/pragma-attribute-strict-subjects.c


Index: clang/test/Sema/pragma-attribute-strict-subjects.c
===
--- clang/test/Sema/pragma-attribute-strict-subjects.c
+++ clang/test/Sema/pragma-attribute-strict-subjects.c
@@ -55,9 +55,9 @@
 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}}
 #pragma clang attribute pop
 
-#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(enum_constant, function, record(unless(is_union)), variable, 
variable(is_parameter)))
+#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(enum_constant, function, record(unless(is_union)), variable, 
variable(is_parameter), enum))
 // FIXME: comma in this diagnostic is wrong.
-// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant', and 'variable(is_parameter)'}}
+// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant', and 'enum'}}
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(function, record(unless(is_union)), enum))
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -195,3 +195,12 @@
 #pragma clang attribute pop
 #pragma clang attribute push([[clang::uninitialized]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter // expected-error 
{{attribute 'uninitialized' can't be applied to 'variable(is_parameter)', and 
'variable(unless(is_parameter))'}}
 #pragma clang attribute pop
+// We're allowed to apply attributes to subsets of allowed subjects.
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable)
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_thread_local))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_global))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter
+#pragma clang attribute pop
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -875,12 +875,33 @@
 }
 Rules.clear();
   } else {
-for (const auto  : StrictSubjectMatchRuleSet) {
-  if (Rules.erase(Rule.first)) {
+// Each rule in Rules must be a strict subset of the attribute's
+// SubjectMatch rules.  I.e. we're allowed to use
+// `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
+// but should not allow `apply_to=variables` on an attribute which has
+// `SubjectList<[GlobalVar]>`.
+for (const auto  : StrictSubjectMatchRuleSet) {
+  // First, check for exact match.
+  if (Rules.erase(StrictRule.first)) {
 // Add the rule to the set of attribute receivers only if it's 
supported
 // in the current language mode.
-if (Rule.second)
-  SubjectMatchRules.push_back(Rule.first);
+if (StrictRule.second)
+  SubjectMatchRules.push_back(StrictRule.first);
+  }
+}
+// Check remaining rules for subset matches.
+auto RulesToCheck = Rules;
+for (const auto  : RulesToCheck) {
+  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
+  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
+if (llvm::any_of(StrictSubjectMatchRuleSet,
+ [ParentRule](const auto ) {
+   return StrictRule.first == *ParentRule &&
+  StrictRule.second; // IsEnabled
+ })) {
+  SubjectMatchRules.push_back(MatchRule);
+  Rules.erase(MatchRule);
+}
   }
 }
   }


Index: clang/test/Sema/pragma-attribute-strict-subjects.c
===
--- clang/test/Sema/pragma-attribute-strict-subjects.c
+++ clang/test/Sema/pragma-attribute-strict-subjects.c
@@ -55,9 +55,9 @@
 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}}
 #pragma clang attribute pop
 
-#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter)))
+#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter), 

[PATCH] D99368: [compiler-rt][hwasan] Add C++17 new/delete operators with alignment

2021-04-08 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.

LGTM




Comment at: compiler-rt/lib/hwasan/hwasan_new_delete.cpp:104
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete(
+void *ptr, std::align_val_t align)NOEXCEPT {
+  OPERATOR_DELETE_BODY;

missing space before NOEXCEPT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99368

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


[PATCH] D99790: [CGCall] Annotate `this` argument with alignment

2021-04-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D99790#2677917 , @brooksmoses wrote:

> As a heads up, I'm seeing segfaults on internal code as a result of this 
> change, as well as errors in Eigen's unalignedassert.cpp test (specifically, 
> this line asserts: 
> https://github.com/madlib/eigen/blob/master/test/unalignedassert.cpp#L151).

Would be good to have a small standalone reproducer.
Not really sure how we can end up with a misaligned `this`, but it sounds like 
UB.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99790

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


[PATCH] D99790: [CGCall] Annotate `this` argument with alignment

2021-04-08 Thread Brooks Moses via Phabricator via cfe-commits
brooksmoses added a comment.

As a heads up, I'm seeing segfaults on internal code as a result of this 
change, as well as errors in Eigen's unalignedassert.cpp test (specifically, 
this line asserts: 
https://github.com/madlib/eigen/blob/master/test/unalignedassert.cpp#L151).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99790

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


[PATCH] D99368: [compiler-rt][hwasan] Add C++17 new/delete operators with alignment

2021-04-08 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 but you should wait a bit for @pcc or @eugenis to have a chance to to 
review this as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99368

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


[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaAttr.cpp:896
+  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
+  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
+if (llvm::any_of(StrictSubjectMatchRuleSet,

Does this need to be a loop? (Can we have a grandparent matcher rule?)



Comment at: clang/test/Sema/pragma-attribute-strict-subjects.c:59
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(enum_constant, function, record(unless(is_union)), variable, 
variable(is_parameter)))
 // FIXME: comma in this diagnostic is wrong.
+// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant'}}

The FIXME here is "fixed" now. Please can you add another example that shows 
the incorrect comma and move the FIXME there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100136

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


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Seems reasonable, but we still need a small IR test.




Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:807
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);

nit, the more common style to name parameters looks like 
`getProfileSummary(/*IsCS=*/false)`. Sort of more Python-y.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1434
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;

I think the preferred spelling is `GV.hasProfileData()`, I think that's 
functionally equivalent.


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

https://reviews.llvm.org/D4

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


[PATCH] D100139: [ifs][elfabi] Merge llvm-ifs/elfabi tools

2021-04-08 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
haowei added reviewers: phosek, plotfi, compnerd, mcgrathr.
Herald added subscribers: hiraditya, mgorny.
haowei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This change merges llvm-elfabi and llvm-ifs tools.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100139

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/lib/Driver/ToolChains/InterfaceStubs.cpp
  clang/test/InterfaceStubs/driver-test.c
  llvm/include/llvm/InterfaceStub/ELFObjHandler.h
  llvm/include/llvm/InterfaceStub/IFSHandler.h
  llvm/include/llvm/InterfaceStub/IFSStub.h
  llvm/lib/InterfaceStub/ELFObjHandler.cpp
  llvm/lib/InterfaceStub/IFSHandler.cpp
  llvm/lib/InterfaceStub/IFSStub.cpp
  llvm/test/CMakeLists.txt
  llvm/test/tools/llvm-ifs/binary-read-add-soname.test
  llvm/test/tools/llvm-ifs/binary-read-arch.test
  llvm/test/tools/llvm-ifs/binary-read-bad-soname.test
  llvm/test/tools/llvm-ifs/binary-read-bad-vaddr.test
  llvm/test/tools/llvm-ifs/binary-read-neededlibs-bad-offset.test
  llvm/test/tools/llvm-ifs/binary-read-neededlibs.test
  llvm/test/tools/llvm-ifs/binary-read-no-dt-strsz.test
  llvm/test/tools/llvm-ifs/binary-read-no-dt-strtab.test
  llvm/test/tools/llvm-ifs/binary-read-no-dynamic.test
  llvm/test/tools/llvm-ifs/binary-read-replace-soname.test
  llvm/test/tools/llvm-ifs/binary-read-soname-no-null.test
  llvm/test/tools/llvm-ifs/binary-read-soname.test
  llvm/test/tools/llvm-ifs/binary-read-syms-gnu-hash.test
  llvm/test/tools/llvm-ifs/binary-read-syms-sysv-hash.test
  llvm/test/tools/llvm-ifs/conflict-header-triple.ifs
  llvm/test/tools/llvm-ifs/conflict-header-version.ifs
  llvm/test/tools/llvm-ifs/conflict-size.ifs
  llvm/test/tools/llvm-ifs/conflict-type.ifs
  llvm/test/tools/llvm-ifs/conflict-weak.ifs
  llvm/test/tools/llvm-ifs/default-empty.ifs
  llvm/test/tools/llvm-ifs/empty1.ifs
  llvm/test/tools/llvm-ifs/empty2.ifs
  llvm/test/tools/llvm-ifs/fail-file-open.test
  llvm/test/tools/llvm-ifs/fail-file-write-windows.test
  llvm/test/tools/llvm-ifs/fail-file-write.test
  llvm/test/tools/llvm-ifs/func.ifs
  llvm/test/tools/llvm-ifs/ifs-emits-current-version.test
  llvm/test/tools/llvm-ifs/ifs-read-basic.test
  llvm/test/tools/llvm-ifs/ios-tbd.ifs
  llvm/test/tools/llvm-ifs/macos-tbd.ifs
  llvm/test/tools/llvm-ifs/object-function-size-weak-combo.ifs
  llvm/test/tools/llvm-ifs/object.ifs
  llvm/test/tools/llvm-ifs/preserve-dates-stub.test
  llvm/test/tools/llvm-ifs/read-elf-dynsym.test
  llvm/test/tools/llvm-ifs/read-ifs-as-elf.test
  llvm/test/tools/llvm-ifs/read-ifs-as-ifs.test
  llvm/test/tools/llvm-ifs/read-ifs-with-bad-bitwidth.test
  llvm/test/tools/llvm-ifs/read-ifs-with-bad-endianness.test
  llvm/test/tools/llvm-ifs/read-unsupported-file.test
  llvm/test/tools/llvm-ifs/strong.ifs
  llvm/test/tools/llvm-ifs/tvos-tbd.ifs
  llvm/test/tools/llvm-ifs/version-ok.ifs
  llvm/test/tools/llvm-ifs/watchos-tbd.ifs
  llvm/test/tools/llvm-ifs/weak-mismatch.ifs
  llvm/test/tools/llvm-ifs/weak.ifs
  llvm/test/tools/llvm-ifs/write-stub-no-nonlocal-symbol.test
  llvm/test/tools/llvm-ifs/write-stub.test
  llvm/tools/llvm-elfabi/CMakeLists.txt
  llvm/tools/llvm-elfabi/ErrorCollector.cpp
  llvm/tools/llvm-elfabi/ErrorCollector.h
  llvm/tools/llvm-elfabi/llvm-elfabi.cpp
  llvm/tools/llvm-ifs/CMakeLists.txt
  llvm/tools/llvm-ifs/ErrorCollector.cpp
  llvm/tools/llvm-ifs/ErrorCollector.h
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
  llvm/utils/gn/secondary/llvm/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn
+++ /dev/null
@@ -1,12 +0,0 @@
-executable("llvm-elfabi") {
-  deps = [
-"//llvm/lib/InterfaceStub",
-"//llvm/lib/Object",
-"//llvm/lib/Support",
-"//llvm/lib/TextAPI",
-  ]
-  sources = [
-"ErrorCollector.cpp",
-"llvm-elfabi.cpp",
-  ]
-}
Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -230,7 +230,6 @@
 "//llvm/tools/llvm-dis",
 "//llvm/tools/llvm-dwarfdump",
 "//llvm/tools/llvm-dwp",
-"//llvm/tools/llvm-elfabi",
 "//llvm/tools/llvm-exegesis",
 "//llvm/tools/llvm-extract",
 "//llvm/tools/llvm-gsymutil:llvm-gsymutil",
Index: llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
===
--- llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
+++ llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
@@ -17,7 +17,7 @@
 
 using namespace llvm;
 using namespace llvm::ELF;
-using namespace llvm::elfabi;
+using namespace llvm::ifs;
 
 void compareByLine(StringRef LHS, StringRef RHS) {
   StringRef Line1;
Index: 

[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-08 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Do we still need the following tests:

- clang/test/CXX/temp/temp.spec/temp.explicit/p11.cpp
- clang/test/CXX/temp/temp.spec/temp.explicit/p12.cpp

?




Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:105
+template  void func10(A::B, int x) {}
+template  void func11(A::C, A::D, int) {}
+template  void func12() {}

aorlov wrote:
> krisb wrote:
> > Before this patch clang diagnosed cases like 
> > 
> > ```
> > class A { class C {}; };
> > template  void func(A::C) {}
> > ```
> > Why is it no longer the case?
> > 
> Your example generates an error `error: 'C' is a private member of 'A'` on 
> latest clang.
> This patch is intended to implement a proposal [[ 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0692r1.html | 
> p0692r1]] and consider this example as valid.
> Did I understand your question correctly?
It doesn't seem the aforementioned example falls under any of the cases from 
P0692R1 unless I misinterpreted its wordings.
It's a primary template, right?
Consider also the following example for which clang issues the error in both 
cases (before and after the patch):
```
class A { class C {}; };
template  A::C func();
```
I'm also wondering about something like:
```
class A { class C {}; };
template  T func() {}
template <> A::C func();
```



Comment at: clang/test/CXX/temp/temp.spec/part.spec.cpp:3
+
+// C++20 [temp.class.spec] 17.6.5/10:
+//   The usual access checking rules do not apply to non-dependent names used

It seems this test checks more than just partial specialization cases.
Could you please align the comments with what the test actually tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman updated this revision to Diff 336223.
Holman added a comment.

Get PGO info from Module instead of adding new field to debug info.


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

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -804,6 +804,9 @@
   // The low byte of the flags indicates the source language.
   Flags = MapDWLangToCVLang(CU->getSourceLanguage());
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);
+  }
 
   OS.AddComment("Flags and language");
   OS.emitInt32(Flags);
@@ -1428,6 +1431,10 @@
   if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
   !GV.hasOptSize() && !GV.hasOptNone())
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;
+FPO |= FrameProcedureOptions::ProfileGuidedOptimization;
+  }
   // FIXME: Set GuardCfg when it is implemented.
   CurFn->FrameProcOpts = FPO;
 


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -804,6 +804,9 @@
   // The low byte of the flags indicates the source language.
   Flags = MapDWLangToCVLang(CU->getSourceLanguage());
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);
+  }
 
   OS.AddComment("Flags and language");
   OS.emitInt32(Flags);
@@ -1428,6 +1431,10 @@
   if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
   !GV.hasOptSize() && !GV.hasOptNone())
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;
+FPO |= FrameProcedureOptions::ProfileGuidedOptimization;
+  }
   // FIXME: Set GuardCfg when it is implemented.
   CurFn->FrameProcOpts = FPO;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100087: Include `count` in AppleClang toolchains.

2021-04-08 Thread Dan Liew via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf66e05a720f7: Include `count` in AppleClang toolchains. 
(authored by delcypher).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100087

Files:
  clang/cmake/caches/Apple-stage2.cmake


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -65,6 +65,7 @@
   FileCheck
   yaml2obj
   not
+  count
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -65,6 +65,7 @@
   FileCheck
   yaml2obj
   not
+  count
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f66e05a - Include `count` in AppleClang toolchains.

2021-04-08 Thread Dan Liew via cfe-commits

Author: Dan Liew
Date: 2021-04-08T14:00:29-07:00
New Revision: f66e05a720f74409790bdede308380909f2ecd86

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

LOG: Include `count` in AppleClang toolchains.

The motivation here is so we can run the compiler-rt tests
from a standalone build against AppleClang.

In particular the `Posix/halt_on_error-torture.cpp` and
`Posix/halt_on_error_suppress_equal_pcs.cpp` ASan test cases currently
require this binary for the tests to pass.

rdar://76366784

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

Added: 


Modified: 
clang/cmake/caches/Apple-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Apple-stage2.cmake 
b/clang/cmake/caches/Apple-stage2.cmake
index 3a8bae087d32f..d347ffcd0f4ff 100644
--- a/clang/cmake/caches/Apple-stage2.cmake
+++ b/clang/cmake/caches/Apple-stage2.cmake
@@ -65,6 +65,7 @@ set(LLVM_TOOLCHAIN_UTILITIES
   FileCheck
   yaml2obj
   not
+  count
   CACHE STRING "")
 
 set(LLVM_DISTRIBUTION_COMPONENTS



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


[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 336212.
tra added a comment.

Updated Sema/pragma-attribute-strict-subjects.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100136

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Sema/pragma-attribute-strict-subjects.c


Index: clang/test/Sema/pragma-attribute-strict-subjects.c
===
--- clang/test/Sema/pragma-attribute-strict-subjects.c
+++ clang/test/Sema/pragma-attribute-strict-subjects.c
@@ -57,7 +57,7 @@
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(enum_constant, function, record(unless(is_union)), variable, 
variable(is_parameter)))
 // FIXME: comma in this diagnostic is wrong.
-// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant', and 'variable(is_parameter)'}}
+// expected-error@-2 {{attribute 'abi_tag' can't be applied to 
'enum_constant'}}
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(function, record(unless(is_union)), enum))
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -195,3 +195,12 @@
 #pragma clang attribute pop
 #pragma clang attribute push([[clang::uninitialized]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter // expected-error 
{{attribute 'uninitialized' can't be applied to 'variable(is_parameter)', and 
'variable(unless(is_parameter))'}}
 #pragma clang attribute pop
+// We're allowed to apply attributes to subsets of allowed subjects.
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable)
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_thread_local))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_global))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter
+#pragma clang attribute pop
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -875,12 +875,33 @@
 }
 Rules.clear();
   } else {
-for (const auto  : StrictSubjectMatchRuleSet) {
-  if (Rules.erase(Rule.first)) {
+// Each rule in Rules must be a strict subset of the attribute's
+// SubjectMatch rules.  I.e. we're allowed to use
+// `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
+// but should not allow `apply_to=variables` on an attribute which has
+// `SubjectList<[GlobalVar]>`.
+for (const auto  : StrictSubjectMatchRuleSet) {
+  // First, check for exact match.
+  if (Rules.erase(StrictRule.first)) {
 // Add the rule to the set of attribute receivers only if it's 
supported
 // in the current language mode.
-if (Rule.second)
-  SubjectMatchRules.push_back(Rule.first);
+if (StrictRule.second)
+  SubjectMatchRules.push_back(StrictRule.first);
+  }
+}
+// Check remaining rules for subset matches.
+auto RulesToCheck = Rules;
+for (const auto  : RulesToCheck) {
+  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
+  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
+if (llvm::any_of(StrictSubjectMatchRuleSet,
+ [ParentRule](const auto ) {
+   return StrictRule.first == *ParentRule &&
+  StrictRule.second; // IsEnabled
+ })) {
+  SubjectMatchRules.push_back(MatchRule);
+  Rules.erase(MatchRule);
+}
   }
 }
   }


Index: clang/test/Sema/pragma-attribute-strict-subjects.c
===
--- clang/test/Sema/pragma-attribute-strict-subjects.c
+++ clang/test/Sema/pragma-attribute-strict-subjects.c
@@ -57,7 +57,7 @@
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter)))
 // FIXME: comma in this diagnostic is wrong.
-// expected-error@-2 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'variable(is_parameter)'}}
+// expected-error@-2 {{attribute 'abi_tag' can't be applied to 'enum_constant'}}
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), enum))
Index: clang/test/Parser/pragma-attribute.cpp
===
--- 

[PATCH] D100136: Allow applying attributes to subset of allowed subjects.

2021-04-08 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added reviewers: rsmith, arphaman.
Herald added a subscriber: bixia.
tra requested review of this revision.
Herald added a project: clang.

The original intent of enforcing exact match between `apply_to` and the 
attribute's was to 
`ensure that the user will know what declarations receive the attribute. If the 
compiler changes the set of allowed attributes in the future`.
https://reviews.llvm.org/D30009?id=88764#inline-260744

However, the exact match, as implemented now, is too conservative. E.g. it does 
not allow using `apply_to=variables(is_global)` with an attribute which has 
`SubjectList<[Var]>`.
Applying an attribute to a subset of the allowed subjects should also be 
allowed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100136

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/pragma-attribute.cpp


Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -195,3 +195,12 @@
 #pragma clang attribute pop
 #pragma clang attribute push([[clang::uninitialized]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter // expected-error 
{{attribute 'uninitialized' can't be applied to 'variable(is_parameter)', and 
'variable(unless(is_parameter))'}}
 #pragma clang attribute pop
+// We're allowed to apply attributes to subsets of allowed subjects.
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable)
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_thread_local))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
variable(is_global))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = 
any(variable(is_parameter), variable(unless(is_parameter
+#pragma clang attribute pop
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -875,12 +875,33 @@
 }
 Rules.clear();
   } else {
-for (const auto  : StrictSubjectMatchRuleSet) {
-  if (Rules.erase(Rule.first)) {
+// Each rule in Rules must be a strict subset of the attribute's
+// SubjectMatch rules.  I.e. we're allowed to use
+// `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
+// but should not allow `apply_to=variables` on an attribute which has
+// `SubjectList<[GlobalVar]>`.
+for (const auto  : StrictSubjectMatchRuleSet) {
+  // First, check for exact match.
+  if (Rules.erase(StrictRule.first)) {
 // Add the rule to the set of attribute receivers only if it's 
supported
 // in the current language mode.
-if (Rule.second)
-  SubjectMatchRules.push_back(Rule.first);
+if (StrictRule.second)
+  SubjectMatchRules.push_back(StrictRule.first);
+  }
+}
+// Check remaining rules for subset matches.
+auto RulesToCheck = Rules;
+for (const auto  : RulesToCheck) {
+  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
+  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
+if (llvm::any_of(StrictSubjectMatchRuleSet,
+ [ParentRule](const auto ) {
+   return StrictRule.first == *ParentRule &&
+  StrictRule.second; // IsEnabled
+ })) {
+  SubjectMatchRules.push_back(MatchRule);
+  Rules.erase(MatchRule);
+}
   }
 }
   }


Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -195,3 +195,12 @@
 #pragma clang attribute pop
 #pragma clang attribute push([[clang::uninitialized]], apply_to = any(variable(is_parameter), variable(unless(is_parameter // expected-error {{attribute 'uninitialized' can't be applied to 'variable(is_parameter)', and 'variable(unless(is_parameter))'}}
 #pragma clang attribute pop
+// We're allowed to apply attributes to subsets of allowed subjects.
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable)
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable(is_thread_local))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = variable(is_global))
+#pragma clang attribute pop
+#pragma clang attribute push([[clang::no_destroy]], apply_to = any(variable(is_parameter), variable(unless(is_parameter
+#pragma clang attribute pop
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ 

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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman marked 2 inline comments as done.
haberman added inline comments.



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

aaron.ballman wrote:
> haberman wrote:
> > aaron.ballman wrote:
> > > haberman wrote:
> > > > aaron.ballman wrote:
> > > > > haberman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > rsmith wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > haberman wrote:
> > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > > > > This functionality belongs in 
> > > > > > > > > > > > > > > > > SemaStmtAttr.cpp, I think.
> > > > > > > > > > > > > > > > That is where I had originally put it, but that 
> > > > > > > > > > > > > > > > didn't work for templates. The semantic checks 
> > > > > > > > > > > > > > > > can only be performed at instantiation time. 
> > > > > > > > > > > > > > > > `ActOnAttributedStmt` seems to be the right 
> > > > > > > > > > > > > > > > hook point where I can evaluate the semantic 
> > > > > > > > > > > > > > > > checks for both template and non-template 
> > > > > > > > > > > > > > > > functions (with template functions getting 
> > > > > > > > > > > > > > > > checked at instantiation time).
> > > > > > > > > > > > > > > I disagree that `ActOnAttributedStmt()` is the 
> > > > > > > > > > > > > > > correct place for this checking -- template 
> > > > > > > > > > > > > > > checking should occur when the template is 
> > > > > > > > > > > > > > > instantiated, same as happens for declaration 
> > > > > > > > > > > > > > > attributes. I'd like to see this functionality 
> > > > > > > > > > > > > > > moved to SemaStmtAttr.cpp. Keeping the attribute 
> > > > > > > > > > > > > > > logic together and following the same patterns is 
> > > > > > > > > > > > > > > what allows us to tablegenerate more of the 
> > > > > > > > > > > > > > > attribute logic. Statement attributes are just 
> > > > > > > > > > > > > > > starting to get more such automation.
> > > > > > > > > > > > > > I tried commenting out this code and adding the 
> > > > > > > > > > > > > > following code into `handleMustTailAttr()` in 
> > > > > > > > > > > > > > `SemaStmtAttr.cpp`:
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > ```
> > > > > > > > > > > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > > > > > > > > > > return nullptr;
> > > > > > > > > > > > > > ```
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > This caused my test cases related to templates to 
> > > > > > > > > > > > > > fail. It also seemed to break test cases related to 
> > > > > > > > > > > > > > `JumpDiagnostics`. My interpretation of this is 
> > > > > > > > > > > > > > that `handleMustTailAttr()` is called during 
> > > > > > > > > > > > > > parsing only, and cannot catch errors at template 
> > > > > > > > > > > > > > instantiation time or that require a more complete 
> > > > > > > > > > > > > > AST.
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > What am I missing? Where in SemaStmtAttr.cpp are 
> > > > > > > > > > > > > > you suggesting that I put this check?
> > > > > > > > > > > > > Scratch the part about `JumpDiagnostics`, that was me 
> > > > > > > > > > > > > failing to call `S.setFunctionHasMustTail()`. I added 
> > > > > > > > > > > > > that and now the `JumpDiagnostics` tests pass.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > But the template test cases still fail, and I can't 
> > > > > > > > > > > > > find any hook point in `SemaStmtAttr.cpp` that will 
> > > > > > > > > > > > > let me evaluate these checks at template 
> > > > > > > > > > > > > instantiation time.
> > > > > > > > > > > > I think there's a bit of an architectural mixup, but 
> > > > > > > > > > > > I'm curious if @rsmith agrees before anyone starts 
> > > > > > > > > > > > doing work to make changes.
> > > > > > > > > > > > 
> > > > > > > > > > > > When transforming declarations, `RebuildWhatever()` 
> > > > > > > > > > > > calls the `ActOnWhatever()` function which calls 
> > > > > > > > > > > > `ProcessDeclAttributeList()` so that attributes are 
> > > > > > > > > > > > processed. `RebuildAttributedStmt()` similarly calls 
> > > > > > > > > > > > `ActOnAttributedStmt()`. However, 
> > > > > > > > > > > > `ActOnAttributedStmt()` doesn't call 
> > > > > > > > > > > > `ProcessStmtAttributes()` -- the logic is reversed so 
> > > > > > > > > > > > that `ProcessStmtAttributes()` is what calls 
> > > > > > > > > > > > `ActOnAttributedStmt()`.
> > > > > > > > > > > > 
> > > > > > > > > > > > I think 

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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336203.
haberman added a comment.

- Formatted files with clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/AttrImpl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-musttail.cpp
  clang/test/Sema/attr-musttail.c
  clang/test/Sema/attr-musttail.cpp
  clang/test/Sema/attr-musttail.m

Index: clang/test/Sema/attr-musttail.m
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
+
+void TestObjcBlock(void) {
+  void (^x)(void) = ^(void) {
+__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
+  };
+  __attribute__((musttail)) return x();
+}
+
+void ReturnsVoid(void);
+void TestObjcBlockVar(void) {
+  __block int i = 0;  // expected-note{{jump exits scope of __block variable}}
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{cannot perform a tail call from this return statement}}
+}
+
+//#import 
+
+__attribute__((objc_root_class))
+@interface TestObjcClass
+@end
+
+@implementation TestObjcClass
+
+- (void)testObjCMethod {
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
+}
+
+@end
Index: clang/test/Sema/attr-musttail.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.cpp
@@ -0,0 +1,191 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fms-extensions -fcxx-exceptions -fopenmp %s
+
+int ReturnsInt1();
+int Func1() {
+  [[clang::musttail]] ReturnsInt1();  // expected-error {{'musttail' attribute only applies to return statements}}
+  [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
+  [[clang::musttail]] return 5;   // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+  [[clang::musttail]] return ReturnsInt1();
+}
+
+void NoFunctionCall() {
+  [[clang::musttail]] return; // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+}
+
+[[clang::musttail]] static int int_val = ReturnsInt1(); // expected-error {{'musttail' attribute cannot be applied to a declaration}}
+
+void NoParams(); // expected-note {{target function has different number of parameters (expected 1 but has 0)}}
+void TestParamArityMismatch(int x) {
+  [[clang::musttail]] return NoParams(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
+void TestParamTypeMismatch(int x) {
+  [[clang::musttail]] return LongParam(x); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+long ReturnsLong(); // expected-note {{target function has different return type ('int' expected but has 'long')}}
+int TestReturnTypeMismatch() {
+  [[clang::musttail]] return ReturnsLong(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+struct Struct1 {
+  void MemberFunction(); // expected-note {{target function is a member of different class (expected 'void' but has 'Struct1')}}
+};
+void TestNonMemberToMember() {
+  Struct1 st;
+  [[clang::musttail]] return st.MemberFunction(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void ReturnsVoid(); // expected-note {{target function is a member of different class (expected 'Struct2' but has 'void')}}
+struct Struct2 {
+  void TestMemberToNonMember() {
+[[clang::musttail]] return ReturnsVoid(); // expected-error{{'musttail' attribute requires that caller and callee have compatible function signatures}}
+  }
+};
+
+class HasNonTrivialDestructor {
+public:
+  ~HasNonTrivialDestructor() {}
+  int ReturnsInt();
+};
+
+void ReturnsVoid2();
+void 

[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman added a comment.

In D4#2677566 , @rnk wrote:

> IMO it's best to avoid adding fields to DICompileUnit if at all possible. 
> It's the "god object" / "katamari damacy" of module debug info. Is there 
> something about the IR module that indicates if PGO data is present or not? 
> We could check that instead. I looked, but I wasn't able to find anything 
> quickly.

Got it. It looks like MMI->getModule()->getProfileSummary() should have the 
info I need. I'll update to use that instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D4

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


[PATCH] D75844: [clang] Set begin loc on GNU attribute parsed attrs

2021-04-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D75844#2677457 , @brooksmoses wrote:

> FWIW, this now causes Clang to produce an error on this code, when it didn't 
> before:
>
>   using namespace::foo __attribute__((deprecated("message")));
>
> I discussed this with Richard Smith, who points out that GCC does not accept 
> this and it's not permitted according to the C++ standard, so this should 
> probably be considered an accidental fix of a longstanding bug.   With that 
> said, would it be useful to add this as a tested case?

I think that would be a useful test case if only to document that we explicitly 
expect the situation to be a parsing error.


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

https://reviews.llvm.org/D75844

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


[PATCH] D100129: Tiny format fix

2021-04-08 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100129

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


[clang] 189310a - [AMDGPU] Allow -amdgpu-unsafe-fp-atomics to ignore denorm mode

2021-04-08 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2021-04-08T12:46:36-07:00
New Revision: 189310a140fa1c33f8f4838560f567bab9e99245

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

LOG: [AMDGPU] Allow -amdgpu-unsafe-fp-atomics to ignore denorm mode

Fixes: SWDEV-274276

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

Added: 


Modified: 
clang/docs/ClangCommandLineReference.rst
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index d895587c458a4..97812f2b6e29e 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -2997,6 +2997,10 @@ Enable threadgroup split execution mode (AMDGPU only)
 
 Specify XNACK mode (AMDGPU only)
 
+.. option:: -munsafe-fp-atomics, -mno-unsafe-fp-atomics
+
+Enable generation of unsafe floating point atomic instructions. May generate 
more efficient code, but may not respect rounding and denormal modes, and may 
give incorrect results for certain memory destinations. (AMDGPU only)
+
 ARM
 ---
 .. option:: -faapcs-bitfield-load

diff  --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index e8cfca1c726e1..596612e79036e 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -12055,9 +12055,14 @@ 
SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
 
 if ((AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS) &&
  Subtarget->hasAtomicFaddInsts()) {
-  if (!fpModeMatchesGlobalFPAtomicMode(RMW) ||
-  RMW->getFunction()->getFnAttribute("amdgpu-unsafe-fp-atomics")
-  .getValueAsString() != "true")
+  // The amdgpu-unsafe-fp-atomics attribute enables generation of unsafe
+  // floating point atomic instructions. May generate more efficient code,
+  // but may not respect rounding and denormal modes, and may give 
incorrect
+  // results for certain memory destinations.
+  if (!fpModeMatchesGlobalFPAtomicMode(RMW) &&
+  RMW->getFunction()
+  ->getFnAttribute("amdgpu-unsafe-fp-atomics")
+  .getValueAsString() != "true")
 return AtomicExpansionKind::CmpXChg;
 
   if (Subtarget->hasGFX90AInsts()) {

diff  --git a/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll 
b/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
index 3047d4a3eff38..d5348038f3c3d 100644
--- a/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
+++ b/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
@@ -490,25 +490,13 @@ define amdgpu_kernel void 
@global_atomic_fadd_f64_noret_pat_flush(double addrspa
 ; GFX90A-LABEL: global_atomic_fadd_f64_noret_pat_flush:
 ; GFX90A:   ; %bb.0: ; %main_body
 ; GFX90A-NEXT:s_load_dwordx2 s[0:1], s[0:1], 0x24
-; GFX90A-NEXT:s_mov_b64 s[2:3], 0
-; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
-; GFX90A-NEXT:s_load_dwordx2 s[4:5], s[0:1], 0x0
-; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
-; GFX90A-NEXT:v_pk_mov_b32 v[2:3], s[4:5], s[4:5] op_sel:[0,1]
-; GFX90A-NEXT:  BB27_1: ; %atomicrmw.start
-; GFX90A-NEXT:; =>This Inner Loop Header: Depth=1
-; GFX90A-NEXT:v_mov_b32_e32 v4, 0
-; GFX90A-NEXT:v_add_f64 v[0:1], v[2:3], 4.0
+; GFX90A-NEXT:v_mov_b32_e32 v0, 0
+; GFX90A-NEXT:v_mov_b32_e32 v2, 0
+; GFX90A-NEXT:v_mov_b32_e32 v1, 0x4010
 ; GFX90A-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0)
-; GFX90A-NEXT:global_atomic_cmpswap_x2 v[0:1], v4, v[0:3], s[0:1] glc
+; GFX90A-NEXT:global_atomic_add_f64 v2, v[0:1], s[0:1]
 ; GFX90A-NEXT:s_waitcnt vmcnt(0)
 ; GFX90A-NEXT:buffer_wbinvl1_vol
-; GFX90A-NEXT:v_cmp_eq_u64_e32 vcc, v[0:1], v[2:3]
-; GFX90A-NEXT:s_or_b64 s[2:3], vcc, s[2:3]
-; GFX90A-NEXT:v_pk_mov_b32 v[2:3], v[0:1], v[0:1] op_sel:[0,1]
-; GFX90A-NEXT:s_andn2_b64 exec, exec, s[2:3]
-; GFX90A-NEXT:s_cbranch_execnz BB27_1
-; GFX90A-NEXT:  ; %bb.2: ; %atomicrmw.end
 ; GFX90A-NEXT:s_endpgm
 main_body:
   %ret = atomicrmw fadd double addrspace(1)* %ptr, double 4.0 
syncscope("agent") seq_cst

diff  --git a/llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll 
b/llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
index ecc914123405d..143ef2d14c3d5 100644
--- a/llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
+++ b/llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
@@ -171,26 +171,12 @@ define amdgpu_kernel void 
@global_atomic_fadd_ret_f32_ieee(float addrspace(1)* %
 ; GFX90A-LABEL: global_atomic_fadd_ret_f32_ieee:
 ; GFX90A:   ; %bb.0:
 ; GFX90A-NEXT:s_load_dwordx2 s[0:1], s[0:1], 0x24
-; GFX90A-NEXT:s_mov_b64 s[2:3], 0
-; GFX90A-NEXT:s_waitcnt 

[PATCH] D99291: [AIX] Support init priority attribute

2021-04-08 Thread Xiangling Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Xiangling_L marked an inline comment as done.
Closed by commit rGd5085617986e: [AIX] Support init priority attribute 
(authored by Xiangling_L).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99291

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/aix-init-priority-attribute.cpp

Index: clang/test/CodeGen/aix-init-priority-attribute.cpp
===
--- clang/test/CodeGen/aix-init-priority-attribute.cpp
+++ clang/test/CodeGen/aix-init-priority-attribute.cpp
@@ -1,19 +1,72 @@
-// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s \
-// RUN: 2>&1 | \
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s | \
 // RUN:   FileCheck %s
-// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s \
-// RUN: 2>&1 | \
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s | \
 // RUN:   FileCheck %s
 
-class test {
-  int a;
-
-public:
-  test(int c) { a = c; }
-  ~test() { a = 0; }
+struct test {
+  test() {}
+  ~test() {}
 };
 
-__attribute__((init_priority(2000)))
-test t(1);
+__attribute__((init_priority(200)))
+test t1;
+__attribute__((init_priority(200)))
+test t2;
+__attribute__((init_priority(300)))
+test t3;
+__attribute__((init_priority(150)))
+test t4;
+test t5;
+
+// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__I_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__I_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__I_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }]
+// CHECK: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__a_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__a_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__a_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }]
+
+// CHECK: define internal void @_GLOBAL__I_000150() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__cxx_global_var_init.3()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__I_000200() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__cxx_global_var_init()
+// CHECK:   call void @__cxx_global_var_init.1()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__I_000300() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__cxx_global_var_init.2()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__sub_I__() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__cxx_global_var_init.4()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__a_000150() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__finalize_t4()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__a_000200() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__finalize_t2()
+// CHECK:   call void @__finalize_t1()
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define internal void @_GLOBAL__a_000300() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__finalize_t3()
+// CHECK:   ret void
+// CHECK: }
 
-// CHECK: fatal error: error in backend: 'init_priority' attribute is not yet supported on AIX
+// CHECK: define internal void @_GLOBAL__D_a() [[ATTR:#[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__finalize_t5()
+// CHECK:   ret void
+// CHECK: }
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7926,10 +7926,6 @@
 handleVecTypeHint(S, D, AL);
 break;
   case ParsedAttr::AT_InitPriority:
-if (S.Context.getTargetInfo().getTriple().isOSAIX())
-  llvm::report_fatal_error(
-  "'init_priority' attribute is not yet supported on AIX");
-else
   handleInitPriorityAttr(S, D, AL);
 break;
   case ParsedAttr::AT_Packed:
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4728,16 +4728,17 @@
 
   CGF.FinishFunction();
 
-  assert(!D.getAttr() &&
- "Prioritized sinit and sterm functions are not yet supported.");
-
-  if (isTemplateInstantiation(D.getTemplateSpecializationKind()) ||
-  getContext().GetGVALinkageForVariable() == GVA_DiscardableODR)
+  if (auto *IPA = 

[clang] d508561 - [AIX] Support init priority attribute

2021-04-08 Thread Xiangling Liao via cfe-commits

Author: Xiangling Liao
Date: 2021-04-08T15:40:09-04:00
New Revision: d5085617986e8ceabe7af02eb9c50f5350b3f980

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

LOG: [AIX] Support init priority attribute

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

Added: 


Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/aix-init-priority-attribute.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index c551901acc43..8131b5285075 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -499,7 +499,8 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl 
*D,
   } else if (PerformInit && ISA) {
 EmitPointerToInitFunc(D, Addr, Fn, ISA);
   } else if (auto *IPA = D->getAttr()) {
-OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size());
+OrderGlobalInitsOrStermFinalizers Key(IPA->getPriority(),
+  PrioritizedCXXGlobalInits.size());
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
   } else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
  getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR) {
@@ -566,6 +567,17 @@ static SmallString<128> 
getTransformedFileName(llvm::Module ) {
   return FileName;
 }
 
+static std::string getPrioritySuffix(unsigned int Priority) {
+  assert(Priority <= 65535 && "Priority should always be <= 65535.");
+
+  // Compute the function suffix from priority. Prepend with zeroes to make
+  // sure the function names are also ordered as priorities.
+  std::string PrioritySuffix = llvm::utostr(Priority);
+  PrioritySuffix = std::string(6 - PrioritySuffix.size(), '0') + 
PrioritySuffix;
+
+  return PrioritySuffix;
+}
+
 void
 CodeGenModule::EmitCXXGlobalInitFunc() {
   while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
@@ -577,12 +589,8 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
   llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
   const CGFunctionInfo  = getTypes().arrangeNullaryFunction();
 
-  const bool UseSinitAndSterm = getCXXABI().useSinitAndSterm();
   // Create our global prioritized initialization function.
   if (!PrioritizedCXXGlobalInits.empty()) {
-assert(!UseSinitAndSterm && "Prioritized sinit and sterm functions are not"
-" supported yet.");
-
 SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
@@ -596,14 +604,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
 PrioE = std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp());
 
   LocalCXXGlobalInits.clear();
-  unsigned Priority = I->first.priority;
-  // Compute the function suffix from priority. Prepend with zeroes to make
-  // sure the function names are also ordered as priorities.
-  std::string PrioritySuffix = llvm::utostr(Priority);
-  // Priority is always <= 65535 (enforced by sema).
-  PrioritySuffix = std::string(6-PrioritySuffix.size(), 
'0')+PrioritySuffix;
+
+  unsigned int Priority = I->first.priority;
   llvm::Function *Fn = CreateGlobalInitOrCleanUpFunction(
-  FTy, "_GLOBAL__I_" + PrioritySuffix, FI);
+  FTy, "_GLOBAL__I_" + getPrioritySuffix(Priority), FI);
 
   for (; I < PrioE; ++I)
 LocalCXXGlobalInits.push_back(I->second);
@@ -614,7 +618,7 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
 PrioritizedCXXGlobalInits.clear();
   }
 
-  if (UseSinitAndSterm && CXXGlobalInits.empty())
+  if (getCXXABI().useSinitAndSterm() && CXXGlobalInits.empty())
 return;
 
   // Include the filename in the symbol name. Including "sub_" matches gcc
@@ -649,12 +653,50 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
 }
 
 void CodeGenModule::EmitCXXGlobalCleanUpFunc() {
-  if (CXXGlobalDtorsOrStermFinalizers.empty())
+  if (CXXGlobalDtorsOrStermFinalizers.empty() &&
+  PrioritizedCXXStermFinalizers.empty())
 return;
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
   const CGFunctionInfo  = getTypes().arrangeNullaryFunction();
 
+  // Create our global prioritized cleanup function.
+  if (!PrioritizedCXXStermFinalizers.empty()) {
+SmallVector LocalCXXStermFinalizers;
+llvm::array_pod_sort(PrioritizedCXXStermFinalizers.begin(),
+ PrioritizedCXXStermFinalizers.end());
+// Iterate over "chunks" of dtors with same priority and emit each chunk
+// into separate function. Note - everything is sorted first by priority,
+

[PATCH] D100127: [RISCV][Clang] Add some RVV Permutation intrinsic functions.

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D100127/new/

https://reviews.llvm.org/D100127

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


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

IMO it's best to avoid adding fields to DICompileUnit if at all possible. It's 
the "god object" / "katamari damacy" of module debug info. Is there something 
about the IR module that indicates if PGO data is present or not? We could 
check that instead. I looked, but I wasn't able to find anything quickly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D4

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


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

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

The windows build failure is solved by itself and its all passing now!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99984: [RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02ef9963e1ad: [RISCV] Prevent __builtin_riscv_orc_b_64 from 
being compiled RV32 target. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99984

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -0,0 +1,6 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv32 -target-feature +experimental-zbb -verify 
%s -o -
+
+int orc_b_64(int a) {
+  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires 
'RV64' extension support to be enabled}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3422,12 +3422,18 @@
   Features.split(ReqFeatures, ',');
 
   // Check if each required feature is included
-  for (auto  : ReqFeatures) {
-if (TI.hasFeature(I))
+  for (StringRef F : ReqFeatures) {
+if (TI.hasFeature(F))
   continue;
+
+// If the feature is 64bit, alter the string so it will print better in
+// the diagnostic.
+if (F == "64bit")
+  F = "RV64";
+
 // Convert features like "zbr" and "experimental-zbr" to "Zbr".
-I.consume_front("experimental-");
-std::string FeatureStr = I.str();
+F.consume_front("experimental-");
+std::string FeatureStr = F.str();
 FeatureStr[0] = std::toupper(FeatureStr[0]);
 
 // Error message
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -99,6 +99,11 @@
 
   std::string convertConstraint(const char *) const override;
 
+  bool
+  initFeatureMap(llvm::StringMap , DiagnosticsEngine ,
+ StringRef CPU,
+ const std::vector ) const override;
+
   bool hasFeature(StringRef Feature) const override;
 
   bool handleTargetFeatures(std::vector ,
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -239,6 +239,16 @@
  Builtin::FirstTSBuiltin);
 }
 
+bool RISCVTargetInfo::initFeatureMap(
+llvm::StringMap , DiagnosticsEngine , StringRef CPU,
+const std::vector ) const {
+
+  if (getTriple().getArch() == llvm::Triple::riscv64)
+Features["64bit"] = true;
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
+}
+
 /// Return true if has this feature, need to sync with handleTargetFeatures.
 bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
   bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;
@@ -246,6 +256,7 @@
   .Case("riscv", true)
   .Case("riscv32", !Is64Bit)
   .Case("riscv64", Is64Bit)
+  .Case("64bit", Is64Bit)
   .Case("m", HasM)
   .Case("a", HasA)
   .Case("f", HasF)
Index: clang/include/clang/Basic/BuiltinsRISCV.def
===
--- clang/include/clang/Basic/BuiltinsRISCV.def
+++ clang/include/clang/Basic/BuiltinsRISCV.def
@@ -19,7 +19,7 @@
 
 // Zbb extension
 TARGET_BUILTIN(__builtin_riscv_orc_b_32, "ZiZi", "nc", "experimental-zbb")
-TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", "experimental-zbb")
+TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", 
"experimental-zbb,64bit")
 
 // Zbc extension
 TARGET_BUILTIN(__builtin_riscv_clmul, "LiLiLi", "nc", "experimental-zbc")


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -0,0 +1,6 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv32 -target-feature +experimental-zbb -verify %s -o -
+
+int orc_b_64(int a) {
+  return __builtin_riscv_orc_b_64(a); // expected-error {{builtin requires 'RV64' extension support to be enabled}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3422,12 +3422,18 @@
   Features.split(ReqFeatures, ',');
 
   // Check if each required feature is included
-  for (auto  : ReqFeatures) {
-if (TI.hasFeature(I))
+  for (StringRef 

[clang] 02ef996 - [RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.

2021-04-08 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2021-04-08T11:34:56-07:00
New Revision: 02ef9963e1ad1e6ded539c830861a074b879dc70

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

LOG: [RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.

The backend can't handle this and will throw a fatal error from
type legalization. It's easy enough to fix that for this intrinsic
by just splitting the IR intrinsic since it works on individual bytes.

There will be other intrinsics in the future that would be harder
to support through splitting, for example grev, gorc, and shfl. Those
would require a compare and a select be inserted to check the MSB of
their control input.

This patch adds support for preventing this in the frontend with
a nice diagnostic.

Reviewed By: frasercrmck

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

Added: 
clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c

Modified: 
clang/include/clang/Basic/BuiltinsRISCV.def
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsRISCV.def 
b/clang/include/clang/Basic/BuiltinsRISCV.def
index e0b28011e61ad..8105263ca3ca6 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.def
+++ b/clang/include/clang/Basic/BuiltinsRISCV.def
@@ -19,7 +19,7 @@
 
 // Zbb extension
 TARGET_BUILTIN(__builtin_riscv_orc_b_32, "ZiZi", "nc", "experimental-zbb")
-TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", "experimental-zbb")
+TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", 
"experimental-zbb,64bit")
 
 // Zbc extension
 TARGET_BUILTIN(__builtin_riscv_clmul, "LiLiLi", "nc", "experimental-zbc")

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 4ca41414a9d62..1f31f471db3a4 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -239,6 +239,16 @@ ArrayRef 
RISCVTargetInfo::getTargetBuiltins() const {
  Builtin::FirstTSBuiltin);
 }
 
+bool RISCVTargetInfo::initFeatureMap(
+llvm::StringMap , DiagnosticsEngine , StringRef CPU,
+const std::vector ) const {
+
+  if (getTriple().getArch() == llvm::Triple::riscv64)
+Features["64bit"] = true;
+
+  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
+}
+
 /// Return true if has this feature, need to sync with handleTargetFeatures.
 bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
   bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;
@@ -246,6 +256,7 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
   .Case("riscv", true)
   .Case("riscv32", !Is64Bit)
   .Case("riscv64", Is64Bit)
+  .Case("64bit", Is64Bit)
   .Case("m", HasM)
   .Case("a", HasA)
   .Case("f", HasF)

diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 4fc8cd1e22dfb..4e650d3b2dc16 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -99,6 +99,11 @@ class RISCVTargetInfo : public TargetInfo {
 
   std::string convertConstraint(const char *) const override;
 
+  bool
+  initFeatureMap(llvm::StringMap , DiagnosticsEngine ,
+ StringRef CPU,
+ const std::vector ) const override;
+
   bool hasFeature(StringRef Feature) const override;
 
   bool handleTargetFeatures(std::vector ,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1d39de7ade8b1..be015f02027f5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3422,12 +3422,18 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo ,
   Features.split(ReqFeatures, ',');
 
   // Check if each required feature is included
-  for (auto  : ReqFeatures) {
-if (TI.hasFeature(I))
+  for (StringRef F : ReqFeatures) {
+if (TI.hasFeature(F))
   continue;
+
+// If the feature is 64bit, alter the string so it will print better in
+// the diagnostic.
+if (F == "64bit")
+  F = "RV64";
+
 // Convert features like "zbr" and "experimental-zbr" to "Zbr".
-I.consume_front("experimental-");
-std::string FeatureStr = I.str();
+F.consume_front("experimental-");
+std::string FeatureStr = F.str();
 FeatureStr[0] = std::toupper(FeatureStr[0]);
 
 // Error message

diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
new file mode 100644
index 0..ad864aa65feff
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb-error.c
@@ -0,0 +1,6 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: 

[PATCH] D75844: [clang] Set begin loc on GNU attribute parsed attrs

2021-04-08 Thread Brooks Moses via Phabricator via cfe-commits
brooksmoses added a comment.

FWIW, this now causes Clang to produce an error on this code, when it didn't 
before:

  using namespace::foo __attribute__((deprecated("message")));

I discussed this with Richard Smith, who points out that GCC does not accept 
this and it's not permitted according to the C++ standard, so this should 
probably be considered an accidental fix of a longstanding bug.   With that 
said, would it be useful to add this as a tested case?


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

https://reviews.llvm.org/D75844

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


[PATCH] D100057: Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class.

2021-04-08 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

FWIW, I think this is acceptable, but I think even better would be to make it 
clear in the Standard that this is acceptable. Having spoken with a few folks 
about this, it doesn't appear to be specified very clearly.


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

https://reviews.llvm.org/D100057

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


[PATCH] D99861: [Clang] Record tokens in attribute arguments for user-defined C++/C2x attributes

2021-04-08 Thread Josh Junon via Phabricator via cfe-commits
Qix- updated this revision to Diff 336173.
Qix- added a comment.

Updated the diff to include a lot more context (-U). Thanks again for the 
tip :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99861

Files:
  clang/examples/CMakeLists.txt
  clang/examples/PrintAttributeTokens/CMakeLists.txt
  clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp
  clang/examples/PrintAttributeTokens/PrintAttributeTokens.exports
  clang/examples/PrintAttributeTokens/README.txt
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/test/Frontend/plugin-print-attr-tokens.cpp

Index: clang/test/Frontend/plugin-print-attr-tokens.cpp
===
--- /dev/null
+++ clang/test/Frontend/plugin-print-attr-tokens.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -cc1 -load %llvmshlibdir/PrintAttributeTokens%pluginext -fsyntax-only -ast-dump -verify %s
+// REQUIRES: plugins, examples
+
+// expected-no-diagnostics
+[[print_tokens(
+the, mitochondria,
+, Of::The($cell))]] void
+fn1a() {}
+[[plugin::print_tokens("a string")]] void fn1b() {}
+[[plugin::print_tokens()]] void fn1c() {}
+[[plugin::print_tokens(some_ident)]] void fn1d() {}
+[[plugin::print_tokens(int)]] void fn1e() {}
Index: clang/lib/Sema/ParsedAttr.cpp
===
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -45,10 +45,11 @@
   else if (HasParsedType)
 return totalSizeToAlloc(0, 0, 0, 1, 0);
+detail::PropertyData, Token>(0, 0, 0, 1, 0, 0);
   return totalSizeToAlloc(NumArgs, 0, 0, 0, 0);
+  detail::PropertyData, Token>(NumArgs, 0, 0, 0, 0,
+   NumTokens);
 }
 
 AttributeFactory::AttributeFactory() {
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4096,13 +4096,39 @@
   LO.CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x;
 
   // If the attribute isn't known, we will not attempt to parse any
-  // arguments.
+  // arguments. Instead, we just record the tokens and add the attribute
+  // directly. The recording happens here because this is the only place
+  // where user-defined (via plugins) attributes are parsed, and thus
+  // they care about the token stream directly.
   if (!hasAttribute(LO.CPlusPlus ? AttrSyntax::CXX : AttrSyntax::C, ScopeName,
 AttrName, getTargetInfo(), getLangOpts())) {
-// Eat the left paren, then skip to the ending right paren.
+// Begin recording session.
+SmallVector RecordedTokens;
+assert(!PP.hasTokenRecorder());
+PP.setTokenRecorder(
+[](const Token ) { RecordedTokens.push_back(Tok); });
+
+// Eat the left paren.
 ConsumeParen();
+
+// skip to the ending right paren.
 SkipUntil(tok::r_paren);
-return false;
+
+// End recording session.
+PP.setTokenRecorder(nullptr);
+
+// Add new attribute with the token list.
+// We assert that we have at least one token,
+// since we have to ignore the final r_paren.
+assert(RecordedTokens.size() > 0);
+Attrs.addNew(
+AttrName,
+SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrNameLoc, AttrNameLoc),
+ScopeName, ScopeLoc, nullptr, 0,
+getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x,
+RecordedTokens.data(), RecordedTokens.size() - 2);
+
+return true;
   }
 
   if (ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__"))) {
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2828,7 +2828,7 @@
   ArgsVector ArgExprs;
   ArgExprs.push_back(ArgExpr.get());
   Attrs.addNew(KWName, KWLoc, nullptr, KWLoc, ArgExprs.data(), 1,
-   ParsedAttr::AS_Keyword, EllipsisLoc);
+   ParsedAttr::AS_Keyword, nullptr, 0, EllipsisLoc);
 }
 
 ExprResult Parser::ParseExtIntegerArgument() {
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -970,6 +970,9 @@
 if (OnToken)
   OnToken(Result);
   }
+
+  if (OnRecordedToken)
+OnRecordedToken(Result);
 }
 
 /// Lex a header-name token (including one formed from header-name-tokens if
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -18,6 +18,7 @@
 

[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-08 Thread Josh Junon via Phabricator via cfe-commits
Qix- updated this revision to Diff 336172.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99877

Files:
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/SemaStmtAttr.cpp


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == 
ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to 
this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }
 
   static const ParsedAttrInfo (const AttributeCommonInfo );
 };


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }
 
   static const ParsedAttrInfo (const AttributeCommonInfo );
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-08 Thread Alex Orlov via Phabricator via cfe-commits
aorlov added a comment.

@krisb Thank you for your comments. I will consider them.




Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:105
+template  void func10(A::B, int x) {}
+template  void func11(A::C, A::D, int) {}
+template  void func12() {}

krisb wrote:
> Before this patch clang diagnosed cases like 
> 
> ```
> class A { class C {}; };
> template  void func(A::C) {}
> ```
> Why is it no longer the case?
> 
Your example generates an error `error: 'C' is a private member of 'A'` on 
latest clang.
This patch is intended to implement a proposal [[ 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0692r1.html | 
p0692r1]] and consider this example as valid.
Did I understand your question correctly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D90157: [analyzer] Rework SValBuilder::evalCast function into maintainable and clear way

2021-04-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I'm catching up and these changes look great.

In D90157#2433657 , @steakhal wrote:

> I've run the baseline and your patch as well on 15 projects, both with and 
> without Z3 refutation enabled.
> (...)
> All in all, I'm still in favor of this change, but I'm really curious why did 
> we observe such changes. Debugging the cause seems really tricky to me.

If testing on a large codebase uncovered changes in behavior that weren't 
caught by our LIT test suite it often make sense to update our LIT test suite 
to include those tests in order to avoid similar regressions in the future. 
Regressions like this are easy to auto-reduce with tools like `creduce` because 
there's no functional change intended in the patch so there's a 100% formal 
reduction criterion "any change in diagnostics is observed" which can be easily 
fed to `creduce`. Even though NFC commits don't require tests, this doesn't 
mean they shouldn't add them!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90157

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


[PATCH] D99675: RFC [llvm][clang] Create new intrinsic llvm.arith.fence to control FP optimization at expression level

2021-04-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

In D99675#2672138 , @kbsmith1 wrote:

> In D99675#2671924 , @efriedma wrote:
>
>> How is llvm.arith.fence() different from using "freeze" on a floating-point 
>> value?  The goal isn't really the same, sure, but the effects seem similar 
>> at first glance.
>
> They are similar.  However, freeze is a no-op if the operand can be proven 
> not to be undef or poison, and in such circumstances could be removed by an 
> optimizer.  llvm.arith.fence cannot be removed by an optimizer, because doing 
> so might allow instructions that were "outside" the fence from being 
> reassociated/distrbuted with the instructions/operands that were inside the 
> fence.

Okay.  In practice, it's basically impossible for us to prove that the result 
of "fast" arithmetic isn't poison, given the way ninf/nnan are defined, but 
depending on that would be fragile.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99675

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-04-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> Which is fairly shocking and mind blowing that we've organically developed 
> two independent implementations of casting, one for RegionStore and one for 
> everything else.

Wait, no, nvm, please disregard this. It wasn't like this forever, i just 
happened to catch code in an intermediate state after D90157 
. Either way, it's definitely getting much 
better, and either way, i'm curious if `dispatchCast` can now be eliminated.


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

https://reviews.llvm.org/D96090

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


[PATCH] D99683: [HIP] Support ThinLTO

2021-04-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Any other concerns? Thanks.


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

https://reviews.llvm.org/D99683

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


[PATCH] D100129: Tiny format fix

2021-04-08 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan created this revision.
urnathan added reviewers: rsmith, bruno.
urnathan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A mis-indented } in the middle of a function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100129

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -132,7 +132,7 @@
   << FixItHint::CreateRemoval(InlineLoc);
 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, 
DeclEnd);
 return Actions.ConvertDeclToDeclGroup(NSAlias);
-}
+  }
 
   BalancedDelimiterTracker T(*this, tok::l_brace);
   if (T.consumeOpen()) {


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -132,7 +132,7 @@
   << FixItHint::CreateRemoval(InlineLoc);
 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
 return Actions.ConvertDeclToDeclGroup(NSAlias);
-}
+  }
 
   BalancedDelimiterTracker T(*this, tok::l_brace);
   if (T.consumeOpen()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-04-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Please add a test for `(char*)0-(char*)0`.


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

https://reviews.llvm.org/D98798

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


[PATCH] D100124: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-04-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:460-468
+TARGET_BUILTIN(__nvvm_redux_sync_add_s32, "SiSii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_min_s32, "SiSii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_max_s32, "SiSii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_add_u32, "UiUii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_min_u32, "UiUii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_max_u32, "UiUii", "", SM_80)
+TARGET_BUILTIN(__nvvm_redux_sync_and_b32, "iii", "", SM_80)

Instead of creating one builtin per integer variant, can we use a more generic 
builtin `__nvvm_redux_sync_add_i`, similar to how we handle 
`__nvvm_atom_add_gen_i` ?




Comment at: llvm/include/llvm/IR/IntrinsicsNVVM.td:4103
+// redux.sync.add.u32 dst, src, membermask;
+def int_nvvm_redux_sync_add_u32 : GCCBuiltin<"__nvvm_redux_sync_add_u32">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],

This could also be consolidated into an overloaded intrinsic operating on 
`llvm_anyint_ty`



Comment at: llvm/include/llvm/IR/IntrinsicsNVVM.td:4105
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrNoMem]>;
+

Similar to `shfl`, these intrinsics probably need `IntrInaccessibleMemOnly` as 
they exchange data with other threads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100124

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


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

2021-04-08 Thread Valeriy Savchenko 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 rG663ac91ed1d6: [analyzer] Fix false positives in inner 
pointer checker (PR49628) (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260

Files:
  clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  clang/test/Analysis/inner-pointer.cpp

Index: clang/test/Analysis/inner-pointer.cpp
===
--- clang/test/Analysis/inner-pointer.cpp
+++ clang/test/Analysis/inner-pointer.cpp
@@ -17,6 +17,11 @@
 string my_string = "default";
 void default_arg(int a = 42, string  = my_string);
 
+template 
+T *addressof(T );
+
+char *data(std::string );
+
 } // end namespace std
 
 void consume(const char *) {}
@@ -273,6 +278,15 @@
   // expected-note@-1 {{Inner pointer of container used after re/deallocation}}
 }
 
+void deref_after_std_data() {
+  const char *c;
+  std::string s;
+  c = std::data(s); // expected-note {{Pointer to inner buffer of 'std::string' obtained here}}
+  s.push_back('c'); // expected-note {{Inner buffer of 'std::string' reallocated by call to 'push_back'}}
+  consume(c);   // expected-warning {{Inner pointer of container used after re/deallocation}}
+  // expected-note@-1 {{Inner pointer of container used after re/deallocation}}
+}
+
 struct S {
   std::string s;
   const char *name() {
@@ -361,8 +375,24 @@
   // expected-note@-1 {{Inner pointer of container used after re/deallocation}}
 }
 
+void func_addressof() {
+  const char *c;
+  std::string s;
+  c = s.c_str();
+  addressof(s);
+  consume(c); // no-warning
+}
+
+void func_std_data() {
+  const char *c;
+  std::string s;
+  c = std::data(s);
+  consume(c); // no-warning
+}
+
 struct T {
   std::string to_string() { return s; }
+
 private:
   std::string s;
 };
Index: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -34,9 +34,9 @@
 class InnerPointerChecker
 : public Checker {
 
-  CallDescription AppendFn, AssignFn, ClearFn, CStrFn, DataFn, EraseFn,
-  InsertFn, PopBackFn, PushBackFn, ReplaceFn, ReserveFn, ResizeFn,
-  ShrinkToFitFn, SwapFn;
+  CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
+  DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
+  ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
 
 public:
   class InnerPointerBRVisitor : public BugReporterVisitor {
@@ -73,9 +73,10 @@
   InnerPointerChecker()
   : AppendFn({"std", "basic_string", "append"}),
 AssignFn({"std", "basic_string", "assign"}),
+AddressofFn({"std", "addressof"}),
 ClearFn({"std", "basic_string", "clear"}),
-CStrFn({"std", "basic_string", "c_str"}),
-DataFn({"std", "basic_string", "data"}),
+CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
+DataMemberFn({"std", "basic_string", "data"}),
 EraseFn({"std", "basic_string", "erase"}),
 InsertFn({"std", "basic_string", "insert"}),
 PopBackFn({"std", "basic_string", "pop_back"}),
@@ -90,6 +91,9 @@
   /// pointers referring to the container object's inner buffer.
   bool isInvalidatingMemberFunction(const CallEvent ) const;
 
+  /// Check whether the called function returns a raw inner pointer.
+  bool isInnerPointerAccessFunction(const CallEvent ) const;
+
   /// Mark pointer symbols associated with the given memory region released
   /// in the program state.
   void markPtrSymbolsReleased(const CallEvent , ProgramStateRef State,
@@ -130,6 +134,12 @@
   Call.isCalled(SwapFn));
 }
 
+bool InnerPointerChecker::isInnerPointerAccessFunction(
+const CallEvent ) const {
+  return (Call.isCalled(CStrFn) || Call.isCalled(DataFn) ||
+  Call.isCalled(DataMemberFn));
+}
+
 void InnerPointerChecker::markPtrSymbolsReleased(const CallEvent ,
  ProgramStateRef State,
  const MemRegion *MR,
@@ -172,6 +182,11 @@
   if (!ArgRegion)
 continue;
 
+  // std::addressof function accepts a non-const reference as an argument,
+  // but doesn't modify it.
+  if (Call.isCalled(AddressofFn))
+continue;
+
   markPtrSymbolsReleased(Call, State, ArgRegion, C);
 }
   }
@@ -195,36 +210,49 @@
 CheckerContext ) const {
   ProgramStateRef State = C.getState();
 
+  // TODO: Do we need these to be typed?
+  const TypedValueRegion *ObjRegion = nullptr;
+
   if (const auto *ICall = dyn_cast()) {
-// TODO: Do we need these to be typed?
-const auto *ObjRegion = dyn_cast_or_null(
+

[clang] 663ac91 - [analyzer] Fix false positives in inner pointer checker (PR49628)

2021-04-08 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-08T20:30:12+03:00
New Revision: 663ac91ed1d6156e848e5f5f00cd7e7dd6cf867f

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

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

This patch supports std::data and std::addressof functions.

rdar://73463300

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
clang/test/Analysis/inner-pointer.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
index 65e52e139ee4..bcae73378028 100644
--- a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -34,9 +34,9 @@ namespace {
 class InnerPointerChecker
 : public Checker {
 
-  CallDescription AppendFn, AssignFn, ClearFn, CStrFn, DataFn, EraseFn,
-  InsertFn, PopBackFn, PushBackFn, ReplaceFn, ReserveFn, ResizeFn,
-  ShrinkToFitFn, SwapFn;
+  CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
+  DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
+  ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
 
 public:
   class InnerPointerBRVisitor : public BugReporterVisitor {
@@ -73,9 +73,10 @@ class InnerPointerChecker
   InnerPointerChecker()
   : AppendFn({"std", "basic_string", "append"}),
 AssignFn({"std", "basic_string", "assign"}),
+AddressofFn({"std", "addressof"}),
 ClearFn({"std", "basic_string", "clear"}),
-CStrFn({"std", "basic_string", "c_str"}),
-DataFn({"std", "basic_string", "data"}),
+CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
+DataMemberFn({"std", "basic_string", "data"}),
 EraseFn({"std", "basic_string", "erase"}),
 InsertFn({"std", "basic_string", "insert"}),
 PopBackFn({"std", "basic_string", "pop_back"}),
@@ -90,6 +91,9 @@ class InnerPointerChecker
   /// pointers referring to the container object's inner buffer.
   bool isInvalidatingMemberFunction(const CallEvent ) const;
 
+  /// Check whether the called function returns a raw inner pointer.
+  bool isInnerPointerAccessFunction(const CallEvent ) const;
+
   /// Mark pointer symbols associated with the given memory region released
   /// in the program state.
   void markPtrSymbolsReleased(const CallEvent , ProgramStateRef State,
@@ -130,6 +134,12 @@ bool InnerPointerChecker::isInvalidatingMemberFunction(
   Call.isCalled(SwapFn));
 }
 
+bool InnerPointerChecker::isInnerPointerAccessFunction(
+const CallEvent ) const {
+  return (Call.isCalled(CStrFn) || Call.isCalled(DataFn) ||
+  Call.isCalled(DataMemberFn));
+}
+
 void InnerPointerChecker::markPtrSymbolsReleased(const CallEvent ,
  ProgramStateRef State,
  const MemRegion *MR,
@@ -172,6 +182,11 @@ void InnerPointerChecker::checkFunctionArguments(const 
CallEvent ,
   if (!ArgRegion)
 continue;
 
+  // std::addressof function accepts a non-const reference as an argument,
+  // but doesn't modify it.
+  if (Call.isCalled(AddressofFn))
+continue;
+
   markPtrSymbolsReleased(Call, State, ArgRegion, C);
 }
   }
@@ -195,36 +210,49 @@ void InnerPointerChecker::checkPostCall(const CallEvent 
,
 CheckerContext ) const {
   ProgramStateRef State = C.getState();
 
+  // TODO: Do we need these to be typed?
+  const TypedValueRegion *ObjRegion = nullptr;
+
   if (const auto *ICall = dyn_cast()) {
-// TODO: Do we need these to be typed?
-const auto *ObjRegion = dyn_cast_or_null(
+ObjRegion = dyn_cast_or_null(
 ICall->getCXXThisVal().getAsRegion());
-if (!ObjRegion)
-  return;
 
-if (Call.isCalled(CStrFn) || Call.isCalled(DataFn)) {
-  SVal RawPtr = Call.getReturnValue();
-  if (SymbolRef Sym = RawPtr.getAsSymbol(/*IncludeBaseRegions=*/true)) {
-// Start tracking this raw pointer by adding it to the set of symbols
-// associated with this container object in the program state map.
+// Check [string.require] / second point.
+if (isInvalidatingMemberFunction(Call)) {
+  markPtrSymbolsReleased(Call, State, ObjRegion, C);
+  return;
+}
+  }
 
-PtrSet::Factory  = State->getStateManager().get_context();
-const PtrSet *SetPtr = State->get(ObjRegion);
-PtrSet Set = SetPtr ? *SetPtr : F.getEmptySet();
-assert(C.wasInlined || !Set.contains(Sym));
-Set = F.add(Set, Sym);
+  if (isInnerPointerAccessFunction(Call)) {
 
-   

[PATCH] D99181: [analyzer] Fix crash on spaceship operator (PR47511)

2021-04-08 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b958dd6bcca: [analyzer] Fix crash on spaceship operator 
(PR47511) (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99181

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/PR47511.cpp


Index: clang/test/Analysis/PR47511.cpp
===
--- /dev/null
+++ clang/test/Analysis/PR47511.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -w -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+void test() {
+  // no crash
+  (void)(0 <=> 0);
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -423,6 +423,14 @@
 return UnknownVal();
   }
 
+  if (op == BinaryOperatorKind::BO_Cmp) {
+// We can't reason about C++20 spaceship operator yet.
+//
+// FIXME: Support C++20 spaceship operator.
+//The main problem here is that the result is not integer.
+return UnknownVal();
+  }
+
   if (Optional LV = lhs.getAs()) {
 if (Optional RV = rhs.getAs())
   return evalBinOpLL(state, op, *LV, *RV, type);


Index: clang/test/Analysis/PR47511.cpp
===
--- /dev/null
+++ clang/test/Analysis/PR47511.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -w -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+void test() {
+  // no crash
+  (void)(0 <=> 0);
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -423,6 +423,14 @@
 return UnknownVal();
   }
 
+  if (op == BinaryOperatorKind::BO_Cmp) {
+// We can't reason about C++20 spaceship operator yet.
+//
+// FIXME: Support C++20 spaceship operator.
+//The main problem here is that the result is not integer.
+return UnknownVal();
+  }
+
   if (Optional LV = lhs.getAs()) {
 if (Optional RV = rhs.getAs())
   return evalBinOpLL(state, op, *LV, *RV, type);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b958dd - [analyzer] Fix crash on spaceship operator (PR47511)

2021-04-08 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-08T20:28:05+03:00
New Revision: 4b958dd6bccab386be432cac99332b867ab9ee22

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

LOG: [analyzer] Fix crash on spaceship operator (PR47511)

rdar://68954187

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

Added: 
clang/test/Analysis/PR47511.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index a47a28e1e866..9942b7e1423c 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -423,6 +423,14 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, 
BinaryOperator::Opcode op,
 return UnknownVal();
   }
 
+  if (op == BinaryOperatorKind::BO_Cmp) {
+// We can't reason about C++20 spaceship operator yet.
+//
+// FIXME: Support C++20 spaceship operator.
+//The main problem here is that the result is not integer.
+return UnknownVal();
+  }
+
   if (Optional LV = lhs.getAs()) {
 if (Optional RV = rhs.getAs())
   return evalBinOpLL(state, op, *LV, *RV, type);

diff  --git a/clang/test/Analysis/PR47511.cpp b/clang/test/Analysis/PR47511.cpp
new file mode 100644
index ..d42799f4fbde
--- /dev/null
+++ b/clang/test/Analysis/PR47511.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -w -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+void test() {
+  // no crash
+  (void)(0 <=> 0);
+}



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


[PATCH] D99995: [OpenMP51] Initial support for masked directive and filter clause

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D5

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


[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the patch! Btw, can you add more context to the patch when you 
generate it (I usually use `-U 999` when making patches)?

The changes look good so far, but I think `docs\ClangPlugins.rst` should be 
updated to document the new functionality and it would be nice to add example 
usage (in lieu of tests) to `examples\Attribute`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99877

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


[PATCH] D100085: [X86] Support -march=rocketlake

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:767
+  // Rocketlake
+  list RKLAdditionalFeatures = [FeatureAES,
+  FeatureXSAVEC,

FreddyYe wrote:
> craig.topper wrote:
> > Is this list this long because SKL includes SGX but RKL doesn't?
> Yes. And I don't know any simple ways to exclude SGX here, any suggestions?
Nothing pretty. Guess it depends on if SGX is going to not appear in more 
future CPUs or if this is a one off case. If it's going to continue then we 
could remove it from the inheritance and just give it to SKL, ICL, CNL, etc. 
individually.

Or we could just not default SGX on for any CPU. It's probably not all that 
useful in the backend anyway. Clang will put it in the target-feature attribute 
anyway. Having it in the backend feature lists doesn't really do anything since 
I don't think we have any IR intrinsics for SGX.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100085

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


[PATCH] D100127: [RISCV][Clang] Add some RVV Permutation intrinsic functions.

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

Support the following instructions.

1. Vector Slide Instructions
2. Vector Register Gather Instructions
3. Vector Compress Instruction

Authored-by: Roger Ferrer Ibanez 
Co-Authored-by: Zakk Chen 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100127

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfslide1down.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfslide1up.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vrgather.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslide1down.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslide1up.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslidedown.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vslideup.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfslide1down.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfslide1up.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vrgather.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslide1down.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslide1up.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslidedown.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vslideup.c

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


[PATCH] D100120: [RISCV][Clang] Add all RVV Mask intrinsic functions.

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

LGTM other than that inheritance question




Comment at: clang/include/clang/Basic/riscv_vector.td:247
+list> suffixes_prototypes> {
+  defm "" : RVVBuiltinSet;
+}

Can we use inheritance here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100120

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


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

2021-04-08 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I'm still not satisfied with the `addressof`, but I won't block this either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260

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


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

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/test/CodeGen/matrix-cast.c:82
+
+void cast_unsigned_short_int_to_unsigned_int(unsigned_short_int_5x5 s, 
unsigned_int_5x5 i) {
+  // CHECK-LABEL: define{{.*}} void 
@cast_unsigned_short_int_to_unsigned_int(<25 x i16> %s, <25 x i32> %i)

fhahn wrote:
> I think this is still missing a test from unsigned to signed?
I added a new `cast_unsigned_long_int_matrix_to_short`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman added a comment.

In D99517#2667025 , @rjmccall wrote:

> You should structure this code so it's easy to add exceptions for certain 
> calling conventions that can support tail calls with weaker restrictions 
> (principally, callee-pop conventions).  Mostly that probably means checking 
> the calling convention first, or extracting the type restriction checks into 
> a different function that you can skip.  For example, I believe x86's 
> `fastcall` convention can logically support any combination of prototypes as 
> `musttail` as long as the return types are vaguely compatible.

I moved the calling convention check to be as early as possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


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

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 336154.
SaurabhJha added a comment.

Addressed latest round of comments.
Also rebased with latest main as the windows build failed for some reason


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  

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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336153.
haberman added a comment.

- Moved calling convention check to happen as early as possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/AttrImpl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-musttail.cpp
  clang/test/Sema/attr-musttail.c
  clang/test/Sema/attr-musttail.cpp
  clang/test/Sema/attr-musttail.m

Index: clang/test/Sema/attr-musttail.m
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
+
+void TestObjcBlock(void) {
+  void (^x)(void) = ^(void) {
+__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
+  };
+  __attribute__((musttail)) return x();
+}
+
+void ReturnsVoid(void);
+void TestObjcBlockVar(void) {
+  __block int i = 0;  // expected-note{{jump exits scope of __block variable}}
+  __attribute__((musttail)) return ReturnsVoid();  // expected-error{{cannot perform a tail call from this return statement}}
+}
+
+//#import 
+
+__attribute__((objc_root_class))
+@interface TestObjcClass
+@end
+
+@implementation TestObjcClass
+
+- (void)testObjCMethod {
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
+}
+
+@end
Index: clang/test/Sema/attr-musttail.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.cpp
@@ -0,0 +1,191 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fms-extensions -fcxx-exceptions -fopenmp %s
+
+int ReturnsInt1();
+int Func1() {
+  [[clang::musttail]] ReturnsInt1();   // expected-error {{'musttail' attribute only applies to return statements}}
+  [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
+  [[clang::musttail]] return 5;// expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+  [[clang::musttail]] return ReturnsInt1();
+}
+
+void NoFunctionCall() {
+  [[clang::musttail]] return;  // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+}
+
+[[clang::musttail]] static int int_val = ReturnsInt1(); // expected-error {{'musttail' attribute cannot be applied to a declaration}}
+
+void NoParams(); // expected-note {{target function has different number of parameters (expected 1 but has 0)}}
+void TestParamArityMismatch(int x) {
+  [[clang::musttail]] return NoParams(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
+void TestParamTypeMismatch(int x) {
+  [[clang::musttail]] return LongParam(x); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+long ReturnsLong(); // expected-note {{target function has different return type ('int' expected but has 'long')}}
+int TestReturnTypeMismatch() {
+  [[clang::musttail]] return ReturnsLong(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+struct Struct1 {
+  void MemberFunction(); // expected-note {{target function is a member of different class (expected 'void' but has 'Struct1')}}
+};
+void TestNonMemberToMember() {
+  Struct1 st;
+  [[clang::musttail]] return st.MemberFunction(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void ReturnsVoid(); // expected-note {{target function is a member of different class (expected 'Struct2' but has 'void')}}
+struct Struct2 {
+  void TestMemberToNonMember() {
+[[clang::musttail]] return ReturnsVoid(); // expected-error{{'musttail' attribute requires that caller and callee have compatible function signatures}}
+  }
+};
+
+class HasNonTrivialDestructor {
+public:
+  ~HasNonTrivialDestructor() {}
+  int ReturnsInt();
+};
+
+void ReturnsVoid2();
+void 

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

2021-04-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks great now, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260

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


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

2021-04-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



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

haberman wrote:
> aaron.ballman wrote:
> > haberman wrote:
> > > aaron.ballman wrote:
> > > > haberman wrote:
> > > > > aaron.ballman wrote:
> > > > > > rsmith wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > haberman wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > > > This functionality belongs in SemaStmtAttr.cpp, 
> > > > > > > > > > > > > > > > I think.
> > > > > > > > > > > > > > > That is where I had originally put it, but that 
> > > > > > > > > > > > > > > didn't work for templates. The semantic checks 
> > > > > > > > > > > > > > > can only be performed at instantiation time. 
> > > > > > > > > > > > > > > `ActOnAttributedStmt` seems to be the right hook 
> > > > > > > > > > > > > > > point where I can evaluate the semantic checks 
> > > > > > > > > > > > > > > for both template and non-template functions 
> > > > > > > > > > > > > > > (with template functions getting checked at 
> > > > > > > > > > > > > > > instantiation time).
> > > > > > > > > > > > > > I disagree that `ActOnAttributedStmt()` is the 
> > > > > > > > > > > > > > correct place for this checking -- template 
> > > > > > > > > > > > > > checking should occur when the template is 
> > > > > > > > > > > > > > instantiated, same as happens for declaration 
> > > > > > > > > > > > > > attributes. I'd like to see this functionality 
> > > > > > > > > > > > > > moved to SemaStmtAttr.cpp. Keeping the attribute 
> > > > > > > > > > > > > > logic together and following the same patterns is 
> > > > > > > > > > > > > > what allows us to tablegenerate more of the 
> > > > > > > > > > > > > > attribute logic. Statement attributes are just 
> > > > > > > > > > > > > > starting to get more such automation.
> > > > > > > > > > > > > I tried commenting out this code and adding the 
> > > > > > > > > > > > > following code into `handleMustTailAttr()` in 
> > > > > > > > > > > > > `SemaStmtAttr.cpp`:
> > > > > > > > > > > > > 
> > > > > > > > > > > > > ```
> > > > > > > > > > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > > > > > > > > > return nullptr;
> > > > > > > > > > > > > ```
> > > > > > > > > > > > > 
> > > > > > > > > > > > > This caused my test cases related to templates to 
> > > > > > > > > > > > > fail. It also seemed to break test cases related to 
> > > > > > > > > > > > > `JumpDiagnostics`. My interpretation of this is that 
> > > > > > > > > > > > > `handleMustTailAttr()` is called during parsing only, 
> > > > > > > > > > > > > and cannot catch errors at template instantiation 
> > > > > > > > > > > > > time or that require a more complete AST.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > What am I missing? Where in SemaStmtAttr.cpp are you 
> > > > > > > > > > > > > suggesting that I put this check?
> > > > > > > > > > > > Scratch the part about `JumpDiagnostics`, that was me 
> > > > > > > > > > > > failing to call `S.setFunctionHasMustTail()`. I added 
> > > > > > > > > > > > that and now the `JumpDiagnostics` tests pass.
> > > > > > > > > > > > 
> > > > > > > > > > > > But the template test cases still fail, and I can't 
> > > > > > > > > > > > find any hook point in `SemaStmtAttr.cpp` that will let 
> > > > > > > > > > > > me evaluate these checks at template instantiation time.
> > > > > > > > > > > I think there's a bit of an architectural mixup, but I'm 
> > > > > > > > > > > curious if @rsmith agrees before anyone starts doing work 
> > > > > > > > > > > to make changes.
> > > > > > > > > > > 
> > > > > > > > > > > When transforming declarations, `RebuildWhatever()` calls 
> > > > > > > > > > > the `ActOnWhatever()` function which calls 
> > > > > > > > > > > `ProcessDeclAttributeList()` so that attributes are 
> > > > > > > > > > > processed. `RebuildAttributedStmt()` similarly calls 
> > > > > > > > > > > `ActOnAttributedStmt()`. However, `ActOnAttributedStmt()` 
> > > > > > > > > > > doesn't call `ProcessStmtAttributes()` -- the logic is 
> > > > > > > > > > > reversed so that `ProcessStmtAttributes()` is what calls 
> > > > > > > > > > > `ActOnAttributedStmt()`.
> > > > > > > > > > > 
> > > > > > > > > > > I think the correct answer is to switch the logic so that 
> > > > > > > > > > > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, 
> > > > > > > > > > > then the template logic should automatically work.
> > > > > > > > > > > I think the correct answer is to switch the logic so that 
> > 

[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-04-08 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 336148.
jamieschmeiser added a comment.

Reformat to satisfy clang-format


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

https://reviews.llvm.org/D98798

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/pointer-addition.c


Index: clang/test/Sema/pointer-addition.c
===
--- clang/test/Sema/pointer-addition.c
+++ clang/test/Sema/pointer-addition.c
@@ -29,4 +29,6 @@
   // Cases that don't match the GNU inttoptr idiom get a different warning.
   f = (char*)0 - i; // expected-warning {{performing pointer arithmetic on a 
null pointer has undefined behavior}}
   int *g = (int*)0 + i; // expected-warning {{performing pointer arithmetic on 
a null pointer has undefined behavior}}
+  f = (char*)((char*)0 - f); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}}
+  f = (char*)(f - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}}
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10720,7 +10720,15 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  // Subtracting from a null pointer should produce a warning.
+  if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull))
+diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false);
+
+  // Subtracting a null pointer should produce a warning.
+  if (RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull))
+diagnoseArithmeticOnNullPointer(*this, Loc, RHS.get(), false);
 
   // The pointee type may have zero size.  As an extension, a structure or
   // union may have zero size or an array may have zero length.  In this


Index: clang/test/Sema/pointer-addition.c
===
--- clang/test/Sema/pointer-addition.c
+++ clang/test/Sema/pointer-addition.c
@@ -29,4 +29,6 @@
   // Cases that don't match the GNU inttoptr idiom get a different warning.
   f = (char*)0 - i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
   int *g = (int*)0 + i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
+  f = (char*)((char*)0 - f); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
+  f = (char*)(f - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10720,7 +10720,15 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  // Subtracting from a null pointer should produce a warning.
+  if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull))
+diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false);
+
+  // Subtracting a null pointer should produce a warning.
+  if (RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull))
+diagnoseArithmeticOnNullPointer(*this, Loc, RHS.get(), false);
 
   // The pointee type may have zero size.  As an extension, a structure or
   // union may have zero size or an array may have zero length.  In this
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97462: [clang][cli] Round-trip cc1 arguments in assert builds

2021-04-08 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

I just merged this commit into our CHERI fork and noticed some failing tests 
due to round tripping:
We add some additional CodeGenOptions and LangOptions, but are not including 
those in the generated command line.

For example, I added an additional `std::string CHERIStatsFile;` to 
`CodeGenOptions`. This is set inside `bool 
CompilerInvocation::ParseCodeGenArgs` using `Opts.CHERIStatsFile = 
Args.getLastArgValue(OPT_cheri_stats_file).str();`.
I haven't added logic to round trip this flag (yet). If CC1 argument round 
tripping is enabled, the flag is stripped and the output goes to stderr instead 
of the defined file, causing some tests to fail.

Unfortunately this is not caught by any assertions, so I worry that there are 
other arguments that might be silently removed after this commit. Are there any 
open reviews/plans to check CodeGenOptions/etc, for equality after 
round-tripping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97462

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


[PATCH] D100124: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-04-08 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen created this revision.
steffenlarsen added reviewers: jdoerfert, jholewinski.
Herald added subscribers: hiraditya, yaxunl.
steffenlarsen requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Adds NVPTX builtins and intrinsics for the CUDA PTX `redux.sync` instructions 
for `sm_80` architecture or newer.

PTX ISA description of `redux.sync`: 
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-redux-sync

Authored-by: Steffen Larsen 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100124

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGenCUDA/redux-builtins.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/redux-sync.ll

Index: llvm/test/CodeGen/NVPTX/redux-sync.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/redux-sync.ll
@@ -0,0 +1,73 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck %s
+
+declare i32 @llvm.nvvm.redux.sync.add.u32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_add_u32
+define i32 @redux_sync_add_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.add.u32
+  %val = call i32 @llvm.nvvm.redux.sync.add.u32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.min.u32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_u32
+define i32 @redux_sync_min_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.u32
+  %val = call i32 @llvm.nvvm.redux.sync.min.u32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.max.u32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_u32
+define i32 @redux_sync_max_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.u32
+  %val = call i32 @llvm.nvvm.redux.sync.max.u32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.add.s32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_add_s32
+define i32 @redux_sync_add_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.add.s32
+  %val = call i32 @llvm.nvvm.redux.sync.add.s32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.min.s32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_s32
+define i32 @redux_sync_min_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.s32
+  %val = call i32 @llvm.nvvm.redux.sync.min.s32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.max.s32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_s32
+define i32 @redux_sync_max_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.s32
+  %val = call i32 @llvm.nvvm.redux.sync.max.s32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.and.b32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_and_b32
+define i32 @redux_sync_and_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.and.b32
+  %val = call i32 @llvm.nvvm.redux.sync.and.b32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.xor.b32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_xor_b32
+define i32 @redux_sync_xor_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.xor.b32
+  %val = call i32 @llvm.nvvm.redux.sync.xor.b32(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.or.b32(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_or_b32
+define i32 @redux_sync_or_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.or.b32
+  %val = call i32 @llvm.nvvm.redux.sync.or.b32(i32 %src, i32 %mask)
+  ret i32 %val
+}
Index: llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -274,6 +274,23 @@
 defm MATCH_ALLP_SYNC_64 : MATCH_ALLP_SYNC;
 
+multiclass REDUX_SYNC {
+  def : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$mask),
+  "redux.sync." # BinOp # "." # PTXType # " $dst, $src, $mask;",
+  [(set Int32Regs:$dst, (Intrin Int32Regs:$src, Int32Regs:$mask))]>,
+Requires<[hasPTX70, hasSM80]>;
+}
+
+defm REDUX_SYNC_ADD_U32 : REDUX_SYNC<"add", "u32", int_nvvm_redux_sync_add_u32>;
+defm REDUX_SYNC_MIN_U32 : REDUX_SYNC<"min", "u32", int_nvvm_redux_sync_min_u32>;
+defm REDUX_SYNC_MAX_U32 : REDUX_SYNC<"max", "u32", int_nvvm_redux_sync_max_u32>;
+defm REDUX_SYNC_ADD_S32 : REDUX_SYNC<"add", "s32", int_nvvm_redux_sync_add_s32>;
+defm REDUX_SYNC_MIN_S32 : REDUX_SYNC<"min", "s32", int_nvvm_redux_sync_min_s32>;
+defm REDUX_SYNC_MAX_S32 : REDUX_SYNC<"max", "s32", int_nvvm_redux_sync_max_s32>;
+defm REDUX_SYNC_AND_B32 : REDUX_SYNC<"and", "b32", int_nvvm_redux_sync_and_b32>;
+defm REDUX_SYNC_XOR_B32 : REDUX_SYNC<"xor", "b32", int_nvvm_redux_sync_xor_b32>;
+defm REDUX_SYNC_OR_B32 : REDUX_SYNC<"or", "b32", int_nvvm_redux_sync_or_b32>;
+
 } // 

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

2021-04-08 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:594
   auto PType = Transformer.back();
+  static unsigned NFCount = 0;
   switch (PType) {

rogfer01 wrote:
> Was this meant to be `static` here?
Maybe we can create a new complex type transformer `(Tuple:Value)`,  so 
`(Tuple:3)` means `TTTv`. It can avoid to use `static` here. You could ref 
https://github.com/llvm/llvm-project/blob/main/clang/utils/TableGen/RISCVVEmitter.cpp#L638


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99593

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


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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman added inline comments.



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

aaron.ballman wrote:
> haberman wrote:
> > aaron.ballman wrote:
> > > haberman wrote:
> > > > aaron.ballman wrote:
> > > > > rsmith wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > haberman wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > haberman wrote:
> > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > haberman wrote:
> > > > > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > > > > This functionality belongs in SemaStmtAttr.cpp, I 
> > > > > > > > > > > > > > > think.
> > > > > > > > > > > > > > That is where I had originally put it, but that 
> > > > > > > > > > > > > > didn't work for templates. The semantic checks can 
> > > > > > > > > > > > > > only be performed at instantiation time. 
> > > > > > > > > > > > > > `ActOnAttributedStmt` seems to be the right hook 
> > > > > > > > > > > > > > point where I can evaluate the semantic checks for 
> > > > > > > > > > > > > > both template and non-template functions (with 
> > > > > > > > > > > > > > template functions getting checked at instantiation 
> > > > > > > > > > > > > > time).
> > > > > > > > > > > > > I disagree that `ActOnAttributedStmt()` is the 
> > > > > > > > > > > > > correct place for this checking -- template checking 
> > > > > > > > > > > > > should occur when the template is instantiated, same 
> > > > > > > > > > > > > as happens for declaration attributes. I'd like to 
> > > > > > > > > > > > > see this functionality moved to SemaStmtAttr.cpp. 
> > > > > > > > > > > > > Keeping the attribute logic together and following 
> > > > > > > > > > > > > the same patterns is what allows us to tablegenerate 
> > > > > > > > > > > > > more of the attribute logic. Statement attributes are 
> > > > > > > > > > > > > just starting to get more such automation.
> > > > > > > > > > > > I tried commenting out this code and adding the 
> > > > > > > > > > > > following code into `handleMustTailAttr()` in 
> > > > > > > > > > > > `SemaStmtAttr.cpp`:
> > > > > > > > > > > > 
> > > > > > > > > > > > ```
> > > > > > > > > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > > > > > > > > return nullptr;
> > > > > > > > > > > > ```
> > > > > > > > > > > > 
> > > > > > > > > > > > This caused my test cases related to templates to fail. 
> > > > > > > > > > > > It also seemed to break test cases related to 
> > > > > > > > > > > > `JumpDiagnostics`. My interpretation of this is that 
> > > > > > > > > > > > `handleMustTailAttr()` is called during parsing only, 
> > > > > > > > > > > > and cannot catch errors at template instantiation time 
> > > > > > > > > > > > or that require a more complete AST.
> > > > > > > > > > > > 
> > > > > > > > > > > > What am I missing? Where in SemaStmtAttr.cpp are you 
> > > > > > > > > > > > suggesting that I put this check?
> > > > > > > > > > > Scratch the part about `JumpDiagnostics`, that was me 
> > > > > > > > > > > failing to call `S.setFunctionHasMustTail()`. I added 
> > > > > > > > > > > that and now the `JumpDiagnostics` tests pass.
> > > > > > > > > > > 
> > > > > > > > > > > But the template test cases still fail, and I can't find 
> > > > > > > > > > > any hook point in `SemaStmtAttr.cpp` that will let me 
> > > > > > > > > > > evaluate these checks at template instantiation time.
> > > > > > > > > > I think there's a bit of an architectural mixup, but I'm 
> > > > > > > > > > curious if @rsmith agrees before anyone starts doing work 
> > > > > > > > > > to make changes.
> > > > > > > > > > 
> > > > > > > > > > When transforming declarations, `RebuildWhatever()` calls 
> > > > > > > > > > the `ActOnWhatever()` function which calls 
> > > > > > > > > > `ProcessDeclAttributeList()` so that attributes are 
> > > > > > > > > > processed. `RebuildAttributedStmt()` similarly calls 
> > > > > > > > > > `ActOnAttributedStmt()`. However, `ActOnAttributedStmt()` 
> > > > > > > > > > doesn't call `ProcessStmtAttributes()` -- the logic is 
> > > > > > > > > > reversed so that `ProcessStmtAttributes()` is what calls 
> > > > > > > > > > `ActOnAttributedStmt()`.
> > > > > > > > > > 
> > > > > > > > > > I think the correct answer is to switch the logic so that 
> > > > > > > > > > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, 
> > > > > > > > > > then the template logic should automatically work.
> > > > > > > > > > I think the correct answer is to switch the logic so that 
> > > > > > > > > > ActOnAttributedStmt() calls ProcessStmtAttributes()
> > > > > > > > > 
> > > > > > > > > I think this would require `ProcessStmtAttributes()` to be 
> > > > > > > > > split into two 

[PATCH] D99181: [analyzer] Fix crash on spaceship operator (PR47511)

2021-04-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

Looks great now!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99181

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


[PATCH] D99984: [RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.

2021-04-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:259
   .Case("riscv64", Is64Bit)
+  .Case("64bit", Is64Bit)
   .Case("m", HasM)

frasercrmck wrote:
> craig.topper wrote:
> > frasercrmck wrote:
> > > What's the difference between this new feature and `riscv64` above?
> > The name I added to initFeatureMap has to match the feature name in 
> > RISCV.td because it will end up in the target-features attribute in IR.
> > 
> > SemaChecking just calls hasFeature, but CodeGenFunction also checks builtin 
> > features using the feature map. We check features in SemaChecking because 
> > the CodeGenFunction diagnostic isn’t phrased well for RISCV.
> Ah I see, so since it has to match our `"64bit"` `SubtargetFeature` we can't 
> reuse `"riscv64"`? Thanks.
Correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99984

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


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

2021-04-08 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336141.
haberman added a comment.

- Factored duplicated code into a method on MustTailAttr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/AttrImpl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/EHScopeStack.h
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGen/attr-musttail.cpp
  clang/test/Sema/attr-musttail.c
  clang/test/Sema/attr-musttail.cpp
  clang/test/Sema/attr-musttail.m

Index: clang/test/Sema/attr-musttail.m
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
+
+void TestObjcBlock(void) {
+  void (^x)(void) = ^(void) {
+__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
+  };
+  __attribute__((musttail)) return x();
+}
+
+void ReturnsVoid(void);
+void TestObjcBlockVar(void) {
+  __block int i = 0;  // expected-note{{jump exits scope of __block variable}}
+  __attribute__((musttail)) return ReturnsVoid();  // expected-error{{cannot perform a tail call from this return statement}}
+}
+
+//#import 
+
+__attribute__((objc_root_class))
+@interface TestObjcClass
+@end
+
+@implementation TestObjcClass
+
+- (void)testObjCMethod {
+  __attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
+}
+
+@end
Index: clang/test/Sema/attr-musttail.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-musttail.cpp
@@ -0,0 +1,191 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fms-extensions -fcxx-exceptions -fopenmp %s
+
+int ReturnsInt1();
+int Func1() {
+  [[clang::musttail]] ReturnsInt1();   // expected-error {{'musttail' attribute only applies to return statements}}
+  [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
+  [[clang::musttail]] return 5;// expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+  [[clang::musttail]] return ReturnsInt1();
+}
+
+void NoFunctionCall() {
+  [[clang::musttail]] return;  // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
+}
+
+[[clang::musttail]] static int int_val = ReturnsInt1(); // expected-error {{'musttail' attribute cannot be applied to a declaration}}
+
+void NoParams(); // expected-note {{target function has different number of parameters (expected 1 but has 0)}}
+void TestParamArityMismatch(int x) {
+  [[clang::musttail]] return NoParams(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
+void TestParamTypeMismatch(int x) {
+  [[clang::musttail]] return LongParam(x); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+long ReturnsLong(); // expected-note {{target function has different return type ('int' expected but has 'long')}}
+int TestReturnTypeMismatch() {
+  [[clang::musttail]] return ReturnsLong(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+struct Struct1 {
+  void MemberFunction(); // expected-note {{target function is a member of different class (expected 'void' but has 'Struct1')}}
+};
+void TestNonMemberToMember() {
+  Struct1 st;
+  [[clang::musttail]] return st.MemberFunction(); // expected-error {{'musttail' attribute requires that caller and callee have compatible function signatures}}
+}
+
+void ReturnsVoid(); // expected-note {{target function is a member of different class (expected 'Struct2' but has 'void')}}
+struct Struct2 {
+  void TestMemberToNonMember() {
+[[clang::musttail]] return ReturnsVoid(); // expected-error{{'musttail' attribute requires that caller and callee have compatible function signatures}}
+  }
+};
+
+class HasNonTrivialDestructor {
+public:
+  ~HasNonTrivialDestructor() {}
+  int ReturnsInt();
+};
+
+void ReturnsVoid2();
+void TestNonTrivialDestructorInScope() 

[PATCH] D99995: [OpenMP51] Initial support for masked directive and filter clause

2021-04-08 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen added inline comments.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2814
 }
 
 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))

ABataev wrote:
> This can be simplified like this:
> ```
> if (!FirstClause) {
>   Diag(Tok, diag::err_omp_more_one_clause)
>   << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
>   ErrorFound = true;
> }
> LLVM_FALLTHROUGH;
> case OMPC_filter:
> ```
> Plus, I think, you should not exclude OMPC_filter from the check, I think 
> only single clause is allowed by the spec.
I misunderstood the syntax and will fix this and the tests, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D5

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


[PATCH] D99984: [RISCV] Prevent __builtin_riscv_orc_b_64 from being compiled RV32 target.

2021-04-08 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck accepted this revision.
frasercrmck added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:259
   .Case("riscv64", Is64Bit)
+  .Case("64bit", Is64Bit)
   .Case("m", HasM)

craig.topper wrote:
> frasercrmck wrote:
> > What's the difference between this new feature and `riscv64` above?
> The name I added to initFeatureMap has to match the feature name in RISCV.td 
> because it will end up in the target-features attribute in IR.
> 
> SemaChecking just calls hasFeature, but CodeGenFunction also checks builtin 
> features using the feature map. We check features in SemaChecking because the 
> CodeGenFunction diagnostic isn’t phrased well for RISCV.
Ah I see, so since it has to match our `"64bit"` `SubtargetFeature` we can't 
reuse `"riscv64"`? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99984

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


[PATCH] D100118: [clang] RFC Support new arithmetic __fence builtin to control floating point optiization

2021-04-08 Thread Melanie Blower via Phabricator via cfe-commits
mibintc created this revision.
mibintc added a reviewer: kpn.
Herald added a subscriber: jfb.
mibintc requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: llvm-commits.

This is a proposal to add a new clang builtin, __arithmetic_fence.  The purpose 
of the builtin is to provide the user fine control, at the expression level, 
over floating point optimization when -ffast-math (-ffp-model=fast) is enabled. 
 We are also proposing a new clang builtin that provides access to this 
intrinsic, as well as a new clang command line option `-fprotect-parens` that 
will be implemented using this intrinsic.

This is the clang patch corresponding to https://reviews.llvm.org/D99675 which 
proposes a new llvm intrinsic llvm.arith.fence

Note: Preliminary patch, not ready for code review, doesn't yet run end-to-end 
with the llvm patch, and the logic for the new option is not yet written.

Rationale
-

Some expression transformations that are mathematically correct, such as 
reassociation and distribution, may be incorrect when dealing with finite 
precision floating point.  For example, these two expressions,

  (a + b) + c
  a + (b + c)

are equivalent mathematically in integer arithmetic, but not in floating point. 
 In some floating point (FP) models, the compiler is allowed to make these 
value-unsafe transformations for performance reasons, even when the programmer 
uses parentheses explicitly.  But the compiler must always honor the 
parentheses implied by __arithmetic_fence, regardless of the FP model settings.

Under `–ffp-model=fast`, __arithmetic_fence provides a way to partially enforce 
ordering in an FP expression.

| Original expression   | Transformed expression | Permitted? |
| - | -- | -- |
| (a + b) + c   | a + (b + c)| Yes!   |
| __arithmetic_fence(a + b) + c | a + (b + c)| No!|
|



NOTE: The __arithmetic_fence serves no purpose in value-safe FP modes like 
`–ffp-model=precise`:  FP expressions are already strictly ordered.



Motivation:
---

- The new clang builtin provides clang compatibility with the Intel C++ 
compiler builtin `__fence` which has similar semantics, and likewise enables 
implementation of the option `-fprotect-parens`.
- The new builtin provides the clang programmer control over floating point 
optimizations at the expression level.
- The gnu fortran compiler, gfortran, likewise supports `-fprotect-parens`

Requirements for __arithmetic_fence:


- There is one operand. The operand type must be scalar floating point, complex 
floating point or vector thereof.
- The return type is the same as the operand type.
- The return value is equivalent to the operand.
- The invocation of __arithmetic_fence is not a C/C++ constant expression, even 
if the operands are constant.

New option `-fprotect-parens`
-

- Determines whether the optimizer honors parentheses when floating-point 
expressions are evaluated
- Option defaults to `fno-protect-parens`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100118

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/arithmetic-fence-builtin.c
  clang/test/Sema/arithmetic-fence-builtin.c
  llvm/include/llvm/IR/IRBuilder.h

Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -897,6 +897,13 @@
 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
   }
 
+  /// Create a call to the arithmetic_fence intrinsic.
+  CallInst *CreateArithmeticFence(Value *Val, Type *DstType,
+  const Twine  = "") {
+return CreateIntrinsic(Intrinsic::arithmetic_fence, {DstType}, {Val}, nullptr,
+   Name);
+  }
+
   /// Create a call to the experimental.vector.extract intrinsic.
   CallInst *CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx,
 const Twine  = "") {
Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- /dev/null
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
+int v;
+template  T addT(T a, T b) {
+  T *q = __arithmetic_fence();
+  // expected-error@-1 {{operand of type 'float *' where floating, complex or a vector of such types is required ('float *' invalid)}}
+  // expected-error@-2 {{operand of type 'int *' where floating, complex or a vector of such types is required ('int *' invalid)}}
+ 

  1   2   >