[PATCH] D99308: [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

2021-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 333208.
MaskRay added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99308

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/linux-cross.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/unittests/ADT/TripleTest.cpp


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -111,6 +111,12 @@
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::Musl, T.getEnvironment());
 
+  T = Triple("x86_64-pc-linux-muslx32");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
+
   // PS4 has two spellings for the vendor.
   T = Triple("x86_64-scei-ps4");
   EXPECT_EQ(Triple::x86_64, T.getArch());
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -250,6 +250,7 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case MuslX32: return "muslx32";
   case Simulator: return "simulator";
   }
 
@@ -555,6 +556,7 @@
   .StartsWith("android", Triple::Android)
   .StartsWith("musleabihf", Triple::MuslEABIHF)
   .StartsWith("musleabi", Triple::MuslEABI)
+  .StartsWith("muslx32", Triple::MuslX32)
   .StartsWith("musl", Triple::Musl)
   .StartsWith("msvc", Triple::MSVC)
   .StartsWith("itanium", Triple::Itanium)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -218,6 +218,7 @@
 Musl,
 MuslEABI,
 MuslEABIHF,
+MuslX32,
 
 MSVC,
 Itanium,
@@ -688,7 +689,8 @@
   bool isMusl() const {
 return getEnvironment() == Triple::Musl ||
getEnvironment() == Triple::MuslEABI ||
-   getEnvironment() == Triple::MuslEABIHF;
+   getEnvironment() == Triple::MuslEABIHF ||
+   getEnvironment() == Triple::MuslX32;
   }
 
   /// Tests whether the target is SPIR (32- or 64-bit).
Index: clang/test/Driver/linux-cross.cpp
===
--- clang/test/Driver/linux-cross.cpp
+++ clang/test/Driver/linux-cross.cpp
@@ -75,3 +75,7 @@
 // RUN: %clang -### %s --target=i686-linux-musl --sysroot= \
 // RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s 
--check-prefix=MUSL_I686
 // MUSL_I686: "-dynamic-linker" "/lib/ld-musl-i386.so.1"
+
+// RUN: %clang -### %s --target=x86_64-linux-muslx32 --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s 
--check-prefix=MUSL_X32
+// MUSL_X32: "-dynamic-linker" "/lib/ld-musl-x32.so.1"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -401,6 +401,11 @@
 case llvm::Triple::x86:
   ArchName = "i386";
   break;
+case llvm::Triple::x86_64:
+  ArchName = Triple.getEnvironment() == llvm::Triple::MuslX32
+ ? "x32"
+ : Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -111,6 +111,12 @@
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::Musl, T.getEnvironment());
 
+  T = Triple("x86_64-pc-linux-muslx32");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
+
   // PS4 has two spellings for the vendor.
   T = Triple("x86_64-scei-ps4");
   EXPECT_EQ(Triple::x86_64, T.getArch());
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -250,6 +250,7 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case MuslX32: return "muslx32";
   case Simulator: return "simulator";
   }
 
@@ -555,6 +556,7 @@
   .StartsWith("android", Triple::Android)
   .StartsWith("musleabihf", Triple::MuslEABIHF)
   .StartsWith("musleabi", Triple::MuslEABI)
+  .StartsWith("muslx32", Triple::MuslX32)
   .StartsWith("musl", Triple::Musl)
   .StartsWith("msvc", Triple::MSVC)
   .StartsWith("itanium", Triple::Itanium)
Index: llvm/include/llvm/ADT/Triple.h

[PATCH] D99308: [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

2021-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D99308#2649636 , @raj.khem wrote:

> once you fix the clang-format issue reported this looks good to me.

I'll ignore it... The first block does not directly touch the formatted part 
and the second block would need a larger formatting... Such formatting changes 
should be done separately, if done at all, not mixed in this functionality 
patch.
Personally I deem the formatting less useful, so I'll ignore it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99308

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


[PATCH] D99308: [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

2021-03-24 Thread Khem Raj via Phabricator via cfe-commits
raj.khem accepted this revision.
raj.khem added a comment.
This revision is now accepted and ready to land.

once you fix the clang-format issue reported this looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99308

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


[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99121#2649546 , @ruiling wrote:

>> No, sorry I don't - I ran out of steam after the initial work, and haven't 
>> been able to get back into it. A few folks have picked up my slack in the 
>> last year or two & made some incremental progress.
>>
>> It'd be good to tag any workarounds somehow (I don't know how, exactly) to 
>> be sure they're cleaned up as things are sorted out.
>>
>> Long and the short of it: If these bugs matter to you, probably not worth 
>> waiting for the general fix (but more help would be appreciated if you 
>> wanted to work on the long term solution) & workarounds are probably 
>> reasonable.
>
> Sounds we still need a long way to get there? Do we think the patch 
> acceptable as a short-term solution?

Guess it's a tradeoff. Doesn't look like a load of code/complexity. - but 
equally, does it provide much value? Or is it enough to know it can eventually 
be addressed in a more general manner?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-24 Thread Ruiling, Song via Phabricator via cfe-commits
ruiling added a comment.

> No, sorry I don't - I ran out of steam after the initial work, and haven't 
> been able to get back into it. A few folks have picked up my slack in the 
> last year or two & made some incremental progress.
>
> It'd be good to tag any workarounds somehow (I don't know how, exactly) to be 
> sure they're cleaned up as things are sorted out.
>
> Long and the short of it: If these bugs matter to you, probably not worth 
> waiting for the general fix (but more help would be appreciated if you wanted 
> to work on the long term solution) & workarounds are probably reasonable.

Sounds we still need a long way to get there? Do we think the patch acceptable 
as a short-term solution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D98812: [OPENMP]Map data field with l-value reference types.

2021-03-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.
This revision is now accepted and ready to land.

Thanks Alexey for adding this!  The changes LGTM, but I'm not super well-versed 
with this. You may wait a bit for other reviewers to weigh in before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98812

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


[clang] cdd993f - [Driver] Use -dynamic-linker /lib/ld-musl-i386.so.1 for i?86-linux-musl

2021-03-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-24T19:44:53-07:00
New Revision: cdd993fab3629474011b73985285c04722cffd61

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

LOG: [Driver] Use -dynamic-linker /lib/ld-musl-i386.so.1 for i?86-linux-musl

Noticed by Khem Raj

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-cross.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index c1aabfd0aecd..eacc540fee30 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -398,6 +398,9 @@ std::string Linux::getDynamicLinker(const ArgList ) 
const {
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::x86:
+  ArchName = "i386";
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }

diff  --git a/clang/test/Driver/linux-cross.cpp 
b/clang/test/Driver/linux-cross.cpp
index 6fdd9193fa2f..49e7861923ba 100644
--- a/clang/test/Driver/linux-cross.cpp
+++ b/clang/test/Driver/linux-cross.cpp
@@ -70,3 +70,8 @@
 // DEBIAN_AARCH64-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../.."
 // DEBIAN_AARCH64-SAME: {{^}} "-L[[SYSROOT]]/lib"
 // DEBIAN_AARCH64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+/// LDSO_ARCH is i386 for all x86-32 variants.
+// RUN: %clang -### %s --target=i686-linux-musl --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s 
--check-prefix=MUSL_I686
+// MUSL_I686: "-dynamic-linker" "/lib/ld-musl-i386.so.1"



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


[PATCH] D99152: [AMX] Prototype for vector and amx bitcast.

2021-03-24 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added a comment.

In D99152#2647681 , @fhahn wrote:

> I can't see any `load <256 x i32>` in the linked example, just a store. Could 
> you check the example?

I create another example at https://gcc.godbolt.org/z/v6od5ceEz. In bar() 
function, you can see the `load <256 x i32>*` in the IR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99152

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


[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99121#2647187 , @nlopes wrote:

> In D99121#2645593 , @dblaikie wrote:
>
>> In D99121#2644362 , @lebedev.ri 
>> wrote:
>>
>>> In D99121#2644223 , @nlopes wrote:
>>>
 The pointee type in LLVM doesn't really matter. It's even supposed to 
 disappear one day after the migration is completed.
 E.g., i8* and i64* are exactly the same thing: they are pointers to data.
>>>
>>> Yep. That will be indeed a great to see.
>>>
 So, I don't understand the motivation for this patch. It doesn't solve the 
 root cause of the problem (which one btw?).
>>>
>>> It is indeed temporary until Opaque pointers are here.
>>> The problem has been stated last time in D99051 
>>>  by @ruiling:
>>> https://godbolt.org/z/x7E1EjWvv, i.e. given the same integer,
>>> there can be any number of pointers `inttoptr`'d from it,
>>> and passes won't be able to tell that they are identical.
>>>
>>> @dblaikie @t.p.northover can anyone comment on the Opaque Pointers 
>>> progress? Is there a checklist somewhere?
>>
>> no checklist, unfortunately - myself, @t.p.northover, @jyknight, and @arsenm 
>> have all done bits and pieces of work on it lately.
>>
>> I think we've got most of the big IR changes (adding explicit types where 
>> they'll be needed when they're no longer carried on the type of pointer 
>> parameters) - @arsenm's D98146  is another 
>> piece in that area, hopefully near the last I think.
>>
>> After all that's in place, the next step I think would be to introduce the 
>> typeless pointer, support it as an operand to these various operations - and 
>> then try producing it as a result of instructions too. But I'm probably 
>> missing a bunch of important steps we'll find are necessary...
>
> Do you have an ETA for when the switch will happen? Just to inform us where 
> we should proceed with temp fixes like this one or we should just wait.

No, sorry I don't - I ran out of steam after the initial work, and haven't been 
able to get back into it. A few folks have picked up my slack in the last year 
or two & made some incremental progress.

It'd be good to tag any workarounds somehow (I don't know how, exactly) to be 
sure they're cleaned up as things are sorted out.

Long and the short of it: If these bugs matter to you, probably not worth 
waiting for the general fix (but more help would be appreciated if you wanted 
to work on the long term solution) & workarounds are probably reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D99237: [AVR][clang] Fix wrong calling convention in functions return struct type

2021-03-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

This patch just fix the wrong return type in ABI. The wrong parameters passing 
with be fixed in another patch.


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

https://reviews.llvm.org/D99237

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


[PATCH] D98881: [RISCV] Fix mcount name

2021-03-24 Thread Nathan Chancellor 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 rGef58ae86ba77: [RISCV] Fix mcount name (authored by 
nathanchance).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98881

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/mcount.c


Index: clang/test/CodeGen/mcount.c
===
--- clang/test/CodeGen/mcount.c
+++ clang/test/CodeGen/mcount.c
@@ -12,6 +12,13 @@
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -59,6 +59,7 @@
 WCharType = SignedInt;
 WIntType = UnsignedInt;
 HasRISCVVTypes = true;
+MCountName = "_mcount";
   }
 
   bool setCPU(const std::string ) override {
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -261,6 +261,9 @@
 case llvm::Triple::arm:
   this->MCountName = "__mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };
@@ -491,6 +494,9 @@
 case llvm::Triple::sparcv9:
   this->MCountName = "_mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };


Index: clang/test/CodeGen/mcount.c
===
--- clang/test/CodeGen/mcount.c
+++ clang/test/CodeGen/mcount.c
@@ -12,6 +12,13 @@
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 

[clang] ef58ae8 - [RISCV] Fix mcount name

2021-03-24 Thread Nathan Chancellor via cfe-commits

Author: Nathan Chancellor
Date: 2021-03-24T18:11:37-07:00
New Revision: ef58ae86ba778ed7d01cd3f6bd6d08f943abab44

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

LOG: [RISCV] Fix mcount name

GCC's name for this symbol is _mcount, which the Linux kernel expects in
a few different place:

  $ echo 'int main(void) { return 0; }' | riscv32-linux-gcc -c -pg -o tmp.o -x 
c -

  $ llvm-objdump -dr tmp.o | grep mcount
  000c:  R_RISCV_CALL _mcount

  $ echo 'int main(void) { return 0; }' | riscv64-linux-gcc -c -pg -o tmp.o -x 
c -

  $ llvm-objdump -dr tmp.o | grep mcount
  000c:  R_RISCV_CALL _mcount

  $ echo 'int main(void) { return 0; }' | clang -c -pg -o tmp.o 
--target=riscv32-linux-gnu -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
  000a:  R_RISCV_CALL_PLT mcount

  $ echo 'int main(void) { return 0; }' | clang -c -pg -o tmp.o 
--target=riscv64-linux-gnu -x c -

  $ llvm-objdump -dr tmp.o | grep mcount
  000a:  R_RISCV_CALL_PLT mcount

Set MCountName to "_mcount" in RISCVTargetInfo then prevent it from
getting overridden in certain OSTargetInfo constructors.

Reviewed By: MaskRay

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

Signed-off-by: Nathan Chancellor 

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Basic/Targets/RISCV.h
clang/test/CodeGen/mcount.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 539466c4f678..4de1b8d2db4f 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -261,6 +261,9 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
 case llvm::Triple::arm:
   this->MCountName = "__mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };
@@ -491,6 +494,9 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public 
OSTargetInfo {
 case llvm::Triple::sparcv9:
   this->MCountName = "_mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };

diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index abae51e75a19..8df6e05ebcd5 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -59,6 +59,7 @@ class RISCVTargetInfo : public TargetInfo {
 WCharType = SignedInt;
 WIntType = UnsignedInt;
 HasRISCVVTypes = true;
+MCountName = "_mcount";
   }
 
   bool setCPU(const std::string ) override {

diff  --git a/clang/test/CodeGen/mcount.c b/clang/test/CodeGen/mcount.c
index 649f0b56949d..8f994ab4e754 100644
--- a/clang/test/CodeGen/mcount.c
+++ b/clang/test/CodeGen/mcount.c
@@ -12,6 +12,13 @@
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s



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


[PATCH] D98881: [RISCV] Fix mcount name

2021-03-24 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance updated this revision to Diff 333185.
nathanchance added a comment.

Drop "riscv32" and "riscv64" from list of checked triples (thanks to Fangrui 
for catching it with a good explanation).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98881

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/mcount.c


Index: clang/test/CodeGen/mcount.c
===
--- clang/test/CodeGen/mcount.c
+++ clang/test/CodeGen/mcount.c
@@ -12,6 +12,13 @@
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -59,6 +59,7 @@
 WCharType = SignedInt;
 WIntType = UnsignedInt;
 HasRISCVVTypes = true;
+MCountName = "_mcount";
   }
 
   bool setCPU(const std::string ) override {
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -261,6 +261,9 @@
 case llvm::Triple::arm:
   this->MCountName = "__mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };
@@ -491,6 +494,9 @@
 case llvm::Triple::sparcv9:
   this->MCountName = "_mcount";
   break;
+case llvm::Triple::riscv32:
+case llvm::Triple::riscv64:
+  break;
 }
   }
 };


Index: clang/test/CodeGen/mcount.c
===
--- clang/test/CodeGen/mcount.c
+++ clang/test/CodeGen/mcount.c
@@ -12,6 +12,13 @@
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple 

[PATCH] D99308: [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

2021-03-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: compnerd, raj.khem.
Herald added subscribers: dexonsmith, hiraditya.
MaskRay requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99308

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/linux-cross.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp
  llvm/unittests/ADT/TripleTest.cpp


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -111,6 +111,12 @@
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::Musl, T.getEnvironment());
 
+  T = Triple("x86_64-pc-linux-muslx32");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
+
   // PS4 has two spellings for the vendor.
   T = Triple("x86_64-scei-ps4");
   EXPECT_EQ(Triple::x86_64, T.getArch());
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -250,6 +250,7 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case MuslX32: return "muslx32";
   case Simulator: return "simulator";
   }
 
@@ -555,6 +556,7 @@
   .StartsWith("android", Triple::Android)
   .StartsWith("musleabihf", Triple::MuslEABIHF)
   .StartsWith("musleabi", Triple::MuslEABI)
+  .StartsWith("muslx32", Triple::MuslX32)
   .StartsWith("musl", Triple::Musl)
   .StartsWith("msvc", Triple::MSVC)
   .StartsWith("itanium", Triple::Itanium)
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -218,6 +218,7 @@
 Musl,
 MuslEABI,
 MuslEABIHF,
+MuslX32,
 
 MSVC,
 Itanium,
@@ -688,7 +689,8 @@
   bool isMusl() const {
 return getEnvironment() == Triple::Musl ||
getEnvironment() == Triple::MuslEABI ||
-   getEnvironment() == Triple::MuslEABIHF;
+   getEnvironment() == Triple::MuslEABIHF ||
+   getEnvironment() == Triple::MuslX32;
   }
 
   /// Tests whether the target is SPIR (32- or 64-bit).
Index: clang/test/Driver/linux-cross.cpp
===
--- clang/test/Driver/linux-cross.cpp
+++ clang/test/Driver/linux-cross.cpp
@@ -70,3 +70,12 @@
 // DEBIAN_AARCH64-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../.."
 // DEBIAN_AARCH64-SAME: {{^}} "-L[[SYSROOT]]/lib"
 // DEBIAN_AARCH64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+/// LDSO_ARCH is i386 for all x86-32 variants.
+// RUN: %clang -### %s --target=i686-linux-musl --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s 
--check-prefix=MUSL_I686
+// MUSL_I686: "-dynamic-linker" "/lib/ld-musl-i386.so.1"
+
+// RUN: %clang -### %s --target=x86_64-linux-muslx32 --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s 
--check-prefix=MUSL_X32
+// MUSL_X32: "-dynamic-linker" "/lib/ld-musl-i386.so.1"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -398,6 +398,11 @@
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::x86_64:
+  ArchName = Triple.getEnvironment() == llvm::Triple::MuslX32
+ ? "x32"
+ : Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -111,6 +111,12 @@
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::Musl, T.getEnvironment());
 
+  T = Triple("x86_64-pc-linux-muslx32");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
+
   // PS4 has two spellings for the vendor.
   T = Triple("x86_64-scei-ps4");
   EXPECT_EQ(Triple::x86_64, T.getArch());
Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -250,6 +250,7 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case MuslX32: return "muslx32";
   case Simulator: return "simulator";
   }
 
@@ -555,6 +556,7 @@
   

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

2021-03-24 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl requested changes to this revision.
aprantl added a comment.
This revision now requires changes to proceed.

Can you explain your motivation? There is usually no good reason not to emit 
more specific attributes from future DWARF versions if they aren't in direct 
conflict with the older version of the spec that clang is emitting. Most 
consumers (including LLDB and GDB) will accept DW_LANG_C_plus_plus_14 in DWARF 
v4 compile units without any problem.


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] D98160: [clang] Use decltype((E)) for compound requirement type constraint

2021-03-24 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:8643
 QualType MatchedType =
-BuildDecltypeType(E, E->getBeginLoc()).getCanonicalType();
+BuildDecltypeType(E, E->getBeginLoc(), true, true).getCanonicalType();
 llvm::SmallVector Args;

mizvekov wrote:
> rsmith wrote:
> > Instead of adding complexity to the type system to deal with this special 
> > case, can you directly create a `ParenExpr` here?
> Hmm I thought about that. Since I am a bit unfamiliar with the code there, I 
> was not sure it was going to end up being more or less complicated than the 
> proposed solution. But I'll give it a shot if that looks simpler to you.
So yeah, now we just get the type of the expression directly, by using the now 
exposed underlying code from decltype.
This is OK since the expressions in the requires clause were never dependent in 
the first place.
Even though just creating the parensexpr would likely lead to a smaller change 
as in number of lines of code modified, I think not using it makes the fact 
that dependency is not an issue here more clear in the code than just reusing 
the full decltype machinery.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98160

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


[PATCH] D97831: [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Yuanfang 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 rG217f0f735afe: [Clang][Sema] Implement GCC 
-Wcast-function-type (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97831

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-cast-function-type.c
  clang/test/Sema/warn-cast-function-type.cpp

Index: clang/test/Sema/warn-cast-function-type.cpp
===
--- /dev/null
+++ clang/test/Sema/warn-cast-function-type.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -x c++ %s -fblocks -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
+
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)(...);
+typedef void (f4)(...);
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int ()(long, int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+
+struct S
+{
+  void foo (int*);
+  void bar (int);
+};
+
+typedef void (S::*mf)(int);
+
+void foo() {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  b = reinterpret_cast(x); /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  c = (f3 *)x;
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function types}} */
+  e = (f5 *)x;
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+  g = (f7 *)x;
+
+  mf p1 = (mf)::foo; /* expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function types}} */
+
+  f8 f2 = (f8)x; /* expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function types}} */
+  (void)f2;
+
+  int (^y)(long);
+  f = (f6 *)y; /* expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+}
Index: clang/test/Sema/warn-cast-function-type.c
===
--- /dev/null
+++ clang/test/Sema/warn-cast-function-type.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -x c %s -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
+
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  c = (f3 *)x;
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function types}} */
+  e = (f5 *)x;
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+  g = (f7 *)x;
+}
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -13,8 +13,8 @@
 //
 //===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/Initialization.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallVector.h"
 #include 
 using namespace clang;
@@ -1035,6 +1036,90 @@
 << FixItHint::CreateReplacement(BeginLoc, "static_cast");
 }
 
+static bool argTypeIsABIEquivalent(QualType SrcType, QualType DestType,
+   ASTContext ) {
+  if (SrcType->isPointerType() && DestType->isPointerType())
+return true;
+
+  // Allow integral type mismatch if their size are equal.
+  if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
+if (Context.getTypeInfoInChars(SrcType).Width ==
+Context.getTypeInfoInChars(DestType).Width)
+  return true;
+
+  return Context.hasSameUnqualifiedType(SrcType, DestType);
+}
+
+static bool checkCastFunctionType(Sema , const ExprResult ,
+  QualType DestType) {

[clang] 217f0f7 - [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-03-24T16:04:18-07:00
New Revision: 217f0f735afec57a51fa6f9ab863d4713a2f85e2

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

LOG: [Clang][Sema] Implement GCC -Wcast-function-type

```
Warn when a function pointer is cast to an incompatible function
pointer. In a cast involving function types with a variable argument
list only the types of initial arguments that are provided are
considered. Any parameter of pointer-type matches any other
pointer-type. Any benign differences in integral types are ignored, like
int vs. long on ILP32 targets. Likewise type qualifiers are ignored. The
function type void (*) (void) is special and matches everything, which
can be used to suppress this warning. In a cast involving pointer to
member types this warning warns whenever the type cast is changing the
pointer to member type. This warning is enabled by -Wextra.
```

Reviewed By: rsmith

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

Added: 
clang/test/Sema/warn-cast-function-type.c
clang/test/Sema/warn-cast-function-type.cpp

Modified: 
clang/docs/DiagnosticsReference.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp

Removed: 




diff  --git a/clang/docs/DiagnosticsReference.rst 
b/clang/docs/DiagnosticsReference.rst
index 04d7f74d5bfc9..730077f33397a 100644
--- a/clang/docs/DiagnosticsReference.rst
+++ b/clang/docs/DiagnosticsReference.rst
@@ -851,6 +851,13 @@ This diagnostic is enabled by default.
 |:warning:`warning:` |nbsp| :diagtext:`cast from function call of type` |nbsp| 
:placeholder:`A` |nbsp| :diagtext:`to non-matching type` |nbsp| 
:placeholder:`B`|
 
+--+
 
+-Wcast-function-type
+---
+**Diagnostic text:**
+
++--+
+|:warning:`warning:` |nbsp| :diagtext:`cast from` |nbsp| :placeholder:`A` 
|nbsp| :diagtext:`to` |nbsp| :placeholder:`B` |nbsp| :diagtext:`converts to 
incompatible function types`|
++--+
 
 -Wbinary-literal
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 291cca02694fc..85f798013a3d4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -499,6 +499,7 @@ def PrivateExtern : DiagGroup<"private-extern">;
 def SelTypeCast : DiagGroup<"cast-of-sel-type">;
 def FunctionDefInObjCContainer : DiagGroup<"function-def-in-objc-container">;
 def BadFunctionCast : DiagGroup<"bad-function-cast">;
+def CastFunctionType : DiagGroup<"cast-function-type">;
 def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
 def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
 def ObjCPropertyAssignOnObjectType : 
DiagGroup<"objc-property-assign-on-object-type">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58e221a004689..df2f79a4f3441 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8386,6 +8386,9 @@ def note_change_calling_conv_fixit : Note<
 def warn_bad_function_cast : Warning<
   "cast from function call of type %0 to non-matching type %1">,
   InGroup, DefaultIgnore;
+def warn_cast_function_type : Warning<
+  "cast from %0 to %1 converts to incompatible function types">,
+  InGroup, DefaultIgnore;
 def err_cast_pointer_to_non_pointer_int : Error<
   "pointer cannot be cast to type %0">;
 def err_cast_to_bfloat16 : Error<"cannot type-cast to __bf16">;

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 22ec2c7ed8bbf..719cbf46bd5c2 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -13,8 +13,8 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/Initialization.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallVector.h"
 #include 

[PATCH] D97831: [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 333162.
ychen added a comment.

- update doc to match diagnostics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97831

Files:
  clang/docs/DiagnosticsReference.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-cast-function-type.c
  clang/test/Sema/warn-cast-function-type.cpp

Index: clang/test/Sema/warn-cast-function-type.cpp
===
--- /dev/null
+++ clang/test/Sema/warn-cast-function-type.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -x c++ %s -fblocks -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
+
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)(...);
+typedef void (f4)(...);
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int ()(long, int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+
+struct S
+{
+  void foo (int*);
+  void bar (int);
+};
+
+typedef void (S::*mf)(int);
+
+void foo() {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  b = reinterpret_cast(x); /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  c = (f3 *)x;
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function types}} */
+  e = (f5 *)x;
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+  g = (f7 *)x;
+
+  mf p1 = (mf)::foo; /* expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function types}} */
+
+  f8 f2 = (f8)x; /* expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function types}} */
+  (void)f2;
+
+  int (^y)(long);
+  f = (f6 *)y; /* expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+}
Index: clang/test/Sema/warn-cast-function-type.c
===
--- /dev/null
+++ clang/test/Sema/warn-cast-function-type.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -x c %s -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
+
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function types}} */
+  c = (f3 *)x;
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function types}} */
+  e = (f5 *)x;
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function types}} */
+  g = (f7 *)x;
+}
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -13,8 +13,8 @@
 //
 //===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -23,6 +23,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/Initialization.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallVector.h"
 #include 
 using namespace clang;
@@ -1035,6 +1036,90 @@
 << FixItHint::CreateReplacement(BeginLoc, "static_cast");
 }
 
+static bool argTypeIsABIEquivalent(QualType SrcType, QualType DestType,
+   ASTContext ) {
+  if (SrcType->isPointerType() && DestType->isPointerType())
+return true;
+
+  // Allow integral type mismatch if their size are equal.
+  if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
+if (Context.getTypeInfoInChars(SrcType).Width ==
+Context.getTypeInfoInChars(DestType).Width)
+  return true;
+
+  return Context.hasSameUnqualifiedType(SrcType, DestType);
+}
+
+static bool checkCastFunctionType(Sema , const ExprResult ,
+  QualType DestType) {
+  if (Self.Diags.isIgnored(diag::warn_cast_function_type,
+   SrcExpr.get()->getExprLoc()))
+return 

[PATCH] D97831: [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Thanks for the insightful suggestions. I'll definitely send a follow-up patch 
for these (pointerLike arguments, TargetInfo refactoring, promotable integral 
types).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97831

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-24 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 333158.
mizvekov added a comment.

Rebased on top of D99225 , running on a bunch 
of extra tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.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-cxx14.cpp
  clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp
  clang/test/SemaCXX/coroutines.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,8 +1,8 @@
-// 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++2b -fsyntax-only -verify=cxx20_2b,cxx2b -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
@@ -217,8 +217,8 @@
 }
 
 // But if the return type is a reference type, then moving would be wrong.
-Derived& testRetRef1(Derived&& d) { return d; }
-Base& testRetRef2(Derived&& d) { return d; }
+Derived& testRetRef1(Derived&& d) { return d; } // cxx2b-error {{on-const lvalue reference to type 'Derived' cannot bind to a temporary of type 'Derived'}}
+Base& testRetRef2(Derived&& d) { return d; } // cxx2b-error {{non-const lvalue reference to type 'Base' cannot bind to a temporary of type 'Derived'}}
 #if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
Index: clang/test/SemaCXX/return-stack-addr.cpp
===
--- clang/test/SemaCXX/return-stack-addr.cpp
+++ clang/test/SemaCXX/return-stack-addr.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected   %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11 %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx2b  %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11 %s
 
 int* ret_local() {
   int x = 1;
@@ -29,7 +29,8 @@
 
 int& ret_local_ref() {
   int x = 1;
-  return x;  // expected-warning {{reference to stack memory}}
+  return x;  // cxx11_20-warning {{reference to stack memory}}
+  // cxx2b-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
 }
 
 int* ret_local_addrOf() {
@@ -154,8 +155,10 @@
   (void) [&]() -> int& { return b; };
   (void) [=]() mutable -> int& { return a; };
   (void) [=]() mutable -> int& { return b; };
-  (void) [&]() -> int& { int a; return a; }; // expected-warning {{reference to stack}}
-  (void) [=]() -> int& { int a; return a; }; // expected-warning {{reference to stack}}
+  (void) [&]() -> int& { int a; return a; }; // cxx11_20-warning {{reference to stack}}
+  // cxx2b-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
+  (void) [=]() -> int& { int a; return a; }; // cxx11_20-warning {{reference to stack}}
+  // cxx2b-error@-1 {{non-const lvalue reference to type 'int' cannot bind 

[clang] 35dd647 - [Driver] Bring back "Clean up Debian multiarch /usr/include/ madness"

2021-03-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-24T15:25:37-07:00
New Revision: 35dd6470de847636c212d7e0cd4d7ac2995679cc

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

LOG: [Driver] Bring back "Clean up Debian multiarch /usr/include/ 
madness"

This reverts commit aae84b8e3939e815bbc1e64b3b30c0f10b055be4.

The chromium goma folks want to use a Debian sysroot without
lib/x86_64-linux-gnu to perform `clang -c` but no link action. The previous
commit has removed D.getVFS().exists check to make such usage work.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index cea77b679318..c1aabfd0aecd 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -562,172 +562,13 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
,
 return;
   }
 
-  // Implement generic Debian multiarch support.
-  const StringRef X86_64MultiarchIncludeDirs[] = {
-  "/usr/include/x86_64-linux-gnu",
-
-  // FIXME: These are older forms of multiarch. It's not clear that they're
-  // in use in any released version of Debian, so we should consider
-  // removing them.
-  "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
-  const StringRef X86MultiarchIncludeDirs[] = {
-  "/usr/include/i386-linux-gnu",
-
-  // FIXME: These are older forms of multiarch. It's not clear that they're
-  // in use in any released version of Debian, so we should consider
-  // removing them.
-  "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
-  "/usr/include/i486-linux-gnu"};
-  const StringRef AArch64MultiarchIncludeDirs[] = {
-  "/usr/include/aarch64-linux-gnu"};
-  const StringRef ARMMultiarchIncludeDirs[] = {
-  "/usr/include/arm-linux-gnueabi"};
-  const StringRef ARMHFMultiarchIncludeDirs[] = {
-  "/usr/include/arm-linux-gnueabihf"};
-  const StringRef ARMEBMultiarchIncludeDirs[] = {
-  "/usr/include/armeb-linux-gnueabi"};
-  const StringRef ARMEBHFMultiarchIncludeDirs[] = {
-  "/usr/include/armeb-linux-gnueabihf"};
-  const StringRef M68kMultiarchIncludeDirs[] = {"/usr/include/m68k-linux-gnu"};
-  const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
-  const StringRef MIPSELMultiarchIncludeDirs[] = {
-  "/usr/include/mipsel-linux-gnu"};
-  const StringRef MIPS64MultiarchIncludeDirs[] = {
-  "/usr/include/mips64-linux-gnuabi64"};
-  const StringRef MIPS64ELMultiarchIncludeDirs[] = {
-  "/usr/include/mips64el-linux-gnuabi64"};
-  const StringRef MIPSN32MultiarchIncludeDirs[] = {
-  "/usr/include/mips64-linux-gnuabin32"};
-  const StringRef MIPSN32ELMultiarchIncludeDirs[] = {
-  "/usr/include/mips64el-linux-gnuabin32"};
-  const StringRef MIPSR6MultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa32-linux-gnu"};
-  const StringRef MIPSR6ELMultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa32r6el-linux-gnu"};
-  const StringRef MIPS64R6MultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa64r6-linux-gnuabi64"};
-  const StringRef MIPS64R6ELMultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa64r6el-linux-gnuabi64"};
-  const StringRef MIPSN32R6MultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa64r6-linux-gnuabin32"};
-  const StringRef MIPSN32R6ELMultiarchIncludeDirs[] = {
-  "/usr/include/mipsisa64r6el-linux-gnuabin32"};
-  const StringRef PPCMultiarchIncludeDirs[] = {
-  "/usr/include/powerpc-linux-gnu",
-  "/usr/include/powerpc-linux-gnuspe"};
-  const StringRef PPCLEMultiarchIncludeDirs[] = {
-  "/usr/include/powerpcle-linux-gnu"};
-  const StringRef PPC64MultiarchIncludeDirs[] = {
-  "/usr/include/powerpc64-linux-gnu"};
-  const StringRef PPC64LEMultiarchIncludeDirs[] = {
-  "/usr/include/powerpc64le-linux-gnu"};
-  const StringRef SparcMultiarchIncludeDirs[] = {
-  "/usr/include/sparc-linux-gnu"};
-  const StringRef Sparc64MultiarchIncludeDirs[] = {
-  "/usr/include/sparc64-linux-gnu"};
-  const StringRef SYSTEMZMultiarchIncludeDirs[] = {
-  "/usr/include/s390x-linux-gnu"};
-  ArrayRef MultiarchIncludeDirs;
-  switch (getTriple().getArch()) {
-  case llvm::Triple::x86_64:
-MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
-break;
-  case llvm::Triple::x86:
-MultiarchIncludeDirs = X86MultiarchIncludeDirs;
-break;
-  case llvm::Triple::aarch64:
-  case llvm::Triple::aarch64_be:
-MultiarchIncludeDirs = AArch64MultiarchIncludeDirs;
-break;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
-  MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs;
-else
-  MultiarchIncludeDirs = 

[clang] bfbfd83 - [Driver] Linux.cpp: delete unneeded D.getVFS().exists checks

2021-03-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-24T15:25:36-07:00
New Revision: bfbfd83f147f0e02e652f3ae2635dd834c2e6b46

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

LOG: [Driver] Linux.cpp: delete unneeded D.getVFS().exists checks

Not only can this save unneeded filesystem stats, it can make `clang
--sysroot=/path/to/debian-sysroot -c a.cc` work (get `-internal-isystem
$sysroot/usr/include/x86_64-linux-gnu`) even without `lib/x86_64-linux-gnu/`.
This should make thakis happy.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index cbfa5152bc8e..cea77b679318 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -58,70 +58,42 @@ std::string Linux::getMultiarchTriple(const Driver ,
   // regardless of what the actual target triple is.
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
-if (IsAndroid) {
+if (IsAndroid)
   return "arm-linux-androideabi";
-} else if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
-  if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
-return "arm-linux-gnueabihf";
-} else {
-  if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi"))
-return "arm-linux-gnueabi";
-}
-break;
+if (TargetEnvironment == llvm::Triple::GNUEABIHF)
+  return "arm-linux-gnueabihf";
+return "arm-linux-gnueabi";
   case llvm::Triple::armeb:
   case llvm::Triple::thumbeb:
-if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
-  if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf"))
-return "armeb-linux-gnueabihf";
-} else {
-  if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi"))
-return "armeb-linux-gnueabi";
-}
-break;
+if (TargetEnvironment == llvm::Triple::GNUEABIHF)
+  return "armeb-linux-gnueabihf";
+return "armeb-linux-gnueabi";
   case llvm::Triple::x86:
 if (IsAndroid)
   return "i686-linux-android";
-if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
-  return "i386-linux-gnu";
-break;
+return "i386-linux-gnu";
   case llvm::Triple::x86_64:
 if (IsAndroid)
   return "x86_64-linux-android";
-// We don't want this for x32, otherwise it will match x86_64 libs
-if (TargetEnvironment != llvm::Triple::GNUX32 &&
-D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
-  return "x86_64-linux-gnu";
-break;
+if (TargetEnvironment == llvm::Triple::GNUX32)
+  return "x86_64-linux-gnux32";
+return "x86_64-linux-gnu";
   case llvm::Triple::aarch64:
 if (IsAndroid)
   return "aarch64-linux-android";
-if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
-  return "aarch64-linux-gnu";
-break;
+return "aarch64-linux-gnu";
   case llvm::Triple::aarch64_be:
-if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
-  return "aarch64_be-linux-gnu";
-break;
+return "aarch64_be-linux-gnu";
 
   case llvm::Triple::m68k:
-if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
-  return "m68k-linux-gnu";
-break;
+return "m68k-linux-gnu";
 
-  case llvm::Triple::mips: {
-std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
-  return MT;
-break;
-  }
-  case llvm::Triple::mipsel: {
+  case llvm::Triple::mips:
+return IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
+  case llvm::Triple::mipsel:
 if (IsAndroid)
   return "mipsel-linux-android";
-std::string MT = IsMipsR6 ? "mipsisa32r6el-linux-gnu" : "mipsel-linux-gnu";
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
-  return MT;
-break;
-  }
+return IsMipsR6 ? "mipsisa32r6el-linux-gnu" : "mipsel-linux-gnu";
   case llvm::Triple::mips64: {
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
@@ -145,33 +117,19 @@ std::string Linux::getMultiarchTriple(const Driver ,
   case llvm::Triple::ppc:
 if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
   return "powerpc-linux-gnuspe";
-if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu"))
-  return "powerpc-linux-gnu";
-break;
+return "powerpc-linux-gnu";
   case llvm::Triple::ppcle:
-if (D.getVFS().exists(SysRoot + "/lib/powerpcle-linux-gnu"))
-  return "powerpcle-linux-gnu";
-break;
+return "powerpcle-linux-gnu";
   case llvm::Triple::ppc64:
-if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu"))
-  return "powerpc64-linux-gnu";
-break;
+return 

[PATCH] D99301: [HIP] add __builtin_get_device_side_mangled_name

2021-03-24 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with a couple of nits.




Comment at: clang/include/clang/Basic/Builtins.h:39
   OMP_LANG = 0x80,// builtin requires OpenMP.
+  HIP_LANG = 0x100,   // builtin requires HIP.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.

The issue is common for both CUDA and HIP. 



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8310
+def err_hip_invalid_args_builtin_mangled_name : Error<
+"invalid argument: expect a device-side function or global variable">;
+

Nit. I'd rephrase it in terms of what makes the argument invalid. E.g. `symbol 
must be a device-side function or global variable`.



Comment at: clang/lib/Basic/Builtins.cpp:78
   bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
+  bool HIPUnsupported = !LangOpts.HIP && BuiltinInfo.Langs == HIP_LANG;
   bool CPlusPlusUnsupported =

tra wrote:
> Wow! The density of negations in this function is impressive.
> 
> 
Please enable it for CUDA, too.



Comment at: clang/lib/Basic/Builtins.cpp:78-84
+  bool HIPUnsupported = !LangOpts.HIP && BuiltinInfo.Langs == HIP_LANG;
   bool CPlusPlusUnsupported =
   !LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG;
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported 
&&
  !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
  !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported &&
+ !CPlusPlusUnsupported && !HIPUnsupported;

Wow! The density of negations in this function is impressive.





Comment at: clang/lib/Sema/SemaChecking.cpp:1980-1983
+  if (!D->hasAttr() && !D->hasAttr() &&
+  !D->hasAttr() && !D->hasAttr())
+return false;
+  return true;

```
  return D->hasAttr() || D->hasAttr() ||
  D->hasAttr() || D->hasAttr();
```


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

https://reviews.llvm.org/D99301

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


[PATCH] D98554: Save strings for CC_PRINT env vars

2021-03-24 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast accepted this revision.
hubert.reinterpretcast added a comment.
This revision is now accepted and ready to land.

LGTM; thanks.




Comment at: clang/lib/Driver/Driver.cpp:4042
 
-  if (!CCPrintStatReportFilename) {
+  if (CCPrintStatReportFilename.empty()) {
 using namespace llvm;

Just noting that this means having the environment variable set (but empty) 
will now "work" instead of generating an error.


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

https://reviews.llvm.org/D98554

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


[PATCH] D97831: [Clang][Sema] Implement GCC -Wcast-function-type

2021-03-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Looks good. Some possible improvements to make the diagnostic a bit more 
precise, but I'd be happy if you want to address some of those as follow-ups 
after this change.




Comment at: clang/lib/Sema/SemaCast.cpp:1041
+   ASTContext ) {
+  if (SrcType->isPointerType() && DestType->isPointerType())
+return true;

I think we should also treat references like pointers here, and similarly for 
block pointers and ObjC pointers. Perhaps using `hasPointerRepresentation()` 
would make sense?



Comment at: clang/lib/Sema/SemaCast.cpp:1044-1048
+  // Allow integral type mismatch if their size are equal.
+  if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
+if (Context.getTypeInfoInChars(SrcType).Width ==
+Context.getTypeInfoInChars(DestType).Width)
+  return true;

ychen wrote:
> rsmith wrote:
> > In addition to allowing the cases where the sizes are the same width, 
> > should we also allow cases where the promoted types are the same width (eg, 
> > `int` versus `short`)? What does GCC do?
> GCC does exactly that. I didn't find a way to do that by looking at 
> TargetInfo. Maybe there is a way for clang?
Hm. The right thing to do would be to call 
`ABIInfo::isPromotableIntegerTypeForABI`, but that's defined in `CodeGen` so we 
can't call it from here without violating layering. I suppose we could pull it 
up into the target info in `Basic`, if you're prepared to do that kind of 
refactoring, but maybe for now we can skip this check and emit a few warnings 
that GCC doesn't.



Comment at: clang/lib/Sema/SemaCast.cpp:1050-1055
+  llvm::DenseSet> NonEquivalentDecls;
+  StructuralEquivalenceContext Ctx(
+  Context, Context, NonEquivalentDecls, StructuralEquivalenceKind::Default,
+  false /*StrictTypeSpelling*/, false /*Complain*/,
+  false /*ErrorOnTagTypeMismatch*/);
+  return Ctx.IsEquivalent(SrcType, DestType);

ychen wrote:
> rsmith wrote:
> > I think a "same type" check (`Context.hasSameUnqualifiedType(SrcType, 
> > DestType)`) would be more appropriate here than a structural equivalence 
> > check.
> Agreed.
Taking this a bit further: we could use `hasSimilarType` to allow changes in 
nested cv-qualifiers. But given that we've already allowed arbitrary 
differences in pointee types, I suppose this would only affect 
pointers-to-members, and it might be preferable to allow arbitrary changes 
between pointer-to-member types here (except in the MS ABI case where there are 
meaningful differences in pointer-to-member representations between classes).

What does GCC do with differences in pointer-to-member types in function 
parameter types?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97831

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


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

2021-03-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey @fhahn ,

I realise, as you pointed out before, that we need to do some changes in 
CodeGen too. I think its going to be more involved so before starting on that, 
it would be great if you can confirm whether I am on the right path. I will 
describe what I did, what happened, and what I inferred from that.

I ran this simple cast.

  typedef char cx4x4 __attribute__((matrix_type(4, 4)));
  typedef int ix4x4 __attribute__((matrix_type(4, 4)));
  cx4x4 c = (cx4x4) i;

This crashed the compiler with this stack trace.

  clang: /tmp/llvm/lib/IR/Instructions.cpp:2934: static llvm::CastInst 
*llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, 
const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && 
"Invalid cast!"' failed.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.Program arguments: /tmp/build/bin/clang -cc1 -internal-isystem 
/tmp/build/lib/clang/13.0.0/include -nostdsysteminc -fenable-matrix -triple 
x86_64-apple-darwin /tmp/clang/test/CodeGen/matrix-cast.c -emit-llvm 
-disable-llvm-passes -o -
  1. parser at end of file
  2./tmp/clang/test/CodeGen/matrix-cast.c:15:6: LLVM IR generation of 
declaration 'cast_char_matrix_to_int_same_size'
  3./tmp/clang/test/CodeGen/matrix-cast.c:15:6: Generating code for 
declaration 'cast_char_matrix_to_int_same_size'
   #0 0x0972648a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:565:11
   #1 0x0972665b PrintStackTraceSignalHandler(void*) 
/tmp/llvm/lib/Support/Unix/Signals.inc:632:1
   #2 0x09724c4b llvm::sys::RunSignalHandlers() 
/tmp/llvm/lib/Support/Signals.cpp:70:5
   #3 0x09726dd1 SignalHandler(int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:407:1
   #4 0x7ff3d17353c0 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
   #5 0x7ff3d11e618b raise 
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #6 0x7ff3d11c5859 abort 
/build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
   #7 0x7ff3d11c5729 get_sysdep_segment_value 
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
   #8 0x7ff3d11c5729 _nl_load_domain 
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
   #9 0x7ff3d11d6f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
  #10 0x08a5c1bf llvm::CastInst::Create(llvm::Instruction::CastOps, 
llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) 
/tmp/llvm/lib/IR/Instructions.cpp:2936:11
  #11 0x06205834 
llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, 
llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2106:52
  #12 0x061ef472 llvm::IRBuilderBase::CreateBitCast(llvm::Value*, 
llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2065:5
  #13 0x09fb1140 (anonymous 
namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:2069:5
  #14 0x09fb002e (anonymous 
namespace)::ScalarExprEmitter::VisitExplicitCastExpr(clang::ExplicitCastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:563:5
  #15 0x09fa8493 clang::StmtVisitorBase::VisitCStyleCastExpr(clang::CStyleCastExpr*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
  #16 0x09fa2747 clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
  #17 0x09f976fb (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
  #18 0x09fa4f82 (anonymous 
namespace)::ScalarExprEmitter::VisitBinAssign(clang::BinaryOperator const*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4168:9
  #19 0x09fa157d clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/clang/include/clang/AST/StmtVisitor.h:72:26
  #20 0x09f976fb (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
  #21 0x09f97656 
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4757:3
  #22 0x09e5638c 
clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot, bool) /tmp/clang/lib/CodeGen/CGExpr.cpp:218:12
  #23 0x09e562bd 
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) 
/tmp/clang/lib/CodeGen/CGExpr.cpp:203:19
  #24 0x09fc3616 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt 
const*, llvm::ArrayRef) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:118:5
  #25 0x09fcc7ab 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:447:3
  #26 0x09e2ebd1 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt 

[PATCH] D82880: [clang] Handle 128-bits IntegerLiterals in StmtPrinter

2021-03-24 Thread David Stone via Phabricator via cfe-commits
davidstone marked 2 inline comments as done.
davidstone added a comment.

I believe this addresses the review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82880

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


[PATCH] D82880: Fix PR35677: UB on __int128_t or __uint128_t template parameters.

2021-03-24 Thread David Stone via Phabricator via cfe-commits
davidstone updated this revision to Diff 333135.
davidstone added a comment.

[clang] Handle 128-bits IntegerLiterals in StmtPrinter

This fixes PR35677: "__int128_t or __uint128_t as non-type template parameter
causes crash when considering invalid constructor".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82880

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/test/AST/ast-print-int128.cpp


Index: clang/test/AST/ast-print-int128.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-int128.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print -std=c++20 %s -o - | FileCheck %s
+
+template 
+struct enable_if {
+};
+
+template <__uint128_t x, typename = typename enable_if::type>
+void f();
+
+template <__int128_t>
+void f();
+
+using T = decltype(f<0>());
+
+// CHECK: using T = decltype(f<0>());
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -1170,6 +1170,8 @@
   case BuiltinType::ULong: OS << "UL"; break;
   case BuiltinType::LongLong:  OS << "LL"; break;
   case BuiltinType::ULongLong: OS << "ULL"; break;
+  case BuiltinType::Int128:break; // no suffix.
+  case BuiltinType::UInt128:   break; // no suffix.
   }
 }
 


Index: clang/test/AST/ast-print-int128.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-int128.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print -std=c++20 %s -o - | FileCheck %s
+
+template 
+struct enable_if {
+};
+
+template <__uint128_t x, typename = typename enable_if::type>
+void f();
+
+template <__int128_t>
+void f();
+
+using T = decltype(f<0>());
+
+// CHECK: using T = decltype(f<0>());
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -1170,6 +1170,8 @@
   case BuiltinType::ULong: OS << "UL"; break;
   case BuiltinType::LongLong:  OS << "LL"; break;
   case BuiltinType::ULongLong: OS << "ULL"; break;
+  case BuiltinType::Int128:break; // no suffix.
+  case BuiltinType::UInt128:   break; // no suffix.
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99301: [HIP] add __builtin_get_device_side_mangled_name

2021-03-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

Add builtin function __builtin_get_device_side_mangled_name
to get device side manged name for functions and global
variables, which can be used to get symbol address of kernels
or variables by mangled name in dynamically loaded
bundled code objects at run time.


https://reviews.llvm.org/D99301

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Builtins.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCUDA/builtin-mangled-name.cu
  clang/test/SemaCUDA/builtin-mangled-name.cu

Index: clang/test/SemaCUDA/builtin-mangled-name.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/builtin-mangled-name.cu
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -verify -fsyntax-only -x hip %s
+
+#include "Inputs/cuda.h"
+
+__global__ void kern1();
+int y;
+
+void fun1() {
+  int x;
+  const char *p;
+  p = __builtin_get_device_side_mangled_name();
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(kern1, kern1);
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(1);
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(x);
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(fun1);
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(y);
+  // expected-error@-1 {{invalid argument: expect a device-side function or global variable}}
+}
Index: clang/test/CodeGenCUDA/builtin-mangled-name.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/builtin-mangled-name.cu
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=CHECK,LNX %s 
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=CHECK,MSVC %s 
+
+#include "Inputs/cuda.h"
+
+namespace X {
+  __global__ void kern1(int *x);
+  __device__ int var1;
+}
+
+// CHECK: @[[STR1:.*]] = {{.*}} c"_ZN1X5kern1EPi\00"
+// CHECK: @[[STR2:.*]] = {{.*}} c"_ZN1X4var1E\00"
+
+// LNX-LABEL: define {{.*}}@_Z4fun1v()
+// MSVC-LABEL: define {{.*}} @"?fun1@@YAPEBDXZ"()
+// CHECK: ret i8* getelementptr inbounds ({{.*}} @[[STR1]], i64 0, i64 0)
+const char *fun1() {
+  return __builtin_get_device_side_mangled_name(X::kern1);
+}
+
+// LNX-LABEL: define {{.*}}@_Z4fun2v()
+// MSVC-LABEL: define {{.*}}@"?fun2@@YAPEBDXZ"()
+// CHECK: ret i8* getelementptr inbounds ({{.*}} @[[STR2]], i64 0, i64 0)
+__host__ __device__ const char *fun2() {
+  return __builtin_get_device_side_mangled_name(X::var1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1966,6 +1966,28 @@
 
   case Builtin::BI__builtin_matrix_column_major_store:
 return SemaBuiltinMatrixColumnMajorStore(TheCall, TheCallResult);
+
+  case Builtin::BI__builtin_get_device_side_mangled_name: {
+auto Check = [](CallExpr *TheCall) {
+  if (TheCall->getNumArgs() != 1)
+return false;
+  auto *DRE = dyn_cast(TheCall->getArg(0)->IgnoreImpCasts());
+  if (!DRE)
+return false;
+  auto *D = DRE->getDecl();
+  if (!isa(D) && !isa(D))
+return false;
+  if (!D->hasAttr() && !D->hasAttr() &&
+  !D->hasAttr() && !D->hasAttr())
+return false;
+  return true;
+};
+if (!Check(TheCall)) {
+  Diag(TheCall->getBeginLoc(),
+   diag::err_hip_invalid_args_builtin_mangled_name);
+  return ExprError();
+}
+  }
   }
 
   // Since the target specific builtins for each arch overlap, only check those
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -12,6 +12,7 @@
 //===--===//
 
 #include "CGCUDARuntime.h"
+#include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
@@ -260,10 +261,15 @@
   else
 GD = GlobalDecl(ND);
   std::string DeviceSideName;
-  if (DeviceMC->shouldMangleDeclName(ND)) {
+  

[PATCH] D99243: [CMake][Fuchsia] Include llvm-lipo

2021-03-24 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39f3e9a9e07d: [CMake][Fuchsia] Include llvm-lipo (authored 
by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99243

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


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -263,6 +263,7 @@
   llvm-elfabi
   llvm-gsymutil
   llvm-lib
+  llvm-lipo
   llvm-mt
   llvm-nm
   llvm-objcopy


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -263,6 +263,7 @@
   llvm-elfabi
   llvm-gsymutil
   llvm-lib
+  llvm-lipo
   llvm-mt
   llvm-nm
   llvm-objcopy
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 39f3e9a - [CMake][Fuchsia] Include llvm-lipo

2021-03-24 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2021-03-24T14:21:40-07:00
New Revision: 39f3e9a9e07db547b8daac67155abf3a56b34181

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

LOG: [CMake][Fuchsia] Include llvm-lipo

We want to use llvm-lipo for building universal libraries.

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

Added: 


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

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 667e33c700d5..27391bdafb3e 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -263,6 +263,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-elfabi
   llvm-gsymutil
   llvm-lib
+  llvm-lipo
   llvm-mt
   llvm-nm
   llvm-objcopy



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


[PATCH] D98747: Thread safety analysis: Don't warn about managed locks on join points

2021-03-24 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Not replying in order, I hope that's not confusing. Let's start with the 
motivation.

In D98747#2648381 , @delesley wrote:

> Is there a compelling reason for this change, other than consistency/symmetry 
> concerns?  In other words, do you have real-world code where you are getting 
> false positives when using MutexUnlock?  If so, then I am in favor of the 
> change.  If not, then I tend to err on the side of "if it ain't broke don't 
> fix it."  :-)

When I originally implemented relockable scopes in D49885 
 I was (not sure if deliberately or not) 
making it stricter than regular scopes. But then there were a couple of cases 
in our code like this:

  RelockableMutexLock scope(, DeferTraits{});
  scope.Lock(); // Often also something like "if (!scope.TryLock()) return;"
  if (condition) {
scope.Unlock();
// ... do stuff without the lock
  } // warning: not all paths joining here hold the lock

The warning is somewhat surprising, because if you acquire in the constructor 
it's fine. (Compare e.g. `Foo::test2` on line 2593 with `join` on line 2891. 
The latter has a warning on the join point, the former doesn't.)

These are usually easy to fix, you can just add an else branch that releases 
the lock, but then we got into cases with nested ifs and people started asking: 
why can't I just rely on the RAII type to do the unlocking for me? There were 
maybe 5 cases or so and I could fix them all, but I couldn't really explain why 
it's fine when you lock in the constructor, but not if you lock later. (All 
through the RAII object of course.)

> A MutexLock object uses the RAII design pattern to ensure that the underlying 
> mutex is unlocked on every control flow path, and presumably includes logic 
> to prevent double releases/unlocks, as is usually the case with RAII.

Precisely, if `MutexLock` has an `Unlock` method, the destructor can't assume 
the lock is still held. `Unlock` itself though might assume it, so we might 
have false negatives here. But we've been accepting them before: see 
`Foo::test5`. (See below for a potential solution.)

> The RAII pattern is sufficiently robust that we can "trust the 
> implementation", and relax static checks.  A MutexUnlock object inverts the 
> RAII pattern.  Because a lock is being acquired on different control-flow 
> paths, rather than being released, it may make sense to keep the stronger 
> checks in order to guard against potential deadlocks.

I think we can assume the same thing here. If `MutexUnlock` has a `Lock`, then 
the destructor can't assume the lock is not held. But `Lock` might assume it, 
which means we have essentially the same false negative, except the other way 
around.

When it comes to deadlocks, I'm afraid that's not new:

  MutexLocker rlock(_);
  if (c)
rlock.Unlock();
  rlock.Lock();

might deadlock, but we don't warn currently. The reason is that we remove 
scoped locks when there are discrepancies at join points, because we don't want 
to miss race conditions. So we miss that the second `Lock` call might deadlock.

We could probably address all false negatives by introducing a `FactEntry` for 
"managed locks that might be held", which we introduce on discrepancies at join 
points. We assume that they're fine for the destructor, but we would warn if 
there is an explicit lock/unlock. I could start working on this if you think 
that's a good idea, but it would not only address false negatives introduced in 
this change, but also false negatives that we've had before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98747

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


[PATCH] D96771: [OpenCL] Add distinct file extension for C++ for OpenCL

2021-03-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D96771#2647848 , @gribozavr2 wrote:

> Pushed the most minimal fix in 
> https://github.com/llvm/llvm-project/commit/41454c30f6a38c3e107d857e63da0561610fd141,
>  please double check.

This looks great! Thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96771

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


[PATCH] D99297: [OPENMP]Fix PR49636: Assertion `(!Entry.getAddress() || Entry.getAddress() == Addr) && "Resetting with the new address."' failed.

2021-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added a reviewer: jdoerfert.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a project: clang.

The original issue is caused by the fact that the variable is allocated
with incorrect type i1 instead of i8. This causes the bitcasting of the
declaration to i8 type and the bitcast expression does not match the
original variable.
To fix the problem, the UndefValue initializer and the original
variable should be emitted with type i8, not i1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99297

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/OpenMP/declare_target_codegen.cpp


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -26,6 +26,7 @@
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}
 // CHECK-DAG: Bake
 // CHECK-NOT: @{{hhh|ggg|fff|eee}} =
+// CHECK-DAG: @flag = hidden global i8 undef,
 // CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb ={{ hidden | }}global i32 0,
 // CHECK-DAG: weak constant %struct.__tgt_offload_entry { i8* bitcast (i32* 
@bbb to i8*),
@@ -53,8 +54,8 @@
 
 #ifndef HEADER
 #define HEADER
-
 #pragma omp declare target
+bool flag [[clang::loader_uninitialized]];
 extern int bbb;
 #pragma omp end declare target
 #pragma omp declare target
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4256,9 +4256,9 @@
D->getType()->isCUDADeviceBuiltinTextureType());
   if (getLangOpts().CUDA &&
   (IsCUDASharedVar || IsCUDAShadowVar || IsCUDADeviceShadowVar))
-Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
+Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy));
   else if (D->hasAttr())
-Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
+Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy));
   else if (!InitExpr) {
 // This is a tentative definition; tentative definitions are
 // implicitly initialized with { 0 }.


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -26,6 +26,7 @@
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}
 // CHECK-DAG: Bake
 // CHECK-NOT: @{{hhh|ggg|fff|eee}} =
+// CHECK-DAG: @flag = hidden global i8 undef,
 // CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb ={{ hidden | }}global i32 0,
 // CHECK-DAG: weak constant %struct.__tgt_offload_entry { i8* bitcast (i32* @bbb to i8*),
@@ -53,8 +54,8 @@
 
 #ifndef HEADER
 #define HEADER
-
 #pragma omp declare target
+bool flag [[clang::loader_uninitialized]];
 extern int bbb;
 #pragma omp end declare target
 #pragma omp declare target
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4256,9 +4256,9 @@
D->getType()->isCUDADeviceBuiltinTextureType());
   if (getLangOpts().CUDA &&
   (IsCUDASharedVar || IsCUDAShadowVar || IsCUDADeviceShadowVar))
-Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
+Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy));
   else if (D->hasAttr())
-Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
+Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy));
   else if (!InitExpr) {
 // This is a tentative definition; tentative definitions are
 // implicitly initialized with { 0 }.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98286: [Driver] Enable kernel address and memory sanitizers on FreeBSD

2021-03-24 Thread Mark Johnston via Phabricator via cfe-commits
markj updated this revision to Diff 333106.
markj added a comment.

- Add a couple of regression tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98286

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -695,7 +695,13 @@
 // RUN: %clang -target x86_64-unknown-cloudabi -fsanitize=safe-stack %s -### 
2>&1 | FileCheck %s -check-prefix=SAFESTACK-CLOUDABI
 // SAFESTACK-CLOUDABI: "-fsanitize=safe-stack"
 
+// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-address %s -### 2>&1 
| FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
+// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-address %s -### 2>&1 
| FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
+// KERNEL-ADDRESS-FREEBSD: "-fsanitize=kernel-address"
 
+// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-memory %s -### 2>&1 | 
FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
+// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-memory %s -### 2>&1 
| FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
+// KERNEL-MEMORY-FREEBSD: "-fsanitize=kernel-memory"
 
 // * NetBSD; please keep ordered as in Sanitizers.def *
 
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -467,6 +467,7 @@
 bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
 
 SanitizerMask FreeBSD::getSupportedSanitizers() const {
+  const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64;
   const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
   const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
   const bool IsMIPS64 = getTriple().isMIPS64();
@@ -485,8 +486,13 @@
 Res |= SanitizerKind::Fuzzer;
 Res |= SanitizerKind::FuzzerNoLink;
   }
-  if (IsX86_64)
+  if (IsAArch64 || IsX86_64) {
+Res |= SanitizerKind::KernelAddress;
+Res |= SanitizerKind::KernelMemory;
+  }
+  if (IsX86_64) {
 Res |= SanitizerKind::Memory;
+  }
   return Res;
 }
 


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -695,7 +695,13 @@
 // RUN: %clang -target x86_64-unknown-cloudabi -fsanitize=safe-stack %s -### 2>&1 | FileCheck %s -check-prefix=SAFESTACK-CLOUDABI
 // SAFESTACK-CLOUDABI: "-fsanitize=safe-stack"
 
+// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-address %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
+// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-address %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
+// KERNEL-ADDRESS-FREEBSD: "-fsanitize=kernel-address"
 
+// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-memory %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
+// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-memory %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
+// KERNEL-MEMORY-FREEBSD: "-fsanitize=kernel-memory"
 
 // * NetBSD; please keep ordered as in Sanitizers.def *
 
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -467,6 +467,7 @@
 bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
 
 SanitizerMask FreeBSD::getSupportedSanitizers() const {
+  const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64;
   const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
   const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
   const bool IsMIPS64 = getTriple().isMIPS64();
@@ -485,8 +486,13 @@
 Res |= SanitizerKind::Fuzzer;
 Res |= SanitizerKind::FuzzerNoLink;
   }
-  if (IsX86_64)
+  if (IsAArch64 || IsX86_64) {
+Res |= SanitizerKind::KernelAddress;
+Res |= SanitizerKind::KernelMemory;
+  }
+  if (IsX86_64) {
 Res |= SanitizerKind::Memory;
+  }
   return Res;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97869: [OpenCL][Draft] Add OpenCL builtin test generator

2021-03-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

I have done some measurements using the test produced from this Tablegen 
emitter (59K lines).

I have used the test it in two files:

1. `SemaOpenCL/all-std-buitins.cl` that has the following RUN line appended 6 
times (for every supported OpenCL version v1.0, v1.1, v1.2, v2.0, v1.3, C++)

  //RUN: %clang_cc1 %s -triple=spir -fsyntax-only -verify -cl-std=CL2.0 
-finclude-default-header -fdeclare-opencl-builtins



2. `SemaOpenCL/all-std-buitins-slow-header.cl` that has the following RUN line 
appended 6 times (for every supported OpenCL version v1.0, v1.1, v1.2, v2.0, 
v3.0, C++)

  //RUN: %clang_cc1 %s -triple=spir -fsyntax-only -verify -cl-std=CL2.0 
-finclude-default-header

So I am getting the following testing time breakdown then:

  201.61s: Clang :: SemaOpenCL/all-std-buitins-slow-header.cl
  199.70s: Clang :: SemaOpenCL/all-std-buitins.cl
  85.14s: Clang :: Headers/arm-neon-header.c
  68.06s: Clang :: OpenMP/nesting_of_regions.cpp
  65.23s: Clang :: Driver/crash-report.c
  60.26s: Clang :: Analysis/PR24184.cpp
  57.80s: Clang :: CodeGen/X86/rot-intrinsics.c
  57.58s: Clang :: CodeGen/X86/x86_64-xsave.c
  56.34s: Clang :: Headers/opencl-c-header.cl
  55.68s: Clang :: CodeGen/X86/x86_32-xsave.c
  44.83s: Clang :: Driver/crash-report-with-asserts.c
  40.38s: Clang :: Lexer/SourceLocationsOverflow.c
  37.44s: Clang :: Headers/x86intrin-2.c
  36.53s: Clang :: 
OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp
  34.09s: Clang :: CodeGen/X86/avx512f-builtins-constrained.c
  33.41s: Clang :: CodeGen/X86/sse-builtins-constrained.c
  32.82s: Clang :: Analysis/iterator-modeling.cpp
  31.37s: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp
  31.10s: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp
  30.78s: Clang :: Analysis/use-after-move.cpp

I am very confused though about why is the difference between Tablegen and 
`opencl-c.h` so insignificant? FYI, also for a single clang invocation with 
Tablegen and `opencl-c.h` the difference is very insignificant in parsing time 
of this test - 20.794s vs 21.401s. This is really interesting because with 
small files the difference is huge 0.043s vs 3.990s on test with empty kernel.

---

I also timed `check-clang` invocation on my 8 core machine:

1. with both tests  - 697.70s
2. with all-std-buitins.cl only  - 684.43s
3. without any new tests  - 673.00s

The change in total testing time appears to be insignificant. I guess this is 
due to parallel execution?
Btw one thing I have thought of since OpenCL v1.0-1.1 doesn't differ a lot for 
builtin functions and they are not modified much either, perhaps we only need 
to test v1.2? That would reduce number of clang invocations to 4 in each test. 
Then the measurements are as follows:

  134.13s: Clang :: SemaOpenCL/all-std-buitins-slow-header.cl
  131.52s: Clang :: SemaOpenCL/all-std-buitins.cl
  85.81s: Clang :: Headers/arm-neon-header.c
  69.14s: Clang :: OpenMP/nesting_of_regions.cpp
  60.08s: Clang :: Driver/crash-report.c
  59.67s: Clang :: Analysis/PR24184.cpp
  57.27s: Clang :: CodeGen/X86/rot-intrinsics.c
  56.93s: Clang :: CodeGen/X86/x86_32-xsave.c
  56.59s: Clang :: CodeGen/X86/x86_64-xsave.c
  55.68s: Clang :: Headers/opencl-c-header.cl
  40.71s: Clang :: Driver/crash-report-with-asserts.c
  39.44s: Clang :: Lexer/SourceLocationsOverflow.c
  38.02s: Clang :: 
OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp
  37.07s: Clang :: Headers/x86intrin-2.c
  32.61s: Clang :: CodeGen/X86/avx512f-builtins-constrained.c
  32.58s: Clang :: CodeGen/X86/sse-builtins-constrained.c
  32.19s: Clang :: Analysis/use-after-move.cpp
  31.96s: Clang :: Analysis/iterator-modeling.cpp
  31.02s: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp
  30.59s: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp

with a total testing time 688.61s

**Conclusion:**

- if we test the whole functionality the test will be at least 2x slower than 
the slowest clang test so far but it hardly affect the full testing time of 
clang-check on modern HW due to the parallel execution. Also related to this 
partitioning of test files could help with the latency due to the parallel 
execution.
- Testing of opencl-c.h only doubles the testing time.


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

https://reviews.llvm.org/D97869

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


[PATCH] D98286: [Driver] Enable kernel address and memory sanitizers on FreeBSD

2021-03-24 Thread Mark Johnston via Phabricator via cfe-commits
markj added a comment.

In D98286#2648449 , @dim wrote:

> LGTM, but this would probably need some sort of test, at least that it 
> correctly accepts the flag(s) now?

Working on it, I see some examples.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98286

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


[PATCH] D98824: [Tooling] Handle compilation databases containing commands with double dashes

2021-03-24 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe030ce3ec790: [Tooling] Handle compilation databases 
containing commands with double dashes (authored by jnykiel, committed by 
aganea).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98824

Files:
  clang/lib/Tooling/ArgumentsAdjusters.cpp
  clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -725,14 +725,14 @@
 protected:
   // Look up the command from a relative path, and return it in string form.
   // The input file is not included in the returned command.
-  std::string getCommand(llvm::StringRef F) {
+  std::string getCommand(llvm::StringRef F, bool MakeNative = true) {
 auto Results =
 inferMissingCompileCommands(std::make_unique(Entries))
-->getCompileCommands(path(F));
+->getCompileCommands(MakeNative ? path(F) : F);
 if (Results.empty())
   return "none";
 // drop the input file argument, so tests don't have to deal with path().
-EXPECT_EQ(Results[0].CommandLine.back(), path(F))
+EXPECT_EQ(Results[0].CommandLine.back(), MakeNative ? path(F) : F)
 << "Last arg should be the file";
 Results[0].CommandLine.pop_back();
 return llvm::join(Results[0].CommandLine, " ");
@@ -812,6 +812,28 @@
   EXPECT_EQ(getCommand("dir/bar.cpp"), "clang -D dir/foo.cpp -Wall");
 }
 
+TEST_F(InterpolateTest, StripDoubleDash) {
+  add("dir/foo.cpp", "-o foo.o -std=c++14 -Wall -- dir/foo.cpp");
+  // input file and output option are removed
+  // -Wall flag isn't
+  // -std option gets re-added as the last argument before the input file
+  // -- is removed as it's not necessary - the new input file doesn't start with
+  // a dash
+  EXPECT_EQ(getCommand("dir/bar.cpp"), "clang -D dir/foo.cpp -Wall -std=c++14");
+}
+
+TEST_F(InterpolateTest, InsertDoubleDash) {
+  add("dir/foo.cpp", "-o foo.o -std=c++14 -Wall");
+  EXPECT_EQ(getCommand("-dir/bar.cpp", false),
+"clang -D dir/foo.cpp -Wall -std=c++14 --");
+}
+
+TEST_F(InterpolateTest, InsertDoubleDashForClangCL) {
+  add("dir/foo.cpp", "clang-cl", "/std:c++14 /W4");
+  EXPECT_EQ(getCommand("/dir/bar.cpp", false),
+"clang-cl -D dir/foo.cpp /W4 /std:c++14 --");
+}
+
 TEST_F(InterpolateTest, Case) {
   add("FOO/BAR/BAZ/SHOUT.cc");
   add("foo/bar/baz/quiet.cc");
@@ -831,7 +853,7 @@
   add("foo.cpp", "clang-cl", "/W4");
 
   // Language flags should be added with CL syntax.
-  EXPECT_EQ(getCommand("foo.h"), "clang-cl -D foo.cpp /W4 /TP");
+  EXPECT_EQ(getCommand("foo.h", false), "clang-cl -D foo.cpp /W4 /TP");
 }
 
 TEST_F(InterpolateTest, DriverModes) {
@@ -839,8 +861,10 @@
   add("bar.cpp", "clang", "--driver-mode=cl");
 
   // --driver-mode overrides should be respected.
-  EXPECT_EQ(getCommand("foo.h"), "clang-cl -D foo.cpp --driver-mode=gcc -x c++-header");
-  EXPECT_EQ(getCommand("bar.h"), "clang -D bar.cpp --driver-mode=cl /TP");
+  EXPECT_EQ(getCommand("foo.h"),
+"clang-cl -D foo.cpp --driver-mode=gcc -x c++-header");
+  EXPECT_EQ(getCommand("bar.h", false),
+"clang -D bar.cpp --driver-mode=cl /TP");
 }
 
 TEST(TransferCompileCommandTest, Smoke) {
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -440,8 +440,9 @@
   return;
 
   // If there's no override in place add our resource dir.
-  Args.push_back("-resource-dir=" +
- CompilerInvocation::GetResourcesPath(Argv0, MainAddr));
+  Args = getInsertArgumentAdjuster(
+  ("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, MainAddr))
+  .c_str())(Args, "");
 }
 
 int ClangTool::run(ToolAction *Action) {
Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -177,6 +177,10 @@
Opt.matches(OPT__SLASH_Fo
 continue;
 
+  // ...including when the inputs are passed after --.
+  if (Opt.matches(OPT__DASH_DASH))
+break;
+
   // Strip -x, but record the overridden language.
   if (const auto GivenType = tryParseTypeArg(*Arg)) {
 Type = *GivenType;
@@ -235,6 +239,8 @@
   llvm::Twine(ClangCLMode ? "/std:" : "-std=") +
   LangStandard::getLangStandardForKind(Std).getName()).str());
 }
+if (Filename.startswith("-") || (ClangCLMode && Filename.startswith("/")))
+  

[clang] e030ce3 - [Tooling] Handle compilation databases containing commands with double dashes

2021-03-24 Thread Alexandre Ganea via cfe-commits

Author: Janusz Nykiel
Date: 2021-03-24T16:01:47-04:00
New Revision: e030ce3ec790a0017ec789b4f487afec99e1cac9

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

LOG: [Tooling] Handle compilation databases containing commands with double 
dashes

As of CMake commit https://gitlab.kitware.com/cmake/cmake/-/commit/d993ebd4,
which first appeared in CMake 3.19.x series, in the compile commands for
clang-cl, CMake puts `--` before the input file. When operating on such a
database, the `InterpolatingCompilationDatabase` - specifically, the
`TransferableCommand` constructor - does not recognize that pattern and so, does
not strip the input, or the double dash when 'transferring' the compile command.
This results in a incorrect compile command - with the double dash and old input
file left in, and the language options and new input file appended after them,
where they're all treated as inputs, including the language version option.

Test files for some tests have names similar enough to be matched to commands
from the database, e.g.:

`.../path-mappings.test.tmp/server/bar.cpp`

can be matched to:

`.../Driver/ToolChains/BareMetal.cpp`

etc. When that happens, the tool being tested tries to use the matched, and
incorrectly 'transferred' compile command, and fails, reporting errors similar
to:

`error: no such file or directory: '/std:c++14'; did you mean '/std:c++14'? 
[clang-diagnostic-error]`

This happens in at least 4 tests:

  Clang Tools :: clang-tidy/checkers/performance-trivially-destructible.cpp
  Clangd :: check-fail.test
  Clangd :: check.test
  Clangd :: path-mappings.test

The fix for `TransferableCommand` removes the `--` and everything after it when
determining the arguments that apply to the new file. `--` is inserted in the
'transferred' command if the new file name starts with `-` and when operating in
clang-cl mode, also `/`. Additionally, other places in the code known to do
argument adjustment without accounting for the `--` and causing the tests to
fail are fixed as well.

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

Added: 


Modified: 
clang/lib/Tooling/ArgumentsAdjusters.cpp
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp 
b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index bcfb5b39a0770..d94673bd2ab90 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -62,7 +62,8 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
 HasSyntaxOnly = true;
 }
 if (!HasSyntaxOnly)
-  AdjustedArgs.push_back("-fsyntax-only");
+  AdjustedArgs =
+  getInsertArgumentAdjuster("-fsyntax-only")(AdjustedArgs, "");
 return AdjustedArgs;
   };
 }
@@ -137,7 +138,7 @@ ArgumentsAdjuster getInsertArgumentAdjuster(const 
CommandLineArguments ,
 
 CommandLineArguments::iterator I;
 if (Pos == ArgumentInsertPosition::END) {
-  I = Return.end();
+  I = std::find(Return.begin(), Return.end(), "--");
 } else {
   I = Return.begin();
   ++I; // To leave the program name in place

diff  --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp 
b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 6f97d2867ae5d..3b65504b98ea3 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -177,6 +177,10 @@ struct TransferableCommand {
Opt.matches(OPT__SLASH_Fo
 continue;
 
+  // ...including when the inputs are passed after --.
+  if (Opt.matches(OPT__DASH_DASH))
+break;
+
   // Strip -x, but record the overridden language.
   if (const auto GivenType = tryParseTypeArg(*Arg)) {
 Type = *GivenType;
@@ -235,6 +239,8 @@ struct TransferableCommand {
   llvm::Twine(ClangCLMode ? "/std:" : "-std=") +
   LangStandard::getLangStandardForKind(Std).getName()).str());
 }
+if (Filename.startswith("-") || (ClangCLMode && Filename.startswith("/")))
+  Result.CommandLine.push_back("--");
 Result.CommandLine.push_back(std::string(Filename));
 return Result;
   }

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 79851ac723da0..b28e8f6a7c967 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -440,8 +440,9 @@ static void injectResourceDir(CommandLineArguments , 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args.push_back("-resource-dir=" +
- CompilerInvocation::GetResourcesPath(Argv0, MainAddr));
+  Args = 

[PATCH] D95458: [PowerPC] Exploit xxsplti32dx (constant materialization) for scalars

2021-03-24 Thread Albion Fung via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe29bb074c62c: [PowerPC] Exploit xxsplti32dx (constant 
materialization) for scalars (authored by Conanap).

Changed prior to commit:
  https://reviews.llvm.org/D95458?vs=329015=333101#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95458

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/constant-pool.ll
  llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
  llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
  llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
  llvm/test/CodeGen/PowerPC/pcrel.ll

Index: llvm/test/CodeGen/PowerPC/pcrel.ll
===
--- llvm/test/CodeGen/PowerPC/pcrel.ll
+++ llvm/test/CodeGen/PowerPC/pcrel.ll
@@ -8,13 +8,14 @@
 
 ; Constant Pool Index.
 ; CHECK-S-LABEL: ConstPool
-; CHECK-S:   plfd f1, .LCPI0_0@PCREL(0), 1
+; CHECK-S:   xxsplti32dx vs1, 0, 1081002676
+; CHECK-S-NEXT:   xxsplti32dx vs1, 1, 962072674
 ; CHECK-S:   blr
 
 ; CHECK-O-LABEL: ConstPool
-; CHECK-O:   plfd 1, 0(0), 1
-; CHECK-O-NEXT:  R_PPC64_PCREL34  .rodata.cst8
-; CHECK-O:   blr
+; CHECK-O:   xxsplti32dx 1, 0, 1081002676
+; CHECK-O-NEXT:  xxsplti32dx 1, 1, 962072674
+; CHECK-O-NEXT:  blr
 define dso_local double @ConstPool() local_unnamed_addr {
   entry:
 ret double 0x406ECAB439581062
Index: llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
===
--- llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
+++ llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
@@ -35,6 +35,9 @@
 @FuncPtrOut = external local_unnamed_addr global void (...)*, align 8
 
 define dso_local void @ReadWrite8() local_unnamed_addr #0 {
+; In this test the stb r3, 0(r4) cannot be optimized because it
+; uses the register r3 and that register is defined by lbz r3, 0(r3)
+; which is defined between the pld and the stb.
 ; CHECK-LABEL: ReadWrite8:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, input8@got@pcrel(0), 1
@@ -44,9 +47,6 @@
 ; CHECK-NEXT:lbz r3, 0(r3)
 ; CHECK-NEXT:stb r3, 0(r4)
 ; CHECK-NEXT:blr
-; In this test the stb r3, 0(r4) cannot be optimized because it
-; uses the register r3 and that register is defined by lbz r3, 0(r3)
-; which is defined between the pld and the stb.
 entry:
   %0 = load i8, i8* @input8, align 1
   store i8 %0, i8* @output8, align 1
@@ -54,6 +54,9 @@
 }
 
 define dso_local void @ReadWrite16() local_unnamed_addr #0 {
+; In this test the sth r3, 0(r4) cannot be optimized because it
+; uses the register r3 and that register is defined by lhz r3, 0(r3)
+; which is defined between the pld and the sth.
 ; CHECK-LABEL: ReadWrite16:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, input16@got@pcrel(0), 1
@@ -63,9 +66,6 @@
 ; CHECK-NEXT:lhz r3, 0(r3)
 ; CHECK-NEXT:sth r3, 0(r4)
 ; CHECK-NEXT:blr
-; In this test the sth r3, 0(r4) cannot be optimized because it
-; uses the register r3 and that register is defined by lhz r3, 0(r3)
-; which is defined between the pld and the sth.
 entry:
   %0 = load i16, i16* @input16, align 2
   store i16 %0, i16* @output16, align 2
@@ -144,7 +144,8 @@
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, inputf64@got@pcrel(0), 1
 ; CHECK-NEXT:  .Lpcrel5:
-; CHECK-NEXT:plfd f1, .LCPI6_0@PCREL(0), 1
+; CHECK-NEXT:xxsplti32dx vs1, 0, 1075524403
+; CHECK-NEXT:xxsplti32dx vs1, 1, 858993459
 ; CHECK-NEXT:.reloc .Lpcrel5-8,R_PPC64_PCREL_OPT,.-(.Lpcrel5-8)
 ; CHECK-NEXT:lfd f0, 0(r3)
 ; CHECK-NEXT:pld r3, outputf64@got@pcrel(0), 1
Index: llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
===
--- llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
+++ llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
@@ -173,7 +173,9 @@
 ; CHECK-LARGE: add r2, r2, r12
 ; CHECK-S-NOT:   .localentry
 ; CHECK-ALL:   # %bb.0: # %entry
-; CHECK-S-NEXT:plfd f1, .LCPI7_0@PCREL(0), 1
+; CHECK-S-NEXT:xxsplti32dx vs1, 0, 1078011044
+; CHECK-S-NEXT:xxsplti32dx vs1, 1, -337824948
+; CHECK-S-NEXT:# kill: def $f1 killed $f1 killed $vsl1
 ; CHECK-S-NEXT:blr
 entry:
   ret double 0x404124A4EBDD334C
Index: llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
===
--- llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
+++ llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
@@ -122,19 +122,23 @@
 define dso_local double @testDoubleNonRepresentableScalar() local_unnamed_addr {
 ; CHECK-LE-LABEL: testDoubleNonRepresentableScalar:
 ; CHECK-LE:   # %bb.0: # %entry
-; 

[PATCH] D99288: [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

2021-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e9f6eba84f0: [OPENMP]Fix PR49468: Declare target should 
allow empty sequences and namespaces. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99288

Files:
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/declare_target_ast_print.cpp


Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@
 
 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
 llvm::SmallVector Decls;
-DKind = parseOpenMPDirectiveKind(*this);
-while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-   Tok.isNot(tok::r_brace)) {
+while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+TentativeParsingAction TPA(*this);
+ConsumeAnnotationToken();
+DKind = parseOpenMPDirectiveKind(*this);
+if (DKind != OMPD_end_declare_target)
+  TPA.Revert();
+else
+  TPA.Commit();
+  }
+  if (DKind == OMPD_end_declare_target)
+break;
   DeclGroupPtrTy Ptr;
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
@@ -2133,15 +2142,6 @@
 DeclGroupRef Ref = Ptr.get();
 Decls.append(Ref.begin(), Ref.end());
   }
-  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-TentativeParsingAction TPA(*this);
-ConsumeAnnotationToken();
-DKind = parseOpenMPDirectiveKind(*this);
-if (DKind != OMPD_end_declare_target)
-  TPA.Revert();
-else
-  TPA.Commit();
-  }
 }
 
 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);


Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@
 
 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
 llvm::SmallVector Decls;
-DKind = parseOpenMPDirectiveKind(*this);
-while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-   Tok.isNot(tok::r_brace)) {
+while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+TentativeParsingAction TPA(*this);
+ConsumeAnnotationToken();
+DKind = parseOpenMPDirectiveKind(*this);
+if (DKind != OMPD_end_declare_target)
+  TPA.Revert();
+else
+  TPA.Commit();
+  }
+  if (DKind == OMPD_end_declare_target)
+break;
   DeclGroupPtrTy Ptr;
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
@@ -2133,15 +2142,6 @@
 DeclGroupRef Ref = Ptr.get();
 Decls.append(Ref.begin(), Ref.end());
   }
-  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-TentativeParsingAction TPA(*this);
-ConsumeAnnotationToken();
-DKind = parseOpenMPDirectiveKind(*this);
-if (DKind != OMPD_end_declare_target)
-  TPA.Revert();
-else
-  TPA.Commit();
-  }
 }
 
 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9e9f6eb - [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

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

Author: Alexey Bataev
Date: 2021-03-24T12:53:33-07:00
New Revision: 9e9f6eba84f01785ef154539878a7ebd2692344a

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

LOG: [OPENMP]Fix PR49468: Declare target should allow empty sequences and 
namespaces.

The emty declare target/end declare target region should not cause an
error emission.

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

Added: 


Modified: 
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/declare_target_ast_print.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 2e0104e3d348..1ea01409d3d3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 
 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
 llvm::SmallVector Decls;
-DKind = parseOpenMPDirectiveKind(*this);
-while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-   Tok.isNot(tok::r_brace)) {
+while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+TentativeParsingAction TPA(*this);
+ConsumeAnnotationToken();
+DKind = parseOpenMPDirectiveKind(*this);
+if (DKind != OMPD_end_declare_target)
+  TPA.Revert();
+else
+  TPA.Commit();
+  }
+  if (DKind == OMPD_end_declare_target)
+break;
   DeclGroupPtrTy Ptr;
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
@@ -2133,15 +2142,6 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 DeclGroupRef Ref = Ptr.get();
 Decls.append(Ref.begin(), Ref.end());
   }
-  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-TentativeParsingAction TPA(*this);
-ConsumeAnnotationToken();
-DKind = parseOpenMPDirectiveKind(*this);
-if (DKind != OMPD_end_declare_target)
-  TPA.Revert();
-else
-  TPA.Commit();
-  }
 }
 
 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);

diff  --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index c086f8526147..dbd0b923a7d6 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@ int main (int argc, char **argv) {
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif



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


[PATCH] D98275: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

2021-03-24 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp:29-30
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+

aaron.ballman wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > This is racy, but I don't think we support running multiple checks in 
> > > parallel, do we?
> > This isn't racy as one instance of a check will only ever run on one 
> > thread. 
> I was thinking if the check gets run multiple times in parallel on different 
> source files (e.g., someone downstream who incorporates the checks as a 
> library in a creative way rather than runs clang-tidy as a command line 
> tool). But yeah, I'm not worried about it as I don't think we support that 
> sort of thing.
Plenty of other checks hold state that is mutated in the check callback, so if 
this is a race, all the other checks that mutate state in the callbacks will 
also have a race.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98275

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


[PATCH] D99259: [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions

2021-03-24 Thread Heejin Ahn 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 rGa6aae5f7fcd1: [WebAssembly] Dont inline 
-emscripten-cxx-exceptions-allowed functions (authored by aheejin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99259

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -79,6 +79,21 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_SIGN_EXT %s
 // PTHREAD_NO_SIGN_EXT: invalid argument '-pthread' not allowed with 
'-mno-sign-ext'
 
+// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
+// '-mllvm --force-attribute=foo:noinline -mllvm 
--force-attribute=bar:noinline'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN:--sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN:-mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
+// RUN:  | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
+// EMSCRIPTEN_EH_ALLOWED_NOINLINE: clang{{.*}}" "-cc1" {{.*}} "-mllvm" 
"--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
+
+// '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with
+// '-mllvm -enable-emscripten-cxx-exceptions'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -mllvm -emscripten-cxx-exceptions-allowed 2>&1 \
+// RUN:   | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
+// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument '-mllvm 
-emscripten-cxx-exceptions-allowed' only allowed with '-mllvm 
-enable-emscripten-cxx-exceptions'
+
 // '-fwasm-exceptions' sets +exception-handling
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fwasm-exceptions 2>&1 \
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -294,6 +294,36 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+exception-handling");
   }
+
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+StringRef Opt = A->getValue(0);
+if (Opt.startswith("-emscripten-cxx-exceptions-allowed")) {
+  // '-mllvm -emscripten-cxx-exceptions-allowed' should be used with
+  // '-mllvm -enable-emscripten-cxx-exceptions'
+  bool EmExceptionArgExists = false;
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions") {
+  EmExceptionArgExists = true;
+  break;
+}
+  }
+  if (!EmExceptionArgExists)
+getDriver().Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mllvm -emscripten-cxx-exceptions-allowed"
+<< "-mllvm -enable-emscripten-cxx-exceptions";
+
+  // Prevent functions specified in -emscripten-cxx-exceptions-allowed list
+  // from being inlined before reaching the wasm backend.
+  StringRef FuncNamesStr = Opt.split('=').second;
+  SmallVector FuncNames;
+  FuncNamesStr.split(FuncNames, ',');
+  for (auto Name : FuncNames) {
+CC1Args.push_back("-mllvm");
+CC1Args.push_back(DriverArgs.MakeArgString("--force-attribute=" + Name 
+
+   ":noinline"));
+  }
+}
+  }
 }
 
 ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const {


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -79,6 +79,21 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_SIGN_EXT %s
 // PTHREAD_NO_SIGN_EXT: invalid argument '-pthread' not allowed with '-mno-sign-ext'
 
+// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
+// '-mllvm --force-attribute=foo:noinline -mllvm --force-attribute=bar:noinline'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN:--sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN:-mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
+// RUN:  | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
+// EMSCRIPTEN_EH_ALLOWED_NOINLINE: clang{{.*}}" "-cc1" {{.*}} "-mllvm" "--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
+
+// '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with
+// '-mllvm -enable-emscripten-cxx-exceptions'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s 

[clang] a6aae5f - [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions

2021-03-24 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2021-03-24T12:27:49-07:00
New Revision: a6aae5f7fcddb87bfe77072912484213f872

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

LOG: [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions

Functions specified in `-emscripten-cxx-exceptions-allowed`, which is
set by Emscripten's `EXCEPTION_CATCHING_ALLOWED` setting, can be inlined
in LLVM middle ends before we reach WebAssemblyLowerEmscriptenEHSjLj
pass in the wasm backend and thus don't get transformed for exception
catching.

This fixes the issue by adding `--force-attribute=FUNC_NAME:noinline`
for each function name in `-emscripten-cxx-exceptions-allowed`, which
adds `noinline` attribute to the specified function and thus excludes
the function from inlining candidates in optimization passes.

Fixes the remaining half of
https://github.com/emscripten-core/emscripten/issues/10721.

Reviewed By: sbc100

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/test/Driver/wasm-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 8c4d99b8ad07..e1ca90b195e2 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -294,6 +294,36 @@ void WebAssembly::addClangTargetOptions(const ArgList 
,
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+exception-handling");
   }
+
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+StringRef Opt = A->getValue(0);
+if (Opt.startswith("-emscripten-cxx-exceptions-allowed")) {
+  // '-mllvm -emscripten-cxx-exceptions-allowed' should be used with
+  // '-mllvm -enable-emscripten-cxx-exceptions'
+  bool EmExceptionArgExists = false;
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions") {
+  EmExceptionArgExists = true;
+  break;
+}
+  }
+  if (!EmExceptionArgExists)
+getDriver().Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mllvm -emscripten-cxx-exceptions-allowed"
+<< "-mllvm -enable-emscripten-cxx-exceptions";
+
+  // Prevent functions specified in -emscripten-cxx-exceptions-allowed list
+  // from being inlined before reaching the wasm backend.
+  StringRef FuncNamesStr = Opt.split('=').second;
+  SmallVector FuncNames;
+  FuncNamesStr.split(FuncNames, ',');
+  for (auto Name : FuncNames) {
+CC1Args.push_back("-mllvm");
+CC1Args.push_back(DriverArgs.MakeArgString("--force-attribute=" + Name 
+
+   ":noinline"));
+  }
+}
+  }
 }
 
 ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const {

diff  --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index 17037819cfda..d2e6de4667ac 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -79,6 +79,21 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_SIGN_EXT %s
 // PTHREAD_NO_SIGN_EXT: invalid argument '-pthread' not allowed with 
'-mno-sign-ext'
 
+// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
+// '-mllvm --force-attribute=foo:noinline -mllvm 
--force-attribute=bar:noinline'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN:--sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN:-mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
+// RUN:  | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
+// EMSCRIPTEN_EH_ALLOWED_NOINLINE: clang{{.*}}" "-cc1" {{.*}} "-mllvm" 
"--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
+
+// '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with
+// '-mllvm -enable-emscripten-cxx-exceptions'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -mllvm -emscripten-cxx-exceptions-allowed 2>&1 \
+// RUN:   | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
+// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument '-mllvm 
-emscripten-cxx-exceptions-allowed' only allowed with '-mllvm 
-enable-emscripten-cxx-exceptions'
+
 // '-fwasm-exceptions' sets +exception-handling
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fwasm-exceptions 2>&1 \



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


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

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

In D99262#2648533 , @vsavchenko wrote:

> In D99262#2648512 , @steakhal wrote:
>
>> I see your point.
>>
>> Would it report this issue?
>>
>>   int test() {
>> struct Foo foo = {0, 0}; // I would expect a warning here, that 'foo' 
>> was initialized but never read.
>> (void)foo;
>>return 0;
>>   }
>>
>> Only nits besides this.
>
> We got one big fat complaint about that, and I can see the point.

We should at least document it as testcase.




Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:25
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"

vsavchenko wrote:
> steakhal wrote:
> > I don't see any new code that would depend on this header.
> `llvm::all_of`?
Oh sure!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99262

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


[PATCH] D98275: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

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



Comment at: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp:29-30
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+

njames93 wrote:
> aaron.ballman wrote:
> > This is racy, but I don't think we support running multiple checks in 
> > parallel, do we?
> This isn't racy as one instance of a check will only ever run on one thread. 
I was thinking if the check gets run multiple times in parallel on different 
source files (e.g., someone downstream who incorporates the checks as a library 
in a creative way rather than runs clang-tidy as a command line tool). But 
yeah, I'm not worried about it as I don't think we support that sort of thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98275

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


[PATCH] D99288: [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

2021-03-24 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert 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/D99288/new/

https://reviews.llvm.org/D99288

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


[PATCH] D99292: [flang][driver] Add support for `-cpp/-nocpp`

2021-03-24 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/include/flang/Frontend/CompilerInvocation.h:135-138
+
+  /// Updates this instance based on the extension of the input file (e.g. f90
+  /// s F90)
+  void updateBasedOnExtension(const FrontendInputFile );

DELETEME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99292

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


[PATCH] D98745: [clang] Add fixit for Wreorder-ctor

2021-03-24 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG279ea930fa21: [clang] Add fixit for Wreorder-ctor (authored 
by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98745

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/FixIt/fixit-cxx-init-order.cpp
  clang/test/SemaCXX/constructor-initializer.cpp
  clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp

Index: clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp
===
--- clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp
+++ clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp
@@ -4,15 +4,14 @@
 
 struct BB1 {};
 
-class complex : public BB, BB1 { 
-public: 
+class complex : public BB, BB1 {
+public:
   complex()
-: s2(1), // expected-warning {{field 's2' will be initialized after field 's1'}}
-  s1(1),
-  s3(3), // expected-warning {{field 's3' will be initialized after base 'BB1'}} 
-  BB1(), // expected-warning {{base class 'BB1' will be initialized after base 'BB'}}
-  BB()
-  {}
+  : s2(1), // expected-warning {{initializer order does not match the declaration order}} expected-note {{field 's2' will be initialized after field 's1'}}
+s1(1),
+s3(3), // expected-note {{field 's3' will be initialized after base 'BB1'}}
+BB1(), // expected-note {{base class 'BB1' will be initialized after base 'BB'}}
+BB() {}
   int s1;
   int s2;
   int s3;
Index: clang/test/SemaCXX/constructor-initializer.cpp
===
--- clang/test/SemaCXX/constructor-initializer.cpp
+++ clang/test/SemaCXX/constructor-initializer.cpp
@@ -91,13 +91,14 @@
 
 struct Current : Derived {
   int Derived;
-  Current() : Derived(1), ::Derived(), // expected-warning {{field 'Derived' will be initialized after base '::Derived'}} \
-   // expected-warning {{base class '::Derived' will be initialized after base 'Derived::V'}}
-  ::Derived::Base(), // expected-error {{type '::Derived::Base' is not a direct or virtual base of 'Current'}}
-   Derived::Base1(), // expected-error {{type 'Derived::Base1' is not a direct or virtual base of 'Current'}}
-   Derived::V(),
-   ::NonExisting(), // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
-   INT::NonExisting()  {} // expected-error {{'INT' (aka 'int') is not a class, namespace, or enumeration}} \
+  Current() : Derived(1), ::Derived(), // expected-warning {{initializer order does not match the declaration order}} \
+   // expected-note {{field 'Derived' will be initialized after base '::Derived'}} \
+   // expected-note {{base class '::Derived' will be initialized after base 'Derived::V'}}
+  ::Derived::Base(),   // expected-error {{type '::Derived::Base' is not a direct or virtual base of 'Current'}}
+  Derived::Base1(),// expected-error {{type 'Derived::Base1' is not a direct or virtual base of 'Current'}}
+  Derived::V(),
+  ::NonExisting(),  // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
+  INT::NonExisting() {} // expected-error {{'INT' (aka 'int') is not a class, namespace, or enumeration}} \
   // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
 };
 
Index: clang/test/FixIt/fixit-cxx-init-order.cpp
===
--- /dev/null
+++ clang/test/FixIt/fixit-cxx-init-order.cpp
@@ -0,0 +1,22 @@
+// Due to the fix having multiple edits we can't use
+// '-fdiagnostics-parseable-fixits' to determine if fixes are correct. However,
+// running fixit recompile with 'Werror' should fail if the fixes are invalid.
+
+// RUN: %clang_cc1 %s -Werror=reorder-ctor -fixit-recompile -fixit-to-temporary
+// RUN: %clang_cc1 %s -Wreorder-ctor -verify -verify-ignore-unexpected=note
+
+struct Foo {
+  int A, B, C;
+
+  Foo() : A(1), B(3), C(2) {}
+  Foo(int) : A(1), C(2), B(3) {}  // expected-warning {{field 'C' will be initialized after field 'B'}}
+  Foo(unsigned) : C(2), B(3), A(1) {} // expected-warning {{initializer order does not match the declaration order}}
+};
+
+struct Bar : Foo {
+  int D, E, F;
+
+  Bar() : Foo(), D(1), E(2), F(3) {}
+  Bar(int) : D(1), E(2), F(3), Foo(4) {}  // expected-warning {{field 'F' will be initialized after base 'Foo'}}
+  Bar(unsigned) : F(3), E(2), D(1), Foo(4) {} // expected-warning {{initializer order does not 

[clang] 279ea93 - [clang] Add fixit for Wreorder-ctor

2021-03-24 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-03-24T19:22:53Z
New Revision: 279ea930fa21b283688b2598816095a48d0ca4d7

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

LOG: [clang] Add fixit for Wreorder-ctor

Create fix-it hints to fix the order of constructors.
To make this a lot simpler, I've grouped all the warnings for each out of order 
initializer into 1.
This is necessary as fixing one initializer would often interfere with other 
initializers.

Reviewed By: aaron.ballman

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

Added: 
clang/test/FixIt/fixit-cxx-init-order.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/constructor-initializer.cpp
clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 492ff63fe5ad..58e221a00468 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8606,6 +8606,15 @@ def warn_initializer_out_of_order : Warning<
   "%select{field|base class}0 %1 will be initialized after "
   "%select{field|base}2 %3">,
   InGroup, DefaultIgnore;
+
+def warn_some_initializers_out_of_order : Warning<
+  "initializer order does not match the declaration order">,
+  InGroup, DefaultIgnore;
+
+def note_initializer_out_of_order : Note<
+  "%select{field|base class}0 %1 will be initialized after "
+  "%select{field|base}2 %3">;
+
 def warn_abstract_vbase_init_ignored : Warning<
   "initializer for virtual base class %0 of abstract class %1 "
   "will never be used">,

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8470fad39854..f54dd4cb6f43 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5234,6 +5234,20 @@ static const void *GetKeyForMember(ASTContext ,
   return Member->getAnyMember()->getCanonicalDecl();
 }
 
+static void AddInitializerToDiag(const Sema::SemaDiagnosticBuilder ,
+ const CXXCtorInitializer *Previous,
+ const CXXCtorInitializer *Current) {
+  if (Previous->isAnyMemberInitializer())
+Diag << 0 << Previous->getAnyMember();
+  else
+Diag << 1 << Previous->getTypeSourceInfo()->getType();
+
+  if (Current->isAnyMemberInitializer())
+Diag << 0 << Current->getAnyMember();
+  else
+Diag << 1 << Current->getTypeSourceInfo()->getType();
+}
+
 static void DiagnoseBaseOrMemInitializerOrder(
 Sema , const CXXConstructorDecl *Constructor,
 ArrayRef Inits) {
@@ -5283,10 +5297,15 @@ static void DiagnoseBaseOrMemInitializerOrder(
   unsigned NumIdealInits = IdealInitKeys.size();
   unsigned IdealIndex = 0;
 
-  CXXCtorInitializer *PrevInit = nullptr;
+  // Track initializers that are in an incorrect order for either a warning or
+  // note if multiple ones occur.
+  SmallVector WarnIndexes;
+  // Correlates the index of an initializer in the init-list to the index of
+  // the field/base in the class.
+  SmallVector, 32> CorrelatedInitOrder;
+
   for (unsigned InitIndex = 0; InitIndex != Inits.size(); ++InitIndex) {
-CXXCtorInitializer *Init = Inits[InitIndex];
-const void *InitKey = GetKeyForMember(SemaRef.Context, Init);
+const void *InitKey = GetKeyForMember(SemaRef.Context, Inits[InitIndex]);
 
 // Scan forward to try to find this initializer in the idealized
 // initializers list.
@@ -5297,20 +5316,8 @@ static void DiagnoseBaseOrMemInitializerOrder(
 // If we didn't find this initializer, it must be because we
 // scanned past it on a previous iteration.  That can only
 // happen if we're out of order;  emit a warning.
-if (IdealIndex == NumIdealInits && PrevInit) {
-  Sema::SemaDiagnosticBuilder D =
-SemaRef.Diag(PrevInit->getSourceLocation(),
- diag::warn_initializer_out_of_order);
-
-  if (PrevInit->isAnyMemberInitializer())
-D << 0 << PrevInit->getAnyMember()->getDeclName();
-  else
-D << 1 << PrevInit->getTypeSourceInfo()->getType();
-
-  if (Init->isAnyMemberInitializer())
-D << 0 << Init->getAnyMember()->getDeclName();
-  else
-D << 1 << Init->getTypeSourceInfo()->getType();
+if (IdealIndex == NumIdealInits && InitIndex) {
+  WarnIndexes.push_back(InitIndex);
 
   // Move back to the initializer's location in the ideal list.
   for (IdealIndex = 0; IdealIndex != NumIdealInits; ++IdealIndex)
@@ -5320,8 +5327,54 @@ static void DiagnoseBaseOrMemInitializerOrder(
   assert(IdealIndex < NumIdealInits &&
  "initializer not found in initializer list");
 }
+

[PATCH] D98275: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

2021-03-24 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp:29-30
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+

aaron.ballman wrote:
> This is racy, but I don't think we support running multiple checks in 
> parallel, do we?
This isn't racy as one instance of a check will only ever run on one thread. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98275

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


[PATCH] D99292: [flang][driver] Add support for `-cpp/-nocpp`

2021-03-24 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added subscribers: jansvoboda11, dang.
awarzynski requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds support for the `-cpp` and `-nocpp` flags. The
implemented semantics match f18 (i.e. the "throwaway" driver), but are
different to gfortran. In Flang the preprocessor is always run and
`-cpp/-nocpp` are only used to control whether standard macro
predefinitions are added or not. In practice this is sufficient to model
gfortran`s `-cpp/-nocpp`.

In the absence of `-cpp/-nocpp`, the driver will use the extension of
the input file to decide whether to include the standard macro
predefinitions. gfortran's documentation [1] was used to decide which
file extension to use for this. The extension for:

- predefined-macros-compiler-version.f90

had to be updated accordingly.

The logic mentioned above was added in FrontendAction::BeginSourceFile.
That's relatively late in the driver set-up, but this roughly where the
name of the input file becomes available. The logic for deciding between
fixed and free form works in an a similar way and was also moved to
FrontendAction::BeginSourceFile for consistency (and to reduce
code-duplication).

[1] https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99292

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendAction.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/test/Driver/cpp_nocpp.F90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/predefined-macros-compiler-version.F90
  flang/test/Driver/predefined-macros-compiler-version.f90

Index: flang/test/Driver/predefined-macros-compiler-version.f90
===
--- /dev/null
+++ flang/test/Driver/predefined-macros-compiler-version.f90
@@ -1,26 +0,0 @@
-! Check that the driver correctly defines macros with the compiler version
-
-! REQUIRES: new-flang-driver
-
-!--
-! FLANG DRIVER (flang-new)
-!--
-! RUN: %flang-new -E %s  2>&1 | FileCheck %s --ignore-case
-
-!-
-! FRONTEND FLANG DRIVER (flang-new -fc1)
-!-
-! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --ignore-case
-
-!-
-! EXPECTED OUTPUT
-!-
-! CHECK: flang = 1
-! CHECK: flang_major = {{[1-9][0-9]*$}}
-! CHECK: flang_minor = {{[0-9]+$}}
-! CHECK: flang_patchlevel = {{[0-9]+$}}
-
-integer, parameter :: flang = __flang__
-integer, parameter :: flang_major = __flang_major__
-integer, parameter :: flang_minor = __flang_minor__
-integer, parameter :: flang_patchlevel = __flang_patchlevel__
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -19,6 +19,7 @@
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
 ! HELP-NEXT: -###   Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -cpp   Always add standard macro predefinitions
 ! HELP-NEXT: -c Only run preprocess, compile, and assemble steps
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
@@ -46,6 +47,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
+! HELP-NEXT: -nocpp Never add standard macro predefinitions
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -57,6 +59,7 @@
 ! HELP-FC1:USAGE: flang-new
 ! HELP-FC1-EMPTY:
 ! HELP-FC1-NEXT:OPTIONS:
+! HELP-FC1-NEXT: -cpp   Always add standard macro predefinitions
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
@@ -95,6 +98,7 @@
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
+! HELP-FC1-NEXT: -nocpp Never add standard macro predefinitions
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -test-io 

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

2021-03-24 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L created this revision.
Xiangling_L added reviewers: jasonliu, hubert.reinterpretcast, ZarkoCA, xingxue.
Herald added a reviewer: aaron.ballman.
Xiangling_L requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99291

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

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

[PATCH] D98275: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

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

LGTM, thanks!




Comment at: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp:29-30
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+

This is racy, but I don't think we support running multiple checks in parallel, 
do we?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98275

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


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

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

In D99262#2648512 , @steakhal wrote:

> I see your point.
>
> Would it report this issue?
>
>   int test() {
> struct Foo foo = {0, 0}; // I would expect a warning here, that 'foo' was 
> initialized but never read.
> (void)foo;
>return 0;
>   }
>
> Only nits besides this.

We got one big fat complaint about that, and I can see the point.




Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:25
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"

steakhal wrote:
> I don't see any new code that would depend on this header.
`llvm::all_of`?



Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:420-425
+  if (const auto *ILE =
+  dyn_cast(E->IgnoreParenCasts()))
+if (llvm::all_of(ILE->inits(), [this](const Expr *Init) {
+  return Init->isEvaluatable(Ctx);
+}))
+  return;

steakhal wrote:
> Eh, the indentation looks horrible.
> It would be probably better to use braces here.
Yeah, I agree. I'm not sure braces will help much.  I will try to do smith 
about it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99262

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


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

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

I see your point.

Would it report this issue?

  int test() {
struct Foo foo = {0, 0}; // I would expect a warning here, that 'foo' was 
initialized but never read.
(void)foo;
   return 0;
  }

Only nits besides this.




Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:25
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"

I don't see any new code that would depend on this header.



Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:420-425
+  if (const auto *ILE =
+  dyn_cast(E->IgnoreParenCasts()))
+if (llvm::all_of(ILE->inits(), [this](const Expr *Init) {
+  return Init->isEvaluatable(Ctx);
+}))
+  return;

Eh, the indentation looks horrible.
It would be probably better to use braces here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99262

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


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

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



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst:17
+Calls to ``new`` can throw exception of type ``bad_alloc`` that should be
+handled by the code. Alternatively the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:20
+
+void f1() noexcept {
+  int *I1 = new int;

It would be useful to also have a test with a function-try-block to ensure 
those are handled properly.



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

You have tests for placement new with `nothrow_t`, but I think other forms of 
placement new are also very interesting to test as those typically don't throw.

Additionally, perhaps tests where the allocation functions have been replaced 
by the user (such as a class allocation function)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97196

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


[PATCH] D99288: [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

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

The emty declare target/end declare target region should not cause an
error emission.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99288

Files:
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/declare_target_ast_print.cpp


Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@
 
 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
 llvm::SmallVector Decls;
-DKind = parseOpenMPDirectiveKind(*this);
-while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-   Tok.isNot(tok::r_brace)) {
+while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+TentativeParsingAction TPA(*this);
+ConsumeAnnotationToken();
+DKind = parseOpenMPDirectiveKind(*this);
+if (DKind != OMPD_end_declare_target)
+  TPA.Revert();
+else
+  TPA.Commit();
+  }
+  if (DKind == OMPD_end_declare_target)
+break;
   DeclGroupPtrTy Ptr;
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
@@ -2133,15 +2142,6 @@
 DeclGroupRef Ref = Ptr.get();
 Decls.append(Ref.begin(), Ref.end());
   }
-  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-TentativeParsingAction TPA(*this);
-ConsumeAnnotationToken();
-DKind = parseOpenMPDirectiveKind(*this);
-if (DKind != OMPD_end_declare_target)
-  TPA.Revert();
-else
-  TPA.Commit();
-  }
 }
 
 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);


Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@
 
 ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
 llvm::SmallVector Decls;
-DKind = parseOpenMPDirectiveKind(*this);
-while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-   Tok.isNot(tok::r_brace)) {
+while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+TentativeParsingAction TPA(*this);
+ConsumeAnnotationToken();
+DKind = parseOpenMPDirectiveKind(*this);
+if (DKind != OMPD_end_declare_target)
+  TPA.Revert();
+else
+  TPA.Commit();
+  }
+  if (DKind == OMPD_end_declare_target)
+break;
   DeclGroupPtrTy Ptr;
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
@@ -2133,15 +2142,6 @@
 DeclGroupRef Ref = Ptr.get();
 Decls.append(Ref.begin(), Ref.end());
   }
-  if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-TentativeParsingAction TPA(*this);
-ConsumeAnnotationToken();
-DKind = parseOpenMPDirectiveKind(*this);
-if (DKind != OMPD_end_declare_target)
-  TPA.Revert();
-else
-  TPA.Commit();
-  }
 }
 
 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98286: [Driver] Enable kernel address and memory sanitizers on FreeBSD

2021-03-24 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.

LGTM, but this would probably need some sort of test, at least that it 
correctly accepts the flag(s) now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98286

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


[PATCH] D99285: [SystemZ][z/OS] csv files should be text files

2021-03-24 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan created this revision.
abhina.sreeskantharajan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch sets the OF_Text flag correctly for the csv file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99285

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4081,7 +4081,8 @@
 Out.flush();
 std::error_code EC;
 llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
-llvm::sys::fs::OF_Append);
+llvm::sys::fs::OF_Append |
+llvm::sys::fs::OF_Text);
 if (EC)
   return;
 auto L = OS.lock();


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4081,7 +4081,8 @@
 Out.flush();
 std::error_code EC;
 llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
-llvm::sys::fs::OF_Append);
+llvm::sys::fs::OF_Append |
+llvm::sys::fs::OF_Text);
 if (EC)
   return;
 auto L = OS.lock();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65572: Fix static linking failure with --unwindlib=libunwind

2021-03-24 Thread Khem Raj via Phabricator via cfe-commits
raj.khem added a comment.

@MaskRay how should be proceeed here


Repository:
  rC Clang

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

https://reviews.llvm.org/D65572

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


[PATCH] D98747: Thread safety analysis: Don't warn about managed locks on join points

2021-03-24 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley added a comment.

Thanks for roping me into the conversation, Aaron, and sorry about the delay.  
I have mixed feelings about this patch.  With respect to the purpose of thread 
safety analysis, finding race conditions is obviously a major concern, because 
race conditions are hard to find in tests.  However, preventing deadlocks is 
almost as important, and can be even more important in certain critical 
applications.  The consequence of a double unlock is usually a crash or an 
exception with an error message.  The consequence of a double lock is often a 
deadlock, depending on the underlying thread library, which is a more serious 
problem that is harder to fix.  Thus, I am concerned about the change in the 
test case on line 2895, where a potential deadlock has gone from detected, to 
no warning.  Deadlocks are often not found in tests, because test coverage is 
never perfect over all possible control-flow paths.

The use cases here are also slightly different.  A MutexLock object uses the 
RAII design pattern to ensure that the underlying mutex is unlocked on every 
control flow path, and presumably includes logic to prevent double 
releases/unlocks, as is usually the case with RAII.  The RAII pattern is 
sufficiently robust that we can "trust the implementation", and relax static 
checks.  A MutexUnlock object inverts the RAII pattern.  Because a lock is 
being acquired on different control-flow paths, rather than being released, it 
may make sense to keep the stronger checks in order to guard against potential 
deadlocks.  On the other hand, we are still using RAII, so the implementer of 
MutexUnlock could presumably insert logic to guard against deadlocks if that 
was a concern.  Thus, I could be persuaded that deadlocks are less important in 
this particular case.

Is there a compelling reason for this change, other than consistency/symmetry 
concerns?  In other words, do you have real-world code where you are getting 
false positives when using MutexUnlock?  If so, then I am in favor of the 
change.  If not, then I tend to err on the side of "if it ain't broke don't fix 
it."  :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98747

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


[PATCH] D71369: Detect libdl from cmake variable

2021-03-24 Thread Khem Raj via Phabricator via cfe-commits
raj.khem abandoned this revision.
raj.khem added a comment.

0073c293a401774ac96b4b3d27f05e13f379f98e 
 has fixed 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71369

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


[PATCH] D46914: Run scan-view on systems with python3 as default python provider

2021-03-24 Thread Khem Raj via Phabricator via cfe-commits
raj.khem abandoned this revision.
raj.khem added a comment.

it works with python3 too, perhaps it would be good to ask for python3 instead


Repository:
  rC Clang

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

https://reviews.llvm.org/D46914

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


[PATCH] D99086: [clang][Syntax] Optimize expandedTokens for token ranges.

2021-03-24 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 333052.
usaxena95 added a comment.

Remove unintended changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99086

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -106,6 +106,7 @@
   void EndSourceFileAction() override {
 assert(Collector && "BeginSourceFileAction was never called");
 Result = std::move(*Collector).consume();
+Result.indexExpandedTokens();
   }
 
   std::unique_ptr
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,7 +183,31 @@
   return Text.substr(Begin, length());
 }
 
+void TokenBuffer::indexExpandedTokens() {
+  // No-op if the index is already created.
+  if (!ExpandedTokIndex.empty())
+return;
+  ExpandedTokIndex.reserve(ExpandedTokens.size());
+  // Index ExpandedTokens for faster lookups by SourceLocation.
+  for (size_t I = 0, E = ExpandedTokens.size(); I != E; ++I)
+ExpandedTokIndex[ExpandedTokens[I].location()] = I;
+}
+
 llvm::ArrayRef TokenBuffer::expandedTokens(SourceRange R) const {
+  if (!ExpandedTokIndex.empty()) {
+// Quick lookup if `R` is a token range.
+// This is a huge win since majority of the users use ranges provided by an
+// AST. Ranges in AST are token ranges from expanded token stream.
+const auto B = ExpandedTokIndex.find(R.getBegin());
+const auto E = ExpandedTokIndex.find(R.getEnd());
+if (B != ExpandedTokIndex.end() && E != ExpandedTokIndex.end()) {
+  // Add 1 to End to make a half-open range.
+  return {ExpandedTokens.data() + B->getSecond(),
+  ExpandedTokens.data() + E->getSecond() + 1};
+}
+  }
+  // Slow case. Use `isBeforeInTranslationUnit` to binary search for the
+  // required range.
   return getTokensCovering(expandedTokens(), R, *SourceMgr);
 }
 
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -34,6 +34,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
@@ -192,8 +193,16 @@
 return ExpandedTokens;
   }
 
+  /// Creates an index ExpandedTokens by their SourceLocation for faster
+  /// lookups. This optimizes future calls to `expandedTokens(SourceRange)` for
+  /// finding expanded tokens in a 'token range'.
+  /// Creates an index only once. Further calls to it will be no-op.
+  void indexExpandedTokens();
+
   /// Returns the subrange of expandedTokens() corresponding to the closed
-  /// token range R.
+  /// source range R.
+  /// Consider calling indexExpandedTokens() before for faster lookups for
+  /// 'token ranges'.
   llvm::ArrayRef expandedTokens(SourceRange R) const;
 
   /// Returns the subrange of spelled tokens corresponding to AST node spanning
@@ -366,6 +375,9 @@
   /// same stream as 'clang -E' (excluding the preprocessor directives like
   /// #file, etc.).
   std::vector ExpandedTokens;
+  // Index of ExpandedTokens for faster lookups by SourceLocation. This is
+  // useful while finding expanded tokens in a 'token range'.
+  llvm::DenseMap ExpandedTokIndex;
   llvm::DenseMap Files;
   // The value is never null, pointer instead of reference to avoid disabling
   // implicit assignment operator.
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -318,7 +318,7 @@
   Check->registerMatchers();
 }
 
-const Config& Cfg = Config::current();
+const Config  = Config::current();
 ASTDiags.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
   const clang::Diagnostic ) {
   if (Cfg.Diagnostics.SuppressAll ||
@@ -423,6 +423,9 @@
   // tokens from running the preprocessor inside the checks (only
   // modernize-use-trailing-return-type does that today).
   syntax::TokenBuffer Tokens = std::move(CollectTokens).consume();
+  // Index expanded tokens to optimize finding expandedToken in token ranges.
+  // Primarily useful for building a SelectionTree.
+  Tokens.indexExpandedTokens();
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals 

[PATCH] D18174: Fix libcxx build on musl

2021-03-24 Thread Khem Raj via Phabricator via cfe-commits
raj.khem abandoned this revision.
raj.khem added a comment.

this is no longer needed.


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

https://reviews.llvm.org/D18174

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


[PATCH] D99086: [clang][Syntax] Optimize expandedTokens for token ranges.

2021-03-24 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 333045.
usaxena95 marked 6 inline comments as done.
usaxena95 edited the summary of this revision.
usaxena95 added a comment.
Herald added a subscriber: arphaman.
Herald added a project: clang-tools-extra.

Made the optimization an 'opt-in'.
Created `TokenBuffer::indexExpandedToken()` for creating the index.

Made some more measurements on other files. Added to description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99086

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -106,6 +106,7 @@
   void EndSourceFileAction() override {
 assert(Collector && "BeginSourceFileAction was never called");
 Result = std::move(*Collector).consume();
+Result.indexExpandedTokens();
   }
 
   std::unique_ptr
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,7 +183,31 @@
   return Text.substr(Begin, length());
 }
 
+void TokenBuffer::indexExpandedTokens() {
+  // No-op if the index is already created.
+  if (!ExpandedTokIndex.empty())
+return;
+  ExpandedTokIndex.reserve(ExpandedTokens.size());
+  // Index ExpandedTokens for faster lookups by SourceLocation.
+  for (size_t I = 0, E = ExpandedTokens.size(); I != E; ++I)
+ExpandedTokIndex[ExpandedTokens[I].location()] = I;
+}
+
 llvm::ArrayRef TokenBuffer::expandedTokens(SourceRange R) const {
+  if (!ExpandedTokIndex.empty()) {
+// Quick lookup if `R` is a token range.
+// This is a huge win since majority of the users use ranges provided by an
+// AST. Ranges in AST are token ranges from expanded token stream.
+const auto B = ExpandedTokIndex.find(R.getBegin());
+const auto E = ExpandedTokIndex.find(R.getEnd());
+if (B != ExpandedTokIndex.end() && E != ExpandedTokIndex.end()) {
+  // Add 1 to End to make a half-open range.
+  return {ExpandedTokens.data() + B->getSecond(),
+  ExpandedTokens.data() + E->getSecond() + 1};
+}
+  }
+  // Slow case. Use `isBeforeInTranslationUnit` to binary search for the
+  // required range.
   return getTokensCovering(expandedTokens(), R, *SourceMgr);
 }
 
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -34,6 +34,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
@@ -192,8 +193,16 @@
 return ExpandedTokens;
   }
 
+  /// Creates an index ExpandedTokens by their SourceLocation for faster
+  /// lookups. This optimizes future calls to `expandedTokens(SourceRange)` for
+  /// finding expanded tokens in a 'token range'.
+  /// Creates an index only once. Further calls to it will be no-op.
+  void indexExpandedTokens();
+
   /// Returns the subrange of expandedTokens() corresponding to the closed
-  /// token range R.
+  /// source range R.
+  /// Consider calling indexExpandedTokens() before for faster lookups for
+  /// 'token ranges'.
   llvm::ArrayRef expandedTokens(SourceRange R) const;
 
   /// Returns the subrange of spelled tokens corresponding to AST node spanning
@@ -366,6 +375,9 @@
   /// same stream as 'clang -E' (excluding the preprocessor directives like
   /// #file, etc.).
   std::vector ExpandedTokens;
+  // Index of ExpandedTokens for faster lookups by SourceLocation. This is
+  // useful while finding expanded tokens in a 'token range'.
+  llvm::DenseMap ExpandedTokIndex;
   llvm::DenseMap Files;
   // The value is never null, pointer instead of reference to avoid disabling
   // implicit assignment operator.
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -318,7 +318,7 @@
   Check->registerMatchers();
 }
 
-const Config& Cfg = Config::current();
+const Config  = Config::current();
 ASTDiags.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
   const clang::Diagnostic ) {
   if (Cfg.Diagnostics.SuppressAll ||
@@ -423,6 +423,9 @@
   // tokens from running the preprocessor inside the checks (only
   // modernize-use-trailing-return-type does that today).

[PATCH] D99259: [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions

2021-03-24 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 333041.
aheejin added a comment.

Add break


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99259

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -79,6 +79,21 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_SIGN_EXT %s
 // PTHREAD_NO_SIGN_EXT: invalid argument '-pthread' not allowed with 
'-mno-sign-ext'
 
+// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
+// '-mllvm --force-attribute=foo:noinline -mllvm 
--force-attribute=bar:noinline'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN:--sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN:-mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
+// RUN:  | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
+// EMSCRIPTEN_EH_ALLOWED_NOINLINE: clang{{.*}}" "-cc1" {{.*}} "-mllvm" 
"--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
+
+// '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with
+// '-mllvm -enable-emscripten-cxx-exceptions'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -mllvm -emscripten-cxx-exceptions-allowed 2>&1 \
+// RUN:   | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
+// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument '-mllvm 
-emscripten-cxx-exceptions-allowed' only allowed with '-mllvm 
-enable-emscripten-cxx-exceptions'
+
 // '-fwasm-exceptions' sets +exception-handling
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
 // RUN:--sysroot=/foo %s -fwasm-exceptions 2>&1 \
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -294,6 +294,36 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+exception-handling");
   }
+
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+StringRef Opt = A->getValue(0);
+if (Opt.startswith("-emscripten-cxx-exceptions-allowed")) {
+  // '-mllvm -emscripten-cxx-exceptions-allowed' should be used with
+  // '-mllvm -enable-emscripten-cxx-exceptions'
+  bool EmExceptionArgExists = false;
+  for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
+if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions") {
+  EmExceptionArgExists = true;
+  break;
+}
+  }
+  if (!EmExceptionArgExists)
+getDriver().Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mllvm -emscripten-cxx-exceptions-allowed"
+<< "-mllvm -enable-emscripten-cxx-exceptions";
+
+  // Prevent functions specified in -emscripten-cxx-exceptions-allowed list
+  // from being inlined before reaching the wasm backend.
+  StringRef FuncNamesStr = Opt.split('=').second;
+  SmallVector FuncNames;
+  FuncNamesStr.split(FuncNames, ',');
+  for (auto Name : FuncNames) {
+CC1Args.push_back("-mllvm");
+CC1Args.push_back(DriverArgs.MakeArgString("--force-attribute=" + Name 
+
+   ":noinline"));
+  }
+}
+  }
 }
 
 ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const {


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -79,6 +79,21 @@
 // RUN:   | FileCheck -check-prefix=PTHREAD_NO_SIGN_EXT %s
 // PTHREAD_NO_SIGN_EXT: invalid argument '-pthread' not allowed with '-mno-sign-ext'
 
+// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
+// '-mllvm --force-attribute=foo:noinline -mllvm --force-attribute=bar:noinline'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN:--sysroot=/foo %s -mllvm -enable-emscripten-cxx-exceptions \
+// RUN:-mllvm -emscripten-cxx-exceptions-allowed=foo,bar 2>&1 \
+// RUN:  | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_NOINLINE %s
+// EMSCRIPTEN_EH_ALLOWED_NOINLINE: clang{{.*}}" "-cc1" {{.*}} "-mllvm" "--force-attribute=foo:noinline" "-mllvm" "--force-attribute=bar:noinline"
+
+// '-mllvm -emscripten-cxx-exceptions-allowed' only allowed with
+// '-mllvm -enable-emscripten-cxx-exceptions'
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown \
+// RUN: --sysroot=/foo %s -mllvm -emscripten-cxx-exceptions-allowed 2>&1 \
+// RUN:   | FileCheck -check-prefix=EMSCRIPTEN_EH_ALLOWED_WO_ENABLE %s
+// EMSCRIPTEN_EH_ALLOWED_WO_ENABLE: invalid argument 

[PATCH] D99235: [HIP] Change to code object v4

2021-03-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/HIP.cpp:116
+  if (getOrCheckAMDGPUCodeObjectVersion(C.getDriver(), Args) >= 4)
+OffloadKind = OffloadKind + "v4";
   for (const auto  : Inputs) {

tra wrote:
> We do not do it for v2/v3. Could you elaborate on what makes v4 special that 
> it needs its own offload kind? 
> 
> Will you need to target different object versions simultaneously?
> If yes, how? AFAICT, the version specified is currently global and applies to 
> all sub-compilations.
> If not, then do we really need to encode the version in the offload target 
> name?
Introducing hipv4 is to differentiate with code object version 2 and 3 which 
are used by HIP applications compiled by older version of clang. ROCm platform 
is required to keep binary backward compatibility, i.e., old HIP applications 
built by ROCm 4.0 should run on ROCm 4.1. The bundle ID has different 
interpretation depending on whether it is version 2/3 or version 4, e.g. 
'gfx906' implies xnack and sramecc off with code object v2/3 but implies xnack 
and sramecc ANY with v4. Since code object version 2/3 uses 'hip', code object 
version 4 needs to be different, therefore it uses 'hipv4'.


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

https://reviews.llvm.org/D99235

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


[PATCH] D99259: [WebAssembly] Don't inline -emscripten-cxx-exceptions-allowed functions

2021-03-24 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 accepted this revision.
sbc100 added a comment.
This revision is now accepted and ready to land.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99259

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


[PATCH] D99200: [SystemZ][z/OS] JSON file should be text files

2021-03-24 Thread Abhina Sree via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bf833f670bd: [SystemZ][z/OS] JSON file should be text files 
(authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99200

Files:
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2336,7 +2336,8 @@
   Twine(llvm::sys::path::filename(Input.getFilename())) + "..json");
   int FD;
   SmallString<256> TempPath;
-  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath);
+  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath,
+llvm::sys::fs::OF_Text);
   if (Err) {
 Driver.Diag(diag::err_drv_compilationdatabase) << Path << Err.message();
 return;


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2336,7 +2336,8 @@
   Twine(llvm::sys::path::filename(Input.getFilename())) + "..json");
   int FD;
   SmallString<256> TempPath;
-  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath);
+  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath,
+llvm::sys::fs::OF_Text);
   if (Err) {
 Driver.Diag(diag::err_drv_compilationdatabase) << Path << Err.message();
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0bf833f - [SystemZ][z/OS] JSON file should be text files

2021-03-24 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2021-03-24T13:28:08-04:00
New Revision: 0bf833f670bdc42009b0ff208e8266f528e0a82c

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

LOG: [SystemZ][z/OS] JSON file should be text files

This patch sets the OF_Text flag correctly for the json file created in 
Clang::DumpCompilationDatabaseFragmentToDir.

Reviewed By: amccarth

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 95275b14cabe..a64dc4e80dec 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2336,7 +2336,8 @@ void Clang::DumpCompilationDatabaseFragmentToDir(
   Twine(llvm::sys::path::filename(Input.getFilename())) + "..json");
   int FD;
   SmallString<256> TempPath;
-  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath);
+  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath,
+llvm::sys::fs::OF_Text);
   if (Err) {
 Driver.Diag(diag::err_drv_compilationdatabase) << Path << Err.message();
 return;



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


[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

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

This patch does not model faithfully how reinterpretcasting member pointers 
should work.

The base specifiers represent the history for the member pointer (aka. mptr), 
describing how it was transformed to point wherever it currently points to.
If and only if the `PointerToMemberData` is `null`, then the represented member 
pointer is `null`.

`class PointerToMemberData` could have a bool `IsValid` field, representing 
whether or not this mptr is safely dereferancable or not.
Depending on this, loading a value via this mptr should result in `Undefined` 
or the associated value from the //store//.
Whenever you encounter a `reinterpret_cast` expression casting a valid mptr to 
a different type, the resulting `PointerToMemberData` should be the same as 
before **BUT** the `IsValid` field set to `false`!
Later, if it's cast back to the original type (which is probably the 
`NamedDecl` inside the `PointerToMemberData`, I don't know).

You should also change the way how the abstract machine loads a value from the 
//store// using an invalid mptr - as that should return `Undefined` instead of 
the actual associated value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


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

2021-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D98499#2644313 , @kadircet wrote:

> In D98499#2626502 , @sammccall wrote:
>
>> My model for modules using this diagnostic stuff (apart from the 
>> build-system stuff which sadly can't be meaningfully upstreamed) are 
>> IncludeFixer, ClangTidy, and IWYU - worth thinking about how we'd build 
>> those on top of this model. (Doesn't mean we need to add a hook to emit 
>> diagnostics, but it probably means we should know where it would go)
>
> Agreed. I believe they all would need extra end points to ASTHooks though.

Yup. Let's not bite off more for now.

> - make ASTHooks own it and instantiate a new one on every parse (i think the 
> cleanest and most explicit)

Agreed. (And this only one that overlaps this patch a lot)




Comment at: clang-tools-extra/clangd/FeatureModule.h:112
+  };
+  /// Can be called asynchronously before building an AST.
+  virtual std::unique_ptr astHooks() { return nullptr; }

kadircet wrote:
> sammccall wrote:
> > This comment hints at what I *thought* was the idea: astHooks() is called 
> > each time we parse a file, the returned object has methods called on it 
> > while the file is being parsed, and is then destroyed.
> > 
> > But the code suggests we call once globally and it has effectively the same 
> > lifetime as the module.
> > This seems much less useful, e.g. if we want to observe several 
> > diagnostics, examine the preamble, and emit new diagnostics, then we have 
> > to plumb around some notion of "AST identity" rather than just tying it to 
> > the identity of the ParseASTHooks object itself.
> > 
> > (Lots of natural extensions here like providing ParseInputs to astHooks(), 
> > but YAGNI for now)
> > This comment hints at what I *thought* was the idea: astHooks() is called 
> > each time we parse a file, the returned object has methods called on it 
> > while the file is being parsed, and is then destroyed.
> 
> This was the intent actually (to enable modularization of other features like 
> clangtidy, includefixer, etc. as mentioned above), but looks like i got 
> confused while integrating this into clangdserver :/
> 
> While trying to resolve my confusion i actually noticed that we cannot uphold 
> the contract of "hooks being called synchronously", because we actually have 
> both a preamblethread and astworker that can invoke hooks (embarrassing of me 
> to forget that ).
> 
> So we can:
> - Give up on that promise and make life slightly complicated for module 
> implementers
> - Don't invoke hooks from preamblethread, (at the cost of limiting 
> functionality, we can still have downstream users that act on PPCallbacks, 
> but no direct integration with compiler, and that's where layering violations 
> are generated :/)
> - Handle the synchronization ourselves, only complicates TUScheduler more, 
> rather than all the module implementers.
> - Propogate FeatureModuleSet into TUScheduler and create 2 set of hooks on 
> each thread :)
> 
> I am leaning towards 4, but unsure (mostly hesitant about dependency schema, 
> as featuremodules also depend on TUScheduler..). WDYT?
> we actually have both a preamblethread and astworker that can invoke hooks 
> (embarrassing of me to forget that )

Ha! And yes, in our motivating case of fixing build system rules, the 
diagnostics are mostly going to be in the preamble.

The options that seem most tempting to me are:
 - don't attempt to create/run astHooks while building preambles, but *do* feed 
the preamble's Diags into the main-file's AST hooks every time it's used. (you 
won't have a clang::Diagnostic, so that param would have to be gone/optional, 
and we'd scrape the messages instead of extracting args). This is kind of 
thematic, remember how we replay PPCallbacks for clang-tidy :-). This is the 
smallest tweak to your #2 that actually works for us, I think.
 - create one astHooks for the preamble, and another for the AST build, and try 
to make the interface suitable for both. This is cute but there may be too much 
tension between the two cases. (Is this what you mean by #4?)
 - or have separate ASTHooks & PreambleHooks interfaces and support all this 
crap for both. (Or is *this* what you mean by #4?) Hybrid is also possible, 
give the interfaces an inheritance relationship, or have one interface but pass 
boolean parameters to indicate which version we're doing, or...
 - preambles and ASTs are a tree, so... give modules a PreambleHooks factory, 
and the factory function for ASTHooks is PreambleHooks::astHooks(). Holy 
overengineering batman...

These are roughly in order of complexity so we should probably start toward the 
top of the list somewhere. Up to you.

(I don't like the #1 or #3 in your list above much at all.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98499


[PATCH] D99280: [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.

2021-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7654bb6303d2: [OPENMP]Fix PR48571: critical/master in 
outlined contexts cause crash. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99280

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/critical_codegen.cpp
  clang/test/OpenMP/master_codegen.cpp

Index: clang/test/OpenMP/master_codegen.cpp
===
--- clang/test/OpenMP/master_codegen.cpp
+++ clang/test/OpenMP/master_codegen.cpp
@@ -55,6 +55,41 @@
   return a;
 }
 
+// ALL-LABEL:lambda_master
+// TERM_DEBUG-LABEL: lambda_master
+void lambda_master(int a, int b) {
+  auto l = [=]() {
+#pragma omp master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l();
+
+  auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l1();
+
+  auto l2 = [=]() {
+#pragma omp parallel master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l2();
+}
+
 // ALL-LABEL:  parallel_master
 // TERM_DEBUG-LABEL: parallel_master
 void parallel_master() {
Index: clang/test/OpenMP/critical_codegen.cpp
===
--- clang/test/OpenMP/critical_codegen.cpp
+++ clang/test/OpenMP/critical_codegen.cpp
@@ -68,6 +68,31 @@
   return a;
 }
 
+// ALL-LABEL:lambda_critical
+// TERM_DEBUG-LABEL: lambda_critical
+void lambda_critical(int a, int b) {
+  auto l = [=]() {
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l();
+
+  auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l1();
+}
+
 struct S {
   int a;
 };
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -409,6 +409,7 @@
   llvm::DenseMap LambdaCaptureFields;
   FieldDecl *LambdaThisCaptureField = nullptr;
   const CodeGen::CGBlockInfo *BlockInfo = nullptr;
+  bool NoInheritance = false;
 
 public:
   /// Constructs region for combined constructs.
@@ -416,16 +417,19 @@
   /// a list of functions used for code generation of implicitly inlined
   /// regions.
   InlinedOpenMPRegionRAII(CodeGenFunction , const RegionCodeGenTy ,
-  OpenMPDirectiveKind Kind, bool HasCancel)
-  : CGF(CGF) {
+  OpenMPDirectiveKind Kind, bool HasCancel,
+  bool NoInheritance = true)
+  : CGF(CGF), NoInheritance(NoInheritance) {
 // Start emission for the construct.
 CGF.CapturedStmtInfo = new CGOpenMPInlinedRegionInfo(
 CGF.CapturedStmtInfo, CodeGen, Kind, HasCancel);
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-LambdaThisCaptureField = CGF.LambdaThisCaptureField;
-CGF.LambdaThisCaptureField = nullptr;
-BlockInfo = CGF.BlockInfo;
-CGF.BlockInfo = nullptr;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  LambdaThisCaptureField = CGF.LambdaThisCaptureField;
+  CGF.LambdaThisCaptureField = nullptr;
+  BlockInfo = CGF.BlockInfo;
+  CGF.BlockInfo = nullptr;
+}
   }
 
   ~InlinedOpenMPRegionRAII() {
@@ -434,9 +438,11 @@
 cast(CGF.CapturedStmtInfo)->getOldCSI();
 delete CGF.CapturedStmtInfo;
 CGF.CapturedStmtInfo = OldCSI;
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-CGF.LambdaThisCaptureField = LambdaThisCaptureField;
-CGF.BlockInfo = BlockInfo;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  CGF.LambdaThisCaptureField = LambdaThisCaptureField;
+  CGF.BlockInfo = BlockInfo;
+}
   }
 };
 
@@ -3857,7 +3863,7 @@
   // Processing for implicitly captured variables.
   InlinedOpenMPRegionRAII Region(
   CGF, [](CodeGenFunction &, PrePostActionTy &) {}, OMPD_unknown,
-  /*HasCancel=*/false);
+  /*HasCancel=*/false, /*NoInheritance=*/true);
   SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef);
 }
 if (Type->isArrayType()) {
@@ -6218,7 +6224,9 @@
bool HasCancel) {
   if (!CGF.HaveInsertPoint())
 return;
-  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel);
+  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel,
+ InnerKind != OMPD_critical &&
+ InnerKind != OMPD_master);
   

[clang] 7654bb6 - [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.

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

Author: Alexey Bataev
Date: 2021-03-24T10:15:24-07:00
New Revision: 7654bb6303d290b19cad29137be810e69a0bf917

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

LOG: [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.

If emit inlined region for master/critical directives, no need to clear
lambda/block context data, otherwise the variables cannot be found and
it causes a crash at compile time.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/critical_codegen.cpp
clang/test/OpenMP/master_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e41eeef04331..a8f21548d3e0 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -409,6 +409,7 @@ class InlinedOpenMPRegionRAII {
   llvm::DenseMap LambdaCaptureFields;
   FieldDecl *LambdaThisCaptureField = nullptr;
   const CodeGen::CGBlockInfo *BlockInfo = nullptr;
+  bool NoInheritance = false;
 
 public:
   /// Constructs region for combined constructs.
@@ -416,16 +417,19 @@ class InlinedOpenMPRegionRAII {
   /// a list of functions used for code generation of implicitly inlined
   /// regions.
   InlinedOpenMPRegionRAII(CodeGenFunction , const RegionCodeGenTy ,
-  OpenMPDirectiveKind Kind, bool HasCancel)
-  : CGF(CGF) {
+  OpenMPDirectiveKind Kind, bool HasCancel,
+  bool NoInheritance = true)
+  : CGF(CGF), NoInheritance(NoInheritance) {
 // Start emission for the construct.
 CGF.CapturedStmtInfo = new CGOpenMPInlinedRegionInfo(
 CGF.CapturedStmtInfo, CodeGen, Kind, HasCancel);
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-LambdaThisCaptureField = CGF.LambdaThisCaptureField;
-CGF.LambdaThisCaptureField = nullptr;
-BlockInfo = CGF.BlockInfo;
-CGF.BlockInfo = nullptr;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  LambdaThisCaptureField = CGF.LambdaThisCaptureField;
+  CGF.LambdaThisCaptureField = nullptr;
+  BlockInfo = CGF.BlockInfo;
+  CGF.BlockInfo = nullptr;
+}
   }
 
   ~InlinedOpenMPRegionRAII() {
@@ -434,9 +438,11 @@ class InlinedOpenMPRegionRAII {
 cast(CGF.CapturedStmtInfo)->getOldCSI();
 delete CGF.CapturedStmtInfo;
 CGF.CapturedStmtInfo = OldCSI;
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-CGF.LambdaThisCaptureField = LambdaThisCaptureField;
-CGF.BlockInfo = BlockInfo;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  CGF.LambdaThisCaptureField = LambdaThisCaptureField;
+  CGF.BlockInfo = BlockInfo;
+}
   }
 };
 
@@ -3857,7 +3863,7 @@ static void emitPrivatesInit(CodeGenFunction ,
   // Processing for implicitly captured variables.
   InlinedOpenMPRegionRAII Region(
   CGF, [](CodeGenFunction &, PrePostActionTy &) {}, OMPD_unknown,
-  /*HasCancel=*/false);
+  /*HasCancel=*/false, /*NoInheritance=*/true);
   SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef);
 }
 if (Type->isArrayType()) {
@@ -6218,7 +6224,9 @@ void 
CGOpenMPRuntime::emitInlinedDirective(CodeGenFunction ,
bool HasCancel) {
   if (!CGF.HaveInsertPoint())
 return;
-  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel);
+  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel,
+ InnerKind != OMPD_critical &&
+ InnerKind != OMPD_master);
   CGF.CapturedStmtInfo->EmitBody(CGF, /*S=*/nullptr);
 }
 

diff  --git a/clang/test/OpenMP/critical_codegen.cpp 
b/clang/test/OpenMP/critical_codegen.cpp
index 46fad63b3bd8..d84f2b2af22b 100644
--- a/clang/test/OpenMP/critical_codegen.cpp
+++ b/clang/test/OpenMP/critical_codegen.cpp
@@ -68,6 +68,31 @@ int main() {
   return a;
 }
 
+// ALL-LABEL:lambda_critical
+// TERM_DEBUG-LABEL: lambda_critical
+void lambda_critical(int a, int b) {
+  auto l = [=]() {
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l();
+
+  auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l1();
+}
+
 struct S {
   int a;
 };

diff  --git a/clang/test/OpenMP/master_codegen.cpp 
b/clang/test/OpenMP/master_codegen.cpp
index 8554ad8e7dec..353284ea8541 100644
--- a/clang/test/OpenMP/master_codegen.cpp
+++ b/clang/test/OpenMP/master_codegen.cpp
@@ -55,6 

[PATCH] D99151: [RISCV][Clang] Add RVV vleff intrinsic functions.

2021-03-24 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vle16ff.c:9
+// RUN:   -target-feature +experimental-zfh -target-feature +m 
-fallow-half-arguments-and-returns -Werror -Wall -S -o - %s >/dev/null 2>%t
+// RUN: FileCheck --check-prefix=ASM --allow-empty %s <%t
+

jrtc27 wrote:
> craig.topper wrote:
> > jrtc27 wrote:
> > > khchen wrote:
> > > > nit: skip the temporary file and remove +experimental-zfh and 
> > > > -fallow-half-arguments-and-returns.
> > > Can we please stop putting ASM tests in Clang, and if they really are 
> > > needed, splitting them out into their own files separate from the IR 
> > > tests?
> > For more background, this approach was copied from AArch64 SVE where they 
> > said this was beneficial to catch warnings from TypeSize's implicit 
> > conversion to uint64_t.
> You can have the ASM tests in a separate .test file though so you can still 
> run the IR tests without the backend if there's value in having the 
> end-to-end tests
(well s/tests/RUN lines/)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99151

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


[PATCH] D99151: [RISCV][Clang] Add RVV vleff intrinsic functions.

2021-03-24 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vle16ff.c:9
+// RUN:   -target-feature +experimental-zfh -target-feature +m 
-fallow-half-arguments-and-returns -Werror -Wall -S -o - %s >/dev/null 2>%t
+// RUN: FileCheck --check-prefix=ASM --allow-empty %s <%t
+

craig.topper wrote:
> jrtc27 wrote:
> > khchen wrote:
> > > nit: skip the temporary file and remove +experimental-zfh and 
> > > -fallow-half-arguments-and-returns.
> > Can we please stop putting ASM tests in Clang, and if they really are 
> > needed, splitting them out into their own files separate from the IR tests?
> For more background, this approach was copied from AArch64 SVE where they 
> said this was beneficial to catch warnings from TypeSize's implicit 
> conversion to uint64_t.
You can have the ASM tests in a separate .test file though so you can still run 
the IR tests without the backend if there's value in having the end-to-end tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99151

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


[PATCH] D99280: [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.

2021-03-24 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99280

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


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

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99274

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


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

2021-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/index/Merge.cpp:59
+
+  bool DynamicIndexIsAuthoritative =
+  // We expect the definition to see the canonical declaration, so it

this bool seems complicated enough & duplicated that you could consider pulling 
out

static bool indexIsAuthoritative(const SymbolIndex::IndexedFiles&, const Symbol 
);

(The IndexedFiles typedef doesn't exist, but it should!)



Comment at: clang-tools-extra/clangd/index/Merge.cpp:67
+  // index is stale just drop the symbol.
+  if (DynamicIndexIsAuthoritative)
 return;

we could SPAN_ATTACH a counter for this too, e.g. static_dropped

(and possibly hoist ++StaticCount to the top, static_dropped can be a subset)



Comment at: clang-tools-extra/clangd/unittests/IndexTests.cpp:318
+  // Even though the definition is actually deleted in the newer version of the
+  // file, we still chose to merge with information coming from static index.
   LookupRequest LookupReq;

Bah, this is actually incorrect, for the given example, right? We point to a 
definition that doesn't exist, in a file where the index is up to date.
Can we at least hint why we do this?
("This seems wrong, but is generic behavior we want for e.g. include headers 
which are always missing from the dynamic index")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98538

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


[PATCH] D99280: [OPENMP]Fix PR48571: critical/master in outlined contexts cause crash.

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

If emit inlined region for master/critical directives, no need to clear
lambda/block context data, otherwise the variables cannot be found and
it causes a crash at compile time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99280

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/critical_codegen.cpp
  clang/test/OpenMP/master_codegen.cpp

Index: clang/test/OpenMP/master_codegen.cpp
===
--- clang/test/OpenMP/master_codegen.cpp
+++ clang/test/OpenMP/master_codegen.cpp
@@ -55,6 +55,41 @@
   return a;
 }
 
+// ALL-LABEL:lambda_master
+// TERM_DEBUG-LABEL: lambda_master
+void lambda_master(int a, int b) {
+  auto l = [=]() {
+#pragma omp master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l();
+
+  auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l1();
+
+  auto l2 = [=]() {
+#pragma omp parallel master
+{
+  // ALL: call i32 @__kmpc_master(
+  int c = a + b;
+}
+  };
+
+  l2();
+}
+
 // ALL-LABEL:  parallel_master
 // TERM_DEBUG-LABEL: parallel_master
 void parallel_master() {
Index: clang/test/OpenMP/critical_codegen.cpp
===
--- clang/test/OpenMP/critical_codegen.cpp
+++ clang/test/OpenMP/critical_codegen.cpp
@@ -68,6 +68,31 @@
   return a;
 }
 
+// ALL-LABEL:lambda_critical
+// TERM_DEBUG-LABEL: lambda_critical
+void lambda_critical(int a, int b) {
+  auto l = [=]() {
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l();
+
+  auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp critical
+{
+  // ALL: call void @__kmpc_critical(
+  int c = a + b;
+}
+  };
+
+  l1();
+}
+
 struct S {
   int a;
 };
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -409,6 +409,7 @@
   llvm::DenseMap LambdaCaptureFields;
   FieldDecl *LambdaThisCaptureField = nullptr;
   const CodeGen::CGBlockInfo *BlockInfo = nullptr;
+  bool NoInheritance = false;
 
 public:
   /// Constructs region for combined constructs.
@@ -416,16 +417,19 @@
   /// a list of functions used for code generation of implicitly inlined
   /// regions.
   InlinedOpenMPRegionRAII(CodeGenFunction , const RegionCodeGenTy ,
-  OpenMPDirectiveKind Kind, bool HasCancel)
-  : CGF(CGF) {
+  OpenMPDirectiveKind Kind, bool HasCancel,
+  bool NoInheritance = true)
+  : CGF(CGF), NoInheritance(NoInheritance) {
 // Start emission for the construct.
 CGF.CapturedStmtInfo = new CGOpenMPInlinedRegionInfo(
 CGF.CapturedStmtInfo, CodeGen, Kind, HasCancel);
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-LambdaThisCaptureField = CGF.LambdaThisCaptureField;
-CGF.LambdaThisCaptureField = nullptr;
-BlockInfo = CGF.BlockInfo;
-CGF.BlockInfo = nullptr;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  LambdaThisCaptureField = CGF.LambdaThisCaptureField;
+  CGF.LambdaThisCaptureField = nullptr;
+  BlockInfo = CGF.BlockInfo;
+  CGF.BlockInfo = nullptr;
+}
   }
 
   ~InlinedOpenMPRegionRAII() {
@@ -434,9 +438,11 @@
 cast(CGF.CapturedStmtInfo)->getOldCSI();
 delete CGF.CapturedStmtInfo;
 CGF.CapturedStmtInfo = OldCSI;
-std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
-CGF.LambdaThisCaptureField = LambdaThisCaptureField;
-CGF.BlockInfo = BlockInfo;
+if (NoInheritance) {
+  std::swap(CGF.LambdaCaptureFields, LambdaCaptureFields);
+  CGF.LambdaThisCaptureField = LambdaThisCaptureField;
+  CGF.BlockInfo = BlockInfo;
+}
   }
 };
 
@@ -3857,7 +3863,7 @@
   // Processing for implicitly captured variables.
   InlinedOpenMPRegionRAII Region(
   CGF, [](CodeGenFunction &, PrePostActionTy &) {}, OMPD_unknown,
-  /*HasCancel=*/false);
+  /*HasCancel=*/false, /*NoInheritance=*/true);
   SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef);
 }
 if (Type->isArrayType()) {
@@ -6218,7 +6224,9 @@
bool HasCancel) {
   if (!CGF.HaveInsertPoint())
 return;
-  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel);
+  InlinedOpenMPRegionRAII Region(CGF, CodeGen, InnerKind, HasCancel,
+ InnerKind != 

[PATCH] D98505: [clangd] Propagate data in diagnostics

2021-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Diagnostics.h:77
+  // list.
+  std::vector OpaqueData;
 };

Hmm, you've replaced the json::Array with an array of objects :-)
Any reason we can't just use llvm::json::Object here?

We don't really handle conflicts anyway, and I don't think having one tweak 
read another one's data out of this field is a real concern.



Comment at: clang-tools-extra/clangd/Protocol.cpp:616
+  if (auto *Data = Params.getAsObject()->getObject("data"))
+R.data = std::move(*Data);
+  return O.map("range", R.range) && O.map("message", R.message) &&

std::move is a fancy way to spell copy here, since Params is const.

json::Value(*Data) (or can you just use mapOptOrNull?)



Comment at: clang-tools-extra/clangd/Protocol.h:413
+  /// textDocument.publishDiagnostics.dataSupport
+  bool DiagnosticDataSupport = false;
+

this is now unused



Comment at: clang-tools-extra/clangd/refactor/Tweak.h:71
+/// Diagnostics related to this selection.
+llvm::ArrayRef Diags;
 // FIXME: provide a way to get sources and ASTs for other files.

unrelated?
(well not quite, but neither populated or used in this patch)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98505

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


[PATCH] D98724: Fix false negative in -Wthread-safety-attributes

2021-03-24 Thread Aaron Puchert 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 rGa6a1c3051dbd: Fix false negative in 
-Wthread-safety-attributes (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98724

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-thread-safety-parsing.cpp


Index: clang/test/SemaCXX/warn-thread-safety-parsing.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1295,6 +1295,11 @@
 // expected-warning{{'unlock_function' attribute without capability 
arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' 
or 'scoped_lockable' attribute}}
 };
 
+struct SLDerived3 : public SLTemplateDerived {
+  ~SLDerived3() UNLOCK_FUNCTION(); // \
+// expected-warning{{'unlock_function' attribute without capability 
arguments refers to 'this', but 'SLDerived3' isn't annotated with 'capability' 
or 'scoped_lockable' attribute}}
+};
+
 //-
 // Parsing of member variables and function parameters
 //--
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -513,16 +513,9 @@
 
   // Else check if any base classes have the attribute.
   if (const auto *CRD = dyn_cast(RD)) {
-CXXBasePaths BPaths(false, false);
-if (CRD->lookupInBases(
-[](const CXXBaseSpecifier *BS, CXXBasePath &) {
-  const auto  = *BS->getType();
-  // If it's type-dependent, we assume it could have the attribute.
-  if (Ty.isDependentType())
-return true;
-  return Ty.castAs()->getDecl()->hasAttr();
-},
-BPaths, true))
+if (!CRD->forallBases([](const CXXRecordDecl *Base) {
+  return !Base->hasAttr();
+}))
   return true;
   }
   return false;


Index: clang/test/SemaCXX/warn-thread-safety-parsing.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1295,6 +1295,11 @@
 // expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
 };
 
+struct SLDerived3 : public SLTemplateDerived {
+  ~SLDerived3() UNLOCK_FUNCTION(); // \
+// expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived3' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
+};
+
 //-
 // Parsing of member variables and function parameters
 //--
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -513,16 +513,9 @@
 
   // Else check if any base classes have the attribute.
   if (const auto *CRD = dyn_cast(RD)) {
-CXXBasePaths BPaths(false, false);
-if (CRD->lookupInBases(
-[](const CXXBaseSpecifier *BS, CXXBasePath &) {
-  const auto  = *BS->getType();
-  // If it's type-dependent, we assume it could have the attribute.
-  if (Ty.isDependentType())
-return true;
-  return Ty.castAs()->getDecl()->hasAttr();
-},
-BPaths, true))
+if (!CRD->forallBases([](const CXXRecordDecl *Base) {
+  return !Base->hasAttr();
+}))
   return true;
   }
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a6a1c30 - Fix false negative in -Wthread-safety-attributes

2021-03-24 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2021-03-24T17:45:25+01:00
New Revision: a6a1c3051dbd2cc5ccc70272890cf38d11dca9c7

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

LOG: Fix false negative in -Wthread-safety-attributes

The original implementation didn't fire on non-template classes when a
base class was an instantiation of a template with a dependent base.
In that case the base of the base is dependent as seen from the base,
but not from the class we're interested in, which isn't a template.

Also it simplifies the code a lot.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/warn-thread-safety-parsing.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c4901042c042..b39460d33214 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -513,16 +513,9 @@ static bool checkRecordDeclForAttr(const RecordDecl *RD) {
 
   // Else check if any base classes have the attribute.
   if (const auto *CRD = dyn_cast(RD)) {
-CXXBasePaths BPaths(false, false);
-if (CRD->lookupInBases(
-[](const CXXBaseSpecifier *BS, CXXBasePath &) {
-  const auto  = *BS->getType();
-  // If it's type-dependent, we assume it could have the attribute.
-  if (Ty.isDependentType())
-return true;
-  return Ty.castAs()->getDecl()->hasAttr();
-},
-BPaths, true))
+if (!CRD->forallBases([](const CXXRecordDecl *Base) {
+  return !Base->hasAttr();
+}))
   return true;
   }
   return false;

diff  --git a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp 
b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
index 6ad0f877a11d..b6e9c052a241 100644
--- a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1295,6 +1295,11 @@ struct SLDerived2 : public SLTemplateClass {
 // expected-warning{{'unlock_function' attribute without capability 
arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' 
or 'scoped_lockable' attribute}}
 };
 
+struct SLDerived3 : public SLTemplateDerived {
+  ~SLDerived3() UNLOCK_FUNCTION(); // \
+// expected-warning{{'unlock_function' attribute without capability 
arguments refers to 'this', but 'SLDerived3' isn't annotated with 'capability' 
or 'scoped_lockable' attribute}}
+};
+
 //-
 // Parsing of member variables and function parameters
 //--



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


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

2021-03-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, rsmith, rjmccall.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sorry for the title, I'm not 100% sure that's even correct here.

This call to `ProhibitAttributes()` is dead code in the case of GNU-style 
attributes. They are needed in e.g. 
`clang/test/Parser/objcbridge-related-attribute.m`.

However, adding a `&& !getLangOpts().ObjC` to the if statement just before is 
also not sufficient since clang expects to parse GNU-style attributes at this 
place without diagnosing them as well, for example in 
`clang/test/Sema/struct-decl.c:71`. This ends up diagnosing the wrongly-placed 
`noreturn` attribute at a later stage.

Once `ProhibitAttributes()` works with GNU-style attributes the cases mentioned 
above (and tons of other cases) are being diagnosed as incorrect.

This change depends on https://reviews.llvm.org/D97362 landing first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99278

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1933,7 +1933,7 @@
TemplateParams ? TemplateParams->size() : 0));
   } else {
 if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, /* 
DiagnoseEmptyAttrs=*/true);
 
 if (TUK == Sema::TUK_Definition &&
 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1933,7 +1933,7 @@
TemplateParams ? TemplateParams->size() : 0));
   } else {
 if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, /* DiagnoseEmptyAttrs=*/true);
 
 if (TUK == Sema::TUK_Definition &&
 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99235: [HIP] Change to code object v4

2021-03-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Driver/ToolChains/HIP.cpp:116
+  if (getOrCheckAMDGPUCodeObjectVersion(C.getDriver(), Args) >= 4)
+OffloadKind = OffloadKind + "v4";
   for (const auto  : Inputs) {

We do not do it for v2/v3. Could you elaborate on what makes v4 special that it 
needs its own offload kind? 

Will you need to target different object versions simultaneously?
If yes, how? AFAICT, the version specified is currently global and applies to 
all sub-compilations.
If not, then do we really need to encode the version in the offload target name?


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

https://reviews.llvm.org/D99235

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


[PATCH] D98747: Thread safety analysis: Don't warn about managed locks on join points

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

I'd really like to hear from @delesley about these changes, specifically 
because of this bit:

> the primary goal of the Thread safety analysis is not to find double locks 
> but race conditions.

I believe the primary goal of TSA is to find threading-related issues that can 
be caught at compile time which includes both double locks and race conditions, 
and I don't have a good feel for whether these changes have a larger impact on 
the overall design or not.

As far as the changes in the patch go, they look reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98747

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


[PATCH] D98856: Always emit error for wrong interfaces to scalable vectors, unless cmdline flag is passed.

2021-03-24 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: llvm/lib/CodeGen/ValueTypes.cpp:17
 
+unsigned EVT::getVectorNumElements() const {
+  auto Error = []() {

ctetreau wrote:
> Out of curiosity, what is the eventual plan for this function? Does it go 
> away, or will it just assert if this is a scalable vector?
The eventual plan is for this function to go away, so we just have a single 
getElementCount interface, although this hasn't really been discussed yet.
We could also end up renaming it to `getFixedVectorNumElements` for 
convenience, at which point it always asserts if it is scalable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98856

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


[PATCH] D98856: Always emit error for wrong interfaces to scalable vectors, unless cmdline flag is passed.

2021-03-24 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 333018.
sdesmalen marked 5 inline comments as done.
sdesmalen added a comment.

Moved implementation of EVT::getVectorNumElements back to header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98856

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/TypeSize.cpp
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp

Index: llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
===
--- llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
+++ llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
@@ -180,7 +180,8 @@
   // Check convenience size scaling methods.
   EXPECT_EQ(v2i32.getSizeInBits() * 2, v4i32.getSizeInBits());
   EXPECT_EQ(2 * nxv2i32.getSizeInBits(), nxv4i32.getSizeInBits());
-  EXPECT_EQ(nxv2f64.getSizeInBits() / 2, nxv2i32.getSizeInBits());
+  EXPECT_EQ(nxv2f64.getSizeInBits().divideCoefficientBy(2),
+nxv2i32.getSizeInBits());
 }
 
 } // end anonymous namespace
Index: llvm/lib/Support/TypeSize.cpp
===
--- /dev/null
+++ llvm/lib/Support/TypeSize.cpp
@@ -0,0 +1,41 @@
+//===- TypeSize.cpp - Wrapper around type sizes--*- 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
+//
+//===--===//
+
+#include "llvm/Support/TypeSize.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+/// The ScalableErrorAsWarning is a temporary measure to suppress errors from
+/// using the wrong interface on a scalable vector.
+cl::opt ScalableErrorAsWarning(
+"treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false),
+cl::desc("Treat issues where a fixed-width property is requested from a "
+ "scalable type as a warning, instead of an error."),
+cl::ZeroOrMore);
+
+void llvm::reportInvalidSizeRequest(const char *Msg) {
+#ifndef STRICT_FIXED_SIZE_VECTORS
+  if (ScalableErrorAsWarning) {
+WithColor::warning() << "Invalid size request on a scalable vector; " << Msg
+ << "\n";
+return;
+  }
+#endif
+  report_fatal_error("Invalid size request on a scalable vector.");
+}
+
+TypeSize::operator TypeSize::ScalarTy() const {
+  if (isScalable()) {
+reportInvalidSizeRequest(
+"Cannot implicitly convert a scalable size to a fixed-width size in "
+"`TypeSize::operator ScalarTy()`");
+return getKnownMinValue();
+  }
+  return getFixedValue();
+}
Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -185,6 +185,7 @@
   TrigramIndex.cpp
   Triple.cpp
   Twine.cpp
+  TypeSize.cpp
   Unicode.cpp
   UnicodeCaseFold.cpp
   VersionTuple.cpp
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4847,8 +4847,8 @@
 assert(VT.isVector() && "This DAG node is restricted to vector types.");
 assert(Operand.getValueType().bitsLE(VT) &&
"The input must be the same size or smaller than the result.");
-assert(VT.getVectorNumElements() <
- Operand.getValueType().getVectorNumElements() &&
+assert(VT.getVectorMinNumElements() <
+   Operand.getValueType().getVectorMinNumElements() &&
"The destination vector type must have fewer lanes than the input.");
 break;
   case ISD::ABS:
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4332,7 +4332,10 @@
   if (Q.isUndefValue(Ops[0]))
 return UndefValue::get(GEPTy);
 
-  bool IsScalableVec = isa(SrcTy);
+  bool IsScalableVec =
+  isa(SrcTy) || any_of(Ops, [](const Value *V) {
+return isa(V->getType());
+  });
 
   if (Ops.size() == 2) {
 // getelementptr P, 0 -> P.
Index: llvm/include/llvm/Support/TypeSize.h
===
--- llvm/include/llvm/Support/TypeSize.h
+++ llvm/include/llvm/Support/TypeSize.h
@@ -27,6 +27,10 @@
 
 namespace llvm {
 
+/// Reports a diagnostic message to indicate a invalid size request has been
+/// done on a scalable vector. This function may not return.
+void 

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

2021-03-24 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, steakhal, xazax.hun, ASDenysPetrov.
Herald added subscribers: Charusso, dkrupp, donat.nagy, Szelethus, jfb, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://75020762


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99274

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


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


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


[PATCH] D98856: Always emit error for wrong interfaces to scalable vectors, unless cmdline flag is passed.

2021-03-24 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5052-5055
+  if (isa(JA)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-treat-scalable-fixed-error-as-warning");
+  }

paulwalker-arm wrote:
> Are there any concerns related to LTO here? Could we live with LTO triggering 
> errors for the invalid uses?  Part of me thinks this is reasonable given the 
> clang exception is more about ensuring we can continue active development 
> until we're ready to press the "it's supported" switch.
> Are there any concerns related to LTO here?
Yes, probably.

> Could we live with LTO triggering errors for the invalid uses? Part of me 
> thinks this is reasonable given the clang exception is more about ensuring we 
> can continue active development until we're ready to press the "it's 
> supported" switch.
Yes, that's my thinking about this as well. When the compiler is ready  to be 
used in production, then an actual runtime compiler error (the default) would 
be appropriate which would lead to a bug-report that'd we need to go off and 
fix. During development of scalable vector support, we just want to have some 
extra flexibility, because we know not all code-paths are covered. So while we 
use it for those purposes, the recommendation is not to use LTO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98856

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


[PATCH] D98724: Fix false negative in -Wthread-safety-attributes

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

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98724

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


[PATCH] D99151: [RISCV][Clang] Add RVV vleff intrinsic functions.

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



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vle16ff.c:9
+// RUN:   -target-feature +experimental-zfh -target-feature +m 
-fallow-half-arguments-and-returns -Werror -Wall -S -o - %s >/dev/null 2>%t
+// RUN: FileCheck --check-prefix=ASM --allow-empty %s <%t
+

jrtc27 wrote:
> khchen wrote:
> > nit: skip the temporary file and remove +experimental-zfh and 
> > -fallow-half-arguments-and-returns.
> Can we please stop putting ASM tests in Clang, and if they really are needed, 
> splitting them out into their own files separate from the IR tests?
For more background, this approach was copied from AArch64 SVE where they said 
this was beneficial to catch warnings from TypeSize's implicit conversion to 
uint64_t.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99151

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


[PATCH] D98505: [clangd] Propagate data in diagnostics

2021-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.h:58
+  /// If true, Clangd will populate the data field in LSP diagnostic
+  /// representation. This is used to prevent extra data transfer with old
+  /// clients that doesn't support data field.

sammccall wrote:
> Second sentence is confusing because of inverted sense. And really I don't 
> think the reason is that we don't want to send extra data, but rather the 
> fear that old clients will choke on it.
> 
> If we're *not* afraid of that, i.e. we think they'll just drop it on the 
> floor, then I don't think we should bother to feature-detect it just so *we* 
> can drop it on the floor.
> Not sure how you feel about this, but it's pretty tempting to me...
as discussed offline dropping this completely. since we don't really guard 
against adding "extra" properties to objects, and the worst that could happen 
is clangd won't surface a particular tweak on clients without support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98505

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


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

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

I see that `-Werror` changes the behavior of the driver in 5 different places. 
I would hope to see  5 new tests to verify each case.




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:353-354
 
+/// Parses all semantic related arguments and populates the variables
+/// options accordingly.
+static void parseDiagArgs(CompilerInvocation , llvm::opt::ArgList ) {

Please update



Comment at: flang/lib/Frontend/FrontendActions.cpp:67-69
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {

Please add a test for this change.



Comment at: flang/lib/Frontend/FrontendActions.cpp:102-104
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {

Please add a test for this change.



Comment at: flang/lib/Frontend/FrontendActions.cpp:116-118
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {

Please add a test for this change.



Comment at: flang/lib/Frontend/FrontendActions.cpp:273-275
+  if (!ci.parsing().messages().empty() &&
+  (ci.invocation().warnAsErr() ||
+  ci.parsing().messages().AnyFatalError())) {

Please add a test for this change.



Comment at: flang/test/Driver/werror.f90:11-12
+!-
+! RUN: not %flang_fc1 -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+

Does this work for `f18`?


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

https://reviews.llvm.org/D98657

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


[PATCH] D99227: [Coroutine][Clang] Force emit lifetime intrinsics for Coroutines

2021-03-24 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

In D99227#2646819 , @rjmccall wrote:

> Is it feasible to outline the initial segment that you don't want to be part 
> of the coroutine, and then have coroutine splitting force that outlined 
> function to be inlined into the ramp function?  IIUC, you were saying that 
> the splitting patch was difficult, but maybe thinking about it as outlining 
> simplifies things.  I know we had some nasty representational problems with 
> the async lowering that we solved with outlining and force-inlining.

That's a good idea. I will think about it. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99227

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


[PATCH] D98856: Always emit error for wrong interfaces to scalable vectors, unless cmdline flag is passed.

2021-03-24 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 333010.
sdesmalen added a comment.

Moved error reporting to llvm::reportInvalidSizeRequest in TypeSize.cpp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98856

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/TypeSize.cpp
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp

Index: llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
===
--- llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
+++ llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
@@ -180,7 +180,8 @@
   // Check convenience size scaling methods.
   EXPECT_EQ(v2i32.getSizeInBits() * 2, v4i32.getSizeInBits());
   EXPECT_EQ(2 * nxv2i32.getSizeInBits(), nxv4i32.getSizeInBits());
-  EXPECT_EQ(nxv2f64.getSizeInBits() / 2, nxv2i32.getSizeInBits());
+  EXPECT_EQ(nxv2f64.getSizeInBits().divideCoefficientBy(2),
+nxv2i32.getSizeInBits());
 }
 
 } // end anonymous namespace
Index: llvm/lib/Support/TypeSize.cpp
===
--- /dev/null
+++ llvm/lib/Support/TypeSize.cpp
@@ -0,0 +1,41 @@
+//===- TypeSize.cpp - Wrapper around type sizes--*- 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
+//
+//===--===//
+
+#include "llvm/Support/TypeSize.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+/// The ScalableErrorAsWarning is a temporary measure to suppress errors from
+/// using the wrong interface on a scalable vector.
+cl::opt ScalableErrorAsWarning(
+"treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false),
+cl::desc("Treat issues where a fixed-width property is requested from a "
+ "scalable type as a warning, instead of an error."),
+cl::ZeroOrMore);
+
+void llvm::reportInvalidSizeRequest(const char *Msg) {
+#ifndef STRICT_FIXED_SIZE_VECTORS
+  if (ScalableErrorAsWarning) {
+WithColor::warning() << "Invalid size request on a scalable vector; " << Msg
+ << "\n";
+return;
+  }
+#endif
+  report_fatal_error("Invalid size request on a scalable vector.");
+}
+
+TypeSize::operator TypeSize::ScalarTy() const {
+  if (isScalable()) {
+reportInvalidSizeRequest(
+"Cannot implicitly convert a scalable size to a fixed-width size in "
+"`TypeSize::operator ScalarTy()`");
+return getKnownMinValue();
+  }
+  return getFixedValue();
+}
Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -185,6 +185,7 @@
   TrigramIndex.cpp
   Triple.cpp
   Twine.cpp
+  TypeSize.cpp
   Unicode.cpp
   UnicodeCaseFold.cpp
   VersionTuple.cpp
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -14,6 +14,18 @@
 #include "llvm/Support/TypeSize.h"
 using namespace llvm;
 
+unsigned EVT::getVectorNumElements() const {
+  assert(isVector() && "Invalid vector type!");
+
+  if (isScalableVector())
+llvm::reportInvalidSizeRequest(
+"Possible incorrect use of EVT::getVectorNumElements() for "
+"scalable vector. Scalable flag may be dropped, use "
+"EVT::getVectorElementCount() instead");
+
+  return isSimple() ? V.getVectorNumElements() : getExtendedVectorNumElements();
+}
+
 EVT EVT::changeExtendedTypeToInteger() const {
   assert(isExtended() && "Type is not extended!");
   LLVMContext  = LLVMTy->getContext();
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4847,8 +4847,8 @@
 assert(VT.isVector() && "This DAG node is restricted to vector types.");
 assert(Operand.getValueType().bitsLE(VT) &&
"The input must be the same size or smaller than the result.");
-assert(VT.getVectorNumElements() <
- Operand.getValueType().getVectorNumElements() &&
+assert(VT.getVectorMinNumElements() <
+   Operand.getValueType().getVectorMinNumElements() &&
"The destination vector type must have fewer lanes than the input.");
 break;
   case ISD::ABS:
Index: llvm/lib/Analysis/InstructionSimplify.cpp

  1   2   >