[PATCH] D96853: [clang][AVR] Support variable decorator '__flash'

2021-04-09 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f173c0c42d0: [clang][AVR] Support variable decorator 
__flash (authored by benshi001).

Changed prior to commit:
  https://reviews.llvm.org/D96853?vs=334336=336593#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96853

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/address-space-avr.c
  clang/test/CodeGen/avr-flash.c


Index: clang/test/CodeGen/avr-flash.c
===
--- /dev/null
+++ clang/test/CodeGen/avr-flash.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm-only -verify %s
+
+int foo(void) {
+  static __flash int b[] = {4, 6}; // expected-error {{qualifier 'const' is 
needed for variables in address space '__flash'}}
+  return b[0];
+}
Index: clang/test/CodeGen/address-space-avr.c
===
--- clang/test/CodeGen/address-space-avr.c
+++ clang/test/CodeGen/address-space-avr.c
@@ -1,12 +1,21 @@
 // RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s
 
-// Test that function declarations in nonzero address spaces without prototype
-// are called correctly.
+// CHECK: @var0 {{.*}} addrspace(1) constant [3 x i16]
+// CHECK: @bar.var2 {{.*}} addrspace(1) constant [3 x i16]
+// CHECK: @var1 {{.*}} addrspace(1) constant [3 x i16]
 
 // CHECK: define{{.*}} void @bar() addrspace(1)
-// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to 
void (i16) addrspace(1)*)(i16 3)
+// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to 
void (i16) addrspace(1)*)
 // CHECK: declare void @foo(...) addrspace(1)
+
+__flash const int var0[] = {999, 888, 777};
+__flash static const int var1[] = {111, 222, 333};
+
+int i;
+
 void foo();
-void bar(void) {
-   foo(3);
+
+void bar() {
+  static __flash const int var2[] = {555, 666, 777};
+  foo(var1[i]);
 }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8108,6 +8108,19 @@
   AVRTargetCodeGenInfo(CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
+  LangAS getGlobalVarAddressSpace(CodeGenModule ,
+  const VarDecl *D) const override {
+// Check if a global/static variable is defined within address space 1
+// but not constant.
+LangAS AS = D->getType().getAddressSpace();
+if (isTargetAddressSpace(AS) && toTargetAddressSpace(AS) == 1 &&
+!D->getType().isConstQualified())
+  CGM.getDiags().Report(D->getLocation(),
+diag::err_verify_nonconst_addrspace)
+  << "__flash";
+return TargetCodeGenInfo::getGlobalVarAddressSpace(CGM, D);
+  }
+
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override {
 if (GV->isDeclaration())
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -308,6 +308,7 @@
   Builder.defineMacro("__AVR");
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
+  Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(
Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td
===
--- clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -158,6 +158,8 @@
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<
 "no expected directives found: consider use of 'expected-no-diagnostics'">;
+def err_verify_nonconst_addrspace : Error<
+  "qualifier 'const' is needed for variables in address space '%0'">;
 
 def note_fixit_applied : Note<"FIX-IT applied suggested code changes">;
 def note_fixit_in_macro : Note<


Index: clang/test/CodeGen/avr-flash.c
===
--- /dev/null
+++ clang/test/CodeGen/avr-flash.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm-only -verify %s
+
+int foo(void) {
+  static __flash int b[] = {4, 6}; // expected-error {{qualifier 'const' is needed for variables in address space '__flash'}}
+  return b[0];
+}
Index: clang/test/CodeGen/address-space-avr.c
===
--- clang/test/CodeGen/address-space-avr.c
+++ clang/test/CodeGen/address-space-avr.c
@@ -1,12 +1,21 @@
 // RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s
 
-// Test that 

[clang] 4f173c0 - [clang][AVR] Support variable decorator '__flash'

2021-04-09 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2021-04-10T11:23:55+08:00
New Revision: 4f173c0c42d02b14ab388a826ef0d463a07d7953

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

LOG: [clang][AVR] Support variable decorator '__flash'

Reviewed By: Anastasia

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

Added: 
clang/test/CodeGen/avr-flash.c

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/Basic/Targets/AVR.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/address-space-avr.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 3086e922d9ed6..39fdefc77fbee 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -158,6 +158,8 @@ def err_verify_invalid_no_diags : Error<
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<
 "no expected directives found: consider use of 'expected-no-diagnostics'">;
+def err_verify_nonconst_addrspace : Error<
+  "qualifier 'const' is needed for variables in address space '%0'">;
 
 def note_fixit_applied : Note<"FIX-IT applied suggested code changes">;
 def note_fixit_in_macro : Note<

diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 664eea0de8416..e87b7338c4d6e 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -308,6 +308,7 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
,
   Builder.defineMacro("__AVR");
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
+  Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index de3d3f86fe9b9..7f4deb21d6ed0 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8108,6 +8108,19 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
   AVRTargetCodeGenInfo(CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
+  LangAS getGlobalVarAddressSpace(CodeGenModule ,
+  const VarDecl *D) const override {
+// Check if a global/static variable is defined within address space 1
+// but not constant.
+LangAS AS = D->getType().getAddressSpace();
+if (isTargetAddressSpace(AS) && toTargetAddressSpace(AS) == 1 &&
+!D->getType().isConstQualified())
+  CGM.getDiags().Report(D->getLocation(),
+diag::err_verify_nonconst_addrspace)
+  << "__flash";
+return TargetCodeGenInfo::getGlobalVarAddressSpace(CGM, D);
+  }
+
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override {
 if (GV->isDeclaration())

diff  --git a/clang/test/CodeGen/address-space-avr.c 
b/clang/test/CodeGen/address-space-avr.c
index 6c32dff2d0fe3..ea78c895f63dc 100644
--- a/clang/test/CodeGen/address-space-avr.c
+++ b/clang/test/CodeGen/address-space-avr.c
@@ -1,12 +1,21 @@
 // RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s
 
-// Test that function declarations in nonzero address spaces without prototype
-// are called correctly.
+// CHECK: @var0 {{.*}} addrspace(1) constant [3 x i16]
+// CHECK: @bar.var2 {{.*}} addrspace(1) constant [3 x i16]
+// CHECK: @var1 {{.*}} addrspace(1) constant [3 x i16]
 
 // CHECK: define{{.*}} void @bar() addrspace(1)
-// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to 
void (i16) addrspace(1)*)(i16 3)
+// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to 
void (i16) addrspace(1)*)
 // CHECK: declare void @foo(...) addrspace(1)
+
+__flash const int var0[] = {999, 888, 777};
+__flash static const int var1[] = {111, 222, 333};
+
+int i;
+
 void foo();
-void bar(void) {
-   foo(3);
+
+void bar() {
+  static __flash const int var2[] = {555, 666, 777};
+  foo(var1[i]);
 }

diff  --git a/clang/test/CodeGen/avr-flash.c b/clang/test/CodeGen/avr-flash.c
new file mode 100644
index 0..99648137d0f18
--- /dev/null
+++ b/clang/test/CodeGen/avr-flash.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm-only -verify %s
+
+int foo(void) {
+  static __flash int b[] = {4, 6}; // expected-error {{qualifier 'const' is 
needed for variables in address space '__flash'}}
+  return b[0];
+}



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


[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-04-09 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:854
   if (Ex && !Ex->isTypeDependent()) {
+NRVOResult NRVORes = IsThrownVarInScope ? getNRVOResult(Ex) : NRVOResult();
+

mizvekov wrote:
> aaronpuchert wrote:
> > Any reason why you've moved that away from the comment that wants to 
> > explain it?
> Yes, on C++2b this might modify Ex, and I moved it so this would happen 
> before we do the check with the type of the expression just below here.
But yeah I forgot to move the comment, good catch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

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


[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-04-09 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaCoroutine.cpp:1585-1586
   InitializedEntity Entity = InitializedEntity::InitializeVariable(GroDecl);
-  ExprResult Res = S.PerformMoveOrCopyInitialization(Entity, nullptr, GroType,
- this->ReturnValue);
+  ExprResult Res =
+  S.PerformCopyInitialization(Entity, SourceLocation(), ReturnValue);
   if (Res.isInvalid())

mizvekov wrote:
> aaronpuchert wrote:
> > Perhaps this should just be direct initialization? Can't really find 
> > anything in the standard though.
> So I just checked this again. Regarding our conversation on IRC, what I said 
> initially was correct: `ReturnValue` is always a member function expression, 
> built by `makeReturnObject` -> `buildPromiseCall` -> `buildMemberCall`. So 
> implicit move would never trigger here, and as far as I see there is no 
> reason for this code to have used PerformMoveOrCopyInitialization in the 
> first place.
Err I meant: member function *call* expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

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


[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-04-09 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaCoroutine.cpp:1585-1586
   InitializedEntity Entity = InitializedEntity::InitializeVariable(GroDecl);
-  ExprResult Res = S.PerformMoveOrCopyInitialization(Entity, nullptr, GroType,
- this->ReturnValue);
+  ExprResult Res =
+  S.PerformCopyInitialization(Entity, SourceLocation(), ReturnValue);
   if (Res.isInvalid())

aaronpuchert wrote:
> Perhaps this should just be direct initialization? Can't really find anything 
> in the standard though.
So I just checked this again. Regarding our conversation on IRC, what I said 
initially was correct: `ReturnValue` is always a member function expression, 
built by `makeReturnObject` -> `buildPromiseCall` -> `buildMemberCall`. So 
implicit move would never trigger here, and as far as I see there is no reason 
for this code to have used PerformMoveOrCopyInitialization in the first place.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:854
   if (Ex && !Ex->isTypeDependent()) {
+NRVOResult NRVORes = IsThrownVarInScope ? getNRVOResult(Ex) : NRVOResult();
+

aaronpuchert wrote:
> Any reason why you've moved that away from the comment that wants to explain 
> it?
Yes, on C++2b this might modify Ex, and I moved it so this would happen before 
we do the check with the type of the expression just below here.



Comment at: clang/lib/Sema/SemaStmt.cpp:3030-3032
+  Res.S = Res.S != Sema::NRVOResult::None && CanMove
+  ? Sema::NRVOResult::MoveEligible
+  : Sema::NRVOResult::None;

aaronpuchert wrote:
> The way you've designed the enumeration, couldn't you use `std::min` here?
Yes exactly!
The previous version of this patch I submitted used exactly that, but then for 
some reason I thought people could find std::min a bit odd here, and so I 
changed it.
But now I think I was right the first time around :)



Comment at: clang/lib/Sema/SemaStmt.cpp:3140
+/// \param ReturnType This is the return type of the function.
+void Sema::updNRVOResultWithRetType(NRVOResult , QualType ReturnType) {
+  if (!Res.Candidate)

aaronpuchert wrote:
> `NRVOResult` seems to be small, why not make this a proper function and let 
> it return the result?
It does use the result parameter as input and output. This function can only 
"downgrade" a result it received previously.
I could make it receive a result and return the result, but then would probably 
just use it like this:
```
NRVORes = updNRVOResultWithRetType(NRVORes, ...);
```
Do you think that looks clearer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

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


[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-04-09 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Didn't really check for correctness yet, just a superficial review.

I like the idea, splitting the functionality up definitely helps understanding 
this.




Comment at: clang/include/clang/Sema/Sema.h:4733
+
+bool isMoveEligible() const { return S >= MoveEligible; };
+bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }

Nitpick: I'd go with `!= None` here.



Comment at: clang/lib/Sema/SemaCoroutine.cpp:1585-1586
   InitializedEntity Entity = InitializedEntity::InitializeVariable(GroDecl);
-  ExprResult Res = S.PerformMoveOrCopyInitialization(Entity, nullptr, GroType,
- this->ReturnValue);
+  ExprResult Res =
+  S.PerformCopyInitialization(Entity, SourceLocation(), ReturnValue);
   if (Res.isInvalid())

Perhaps this should just be direct initialization? Can't really find anything 
in the standard though.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:854
   if (Ex && !Ex->isTypeDependent()) {
+NRVOResult NRVORes = IsThrownVarInScope ? getNRVOResult(Ex) : NRVOResult();
+

Any reason why you've moved that away from the comment that wants to explain it?



Comment at: clang/lib/Sema/SemaStmt.cpp:3030-3032
+  Res.S = Res.S != Sema::NRVOResult::None && CanMove
+  ? Sema::NRVOResult::MoveEligible
+  : Sema::NRVOResult::None;

The way you've designed the enumeration, couldn't you use `std::min` here?



Comment at: clang/lib/Sema/SemaStmt.cpp:3040
 ///
-/// \param E The expression being returned from the function or block, or
-/// being thrown.
+/// \\param Parenthesized Whether the expression this candidate was obtained
+/// from was parenthesized.

The second backslash seems superfluous.



Comment at: clang/lib/Sema/SemaStmt.cpp:3058
 
-bool Sema::isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK) {
-  QualType VDType = VD->getType();
-  // - in a return statement in a function with ...
-  // ... a class return type ...
-  if (!ReturnType.isNull() && !ReturnType->isDependentType()) {
-if (!ReturnType->isRecordType())
-  return false;
-// ... the same cv-unqualified type as the function return type ...
-// When considering moving this expression out, allow dissimilar types.
-if (!(CESK & CES_AllowDifferentTypes) && !VDType->isDependentType() &&
-!Context.hasSameUnqualifiedType(ReturnType, VDType))
-  return false;
+  // (other than a function ... parameter)
+  if (VD->getKind() == Decl::ParmVar) {

These comments seem to be separated from their context now...



Comment at: clang/lib/Sema/SemaStmt.cpp:3059
+  // (other than a function ... parameter)
+  if (VD->getKind() == Decl::ParmVar) {
+downgradeNRVOResult(Res, hasCXX11);

Braces are usually omitted if both branches are single statements.



Comment at: clang/lib/Sema/SemaStmt.cpp:3073
 
   // Return false if VD is a __block variable. We don't want to implicitly move
   // out of a __block variable during a return because we cannot assume the

Just remove "Return false if VD is a __block variable." No need to repeat the 
code, what follows is important.



Comment at: clang/lib/Sema/SemaStmt.cpp:3107
+
+/// Determine whether the given expression might be move-eligible or
+/// copy-elidable in either a (co_)return statement or throw expression,

Can we maybe move this function up one place to make the diff a bit smaller? It 
appears to contain the first part of the original `getCopyElisionCandidate`.



Comment at: clang/lib/Sema/SemaStmt.cpp:3140
+/// \param ReturnType This is the return type of the function.
+void Sema::updNRVOResultWithRetType(NRVOResult , QualType ReturnType) {
+  if (!Res.Candidate)

`NRVOResult` seems to be small, why not make this a proper function and let it 
return the result?



Comment at: clang/lib/Sema/SemaStmt.cpp:3156
+  // If is decltype(auto) and the original return expression
+  // was parethesized, then we can discard this candidate because
+  // it would deduce to a reference.

parenthesized



Comment at: clang/lib/Sema/SemaStmt.cpp:3157-3159
+  // it would deduce to a reference.
+  if (AT->isDecltypeAuto() && Res.isParenthesized)
+return Res = NRVOResult(), void();

Can't we just do this when we know what it deduces to? It sounds weird to 
handle dependent contexts here because we shouldn't attempt any return value 
initialization then.



Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:1062
+else
+  assert(false && "Unknown 

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

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

The OpenJDK bug was UB in the OpenJDK code: 
https://bugs.openjdk.java.net/browse/JDK-8229258 already fixed in JDK14. (But 
not backported to JDK 11 LTS, which is the version Brooks found an error in 
above.)

They probably need to backport that patch.

My only confusion there is that I had thought GCC had the same optimizations 
around "this" alignment, so it's a bit strange to me that this hadn't been 
causing miscompiles in OpenJDK compiled by GCC, too. (Although, I note the 
OpenJDK build is passing -fno-delete-null-pointer-checks)


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-09 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

It seems like there's a bug with vtable thunks getting the wrong information. 
This appears to be a pre-existing bug, but this change has caused it to start 
actively breaking code.

Test case:

  class Base1 {
  virtual void Foo1();
  };
  
  class Base2 {
  virtual void Foo2();
  };
  
  class alignas(16) Obj : public Base1, public Base2 {
 void Foo1() override;
 void Foo2() override;
 ~Obj();
  };
  
  void Obj::Foo1() {}
  void Obj::Foo2() {}

emits three method definitions:

  define dso_local void @_ZN3Obj4Foo1Ev(%class.Obj* nonnull align 16 
dereferenceable(16) %0) unnamed_addr #0 align 2 !dbg !7 {
  define dso_local void @_ZN3Obj4Foo2Ev(%class.Obj* nonnull align 16 
dereferenceable(16) %0) unnamed_addr #0 align 2 !dbg !25 {
  define dso_local void @_ZThn8_N3Obj4Foo2Ev(%class.Obj* nonnull align 16 
dereferenceable(16) %0) unnamed_addr #2 align 2 !dbg !29 {

(See https://godbolt.org/z/MxhYMe1q7, for now at least)

That third method declaration is bogus -- its argument is _not_ an `Obj*` at 
all! In fact, it's pointing at `Obj + 8` -- at the embedded `Base2` object! As 
such, `align 16` is incorrect, as is `dereferenceable(16)`. The additional 8 
bytes of dereferenceable claim apparently hasn't broken anything noticeable, 
but the alignment claim is causing actual trouble.

As such, I suggest to revert this change, separately commit a fix to that 
underlying bug, and then re-submit this change after that.


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] D98798: Produce warning for performing pointer arithmetic on a null pointer.

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

Respond to review comments:  Do not issue warning for nullptr - nullptr in C++.


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,7 @@
   // 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}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}} 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,17 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+  bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+
+  // Subtracting nullptr or from nullptr should produce
+  // a warning expect nullptr - nullptr is valid in C++ [expr.add]p7
+  if (LHSIsNullPtr && (!getLangOpts().CPlusPlus || !RHSIsNullPtr))
+diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false);
+  if (RHSIsNullPtr && (!getLangOpts().CPlusPlus || !LHSIsNullPtr))
+  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,7 @@
   // 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}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} 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,17 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+  bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+
+  // Subtracting nullptr or from nullptr should produce
+  // a warning expect nullptr - nullptr is valid in C++ [expr.add]p7
+  if (LHSIsNullPtr && (!getLangOpts().CPlusPlus || !RHSIsNullPtr))
+diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false);
+  if (RHSIsNullPtr && (!getLangOpts().CPlusPlus || !LHSIsNullPtr))
+  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] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/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] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added inline comments.



Comment at: clang/test/Sema/pointer-addition.c:34
+  f = (char*)(f - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}} expected-warning 
{{performing pointer arithmetic on a null pointer has undefined behavior}}
 }

jamieschmeiser wrote:
> efriedma wrote:
> > This is what I was afraid would happen.
> > 
> > C++ has a specific carveout in the standard that "null-null" isn't 
> > undefined. C doesn't, but I'm not sure warning is practically useful there.
> > 
> > In any case, printing the same warning twice isn't useful.
> Yes, I see that [expr.add] p 7 says nullptr-nullptr is defined to be 0.  I 
> will suppress the warning for this.
I disagree with the comment that the two warnings are not useful.  While it is 
the same warning, the section of code indicated by each warning is different 
and both need to be corrected to clear the code of warnings.  A single warning 
would likely be more confusing in that a user would see the same warning and 
not notice that a different section of code is indicated after fixing the 
indicated problem.  I would expect the typical response to be the user assuming 
that they had made a mistake and removing the initial fix and fixing the 
second, only to again receive a same warning again with a different section of 
code.  The different code sections indicated would likely be overlooked, 
leading to frustration whereas two warnings clearly indicates there are 2 
problems.


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] D99630: phase 01: add new command line flag to enable UAR in 3 modes (always, [runtime], never).

2021-04-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a reviewer: vitalybuka.
vitalybuka added a comment.

Smaller incremental patches are highly encouraged. But I assume it's WIP.
In the first I'd recommend to try to land clang pieces and leave llvm and 
compiler-rt parts unchanged.

And I can with interactive session next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99630

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


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

2021-04-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@rjmccall, @rsmith, ping...


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

https://reviews.llvm.org/D96033

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


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

2021-04-09 Thread Josh Junon via Phabricator via cfe-commits
Qix- marked an inline comment as not done.
Qix- added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4100-4102
+  // 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.

Qix- wrote:
> aaron.ballman wrote:
> > I think plugins will expect these tokens to be available regardless of 
> > which attribute syntax is used, so you may need to look into also doing 
> > work for GNU and declspec attribute argument lists.
> As far as I understand (and perhaps poorly communicated in the comment) is 
> that plugin-defined attributes will always hit this codepath as opposed to 
> the built-in attribute parsers.
> 
> I could be wrong here, though. Are arbitrary tokens even allowed in 
> GNU/Declspec attributes? I thought it was just the C2x/C++ attributes syntax 
> that allowed non-identifier tokens in the first place.
> 
> Either way, from what I could tell (trying a few different implementations of 
> this change), this is the only place where user-defined attributes are 
> parsed. I certainly could be missing something though.
See my latest top-level comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99861

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


[clang] 3d81653 - [OpenMP51][DOCS] Claimed masked construct and report current patch, NFC.

2021-04-09 Thread via cfe-commits

Author: cchen
Date: 2021-04-09T15:21:13-05:00
New Revision: 3d816537df2c99cdb151a86249da58f4529ec17d

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

LOG: [OpenMP51][DOCS] Claimed masked construct and report current patch, NFC.

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index ab4d4d52c736b..6a4cdf210131e 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -338,7 +338,7 @@ want to help with the implementation.
 
+--+--+--+---+
 | misc extension   | nothing directive 
   | :none:`unclaimed`| 
  |
 
+--+--+--+---+
-| misc extension   | masked construct and related combined 
constructs | :none:`unclaimed`| 
  |
+| misc extension   | masked construct and related combined 
constructs | :part:`worked on`| D5  
  |
 
+--+--+--+---+
 | misc extension   | default(firstprivate) & default(private)  
   | :part:`partial`  | firstprivate done: D75591   
  |
 
+--+--+--+---+



___
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-09 Thread Josh Junon via Phabricator via cfe-commits
Qix- marked 3 inline comments as done.
Qix- added a comment.

So I went back and checked and I remember why I didn't add explicit support for 
GNU/declspec attributes - they actually perform symbol lookups in the 
surrounding scope. I believe there's an issue right now with plugins that 
GNU-style attributes parser assumes that they're being parsed from the Tablegen 
stuff and thus expect the attribute classes to be parameterized as e.g. taking 
arguments or not. Therefore, putting arbitrary tokens in GNU-style and (as far 
as I can tell) declspec-style attributes is expressely not supported by the 
compiler. Also I believe this makes sense, too, because those syntaxes aren't 
spec'd to allow arbitrary tokens like C2x and C++ attributes are.

In fact, in my testing, the GNU-style attributes in plugins can't accept 
arguments whatsoever without getting some sort of compilation error. Maybe I'm 
not using the plugin system correctly, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99861

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


[PATCH] D100225: [Clang][AArch64] Coerce integer return values through an undef vector

2021-04-09 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic created this revision.
Herald added subscribers: danielkiss, kristof.beyls.
asavonic requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If target ABI requires coercion to a larger type, higher bits of the
resulting value are supposed to be undefined. However, before this
patch Clang CG used to generate a `zext` instruction to coerce a value
to a larger type, forcing higher bits to zero.

This is problematic in some cases:

  struct st {
int i;
  };
  struct st foo(i);
  struct st bar(int x) {
return foo(x);
  }

For AArch64 Clang generates the following LLVM IR:

  define i64 @bar(i32 %x) {
%call = call i64 @foo(i32 %0)
%coerce.val.ii = trunc i64 %call to i32
;; ... store to alloca and load back
%coerce.val.ii2 = zext i32 %1 to i64
ret i64 %coerce.val.ii2
  }

Coercion is done with a `trunc` and a `zext`. After optimizations we
get the following:

  define i64 @bar(i32 %x) local_unnamed_addr #0 {
  entry:
%call = tail call i64 @foo(i32 %x)
%coerce.val.ii2 = and i64 %call, 4294967295
ret i64 %coerce.val.ii2
  }

The compiler has to keep semantic of the `zext` instruction, even
though no extension or truncation is required in this case.
This extra `and` instruction also prevents tail call optimization.

In order to keep information about undefined higher bits, the patch
replaces `zext` with a sequence of an `insertelement` and a `bitcast`:

  define i64 @_Z3bari(i32 %x) local_unnamed_addr #0 {
  entry:
%call = tail call i64 @_Z3fooi(i32 %x) #2
%coerce.val.ii = trunc i64 %call to i32
%coerce.val.vec = insertelement <2 x i32> undef, i32 %coerce.val.ii, i8 0
%coerce.val.vec.ii = bitcast <2 x i32> %coerce.val.vec to i64
ret i64 %coerce.val.vec.ii
  }

InstCombiner can then fold this sequence into a nop, and allow tail
call optimization.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100225

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/arm64-arguments.c
  clang/test/CodeGenCXX/trivial_abi.cpp

Index: clang/test/CodeGenCXX/trivial_abi.cpp
===
--- clang/test/CodeGenCXX/trivial_abi.cpp
+++ clang/test/CodeGenCXX/trivial_abi.cpp
@@ -202,7 +202,8 @@
 // CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_TRIVIAL:.*]], align 4
 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_TRIVIAL]], %[[STRUCT_TRIVIAL]]* %[[RETVAL]], i32 0, i32 0
 // CHECK: %[[V0:.*]] = load i32, i32* %[[COERCE_DIVE]], align 4
-// CHECK: %[[COERCE_VAL_II:.*]] = zext i32 %[[V0]] to i64
+// CHECK: %[[COERCE_VAL_VEC:.*]] = insertelement <2 x i32> undef, i32 %[[V0]], i8 0
+// CHECK: %[[COERCE_VAL_II:.*]] = bitcast <2 x i32> %[[COERCE_VAL_VEC]] to i64
 // CHECK: ret i64 %[[COERCE_VAL_II]]
 // CHECK: }
 
Index: clang/test/CodeGen/arm64-arguments.c
===
--- clang/test/CodeGen/arm64-arguments.c
+++ clang/test/CodeGen/arm64-arguments.c
@@ -745,3 +745,63 @@
 // CHECK: call <3 x float> (i32, ...) @test_hva_v3(i32 1, [4 x <4 x float>] {{.*}})
   return test_hva_v3(1, *a);
 }
+
+char ret_coerce1(void) {
+  // CHECK-LABEL: i8 @ret_coerce1
+  // CHECK:  alloca i8
+  // CHECK-NEXT: load i8
+  // CHECK-NEXT: ret i8
+}
+
+short ret_coerce2(void) {
+  // CHECK-LABEL: i16 @ret_coerce2
+  // CHECK:  alloca i16
+  // CHECK-NEXT: load i16
+  // CHECK-NEXT: ret i16
+}
+
+int ret_coerce3(void) {
+  // CHECK-LABEL: i32 @ret_coerce3
+  // CHECK:  alloca i32
+  // CHECK-NEXT: load i32
+  // CHECK-NEXT: ret i32
+}
+
+struct ret_coerce_char {
+  char f0;
+};
+struct ret_coerce_char ret_coerce4(void) {
+  // CHECK-LABEL: i64 @ret_coerce4
+  // CHECK: %[[ALLOCA:.*]] = alloca %struct.ret_coerce_char
+  // CHECK: %[[GEP:.*]] = getelementptr {{.*}} %[[ALLOCA]], i32 0, i32 0
+  // CHECK: %[[LOAD:.*]] = load i8, i8* %[[GEP]]
+  // CHECK: %[[VEC:.*]] = insertelement <8 x i8> undef, i8 %[[LOAD]], i8 0
+  // CHECK: %[[CAST:.*]] = bitcast <8 x i8> %[[VEC]] to i64
+  // CHECK: ret i64 %[[CAST]]
+}
+
+struct ret_coerce_short {
+  short f0;
+};
+struct ret_coerce_short ret_coerce5(void) {
+  // CHECK-LABEL: i64 @ret_coerce5
+  // CHECK: %[[ALLOCA:.*]] = alloca %struct.ret_coerce_short
+  // CHECK: %[[GEP:.*]] = getelementptr {{.*}} %[[ALLOCA]], i32 0, i32 0
+  // CHECK: %[[LOAD:.*]] = load i16, i16* %[[GEP]]
+  // CHECK: %[[VEC:.*]] = insertelement <4 x i16> undef, i16 %[[LOAD]], i8 0
+  // CHECK: %[[CAST:.*]] = bitcast <4 x i16> %[[VEC]] to i64
+  // CHECK: ret i64 %[[CAST]]
+}
+
+struct ret_coerce_int {
+  int f0;
+};
+struct ret_coerce_int ret_coerce6(void) {
+  // CHECK-LABEL: i64 @ret_coerce6
+  // CHECK: %[[ALLOCA:.*]] = alloca %struct.ret_coerce_int
+  // CHECK: %[[GEP:.*]] = getelementptr {{.*}} %[[ALLOCA]], i32 0, i32 0
+  // CHECK: %[[LOAD:.*]] = load i32, i32* %[[GEP]]
+  // CHECK: %[[VEC:.*]] = insertelement <2 x i32> undef, i32 %[[LOAD]], i8 0
+  // CHECK: %[[CAST:.*]] = bitcast <2 

[PATCH] D100197: Enable creation of large response file on z/OS

2021-04-09 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan accepted this revision.
abhina.sreeskantharajan 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/D100197/new/

https://reviews.llvm.org/D100197

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-09 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/include/clang/AST/Type.h:493
+   // Default is a superset of SYCL address spaces.
+   (A == LangAS::Default &&
+(B == LangAS::sycl_private || B == LangAS::sycl_local ||

Anastasia wrote:
> Ok if you allow implicit conversions both ways then this condition should be 
> extended to also contain all named address spaces in `A` and `Default` in 
> `B`. But actually, could you simplify by checking that you have `Default` on 
> either side, so something like 
> 
> 
> ```
> (A == LangAS::Default || B == LangAS::Default)
> ```
> ?
> Ok if you allow implicit conversions both ways then this condition should be 
> extended to also contain all named address spaces in `A` and `Default` in 
> `B`. But actually, could you simplify by checking that you have `Default` on 
> either side, so something like 
> 
> 
> ```
> (A == LangAS::Default || B == LangAS::Default)
> ```
> ?

According to the comment above `isAddressSpaceSupersetOf` function definition.
```
  /// Returns true if address space A is equal to or a superset of B.
```

`(A == LangAS::Default || B == LangAS::Default)` <- this change makes `Default` 
address space a superset of all address spaces including OpenCL, which we were 
trying to avoid with adding SYCL address spaces. Another problem with this code 
is that make `Default` a **sub-set** of named address spaces (like 
`sycl_local`), which is not right.
If I understand it correctly defining "isSupersSetOf" relation is enough for 
the rest of framework to enable conversions. Am I right?



Comment at: clang/lib/AST/ItaniumMangle.cpp:2379
   unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS);
-  if (TargetAS != 0)
+  if (TargetAS != 0 || Context.getASTContext().getLangOpts().SYCLIsDevice)
 ASString = "AS" + llvm::utostr(TargetAS);

Anastasia wrote:
> Any reason not to use OpenCL mangling? If you do then you might be able to 
> link against libraries compiled for OpenCL. Also you will get more stable 
> naming i.e. it would not differ from target to target. 
> Any reason not to use OpenCL mangling? If you do then you might be able to 
> link against libraries compiled for OpenCL. Also you will get more stable 
> naming i.e. it would not differ from target to target. 

I'm not sure I understand your suggestion. Could you elaborate on "OpenCL 
mangling", please?

Let me clarify the problem this change addresses. The test case covering it is 
located in `clang/test/CodeGenSYCL/address-space-parameter-conversions.cpp` 
lines 86-91.

```
template 
void tmpl(T t) {}

int *NoAS;
__attribute__((opencl_private)) int *PRIV;

tmpl(PRIV);
// CHECK-DAG: [[PRIV_LOAD5:%[a-zA-Z0-9]+]] = load i32*, i32* addrspace(4)* 
[[PRIV]].ascast
// CHECK-DAG: call spir_func void [[PRIV_TMPL:@[a-zA-Z0-9_]+]](i32* 
[[PRIV_LOAD5]])
tmpl(NoAS);
// CHECK-DAG: [[NoAS_LOAD5:%[a-zA-Z0-9]+]] = load i32 addrspace(4)*, i32 
addrspace(4)* addrspace(4)* [[NoAS]].ascast
// CHECK-DAG: call spir_func void [[GEN_TMPL:@[a-zA-Z0-9_]+]](i32 addrspace(4)* 
[[NoAS_LOAD5]])
```
Clang has separate code paths for mangling types w/ and w/o address space 
attributes (i.e. using `Default` address space).

Address space is not mangled if there is no AS attribute (`Default`) or if 
address space attribute is maps to `0` target address space. SPIR target maps 
`*_private` address space to `0`, which causes name conflict for the example 
above.

This change for SYCL compiler enables mangling for non-default address space 
attributes regardless of their mapping to target address space.



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:74
 Local,// cuda_shared
+Global,   // sycl_global
+Local,// sycl_local

Anastasia wrote:
> Would this map ever be used for SYCL? If not it would be better to add a 
> comment about it and/or perhaps even just use dummy values.
I can't find an example of how to do this.
CUDA address spaces use valid values and I wasn't able to find similar comments.

Where do you think we can put a comment?



Comment at: clang/lib/Basic/Targets/SPIR.h:36
 0, // cuda_shared
+1, // sycl_global
+3, // sycl_local

Anastasia wrote:
> The same here. This map will never work for SYCL so let's just use dummy 
> values like for CUDA and add a comment explaining this.
I've set 0 for SYCL values.



Comment at: clang/lib/Basic/Targets/SPIR.h:71
 LongWidth = LongAlign = 64;
-AddrSpaceMap = 
+AddrSpaceMap = Triple.getEnvironment() == llvm::Triple::SYCLDevice
+   ? 

Anastasia wrote:
> Ok so what I understand is that the only reason you need a separate map is 
> that the semantics of `Default` is different for SYCL than for C/C++.
> 
> //i.e. in SYCL (i.e. inherited from CUDA) it is a virtual/placeholder address 
> space that can 

[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-09 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 336543.
bader marked 32 inline comments as done.
bader added a comment.

Applied code review suggestions.

Rebased on ToT and updated commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenSYCL/address-space-cond-op.cpp
  clang/test/CodeGenSYCL/address-space-conversions.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/CodeGenSYCL/address-space-of-returns.cpp
  clang/test/CodeGenSYCL/convergent.cpp
  clang/test/SemaSYCL/address-space-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388593)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x71>();
+  correct<0x7FFFED>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-conversions.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/address-space-conversions.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s
+
+void bar(int ) {}
+void bar2(int ) {}
+void bar(__attribute__((opencl_private)) int ) {}
+void foo(int *Data) {}
+void foo2(int *Data) {}
+void foo(__attribute__((opencl_private)) int *Data) {}
+
+template 
+void tmpl(T *t) {}
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  __attribute__((opencl_private)) int *PRIV;
+  __attribute__((opencl_local)) int *LOC;
+  int *NoAS;
+
+  GLOB = PRIV; // expected-error {{assigning '__private int *' to '__global int *' changes address space of pointer}}
+  GLOB = LOC; // expected-error {{assigning '__local int *' to '__global int *' changes address space of pointer}}
+  PRIV = static_cast<__attribute__((opencl_private)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__private int *' is not allowed}}
+  PRIV = static_cast<__attribute__((opencl_private)) int *>(LOC); // expected-error {{static_cast from '__local int *' to '__private int *' is not allowed}}
+  NoAS = GLOB + PRIV; // expected-error {{invalid operands to binary expression ('__global int *' and '__private int *')}}
+  NoAS = GLOB + LOC; // expected-error {{invalid operands to binary expression ('__global int *' and '__local int *')}}
+  NoAS += GLOB; // expected-error {{invalid operands to binary expression ('int *' and '__global int *')}}
+
+  bar(*GLOB);
+  bar2(*GLOB);
+
+  bar(*PRIV);
+  bar2(*PRIV);
+
+  bar(*NoAS);
+  bar2(*NoAS);
+
+  bar(*LOC);
+  bar2(*LOC);
+
+  foo(GLOB);
+  foo2(GLOB);
+  foo(PRIV);
+  foo2(PRIV);
+  foo(NoAS);
+  foo2(NoAS);
+  foo(LOC);
+  foo2(LOC);
+
+  tmpl(GLOB);
+  tmpl(PRIV);
+  tmpl(NoAS);
+  tmpl(LOC);
+
+  (void)static_cast(GLOB);
+  (void)static_cast(GLOB);
+  int *i = GLOB;
+  void *v = GLOB;
+  (void)i;
+  (void)v;
+}
Index: clang/test/CodeGenSYCL/convergent.cpp
===
--- clang/test/CodeGenSYCL/convergent.cpp
+++ clang/test/CodeGenSYCL/convergent.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
+// RUN:  -triple spir64 -emit-llvm %s -o - | \
 // RUN:   FileCheck %s
 
 // CHECK-DAG: Function Attrs:
Index: clang/test/CodeGenSYCL/address-space-of-returns.cpp
===
--- /dev/null
+++ clang/test/CodeGenSYCL/address-space-of-returns.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -disable-llvm-passes -emit-llvm -x c++ 

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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:697-699
+  } else if (VD && dyn_cast(VD->getType())) {
+// Call is: obj->*method_ptr or obj.*method_ptr
+const auto *MPT = VD->getType()->castAs();

I'm not certain if I should take a shower after writing that code or not, but 
it's one potential way not to perform the cast twice.

If that code is too odious for others, we should at least change the 
`dyn_cast<>` in the `else if` to be an `isa<>`.


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


[clang] 1a43fd2 - [OpenMP51] Initial support for masked directive and filter clause

2021-04-09 Thread via cfe-commits

Author: cchen
Date: 2021-04-09T14:00:36-05:00
New Revision: 1a43fd27691c6ae5c3d725ca7c6f4fd19357f4b8

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

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

Adds basic parsing/sema/serialization support for the #pragma omp masked
directive.

Reviewed By: ABataev

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

Added: 
clang/test/OpenMP/masked_ast_print.cpp
clang/test/OpenMP/masked_messages.cpp

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 696e271a72313..87592156dd6b8 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2584,7 +2584,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPDispatchDirective = 291,
 
-  CXCursor_LastStmt = CXCursor_OMPDispatchDirective,
+  /** OpenMP masked directive.
+   */
+  CXCursor_OMPMaskedDirective = 292,
+
+  CXCursor_LastStmt = CXCursor_OMPMaskedDirective,
 
   /**
* Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 11eb453a02060..e484a89bc84a8 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -8225,6 +8225,77 @@ class OMPAffinityClause final
   }
 };
 
+/// This represents 'filter' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp masked filter(tid)
+/// \endcode
+/// In this example directive '#pragma omp masked' has 'filter' clause with
+/// thread id.
+class OMPFilterClause final : public OMPClause, public OMPClauseWithPreInit {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Express of the 'filter' clause.
+  Stmt *ThreadID = nullptr;
+
+  /// Sets the thread identifier.
+  void setThreadID(Expr *TID) { ThreadID = TID; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'filter' clause with thread-id \a ThreadID.
+  ///
+  /// \param ThreadID Thread identifier.
+  /// \param HelperE Helper expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPFilterClause(Expr *ThreadID, Stmt *HelperE,
+  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
+  SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_filter, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadID(ThreadID) {
+setPreInitStmt(HelperE, CaptureRegion);
+  }
+
+  /// Build an empty clause.
+  OMPFilterClause()
+  : OMPClause(llvm::omp::OMPC_filter, SourceLocation(), SourceLocation()),
+OMPClauseWithPreInit(this) {}
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Return thread identifier.
+  Expr *getThreadID() { return cast(ThreadID); }
+
+  /// Return thread identifier.
+  Expr *getThreadID() const { return cast(ThreadID); }
+
+  child_range children() { return child_range(,  + 1); }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == 

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

2021-04-09 Thread Chi Chun Chen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a43fd27691c: [OpenMP51] Initial support for masked 
directive and filter clause (authored by cchen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D5

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/masked_ast_print.cpp
  clang/test/OpenMP/masked_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -331,6 +331,10 @@
 }
 def OMPC_Inbranch : Clause<"inbranch"> {}
 def OMPC_Notinbranch : Clause<"notinbranch"> {}
+def OMPC_Filter : Clause<"filter"> {
+  let clangClass = "OMPFilterClause";
+  let flangClass = "ScalarIntExpr";
+}
 
 //===--===//
 // Definition of OpenMP directives
@@ -1675,6 +1679,11 @@
 VersionedClause
   ];
 }
+def OMP_masked : Directive<"masked"> {
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_Unknown : Directive<"unknown"> {
   let isDefault = true;
 }
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -772,6 +772,7 @@
 CHECK_SIMPLE_CLAUSE(Use, OMPC_use)
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
 CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
+CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -813,6 +813,9 @@
   case Stmt::OMPDispatchDirectiveClass:
 K = CXCursor_OMPDispatchDirective;
 break;
+  case Stmt::OMPMaskedDirectiveClass:
+K = CXCursor_OMPMaskedDirective;
+break;
   case Stmt::BuiltinBitCastExprClass:
 K = CXCursor_BuiltinBitCastExpr;
   }
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2299,6 +2299,11 @@
   Visitor->AddStmt(C->getCondition());
 }
 
+void OMPClauseEnqueue::VisitOMPFilterClause(const OMPFilterClause *C) {
+  VisitOMPClauseWithPreInit(C);
+  Visitor->AddStmt(C->getThreadID());
+}
+
 void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
 const OMPUnifiedAddressClause *) {}
 
@@ -5678,6 +5683,8 @@
 return cxstring::createRef("OMPInteropDirective");
   case CXCursor_OMPDispatchDirective:
 return cxstring::createRef("OMPDispatchDirective");
+  case CXCursor_OMPMaskedDirective:
+return cxstring::createRef("OMPMaskedDirective");
   case CXCursor_OverloadCandidate:
 return cxstring::createRef("OverloadCandidate");
   case CXCursor_TypeAliasTemplateDecl:
Index: clang/test/OpenMP/masked_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/masked_messages.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+
+void xxx(int argc) {
+  int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+#pragma omp masked
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+void yyy(int argc) {
+  int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+#pragma omp masked filter(1)
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+int foo();
+
+int main() {
+  #pragma omp masked
+  ;
+  #pragma omp masked filter(1) filter(2) // expected-error 

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

2021-04-09 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen updated this revision to Diff 336537.
cchen added a comment.

Fix lit-test failure for dispatch_ast_print and rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D5

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/masked_ast_print.cpp
  clang/test/OpenMP/masked_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -331,6 +331,10 @@
 }
 def OMPC_Inbranch : Clause<"inbranch"> {}
 def OMPC_Notinbranch : Clause<"notinbranch"> {}
+def OMPC_Filter : Clause<"filter"> {
+  let clangClass = "OMPFilterClause";
+  let flangClass = "ScalarIntExpr";
+}
 
 //===--===//
 // Definition of OpenMP directives
@@ -1675,6 +1679,11 @@
 VersionedClause
   ];
 }
+def OMP_masked : Directive<"masked"> {
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_Unknown : Directive<"unknown"> {
   let isDefault = true;
 }
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -772,6 +772,7 @@
 CHECK_SIMPLE_CLAUSE(Use, OMPC_use)
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
 CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
+CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -813,6 +813,9 @@
   case Stmt::OMPDispatchDirectiveClass:
 K = CXCursor_OMPDispatchDirective;
 break;
+  case Stmt::OMPMaskedDirectiveClass:
+K = CXCursor_OMPMaskedDirective;
+break;
   case Stmt::BuiltinBitCastExprClass:
 K = CXCursor_BuiltinBitCastExpr;
   }
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2299,6 +2299,11 @@
   Visitor->AddStmt(C->getCondition());
 }
 
+void OMPClauseEnqueue::VisitOMPFilterClause(const OMPFilterClause *C) {
+  VisitOMPClauseWithPreInit(C);
+  Visitor->AddStmt(C->getThreadID());
+}
+
 void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
 const OMPUnifiedAddressClause *) {}
 
@@ -5678,6 +5683,8 @@
 return cxstring::createRef("OMPInteropDirective");
   case CXCursor_OMPDispatchDirective:
 return cxstring::createRef("OMPDispatchDirective");
+  case CXCursor_OMPMaskedDirective:
+return cxstring::createRef("OMPMaskedDirective");
   case CXCursor_OverloadCandidate:
 return cxstring::createRef("OverloadCandidate");
   case CXCursor_TypeAliasTemplateDecl:
Index: clang/test/OpenMP/masked_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/masked_messages.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+
+void xxx(int argc) {
+  int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+#pragma omp masked
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+void yyy(int argc) {
+  int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+#pragma omp masked filter(1)
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+int foo();
+
+int main() {
+  #pragma omp masked
+  ;
+  #pragma omp masked filter(1) filter(2) // expected-error {{directive '#pragma omp masked' cannot contain more than one 'filter' clause}}
+  ;
+  int x,y,z;
+  #pragma omp masked filter(x) 

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

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

In D99790#2680366 , @brooksmoses wrote:

> In D99790#2678674 , @lebedev.ri 
> wrote:
>
>> In D99790#2678384 , @brooksmoses 
>> wrote:
>>
>>> In any case, thanks for the quick reply, and I'll figure out a small 
>>> reproducer if we find something that isn't UB.
>>
>> Nono, you misunderstand, i want the samples *with* UB.
>> I will then revert this, and add UBSan check to catch that UB first.
>
> Oh!  Okay, will do. Do you still want the samples even if UBSan catches them?

I'm interested in the cases that *aren't* currently being caught by UBSan, or 
are caught too late.

> Meanwhile, would you be open to providing a gating flag to turn this off, so 
> we can roll it out generally while turning it off for the specific things 
> that have issues until we can fix them?  So far, what we're finding is caught 
> by UBSan but not very trivial to fix.




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] D69000: [clang-tidy] new check: modernize-deprecated-iterator-base

2021-04-09 Thread Nikita Kniazev via Phabricator via cfe-commits
nick updated this revision to Diff 336533.
nick edited the summary of this revision.
nick added reviewers: njames93, steveire.
nick added a comment.

Rebased. Now using native `cxxBaseSpecifier` and `hasDirectBase`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69000

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/DeprecatedIteratorBaseCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedIteratorBaseCheck.h
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-deprecated-iterator-base.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-iterator-base.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-iterator-base.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-iterator-base.cpp
@@ -0,0 +1,321 @@
+// RUN: %check_clang_tidy %s modernize-deprecated-iterator-base %t 
+
+namespace std {
+using ptrdiff_t = int;
+struct input_iterator_tag;
+template 
+struct iterator {
+  using iterator_category = C;
+  using value_type= T;
+  using difference_type   = D;
+  using pointer   = P;
+  using reference = R;
+};
+}
+
+
+using iterator_alias = std::iterator;
+typedef std::iterator iterator_typedef;
+
+
+// Sugar
+
+// CHECK-FIXES: struct from_alias {
+// CHECK-MESSAGES: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct from_alias: iterator_alias {};
+
+// CHECK-FIXES: struct from_typedef {
+// CHECK-MESSAGES: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct from_typedef: iterator_typedef {};
+
+
+// False-positive
+
+// CHECK-FIXES: struct indirect_base: from_alias {};
+// CHECK-MESSAGES-NOT: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct indirect_base: from_alias {};
+
+
+// Unsupported
+
+// CHECK-FIXES: class skipif_non_public_inheritance: iterator_alias {};
+// CHECK-MESSAGES: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+class skipif_non_public_inheritance: iterator_alias {};
+
+
+// Base removal
+
+struct A {};
+struct B {};
+
+struct collection {
+  template 
+  struct iterator;
+};
+
+// CHECK-FIXES: template <> struct collection::iterator<> {
+// CHECK-MESSAGES: :[[@LINE+1]]:45: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+template <> struct collection::iterator<> : iterator_alias {};
+// CHECK-FIXES: template <> struct collection::iterator : A {
+// CHECK-MESSAGES: :[[@LINE+1]]:49: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+template <> struct collection::iterator : A, iterator_alias {};
+// CHECK-FIXES: template <> struct collection::iterator : B {
+// CHECK-MESSAGES: :[[@LINE+1]]:46: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+template <> struct collection::iterator : iterator_alias, B {};
+// CHECK-FIXES: template <> struct collection::iterator : A, B {
+// CHECK-MESSAGES: :[[@LINE+1]]:52: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+template <> struct collection::iterator : A, iterator_alias, B {};
+
+// CHECK-FIXES: struct do_not_strip_final final {
+// CHECK-MESSAGES: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct do_not_strip_final final : iterator_alias {};
+
+// CHECK-FIXES: struct iteratorZ // iterator_alias
+// CHECK-FIXES: {
+// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct iteratorZ   // iteratorZ
+  : iterator_alias // iterator_alias
+{};
+// CHECK-FIXES: struct iteratorA   // iteratorA
+// CHECK-FIXES:   : A // iterator_alias
+// CHECK-FIXES: {
+// CHECK-MESSAGES: :[[@LINE+3]]:5: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct iteratorA   // iteratorA
+  : A  // A
+  , iterator_alias // iterator_alias
+{};
+// CHECK-FIXES: struct iteratorB   // iteratorB
+// CHECK-FIXES:   : B  // B
+// CHECK-FIXES: {
+// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: inheriting from 'std::iterator' is deprecated [modernize-deprecated-iterator-base]
+struct iteratorB   // iteratorB
+  : iterator_alias // iterator_alias
+  , B  // B
+{};
+// CHECK-FIXES: struct iteratorAB  // iteratorAB
+// CHECK-FIXES:   : A  // A
+// CHECK-FIXES:   , B  // B
+// CHECK-FIXES: {
+// CHECK-MESSAGES: :[[@LINE+3]]:5: warning: 

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

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

In D99790#2678674 , @lebedev.ri wrote:

> In D99790#2678384 , @brooksmoses 
> wrote:
>
>> In any case, thanks for the quick reply, and I'll figure out a small 
>> reproducer if we find something that isn't UB.
>
> Nono, you misunderstand, i want the samples *with* UB.
> I will then revert this, and add UBSan check to catch that UB first.

Oh!  Okay, will do.  Do you still want the samples even if UBSan catches them?

Meanwhile, would you be open to providing a gating flag to turn this off, so we 
can roll it out generally while turning it off for the specific things that 
have issues until we can fix them?  So far, what we're finding is caught by 
UBSan but not very trivial to fix.


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] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-04-09 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added inline comments.



Comment at: clang/test/Sema/pointer-addition.c:34
+  f = (char*)(f - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}} expected-warning 
{{performing pointer arithmetic on a null pointer has undefined behavior}}
 }

efriedma wrote:
> This is what I was afraid would happen.
> 
> C++ has a specific carveout in the standard that "null-null" isn't undefined. 
> C doesn't, but I'm not sure warning is practically useful there.
> 
> In any case, printing the same warning twice isn't useful.
Yes, I see that [expr.add] p 7 says nullptr-nullptr is defined to be 0.  I will 
suppress the warning for this.


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] D99861: [Clang] Record tokens in attribute arguments for user-defined C++/C2x attributes

2021-04-09 Thread Josh Junon via Phabricator via cfe-commits
Qix- planned changes to this revision.
Qix- marked 5 inline comments as done.
Qix- added inline comments.



Comment at: clang/examples/PrintAttributeTokens/CMakeLists.txt:3-10
+if( NOT MSVC ) # MSVC mangles symbols differently, and
+   # PrintAttributeTokens.export contains C++ symbols.
+  if( NOT LLVM_REQUIRES_RTTI )
+if( NOT LLVM_REQUIRES_EH )
+  set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/PrintAttributeTokens.exports)
+endif()
+  endif()

aaron.ballman wrote:
> I'm not certain what this is actually doing -- the .exports file is empty 
> (and no other plugin has this sort of .exports file thing). Is this needed?
Most likely not - the directory was copied from the PrintFunctionNames 
directory, which also has an empty exports file. I'm not completely familiar 
with the LLVM build configs so I figured it was required. Happy to remove it if 
need be :)



Comment at: clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp:37
+   const ParsedAttr ) const override {
+llvm::errs() << "PrintAttributeTokens ---\n";
+D->dump(llvm::errs());

aaron.ballman wrote:
> Should probably use `llvm::outs()` instead (here and elsewhere in the plugin).
Sure thing, though should PrintFunctionNames be updated as well? Mostly copied 
the conventions over from that.



Comment at: clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp:48-50
+if (tokens[i].isLiteral()) {
+  llvm::errs() << "\t=" << tokens[i].getLiteralData();
+}

aaron.ballman wrote:
> It'd probably be handy to also print identifier tokens.
Yeah I caught that the other day too, thanks for reminding me.



Comment at: clang/include/clang/Sema/ParsedAttr.h:284
+  Token *getTokensBuffer() { return getTrailingObjects(); }
+  Token const *getTokensBuffer() const { return getTrailingObjects(); }
+

aaron.ballman wrote:
> 
Agreed; should 279 be updated too?



Comment at: clang/include/clang/Sema/ParsedAttr.h:486
+  const Token *getTokens() const {
+assert(NumTokens > 0 && "No Tokens to retrieve!");
+return getTokensBuffer();

aaron.ballman wrote:
> I think it'd be reasonable to return `nullptr` in this case, WDYT?
Sure, that's fine. I was trying to think why I did the assertion but nullptr 
seems fine too.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4100-4102
+  // 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.

aaron.ballman wrote:
> I think plugins will expect these tokens to be available regardless of which 
> attribute syntax is used, so you may need to look into also doing work for 
> GNU and declspec attribute argument lists.
As far as I understand (and perhaps poorly communicated in the comment) is that 
plugin-defined attributes will always hit this codepath as opposed to the 
built-in attribute parsers.

I could be wrong here, though. Are arbitrary tokens even allowed in 
GNU/Declspec attributes? I thought it was just the C2x/C++ attributes syntax 
that allowed non-identifier tokens in the first place.

Either way, from what I could tell (trying a few different implementations of 
this change), this is the only place where user-defined attributes are parsed. 
I certainly could be missing something though.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4121-4122
+// 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);

aaron.ballman wrote:
> To be clear, we should have at least *two* tokens, right? One for the left 
> paren and one for the right?
This was confusing for me too at first.

By 4112, the left paren token has already been emitted by the lexer; 
`ConsumeParen` advances to the next token *after* the left-paren; _that_ token 
then becomes the first in the recording session.

Further, `SkipUntil(tok::r_paren)` checks if the current token is an `r_paren`, 
and if not, advances and then starts over. It doesn't advance _then_ check.

It's the presence of the left paren that advances us to this stage of the 
parsing in the first place and thus is emitted before our recording session 
starts. An empty argument list (`[[some_attr()]]`) thus only has an `r_paren` 
token emitted to the recording session, which is then ignored.

This is the existing design of the lexer it seems - I wasn't expecting the 
"reversed" order of operations, and the names of the lexer methods didn't help, 
either :)



Comment at: clang/test/Frontend/plugin-print-attr-tokens.cpp:9-12
+[[plugin::print_tokens("a string")]] void fn1b() {}

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

2021-04-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:10724
+  // Subtracting from a null pointer should produce a warning.
+  if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull))

IgnoreParenCasts() seems a little weird here; e.g. this code thinks 
`(char*)(char)256` isn't null?  Not sure how much it practically matters, 
though, given this is just a warning.



Comment at: clang/test/Sema/pointer-addition.c:34
+  f = (char*)(f - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}} expected-warning 
{{performing pointer arithmetic on a null pointer has undefined behavior}}
 }

This is what I was afraid would happen.

C++ has a specific carveout in the standard that "null-null" isn't undefined. C 
doesn't, but I'm not sure warning is practically useful there.

In any case, printing the same warning twice isn't useful.


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] D100054: Handle flags such as -m32 when computing the prefix for programs/runtime libs

2021-04-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1176-1210
+  // If command line flags such as -m32, etc. changed parts of the triple that
+  // are not just changes to normalization, we also need to update the raw
+  // triple string that is used to find tools. This ensures e.g. that clang 
-m32
+  // searches for i386-*-ld instead of x86_64-*-ld when linking (and also uses
+  // the triple-prefixed library paths).
+  EffectiveTargetTriple =
+  computeTargetTriple(*this, RawTargetTriple, *UArgs, "");

I think this should be handled by each toolchain. For example `Linux` toolchain 
already [has 
getMultiarchTriple](https://github.com/llvm/llvm-project/blob/16fe741c69429235210c03c46420f8fa6aece4a1/clang/lib/Driver/ToolChains/Linux.cpp#L40)
 which takes into account target handling on various existing platforms like 
Debian.

What I've been thinking of doing is to move that method to the `ToolChain` 
class as virtual so it could be overriden and customized by each toolchain, and 
then use it in 
[getRuntimePath](https://github.com/llvm/llvm-project/blob/16fe741c69429235210c03c46420f8fa6aece4a1/clang/lib/Driver/ToolChain.cpp#L485).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100054

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


[PATCH] D98902: [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system has CUDA

2021-04-09 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Ping...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98902

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


[clang] dc4abca - Handle alloc_size attribute on function pointers

2021-04-09 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2021-04-09T18:49:38+01:00
New Revision: dc4abca7662b74467c2b6bceb7e8b046ae04b8a0

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

LOG: Handle alloc_size attribute on function pointers

I have been trying to statically find and analyze all calls to heap
allocation functions to determine how many of them use sizes known at
compile time vs only at runtime. While doing so I saw that quite a few
projects use replaceable function pointers for heap allocation and noticed
that clang was not able to annotate functions pointers with alloc_size.
I have changed the Sema checks to allow alloc_size on all function pointers
and typedefs for function pointers now and added checks that these
attributes are propagated to the LLVM IR correctly.

With this patch we can also compute __builtin_object_size() for calls to
allocation function pointers with the alloc_size attribute.

Reviewed By: aaron.ballman, erik.pilkington
Differential Revision: https://reviews.llvm.org/D55212

Added: 
clang/test/CodeGen/alloc-size-fnptr.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/alloc-size.c
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/Sema/alloc-size.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index d9c2422536d0c..400dfe84b7d98 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1308,7 +1308,7 @@ def EmptyBases : InheritableAttr, 
TargetSpecificAttr {
 
 def AllocSize : InheritableAttr {
   let Spellings = [GCC<"alloc_size">];
-  let Subjects = SubjectList<[Function]>;
+  let Subjects = SubjectList<[HasFunctionProto]>;
   let Args = [ParamIdxArgument<"ElemSizeParam">,
   ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
   let TemplateDependent = 1;

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fe6573b8bd2c1..5a68b1c3cad17 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -108,8 +108,11 @@ namespace {
 
   /// Given a CallExpr, try to get the alloc_size attribute. May return null.
   static const AllocSizeAttr *getAllocSizeAttr(const CallExpr *CE) {
-const FunctionDecl *Callee = CE->getDirectCallee();
-return Callee ? Callee->getAttr() : nullptr;
+if (const FunctionDecl *DirectCallee = CE->getDirectCallee())
+  return DirectCallee->getAttr();
+if (const Decl *IndirectCallee = CE->getCalleeDecl())
+  return IndirectCallee->getAttr();
+return nullptr;
   }
 
   /// Attempts to unwrap a CallExpr (with an alloc_size attribute) from an 
Expr.

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dbc217640fd56..17d63bf1f1364 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6831,6 +6831,16 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
   return true;
 }
 
+template 
+static void copyAttrFromTypedefToDecl(Sema , Decl *D, const TypedefType *TT) 
{
+  const TypedefNameDecl *TND = TT->getDecl();
+  if (const auto *Attribute = TND->getAttr()) {
+AttrTy *Clone = Attribute->clone(S.Context);
+Clone->setInherited(true);
+D->addAttr(Clone);
+  }
+}
+
 NamedDecl *Sema::ActOnVariableDeclarator(
 Scope *S, Declarator , DeclContext *DC, TypeSourceInfo *TInfo,
 LookupResult , MultiTemplateParamsArg TemplateParamLists,
@@ -7253,6 +7263,14 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   // Handle attributes prior to checking for duplicates in MergeVarDecl
   ProcessDeclAttributes(S, NewVD, D);
 
+  // FIXME: This is probably the wrong location to be doing this and we should
+  // probably be doing this for more attributes (especially for function
+  // pointer attributes such as format, warn_unused_result, etc.). Ideally
+  // the code to copy attributes would be generated by TableGen.
+  if (R->isFunctionPointerType())
+if (const auto *TT = R->getAs())
+  copyAttrFromTypedefToDecl(*this, NewVD, TT);
+
   if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
   getLangOpts().SYCLIsDevice) {
 if (EmitTLSUnsupportedError &&

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 550fa503bf569..43ca644ed21ed 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -788,20 +788,20 @@ static void handleAssertExclusiveLockAttr(Sema , Decl 
*D,
 ///
 /// AttrArgNo is used to actually retrieve the argument, so it's base-0.
 template 
-static bool checkParamIsIntegerType(Sema , const FunctionDecl *FD,
-const AttrInfo , unsigned AttrArgNo) 

[PATCH] D55212: Handle alloc_size attribute on function pointers

2021-04-09 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc4abca7662b: Handle alloc_size attribute on function 
pointers (authored by arichardson).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D55212?vs=177519=336519#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D55212

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/alloc-size-fnptr.c
  clang/test/CodeGen/alloc-size.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/alloc-size.c

Index: clang/test/Sema/alloc-size.c
===
--- clang/test/Sema/alloc-size.c
+++ clang/test/Sema/alloc-size.c
@@ -14,7 +14,7 @@
 
 int fail9(int a) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to return values that are pointers}}
 
-int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}}
+int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to non-K functions}}
 
 void *fail11(void *a) __attribute__((alloc_size(1))); //expected-error{{'alloc_size' attribute argument may only refer to a function parameter of integer type}}
 
@@ -22,4 +22,39 @@
 void *fail12(int a) __attribute__((alloc_size(1, "abc"))); //expected-error{{'alloc_size' attribute requires parameter 2 to be an integer constant}}
 void *fail13(int a) __attribute__((alloc_size(1U<<31))); //expected-error{{integer constant expression evaluates to value 2147483648 that cannot be represented in a 32-bit signed integer type}}
 
-int (*PR31453)(int) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}}
+void *(*PR31453)(int)__attribute__((alloc_size(1)));
+
+void *KR() __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to non-K functions}}
+
+// Applying alloc_size to function pointers should work:
+void *(__attribute__((alloc_size(1))) * func_ptr1)(int);
+void *(__attribute__((alloc_size(1, 2))) func_ptr2)(int, int);
+
+// TODO: according to GCC documentation the following should actually be the type
+// “pointer to pointer to alloc_size attributed function returning void*” and should
+// therefore be supported
+void *(__attribute__((alloc_size(1))) **ptr_to_func_ptr)(int); // expected-warning{{'alloc_size' attribute only applies to non-K functions}}
+// The following definitions apply the attribute to the pointer to the function pointer which should not be possible
+void *(*__attribute__((alloc_size(1))) * ptr_to_func_ptr2)(int); // expected-warning{{'alloc_size' attribute only applies to non-K functions}}
+void *(**__attribute__((alloc_size(1))) ptr_to_func_ptr2)(int);  // expected-warning{{'alloc_size' attribute only applies to non-K functions}}
+
+// It should also work for typedefs:
+typedef void *(__attribute__((alloc_size(1))) allocator_function_typdef)(int);
+typedef void *(__attribute__((alloc_size(1, 2))) * allocator_function_typdef2)(int, int);
+void *(__attribute__((alloc_size(1, 2))) * allocator_function_typdef3)(int, int);
+// This typedef applies the alloc_size to the pointer to the function pointer and should not be allowed
+void *(**__attribute__((alloc_size(1, 2))) * allocator_function_typdef4)(int, int); // expected-warning{{'alloc_size' attribute only applies to non-K functions}}
+
+// We should not be warning when assigning function pointers with and without the alloc size attribute
+// since it doesn't change the type of the function
+typedef void *(__attribute__((alloc_size(1))) * my_malloc_fn_pointer_type)(int);
+typedef void *(*my_other_malloc_fn_pointer_type)(int);
+void *fn(int i);
+__attribute__((alloc_size(1))) void *fn2(int i);
+
+int main() {
+  my_malloc_fn_pointer_type f = fn;
+  my_other_malloc_fn_pointer_type f2 = fn;
+  my_malloc_fn_pointer_type f3 = fn2;
+  my_other_malloc_fn_pointer_type f4 = fn2;
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -12,7 +12,6 @@
 // CHECK-NEXT: AcquireHandle (SubjectMatchRule_function, SubjectMatchRule_type_alias, SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: Alias (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: AlignValue (SubjectMatchRule_variable, SubjectMatchRule_type_alias)
-// CHECK-NEXT: AllocSize (SubjectMatchRule_function)
 // CHECK-NEXT: AlwaysDestroy (SubjectMatchRule_variable)
 // CHECK-NEXT: AlwaysInline (SubjectMatchRule_function)
 // CHECK-NEXT: Annotate ()
Index: 

[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-04-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@vsavchenko
Thank you for a proposed solution. It looks much easier to understand and 
maintain. Great! I will take it into account.

> Well, that is a nice exercise for "two pointer" problems, but can we please 
> talk about the actual use case for it?

I'm currently working on **integral cast between ranges**. Consider the range 
of `int` which is casted to `char`. You've got some ranges of `int` which 
obviously should be corespondently represented as some other ranges of `char`.
Some examples:

  int [257, 259]  -> char [1, 3]
  int [510, 513]  -> char [-2, 1]
  int [42, 1000]  -> char [-128, 127]
  int [257, 259] U [2049, 2051]  -> char [1,3] // Here we need `unite` logic to 
get a casted range because both original ranges lay on the same area after 
trancation.


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

https://reviews.llvm.org/D99797

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


[PATCH] D70094: [clang-tidy] new altera ID dependent backward branch check

2021-04-09 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp:1
+//===--- IdDependentBackwardBranchCheck.cpp - clang-tidy *- C++ 
-*-===//
+//

`*- C++ -*` is not necessary for `.cpp` files.


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

https://reviews.llvm.org/D70094

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


[PATCH] D70094: [clang-tidy] new altera ID dependent backward branch check

2021-04-09 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 336512.
ffrankies added a comment.

Addressed comments by @Eugene.Zelenko and the automated

- Fixed header comments and include guard style
- Removed unnecessary comments in `getLoopType()`
- changed `IDDependencyRecord() {}` to `IDDependencyRecord() = default;`


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

https://reviews.llvm.org/D70094

Files:
  clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
  clang-tools-extra/clang-tidy/altera/CMakeLists.txt
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/altera-id-dependent-backward-branch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -0,0 +1,86 @@
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+
+typedef struct ExampleStruct {
+  int IDDepField;
+} ExampleStruct;
+
+void error() {
+  //  Conditional Expressions 
+  int accumulator = 0;
+  for (int i = 0; i < get_local_id(0); i++) {
+// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  int j = 0;
+  while (j < get_local_id(0)) {
+// CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < get_local_id(0));
+  // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to ID function call and may cause performance degradation [altera-id-dependent-backward-branch]
+
+  //  Assignments 
+  int ThreadID = get_local_id(0);
+
+  while (j < ThreadID) {
+// CHECK-NOTES: :[[@LINE-3]]:3: note: assignment of ID-dependent variable ThreadID
+// CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  ExampleStruct Example;
+  Example.IDDepField = get_local_id(0);
+
+  //  Inferred Assignments 
+  int ThreadID2 = ThreadID * get_local_size(0);
+
+  int ThreadID3 = Example.IDDepField; // OK: not used in any loops
+
+  ExampleStruct UnusedStruct = {
+  ThreadID * 2 // OK: not used in any loops
+  };
+
+  for (int i = 0; i < ThreadID2; i++) {
+// CHECK-NOTES: :[[@LINE-9]]:3: note: inferred assignment of ID-dependent value from ID-dependent variable ThreadID
+// CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is ID-dependent due to variable reference to 'ThreadID2' and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < ThreadID);
+  // CHECK-NOTES: :[[@LINE-29]]:3: note: assignment of ID-dependent variable ThreadID
+  // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+
+  for (int i = 0; i < Example.IDDepField; i++) {
+// CHECK-NOTES: :[[@LINE-24]]:3: note: assignment of ID-dependent field IDDepField
+// CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  while (j < Example.IDDepField) {
+// CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent field IDDepField
+// CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < Example.IDDepField);
+  // CHECK-NOTES: :[[@LINE-38]]:3: note: assignment of ID-dependent field IDDepField
+  // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+}
+
+void success() {
+  int accumulator = 0;
+
+  for (int i = 0; i < 1000; i++) {
+if (i < get_local_id(0)) {
+  accumulator++;
+}
+  }
+}
Index: 

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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:636-637
+
+  if (!CE->getCalleeDecl()) {
+assert(hasUncompilableErrorOccurred() && "expected previous error");
+return false;

aaron.ballman wrote:
> This worries me slightly -- not all `CallExpr` objects have a callee 
> declaration 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/Expr.cpp#L1367).
>  That said, I'm struggling to come up with an example that isn't covered so 
> this may be fine.
That was my experience too, I wasn't able to find a case that isn't covered. I 
tried to avoid adding any diagnostics that I didn't know how to trigger or test.



Comment at: clang/lib/Sema/SemaStmt.cpp:700
+// Call is: obj->*method_ptr or obj.*method_ptr
+const MemberPointerType *MPT = VD->getType()->castAs();
+CalleeType.This = QualType(MPT->getClass(), 0);

aaron.ballman wrote:
> It'd be better not to go through the cast machinery twice -- you cast to the 
> `MemberPointerType` and then cast to the same thing again (but in a different 
> way).
I changed to `auto`, but I can't tell if you have another suggestion here also. 
I can't see how any of these casts can be removed.


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-09 Thread Josh Haberman via Phabricator via cfe-commits
haberman updated this revision to Diff 336511.
haberman marked 9 inline comments as done.
haberman added a comment.

- Simplified some casts and type declarations.


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] D100046: [AArch64] ACLE: Fix issue for mismatching enum types with builtins.

2021-04-09 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

In D100046#2674311 , @sdesmalen wrote:

> The fact that Clang chooses to (explicitly) forget about a builtin in 
> SemaDecl.cpp was quite puzzling to me. Maybe that just shows that I don't 
> fully understand how the builtin mechanism is supposed to work.
> @rsmith and @tambre, git history showed me you have more experience in this 
> area and touched some of that code before, so hopefully you can give me some 
> good feedback!

Sorry for the delay, I'm lately quite busy during the week.
I'll have a look over the weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100046

___
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-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:742
   FeatureGFNI,
   FeatureCLWB,
   FeatureRDPID,

I'm not sure that rocketlake has CLWB. Can you double check that? It's not 
listed in the cpuinfo dump on the 11700K that I found with a google search here 
https://www.pugetsystems.com/labs/hpc/Intel-Rocket-Lake-Compute-Performance-Results-HPL-HPCG-NAMD-and-Numpy-2116/


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] D98798: Produce warning for performing pointer arithmetic on a null pointer.

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

Respond to review comments: add requested test.


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,7 @@
   // 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}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer 
arithmetic on a null pointer has undefined behavior}} 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,7 @@
   // 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}}
+  f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} 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] D99994: [CodeView] Add CodeView support for PGO debug information

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

Fix clang-format issue.


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, i32 0}
+!26 = !{i32 40, i64 0, i32 0}
+!27 = !{i32 

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

2021-04-09 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/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] D100092: [clang-tidy] cppcoreguidelines-declare-loop-variable-in-the-initializer: a new check

2021-04-09 Thread Fabian Thurnheer via Phabricator via cfe-commits
DNS320 added a comment.

Thank you for your reviews.
I will work on your comments and write back soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100092

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


[PATCH] D100054: Handle flags such as -m32 when computing the prefix for programs/runtime libs

2021-04-09 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson updated this revision to Diff 336483.
arichardson added a comment.

- Fix Windows path regex


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100054

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  
clang/test/Driver/Inputs/basic_freebsd64_tree/usr/bin/i386-unknown-freebsd12.2-ld
  clang/test/Driver/Inputs/basic_freebsd64_tree/usr/bin/x86_64-freebsd12.2-ld
  
clang/test/Driver/Inputs/basic_freebsd64_tree/usr/bin/x86_64-unknown-freebsd12.2-ld
  clang/test/Driver/freebsd-m32.c
  clang/test/Driver/linux-per-target-runtime-dir.c

Index: clang/test/Driver/linux-per-target-runtime-dir.c
===
--- clang/test/Driver/linux-per-target-runtime-dir.c
+++ clang/test/Driver/linux-per-target-runtime-dir.c
@@ -25,3 +25,18 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-X8664 %s
 // CHECK-FILE-NAME-X8664: lib{{/|\\}}x86_64-linux-gnu{{/|\\}}libclang_rt.builtins.a
+
+/// Check that we handle flags such as -m32 when searching for the builtins:
+/// Previously clang would use the raw triple passed to -target to find builtins
+/// and sanitizer libraries, but this will result in build errors when compiling
+/// with flags such as -m32. Check that we use the adjusted triple instead:
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=i386-linux-gnu \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-I386 %s
+// CHECK-FILE-NAME-I386: resource_dir_with_per_target_subdir{{/|\\}}lib{{/|\\}}i386-linux-gnu{{/|\\}}libclang_rt.builtins.a
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=x86_64-linux-gnu -m32 \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-X8664-M32 %s
+// CHECK-FILE-NAME-X8664-M32: resource_dir_with_per_target_subdir{{/|\\}}lib{{/|\\}}i386-linux-gnu{{/|\\}}libclang_rt.builtins.a
Index: clang/test/Driver/freebsd-m32.c
===
--- /dev/null
+++ clang/test/Driver/freebsd-m32.c
@@ -0,0 +1,76 @@
+/// Check that building with -m32 links with i386-freebsd12.2-ld/ instead of
+/// x86_64-freebsd12.2-ld and that we select the right sanitizer runtime.
+
+/// We should select x86_64-unknown-freebsd12.2-ld since it matches the triple argument
+/// Note: The paths specified by -B are not searched for triple-prefixed tools, so
+/// we also have to set $PATH.
+// RUN: env PATH=%S/Inputs/basic_freebsd64_tree/usr/bin %clang -no-canonical-prefixes \
+// RUN:   -target x86_64-unknown-freebsd12.2 %s \
+// RUN:   -B%S/Inputs/basic_freebsd64_tree/usr/bin -### 2>&1 | FileCheck %s --check-prefix=PREFIXED-64
+// PREFIXED-64: "-cc1" "-triple" "x86_64-unknown-freebsd12.2"
+// PREFIXED-64-NEXT: "{{.+}}Inputs{{/|}}basic_freebsd64_tree{{/|}}usr{{/|}}bin{{/|}}x86_64-unknown-freebsd12.2-ld" "--eh-frame-hdr"
+// Should not be passing an explicit linker emulation for the 64-bit case
+// PREFIXED-64-NOT: "-m"
+// RUN: env PATH=/this/path/does/not/exist %clang -no-canonical-prefixes \
+// RUN:   -target x86_64-unknown-freebsd12.2 %s \
+// RUN:   -B%S/Inputs/basic_freebsd64_tree/usr/bin -### 2>&1 | FileCheck %s --check-prefix=MINUS-B-NO-TRIPLE-PREFIX
+// MINUS-B-NO-TRIPLE-PREFIX: "-cc1" "-triple" "x86_64-unknown-freebsd12.2"
+// MINUS-B-NO-TRIPLE-PREFIX-NEXT: "ld" "--eh-frame-hdr"
+// MINUS-B-NO-TRIPLE-PREFIX-NOT: "-m"
+
+/// The triple passed to clang -cc1 should be normalized, but the prefix when searching
+/// for ld should not be normalized. Since there is no x86_64--freebsd12.2-ld, passing
+/// -target x86_64--freebsd12.2 should not find a a valid linker:
+// RUN: env PATH=%S/Inputs/basic_freebsd64_tree/usr/bin %clang -no-canonical-prefixes \
+// RUN:   -target x86_64--freebsd12.2 %s \
+// RUN:   -B%S/Inputs/basic_freebsd64_tree/usr/bin -### 2>&1 | FileCheck %s --check-prefix=NO-NORMALIZE-LD-PREFIX-64
+// NO-NORMALIZE-LD-PREFIX-64: "-cc1" "-triple" "x86_64-unknown-freebsd12.2"
+// NO-NORMALIZE-LD-PREFIX-64-NEXT: "ld" "--eh-frame-hdr"
+// NO-NORMALIZE-LD-PREFIX-NOT: "-m"
+
+/// We should search for i386-unknown-freebsd12.2-ld when -m32 is passed (and also pass -m elf_i386_fbsd):
+// RUN: env PATH=%S/Inputs/basic_freebsd64_tree/usr/bin %clang -no-canonical-prefixes \
+// RUN:   -target x86_64-unknown-freebsd12.2 %s -m32 \
+// RUN:   -B%S/Inputs/basic_freebsd64_tree/usr/bin -### 2>&1  | FileCheck %s --check-prefix=PREFIXED-M32
+// PREFIXED-M32: "-cc1" "-triple" "i386-unknown-freebsd12.2"
+// PREFIXED-M32-NEXT: 

[PATCH] D100209: [OpenCL] Do not add builtins with unavailable types

2021-04-09 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
svenvh added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

Add functionality to assign extensions to types in `OpenCLBuiltins.td` and use 
that information to filter candidates that should not be exposed if a type is 
not available.

Most of the changes affect the addition of scalar base types into the `QT` 
vector in the generated `OCL2Qual` function (that is, the switch statement as 
described in step 1 in the `OCL2Qual` top comment).  For types that are 
associated with an extension, the QualType is now added only if the 
corresponding extension macro is defined.

The old code was as follows for the `FGenTypeN` GenericType, which represents 
all floating point types for all vector sizes.

  case OCLT_FGenTypeN:
QT.append({Context.FloatTy, Context.DoubleTy, Context.HalfTy, 
Context.FloatTy, Context.DoubleTy, Context.HalfTy, Context.FloatTy, ...
GenTypeNumTypes = 3;
GenVectorSizes = ListVecAndScalar;
break;

With this patch, the generated code becomes:

  case OCLT_FGenTypeN: {
SmallVector TypeList;
TypeList.push_back(Context.FloatTy);
if (S.getPreprocessor().isMacroDefined("cl_khr_fp64")) {
  TypeList.push_back(Context.DoubleTy);
}
if (S.getPreprocessor().isMacroDefined("cl_khr_fp16")) {
  TypeList.push_back(Context.HalfTy);
}
GenTypeNumTypes = TypeList.size();
QT.reserve(18);
for (unsigned I = 0; I < 6; I++) {
  QT.append(TypeList);
}
GenVectorSizes = ListVecAndScalar;
break;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100209

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -705,34 +705,45 @@
 
   // Switch cases for generic types.
   for (const auto *GenType : Records.getAllDerivedDefinitions("GenericType")) {
-OS << "case OCLT_" << GenType->getValueAsString("Name") << ":\n";
-OS << "  QT.append({";
+OS << "case OCLT_" << GenType->getValueAsString("Name") << ": {\n";
 
 // Build the Cartesian product of (vector sizes) x (types).  Only insert
 // the plain scalar types for now; other type information such as vector
 // size and type qualifiers will be added after the switch statement.
-for (unsigned I = 0; I < GenType->getValueAsDef("VectorList")
- ->getValueAsListOfInts("List")
- .size();
- I++) {
-  for (const auto *T :
-   GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List")) {
-OS << T->getValueAsDef("QTExpr")->getValueAsString("TypeExpr") << ", ";
+std::vector BaseTypes =
+GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List");
+
+// Collect all QualTypes for a single vector size into TypeList.
+OS << "  SmallVector TypeList;\n";
+for (const auto *T : BaseTypes) {
+  StringRef Ext =
+  T->getValueAsDef("Extension")->getValueAsString("ExtName");
+  if (!Ext.empty()) {
+OS << "  if (S.getPreprocessor().isMacroDefined(\"" << Ext
+   << "\")) {\n  ";
+  }
+  OS << "  TypeList.push_back("
+ << T->getValueAsDef("QTExpr")->getValueAsString("TypeExpr") << ");\n";
+  if (!Ext.empty()) {
+OS << "  }\n";
   }
 }
-OS << "});\n";
-// GenTypeNumTypes is the number of types in the GenType
-// (e.g. float/double/half).
-OS << "  GenTypeNumTypes = "
-   << GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List")
-  .size()
-   << ";\n";
+OS << "  GenTypeNumTypes = TypeList.size();\n";
+
+// Duplicate the TypeList for every vector size.
+std::vector VectorList =
+GenType->getValueAsDef("VectorList")->getValueAsListOfInts("List");
+OS << "  QT.reserve(" << VectorList.size() * BaseTypes.size() << ");\n"
+   << "  for (unsigned I = 0; I < " << VectorList.size() << "; I++) {\n"
+   << "QT.append(TypeList);\n"
+   << "  }\n";
+
 // GenVectorSizes is the list of vector sizes for this GenType.
-// QT contains GenTypeNumTypes * #GenVectorSizes elements.
 OS << "  GenVectorSizes = List"
<< GenType->getValueAsDef("VectorList")->getValueAsString("Name")
-   << ";\n";
-OS << "  break;\n";
+   << ";\n"
+   << "  break;\n"
+   << "}\n";
   }
 
   // Switch cases for non generic, non image types (int, int4, float, ...).
@@ -755,9 +766,20 @@
 if (QT->getValueAsBit("IsAbstract") == 1)
 

[PATCH] D100161: Redistribute energy for Corpus

2021-04-09 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

Thanks for the patch!  Would you mind sharing the experimental data/results you 
obtained for this patch?

Additionally, could you submit this patch to FuzzBench 
 for an independent evaluation?

Thanks,
Matt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100161

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


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

2021-04-09 Thread Saurabh Jha via cfe-commits
Seems like the new build is passing. Can you please commit it on my behalf
if it looks okay to you?

Thanks a lot for your help in this patch.

Saurabh

On Fri, Apr 9, 2021 at 12:37 PM Saurabh Jha via Phabricator <
revi...@reviews.llvm.org> wrote:

> SaurabhJha added a comment.
>
> In D99037#2679131 , @fhahn wrote:
>
> > In D99037#2678848 ,
> @SaurabhJha wrote:
> >
> >> In D99037#2678779 , @fhahn
> wrote:
> >>
> >>>
> >>
> >> Will create a new patch to address your last comments
> >
> > Can you directly update this one? I'll commit it after the update.
>
> Sure, done. I did not know I could change the patch after its accepted.
>
>
> 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] D99225: [clang] tests: cleanup, update and add some new ones

2021-04-09 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG18192228602c: [clang] tests: cleanup, update and add some 
new ones (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99225

Files:
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
  clang/test/CXX/special/class.copy/p3-cxx11.cpp
  clang/test/CXX/special/class.copy/p33-0x.cpp
  clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
  clang/test/CodeGen/nrvo-tracking.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/constant-expression-cxx1y.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx1y-deduced-return-type.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp
  clang/test/SemaCXX/return-stack-addr.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp

Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,10 +1,12 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
+
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
@@ -76,8 +78,8 @@
 Base test2() {
 Derived d2;
 return d2;  // e1
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
+// cxx11_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_17-note@-2{{to avoid copying}}
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
@@ -87,22 +89,22 @@
 ConstructFromBase test4() {
 Derived d4;
 return d4;  // e3
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
+// cxx11_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_17-note@-2{{to avoid copying}}
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
 }
 ConvertFromDerived test5() {
 Derived d5;
 return d5;  // e4
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
+// cxx11_17-warning@-1{{will be copied despite being returned by name}}
+// cxx11_17-note@-2{{to avoid copying}}
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
 }
 ConvertFromBase test6() {
 Derived d6;
 return d6;  // e5
-// expected-warning@-1{{will be copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
+// cxx11_17-warning@-1{{will be copied despite being returned by name}}
+// 

[clang] 1819222 - [clang] tests: cleanup, update and add some new ones

2021-04-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-04-09T17:24:08+02:00
New Revision: 18192228602c6a8093fb0eefa863ab854dd03e59

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

LOG: [clang] tests: cleanup, update and add some new ones

This reworks a small set of tests, as preparatory work for implementing
P2266.
* Run for more standard versions, including c++2b.
* Normalize file names and run commands.
* Adds some extra tests.

New Coroutine tests taken from Aaron Puchert's D68845.

Signed-off-by: Matheus Izvekov 

Reviewed By: thakis

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

Added: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/special/class.copy/p3-cxx11.cpp
clang/test/CodeGen/nrvo-tracking.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Modified: 
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/P1155.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp

Removed: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
clang/test/CXX/special/class.copy/p33-0x.cpp
clang/test/SemaCXX/constant-expression-cxx1y.cpp
clang/test/SemaCXX/cxx1y-deduced-return-type.cpp



diff  --git a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp 
b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
index e4056221b4f3c..9d1d7d9a0d8bd 100644
--- a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20 %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20_2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20_2b %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
 
 namespace test_delete_function {
 struct A1 {
@@ -54,38 +55,38 @@ B2 test4() {
 namespace test_implicitly_movable_rvalue_ref {
 struct A1 {
   A1(A1 &&);
-  A1(const A1 &) = delete; // cxx11_14_17-note {{'A1' has been explicitly 
marked deleted here}}
+  A1(const A1 &) = delete; // cxx11_17-note {{'A1' has been explicitly marked 
deleted here}}
 };
 A1 test1(A1 &) {
-  return a; // cxx11_14_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
+  return a; // cxx11_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
 }
 
 struct A2 {
   A2(A2 &&);
 
 private:
-  A2(const A2 &); // cxx11_14_17-note {{declared private here}}
+  A2(const A2 &); // cxx11_17-note {{declared private here}}
 };
 A2 test2(A2 &) {
-  return a; // cxx11_14_17-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::A2'}}
+  return a; // cxx11_17-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::A2'}}
 }
 
 struct B1 {
   B1(const B1 &);
-  B1(B1 &&) = delete; // cxx20-note {{'B1' has been explicitly marked deleted 
here}}
+  B1(B1 &&) = delete; // cxx20_2b-note {{'B1' has been explicitly marked 
deleted here}}
 };
 B1 test3(B1 &) {
-  return b; // cxx20-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::B1'}}
+  return b; // cxx20_2b-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::B1'}}
 }
 
 struct B2 {
   B2(const B2 &);
 
 private:
-  B2(B2 &&); // cxx20-note {{declared private here}}
+  B2(B2 &&); // cxx20_2b-note {{declared private here}}
 };
 B2 test4(B2 &) {
-  return b; // cxx20-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::B2'}}
+  return b; // cxx20_2b-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::B2'}}
 }
 } // namespace test_implicitly_movable_rvalue_ref
 
@@ 

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

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

So, we only need D99988  and this one (D100148 
) now and the LLVM package will finally build 
on Debian without any additional tweaks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

___
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-09 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 336454.
steffenlarsen added a comment.

Following changes:

- Changed the type in the names of the intrinsics and builtins.
- Changed use of `IntrNoMem` to `IntrInaccessibleMemOnly`.
- Added `PTX70` as a requirement to the builtins.


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

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_ui>;
+defm REDUX_SYNC_MIN_U32 : REDUX_SYNC<"min", "u32", int_nvvm_redux_sync_min_ui>;
+defm REDUX_SYNC_MAX_U32 : REDUX_SYNC<"max", "u32", int_nvvm_redux_sync_max_ui>;
+defm REDUX_SYNC_ADD_S32 : REDUX_SYNC<"add", "s32", int_nvvm_redux_sync_add_i>;
+defm REDUX_SYNC_MIN_S32 : REDUX_SYNC<"min", "s32", int_nvvm_redux_sync_min_i>;
+defm REDUX_SYNC_MAX_S32 : REDUX_SYNC<"max", "s32", int_nvvm_redux_sync_max_i>;
+defm REDUX_SYNC_AND_B32 : REDUX_SYNC<"and", "b32", int_nvvm_redux_sync_and_i>;
+defm REDUX_SYNC_XOR_B32 : REDUX_SYNC<"xor", "b32", int_nvvm_redux_sync_xor_i>;
+defm REDUX_SYNC_OR_B32 : REDUX_SYNC<"or", "b32", int_nvvm_redux_sync_or_i>;
+
 } // isConvergent = true
 
 //---
Index: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
===
--- llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -144,11 +144,13 @@
 def hasPTX61 : 

[clang] f9264ac - [HIP] Workaround ICE compiling SemaChecking.cpp with gcc 5

2021-04-09 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-04-09T10:40:07-04:00
New Revision: f9264ac0fdb7b58d1eb088ea91af0fee48816033

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

LOG: [HIP] Workaround ICE compiling SemaChecking.cpp with gcc 5

Change-Id: I6c6213bc6b90365bfb78636ce7fb0700a58807cf

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bb038ac5730c..fa5e184d2864 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3388,18 +3388,17 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
 
   // Check valididty of memory ordering as per C11 / C++11's memody model.
   // Only fence needs check. Atomic dec/inc allow all memory orders.
-  auto DiagInvalidMemOrder = [&](auto *ArgExpr) {
+  if (!llvm::isValidAtomicOrderingCABI(Ord))
 return Diag(ArgExpr->getBeginLoc(),
 diag::warn_atomic_op_has_invalid_memory_order)
<< ArgExpr->getSourceRange();
-  };
-  if (!llvm::isValidAtomicOrderingCABI(Ord))
-return DiagInvalidMemOrder(ArgExpr);
   switch (static_cast(Ord)) {
   case llvm::AtomicOrderingCABI::relaxed:
   case llvm::AtomicOrderingCABI::consume:
 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_fence)
-  return DiagInvalidMemOrder(ArgExpr);
+  return Diag(ArgExpr->getBeginLoc(),
+  diag::warn_atomic_op_has_invalid_memory_order)
+ << ArgExpr->getSourceRange();
 break;
   case llvm::AtomicOrderingCABI::acquire:
   case llvm::AtomicOrderingCABI::release:



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


[PATCH] D100197: Enable creation of large response file on z/OS

2021-04-09 Thread Sean via Phabricator via cfe-commits
SeanP created this revision.
SeanP added reviewers: abhina.sree, hubert.reinterpretcast, muiez.
SeanP requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Most text processing commands (eg. grep, awk) have a maximum line length limit 
on z/OS.  The current method of using cc -E & grep fails on z/OS because of 
this limit.  I'm changing the command to create the long line in the response 
file to use python.  This avoids the possibility of any tools blocking the 
generation of the large response file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100197

Files:
  clang/test/Driver/Inputs/gen-response.c
  clang/test/Driver/response-file.c


Index: clang/test/Driver/response-file.c
===
--- clang/test/Driver/response-file.c
+++ clang/test/Driver/response-file.c
@@ -13,7 +13,7 @@
 // But there's no guarantee that we actually will (the system limit could be
 // *huge*), so just check that invoking cc1 succeeds under these conditions.
 //
-// RUN: %clang -E %S/Inputs/gen-response.c | grep DTEST > %t.1.txt
+// RUN: %python  -c 'print(*("-DTEST" for x in range(30)))' >%t.1.txt
 // RUN: %clang -E @%t.1.txt %s -v 2>&1 | FileCheck %s -check-prefix=LONG
 // LONG: extern int it_works;
 
Index: clang/test/Driver/Inputs/gen-response.c
===
--- clang/test/Driver/Inputs/gen-response.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#define M -DTEST
-#define M1 M M M M M M M M M M
-#define M2 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1
-#define M3 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2
-#define M4 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3
-#define M5 M4 M4 M4 M4 M4 M4 M4 M4 M4 M4
-#define TEXT M5 M5 M5
-TEXT


Index: clang/test/Driver/response-file.c
===
--- clang/test/Driver/response-file.c
+++ clang/test/Driver/response-file.c
@@ -13,7 +13,7 @@
 // But there's no guarantee that we actually will (the system limit could be
 // *huge*), so just check that invoking cc1 succeeds under these conditions.
 //
-// RUN: %clang -E %S/Inputs/gen-response.c | grep DTEST > %t.1.txt
+// RUN: %python  -c 'print(*("-DTEST" for x in range(30)))' >%t.1.txt
 // RUN: %clang -E @%t.1.txt %s -v 2>&1 | FileCheck %s -check-prefix=LONG
 // LONG: extern int it_works;
 
Index: clang/test/Driver/Inputs/gen-response.c
===
--- clang/test/Driver/Inputs/gen-response.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#define M -DTEST
-#define M1 M M M M M M M M M M
-#define M2 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1
-#define M3 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2
-#define M4 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3
-#define M5 M4 M4 M4 M4 M4 M4 M4 M4 M4 M4
-#define TEXT M5 M5 M5
-TEXT
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100172: Fix static code analysis concerns with uninitialized variables

2021-04-09 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d7cb79416ad: RISCVABIInfo::classifyArgumentType: Fix static 
analyzer warnings with… (authored by Manna, committed by RKSimon).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100172

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10700,8 +10700,8 @@
 llvm::Type *Field2Ty = nullptr;
 CharUnits Field1Off = CharUnits::Zero();
 CharUnits Field2Off = CharUnits::Zero();
-int NeededArgGPRs;
-int NeededArgFPRs;
+int NeededArgGPRs = 0;
+int NeededArgFPRs = 0;
 bool IsCandidate =
 detectFPCCEligibleStruct(Ty, Field1Ty, Field1Off, Field2Ty, Field2Off,
  NeededArgGPRs, NeededArgFPRs);


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10700,8 +10700,8 @@
 llvm::Type *Field2Ty = nullptr;
 CharUnits Field1Off = CharUnits::Zero();
 CharUnits Field2Off = CharUnits::Zero();
-int NeededArgGPRs;
-int NeededArgFPRs;
+int NeededArgGPRs = 0;
+int NeededArgFPRs = 0;
 bool IsCandidate =
 detectFPCCEligibleStruct(Ty, Field1Ty, Field1Off, Field2Ty, Field2Off,
  NeededArgGPRs, NeededArgFPRs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5d7cb79 - RISCVABIInfo::classifyArgumentType: Fix static analyzer warnings with uninitialized variables warnings - NFCI

2021-04-09 Thread Simon Pilgrim via cfe-commits

Author: Soumi Manna
Date: 2021-04-09T15:23:32+01:00
New Revision: 5d7cb79416adee00cf52be12ee42692dd19d4acb

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

LOG: RISCVABIInfo::classifyArgumentType: Fix static analyzer warnings with 
uninitialized variables warnings - NFCI

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index c3df36fc1ea2..de3d3f86fe9b 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -10700,8 +10700,8 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType 
Ty, bool IsFixed,
 llvm::Type *Field2Ty = nullptr;
 CharUnits Field1Off = CharUnits::Zero();
 CharUnits Field2Off = CharUnits::Zero();
-int NeededArgGPRs;
-int NeededArgFPRs;
+int NeededArgGPRs = 0;
+int NeededArgFPRs = 0;
 bool IsCandidate =
 detectFPCCEligibleStruct(Ty, Field1Ty, Field1Off, Field2Ty, Field2Off,
  NeededArgGPRs, NeededArgFPRs);



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


[PATCH] D97960: [clang-tidy] bugprone-signal-handler improvements: display call chain

2021-04-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a subscriber: Eugene.Zelenko.
balazske added a comment.

In D97960#2611531 , @Eugene.Zelenko 
wrote:

> I think call stack may be useful for other checks too. May be code should be 
> moved to utilities?

Yes it is useful for other checks, but the code here is specialized for this 
problem only. It is possible to make a call graph that stores the "parents" of 
the calls, probably root items that are of a special kind, and can add notes 
for call chain. But there is already a `clang::CallGraph` that can compute call 
graph, if I remember correctly it was not usable here because the parent node 
(caller) is not available. That `CallGraph` could be extended too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97960

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


[clang-tools-extra] b9b708e - [clangd] Log a message when gRPC support is off, but remote-index is configured

2021-04-09 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-04-09T15:52:51+02:00
New Revision: b9b708eef8cb7bcb073361283cd573beb04992a9

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

LOG: [clangd] Log a message when gRPC support is off, but remote-index is 
configured

Before this change clangd would emit a diagnostic whenever remote-index
was configured but binary didn't have grpc support.

This can be annoying when projects are configuring remote-index through their
configs but developers have a clangd binary without the support.

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

Added: 


Modified: 
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 8f402ae061535..1185eb7255b4c 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -322,8 +322,9 @@ struct FragmentCompiler {
llvm::SMRange BlockRange) {
 #ifndef CLANGD_ENABLE_REMOTE
 if (External.Server) {
-  diag(Error, "Clangd isn't compiled with remote index support, ignoring "
-  "Server." External.Server->Range);
+  elog("Clangd isn't compiled with remote index support, ignoring Server: "
+   "{0}",
+   *External.Server);
   External.Server.reset();
 }
 #endif

diff  --git a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp 
b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
index b68d7e5f5e173..f2c27c22fdeb9 100644
--- a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -324,15 +324,15 @@ TEST_F(ConfigCompileTests, 
ExternalBlockWarnOnMultipleSource) {
   External.Server.emplace("");
   Frag.Index.External = std::move(External);
   compileAndApply();
-  llvm::StringLiteral ExpectedDiag =
 #ifdef CLANGD_ENABLE_REMOTE
-  "Exactly one of File or Server must be set.";
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  Contains(AllOf(DiagMessage("Exactly one of File or Server must be set."),
+ DiagKind(llvm::SourceMgr::DK_Error;
 #else
-  "Clangd isn't compiled with remote index support, ignoring Server.";
+  ASSERT_TRUE(Conf.Index.External.hasValue());
+  EXPECT_EQ(Conf.Index.External->Kind, Config::ExternalIndexSpec::File);
 #endif
-  EXPECT_THAT(Diags.Diagnostics,
-  Contains(AllOf(DiagMessage(ExpectedDiag),
- DiagKind(llvm::SourceMgr::DK_Error;
 }
 
 TEST_F(ConfigCompileTests, ExternalBlockErrOnNoSource) {



___
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-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rsmith, erichkeane.
aaron.ballman added a comment.

Thank you for this patch, I think it's really useful functionality for plugin 
authors!

Adding some additional reviewers for more opinions on the changes in the 
preprocessor.




Comment at: clang/examples/PrintAttributeTokens/CMakeLists.txt:3-10
+if( NOT MSVC ) # MSVC mangles symbols differently, and
+   # PrintAttributeTokens.export contains C++ symbols.
+  if( NOT LLVM_REQUIRES_RTTI )
+if( NOT LLVM_REQUIRES_EH )
+  set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/PrintAttributeTokens.exports)
+endif()
+  endif()

I'm not certain what this is actually doing -- the .exports file is empty (and 
no other plugin has this sort of .exports file thing). Is this needed?



Comment at: clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp:37
+   const ParsedAttr ) const override {
+llvm::errs() << "PrintAttributeTokens ---\n";
+D->dump(llvm::errs());

Should probably use `llvm::outs()` instead (here and elsewhere in the plugin).



Comment at: clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp:44-45
+} else {
+  const Token *tokens = Attr.getTokens();
+  for (unsigned i = 0; i < Attr.getNumTokens(); i++) {
+llvm::errs() << tokens[i].getName();

Per the usual coding conventions.



Comment at: clang/examples/PrintAttributeTokens/PrintAttributeTokens.cpp:48-50
+if (tokens[i].isLiteral()) {
+  llvm::errs() << "\t=" << tokens[i].getLiteralData();
+}

It'd probably be handy to also print identifier tokens.



Comment at: clang/include/clang/Sema/ParsedAttr.h:236-238
+  /// The number of tokens within the argument.
+  /// The tokens themselves are stored after the object.
+  unsigned NumTokens : 32;

Rather than use a bit-field for this, I'd add it as a regular `unsigned` after 
the declaration of `UnavailableLoc`.



Comment at: clang/include/clang/Sema/ParsedAttr.h:284
+  Token *getTokensBuffer() { return getTrailingObjects(); }
+  Token const *getTokensBuffer() const { return getTrailingObjects(); }
+





Comment at: clang/include/clang/Sema/ParsedAttr.h:486
+  const Token *getTokens() const {
+assert(NumTokens > 0 && "No Tokens to retrieve!");
+return getTokensBuffer();

I think it'd be reasonable to return `nullptr` in this case, WDYT?



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4100-4102
+  // 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.

I think plugins will expect these tokens to be available regardless of which 
attribute syntax is used, so you may need to look into also doing work for GNU 
and declspec attribute argument lists.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:4121-4122
+// 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);

To be clear, we should have at least *two* tokens, right? One for the left 
paren and one for the right?



Comment at: clang/test/Frontend/plugin-print-attr-tokens.cpp:9-12
+[[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() {}

Can  you also verify that the token stream output from the plugin looks correct?

Can you also add additional tests for GNU and declspec attribute syntaxes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99861

___
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-09 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added a comment.

@tra  Thank you for the feedback! I think I see what you're getting at, but I 
am not quite understanding how it would work for these builtins and intrinsics. 
I have added some comments to the corresponding

The comment about `IntrInaccessibleMemOnly` I agree with completely, so I will 
replace `IntrNoMem` with it in the updated version I'm getting ready. Good 
call. :)




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)

tra wrote:
> 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` ?
> 
What gives me pause is that a for atomic minimum there are both 
`__nvvm_atom_min_gen_i` and `__nvvm_atom_min_gen_ui` to distinguish between 
signed and unsigned. What makes the difference?

That noted, I'll happily rename the builtins to be more in line with the other 
builtins. `__nvvm_redux_sync_*_i` and `__nvvm_redux_sync_*_ui` maybe?



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],

tra wrote:
> This could also be consolidated into an overloaded intrinsic operating on 
> `llvm_anyint_ty`
I am having a look at other uses of this, but I'm having difficulty wrapping my 
head around how to map these overloads to the PTX instructions in 
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td. Though it would be nice, it just 
seems overly complicated to get a signed and an unsigned 32-bit integer version 
of each of these intrinsics.


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] D100144: [AMDGPU] Allow relaxed/consume memory order for atomic inc/dec

2021-04-09 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG25942d7c49ed: [AMDGPU] Allow relaxed/consume memory order 
for atomic inc/dec (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

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

[clang] 25942d7 - [AMDGPU] Allow relaxed/consume memory order for atomic inc/dec

2021-04-09 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-04-09T09:23:41-04:00
New Revision: 25942d7c49ed37a6fa9b291423bb0a22ae77e32d

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

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

Reviewed by: Jon Chesterfield

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

Added: 


Modified: 
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

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a38176af390d4..439b378306550 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15469,8 +15469,10 @@ bool CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
 int ord = cast(Order)->getZExtValue();
 
 // Map C11/C++11 memory ordering to LLVM memory ordering
+assert(llvm::isValidAtomicOrderingCABI(ord));
 switch (static_cast(ord)) {
 case llvm::AtomicOrderingCABI::acquire:
+case llvm::AtomicOrderingCABI::consume:
   AO = llvm::AtomicOrdering::Acquire;
   break;
 case llvm::AtomicOrderingCABI::release:
@@ -15482,8 +15484,8 @@ bool CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
 case llvm::AtomicOrderingCABI::seq_cst:
   AO = llvm::AtomicOrdering::SequentiallyConsistent;
   break;
-case llvm::AtomicOrderingCABI::consume:
 case llvm::AtomicOrderingCABI::relaxed:
+  AO = llvm::AtomicOrdering::Monotonic;
   break;
 }
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index be015f02027f5..bb038ac5730c8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3384,20 +3384,28 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned 
BuiltinID,
   if (!ArgExpr->EvaluateAsInt(ArgResult, Context))
 return Diag(ArgExpr->getExprLoc(), diag::err_typecheck_expect_int)
<< ArgExpr->getType();
-  int ord = ArgResult.Val.getInt().getZExtValue();
+  auto Ord = ArgResult.Val.getInt().getZExtValue();
 
   // Check valididty of memory ordering as per C11 / C++11's memody model.
-  switch (static_cast(ord)) {
+  // Only fence needs check. Atomic dec/inc allow all memory orders.
+  auto DiagInvalidMemOrder = [&](auto *ArgExpr) {
+return Diag(ArgExpr->getBeginLoc(),
+diag::warn_atomic_op_has_invalid_memory_order)
+   << ArgExpr->getSourceRange();
+  };
+  if (!llvm::isValidAtomicOrderingCABI(Ord))
+return DiagInvalidMemOrder(ArgExpr);
+  switch (static_cast(Ord)) {
+  case llvm::AtomicOrderingCABI::relaxed:
+  case llvm::AtomicOrderingCABI::consume:
+if (BuiltinID == AMDGPU::BI__builtin_amdgcn_fence)
+  return DiagInvalidMemOrder(ArgExpr);
+break;
   case llvm::AtomicOrderingCABI::acquire:
   case llvm::AtomicOrderingCABI::release:
   case llvm::AtomicOrderingCABI::acq_rel:
   case llvm::AtomicOrderingCABI::seq_cst:
 break;
-  default: {
-return Diag(ArgExpr->getBeginLoc(),
-diag::warn_atomic_op_has_invalid_memory_order)
-   << ArgExpr->getSourceRange();
-  }
   }
 
   Arg = TheCall->getArg(ScopeIndex);

diff  --git a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp 
b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
index 16600d15f2c40..c01d3e215ff93 100644
--- a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
+++ b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
@@ -188,16 +188,22 @@ __attribute__((device)) void test_order32() {
   // CHECK-LABEL: test_order32
   __attribute__((shared)) __UINT32_TYPE__ val;
 
-  // CHECK: %1 = call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* addrspacecast 
(i32 addrspace(3)* @_ZZ12test_order32vE3val to i32*), i32 %0, i32 4, i32 2, i1 
false)
+  // CHECK: call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* addrspacecast (i32 
addrspace(3)* @_ZZ12test_order32vE3val to i32*), i32 {{.*}}, i32 2, i32 2, i1 
false)
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_RELAXED, 
"workgroup");
+
+  // CHECK: call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* addrspacecast (i32 
addrspace(3)* @_ZZ12test_order32vE3val to i32*), i32 {{.*}}, i32 4, i32 2, i1 
false)
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_CONSUME, 
"workgroup");
+
+  // CHECK: call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* addrspacecast (i32 
addrspace(3)* @_ZZ12test_order32vE3val to i32*), i32 {{.*}}, i32 4, i32 2, i1 
false)
   val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_ACQUIRE, 
"workgroup");
 
-  // CHECK: %3 = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* addrspacecast 
(i32 addrspace(3)* @_ZZ12test_order32vE3val to i32*), i32 %2, i32 5, i32 2, i1 
false)
+  // 

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

2021-04-09 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/lib/Basic/TargetInfo.cpp:398
+auto CLVer = Opts.OpenCLCPlusPlus ? 200 : Opts.OpenCLVersion;
+if (CLVer >= 300) {
+  auto  = getSupportedOpenCLOpts();

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > I suggest we move this onto `OpenCLOptions::addSupport`.
> > This should stay here to control simultaneous macro definitions
> Could we leave this bit out? These are set correctly by the targets 
> already... and I think targets do need to set those explicitly indeed. I 
> don't see big value in this functionality right now.
There are 2 reasons why it should be here

1) Simultaneous macro definition

2) Correct option processing: we need to remove `cl_khr_fp64` macro if 
`-cl-ext=-__opencl_c_fp64` specified


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

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


[PATCH] D100187: [OPENMP]Fix PR49115: Incorrect results for scan directive.

2021-04-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added reviewers: jdoerfert, mikerice, jyu2.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

For combined worksharing directives need to emit the temp arrays outside
of the parallel region and update them in the master thread only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100187

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

Index: clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp
===
--- clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp
+++ clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp
@@ -18,10 +18,15 @@
   static float a[10];
   static double b;
 
-  // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
+  // CHECK: call i8* @llvm.stacksave()
+  // CHECK: [[A_BUF_SIZE:%.+]] = mul nuw i64 10, [[NUM_ELEMS:%[^,]+]]
+
+  // float a_buffer[10][n];
+  // CHECK: [[A_BUF:%.+]] = alloca float, i64 [[A_BUF_SIZE]],
+  // CHECK: [[B_BUF:%.+]] = alloca double, i64 10,
+
   // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
 
-  // CHECK: call i8* @llvm.stacksave()
   // CHECK: [[A_BUF_SIZE:%.+]] = mul nuw i64 10, [[NUM_ELEMS:%[^,]+]]
 
   // float a_buffer[10][n];
@@ -29,6 +34,9 @@
 
   // double b_buffer[10];
   // CHECK: [[B_BUF:%.+]] = alloca double, i64 10,
+  // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
+  // CHECK: call void @llvm.stackrestore(i8*
+
 #pragma omp parallel for simd reduction(inscan, +:a[:n], b)
   for (int i = 0; i < 10; ++i) {
 // CHECK: call void @__kmpc_for_static_init_4(
@@ -42,8 +50,8 @@
 // a_buffer[i][0..n] = a_priv[[0..n];
 // CHECK: [[BASE_IDX_I:%.+]] = load i32, i32* [[IV_ADDR:%.+]],
 // CHECK: [[BASE_IDX:%.+]] = zext i32 [[BASE_IDX_I]] to i64
-// CHECK: [[IDX:%.+]] = mul nsw i64 [[BASE_IDX]], [[NUM_ELEMS]]
-// CHECK: [[A_BUF_IDX:%.+]] = getelementptr inbounds float, float* [[A_BUF]], i64 [[IDX]]
+// CHECK: [[IDX:%.+]] = mul nsw i64 [[BASE_IDX]], [[NUM_ELEMS:%.+]]
+// CHECK: [[A_BUF_IDX:%.+]] = getelementptr inbounds float, float* [[A_BUF:%.+]], i64 [[IDX]]
 // CHECK: [[A_PRIV:%.+]] = getelementptr inbounds [10 x float], [10 x float]* [[A_PRIV_ADDR:%.+]], i64 0, i64 0
 // CHECK: [[BYTES:%.+]] = mul nuw i64 [[NUM_ELEMS:%.+]], 4
 // CHECK: [[DEST:%.+]] = bitcast float* [[A_BUF_IDX]] to i8*
@@ -51,7 +59,7 @@
 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}[[DEST]], i8* {{.*}}[[SRC]], i64 [[BYTES]], i1 false)
 
 // b_buffer[i] = b_priv;
-// CHECK: [[B_BUF_IDX:%.+]] = getelementptr inbounds double, double* [[B_BUF]], i64 [[BASE_IDX]]
+// CHECK: [[B_BUF_IDX:%.+]] = getelementptr inbounds double, double* [[B_BUF:%.+]], i64 [[BASE_IDX]]
 // CHECK: [[B_PRIV:%.+]] = load double, double* [[B_PRIV_ADDR]],
 // CHECK: store double [[B_PRIV]], double* [[B_BUF_IDX]],
 // CHECK: br label %[[LOOP_CONTINUE:.+]]
@@ -158,17 +166,8 @@
 // CHECK: [[LOOP_CONTINUE]]:
 // CHECK: call void @llvm.stackrestore(i8* %
 // CHECK: call void @__kmpc_for_static_fini(
-// CHECK: call void @llvm.stackrestore(i8*
   }
 
-  // CHECK: call i8* @llvm.stacksave()
-  // CHECK: [[A_BUF_SIZE:%.+]] = mul nuw i64 10, [[NUM_ELEMS:%[^,]+]]
-
-  // float a_buffer[10][n];
-  // CHECK: [[A_BUF:%.+]] = alloca float, i64 [[A_BUF_SIZE]],
-
-  // double b_buffer[10];
-  // CHECK: [[B_BUF:%.+]] = alloca double, i64 10,
 #pragma omp parallel for simd reduction(inscan, +:a[:n], b)
   for (int i = 0; i < 10; ++i) {
 // CHECK: call void @__kmpc_for_static_init_4(
@@ -185,8 +184,8 @@
 // a_buffer[i][0..n] = a_priv[[0..n];
 // CHECK: [[BASE_IDX_I:%.+]] = load i32, i32* [[IV_ADDR:%.+]],
 // CHECK: [[BASE_IDX:%.+]] = zext i32 [[BASE_IDX_I]] to i64
-// CHECK: [[IDX:%.+]] = mul nsw i64 [[BASE_IDX]], [[NUM_ELEMS]]
-// CHECK: [[A_BUF_IDX:%.+]] = getelementptr inbounds float, float* [[A_BUF]], i64 [[IDX]]
+// CHECK: [[IDX:%.+]] = mul nsw i64 [[BASE_IDX]], [[NUM_ELEMS:%.+]]
+// CHECK: [[A_BUF_IDX:%.+]] = getelementptr inbounds float, float* [[A_BUF:%.+]], i64 [[IDX]]
 // CHECK: [[A_PRIV:%.+]] = getelementptr inbounds [10 x float], [10 x float]* [[A_PRIV_ADDR:%.+]], i64 0, i64 0
 // CHECK: [[BYTES:%.+]] = mul nuw i64 [[NUM_ELEMS:%.+]], 4
 // CHECK: [[DEST:%.+]] = bitcast float* [[A_BUF_IDX]] to i8*
@@ -194,7 +193,7 @@
 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}[[DEST]], i8* {{.*}}[[SRC]], i64 [[BYTES]], i1 false)
 
 // b_buffer[i] = b_priv;
-// CHECK: [[B_BUF_IDX:%.+]] = getelementptr inbounds double, double* [[B_BUF]], i64 [[BASE_IDX]]
+// CHECK: [[B_BUF_IDX:%.+]] = getelementptr 

[PATCH] D99501: ignore -flto= options recognized by GCC

2021-04-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D99501#2679394 , @doko wrote:

> here in the same place, or in a different merge request?

This one is closed now I think, so a new review would be ideal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99501

___
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-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Mostly just nits from me, but the attribute portions look good to me.




Comment at: clang/include/clang/AST/IgnoreExpr.h:127
+  if (CCE && CCE->isElidable() && !isa(CCE)) {
+auto NumArgs = CCE->getNumArgs();
+if ((NumArgs == 1 ||





Comment at: clang/lib/Sema/SemaStmt.cpp:628
+
+  const CallExpr *CE =
+  dyn_cast_or_null(IgnoreParenImplicitAsWritten(Ex));





Comment at: clang/lib/Sema/SemaStmt.cpp:636-637
+
+  if (!CE->getCalleeDecl()) {
+assert(hasUncompilableErrorOccurred() && "expected previous error");
+return false;

This worries me slightly -- not all `CallExpr` objects have a callee 
declaration 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/Expr.cpp#L1367). 
That said, I'm struggling to come up with an example that isn't covered so this 
may be fine.



Comment at: clang/lib/Sema/SemaStmt.cpp:641
+
+  if (const ExprWithCleanups *EWC = dyn_cast(Ex)) {
+if (EWC->cleanupsHaveSideEffects()) {





Comment at: clang/lib/Sema/SemaStmt.cpp:655
+
+  const FunctionDecl *CallerDecl = dyn_cast(CurContext);
+





Comment at: clang/lib/Sema/SemaStmt.cpp:659
+   bool IsCallee) -> bool {
+if (isa(CMD) || isa(CMD)) {
+  Diag(St->getBeginLoc(), diag::err_musttail_structors_forbidden) << 





Comment at: clang/lib/Sema/SemaStmt.cpp:682
+return false;
+  } else if (const CXXMethodDecl *CMD = dyn_cast(CurContext)) {
+// Caller is a class/struct method.





Comment at: clang/lib/Sema/SemaStmt.cpp:700
+// Call is: obj->*method_ptr or obj.*method_ptr
+const MemberPointerType *MPT = VD->getType()->castAs();
+CalleeType.This = QualType(MPT->getClass(), 0);

It'd be better not to go through the cast machinery twice -- you cast to the 
`MemberPointerType` and then cast to the same thing again (but in a different 
way).



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:214
+SourceRange Range) {
+  MustTailAttr MTA(S.Context, A);
+

This can be removed entirely.


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] D99501: ignore -flto= options recognized by GCC

2021-04-09 Thread Matthias Klose via Phabricator via cfe-commits
doko added a comment.

here in the same place, or in a different merge request?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99501

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


[PATCH] D93031: Enable fexec-charset option

2021-04-09 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 336417.
abhina.sreeskantharajan added a comment.

Accidentally added dependent patch in this one. Removing that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93031

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/LiteralConverter.h
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/LiteralConverter.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CodeGen/systemz-charset.c
  clang/test/CodeGen/systemz-charset.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1046,6 +1046,13 @@
   return Tmp.split('-').second;  // Strip second component
 }
 
+// System charset on z/OS is IBM-1047 and UTF-8 otherwise
+StringRef Triple::getSystemCharset() const {
+  if (getOS() == llvm::Triple::ZOS)
+return "IBM-1047";
+  return "UTF-8";
+}
+
 static unsigned EatNumber(StringRef ) {
   assert(!Str.empty() && isDigit(Str[0]) && "Not a number");
   unsigned Result = 0;
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -397,6 +397,9 @@
   /// if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// getSystemCharset - Get the system charset of the triple.
+  StringRef getSystemCharset() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -209,8 +209,14 @@
 // RUN: %clang -### -S -finput-charset=iso-8859-1 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-CHARSET %s
 // CHECK-INVALID-CHARSET: error: invalid value 'iso-8859-1' in '-finput-charset=iso-8859-1'
 
-// RUN: %clang -### -S -fexec-charset=iso-8859-1 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-INPUT-CHARSET %s
-// CHECK-INVALID-INPUT-CHARSET: error: invalid value 'iso-8859-1' in '-fexec-charset=iso-8859-1'
+// RUN: %clang -### -S -fexec-charset=invalid-charset -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-INPUT-CHARSET %s
+// CHECK-INVALID-INPUT-CHARSET: error: invalid value 'invalid-charset' in '-fexec-charset=invalid-charset'
+
+// Test that we support the following exec charsets.
+// RUN: %clang -### -S -fexec-charset=UTF-8 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: %clang -### -S -fexec-charset=ISO8859-1 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// RUN: %clang -### -S -fexec-charset=IBM-1047 -o /dev/null %s 2>&1 | FileCheck --check-prefix=INVALID %s
+// INVALID-NOT: error: invalid value
 
 // Test that we don't error on these.
 // RUN: %clang -### -S -Werror\
@@ -224,7 +230,7 @@
 // RUN: -fident -fno-ident\
 // RUN: -fimplicit-templates -fno-implicit-templates  \
 // RUN: -finput-charset=UTF-8 \
-// RUN: -fexec-charset=UTF-8 \
+// RUN: -fexec-charset=UTF-8  \
 // RUN: -fivopts -fno-ivopts  \
 // RUN: -fnon-call-exceptions -fno-non-call-exceptions\
 // RUN: -fpermissive -fno-permissive  \
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -210,10 +210,11 @@
 // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s
 // source-charset-utf-16: invalid value 'utf-16' in '/source-charset:utf-16'
 
-// /execution-charset: should warn on everything except UTF-8.
-// RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-utf-16 %s
-// execution-charset-utf-16: invalid value 'utf-16' in '/execution-charset:utf-16'
+// /execution-charset: should warn on invalid charsets.
+// RUN: %clang_cl /execution-charset:invalid-charset -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-invalid %s
+// execution-charset-invalid: invalid value 'invalid-charset' in 

[PATCH] D93031: Enable fexec-charset option

2021-04-09 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 336416.
abhina.sreeskantharajan added a comment.

Rebase + fix CharLiteralParser endian issue by saving the char to a char 
variable first and then creating a StringRef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93031

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/LiteralConverter.h
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/CMakeLists.txt
  clang/lib/Lex/LiteralConverter.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/CodeGen/systemz-charset.c
  clang/test/CodeGen/systemz-charset.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/clang_f_opts.c
  llvm/cmake/config-ix.cmake
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Config/config.h.cmake
  llvm/include/llvm/Support/CharSet.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CharSet.cpp
  llvm/lib/Support/Triple.cpp
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/CharSetTest.cpp

Index: llvm/unittests/Support/CharSetTest.cpp
===
--- /dev/null
+++ llvm/unittests/Support/CharSetTest.cpp
@@ -0,0 +1,191 @@
+//===- unittests/Support/CharSetTest.cpp - Charset conversion tests ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/CharSet.h"
+#include "llvm/ADT/SmallString.h"
+#include "gtest/gtest.h"
+using namespace llvm;
+
+namespace {
+
+// String "Hello World!"
+static const char HelloA[] =
+"\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x21\x0a";
+static const char HelloE[] =
+"\xC8\x85\x93\x93\x96\x40\xE6\x96\x99\x93\x84\x5A\x15";
+
+// String "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+static const char ABCStrA[] =
+"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52"
+"\x53\x54\x55\x56\x57\x58\x59\x5A\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A"
+"\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A";
+static const char ABCStrE[] =
+"\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9"
+"\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91"
+"\x92\x93\x94\x95\x96\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9";
+
+// String "¡¢£AÄÅÆEÈÉÊaàáâãäeèéêë"
+static const char AccentUTF[] =
+"\xc2\xa1\xc2\xa2\xc2\xa3\x41\xc3\x84\xc3\x85\xc3\x86\x45\xc3\x88\xc3\x89"
+"\xc3\x8a\x61\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4\x65\xc3\xa8\xc3\xa9"
+"\xc3\xaa\xc3\xab";
+static const char AccentE[] = "\xaa\x4a\xb1\xc1\x63\x67\x9e\xc5\x74\x71\x72"
+  "\x81\x44\x45\x42\x46\x43\x85\x54\x51\x52\x53";
+
+TEST(CharSet, FromASCII) {
+  // Hello string.
+  StringRef Src(HelloA);
+  SmallString<64> Dst;
+
+  CharSetConverter Conv = CharSetConverter::create(
+  CharSetConverter::CS_LATIN1, CharSetConverter::CS_IBM1047);
+  std::error_code EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(HelloE, static_cast(Dst).c_str());
+
+  // ABC string.
+  Src = ABCStrA;
+  Dst.clear();
+  EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(ABCStrE, static_cast(Dst).c_str());
+}
+
+TEST(CharSet, ToASCII) {
+  // Hello string.
+  StringRef Src(HelloE);
+  SmallString<64> Dst;
+
+  CharSetConverter Conv = CharSetConverter::create(CharSetConverter::CS_IBM1047,
+   CharSetConverter::CS_LATIN1);
+  std::error_code EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(HelloA, static_cast(Dst).c_str());
+
+  // ABC string.
+  Src = ABCStrE;
+  Dst.clear();
+  EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(ABCStrA, static_cast(Dst).c_str());
+}
+
+TEST(CharSet, FromUTF8) {
+  // Hello string.
+  StringRef Src(HelloA);
+  SmallString<64> Dst;
+
+  CharSetConverter Conv = CharSetConverter::create(
+  CharSetConverter::CS_UTF8, CharSetConverter::CS_IBM1047);
+  std::error_code EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(HelloE, static_cast(Dst).c_str());
+
+  // ABC string.
+  Src = ABCStrA;
+  Dst.clear();
+  EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(ABCStrE, static_cast(Dst).c_str());
+
+  // Accent string.
+  Src = AccentUTF;
+  Dst.clear();
+  EC = Conv.convert(Src, Dst);
+  EXPECT_TRUE(!EC);
+  EXPECT_STREQ(AccentE, static_cast(Dst).c_str());
+}
+
+TEST(CharSet, ToUTF8) {
+  // Hello string.
+  StringRef 

[PATCH] D100129: Tiny format fix

2021-04-09 Thread Nathan Sidwell via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92498264269c: [clang] Tiny format fix (authored by urnathan).

Repository:
  rG LLVM Github Monorepo

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

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


[clang] 9249826 - [clang] Tiny format fix

2021-04-09 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2021-04-09T05:19:51-07:00
New Revision: 92498264269c86fd0f5645d184d9f7e1c0c3acdf

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

LOG: [clang] Tiny format fix

Misindented close brace.

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

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 017550cdf34f..498036368c19 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -132,7 +132,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
   << 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] D99839: [C++, test] Fix typo in NSS* vars

2021-04-09 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99839

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


[PATCH] D98635: [libtooling][clang-tidy] Fix diagnostics not respecting and highlighting fed SourceRanges

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

This continues to LGTM, so I'm accepting it. If @alexfh has any remaining 
concerns, hopefully he can raise them quickly or we can handle them 
post-commit. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98635

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


[clang-tools-extra] 3b4936b - [clangd] Add --check-lines to restrict --check to specific lines

2021-04-09 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-04-09T13:47:20+02:00
New Revision: 3b4936ba290594cda4e53169958fe11c83119657

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

LOG: [clangd] Add --check-lines to restrict --check to specific lines

This will allow us to add code completion, which is too expensive at
every token, to --check too.

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

Added: 
clang-tools-extra/clangd/test/check-lines.test

Modified: 
clang-tools-extra/clangd/tool/Check.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/check-lines.test 
b/clang-tools-extra/clangd/test/check-lines.test
new file mode 100644
index ..bfd30dd6104f
--- /dev/null
+++ b/clang-tools-extra/clangd/test/check-lines.test
@@ -0,0 +1,15 @@
+// RUN: cp %s %t.cpp
+// RUN: not clangd -check=%t.cpp -check-lines=6-14 2>&1 | FileCheck 
-strict-whitespace %s
+// RUN: not clangd -check=%t.cpp -check-lines=14 2>&1 | FileCheck 
-strict-whitespace %s
+
+// CHECK: Testing on source file {{.*}}check-lines.test
+// CHECK: internal (cc1) args are: -cc1
+// CHECK: Building preamble...
+// CHECK: Building AST...
+// CHECK: Testing features at each token
+// CHECK: tweak: ExpandAutoType ==> FAIL
+// CHECK: All checks completed, 1 errors
+
+void fun();
+auto x = fun; // This line is tested
+auto y = fun; // This line is not tested

diff  --git a/clang-tools-extra/clangd/tool/Check.cpp 
b/clang-tools-extra/clangd/tool/Check.cpp
index 20b86daff8af..0138ae3eb13b 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -192,14 +192,19 @@ class Checker {
   }
 
   // Run AST-based features at each token in the file.
-  void testLocationFeatures() {
+  void testLocationFeatures(
+  llvm::function_ref ShouldCheckLine) {
 log("Testing features at each token (may be slow in large files)");
-auto SpelledTokens =
-
AST->getTokens().spelledTokens(AST->getSourceManager().getMainFileID());
+auto  = AST->getSourceManager();
+auto SpelledTokens = AST->getTokens().spelledTokens(SM.getMainFileID());
 for (const auto  : SpelledTokens) {
   unsigned Start = AST->getSourceManager().getFileOffset(Tok.location());
   unsigned End = Start + Tok.length();
   Position Pos = offsetToPosition(Inputs.Contents, Start);
+
+  if (!ShouldCheckLine(Pos))
+continue;
+
   // FIXME: dumping the tokens may leak sensitive code into bug reports.
   // Add an option to turn this off, once we decide how options work.
   vlog("  {0} {1}", Pos, Tok.text(AST->getSourceManager()));
@@ -229,8 +234,9 @@ class Checker {
 
 } // namespace
 
-bool check(llvm::StringRef File, const ThreadsafeFS ,
-   const ClangdLSPServer::Options ) {
+bool check(llvm::StringRef File,
+   llvm::function_ref ShouldCheckLine,
+   const ThreadsafeFS , const ClangdLSPServer::Options ) {
   llvm::SmallString<0> FakeFile;
   llvm::Optional Contents;
   if (File.empty()) {
@@ -254,7 +260,7 @@ bool check(llvm::StringRef File, const ThreadsafeFS ,
   if (!C.buildCommand(TFS) || !C.buildInvocation(TFS, Contents) ||
   !C.buildAST())
 return false;
-  C.testLocationFeatures();
+  C.testLocationFeatures(ShouldCheckLine);
 
   log("All checks completed, {0} errors", C.ErrCount);
   return C.ErrCount == 0;

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index c48821cba2c7..6dd13a503887 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -60,8 +60,9 @@ namespace clang {
 namespace clangd {
 
 // Implemented in Check.cpp.
-bool check(const llvm::StringRef File, const ThreadsafeFS ,
-   const ClangdLSPServer::Options );
+bool check(const llvm::StringRef File,
+   llvm::function_ref ShouldCheckLine,
+   const ThreadsafeFS , const ClangdLSPServer::Options );
 
 namespace {
 
@@ -347,6 +348,17 @@ opt CheckFile{
 ValueOptional,
 };
 
+opt CheckFileLines{
+"check-lines",
+cat(Misc),
+desc("If specified, limits the range of tokens in -check file on which "
+ "various features are tested. Example --check-lines=3-7 restricts "
+ "testing to lines 3 to 7 (inclusive) or --check-lines=5 to restrict "
+ "to one line. Default is testing entire file."),
+init(""),
+ValueOptional,
+};
+
 enum PCHStorageFlag { Disk, Memory };
 opt PCHStorage{
 "pch-storage",
@@ -883,10 +895,33 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
 llvm::SmallString<256> Path;
 llvm::sys::fs::real_path(CheckFile, Path, /*expand_tilde=*/true);
 log("Entering check mode (no LSP 

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

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

In D99037#2679131 , @fhahn wrote:

> In D99037#2678848 , @SaurabhJha 
> wrote:
>
>> In D99037#2678779 , @fhahn wrote:
>>
>>> 
>>
>> Will create a new patch to address your last comments
>
> Can you directly update this one? I'll commit it after the update.

Sure, done. I did not know I could change the patch after its accepted.


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] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

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

Replace `matrices` with `matrixes` in comments and rewrite the comment about 
element types


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;
+  ix5x5 m4;
+  fx5x5 

[PATCH] D99812: [PowerPC] [GlobalISel] Implementation of formal arguments lowering in the IRTranslator for the PPC backend

2021-04-09 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 336249.
gandhi21299 added a comment.

- enclosing classes in PPCCallLowering,h within the llvm namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99812

Files:
  llvm/lib/Target/PowerPC/GISel/PPCCallLowering.cpp
  llvm/lib/Target/PowerPC/GISel/PPCCallLowering.h
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-args-lowering.ll
  llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-ret.ll

Index: llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-ret.ll
===
--- llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-ret.ll
+++ /dev/null
@@ -1,7 +0,0 @@
-; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -global-isel -verify-machineinstrs -stop-after=irtranslator < %s | FileCheck %s
-
-; CHECK: name: f
-; CHECK: BLR8
-define void @f() {
-  ret void
-}
Index: llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-args-lowering.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/GlobalISel/irtranslator-args-lowering.ll
@@ -0,0 +1,188 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -global-isel -verify-machineinstrs -stop-after=irtranslator < %s | FileCheck %s
+
+%struct.A = type { i8, float, i32, i32, i32 }
+
+define void @f() {
+  ; CHECK-LABEL: name: f
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+  ret void
+}
+
+define void @foo1(i32 %x){
+  ; CHECK-LABEL: name: foo1
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $x3
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x3
+  ; CHECK:   [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+ret void
+}
+
+define void @foo2(i64 %x){
+  ; CHECK-LABEL: name: foo2
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $x3
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x3
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+ret void
+}
+
+define void @foo3(<7 x i8> %x) {
+  ; CHECK-LABEL: name: foo3
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $x3, $x4, $x5, $x6, $x7, $x8, $x9
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x3
+  ; CHECK:   [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $x4
+  ; CHECK:   [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(s64) = COPY $x5
+  ; CHECK:   [[TRUNC2:%[0-9]+]]:_(s32) = G_TRUNC [[COPY2]](s64)
+  ; CHECK:   [[COPY3:%[0-9]+]]:_(s64) = COPY $x6
+  ; CHECK:   [[TRUNC3:%[0-9]+]]:_(s32) = G_TRUNC [[COPY3]](s64)
+  ; CHECK:   [[COPY4:%[0-9]+]]:_(s64) = COPY $x7
+  ; CHECK:   [[TRUNC4:%[0-9]+]]:_(s32) = G_TRUNC [[COPY4]](s64)
+  ; CHECK:   [[COPY5:%[0-9]+]]:_(s64) = COPY $x8
+  ; CHECK:   [[TRUNC5:%[0-9]+]]:_(s32) = G_TRUNC [[COPY5]](s64)
+  ; CHECK:   [[COPY6:%[0-9]+]]:_(s64) = COPY $x9
+  ; CHECK:   [[TRUNC6:%[0-9]+]]:_(s32) = G_TRUNC [[COPY6]](s64)
+  ; CHECK:   [[BUILD_VECTOR:%[0-9]+]]:_(<7 x s32>) = G_BUILD_VECTOR [[TRUNC]](s32), [[TRUNC1]](s32), [[TRUNC2]](s32), [[TRUNC3]](s32), [[TRUNC4]](s32), [[TRUNC5]](s32), [[TRUNC6]](s32)
+  ; CHECK:   [[TRUNC7:%[0-9]+]]:_(<7 x s8>) = G_TRUNC [[BUILD_VECTOR]](<7 x s32>)
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+  ret void
+}
+
+define void @foo_notrunc(<7 x i64> %x) {
+  ; CHECK-LABEL: name: foo_notrunc
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $x3, $x4, $x5, $x6, $x7, $x8, $x9
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x3
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $x4
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(s64) = COPY $x5
+  ; CHECK:   [[COPY3:%[0-9]+]]:_(s64) = COPY $x6
+  ; CHECK:   [[COPY4:%[0-9]+]]:_(s64) = COPY $x7
+  ; CHECK:   [[COPY5:%[0-9]+]]:_(s64) = COPY $x8
+  ; CHECK:   [[COPY6:%[0-9]+]]:_(s64) = COPY $x9
+  ; CHECK:   [[BUILD_VECTOR:%[0-9]+]]:_(<7 x s64>) = G_BUILD_VECTOR [[COPY]](s64), [[COPY1]](s64), [[COPY2]](s64), [[COPY3]](s64), [[COPY4]](s64), [[COPY5]](s64), [[COPY6]](s64)
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+  ret void
+}
+
+define void @foo_pt(<7 x i8>* %x) {
+  ; CHECK-LABEL: name: foo_pt
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $x3
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x3
+  ; CHECK:   BLR8 implicit $lr8, implicit $rm
+  ret void
+}
+
+define dso_local void @foo_struct(%struct.A %a) #0 {
+  ; CHECK-LABEL: name: foo_struct
+  ; CHECK: bb.1.entry:
+  ; CHECK:   liveins: $f1, $x3, $x4, $x5, $x6
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x3
+  ; CHECK:   [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY]](s64)
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $f1
+  ; CHECK:   [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(s64) = COPY $x4
+  ; CHECK:   [[TRUNC2:%[0-9]+]]:_(s32) = G_TRUNC [[COPY2]](s64)

[PATCH] D99812: [PowerPC] [GlobalISel] Implementation of formal arguments lowering in the IRTranslator for the PPC backend

2021-04-09 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

@arsenm Yea, I am sorry about that. Looks like I am still not using arc properly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99812

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


[PATCH] D99812: [PowerPC] [GlobalISel] Implementation of formal arguments lowering in the IRTranslator for the PPC backend

2021-04-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Attached wrong diff? There are a lot of unrelated files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99812

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


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

2021-04-09 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG189310a140fa: [AMDGPU] Allow -amdgpu-unsafe-fp-atomics to 
ignore denorm mode (authored by rampitec).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100072

Files:
  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

Index: llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
===
--- llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
+++ llvm/test/CodeGen/AMDGPU/global-atomics-fp.ll
@@ -171,26 +171,12 @@
 ; 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 lgkmcnt(0)
-; GFX90A-NEXT:s_load_dword s4, s[0:1], 0x0
-; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
-; GFX90A-NEXT:v_mov_b32_e32 v0, s4
-; GFX90A-NEXT:  BB1_1: ; %atomicrmw.start
-; GFX90A-NEXT:; =>This Inner Loop Header: Depth=1
-; GFX90A-NEXT:v_mov_b32_e32 v1, v0
-; GFX90A-NEXT:v_mov_b32_e32 v2, 0
-; GFX90A-NEXT:v_add_f32_e32 v0, 4.0, v1
+; GFX90A-NEXT:v_mov_b32_e32 v0, 0
+; GFX90A-NEXT:v_mov_b32_e32 v1, 4.0
 ; GFX90A-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0)
-; GFX90A-NEXT:global_atomic_cmpswap v0, v2, v[0:1], s[0:1] glc
+; GFX90A-NEXT:global_atomic_add_f32 v0, v0, v1, s[0:1] glc
 ; GFX90A-NEXT:s_waitcnt vmcnt(0)
 ; GFX90A-NEXT:buffer_wbinvl1_vol
-; GFX90A-NEXT:v_cmp_eq_u32_e32 vcc, v0, v1
-; GFX90A-NEXT:s_or_b64 s[2:3], vcc, s[2:3]
-; GFX90A-NEXT:s_andn2_b64 exec, exec, s[2:3]
-; GFX90A-NEXT:s_cbranch_execnz BB1_1
-; GFX90A-NEXT:  ; %bb.2: ; %atomicrmw.end
-; GFX90A-NEXT:s_or_b64 exec, exec, s[2:3]
 ; GFX90A-NEXT:global_store_dword v[0:1], v0, off
 ; GFX90A-NEXT:s_endpgm
 ;
@@ -330,49 +316,23 @@
 ; GFX908-LABEL: global_atomic_fadd_noret_f32_ieee:
 ; GFX908:   ; %bb.0:
 ; GFX908-NEXT:s_load_dwordx2 s[0:1], s[0:1], 0x24
-; GFX908-NEXT:s_mov_b64 s[2:3], 0
-; GFX908-NEXT:s_waitcnt lgkmcnt(0)
-; GFX908-NEXT:s_load_dword s4, s[0:1], 0x0
-; GFX908-NEXT:s_waitcnt lgkmcnt(0)
-; GFX908-NEXT:v_mov_b32_e32 v1, s4
-; GFX908-NEXT:  BB3_1: ; %atomicrmw.start
-; GFX908-NEXT:; =>This Inner Loop Header: Depth=1
-; GFX908-NEXT:v_mov_b32_e32 v2, 0
-; GFX908-NEXT:v_add_f32_e32 v0, 4.0, v1
+; GFX908-NEXT:v_mov_b32_e32 v0, 0
+; GFX908-NEXT:v_mov_b32_e32 v1, 4.0
 ; GFX908-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0)
-; GFX908-NEXT:global_atomic_cmpswap v0, v2, v[0:1], s[0:1] glc
+; GFX908-NEXT:global_atomic_add_f32 v0, v1, s[0:1]
 ; GFX908-NEXT:s_waitcnt vmcnt(0)
 ; GFX908-NEXT:buffer_wbinvl1_vol
-; GFX908-NEXT:v_cmp_eq_u32_e32 vcc, v0, v1
-; GFX908-NEXT:s_or_b64 s[2:3], vcc, s[2:3]
-; GFX908-NEXT:v_mov_b32_e32 v1, v0
-; GFX908-NEXT:s_andn2_b64 exec, exec, s[2:3]
-; GFX908-NEXT:s_cbranch_execnz BB3_1
-; GFX908-NEXT:  ; %bb.2: ; %atomicrmw.end
 ; GFX908-NEXT:s_endpgm
 ;
 ; GFX90A-LABEL: global_atomic_fadd_noret_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 lgkmcnt(0)
-; GFX90A-NEXT:s_load_dword s4, s[0:1], 0x0
-; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
-; GFX90A-NEXT:v_mov_b32_e32 v1, s4
-; GFX90A-NEXT:  BB3_1: ; %atomicrmw.start
-; GFX90A-NEXT:; =>This Inner Loop Header: Depth=1
-; GFX90A-NEXT:v_mov_b32_e32 v2, 0
-; GFX90A-NEXT:v_add_f32_e32 v0, 4.0, v1
+; GFX90A-NEXT:v_mov_b32_e32 v0, 0
+; GFX90A-NEXT:v_mov_b32_e32 v1, 4.0
 ; GFX90A-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0)
-; GFX90A-NEXT:global_atomic_cmpswap v0, v2, v[0:1], s[0:1] glc
+; GFX90A-NEXT:global_atomic_add_f32 v0, v1, s[0:1]
 ; GFX90A-NEXT:s_waitcnt vmcnt(0)
 ; GFX90A-NEXT:buffer_wbinvl1_vol
-; GFX90A-NEXT:v_cmp_eq_u32_e32 vcc, v0, v1
-; GFX90A-NEXT:s_or_b64 s[2:3], vcc, s[2:3]
-; GFX90A-NEXT:v_mov_b32_e32 v1, v0
-; GFX90A-NEXT:s_andn2_b64 exec, exec, s[2:3]
-; GFX90A-NEXT:s_cbranch_execnz BB3_1
-; GFX90A-NEXT:  ; %bb.2: ; %atomicrmw.end
 ; GFX90A-NEXT:s_endpgm
 ;
 ; GFX10-LABEL: global_atomic_fadd_noret_f32_ieee:
Index: llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
===
--- llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
+++ llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
@@ -490,25 +490,13 @@
 ; 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 

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

2021-04-09 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Sorry for the delay! Looks like this doesn't have any drawbacks for any other 
debuggers, but helps dbx.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


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

2021-04-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D99037#2678848 , @SaurabhJha wrote:

> In D99037#2678779 , @fhahn wrote:
>
>> 
>
> Will create a new patch to address your last comments

Can you directly update this one? I'll commit it after the update.


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] D98635: [libtooling][clang-tidy] Fix diagnostics not respecting and highlighting fed SourceRanges

2021-04-09 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98635

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


[clang] af67deb - [OpenCL] Simplify InsertOCLBuiltinDeclarationsFromTable

2021-04-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-04-09T11:54:15+01:00
New Revision: af67deb005cae4e87109d8ad534446b300351483

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

LOG: [OpenCL] Simplify InsertOCLBuiltinDeclarationsFromTable

 - Use a range-based for loop.  This will help a later patch to skip
   prototypes that use an unavailable return type or argument type.

 - Replace a dyn_cast with a cast, as we are only dealing with
   FunctionProtoType Types here.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index fef96b2eb11f..92efd427ba6c 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -850,28 +850,24 @@ static void InsertOCLBuiltinDeclarationsFromTable(Sema 
, LookupResult ,
 DeclContext *Parent = Context.getTranslationUnitDecl();
 FunctionDecl *NewOpenCLBuiltin;
 
-for (unsigned Index = 0; Index < GenTypeMaxCnt; Index++) {
+for (const auto  : FunctionList) {
   NewOpenCLBuiltin = FunctionDecl::Create(
-  Context, Parent, Loc, Loc, II, FunctionList[Index],
-  /*TInfo=*/nullptr, SC_Extern, false,
-  FunctionList[Index]->isFunctionProtoType());
+  Context, Parent, Loc, Loc, II, FTy, /*TInfo=*/nullptr, SC_Extern,
+  false, FTy->isFunctionProtoType());
   NewOpenCLBuiltin->setImplicit();
 
   // Create Decl objects for each parameter, adding them to the
   // FunctionDecl.
-  if (const FunctionProtoType *FP =
-  dyn_cast(FunctionList[Index])) {
-SmallVector ParmList;
-for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
-  ParmVarDecl *Parm = ParmVarDecl::Create(
-  Context, NewOpenCLBuiltin, SourceLocation(), SourceLocation(),
-  nullptr, FP->getParamType(IParm),
-  /*TInfo=*/nullptr, SC_None, nullptr);
-  Parm->setScopeInfo(0, IParm);
-  ParmList.push_back(Parm);
-}
-NewOpenCLBuiltin->setParams(ParmList);
+  const auto *FP = cast(FTy);
+  SmallVector ParmList;
+  for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
+ParmVarDecl *Parm = ParmVarDecl::Create(
+Context, NewOpenCLBuiltin, SourceLocation(), SourceLocation(),
+nullptr, FP->getParamType(IParm), nullptr, SC_None, nullptr);
+Parm->setScopeInfo(0, IParm);
+ParmList.push_back(Parm);
   }
+  NewOpenCLBuiltin->setParams(ParmList);
 
   // Add function attributes.
   if (OpenCLBuiltin.IsPure)



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


[PATCH] D100092: [clang-tidy] cppcoreguidelines-declare-loop-variable-in-the-initializer: a new check

2021-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I'd argue this check isn't following the enforcement specified in the relevant 
guideline:

  Enforcement:
  Warn when a variable modified inside the for-statement is declared outside 
the loop and not being used outside the loop.

All this is checking is that there is a declStmt in the for stmt, it doesn't 
even have to be a relevant declaration, this code would be considered ok by the 
implementation in here.

  int I = 0;
  for (int Unused = 0; I < 10; ++I) {}

Ideally you want to check for variables modified in the condition or iteration 
expression that aren't declared in the init statement.
To be fully compliant with the wording you would also need to ensure the 
variable isn't referenced outside the loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100092

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


[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-04-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good!




Comment at: clang/lib/AST/Expr.cpp:1386
   QualType CalleeType = Callee->getType();
+
   if (const auto *FnTypePtr = CalleeType->getAs()) {

nit: looks like an accident change, remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95244

___
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-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

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] D100148: [Driver] Fix compiler-rt lookup for x32

2021-04-09 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz accepted this revision.
glaubitz added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/sanitizer-ld.c:309
 // CHECK-UBSAN-LINUX: "-lpthread"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime %s -### -o %t.o 
2>&1 \

glaubitz wrote:
> hvdijk wrote:
> > glaubitz wrote:
> > > Do we need want to run the test for i386 anymore?
> > This test just somewhat arbitrarily distributes the different sanitizer 
> > modules over i386 and x86_64 for testing rather than testing each module 
> > for each arch, so I figured there was no harm in changing one of them to 
> > x86_64-linux-gnux32. i386 is still getting tested elsewhere.
> Do we _not_, not _need_. Sorry.
OK, thanks. Then I will mark this as approved from my side.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

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


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

2021-04-09 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added inline comments.



Comment at: clang/test/Driver/sanitizer-ld.c:309
 // CHECK-UBSAN-LINUX: "-lpthread"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime %s -### -o %t.o 
2>&1 \

glaubitz wrote:
> Do we need want to run the test for i386 anymore?
This test just somewhat arbitrarily distributes the different sanitizer modules 
over i386 and x86_64 for testing rather than testing each module for each arch, 
so I figured there was no harm in changing one of them to x86_64-linux-gnux32. 
i386 is still getting tested elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

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


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

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



Comment at: clang/test/Driver/sanitizer-ld.c:309
 // CHECK-UBSAN-LINUX: "-lpthread"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime %s -### -o %t.o 
2>&1 \

glaubitz wrote:
> Do we need want to run the test for i386 anymore?
Do we _not_, not _need_. Sorry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

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


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

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



Comment at: clang/test/Driver/sanitizer-ld.c:309
 // CHECK-UBSAN-LINUX: "-lpthread"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime %s -### -o %t.o 
2>&1 \

Do we need want to run the test for i386 anymore?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

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


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

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

Thanks, this finally fixes the build for me. I wasn't aware that there was a 
`getArchNameForCompilerRTLib()` function in clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100148

___
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-09 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

In D97462#2678889 , @jansvoboda11 
wrote:

> In D97462#2677130 , @arichardson 
> wrote:
>
>> 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?
>
> We currently don't have the infrastructure to compare `CompilerInvocation` 
> instances directly. Instead we rely on good test coverage of command line 
> options: if the round-tripped `CompilerInvocation` doesn't contain the 
> option, tests will fail. You can then check the generated command lines by 
> passing `-Rround-trip-cc1-args` to the failing CC1 invocation.
>
> There was an attempt to generate `operator==` for `CompilerInvocation` and 
> assert when the round-tripped instance isn't equal to the original, as you 
> suggest. This is the patch that started by moving members to definition 
> databases, but it got reverted: D86290 .

Thanks, that would have caught the problem. Fortunately we don't add too many 
options, so I'll just go through them all and check that they are also handled 
in the Generate* functions.


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] D97462: [clang][cli] Round-trip cc1 arguments in assert builds

2021-04-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D97462#2677130 , @arichardson wrote:

> 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?

We currently don't have the infrastructure to compare `CompilerInvocation` 
instances directly. Instead we rely on good test coverage of command line 
options: if the round-tripped `CompilerInvocation` doesn't contain the option, 
tests will fail. You can then check the generated command lines by passing 
`-Rround-trip-cc1-args` to the failing CC1 invocation.

There was an attempt to generate `operator==` for `CompilerInvocation` and 
assert when the round-tripped instance isn't equal to the original, as you 
suggest. This is the patch that started by moving members to definition 
databases, but it got reverted: D86290 .


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] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

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

In D99037#2678779 , @fhahn wrote:

> 

Will create a new patch to address your last comments


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] D99949: [AMDGPU][OpenMP] Add amdgpu-arch tool to list AMD GPUs installed

2021-04-09 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 336353.
pdhaliwal marked an inline comment as done.
pdhaliwal added a comment.

Fix permissions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99949

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908
  clang/test/Driver/amdgpu-openmp-system-arch-fail.c
  clang/test/Driver/amdgpu-openmp-system-arch.c
  clang/tools/CMakeLists.txt
  clang/tools/amdgpu-arch/AMDGPUArch.cpp
  clang/tools/amdgpu-arch/CMakeLists.txt

Index: clang/tools/amdgpu-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/amdgpu-arch/CMakeLists.txt
@@ -0,0 +1,17 @@
+# //===--===//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //===--===//
+
+find_package(hsa-runtime64 QUIET 1.2.0 HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
+if (NOT ${hsa-runtime64_FOUND})
+  message(STATUS "Not building amdgpu-arch: hsa-runtime64 not found")
+  return()
+endif()
+
+add_clang_tool(amdgpu-arch AMDGPUArch.cpp)
+
+clang_target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64)
Index: clang/tools/amdgpu-arch/AMDGPUArch.cpp
===
--- /dev/null
+++ clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -0,0 +1,59 @@
+//===- AMDGPUArch.cpp - list AMDGPU installed --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a tool for detecting name of AMDGPU installed in system
+// using HSA. This tool is used by AMDGPU OpenMP driver.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+static hsa_status_t iterateAgentsCallback(hsa_agent_t Agent, void *Data) {
+  hsa_device_type_t DeviceType;
+  hsa_status_t Status =
+  hsa_agent_get_info(Agent, HSA_AGENT_INFO_DEVICE, );
+
+  // continue only if device type if GPU
+  if (Status != HSA_STATUS_SUCCESS || DeviceType != HSA_DEVICE_TYPE_GPU) {
+return Status;
+  }
+
+  std::vector *GPUs =
+  static_cast *>(Data);
+  char GPUName[64];
+  Status = hsa_agent_get_info(Agent, HSA_AGENT_INFO_NAME, GPUName);
+  if (Status != HSA_STATUS_SUCCESS) {
+return Status;
+  }
+  GPUs->push_back(GPUName);
+  return HSA_STATUS_SUCCESS;
+}
+
+int main() {
+  hsa_status_t Status = hsa_init();
+  if (Status != HSA_STATUS_SUCCESS) {
+return 1;
+  }
+
+  std::vector GPUs;
+  Status = hsa_iterate_agents(iterateAgentsCallback, );
+  if (Status != HSA_STATUS_SUCCESS) {
+return 1;
+  }
+
+  for (const auto  : GPUs)
+printf("%s\n", GPU.c_str());
+
+  if (GPUs.size() < 1)
+return 1;
+
+  hsa_shut_down();
+  return 0;
+}
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -43,3 +43,5 @@
 
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
+
+add_clang_subdirectory(amdgpu-arch)
Index: clang/test/Driver/amdgpu-openmp-system-arch.c
===
--- /dev/null
+++ clang/test/Driver/amdgpu-openmp-system-arch.c
@@ -0,0 +1,15 @@
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_gfx906 %s 2>&1 \
+// RUN:   | FileCheck %s
+// CHECK: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "[[GFX:gfx906]]"
+// CHECK: llvm-link{{.*}}"-o" "{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc"
+// CHECK: llc{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" "-mtriple=amdgcn-amd-amdhsa" "-mcpu=[[GFX]]" "-filetype=obj" "-o"{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-{{.*}}.o"
+
+// case when amdgpu_arch returns multiple gpus but of same arch
+// RUN:   

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

2021-04-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

The `CodeGen` tests you added are failing pre-merge checks. This is most likely 
because we recently (D97462 ) started 
verifying that all all CC1 command line options can be serialized from a 
`CompilerInvocation` instance. To reproduce this locally, you'd need to build 
with assertions or manually set `-DCLANG_ROUND_TRIP_CC1_ARGS=ON` when building 
with CMake.

The solution would be to add complementary code that generates 
`"-f[no-]sanitize-merge-traps"` from `CodeGenOptions::SanitizeMergeTraps` in 
`CompilerInvocation::GenerateCodeGenArgs`.

More info is here 
https://clang.llvm.org/docs/InternalsManual.html#compiler-invocation and in the 
following sections.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100150

___
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-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

> LGTM, thanks for working on this!

Thanks so much Florian. Can you please also commit this on my behalf as I don't 
have commit access? Cheers.


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] D99949: [AMDGPU][OpenMP] Add amdgpu-arch tool to list AMD GPUs installed

2021-04-09 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 336351.
pdhaliwal added a comment.

Added tests for the failing cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99949

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906
  clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908
  clang/test/Driver/amdgpu-openmp-system-arch-fail.c
  clang/test/Driver/amdgpu-openmp-system-arch.c
  clang/tools/CMakeLists.txt
  clang/tools/amdgpu-arch/AMDGPUArch.cpp
  clang/tools/amdgpu-arch/CMakeLists.txt

Index: clang/tools/amdgpu-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/amdgpu-arch/CMakeLists.txt
@@ -0,0 +1,17 @@
+# //===--===//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //===--===//
+
+find_package(hsa-runtime64 QUIET 1.2.0 HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
+if (NOT ${hsa-runtime64_FOUND})
+  message(STATUS "Not building amdgpu-arch: hsa-runtime64 not found")
+  return()
+endif()
+
+add_clang_tool(amdgpu-arch AMDGPUArch.cpp)
+
+clang_target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64)
Index: clang/tools/amdgpu-arch/AMDGPUArch.cpp
===
--- /dev/null
+++ clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -0,0 +1,59 @@
+//===- AMDGPUArch.cpp - list AMDGPU installed --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a tool for detecting name of AMDGPU installed in system
+// using HSA. This tool is used by AMDGPU OpenMP driver.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+static hsa_status_t iterateAgentsCallback(hsa_agent_t Agent, void *Data) {
+  hsa_device_type_t DeviceType;
+  hsa_status_t Status =
+  hsa_agent_get_info(Agent, HSA_AGENT_INFO_DEVICE, );
+
+  // continue only if device type if GPU
+  if (Status != HSA_STATUS_SUCCESS || DeviceType != HSA_DEVICE_TYPE_GPU) {
+return Status;
+  }
+
+  std::vector *GPUs =
+  static_cast *>(Data);
+  char GPUName[64];
+  Status = hsa_agent_get_info(Agent, HSA_AGENT_INFO_NAME, GPUName);
+  if (Status != HSA_STATUS_SUCCESS) {
+return Status;
+  }
+  GPUs->push_back(GPUName);
+  return HSA_STATUS_SUCCESS;
+}
+
+int main() {
+  hsa_status_t Status = hsa_init();
+  if (Status != HSA_STATUS_SUCCESS) {
+return 1;
+  }
+
+  std::vector GPUs;
+  Status = hsa_iterate_agents(iterateAgentsCallback, );
+  if (Status != HSA_STATUS_SUCCESS) {
+return 1;
+  }
+
+  for (const auto  : GPUs)
+printf("%s\n", GPU.c_str());
+
+  if (GPUs.size() < 1)
+return 1;
+
+  hsa_shut_down();
+  return 0;
+}
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -43,3 +43,5 @@
 
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
+
+add_clang_subdirectory(amdgpu-arch)
Index: clang/test/Driver/amdgpu-openmp-system-arch.c
===
--- /dev/null
+++ clang/test/Driver/amdgpu-openmp-system-arch.c
@@ -0,0 +1,15 @@
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_gfx906 %s 2>&1 \
+// RUN:   | FileCheck %s
+// CHECK: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "[[GFX:gfx906]]"
+// CHECK: llvm-link{{.*}}"-o" "{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc"
+// CHECK: llc{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" "-mtriple=amdgcn-amd-amdhsa" "-mcpu=[[GFX]]" "-filetype=obj" "-o"{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-{{.*}}.o"
+
+// case when amdgpu_arch returns multiple gpus but of same arch
+// RUN:   %clang -### 

  1   2   >