[PATCH] D52524: Add -Wpoison-system-directories warning

2021-05-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

An earlier version did check for library directories [1]. I am not exactly sure 
why was it removed, maybe it didn't work. So if anyone is willing to test that, 
please apply the diff and try.

[1] Diff https://reviews.llvm.org/D52524?id=215958


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

https://reviews.llvm.org/D52524

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


[PATCH] D102820: [Clang] Check for returns_nonnull when deciding to add allocation null checks

2021-05-20 Thread Di Mo via Phabricator via cfe-commits
modimo added a comment.

In D102820#2772184 , @bruno wrote:

> Sounds reasonable to me! Can you double check whether this attribute gets 
> correctly serialized/deserialized in face of `CXXNewExpr`? An example of how 
> to test that would be in `clang/test/PCH/cxx-method.cpp`.

Piggybacking on that test case:

Inputs/cxx-method.h:

  typedef __typeof__(sizeof(0)) size_t;
  
  void *operator new(size_t size)
  {
return ::operator new(size);
  }

cxx-method.cpp:

  int * foo()
  {
  return new int;
  }

Testing

  ~/llvm-project/clang/test/PCH# ~/llvm-project/build-rel/bin/clang++ -cc1 -x 
c++  -emit-pch Inputs/cxx-method.h -o test.pch
  ~/llvm-project/clang/test/PCH# ~/llvm-project/build-rel/bin/clang++ -cc1 -x 
c++ cxx-method.cpp -include-pch test.pch -emit-llvm
  ~/llvm-project/clang/test/PCH# grep _Znwm cxx-method.ll
  define dso_local nonnull i8* @_Znwm(i64 %size) #0 {
%call = call noalias nonnull i8* @_Znwm(i64 %0) #2
%call = call noalias nonnull i8* @_Znwm(i64 4) #3

Assuming I'm answering the correct question that the returns_nonnull is 
preserved through a PCH, the answer is yes.


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

https://reviews.llvm.org/D102820

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji 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 rGedf4d69d3888: [AIX] Print printable byte list as quoted 
string (authored by jsji).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -222,17 +222,17 @@
 ; CHECK:   .dwsect 0x7
 ; CHECK-NEXT:  L...dwstr:
 ; CHECK-NEXT:  L..info_string0:
-; CHECK-NEXT:  .byte   'c,'l,'a,'n,'g,' ,'v,'e,'r,'s,'i,'o,'n,' ,'1,'3,'.,'0,'.,'0, # string offset=0
+; CHECK-NEXT:  .string "clang version 13.0.0"  # string offset=0
 ; CHECK-NEXT:  L..info_string1:
-; CHECK-NEXT:  .byte   '1,'.,'c,   # string offset=21
+; CHECK-NEXT:  .string "1.c"   # string offset=21
 ; CHECK-NEXT:  L..info_string2:
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g, # string offset=25
+; CHECK-NEXT:  .string "debug" # string offset=25
 ; CHECK-NEXT:  L..info_string3:
-; CHECK-NEXT:  .byte   'f,'o,'o,   # string offset=31
+; CHECK-NEXT:  .string "foo"   # string offset=31
 ; CHECK-NEXT:  L..info_string4:
-; CHECK-NEXT:  .byte   'i,'n,'t,   # string offset=35
+; CHECK-NEXT:  .string "int"   # string offset=35
 ; CHECK-NEXT:  L..info_string5:
-; CHECK-NEXT:  .byte   'b,'a,'r,   # string offset=39
+; CHECK-NEXT:  .string "bar"   # string offset=39
 ; CHECK-NEXT:  .toc
 ; CHECK:   .dwsect 0x2
 ; CHECK-NEXT:  L...dwline:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT: 

[clang] edf4d69 - [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via cfe-commits

Author: Jinsong Ji
Date: 2021-05-21T02:37:55Z
New Revision: edf4d69d3888d99187ac28cfcd96a93b41623896

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

LOG: [AIX] Print printable byte list as quoted string

.byte supports string, so if the whole byte list are printable,
we can actually print the string for readability and LIT tests maintainence.

.byte 'H,'e,'l,'l,'o,',,' ,'w,'o,'r,'l,'d
->
.byte "Hello, world"

Reviewed By: hubert.reinterpretcast

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

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-byval.cpp
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
llvm/test/CodeGen/PowerPC/aix-exception.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
llvm/test/DebugInfo/XCOFF/empty.ll
llvm/test/DebugInfo/XCOFF/explicit-section.ll
llvm/test/DebugInfo/XCOFF/function-sections.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-byval.cpp 
b/clang/test/CodeGenCXX/debug-info-byval.cpp
index 38f803d6d9bb..d61c289b3c48 100644
--- a/clang/test/CodeGenCXX/debug-info-byval.cpp
+++ b/clang/test/CodeGenCXX/debug-info-byval.cpp
@@ -24,7 +24,7 @@ void foo(EVT e);
 EVT bar();
 
 void get(int *i, unsigned dl, VAL v, VAL *p, unsigned n, EVT missing_arg) {
-//CHECK: .{{asciz|string}} "missing_arg"
+//CHECK: .{{asciz|string|byte}} "missing_arg"
   EVT e = bar();
   if (dl == n)
 foo(missing_arg);

diff  --git a/llvm/include/llvm/MC/MCAsmInfo.h 
b/llvm/include/llvm/MC/MCAsmInfo.h
index dcc39f0a77cf..e1283c4f7513 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -265,6 +265,11 @@ class MCAsmInfo {
   /// null.  Defaults to null.
   const char *ByteListDirective = nullptr;
 
+  /// This directive allows emission of a zero-terminated ascii string without
+  /// the standard C escape characters embedded into it.  If a target doesn't
+  /// support this, it can be set to null. Defaults to null.
+  const char *PlainStringDirective = nullptr;
+
   /// Form used for character literals in the assembly syntax.  Useful for
   /// producing strings as byte lists.  If a target does not use or support
   /// this, it shall be set to ACLS_Unknown.  Defaults to ACLS_Unknown.
@@ -686,6 +691,7 @@ class MCAsmInfo {
   const char *getAsciiDirective() const { return AsciiDirective; }
   const char *getAscizDirective() const { return AscizDirective; }
   const char *getByteListDirective() const { return ByteListDirective; }
+  const char *getPlainStringDirective() const { return PlainStringDirective; }
   AsmCharLiteralSyntax characterLiteralSyntax() const {
 return CharacterLiteralSyntax;
   }

diff  --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index 603f894dacd2..a55257897608 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -40,6 +40,7 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
   AsciiDirective = nullptr; // not supported
   AscizDirective = nullptr; // not supported
   ByteListDirective = "\t.byte\t";
+  PlainStringDirective = "\t.string\t";
   CharacterLiteralSyntax = ACLS_SingleQuotePrefix;
 
   // Use .vbyte for data definition to avoid directives that apply an implicit

diff  --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index ec4429d62900..2da51f8df391 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -1003,6 +1003,15 @@ void MCAsmStreamer::emitTBSSSymbol(MCSection *Section, 
MCSymbol *Symbol,
   EmitEOL();
 }
 
+static inline bool isPrintableString(StringRef Data) {
+  const auto BeginPtr = Data.begin(), EndPtr = Data.end();
+  for (const unsigned char C : make_range(BeginPtr, EndPtr - 1)) {
+if (!isPrint(C))
+  return false;
+  }
+  return isPrint(Data.back()) || Data.back() == 0;
+}
+
 static inline char toOctal(int X) { return (X&7)+'0'; }
 
 static void PrintByteList(StringRef Data, raw_ostream ,
@@ -1112,6 +1121,22 @@ void MCAsmStreamer::emitBytes(StringRef Data) {
   Data = Data.substr(0, Data.size() - 1);
 } else if (LLVM_LIKELY(MAI->getAsciiDirective())) {
   OS << MAI->getAsciiDirective();
+} else if (MAI->hasPairedDoubleQuoteStringConstants() &&
+   isPrintableString(Data)) {
+  // For target with DoubleQuoteString constants, .string and .byte are 
used
+  // as replacement of .asciz and .ascii.
+  assert(MAI->getPlainStringDirective() &&
+ 

[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346907.
jsji added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -222,17 +222,17 @@
 ; CHECK:   .dwsect 0x7
 ; CHECK-NEXT:  L...dwstr:
 ; CHECK-NEXT:  L..info_string0:
-; CHECK-NEXT:  .byte   'c,'l,'a,'n,'g,' ,'v,'e,'r,'s,'i,'o,'n,' ,'1,'3,'.,'0,'.,'0, # string offset=0
+; CHECK-NEXT:  .string "clang version 13.0.0"  # string offset=0
 ; CHECK-NEXT:  L..info_string1:
-; CHECK-NEXT:  .byte   '1,'.,'c,   # string offset=21
+; CHECK-NEXT:  .string "1.c"   # string offset=21
 ; CHECK-NEXT:  L..info_string2:
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g, # string offset=25
+; CHECK-NEXT:  .string "debug" # string offset=25
 ; CHECK-NEXT:  L..info_string3:
-; CHECK-NEXT:  .byte   'f,'o,'o,   # string offset=31
+; CHECK-NEXT:  .string "foo"   # string offset=31
 ; CHECK-NEXT:  L..info_string4:
-; CHECK-NEXT:  .byte   'i,'n,'t,   # string offset=35
+; CHECK-NEXT:  .string "int"   # string offset=35
 ; CHECK-NEXT:  L..info_string5:
-; CHECK-NEXT:  .byte   'b,'a,'r,   # string offset=39
+; CHECK-NEXT:  .string "bar"   # string offset=39
 ; CHECK-NEXT:  .toc
 ; CHECK:   .dwsect 0x2
 ; CHECK-NEXT:  L...dwline:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect explicit_main_sec[PR],2
@@ 

[PATCH] D101601: [SelectionDAG] Make fast and linearize visible by clang -pre-RA-sched

2021-05-20 Thread TaoPan via Phabricator via cfe-commits
TaoPan added inline comments.



Comment at: clang/test/CodeGen/pre-ra-sched.c:1-2
+// RUN: %clang %s -mllvm -pre-RA-sched=fast -c -o - | FileCheck %s
+// RUN: %clang %s -mllvm -pre-RA-sched=linearize -c -o - | FileCheck %s
+

hubert.reinterpretcast wrote:
> hubert.reinterpretcast wrote:
> > The test as was committed is bogus. It checks the output binary(!) stream 
> > for an error message when stderr was not even redirected. Please fix.
> Fix committed: 
> https://github.com/llvm/llvm-project/commit/603818b97c795114f66a6fc13e8a5f0e54b49a13
Thanks for your review comment and fixing!
I tried to check stderr as you guided and meet empty stdin problem, thanks for 
your quick fixing and I got FileCheck option --allow-empty can resolve this 
kind of problem. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101601

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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D101793#2772461 , @weiwang wrote:

> Thanks for the approval!
>
> Just want to understand the list of "decls to check for deferred diagnostics" 
> better, where are these decls coming from? And why do they need to be checked 
> for warnings? I see decls from libc are in the list, but I have no idea why 
> are they selected.

For offloading languages e.g. OpenMP/CUDA/HIP, there are apparent errors in 
functions shared between host and device. However, unless these functions are 
sure to be emitted on device or host, these errors should not be emitted. These 
errors are so called deferred error messages. The function decls which need to 
be checked are recorded. After AST is finalized, the AST of these functions are 
iterated. If a function is found sure to be emitted, the deferred error message 
in it are emitted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D102241: [clang] p1099 4/5: using enum EnumTag

2021-05-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a reviewer: rsmith.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks for adding the tests. LGTM after some remaining nitpick.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11632
+  // As with enum-decls, we ignore attributes for now.
+
+  auto *Enum = cast(DS.getRepAsDecl());

Remove this empty line.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:12339
+
+if (!CheckUsingShadowDecl(UD, EC, Previous, PrevDecl)) {
+  BuildUsingShadowDecl(S, UD, EC, PrevDecl);

No need for curly braces here.


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

https://reviews.llvm.org/D102241

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


[PATCH] D102772: [SanitizeCoverage] Add support for NoSanitizeCoverage function attribute

2021-05-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:757-760
+bool HaveSanitizeCoverage =
+CGM.getCodeGenOpts().SanitizeCoverageType ||
+CGM.getCodeGenOpts().SanitizeCoverageIndirectCalls ||
+CGM.getCodeGenOpts().SanitizeCoverageTraceCmp;

consider adding method into CodeGenOptions and replace here and and the rest 
ideally in a separate patch




Comment at: clang/test/CodeGen/sanitize-coverage.c:23-87
+static inline __attribute__((__always_inline__)) void always_inlined_fn(int n) 
{
+  if (n)
+x[n] = 42;
+}
+// CHECK-LABEL: define dso_local void @test_always_inline(
+void test_always_inline(int n) {
+  // CHECK-DAG: call void @__sanitizer_cov_trace_pc

you are adding tests for unrelated code.
Could you please land is as a separate NFC patch first?



Comment at: llvm/lib/AsmParser/LLLexer.cpp:674
   KEYWORD(nounwind);
+  KEYWORD(no_sanitize_coverage);
   KEYWORD(null_pointer_is_valid);

looking at the rest, seems "nosanitize_coverage" follows pattern better :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102772

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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang via Phabricator via cfe-commits
weiwang added a comment.

Thanks for the approval!

Just want to understand the list of "decls to check for deferred diagnostics" 
better, where are these decls coming from? And why do they need to be checked 
for warnings? I see decls from libc are in the list, but I have no idea why are 
they selected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D102736: Fix tmp files being left on Windows builds.

2021-05-20 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 346882.
akhuang added a comment.

Change to using TempFiles


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102736

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Windows/Path.inc

Index: llvm/lib/Support/Windows/Path.inc
===
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -560,11 +560,6 @@
   return errc::permission_denied;
 }
 
-static std::error_code rename_fd(int FromFD, const Twine ) {
-  HANDLE FromHandle = reinterpret_cast(_get_osfhandle(FromFD));
-  return rename_handle(FromHandle, To);
-}
-
 std::error_code rename(const Twine , const Twine ) {
   // Convert to utf-16.
   SmallVector WideFrom;
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -1229,7 +1229,7 @@
   auto H = reinterpret_cast(_get_osfhandle(FD));
   std::error_code RenameEC = setDeleteDisposition(H, false);
   if (!RenameEC) {
-RenameEC = rename_fd(FD, Name);
+RenameEC = rename_handle(H, Name);
 // If rename failed because it's cross-device, copy instead
 if (RenameEC ==
   std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
@@ -1261,7 +1261,6 @@
 return errorCodeToError(EC);
   }
   FD = -1;
-
   return errorCodeToError(RenameEC);
 }
 
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -704,6 +704,10 @@
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
   for (OutputFile  : OutputFiles) {
 if (EraseFiles) {
+  if (OF.TempFile) {
+if (llvm::Error E = OF.TempFile->discard())
+  consumeError(std::move(E));
+  }
   if (!OF.TempFilename.empty()) {
 llvm::sys::fs::remove(OF.TempFilename);
 continue;
@@ -720,11 +724,22 @@
 // relative to that.
 SmallString<128> NewOutFile(OF.Filename);
 FileMgr->FixupRelativePath(NewOutFile);
-std::error_code EC = llvm::sys::fs::rename(OF.TempFilename, NewOutFile);
-if (!EC)
+
+std::string ErrorMsg;
+if (OF.TempFile) {
+  if (llvm::Error E = OF.TempFile->keep(NewOutFile))
+ErrorMsg = toString(std::move(E));
+} else {
+  if (std::error_code EC =
+  llvm::sys::fs::rename(OF.TempFilename, NewOutFile))
+ErrorMsg = EC.message();
+}
+
+if (ErrorMsg.empty())
   continue;
+
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.TempFilename << OF.Filename << EC.message();
+<< OF.TempFilename << OF.Filename << ErrorMsg;
 
 llvm::sys::fs::remove(OF.TempFilename);
   }
@@ -808,7 +823,8 @@
 }
   }
 
-  std::string TempFile;
+  std::string TempFileName;
+  Optional Temp;
   if (UseTemporary) {
 // Create a temporary file.
 // Insert - before the extension (if any), and because some tools
@@ -821,9 +837,44 @@
 TempPath += OutputExtension;
 TempPath += ".tmp";
 int fd;
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-TempPath, fd, TempPath,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
+#if _WIN32
+// On Windows, use llvm::sys::fs::TempFile to write the output file so
+// that it is deleted if the program crashes.
+Expected ExpectedFile =
+llvm::sys::fs::TempFile::create(TempPath);
+
+llvm::Error E = handleErrors(
+ExpectedFile.takeError(), [&](const llvm::ECError ) -> llvm::Error {
+  std::error_code EC = E.convertToErrorCode();
+  if (CreateMissingDirectories &&
+  EC == llvm::errc::no_such_file_or_directory) {
+StringRef Parent = llvm::sys::path::parent_path(OutputPath);
+EC = llvm::sys::fs::create_directories(Parent);
+if (!EC) {
+  ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
+  if (!ExpectedFile)
+return llvm::errorCodeToError(
+llvm::errc::no_such_file_or_directory);
+}
+  }
+  return llvm::errorCodeToError(EC);
+});
+
+if (E) {
+  consumeError(std::move(E));
+} else {
+  Temp = std::move(ExpectedFile.get());
+  fd = Temp->FD;
+  TempPath = Temp->TmpName;
+
+  OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/false));
+  OSFile = TempFileName = std::string(TempPath.str());
+}
+#else
+std::error_code EC;
+EC = fs::createUniqueFile(TempPath, fd, TempPath,
+  Binary ? llvm::sys::fs::OF_None
+ : llvm::sys::fs::OF_Text);
 
 if 

[PATCH] D102736: Fix tmp files being left on Windows builds.

2021-05-20 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked 2 inline comments as done.
akhuang added a comment.

In D102736#2769747 , @akhuang wrote:

> In D102736#2769358 , @amccarth 
> wrote:
>
>> At some point, the duplicate handle must be closed.  I don't see that 
>> happening.  I've added an inline comment where I think it should be done.
>>
>> (I find it weird that duplicating the handle seems necessary.)
>>
>> At a high level, it seems a shame that `llvm::support::fs` doesn't have 
>> create-temporary-file and keep-temporary-file operations to hide all this 
>> detail from the frontend.
>
> So, there is a `TempFile` class in `llvm::support::fs` with create temp file 
> and keep temp file operations, and it would be nice to use that. The issue I 
> was running into is that it uses a file descriptor (`int fd`) to keep track 
> of the file, but for some reason, the function to convert the fd to a handle 
> (`_get_osfhandle`) was not working (exits the program when called). I haven't 
> yet figured out why this is happening

Ok, apparently the whole issue with it not being able to open the handle is 
just because we were passing `shouldClose=true` to the `raw_fd_ostream`, which 
makes it close the file when done writing.
 Since that's figured out, I think using `TempFile` makes the most sense


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102736

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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang 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 rGe6b8320c0a63: [clang][AST] Improve AST Reader/Writer memory 
footprint (authored by weiwang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

Files:
  clang/include/clang/Sema/ExternalSemaSource.h
  clang/include/clang/Sema/MultiplexExternalSemaSource.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Sema/MultiplexExternalSemaSource.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4667,9 +4667,9 @@
   }
 
   // Build a record containing all of the DeclsToCheckForDeferredDiags.
-  RecordData DeclsToCheckForDeferredDiags;
+  SmallVector DeclsToCheckForDeferredDiags;
   for (auto *D : SemaRef.DeclsToCheckForDeferredDiags)
-AddDeclRef(D, DeclsToCheckForDeferredDiags);
+DeclsToCheckForDeferredDiags.push_back(GetDeclRef(D));
 
   RecordData DeclUpdatesOffsetsRecord;
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3810,7 +3810,7 @@
 
 case DECLS_TO_CHECK_FOR_DEFERRED_DIAGS:
   for (unsigned I = 0, N = Record.size(); I != N; ++I)
-DeclsToCheckForDeferredDiags.push_back(getGlobalDeclID(F, Record[I]));
+DeclsToCheckForDeferredDiags.insert(getGlobalDeclID(F, Record[I]));
   break;
 }
   }
@@ -8333,18 +8333,15 @@
 }
 
 void ASTReader::ReadDeclsToCheckForDeferredDiags(
-llvm::SmallVector ) {
-  for (unsigned I = 0, N = DeclsToCheckForDeferredDiags.size(); I != N;
-   ++I) {
-auto *D = dyn_cast_or_null(
-GetDecl(DeclsToCheckForDeferredDiags[I]));
+llvm::SmallSetVector ) {
+  for (auto I : DeclsToCheckForDeferredDiags) {
+auto *D = dyn_cast_or_null(GetDecl(I));
 if (D)
-  Decls.push_back(D);
+  Decls.insert(D);
   }
   DeclsToCheckForDeferredDiags.clear();
 }
 
-
 void ASTReader::ReadReferencedSelectors(
SmallVectorImpl> ) {
   if (ReferencedSelectorsData.empty())
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12539,7 +12539,7 @@
   }
 
   if (LangOpts.OpenMP && VDecl->isFileVarDecl())
-DeclsToCheckForDeferredDiags.push_back(VDecl);
+DeclsToCheckForDeferredDiags.insert(VDecl);
   CheckCompleteVariableDeclaration(VDecl);
 }
 
@@ -14773,7 +14773,7 @@
 auto ES = getEmissionStatus(FD);
 if (ES == Sema::FunctionEmissionStatus::Emitted ||
 ES == Sema::FunctionEmissionStatus::Unknown)
-  DeclsToCheckForDeferredDiags.push_back(FD);
+  DeclsToCheckForDeferredDiags.insert(FD);
   }
 
   return dcl;
Index: clang/lib/Sema/MultiplexExternalSemaSource.cpp
===
--- clang/lib/Sema/MultiplexExternalSemaSource.cpp
+++ clang/lib/Sema/MultiplexExternalSemaSource.cpp
@@ -268,7 +268,7 @@
 }
 
 void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags(
-llvm::SmallVector ) {
+llvm::SmallSetVector ) {
   for(size_t i = 0; i < Sources.size(); ++i)
 Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
 }
Index: clang/include/clang/Serialization/ASTWriter.h
===
--- clang/include/clang/Serialization/ASTWriter.h
+++ clang/include/clang/Serialization/ASTWriter.h
@@ -402,8 +402,8 @@
   /// headers. The declarations themselves are stored as declaration
   /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
   /// record.
-  SmallVector EagerlyDeserializedDecls;
-  SmallVector ModularCodegenDecls;
+  SmallVector EagerlyDeserializedDecls;
+  SmallVector ModularCodegenDecls;
 
   /// DeclContexts that have received extensions since their serialized
   /// form.
Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -767,21 +767,21 @@
   /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
   /// in the chain. The referenced declarations are deserialized and passed to
   /// the consumer eagerly.
-  SmallVector EagerlyDeserializedDecls;
+  SmallVector EagerlyDeserializedDecls;
 
   /// The IDs of all tentative definitions stored in the chain.
   ///
   /// Sema keeps track of all tentative definitions in a TU because 

[clang] e6b8320 - [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2021-05-20T15:34:29-07:00
New Revision: e6b8320c0a634ba60c82693c6631ea90fb2988a6

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

LOG: [clang][AST] Improve AST Reader/Writer memory footprint

Reduce memory footprint of AST Reader/Writer:
1. Adjust internal data containers' element type.
2. Switch to set for deduplication of deferred diags.

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

Added: 


Modified: 
clang/include/clang/Sema/ExternalSemaSource.h
clang/include/clang/Sema/MultiplexExternalSemaSource.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Sema/MultiplexExternalSemaSource.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/ExternalSemaSource.h 
b/clang/include/clang/Sema/ExternalSemaSource.h
index 2854b4893484d..9c18aa1398d37 100644
--- a/clang/include/clang/Sema/ExternalSemaSource.h
+++ b/clang/include/clang/Sema/ExternalSemaSource.h
@@ -199,8 +199,8 @@ class ExternalSemaSource : public ExternalASTSource {
   /// and variable decls which may cause deferred diags. Note that this routine
   /// may be invoked multiple times; the external source should take care not 
to
   /// introduce the same declarations repeatedly.
-  virtual void ReadDeclsToCheckForDeferredDiags(
-  llvm::SmallVector ) {}
+  virtual void
+  ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector ) {}
 
   /// \copydoc Sema::CorrectTypo
   /// \note LookupKind must correspond to a valid Sema::LookupNameKind

diff  --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index b54a6283d6408..78658dcf990c4 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -337,7 +337,7 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   /// may be invoked multiple times; the external source should take care not 
to
   /// introduce the same declarations repeatedly.
   void ReadDeclsToCheckForDeferredDiags(
-  llvm::SmallVector ) override;
+  llvm::SmallSetVector ) override;
 
   /// \copydoc ExternalSemaSource::CorrectTypo
   /// \note Returns the first nonempty correction.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114ff6441b4a8..2ac6471c4f04a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1786,7 +1786,7 @@ class Sema final {
   private:
 /// Function or variable declarations to be checked for whether the 
deferred
 /// diagnostics should be emitted.
-SmallVector DeclsToCheckForDeferredDiags;
+llvm::SmallSetVector DeclsToCheckForDeferredDiags;
 
   public:
   // Emit all deferred diagnostics.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 0df687c05366a..6932d9c86d0cc 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -767,21 +767,21 @@ class ASTReader
   /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
   /// in the chain. The referenced declarations are deserialized and passed to
   /// the consumer eagerly.
-  SmallVector EagerlyDeserializedDecls;
+  SmallVector EagerlyDeserializedDecls;
 
   /// The IDs of all tentative definitions stored in the chain.
   ///
   /// Sema keeps track of all tentative definitions in a TU because it has to
   /// complete them and pass them on to CodeGen. Thus, tentative definitions in
   /// the PCH chain must be eagerly deserialized.
-  SmallVector TentativeDefinitions;
+  SmallVector TentativeDefinitions;
 
   /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
   /// used.
   ///
   /// CodeGen has to emit VTables for these records, so they have to be eagerly
   /// deserialized.
-  SmallVector VTableUses;
+  SmallVector VTableUses;
 
   /// A snapshot of the pending instantiations in the chain.
   ///
@@ -789,7 +789,7 @@ class ASTReader
   /// end of the TU. It consists of a pair of values for every pending
   /// instantiation where the first value is the ID of the decl and the second
   /// is the instantiation location.
-  SmallVector PendingInstantiations;
+  SmallVector PendingInstantiations;
 
   //@}
 
@@ -799,24 +799,24 @@ class ASTReader
 
   /// A snapshot of Sema's unused file-scoped variable tracking, for
   /// generating warnings.
-  SmallVector UnusedFileScopedDecls;
+  SmallVector UnusedFileScopedDecls;
 
   /// A list of all the delegating constructors 

[PATCH] D102730: [clang-format] Support custom If macros

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich updated this revision to Diff 346870.
vlovich added a comment.

Fixed missing _ after the hyperlink to the KJ link in the Style options 
documentation. I'm assuming that's required formatting for hyperlinks by what 
renders the markdown.


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

https://reviews.llvm.org/D102730

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17111,6 +17111,11 @@
   CHECK_PARSE("ForEachMacros: [BOOST_FOREACH, Q_FOREACH]", ForEachMacros,
   BoostAndQForeach);
 
+  Style.IfMacros.clear();
+  std::vector CustomIfs;
+  CustomIfs.push_back("MYIF");
+  CHECK_PARSE("IfMacros: [MYIF]", IfMacros, CustomIfs);
+
   Style.AttributeMacros.clear();
   CHECK_PARSE("BasedOnStyle: LLVM", AttributeMacros,
   std::vector{"__capability"});
@@ -19684,11 +19689,16 @@
 
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
+  Spaces.IfMacros.clear();
+  Spaces.IfMacros.push_back("MYIF");
   Spaces.SpacesInConditionalStatement = true;
   verifyFormat("for ( int i = 0; i; i++ )\n  continue;", Spaces);
   verifyFormat("if ( !a )\n  return;", Spaces);
   verifyFormat("if ( a )\n  return;", Spaces);
   verifyFormat("if constexpr ( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse MYIF( b )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse\n  return;", Spaces);
   verifyFormat("switch ( a )\ncase 1:\n  return;", Spaces);
   verifyFormat("while ( a )\n  return;", Spaces);
   verifyFormat("while ( (a && b) )\n  return;", Spaces);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1363,7 +1363,7 @@
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
 if (!CurrentToken->isOneOf(
-TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro,
+TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
 TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
@@ -3022,6 +3022,9 @@
 FormatStyle::SBPO_ControlStatementsExceptForEachMacros &&
 Left.is(TT_ForEachMacro))
   return false;
+if (Left.is(TT_IfMacro)) {
+  return false;
+}
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -39,6 +39,8 @@
 
   for (const std::string  : Style.ForEachMacros)
 Macros.insert({(ForEachMacro), TT_ForEachMacro});
+  for (const std::string  : Style.IfMacros)
+Macros.insert({(IfMacro), TT_IfMacro});
   for (const std::string  : Style.AttributeMacros)
 Macros.insert({(AttributeMacro), TT_AttributeMacro});
   for (const std::string  : Style.StatementMacros)
@@ -1014,6 +1016,9 @@
   tok::pp_define) &&
 it != Macros.end()) {
   FormatTok->setType(it->second);
+  if (it->second == TT_IfMacro) {
+FormatTok->Tok.setKind(tok::kw_if);
+  }
 } else if (FormatTok->is(tok::identifier)) {
   if (MacroBlockBeginRegex.match(Text)) {
 FormatTok->setType(TT_MacroBlockBegin);
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@
   TYPE(FunctionDeclarationName)\
   TYPE(FunctionLBrace) \
   TYPE(FunctionTypeLParen) \
+  TYPE(IfMacro)\
   TYPE(ImplicitStringLiteral)  \
   TYPE(InheritanceColon)   \
   TYPE(InheritanceComma)   \
Index: clang/lib/Format/Format.cpp

[PATCH] D102706: [clang-format] Add new LambdaBodyIndentation option

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich updated this revision to Diff 346869.
vlovich added a comment.
Herald added a subscriber: mgrang.

Review response

- Add examples to documentation + links to KJ style guide.
- Add better header doc
- Add more test cases
- Add release notes
- Note current "problem" test with a TODO (corner case that's not critical for 
KJ).


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

https://reviews.llvm.org/D102706

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17871,6 +17871,7 @@
" aaa;\n"
"});",
getLLVMStyleWithColumns(60));
+
   verifyFormat("SomeFunction({[&] {\n"
"// comment\n"
"  },\n"
@@ -18423,6 +18424,105 @@
"  });\n"
"});",
LLVMWithBeforeLambdaBody);
+
+  // Lambdas with different indentation styles.
+  Style = getLLVMStyleWithColumns(100);
+  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
+"  return promise.then(\n"
+"  [this, , someObject = std::mv(s)](std::vector evaluated) mutable {\n"
+"return someObject.startAsyncAction().then(\n"
+"[this, ](AsyncActionResult result) mutable { result.processMore(); });\n"
+"  });\n"
+"}\n",
+format("SomeResult doSomething(SomeObject promise) {\n"
+   "  return promise.then([this, , someObject = std::mv(s)](std::vector evaluated) mutable {\n"
+   "return someObject.startAsyncAction().then([this, ](AsyncActionResult result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style));
+  Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
+  verifyFormat("test() {\n"
+   "  ([]() -> {\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  }).foo();\n"
+   "}",
+   Style);
+  verifyFormat("test() {\n"
+   "  []() -> {\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  }\n"
+   "}",
+   Style);
+  verifyFormat("std::sort(v.begin(), v.end(),\n"
+   "  [](const auto , const auto ) {\n"
+   "  return someLongArgumentName.someMemberVariable < someOtherLongArgumentName.someMemberVariable;\n"
+   "});",
+   Style);
+  verifyFormat("test() {\n"
+   "  (\n"
+   "  []() -> {\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  },\n"
+   "  foo, bar)\n"
+   "  .foo();\n"
+   "}",
+   Style);
+  verifyFormat("test() {\n"
+   "  ([]() -> {\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  })\n"
+   "  .foo()\n"
+   "  .bar();\n"
+   "}",
+   Style);
+  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
+"  return promise.then(\n"
+"  [this, , someObject = std::mv(s)](std::vector evaluated) mutable {\n"
+"return someObject.startAsyncAction().then(\n"
+"[this, ](AsyncActionResult result) mutable { result.processMore(); });\n"
+"  });\n"
+"}\n",
+format("SomeResult doSomething(SomeObject promise) {\n"
+   "  return promise.then([this, , someObject = std::mv(s)](std::vector evaluated) mutable {\n"
+   "return someObject.startAsyncAction().then([this, ](AsyncActionResult result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style));
+  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
+"  return promise.then([this, ] {\n"
+"return someObject.startAsyncAction().then(\n"
+"[this, ](AsyncActionResult result) mutable { result.processMore(); });\n"
+"  });\n"
+"}\n",
+format("SomeResult doSomething(SomeObject promise) {\n"
+   "  return promise.then([this, ] {\n"
+   "return someObject.startAsyncAction().then([this, ](AsyncActionResult result) mutable {\n"
+  

[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl 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/D101793/new/

https://reviews.llvm.org/D101793

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


[PATCH] D102772: [SanitizeCoverage] Add support for NoSanitizeCoverage function attribute

2021-05-20 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse accepted this revision.
morehouse 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/D102772/new/

https://reviews.llvm.org/D102772

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


[PATCH] D102879: rdar://77307290 (Disable retain-count tracking for references to OSMetaClass)

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna 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/D102879

Files:
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -721,6 +721,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 class SampleClass {
 public:
   OSObjectPtr field;
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -68,6 +68,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,14 +146,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -721,6 +721,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 class SampleClass {
 public:
   OSObjectPtr field;
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -68,6 +68,8 @@
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
   static OSObject * allocClassWithName(const char * name);
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+  void releaseMetaClass() const;
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,14 +146,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang via Phabricator via cfe-commits
weiwang updated this revision to Diff 346866.
weiwang added a comment.

make both ASTReader::DeclsToCheckForDeferredDiags and 
Sema::DeclsToCheckForDeferredDiags SmallSetVector


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

Files:
  clang/include/clang/Sema/ExternalSemaSource.h
  clang/include/clang/Sema/MultiplexExternalSemaSource.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Sema/MultiplexExternalSemaSource.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4667,9 +4667,9 @@
   }
 
   // Build a record containing all of the DeclsToCheckForDeferredDiags.
-  RecordData DeclsToCheckForDeferredDiags;
+  SmallVector DeclsToCheckForDeferredDiags;
   for (auto *D : SemaRef.DeclsToCheckForDeferredDiags)
-AddDeclRef(D, DeclsToCheckForDeferredDiags);
+DeclsToCheckForDeferredDiags.push_back(GetDeclRef(D));
 
   RecordData DeclUpdatesOffsetsRecord;
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3810,7 +3810,7 @@
 
 case DECLS_TO_CHECK_FOR_DEFERRED_DIAGS:
   for (unsigned I = 0, N = Record.size(); I != N; ++I)
-DeclsToCheckForDeferredDiags.push_back(getGlobalDeclID(F, Record[I]));
+DeclsToCheckForDeferredDiags.insert(getGlobalDeclID(F, Record[I]));
   break;
 }
   }
@@ -8333,18 +8333,15 @@
 }
 
 void ASTReader::ReadDeclsToCheckForDeferredDiags(
-llvm::SmallVector ) {
-  for (unsigned I = 0, N = DeclsToCheckForDeferredDiags.size(); I != N;
-   ++I) {
-auto *D = dyn_cast_or_null(
-GetDecl(DeclsToCheckForDeferredDiags[I]));
+llvm::SmallSetVector ) {
+  for (auto I : DeclsToCheckForDeferredDiags) {
+auto *D = dyn_cast_or_null(GetDecl(I));
 if (D)
-  Decls.push_back(D);
+  Decls.insert(D);
   }
   DeclsToCheckForDeferredDiags.clear();
 }
 
-
 void ASTReader::ReadReferencedSelectors(
SmallVectorImpl> ) {
   if (ReferencedSelectorsData.empty())
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12539,7 +12539,7 @@
   }
 
   if (LangOpts.OpenMP && VDecl->isFileVarDecl())
-DeclsToCheckForDeferredDiags.push_back(VDecl);
+DeclsToCheckForDeferredDiags.insert(VDecl);
   CheckCompleteVariableDeclaration(VDecl);
 }
 
@@ -14773,7 +14773,7 @@
 auto ES = getEmissionStatus(FD);
 if (ES == Sema::FunctionEmissionStatus::Emitted ||
 ES == Sema::FunctionEmissionStatus::Unknown)
-  DeclsToCheckForDeferredDiags.push_back(FD);
+  DeclsToCheckForDeferredDiags.insert(FD);
   }
 
   return dcl;
Index: clang/lib/Sema/MultiplexExternalSemaSource.cpp
===
--- clang/lib/Sema/MultiplexExternalSemaSource.cpp
+++ clang/lib/Sema/MultiplexExternalSemaSource.cpp
@@ -268,7 +268,7 @@
 }
 
 void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags(
-llvm::SmallVector ) {
+llvm::SmallSetVector ) {
   for(size_t i = 0; i < Sources.size(); ++i)
 Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
 }
Index: clang/include/clang/Serialization/ASTWriter.h
===
--- clang/include/clang/Serialization/ASTWriter.h
+++ clang/include/clang/Serialization/ASTWriter.h
@@ -402,8 +402,8 @@
   /// headers. The declarations themselves are stored as declaration
   /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS
   /// record.
-  SmallVector EagerlyDeserializedDecls;
-  SmallVector ModularCodegenDecls;
+  SmallVector EagerlyDeserializedDecls;
+  SmallVector ModularCodegenDecls;
 
   /// DeclContexts that have received extensions since their serialized
   /// form.
Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -767,21 +767,21 @@
   /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
   /// in the chain. The referenced declarations are deserialized and passed to
   /// the consumer eagerly.
-  SmallVector EagerlyDeserializedDecls;
+  SmallVector EagerlyDeserializedDecls;
 
   /// The IDs of all tentative definitions stored in the chain.
   ///
   /// Sema keeps track of all tentative definitions in a TU because it has to
   /// complete them and pass them on to CodeGen. Thus, 

[PATCH] D97680: [OpenMP] Simplify GPU memory globalization

2021-05-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

Generally LGTM. Some nits.




Comment at: clang/include/clang/Driver/Options.td:2331
   PosFlag, NegFlag, 
BothFlags<[NoArgumentUnused, HelpHidden]>>;
-def fopenmp_cuda_parallel_target_regions : Flag<["-"], 
"fopenmp-cuda-parallel-target-regions">, Group,
-  Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,

Can we make these removal of options in another patch if it doesn't affect 
remaining functionality?



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:1731
 llvm::ConstantInt::get(CGF.SizeTy, Align.getQuantity());
+
 Size = Bld.CreateUDiv(Size, AlignVal);

unrelated



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:3885
 return;
+
   CheckVarsEscapingDeclContext VarChecker(CGF, TeamAndReductions.second);

unrelated change



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:3907
 assert(VD->isCanonicalDecl() && "Expected canonical declaration");
-const FieldDecl *FD = VarChecker.getFieldForGlobalizedVar(VD);
-Data.insert(std::make_pair(VD, MappedVarData(FD, IsInTTDRegion)));
+Data.insert(std::make_pair(VD, MappedVarData()));
   }

Not sure that's the reason you need the explicit constructor. If yes, can we 
get around it somehow?



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.h:442
   struct MappedVarData {
+MappedVarData() = default;
 /// Corresponding field in the global record.

Constructor is not needed here I suppose?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97680

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


[PATCH] D102730: [clang-format] Support custom If macros

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich updated this revision to Diff 346864.
vlovich marked an inline comment as done.
vlovich added a comment.

Updated release notes.


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

https://reviews.llvm.org/D102730

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17111,6 +17111,11 @@
   CHECK_PARSE("ForEachMacros: [BOOST_FOREACH, Q_FOREACH]", ForEachMacros,
   BoostAndQForeach);
 
+  Style.IfMacros.clear();
+  std::vector CustomIfs;
+  CustomIfs.push_back("MYIF");
+  CHECK_PARSE("IfMacros: [MYIF]", IfMacros, CustomIfs);
+
   Style.AttributeMacros.clear();
   CHECK_PARSE("BasedOnStyle: LLVM", AttributeMacros,
   std::vector{"__capability"});
@@ -19684,11 +19689,16 @@
 
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
+  Spaces.IfMacros.clear();
+  Spaces.IfMacros.push_back("MYIF");
   Spaces.SpacesInConditionalStatement = true;
   verifyFormat("for ( int i = 0; i; i++ )\n  continue;", Spaces);
   verifyFormat("if ( !a )\n  return;", Spaces);
   verifyFormat("if ( a )\n  return;", Spaces);
   verifyFormat("if constexpr ( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse MYIF( b )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse\n  return;", Spaces);
   verifyFormat("switch ( a )\ncase 1:\n  return;", Spaces);
   verifyFormat("while ( a )\n  return;", Spaces);
   verifyFormat("while ( (a && b) )\n  return;", Spaces);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1363,7 +1363,7 @@
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
 if (!CurrentToken->isOneOf(
-TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro,
+TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
 TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
@@ -3022,6 +3022,9 @@
 FormatStyle::SBPO_ControlStatementsExceptForEachMacros &&
 Left.is(TT_ForEachMacro))
   return false;
+if (Left.is(TT_IfMacro)) {
+  return false;
+}
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -39,6 +39,8 @@
 
   for (const std::string  : Style.ForEachMacros)
 Macros.insert({(ForEachMacro), TT_ForEachMacro});
+  for (const std::string  : Style.IfMacros)
+Macros.insert({(IfMacro), TT_IfMacro});
   for (const std::string  : Style.AttributeMacros)
 Macros.insert({(AttributeMacro), TT_AttributeMacro});
   for (const std::string  : Style.StatementMacros)
@@ -1014,6 +1016,9 @@
   tok::pp_define) &&
 it != Macros.end()) {
   FormatTok->setType(it->second);
+  if (it->second == TT_IfMacro) {
+FormatTok->Tok.setKind(tok::kw_if);
+  }
 } else if (FormatTok->is(tok::identifier)) {
   if (MacroBlockBeginRegex.match(Text)) {
 FormatTok->setType(TT_MacroBlockBegin);
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@
   TYPE(FunctionDeclarationName)\
   TYPE(FunctionLBrace) \
   TYPE(FunctionTypeLParen) \
+  TYPE(IfMacro)\
   TYPE(ImplicitStringLiteral)  \
   TYPE(InheritanceColon)   \
   TYPE(InheritanceComma)   \
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -616,6 

[PATCH] D102730: [clang-format] Support custom If macros

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich marked an inline comment as done.
vlovich added inline comments.



Comment at: clang/include/clang/Format/Format.h:2098
+  ///
+  /// For example: KJ_IF_MAYBE.
+  std::vector IfMacros;

HazardyKnusperkeks wrote:
> vlovich wrote:
> > Should I put a hyperlink to 
> > https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes?
> Maybe. *scnr*
Well done. Took me a second.


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

https://reviews.llvm.org/D102730

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


[PATCH] D102730: [clang-format] Support custom If macros

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich updated this revision to Diff 346863.
vlovich added a comment.

Review response:

- Added additional tests.
- Added `KJ_IF_MAYBE` to default `IfMacros`.
- Added links to KJ documentation.


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

https://reviews.llvm.org/D102730

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17111,6 +17111,11 @@
   CHECK_PARSE("ForEachMacros: [BOOST_FOREACH, Q_FOREACH]", ForEachMacros,
   BoostAndQForeach);
 
+  Style.IfMacros.clear();
+  std::vector CustomIfs;
+  CustomIfs.push_back("MYIF");
+  CHECK_PARSE("IfMacros: [MYIF]", IfMacros, CustomIfs);
+
   Style.AttributeMacros.clear();
   CHECK_PARSE("BasedOnStyle: LLVM", AttributeMacros,
   std::vector{"__capability"});
@@ -19684,11 +19689,16 @@
 
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
+  Spaces.IfMacros.clear();
+  Spaces.IfMacros.push_back("MYIF");
   Spaces.SpacesInConditionalStatement = true;
   verifyFormat("for ( int i = 0; i; i++ )\n  continue;", Spaces);
   verifyFormat("if ( !a )\n  return;", Spaces);
   verifyFormat("if ( a )\n  return;", Spaces);
   verifyFormat("if constexpr ( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse MYIF( b )\n  return;", Spaces);
+  verifyFormat("MYIF( a )\n  return;\nelse\n  return;", Spaces);
   verifyFormat("switch ( a )\ncase 1:\n  return;", Spaces);
   verifyFormat("while ( a )\n  return;", Spaces);
   verifyFormat("while ( (a && b) )\n  return;", Spaces);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1363,7 +1363,7 @@
 // Reset token type in case we have already looked at it and then
 // recovered from an error (e.g. failure to find the matching >).
 if (!CurrentToken->isOneOf(
-TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro,
+TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
 TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
@@ -3022,6 +3022,9 @@
 FormatStyle::SBPO_ControlStatementsExceptForEachMacros &&
 Left.is(TT_ForEachMacro))
   return false;
+if (Left.is(TT_IfMacro)) {
+  return false;
+}
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -39,6 +39,8 @@
 
   for (const std::string  : Style.ForEachMacros)
 Macros.insert({(ForEachMacro), TT_ForEachMacro});
+  for (const std::string  : Style.IfMacros)
+Macros.insert({(IfMacro), TT_IfMacro});
   for (const std::string  : Style.AttributeMacros)
 Macros.insert({(AttributeMacro), TT_AttributeMacro});
   for (const std::string  : Style.StatementMacros)
@@ -1014,6 +1016,9 @@
   tok::pp_define) &&
 it != Macros.end()) {
   FormatTok->setType(it->second);
+  if (it->second == TT_IfMacro) {
+FormatTok->Tok.setKind(tok::kw_if);
+  }
 } else if (FormatTok->is(tok::identifier)) {
   if (MacroBlockBeginRegex.match(Text)) {
 FormatTok->setType(TT_MacroBlockBegin);
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@
   TYPE(FunctionDeclarationName)\
   TYPE(FunctionLBrace) \
   TYPE(FunctionTypeLParen) \
+  TYPE(IfMacro)\
   TYPE(ImplicitStringLiteral)  \
   TYPE(InheritanceColon)   \
   TYPE(InheritanceComma)   \
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ 

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102782: Add support for Warning Flag "-Wstack-usage="

2021-05-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Overall looks good, sounds like it's failing tests though?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102782

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


[PATCH] D102706: [clang-format] Add new LambdaBodyIndentation option

2021-05-20 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich added a comment.

> verifyFormat("test() {\n"
>
>   "  ([]() -> {\n"
>   "int b = 32;\n"
>   "return 3;\n"
>   "  }).foo();\n"
>   "}",
>   Style);
>
>   There you have parenthesis around the lambda, how about without?
>   Maybe just something like
>
> std::sort(v.begin(), v.end(), [](const auto& lhs, const auto& rhs) { return 
> lhs.Foo < rhs.Foo; });
>
>   

Ah. Ok. What I had done was run all the tests with this flag & note the ones 
where the formatting changed & copied those. The one without parenthesis didn't 
do anything interesting which is why I omitted it originally. I'll add it back 
+ your sort example too. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102706

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


[PATCH] D101777: [clang] p1099 1/5: [NFC] Break out BaseUsingDecl from UsingDecl

2021-05-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D101777

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


[PATCH] D102876: Fix tmp files being left on Windows builds.

2021-05-20 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
Herald added subscribers: dexonsmith, hiraditya.
akhuang requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Clang writes object files by first writing to a .tmp file and then renaming to 
the final .obj name. On Windows, if a compile is killed partway through the 
.tmp files don't get deleted.

Currently it seems like RemoveFileOnSignal takes care of deleting the
tmp files on Linux, but on Windows we need to call
setDeleteDisposition on tmp files so that they are deleted when
closed.

This patch uses llvm::sys::fs::TempFile to create these files on Windows.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102876

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp
  llvm/include/llvm/Support/FileSystem.h
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Windows/Path.inc

Index: llvm/lib/Support/Windows/Path.inc
===
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -435,6 +435,7 @@
   if (!SetFileInformationByHandle(Handle, FileDispositionInfo, ,
   sizeof(Disposition)))
 return mapWindowsError(::GetLastError());
+
   return std::error_code();
 }
 
@@ -560,11 +561,6 @@
   return errc::permission_denied;
 }
 
-static std::error_code rename_fd(int FromFD, const Twine ) {
-  HANDLE FromHandle = reinterpret_cast(_get_osfhandle(FromFD));
-  return rename_handle(FromHandle, To);
-}
-
 std::error_code rename(const Twine , const Twine ) {
   // Convert to utf-16.
   SmallVector WideFrom;
@@ -1153,6 +1149,7 @@
 return EC;
   }
   ResultFile = H;
+
   return std::error_code();
 }
 
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -1182,14 +1182,16 @@
 namespace llvm {
 namespace sys {
 namespace fs {
-TempFile::TempFile(StringRef Name, int FD)
-: TmpName(std::string(Name)), FD(FD) {}
+TempFile::TempFile(StringRef Name, int FD, file_t Handle = nullptr)
+: TmpName(std::string(Name)), FD(FD), Handle(Handle) {}
 TempFile::TempFile(TempFile &) { *this = std::move(Other); }
 TempFile ::operator=(TempFile &) {
   TmpName = std::move(Other.TmpName);
   FD = Other.FD;
+  Handle = Other.Handle;
   Other.Done = true;
   Other.FD = -1;
+  Other.Handle = 0;
   return *this;
 }
 
@@ -1197,13 +1199,18 @@
 
 Error TempFile::discard() {
   Done = true;
-  if (FD != -1 && close(FD) == -1) {
+  if (!Handle && FD != -1 && close(FD) == -1) {
 std::error_code EC = std::error_code(errno, std::generic_category());
 return errorCodeToError(EC);
   }
   FD = -1;
 
 #ifdef _WIN32
+  if (Handle && !::CloseHandle(Handle)) {
+std::error_code EC = mapWindowsError(::GetLastError());
+return errorCodeToError(EC);
+  }
+
   // On windows closing will remove the file.
   TmpName = "";
   return Error::success();
@@ -1226,10 +1233,10 @@
   // Always try to close and rename.
 #ifdef _WIN32
   // If we can't cancel the delete don't rename.
-  auto H = reinterpret_cast(_get_osfhandle(FD));
+  HANDLE H = (Handle) ? Handle : reinterpret_cast(_get_osfhandle(FD));
   std::error_code RenameEC = setDeleteDisposition(H, false);
   if (!RenameEC) {
-RenameEC = rename_fd(FD, Name);
+RenameEC = rename_handle(H, Name);
 // If rename failed because it's cross-device, copy instead
 if (RenameEC ==
   std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
@@ -1256,12 +1263,20 @@
   if (!RenameEC)
 TmpName = "";
 
-  if (close(FD) == -1) {
-std::error_code EC(errno, std::generic_category());
-return errorCodeToError(EC);
+  if (!Handle) {
+if (close(FD) == -1) {
+  std::error_code EC(errno, std::generic_category());
+  return errorCodeToError(EC);
+}
+  } else {
+#ifdef _WIN32
+if (!::CloseHandle(Handle)) {
+  std::error_code EC = mapWindowsError(::GetLastError());
+  return errorCodeToError(EC);
+}
+#endif
   }
   FD = -1;
-
   return errorCodeToError(RenameEC);
 }
 
@@ -1270,16 +1285,21 @@
   Done = true;
 
 #ifdef _WIN32
-  auto H = reinterpret_cast(_get_osfhandle(FD));
+  auto H = (Handle) ? Handle : reinterpret_cast(_get_osfhandle(FD));
   if (std::error_code EC = setDeleteDisposition(H, false))
 return errorCodeToError(EC);
+
+  if (Handle && !::CloseHandle(Handle)) {
+std::error_code EC = mapWindowsError(::GetLastError());
+return errorCodeToError(EC);
+  }
 #else
   sys::DontRemoveFileOnSignal(TmpName);
 #endif
 
   TmpName = "";
 
-  if (close(FD) == -1) {
+  if (!Handle && close(FD) == -1) {
 std::error_code EC(errno, std::generic_category());
 return errorCodeToError(EC);
   }
@@ -1295,14 +1315,25 @@
   createUniqueFile(Model, FD, ResultPath, OF_Delete, Mode))
 return errorCodeToError(EC);
 
-  TempFile Ret(ResultPath, 

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

2021-05-20 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 346856.
mstorsjo added a comment.

Updated to allow mismatches and just picking the value that is set last on the 
command line - what do you think of this version?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/arm-target-as-mimplicit-it.s

Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -10,22 +10,23 @@
 // RUN: %clang -target arm-linux-gnueabi -### -Xassembler -mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
 // RUN: %clang -target arm-linux-gnueabi -### -Xassembler -mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
 /// Test space separated -Wa,- arguments (latter wins).
+// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -Wa,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=never %s 2>&1 | FileCheck %s --check-prefix=NEVER
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
 /// Test comma separated -Wa,- arguments (latter wins).
+// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=never %s 2>&1 | FileCheck %s --check-prefix=NEVER
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
 
-/// Mix -implicit-it= (compiler) with -Wa,-mimplicit-it= (assembler), assembler
-/// takes priority. -mllvm -arm-implicit-it= will be repeated, with the
-/// assembler flag appearing last (latter wins).
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=never -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=NEVER_ALWAYS
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=always -Wa,-mimplicit-it=never %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
-// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
+/// Mix -implicit-it= (compiler) with -Wa,-mimplicit-it= (assembler), the
+/// last one set takes priority.
+// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=always -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS
+// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=never -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS
+// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS
 
 /// Test invalid input.
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
@@ -34,11 +35,15 @@
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
 
 
+/// Check that there isn't a second -arm-implicit-it before or after the one
+/// that was the indended match.
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
 // ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
+// NEVER-NOT: "-arm-implicit-it={{.*}}"
 // NEVER: "-mllvm" "-arm-implicit-it=never"
+// NEVER-NOT: "-arm-implicit-it={{.*}}"
 // ARM: "-mllvm" "-arm-implicit-it=arm"
 // THUMB: "-mllvm" "-arm-implicit-it=thumb"
-// NEVER_ALWAYS: "-mllvm" "-arm-implicit-it=never" "-mllvm" "-arm-implicit-it=always"
-// ALWAYS_NEVER: "-mllvm" "-arm-implicit-it=always" "-mllvm" "-arm-implicit-it=never"
 // INVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Wa,'
 // XINVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Xassembler'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2366,15 

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

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

In D102812#2770821 , @DavidSpickett 
wrote:

> Given that using both options currently crashes clang (therefore no one is 
> relying on this yet) and GCC doesn't have `-mimplicit-it` I think what you 
> have is actually the best way to go. If the two options agree, fine, if they 
> don't, error. Let's not make it more complicated than it has to be.

Well it's complicated in the sense that there is an error diagnostic that we 
need to provide, and all that. Just picking the last set value should be fine 
too and simplifies the code in that sense.

I'll update the patch with the code in that form, and let you say what you 
think of that form. If you think we should keep the error though, I'll add it 
back (and see if I need to add a new diagnostic id for that case, to get a 
proper error mesasge). It's a bit inconsistent in the sense that one can pass 
multiple conflicting options via each of the options (where the last one of 
each wins); gas does handle it in that way too, but two different kinds of 
options error out instead.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2369
 
-static bool AddARMImplicitITArgs(const ArgList , ArgStringList ,
+static bool CheckARMImplicitITArg(StringRef Value) {
+  return Value == "always" || Value == "never" || Value == "arm" ||

MaskRay wrote:
> Use `functionName` for new functions.
Hmm, the whole rest of the file uses function names starting with a capital, so 
they do look a bit out of place if adding one new that differs...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102875: [PowerPC] Add PowerPC compare and multiply related builtins and instrinsics for XL compatibility

2021-05-20 Thread Victor Huang via Phabricator via cfe-commits
NeHuang created this revision.
Herald added subscribers: shchenz, kbarton, hiraditya, nemanjai.
NeHuang requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This is patch is in a series of patches to provide builtins for compatibility
with the XL compiler. This patch adds the builtins and instrisics for compare
and multiply related operations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102875

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-compare-64bit-only.c
  clang/test/CodeGen/builtins-ppc-xlcompat-compare.c
  clang/test/CodeGen/builtins-ppc-xlcompat-multiply-64bit-only.c
  clang/test/CodeGen/builtins-ppc-xlcompat-multiply.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-compare-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-compare.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply.ll
@@ -0,0 +1,52 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpcle-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s --check-prefix=CHECK-32
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s --check-prefix=CHECK-32
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s --check-prefix=CHECK-64
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s --check-prefix=CHECK-64
+
+; Function Attrs: noinline nounwind optnone
+define dso_local signext i32 @test_builtin_ppc_mulhw(i32 %a, i32%b) #0 {
+; CHECK-32-LABEL: test_builtin_ppc_mulhw:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:mulhw r3, r3, r4
+; CHECK-32-NEXT:blr
+;
+; CHECK-64-LABEL: test_builtin_ppc_mulhw:
+; CHECK-64:   # %bb.0: # %entry
+; CHECK-64-NEXT:mulhw r3, r3, r4
+; CHECK-64-NEXT:extsw r3, r3
+; CHECK-64-NEXT:blr
+entry:
+  %0 = call i32 @llvm.ppc.mulhw(i32 %a, i32 %b)
+  ret i32 %0
+}
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.ppc.mulhw(i32, i32) #1
+
+; Function Attrs: noinline nounwind optnone
+define dso_local zeroext i32 @test_builtin_ppc_mulhwu(i32 %a, i32%b) #0 {
+; CHECK-32-LABEL: test_builtin_ppc_mulhwu:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:mulhwu r3, r3, r4
+; CHECK-32-NEXT:blr
+;
+; CHECK-64-LABEL: test_builtin_ppc_mulhwu:
+; CHECK-64:   # %bb.0: # %entry
+; CHECK-64-NEXT:mulhwu r3, r3, r4
+; CHECK-64-NEXT:clrldi r3, r3, 32
+; CHECK-64-NEXT:blr
+entry:
+  %0 = call i32 @llvm.ppc.mulhwu(i32 %a, i32 %b)
+  ret i32 %0
+}
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.ppc.mulhwu(i32, i32) #1
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="pwr9" "target-features"="+altivec,+bpermd,+crypto,+direct-move,+extdiv,+htm,+power8-vector,+power9-vector,+vsx,-privileged,-rop-protect,-spe" }
+attributes #1 = { nounwind readnone }
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply-64bit-only.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-multiply-64bit-only.ll
@@ -0,0 +1,80 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | FileCheck %s
+
+; Function Attrs: noinline nounwind optnone
+define dso_local i64 @test_builtin_ppc_mulhd(i64 %a, i64 %b) #0 {
+; CHECK-LABEL: test_builtin_ppc_mulhd:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mulhd r3, r3, r4
+; CHECK-NEXT:blr
+entry:
+  %0 = call i64 @llvm.ppc.mulhd(i64 %a, i64 %b)
+  ret i64 %0
+}
+
+; Function Attrs: nounwind readnone
+declare i64 @llvm.ppc.mulhd(i64, i64) #1
+
+; Function Attrs: noinline nounwind optnone
+define dso_local i64 @test_builtin_ppc_mulhdu(i64 %a, i64 %b) #0 {
+; CHECK-LABEL: 

[PATCH] D102820: [Clang] Check for returns_nonnull when deciding to add allocation null checks

2021-05-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Sounds reasonable to me! Can you double check whether this attribute gets 
correctly serialized/deserialized in face of `CXXNewExpr`? An example of how to 
test that would be in `clang/test/PCH/cxx-method.cpp`.


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

https://reviews.llvm.org/D102820

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 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 with minor comments; thanks!




Comment at: llvm/include/llvm/MC/MCAsmInfo.h:268-270
+  /// This directive allows emission of an ascii string without the standard C
+  /// escape characters embedded into it.  If a target doesn't support this, it
+  /// can be set to null. Defaults to null.

See suggested edit. Emphasizing the difference from `.ascii` by starting with 
its associated comment is nice. Need to indicate that this is the 
zero-terminated case though.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1012-1014
+  if (isPrint(Data.back()) || Data.back() == 0)
+return true;
+  return false;

Minor comment: Can just return the expression instead of using it for 
`if`/`else`.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1128
+   isPrintableString(Data)) {
+  // For target with DoubleQuteString constants, .string and .byte are used
+  // as replacement of .asciz and .ascii.

Minor nit: typo.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1139-1140
+Data = Data.substr(0, Data.size() - 1);
+  } else
+OS << MAI->getByteListDirective();
 } else if (MAI->getByteListDirective()) {

The style guide was clarified some time ago to indicate that mixing use/non-use 
of braces in an `if`/`else` chain is discouraged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

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


[clang] 4cb4256 - [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-05-20T17:04:29-04:00
New Revision: 4cb42564ec4b56ef7eb4758bfa4ddf844a163687

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

LOG: [CUDA][HIP] Fix device variables used by host

variables emitted on both host and device side with different addresses
when ODR-used by host function should not cause device side counter-part
to be force emitted.

This fixes the regression caused by https://reviews.llvm.org/D102237

Reviewed by: Artem Belevich

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

Added: 
clang/test/AST/ast-dump-constant-var.cu

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenCUDA/host-used-device-var.cu
clang/test/SemaCUDA/static-device-var.cu

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9c459a95a6916..114ff6441b4a8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12066,6 +12066,15 @@ class Sema final {
 bool IgnoreImplicitHDAttr = false);
   CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView );
 
+  enum CUDAVariableTarget {
+CVT_Device,  /// Emitted on device side with a shadow variable on host side
+CVT_Host,/// Emitted on host side only
+CVT_Both,/// Emitted on both sides with 
diff erent addresses
+CVT_Unified, /// Emitted as a unified address, e.g. managed variables
+  };
+  /// Determines whether the given variable is emitted on host or device side.
+  CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D);
+
   /// Gets the CUDA target for the current context.
   CUDAFunctionTarget CurrentCUDATarget() {
 return IdentifyCUDATarget(dyn_cast(CurContext));

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8131b5285075c..27a93c243eca0 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -644,7 +644,9 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
 Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
   }
 
-  if (getLangOpts().HIP) {
+  assert(!getLangOpts().CUDA || !getLangOpts().CUDAIsDevice ||
+ getLangOpts().GPUAllowDeviceInit);
+  if (getLangOpts().HIP && getLangOpts().CUDAIsDevice) {
 Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
 Fn->addFnAttr("device-init");
   }

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 03920982ee086..8d1b2ea5d5228 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2368,6 +2368,8 @@ void CodeGenModule::EmitDeferred() {
   }
 
   // Emit CUDA/HIP static device variables referenced by host code only.
+  // Note we should not clear CUDADeviceVarODRUsedByHost since it is still
+  // needed for further handling.
   if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
 for (const auto *V : getContext().CUDADeviceVarODRUsedByHost)
   DeferredDeclsToEmit.push_back(V);

diff  --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index b907374b466f3..8f9800767f896 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -26,6 +26,14 @@
 #include "llvm/ADT/SmallVector.h"
 using namespace clang;
 
+template  static bool hasExplicitAttr(const VarDecl *D) {
+  if (!D)
+return false;
+  if (auto *A = D->getAttr())
+return !A->isImplicit();
+  return false;
+}
+
 void Sema::PushForceCUDAHostDevice() {
   assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
   ForceCUDAHostDeviceDepth++;
@@ -133,6 +141,35 @@ Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const 
FunctionDecl *D,
   return CFT_Host;
 }
 
+/// IdentifyTarget - Determine the CUDA compilation target for this variable.
+Sema::CUDAVariableTarget Sema::IdentifyCUDATarget(const VarDecl *Var) {
+  if (Var->hasAttr())
+return CVT_Unified;
+  if (Var->isConstexpr() && !hasExplicitAttr(Var))
+return CVT_Both;
+  if (Var->hasAttr() || Var->hasAttr() ||
+  Var->hasAttr() ||
+  Var->getType()->isCUDADeviceBuiltinSurfaceType() ||
+  Var->getType()->isCUDADeviceBuiltinTextureType())
+return CVT_Device;
+  // Function-scope static variable without explicit device or constant
+  // attribute are emitted
+  //  - on both sides in host device functions
+  //  - on device side in device or global functions
+  if (auto *FD = dyn_cast(Var->getDeclContext())) {
+switch (IdentifyCUDATarget(FD)) {
+case CFT_HostDevice:
+  return CVT_Both;
+case CFT_Device:
+case CFT_Global:
+  return CVT_Device;

[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu 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 rG4cb42564ec4b: [CUDA][HIP] Fix device variables used by host 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D102801?vs=346831=346851#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102801

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-constant-var.cu
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -1,16 +1,14 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev,com
 
-// RUN: %clang_cc1 -triple x86_64-gnu-linux \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host,com
 
 // Checks allowed usage of file-scope and function-scope static variables.
 
-// host-no-diagnostics
-
 #include "Inputs/cuda.h"
 
 // Checks static variables are allowed in device functions.
@@ -42,6 +40,28 @@
   // dev-error@-1 {{reference to __host__ variable 'z' in __global__ function}}
 }
 
+// Check dynamic initialization of static device variable is not allowed.
+
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+class B {
+public:
+  __device__ B(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ B var2(c);
+// com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+(void) var1;
+(void) var2;
+  };
+}
+}
+
 int* getDeviceSymbol(int *x);
 
 void foo() {
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -66,30 +66,148 @@
 template 
 __device__ func_t p_add_func = add_func;
 
+// Check non-constant constexpr variables ODR-used by host code only is not emitted.
+// DEV-NEG-NOT: constexpr_var1a
+// DEV-NEG-NOT: constexpr_var1b
+constexpr int constexpr_var1a = 1;
+inline constexpr int constexpr_var1b = 1;
+
+// Check constant constexpr variables ODR-used by host code only.
+// Non-inline constexpr variable has internal linkage, therefore it is not accessible by host and not kept.
+// Inline constexpr variable has linkonce_ord linkage, therefore it can be accessed by host and kept.
+// DEV-NEG-NOT: constexpr_var2a
+// DEV-DAG: @constexpr_var2b = linkonce_odr addrspace(4) externally_initialized constant i32 2
+__constant__ constexpr int constexpr_var2a = 2;
+inline __constant__ constexpr int constexpr_var2b = 2;
+
 void use(func_t p);
-void use(int *p);
+__host__ __device__ void use(const int *p);
 
+// Check static device variable in host function.
+// DEV-DAG:  @_ZZ4fun1vE11static_var1 = addrspace(1) externally_initialized global i32 3
 void fun1() {
+  static __device__ int static_var1 = 3;
   use();
   use();
   use();
   use(_var);
   use(_var);
   use(p_add_func);
+  use(_var1a);
+  use(_var1b);
+  use(_var2a);
+  use(_var2b);
+  use(_var1);
+}
+
+// Check static variable in host device function.
+// DEV-DAG:  @_ZZ4fun2vE11static_var2 = internal addrspace(1) global i32 4
+// DEV-DAG:  @_ZZ4fun2vE11static_var3 = addrspace(1) global i32 4
+__host__ __device__ void fun2() {
+  static int static_var2 = 4;
+  static __device__ int static_var3 = 4;
+  use(_var2);
+  use(_var3);
 }
 
 __global__ void kern1(int **x) {
   *x = 
+  fun2();
+}
+
+// Check static variables of lambda functions.
+
+// Lambda functions are implicit host device functions.
+// Default static variables in lambda functions should be treated
+// as host variables on host side, therefore should not be forced
+// to be emitted on device.
+
+// DEV-DAG: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var2 = addrspace(1) externally_initialized global i32 5
+// DEV-NEG-NOT: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var1
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ int var2 = 5;
+(void) var1;
+(void) var2;
+  };
+}
+}
+
+// 

[PATCH] D102873: [clang] [MinGW] Fix gcc version detection/picking

2021-05-20 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 346850.
mstorsjo added a comment.

Update another affected testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102873

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include-fixed/.keep
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include/c++/backward/.keep
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include/c++/x86_64-w64-mingw32/.keep
  clang/test/Driver/mingw-sysroot.cpp
  clang/test/Driver/mingw.cpp


Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -52,9 +52,9 @@
 
 
 // RUN: %clang -target x86_64-pc-windows-gnu -rtlib=platform -stdlib=libstdc++ 
-c -### --sysroot=%S/Inputs/mingw_ubuntu_posix_tree/usr %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_UBUNTU_POSIX_TREE %s
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 // RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_NO_UNICODE %s
Index: clang/test/Driver/mingw-sysroot.cpp
===
--- clang/test/Driver/mingw-sysroot.cpp
+++ clang/test/Driver/mingw-sysroot.cpp
@@ -18,9 +18,9 @@
 // sysroot:
 
 // RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %clang -target 
x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 
2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
-// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++"
-// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
-// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
+// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++"
+// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
+// CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_TESTROOT_GCC: 
"{{.*}}/testroot-gcc{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -338,6 +338,7 @@
   continue;
 if (CandidateVersion <= Version)
   continue;
+Version = CandidateVersion;
 Ver = std::string(VersionText);
 GccLibDir = LI->path();
   }


Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -52,9 +52,9 @@
 
 
 // RUN: %clang -target x86_64-pc-windows-gnu -rtlib=platform -stdlib=libstdc++ -c -### --sysroot=%S/Inputs/mingw_ubuntu_posix_tree/usr %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UBUNTU_POSIX_TREE %s
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-20 Thread Min-Yih Hsu 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 rGdccf5c7dfb9e: [M68k] Support for inline asm operands w/ 
simple constraints (authored by myhsu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102585

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/test/Sema/inline-asm-validate-m68k.c
  llvm/lib/Target/M68k/M68kAsmPrinter.cpp
  llvm/lib/Target/M68k/M68kAsmPrinter.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp
  llvm/lib/Target/M68k/M68kISelLowering.h
  llvm/test/CodeGen/M68k/inline-asm.ll

Index: llvm/test/CodeGen/M68k/inline-asm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/inline-asm.ll
@@ -0,0 +1,122 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=m68k < %s -o - | FileCheck %s
+
+; This function is primarily testing constant constraints that can NOT
+; be easily checked by Clang. For example, 'K' and 'M' are both
+; constraints for values that are outside certain numerical range.
+define void @constant_constraints() {
+; CHECK-LABEL: constant_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32767, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-129, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #128, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-257, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #256, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #24, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #31, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #16, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #8, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #15, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #0, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #1, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #-32769, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #32768, %d1
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:rts
+entry:
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "I"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 -32768)
+  call void asm sideeffect "move.l $0, %d1", "J"(i32 32767)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 -129)
+  call void asm sideeffect "move.l $0, %d1", "K"(i32 128)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -8)
+  call void asm sideeffect "move.l $0, %d1", "L"(i32 -1)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 -257)
+  call void asm sideeffect "move.l $0, %d1", "M"(i32 256)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 24)
+  call void asm sideeffect "move.l $0, %d1", "N"(i32 31)
+  call void asm sideeffect "move.l $0, %d1", "O"(i32 16)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 8)
+  call void asm sideeffect "move.l $0, %d1", "P"(i32 15)
+  call void asm sideeffect "move.l $0, %d1", "^C0"(i32 0)
+  call void asm sideeffect "move.l $0, %d1", "^Ci"(i32 1)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void
+}
+
+define void @register_constraints() {
+; CHECK-LABEL: register_constraints:
+; CHECK: .cfi_startproc
+; CHECK-NEXT:  ; %bb.0: ; %entry
+; CHECK-NEXT:sub.l #4, %sp
+; CHECK-NEXT:.cfi_def_cfa_offset -8
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #94, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #87, %d0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %d0, (0,%sp)
+; CHECK-NEXT:;APP
+; CHECK-NEXT:move.l #66, %a0
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:move.l %a0, (0,%sp)
+; CHECK-NEXT:add.l #4, %sp
+; CHECK-NEXT:rts
+entry:
+  %out = alloca i32, align 4
+  %0 = call i32 asm sideeffect "move.l #94, $0", "=r"()
+  store i32 %0, i32* %out, align 4
+  %1 = call i32 asm sideeffect "move.l #87, $0", "=d"()
+  store i32 %1, i32* %out, 

[clang] dccf5c7 - [M68k] Support for inline asm operands w/ simple constraints

2021-05-20 Thread Min-Yih Hsu via cfe-commits

Author: Min-Yih Hsu
Date: 2021-05-20T14:00:09-07:00
New Revision: dccf5c7dfb9e68f8750947f5c10ad3227cd92b50

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

LOG: [M68k] Support for inline asm operands w/ simple constraints

This patch adds supports for inline assembly operands and some simple
operand constraints, including register and constant operands.

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

Added: 
clang/test/Sema/inline-asm-validate-m68k.c
llvm/test/CodeGen/M68k/inline-asm.ll

Modified: 
clang/lib/Basic/Targets/M68k.cpp
clang/lib/Basic/Targets/M68k.h
llvm/lib/Target/M68k/M68kAsmPrinter.cpp
llvm/lib/Target/M68k/M68kAsmPrinter.h
llvm/lib/Target/M68k/M68kISelLowering.cpp
llvm/lib/Target/M68k/M68kISelLowering.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/M68k.cpp 
b/clang/lib/Basic/Targets/M68k.cpp
index 8e8a69f75c8b0..9fcd58ee6401a 100644
--- a/clang/lib/Basic/Targets/M68k.cpp
+++ b/clang/lib/Basic/Targets/M68k.cpp
@@ -18,7 +18,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/TargetParser.h"
+#include 
 #include 
+#include 
 
 namespace clang {
 namespace targets {
@@ -142,18 +144,61 @@ bool M68kTargetInfo::validateAsmConstraint(
   switch (*Name) {
   case 'a': // address register
   case 'd': // data register
-  case 'f': // floating point register
 info.setAllowsRegister();
 return true;
-  case 'K': // the constant 1
-  case 'L': // constant -1^20 .. 1^19
-  case 'M': // constant 1-4:
+  case 'I': // constant integer in the range [1,8]
+info.setRequiresImmediate(1, 8);
 return true;
+  case 'J': // constant signed 16-bit integer
+info.setRequiresImmediate(std::numeric_limits::min(),
+  std::numeric_limits::max());
+return true;
+  case 'K': // constant that is NOT in the range of [-0x80, 0x80)
+info.setRequiresImmediate();
+return true;
+  case 'L': // constant integer in the range [-8,-1]
+info.setRequiresImmediate(-8, -1);
+return true;
+  case 'M': // constant that is NOT in the range of [-0x100, 0x100]
+info.setRequiresImmediate();
+return true;
+  case 'N': // constant integer in the range [24,31]
+info.setRequiresImmediate(24, 31);
+return true;
+  case 'O': // constant integer 16
+info.setRequiresImmediate(16);
+return true;
+  case 'P': // constant integer in the range [8,15]
+info.setRequiresImmediate(8, 15);
+return true;
+  case 'C':
+++Name;
+switch (*Name) {
+case '0': // constant integer 0
+  info.setRequiresImmediate(0);
+  return true;
+case 'i': // constant integer
+case 'j': // integer constant that doesn't fit in 16 bits
+  info.setRequiresImmediate();
+  return true;
+default:
+  break;
+}
+break;
+  default:
+break;
   }
-  // FIXME: Support all constraints like 'N', 'O', 'P', 'R'
   return false;
 }
 
+std::string M68kTargetInfo::convertConstraint(const char *) const {
+  if (*Constraint == 'C')
+// Two-character constraint; add "^" hint for later parsing
+return std::string("^") + std::string(Constraint++, 2);
+
+  return std::string(1, *Constraint);
+}
+
 const char *M68kTargetInfo::getClobbers() const {
   // FIXME: Is this really right?
   return "";

diff  --git a/clang/lib/Basic/Targets/M68k.h b/clang/lib/Basic/Targets/M68k.h
index db001be76c65f..be2462bbd7acd 100644
--- a/clang/lib/Basic/Targets/M68k.h
+++ b/clang/lib/Basic/Targets/M68k.h
@@ -44,6 +44,7 @@ class LLVM_LIBRARY_VISIBILITY M68kTargetInfo : public 
TargetInfo {
   bool hasFeature(StringRef Feature) const override;
   ArrayRef getGCCRegNames() const override;
   ArrayRef getGCCRegAliases() const override;
+  std::string convertConstraint(const char *) const override;
   bool validateAsmConstraint(const char *,
  TargetInfo::ConstraintInfo ) const override;
   const char *getClobbers() const override;

diff  --git a/clang/test/Sema/inline-asm-validate-m68k.c 
b/clang/test/Sema/inline-asm-validate-m68k.c
new file mode 100644
index 0..a0b75304eba00
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-m68k.c
@@ -0,0 +1,86 @@
+// REQUIRES: m68k-registered-target
+// RUN: %clang_cc1 -triple m68k -fsyntax-only -verify %s -DINVALID
+// RUN: %clang_cc1 -triple m68k -fsyntax-only -verify %s
+
+#ifdef INVALID
+
+// Invalid constraint usages that can be blocked by frontend
+
+void I() {
+  static const int BelowMin = 0;
+  static const int AboveMax = 9;
+  asm ("" :: "I"(BelowMin)); // expected-error{{value '0' out of range for 
constraint 'I'}}
+  asm ("" :: "I"(AboveMax)); // expected-error{{value '9' out of range for 
constraint 'I'}}
+}
+
+void J() {
+  static const int BelowMin = -0x8001;

[PATCH] D102805: [M68k] Allow user to preserve certain registers

2021-05-20 Thread Min-Yih Hsu 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 rGe620bea21199: [M68k] Allow user to preserve certain 
registers (authored by myhsu).

Changed prior to commit:
  https://reviews.llvm.org/D102805?vs=346627=346848#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102805

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/test/Driver/m68k-fixed-register.c
  llvm/lib/Target/M68k/M68k.td
  llvm/lib/Target/M68k/M68kRegisterInfo.cpp
  llvm/lib/Target/M68k/M68kSubtarget.cpp
  llvm/lib/Target/M68k/M68kSubtarget.h
  llvm/test/CodeGen/M68k/reserved-regs.ll

Index: llvm/test/CodeGen/M68k/reserved-regs.ll
===
--- /dev/null
+++ llvm/test/CodeGen/M68k/reserved-regs.ll
@@ -0,0 +1,70 @@
+; RUN: llc -mtriple=m68k -mattr="+reserve-a0" < %s | FileCheck --check-prefix=A0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a1" < %s | FileCheck --check-prefix=A1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a2" < %s | FileCheck --check-prefix=A2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a3" < %s | FileCheck --check-prefix=A3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a4" < %s | FileCheck --check-prefix=A4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a5" < %s | FileCheck --check-prefix=A5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-a6" < %s | FileCheck --check-prefix=A6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d0" < %s | FileCheck --check-prefix=D0 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d1" < %s | FileCheck --check-prefix=D1 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d2" < %s | FileCheck --check-prefix=D2 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d3" < %s | FileCheck --check-prefix=D3 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d4" < %s | FileCheck --check-prefix=D4 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d5" < %s | FileCheck --check-prefix=D5 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d6" < %s | FileCheck --check-prefix=D6 %s
+; RUN: llc -mtriple=m68k -mattr="+reserve-d7" < %s | FileCheck --check-prefix=D7 %s
+
+; Used to exhaust all registers
+;
+; A better way to do this might be:
+; ```
+; @var = global [16 x i32] zeroinitializer
+; ...
+; %tmp = load load volatile [16 x i32], [16 x i32]* @var
+; store volatile [16 x i32] %tmp, [16 x i32]* @var
+; ```
+; Which is copied from `test/CodeGen/RISCV/reserved-regs.ll`.
+; But currently we have problem doing codegen for the above snippet
+; (https://bugs.llvm.org/show_bug.cgi?id=50377).
+define void @foo(i32* nocapture readonly %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32* nocapture readonly %d,
+ i32* nocapture readonly %a1, i32* nocapture readonly %b1, i32* nocapture readonly %c1, i32* nocapture readonly %d1,
+ i32* nocapture readonly %a2, i32* nocapture readonly %b2, i32* nocapture readonly %c2, i32* nocapture readonly %d2,
+ i32* nocapture readonly %a3, i32* nocapture readonly %b3, i32* nocapture readonly %c3, i32* nocapture readonly %d3) {
+entry:
+  %0 = load i32, i32* %a, align 4
+  %1 = load i32, i32* %b, align 4
+  %2 = load i32, i32* %c, align 4
+  %3 = load i32, i32* %d, align 4
+  %4 = load i32, i32* %a1, align 4
+  %5 = load i32, i32* %b1, align 4
+  %6 = load i32, i32* %c1, align 4
+  %7 = load i32, i32* %d1, align 4
+  %8 = load i32, i32* %a2, align 4
+  %9 = load i32, i32* %b2, align 4
+  %10 = load i32, i32* %c2, align 4
+  %11 = load i32, i32* %d2, align 4
+  %12 = load i32, i32* %a3, align 4
+  %13 = load i32, i32* %b3, align 4
+  %14 = load i32, i32* %c3, align 4
+  %15 = load i32, i32* %d3, align 4
+  ; A0-NOT: %a0
+  ; A1-NOT: %a1
+  ; A2-NOT: %a2
+  ; A3-NOT: %a3
+  ; A4-NOT: %a4
+  ; A5-NOT: %a5
+  ; A6-NOT: %a6
+  ; D0-NOT: %d0
+  ; D1-NOT: %d1
+  ; D2-NOT: %d2
+  ; D3-NOT: %d3
+  ; D4-NOT: %d4
+  ; D5-NOT: %d5
+  ; D6-NOT: %d6
+  ; D7-NOT: %d7
+  tail call void @bar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, i32 %14, i32 %15)
+  ret void
+}
+
+declare void @bar(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)
+
Index: llvm/lib/Target/M68k/M68kSubtarget.h
===
--- llvm/lib/Target/M68k/M68kSubtarget.h
+++ llvm/lib/Target/M68k/M68kSubtarget.h
@@ -18,6 +18,7 @@
 #include "M68kISelLowering.h"
 #include "M68kInstrInfo.h"
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/DataLayout.h"
@@ -47,6 +48,8 @@
   enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };
   SubtargetEnum SubtargetKind = M00;
 
+  BitVector UserReservedRegister;
+
   InstrItineraryData InstrItins;
 
   /// Small section is used.
@@ -95,6 

[clang] e620bea - [M68k] Allow user to preserve certain registers

2021-05-20 Thread Min-Yih Hsu via cfe-commits

Author: Min-Yih Hsu
Date: 2021-05-20T13:57:22-07:00
New Revision: e620bea21199791513f3193a71b819b20a707ab1

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

LOG: [M68k] Allow user to preserve certain registers

Add `-ffixed-a[0-6]` and `-ffixed-d[0-7]` and the corresponding
subtarget features to prevent certain register from being allocated.

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

Added: 
clang/test/Driver/m68k-fixed-register.c
llvm/test/CodeGen/M68k/reserved-regs.ll

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Arch/M68k.cpp
llvm/lib/Target/M68k/M68k.td
llvm/lib/Target/M68k/M68kRegisterInfo.cpp
llvm/lib/Target/M68k/M68kSubtarget.cpp
llvm/lib/Target/M68k/M68kSubtarget.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1274f7a0af2e8..d45798c1d4043 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4010,6 +4010,13 @@ def m68030 : Flag<["-"], "m68030">, 
Group;
 def m68040 : Flag<["-"], "m68040">, Group;
 def m68060 : Flag<["-"], "m68060">, Group;
 
+foreach i = {0-6} in
+  def ffixed_a#i : Flag<["-"], "ffixed-a"#i>, Group,
+HelpText<"Reserve the a"#i#" register (M68k only)">;
+foreach i = {0-7} in
+  def ffixed_d#i : Flag<["-"], "ffixed-d"#i>, Group,
+HelpText<"Reserve the d"#i#" register (M68k only)">;
+
 // X86 feature flags
 def mx87 : Flag<["-"], "mx87">, Group;
 def mno_x87 : Flag<["-"], "mno-x87">, Group;

diff  --git a/clang/lib/Driver/ToolChains/Arch/M68k.cpp 
b/clang/lib/Driver/ToolChains/Arch/M68k.cpp
index 66c9f5c87bfbc..119e24cedbab4 100644
--- a/clang/lib/Driver/ToolChains/Arch/M68k.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/M68k.cpp
@@ -72,6 +72,38 @@ void m68k::getM68kTargetFeatures(const Driver , const 
llvm::Triple ,
   m68k::FloatABI FloatABI = m68k::getM68kFloatABI(D, Args);
   if (FloatABI == m68k::FloatABI::Soft)
 Features.push_back("-hard-float");
+
+  // Handle '-ffixed-' flags
+  if (Args.hasArg(options::OPT_ffixed_a0))
+Features.push_back("+reserve-a0");
+  if (Args.hasArg(options::OPT_ffixed_a1))
+Features.push_back("+reserve-a1");
+  if (Args.hasArg(options::OPT_ffixed_a2))
+Features.push_back("+reserve-a2");
+  if (Args.hasArg(options::OPT_ffixed_a3))
+Features.push_back("+reserve-a3");
+  if (Args.hasArg(options::OPT_ffixed_a4))
+Features.push_back("+reserve-a4");
+  if (Args.hasArg(options::OPT_ffixed_a5))
+Features.push_back("+reserve-a5");
+  if (Args.hasArg(options::OPT_ffixed_a6))
+Features.push_back("+reserve-a6");
+  if (Args.hasArg(options::OPT_ffixed_d0))
+Features.push_back("+reserve-d0");
+  if (Args.hasArg(options::OPT_ffixed_d1))
+Features.push_back("+reserve-d1");
+  if (Args.hasArg(options::OPT_ffixed_d2))
+Features.push_back("+reserve-d2");
+  if (Args.hasArg(options::OPT_ffixed_d3))
+Features.push_back("+reserve-d3");
+  if (Args.hasArg(options::OPT_ffixed_d4))
+Features.push_back("+reserve-d4");
+  if (Args.hasArg(options::OPT_ffixed_d5))
+Features.push_back("+reserve-d5");
+  if (Args.hasArg(options::OPT_ffixed_d6))
+Features.push_back("+reserve-d6");
+  if (Args.hasArg(options::OPT_ffixed_d7))
+Features.push_back("+reserve-d7");
 }
 
 m68k::FloatABI m68k::getM68kFloatABI(const Driver , const ArgList ) {

diff  --git a/clang/test/Driver/m68k-fixed-register.c 
b/clang/test/Driver/m68k-fixed-register.c
new file mode 100644
index 0..0ee9edcfd1647
--- /dev/null
+++ b/clang/test/Driver/m68k-fixed-register.c
@@ -0,0 +1,61 @@
+// REQUIRES: m68k-registered-target
+// RUN: %clang -target m68k -ffixed-a0 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A0 < %t %s
+// CHECK-FIXED-A0: "-target-feature" "+reserve-a0"
+
+// RUN: %clang -target m68k -ffixed-a1 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A1 < %t %s
+// CHECK-FIXED-A1: "-target-feature" "+reserve-a1"
+
+// RUN: %clang -target m68k -ffixed-a2 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A2 < %t %s
+// CHECK-FIXED-A2: "-target-feature" "+reserve-a2"
+
+// RUN: %clang -target m68k -ffixed-a3 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A3 < %t %s
+// CHECK-FIXED-A3: "-target-feature" "+reserve-a3"
+
+// RUN: %clang -target m68k -ffixed-a4 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A4 < %t %s
+// CHECK-FIXED-A4: "-target-feature" "+reserve-a4"
+
+// RUN: %clang -target m68k -ffixed-a5 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A5 < %t %s
+// CHECK-FIXED-A5: "-target-feature" "+reserve-a5"
+
+// RUN: %clang -target m68k -ffixed-a6 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIXED-A6 < %t %s
+// CHECK-FIXED-A6: 

[PATCH] D102873: [clang] [MinGW] Fix gcc version detection/picking

2021-05-20 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added a reviewer: rnk.
mstorsjo requested review of this revision.
Herald added a project: clang.

Actually compare each version to the version of the last chosen one.

There's no guarantee that the added test case does showcase the
previous issue (it depends on the order that directory entries
are returned when iterating), but with the issue fixed it should behave
deterministically in any case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102873

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include-fixed/.keep
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include/c++/backward/.keep
  
clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/10.2-posix/include/c++/x86_64-w64-mingw32/.keep
  clang/test/Driver/mingw.cpp


Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -52,9 +52,9 @@
 
 
 // RUN: %clang -target x86_64-pc-windows-gnu -rtlib=platform -stdlib=libstdc++ 
-c -### --sysroot=%S/Inputs/mingw_ubuntu_posix_tree/usr %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_UBUNTU_POSIX_TREE %s
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 // RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_NO_UNICODE %s
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -338,6 +338,7 @@
   continue;
 if (CandidateVersion <= Version)
   continue;
+Version = CandidateVersion;
 Ver = std::string(VersionText);
 GccLibDir = LI->path();
   }


Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -52,9 +52,9 @@
 
 
 // RUN: %clang -target x86_64-pc-windows-gnu -rtlib=platform -stdlib=libstdc++ -c -### --sysroot=%S/Inputs/mingw_ubuntu_posix_tree/usr %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UBUNTU_POSIX_TREE %s
-// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
-// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
+// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}10.2-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 // RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s

[PATCH] D102820: [Clang] Check for returns_nonnull when deciding to add allocation null checks

2021-05-20 Thread Di Mo via Phabricator via cfe-commits
modimo added a subscriber: urnathan.
modimo added a comment.

Discussing with @urnathan this makes more sense for the BE to handle when 
optimizing by eliding the generated null check. Confirmed this is indeed the 
case so removing the generation in the FE isn't really needed.


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

https://reviews.llvm.org/D102820

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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D101793#2772033 , @weiwang wrote:

> In D101793#2772021 , @yaxunl wrote:
>
>> In D101793#2769297 , @weiwang 
>> wrote:
>>
>>> Tried to make `Sema::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`. 
>>> The heap RSS did drop significantly (from peak 100GB to 59GB) , but not as 
>>> good as the current fix (peak 26GB), which makes 
>>> `ASTReader::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`.
>>>
>>> I think the reason is that the duplicated decls are read from multiple 
>>> module file sources (`ASTReader::ReadAST()` -> 
>>> `ASTReader::ReadASTBlock()`), then stored into 
>>> `ASTReader::DeclsToCheckForDeferredDiags`, then goes into 
>>> `Sema::DeclsToCheckForDeferredDiags` in 
>>> `ASTReader::ReadDeclsToCheckForDeferredDiags()`. Doing dedup at the early 
>>> stage when the decls were just read in `ASTReader` is more effective at 
>>> reducing RSS.
>>
>> What if you use SmallSetVector for both Sema::DeclsToCheckForDeferredDiags 
>> and ASTReader::DeclsToCheckForDeferredDiags? Does it cause extra memory 
>> usage compared to using it only for ASTReader::DeclsToCheckForDeferredDiags? 
>> Thanks.
>
> There would be a slight increase in memory usage since SmallSetVector 
> requires more memory than just SmallVector internally, but given the majority 
> the RSS comes from duplicated decls, I don't think it's an issue by making 
> both SmallSetVector. If you think it's better to change both, I'll update the 
> diff.

Let's use SmallSetVector for both. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

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

I've verified that Tensorflow still builds with this patch and that the patch 
does fix the regressions we've seen.
If you could land this patch soon, that would be appreciated.


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

https://reviews.llvm.org/D102801

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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang via Phabricator via cfe-commits
weiwang added a comment.

In D101793#2772021 , @yaxunl wrote:

> In D101793#2769297 , @weiwang wrote:
>
>> Tried to make `Sema::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`. 
>> The heap RSS did drop significantly (from peak 100GB to 59GB) , but not as 
>> good as the current fix (peak 26GB), which makes 
>> `ASTReader::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`.
>>
>> I think the reason is that the duplicated decls are read from multiple 
>> module file sources (`ASTReader::ReadAST()` -> `ASTReader::ReadASTBlock()`), 
>> then stored into `ASTReader::DeclsToCheckForDeferredDiags`, then goes into 
>> `Sema::DeclsToCheckForDeferredDiags` in 
>> `ASTReader::ReadDeclsToCheckForDeferredDiags()`. Doing dedup at the early 
>> stage when the decls were just read in `ASTReader` is more effective at 
>> reducing RSS.
>
> What if you use SmallSetVector for both Sema::DeclsToCheckForDeferredDiags 
> and ASTReader::DeclsToCheckForDeferredDiags? Does it cause extra memory usage 
> compared to using it only for ASTReader::DeclsToCheckForDeferredDiags? Thanks.

There would be a slight increase in memory usage since SmallSetVector requires 
more memory than just SmallVector internally, but given the majority the RSS 
comes from duplicated decls, I don't think it's an issue by making both 
SmallSetVector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D102863: [analyzer] RetainCountChecker: Disable tracking for references to OSMetaClass.

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna updated this revision to Diff 346838.
georgi_igna added a comment.

some files were missing in the previous patch


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

https://reviews.llvm.org/D102863

Files:
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/test/Analysis/os_object_base.h
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -721,6 +721,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 class SampleClass {
 public:
   OSObjectPtr field;
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,7 +67,13 @@
 
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
+
   static OSObject * allocClassWithName(const char * name);
+
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+
+  void releaseMetaClass() const;
+
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,14 +146,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -721,6 +721,16 @@
   obj->release();
 }
 
+void test_osmetaclass_release(){
+const char *name = "no_name";
+const OSMetaClass *meta = OSMetaClass::copyMetaClassWithName(name);
+if (!meta) {
+return;
+} else {
+meta->releaseMetaClass();
+}
+}
+
 class SampleClass {
 public:
   OSObjectPtr field;
Index: clang/test/Analysis/os_object_base.h
===
--- clang/test/Analysis/os_object_base.h
+++ clang/test/Analysis/os_object_base.h
@@ -67,7 +67,13 @@
 
 struct OSMetaClass : public OSMetaClassBase {
   virtual OSObject * alloc() const;
+
   static OSObject * allocClassWithName(const char * name);
+
+  static const OSMetaClass * copyMetaClassWithName(const char * name);
+
+  void releaseMetaClass() const;
+
   virtual ~OSMetaClass(){}
 };
 
Index: clang/lib/Analysis/RetainSummaryManager.cpp
===
--- clang/lib/Analysis/RetainSummaryManager.cpp
+++ clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,14 +146,20 @@
   return !(match(SubclassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+static bool isExactClass(const Decl *D, StringRef ClassName) {
+  using namespace ast_matchers;
+  DeclarationMatcher sameClassM =
+  cxxRecordDecl(hasName(std::string(ClassName)));
+  return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 
-static bool isOSObjectDynamicCast(StringRef S) {
-  return S == "safeMetaCast";
+static bool isOSObjectSubclass(const Decl *D) {
+  return D && isSubclass(D, "OSMetaClassBase") &&
+ !isExactClass(D, "OSMetaClass");
 }
 
+static bool isOSObjectDynamicCast(StringRef S) { return S == "safeMetaCast"; }
+
 static bool isOSObjectRequiredCast(StringRef S) {
   return S == "requiredMetaCast";
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D101793#2769297 , @weiwang wrote:

> Tried to make `Sema::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`. 
> The heap RSS did drop significantly (from peak 100GB to 59GB) , but not as 
> good as the current fix (peak 26GB), which makes 
> `ASTReader::DeclsToCheckForDeferredDiags` `llvm::SmallSetVector`.
>
> I think the reason is that the duplicated decls are read from multiple module 
> file sources (`ASTReader::ReadAST()` -> `ASTReader::ReadASTBlock()`), then 
> stored into `ASTReader::DeclsToCheckForDeferredDiags`, then goes into 
> `Sema::DeclsToCheckForDeferredDiags` in 
> `ASTReader::ReadDeclsToCheckForDeferredDiags()`. Doing dedup at the early 
> stage when the decls were just read in `ASTReader` is more effective at 
> reducing RSS.

What if you use SmallSetVector for both Sema::DeclsToCheckForDeferredDiags and 
ASTReader::DeclsToCheckForDeferredDiags? Does it cause extra memory usage 
compared to using it only for ASTReader::DeclsToCheckForDeferredDiags? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3eb12b0ae11f: [WebAssembly] Warn on exception spec for 
Emscripten EH (authored by aheejin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp


Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-ON
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-OFF
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=NOT-WASM-EH
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=EM-EH-WARNING
 
 // Wasm EH ignores dynamic exception specifications with types at the moment.
 // This is controlled by -Wwasm-exception-spec, which is on by default. This
@@ -392,7 +392,7 @@
 // WARNING-DEFAULT: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-ON: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-OFF-NOT: warning: dynamic exception specifications with types are 
currently ignored in wasm
-// NOT-WASM-EH-NOT: warning: dynamic exception specifications with types are 
currently ignored in wasm
+// EM-EH-WARNING: warning: dynamic exception specifications with types are 
currently ignored in wasm
 
 // Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
 // same warning message is printed as if when a 'noexcept' function throws.
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -486,9 +486,9 @@
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
-// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. 
In
 // case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
+// TODO Correctly handle exception specification in Wasm EH
 if (CGM.getLangOpts().hasWasmExceptions()) {
   if (EST == EST_DynamicNone)
 EHStack.pushTerminate();
@@ -498,6 +498,19 @@
 << FD->getExceptionSpecSourceRange();
   return;
 }
+// Currently Emscripten EH only handles 'throw()' but not 'throw' with
+// types. 'throw()' handling will be done in JS glue code so we don't need
+// to do anything in that case. Just print a warning message in case of
+// throw with types.
+// TODO Correctly handle exception specification in Emscripten EH
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
+CGM.getLangOpts().getExceptionHandling() ==
+LangOptions::ExceptionHandlingKind::None &&
+EST == EST_Dynamic)
+  CGM.getDiags().Report(D->getLocation(),
+diag::warn_wasm_dynamic_exception_spec_ignored)
+  << FD->getExceptionSpecSourceRange();
+
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 


Index: clang/test/CodeGenCXX/wasm-eh.cpp
===
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
 

[clang] 3eb12b0 - [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2021-05-20T13:00:20-07:00
New Revision: 3eb12b0ae11fe23dc06e55e526fb45e460f72f1e

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

LOG: [WebAssembly] Warn on exception spec for Emscripten EH

It turns out we have not correctly supported exception spec all along in
Emscripten EH. Emscripten EH supports `throw()` but not `throw` with
types. See https://bugs.llvm.org/show_bug.cgi?id=50396.

Wasm EH also only supports `throw()` but not `throw` with types, and we
have been printing a warning message for the latter. This prints the
same warning message for `throw` with types when Emscripten EH is used,
or more precisely, when Wasm EH is not used. (So this will print the
warning messsage even when `-fno-exceptions` is used but I think that
should be fine. It's cumbersome to do a complilcated option checking in
CGException.cpp and options checkings are mostly done in elsewhere.)

Reviewed By: dschuff, kripken

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 2467922baf95e..9f65e9eb120cf 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -486,9 +486,9 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
   return;
-// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
+// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. 
In
 // case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
+// TODO Correctly handle exception specification in Wasm EH
 if (CGM.getLangOpts().hasWasmExceptions()) {
   if (EST == EST_DynamicNone)
 EHStack.pushTerminate();
@@ -498,6 +498,19 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 << FD->getExceptionSpecSourceRange();
   return;
 }
+// Currently Emscripten EH only handles 'throw()' but not 'throw' with
+// types. 'throw()' handling will be done in JS glue code so we don't need
+// to do anything in that case. Just print a warning message in case of
+// throw with types.
+// TODO Correctly handle exception specification in Emscripten EH
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
+CGM.getLangOpts().getExceptionHandling() ==
+LangOptions::ExceptionHandlingKind::None &&
+EST == EST_Dynamic)
+  CGM.getDiags().Report(D->getLocation(),
+diag::warn_wasm_dynamic_exception_spec_ignored)
+  << FD->getExceptionSpecSourceRange();
+
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 

diff  --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index c9beb69474387..de5cf40259b9a 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -381,7 +381,7 @@ void test8() {
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING-DEFAULT
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-ON
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -exception-model=wasm -target-feature 
+exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | 
FileCheck %s --check-prefix=WARNING-OFF
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=NOT-WASM-EH
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions 
-fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s 
--check-prefix=EM-EH-WARNING
 
 // Wasm EH ignores dynamic exception specifications with types at the moment.
 // This is controlled by -Wwasm-exception-spec, which is on by default. This
@@ -392,7 +392,7 @@ void test9() throw(int) {
 // WARNING-DEFAULT: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-ON: warning: dynamic exception specifications with types are 
currently ignored in wasm
 // WARNING-OFF-NOT: warning: dynamic 

[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 346831.
yaxunl marked 3 inline comments as done.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D102801

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-constant-var.cu
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -1,16 +1,14 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev,com
 
-// RUN: %clang_cc1 -triple x86_64-gnu-linux \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host,com
 
 // Checks allowed usage of file-scope and function-scope static variables.
 
-// host-no-diagnostics
-
 #include "Inputs/cuda.h"
 
 // Checks static variables are allowed in device functions.
@@ -42,6 +40,28 @@
   // dev-error@-1 {{reference to __host__ variable 'z' in __global__ function}}
 }
 
+// Check dynamic initialization of static device variable is not allowed.
+
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+class B {
+public:
+  __device__ B(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ B var2(c);
+// com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+(void) var1;
+(void) var2;
+  };
+}
+}
+
 int* getDeviceSymbol(int *x);
 
 void foo() {
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -66,30 +66,148 @@
 template 
 __device__ func_t p_add_func = add_func;
 
+// Check non-constant constexpr variables ODR-used by host code only is not emitted.
+// DEV-NEG-NOT: constexpr_var1a
+// DEV-NEG-NOT: constexpr_var1b
+constexpr int constexpr_var1a = 1;
+inline constexpr int constexpr_var1b = 1;
+
+// Check constant constexpr variables ODR-used by host code only.
+// Non-inline constexpr variable has internal linkage, therefore it is not accessible by host and not kept.
+// Inline constexpr variable has linkonce_ord linkage, therefore it can be accessed by host and kept.
+// DEV-NEG-NOT: constexpr_var2a
+// DEV-DAG: @constexpr_var2b = linkonce_odr addrspace(4) externally_initialized constant i32 2
+__constant__ constexpr int constexpr_var2a = 2;
+inline __constant__ constexpr int constexpr_var2b = 2;
+
 void use(func_t p);
-void use(int *p);
+__host__ __device__ void use(const int *p);
 
+// Check static device variable in host function.
+// DEV-DAG:  @_ZZ4fun1vE11static_var1 = dso_local addrspace(1) externally_initialized global i32 3
 void fun1() {
+  static __device__ int static_var1 = 3;
   use();
   use();
   use();
   use(_var);
   use(_var);
   use(p_add_func);
+  use(_var1a);
+  use(_var1b);
+  use(_var2a);
+  use(_var2b);
+  use(_var1);
+}
+
+// Check static variable in host device function.
+// DEV-DAG:  @_ZZ4fun2vE11static_var2 = internal addrspace(1) global i32 4
+// DEV-DAG:  @_ZZ4fun2vE11static_var3 = dso_local addrspace(1) global i32 4
+__host__ __device__ void fun2() {
+  static int static_var2 = 4;
+  static __device__ int static_var3 = 4;
+  use(_var2);
+  use(_var3);
 }
 
 __global__ void kern1(int **x) {
   *x = 
+  fun2();
+}
+
+// Check static variables of lambda functions.
+
+// Lambda functions are implicit host device functions.
+// Default static variables in lambda functions should be treated
+// as host variables on host side, therefore should not be forced
+// to be emitted on device.
+
+// DEV-DAG: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var2 = dso_local addrspace(1) externally_initialized global i32 5
+// DEV-NEG-NOT: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var1
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ int var2 = 5;
+(void) var1;
+(void) var2;
+  };
+}
+}
+
+// Check implicit constant variable ODR-used by host code is not emitted.
+
+// AST contains instantiation of al, which triggers AST instantiation
+// of x::al::am, which triggers AST instatiation of x::ap,
+// which 

[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:12066
 
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only

tra wrote:
> Wasn't there another kind, where the variable is emitted on the host with 
> device-side shadow? I vaguely recall it had something to do with textures.
That was the first implementation, which was similar to managed var but used 
pinned host memory as a common memory shared by device and host.

However, that implementation was later replaced by a different implementation 
which is similar to nvcc. In the new implementation textures and surfaces are 
like usual device variables. So far I do not see the necessity to differentiate 
them from usual device variables.



Comment at: clang/include/clang/Sema/Sema.h:12067
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only
+CVT_Host,/// Host only

tra wrote:
> I think we should mention the host-side shadows, too.
will do



Comment at: clang/lib/Sema/SemaCUDA.cpp:148-149
+return CVT_Unified;
+  if (hasImplicitAttr(Var))
+return CVT_Both;
+  if (Var->hasAttr() || Var->hasAttr() ||

tra wrote:
> I'm still not a fan of relying on a implicit __constant__.
> Can we change it to more direct `is-a-constexpr && 
> !has-explicit-device-side-attr` ?
> We may eventually consider relaxing this to `can-be-const-evaluated` and 
> allow const vars with known values.
> 
will do. agree we should relax this for const var in the future


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

https://reviews.llvm.org/D102801

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1008
+  for (const unsigned char C : Data) {
+if (!isPrint(C))
+  return false;

jsji wrote:
> This still need some slight change to deal with the ending 0 so that we can 
> handle .string.
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346830.
jsji added a comment.

Update .string handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -222,17 +222,17 @@
 ; CHECK:   .dwsect 0x7
 ; CHECK-NEXT:  L...dwstr:
 ; CHECK-NEXT:  L..info_string0:
-; CHECK-NEXT:  .byte   'c,'l,'a,'n,'g,' ,'v,'e,'r,'s,'i,'o,'n,' ,'1,'3,'.,'0,'.,'0, # string offset=0
+; CHECK-NEXT:  .string "clang version 13.0.0"  # string offset=0
 ; CHECK-NEXT:  L..info_string1:
-; CHECK-NEXT:  .byte   '1,'.,'c,   # string offset=21
+; CHECK-NEXT:  .string "1.c"   # string offset=21
 ; CHECK-NEXT:  L..info_string2:
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g, # string offset=25
+; CHECK-NEXT:  .string "debug" # string offset=25
 ; CHECK-NEXT:  L..info_string3:
-; CHECK-NEXT:  .byte   'f,'o,'o,   # string offset=31
+; CHECK-NEXT:  .string "foo"   # string offset=31
 ; CHECK-NEXT:  L..info_string4:
-; CHECK-NEXT:  .byte   'i,'n,'t,   # string offset=35
+; CHECK-NEXT:  .string "int"   # string offset=35
 ; CHECK-NEXT:  L..info_string5:
-; CHECK-NEXT:  .byte   'b,'a,'r,   # string offset=39
+; CHECK-NEXT:  .string "bar"   # string offset=39
 ; CHECK-NEXT:  .toc
 ; CHECK:   .dwsect 0x2
 ; CHECK-NEXT:  L...dwline:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect 

[PATCH] D100252: [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"

2021-05-20 Thread Melvin Fox via Phabricator via cfe-commits
super_concat marked 3 inline comments as done.
super_concat added a comment.

@hans, could you land this for me? I do not have commit access.


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

https://reviews.llvm.org/D100252

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


[PATCH] D74436: Change clang option -ffp-model=precise to select ffp-contract=on

2021-05-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

I created https://reviews.llvm.org/D102861 to make changes to the failing LNT 
tests. Hoping to push this commit after the test changes in D102862 
 are approved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74436

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


[PATCH] D74436: Change clang option -ffp-model=precise to select ffp-contract=on

2021-05-20 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D74436#2190566 , @lebedev.ri wrote:

> In D74436#2190492 , @lebedev.ri 
> wrote:
>
>> <...>
>
> And by codegen changes i mostly mean newly-set/now-unset fp fast-math 
> instruction flags.

I added some codegen tests to show you what ffp-contract is doing: the tests 
added are: ffp-contract={on,off,fast} * {ffast-math * fno-fast-math}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74436

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


[PATCH] D102863: [analyzer] RetainCountChecker: Disable tracking for references to OSMetaClass.

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

Please upload the actual change you want to make in the llvm.org main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102863

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


[PATCH] D102863: rdar://77307290 (Disable retain-count tracking for references to OSMetaClass)

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

OSMetaClass does not use reference-counting. We should ignore references to 
OSMetaClass in class RetainSummaryManager.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102863

Files:
  clang/test/Analysis/osobject-retain-release.cpp


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -155,20 +155,12 @@
 void use_always_write_into_two_out_params_leak() {
   OSObject *obj1;
   OSObject *obj2;
-  always_write_into_two_out_params(
-  , ); // expected-note-re{{Call to function
- // 'always_write_into_two_out_params' writes an OSObject 
of
- // type 'OSObject' with a +1 retain count into an out
- // parameter 'a'{{$ expected-note-re@-1{{Call to
- // function 'always_write_into_two_out_params' writes an
- // OSObject of type 'OSObject' with a +1 retain count into
- // an out parameter 'b'{{$
+  always_write_into_two_out_params(, ); // expected-note-re{{Call to 
function 'always_write_into_two_out_params' writes an OSObject of type 
'OSObject' with a +1 retain count into an out parameter 'a'{{$
+  // expected-note-re@-1{{Call 
to function 'always_write_into_two_out_params' writes an OSObject of type 
'OSObject' with a +1 retain count into an out parameter 'b'{{$
 } // expected-warning{{Potential leak of an object stored into 'obj1'}}
   // expected-warning@-1{{Potential leak of an object stored into 'obj2'}}
-  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' 
is
-  // not referenced later in this execution path and has a retain count of +1}}
-  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' 
is
-  // not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' 
is not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' 
is not referenced later in this execution path and has a retain count of +1}}
 
 char *write_into_out_param_on_nonnull(OS_RETURNS_RETAINED OSObject **obj);
 


Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -155,20 +155,12 @@
 void use_always_write_into_two_out_params_leak() {
   OSObject *obj1;
   OSObject *obj2;
-  always_write_into_two_out_params(
-  , ); // expected-note-re{{Call to function
- // 'always_write_into_two_out_params' writes an OSObject of
- // type 'OSObject' with a +1 retain count into an out
- // parameter 'a'{{$ expected-note-re@-1{{Call to
- // function 'always_write_into_two_out_params' writes an
- // OSObject of type 'OSObject' with a +1 retain count into
- // an out parameter 'b'{{$
+  always_write_into_two_out_params(, ); // expected-note-re{{Call to function 'always_write_into_two_out_params' writes an OSObject of type 'OSObject' with a +1 retain count into an out parameter 'a'{{$
+  // expected-note-re@-1{{Call to function 'always_write_into_two_out_params' writes an OSObject of type 'OSObject' with a +1 retain count into an out parameter 'b'{{$
 } // expected-warning{{Potential leak of an object stored into 'obj1'}}
   // expected-warning@-1{{Potential leak of an object stored into 'obj2'}}
-  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' is
-  // not referenced later in this execution path and has a retain count of +1}}
-  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' is
-  // not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-2{{Object leaked: object allocated and stored into 'obj1' is not referenced later in this execution path and has a retain count of +1}}
+  // expected-note@-3{{Object leaked: object allocated and stored into 'obj2' is not referenced later in this execution path and has a retain count of +1}}
 
 char *write_into_out_param_on_nonnull(OS_RETURNS_RETAINED OSObject **obj);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 346817.
RedDocMD added a comment.

Removed un-necessary includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -76,11 +76,16 @@
   {{"release"}, ::handleRelease},
   {{"swap", 1}, ::handleSwap},
   {{"get"}, ::handleGet}};
+  mutable 

[PATCH] D102860: [clang][deps] NFC: Remove the `module-deps-to-rsp.py` utility

2021-05-20 Thread Georgeta Igna via Phabricator via cfe-commits
georgi_igna created this revision.
georgi_igna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was upstreamed in https://reviews.llvm.org/D102495 and put into 
`clang/utils`.

Merge commit 'b99b18eb59ed' from apple/main into internal/main


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102860

Files:
  clang/test/ClangScanDeps/module-deps-to-rsp.py


Index: clang/test/ClangScanDeps/module-deps-to-rsp.py
===
--- clang/test/ClangScanDeps/module-deps-to-rsp.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-import argparse
-import json
-import sys
-
-class ModuleNotFoundError(Exception):
-  def __init__(self, module_name):
-self.module_name = module_name
-
-class FullDeps:
-  def __init__(self):
-self.modules = dict()
-self.translation_units = str()
-
-def getModulePathArgs(modules, full_deps):
-  cmd = []
-  for md in modules:
-m = full_deps.modules[md['module-name'] + '-' + md['context-hash']]
-cmd += [u'-fmodule-map-file=' + m['clang-modulemap-file']]
-cmd += [u'-fmodule-file=' + md['module-name'] + '-' + md['context-hash'] + 
'.pcm']
-  return cmd
-
-def getCommandLineForModule(module_name, full_deps):
-  for m in full_deps.modules.values():
-if m['name'] == module_name:
-  module = m
-  break
-  else:
-raise ModuleNotFoundError(module_name)
-
-  cmd = m['command-line']
-  cmd += getModulePathArgs(m['clang-module-deps'], full_deps)
-  cmd += [u'-o', m['name'] + '-' + m['context-hash'] + '.pcm']
-  cmd += [m['clang-modulemap-file']]
-  
-  return cmd
-  
-def getCommandLineForTU(tu, full_deps):
-  cmd = tu['command-line']
-  cmd = [a for a in cmd if not (a.startswith('-fmodule-map-file=') or 
a.startswith('-fmodule-file='))]
-  cmd += getModulePathArgs(tu['clang-module-deps'], full_deps)
-  return cmd
-
-def parseFullDeps(json):
-  ret = FullDeps()
-  for m in json['modules']:
-ret.modules[m['name'] + '-' + m['context-hash']] = m
-  ret.translation_units = json['translation-units']
-  return ret
-
-def main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument("full_deps_file", help="Path to the full dependencies 
json file",
-  type=str)
-  action = parser.add_mutually_exclusive_group(required=True)
-  action.add_argument("--module-name", help="The name of the module to get 
arguments for",
-  type=str)
-  action.add_argument("--tu-index", help="The index of the translation unit to 
get arguments for",
-  type=int)
-  args = parser.parse_args()
-  
-  full_deps = parseFullDeps(json.load(open(args.full_deps_file, 'r')))
-  
-  try:
-if args.module_name:
-  print(" ".join(getCommandLineForModule(args.module_name, full_deps)))
-
-elif args.tu_index != None:
-  print(" 
".join(getCommandLineForTU(full_deps.translation_units[args.tu_index], 
full_deps)))
-  except:
-print("Unexpected error:", sys.exc_info()[0])
-raise
-
-if __name__ == '__main__':
-  main()


Index: clang/test/ClangScanDeps/module-deps-to-rsp.py
===
--- clang/test/ClangScanDeps/module-deps-to-rsp.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-import argparse
-import json
-import sys
-
-class ModuleNotFoundError(Exception):
-  def __init__(self, module_name):
-self.module_name = module_name
-
-class FullDeps:
-  def __init__(self):
-self.modules = dict()
-self.translation_units = str()
-
-def getModulePathArgs(modules, full_deps):
-  cmd = []
-  for md in modules:
-m = full_deps.modules[md['module-name'] + '-' + md['context-hash']]
-cmd += [u'-fmodule-map-file=' + m['clang-modulemap-file']]
-cmd += [u'-fmodule-file=' + md['module-name'] + '-' + md['context-hash'] + '.pcm']
-  return cmd
-
-def getCommandLineForModule(module_name, full_deps):
-  for m in full_deps.modules.values():
-if m['name'] == module_name:
-  module = m
-  break
-  else:
-raise ModuleNotFoundError(module_name)
-
-  cmd = m['command-line']
-  cmd += getModulePathArgs(m['clang-module-deps'], full_deps)
-  cmd += [u'-o', m['name'] + '-' + m['context-hash'] + '.pcm']
-  cmd += [m['clang-modulemap-file']]
-  
-  return cmd
-  
-def getCommandLineForTU(tu, full_deps):
-  cmd = tu['command-line']
-  cmd = [a for a in cmd if not (a.startswith('-fmodule-map-file=') or a.startswith('-fmodule-file='))]
-  cmd += getModulePathArgs(tu['clang-module-deps'], full_deps)
-  return cmd
-
-def parseFullDeps(json):
-  ret = FullDeps()
-  for m in json['modules']:
-ret.modules[m['name'] + '-' + m['context-hash']] = m
-  ret.translation_units = json['translation-units']
-  return ret
-
-def main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument("full_deps_file", help="Path to the full dependencies json file",
-  type=str)
-  action = 

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:141-163
+auto bugReportOnGet = [&](const Expr *E) -> auto {
+  if (const auto *MCE = llvm::dyn_cast(E)) {
+const auto *Method = MCE->getMethodDecl();
+const auto *Record = MCE->getRecordDecl();
+if (Method->getName() == "get" &&
+Record->getDeclContext()->isStdNamespace() &&
+Record->getName() == "unique_ptr") {

vsavchenko wrote:
> Is there any reason it's not a method of `FindWhereConstrained`?
Not really.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:179-180
+  // P.get()
+  if (const auto *InnerCastExpr =
+  llvm::dyn_cast(Sub)) {
+Sub = InnerCastExpr->getSubExpr();

vsavchenko wrote:
> I think it's better to `IgnoreParensAndCasts` instead of manual traversal.
What is IgnoreParensAndCasts`? I didn't find it in the source code anywhere 
(ripgrep, that is).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:227
+if (const auto *DS = llvm::dyn_cast(S)) {
+  const Decl *D = DS->getSingleDecl();
+  if (const auto *VD = llvm::dyn_cast(D)) {

vsavchenko wrote:
> So, situations like `int *a = nullptr, *b = smart.get();` are not supported?
No it works even in that case (I have added a test for that). It's got to do 
with how the AST data structures are (`int *a = nullptr, *b = smart.get();` is 
considered a single decl).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:229
+  if (const auto *VD = llvm::dyn_cast(D)) {
+for (const auto *I : PtrsTrackedAndConstrained) {
+  if (I->getName() == VD->getName()) {

vsavchenko wrote:
> `llvm::find_if`
Not sure if that'll work neatly since I actually need the return value of the 
predicate function (the report).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:238-245
+}
+  }
+}
+  }
+}
+  }
+}

vsavchenko wrote:
> This level of nestedness is frowned upon. It is a good tell that the function 
> should be refactored.
> The following code:
> ```
> if (cond1) {
>   . . .
>   if (cond2) {
> . . .
> if (cond3) {
>   . . .
> }
>   }
> }
> return nullptr;
> ```
> can be refactored into:
> ```
> if (!cond1)
>   return nullptr;
> 
> . . .
> if (!cond2)
>   return nullptr;
> 
> . . .
> if (!cond3)
>   return nullptr;
> 
> . . .
> ```
> 
> It is easier to follow the logic if the function is composed in this manner 
> because from the very beginning you know that `else` with more stuff is not 
> going to follow.
Do you still think that's the case now? (After breaking it into functions).
I also think that for the sort of pattern matching we are doing in this patch, 
the nested if's make more sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-05-20 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 346808.
RedDocMD marked 10 inline comments as done.
RedDocMD added a comment.

Code clean up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,81 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void multpleDeclsWithGet(std::unique_ptr P) {
+  A *dummy1 = nullptr, *RP = P.get(), *dummy2; // expected-note {{Obtained null inner pointer from 'P'}}
+  if (!RP) {   // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void multipleGetsShouldNotAllHaveNotes(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  A *dummy1 = P.get();
+  A *dummy2 = P.get();
+  if (!RP) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldNotAlwaysLeaveANote() {
+  std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+  A *a = P.get();
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveANoteAfterReset(std::unique_ptr P) {
+  A *a = P.get();
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  P->foo();  // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+ // expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get();
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveNoteOnChaining(std::unique_ptr P) {
+  A *praw = P.get(), *other; // expected-note {{Obtained null inner pointer from 'P'}}
+  other = praw;  // expected-note {{Obtained null value here}}
+  if (!other) {  // expected-note {{Assuming 'other' is null}}
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -26,6 +26,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include 

[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Derek Schuff via Phabricator via cfe-commits
dschuff accepted this revision.
dschuff added a comment.

Got it, this makes sense to me too. And since it can be turned off, I'm not too 
worried about annoying users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1008
+  for (const unsigned char C : Data) {
+if (!isPrint(C))
+  return false;

This still need some slight change to deal with the ending 0 so that we can 
handle .string.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

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

In D102801#2771664 , @yaxunl wrote:

> In the updated patch I have a simpler solution which is easier to explain to 
> the users. Basically we classify variables by how they are emitted: device 
> side only, host side only, both sides as different entities (e.g. default 
> constexpr var), and both sides as unified entity (e.g. managed var). For 
> variables emitted on both sides as separate entities, we have limited 
> knowledge and we limit what we can do for them. I think users should 
> understand the compiler's limitation in such cases. And they can easily 
> workaround that by making the variable explicitly device variable.

This is really nice.

Let me test it internally and see if anything breaks.




Comment at: clang/include/clang/Sema/Sema.h:12066
 
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only

Wasn't there another kind, where the variable is emitted on the host with 
device-side shadow? I vaguely recall it had something to do with textures.



Comment at: clang/include/clang/Sema/Sema.h:12067
+  enum CUDAVariableTarget {
+CVT_Device,  /// Device only
+CVT_Host,/// Host only

I think we should mention the host-side shadows, too.



Comment at: clang/lib/Sema/SemaCUDA.cpp:148-149
+return CVT_Unified;
+  if (hasImplicitAttr(Var))
+return CVT_Both;
+  if (Var->hasAttr() || Var->hasAttr() ||

I'm still not a fan of relying on a implicit __constant__.
Can we change it to more direct `is-a-constexpr && 
!has-explicit-device-side-attr` ?
We may eventually consider relaxing this to `can-be-const-evaluated` and allow 
const vars with known values.



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

https://reviews.llvm.org/D102801

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


[PATCH] D102742: [IR] make stack-protector-guard-* flags into module attrs

2021-05-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 346800.
nickdesaulniers added a comment.

- fix lints


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102742

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-protector-guard.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/IR/Module.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/StackProtector.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
  llvm/test/CodeGen/X86/stack-protector-3.ll

Index: llvm/test/CodeGen/X86/stack-protector-3.ll
===
--- llvm/test/CodeGen/X86/stack-protector-3.ll
+++ llvm/test/CodeGen/X86/stack-protector-3.ll
@@ -1,10 +1,18 @@
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard=tls -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard=global -o - < %s | FileCheck --check-prefix=CHECK-GLOBAL %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=fs -o - < %s | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-reg=gs -o - < %s | FileCheck --check-prefix=CHECK-GS %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=20 -o - < %s | FileCheck --check-prefix=CHECK-OFFSET %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -stack-protector-guard-offset=-20 -o - < %s | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s
+; RUN: split-file %s %t
+; RUN: cat %t/main.ll %t/a.ll > %t/a2.ll
+; RUN: cat %t/main.ll %t/b.ll > %t/b2.ll
+; RUN: cat %t/main.ll %t/c.ll > %t/c2.ll
+; RUN: cat %t/main.ll %t/d.ll > %t/d2.ll
+; RUN: cat %t/main.ll %t/e.ll > %t/e2.ll
+; RUN: cat %t/main.ll %t/f.ll > %t/f2.ll
+; RUN: cat %t/main.ll %t/g.ll > %t/g2.ll
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/a2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/b2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/c2.ll | FileCheck --check-prefix=CHECK-GLOBAL %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/d2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/e2.ll | FileCheck --check-prefix=CHECK-GS %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/f2.ll | FileCheck --check-prefix=CHECK-OFFSET %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/g2.ll | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s
 
 ; CHECK-TLS-FS-40:   movq%fs:40, %rax
 ; CHECK-TLS-FS-40:   movq%fs:40, %rax
@@ -47,6 +55,8 @@
 ; CHECK-GLOBAL-NEXT:  .cfi_def_cfa_offset 32
 ; CHECK-GLOBAL-NEXT:  callq   __stack_chk_fail
 
+;--- main.ll
+
 ; ModuleID = 't.c'
 @.str = private unnamed_addr constant [14 x i8] c"stackoverflow\00", align 1
 @a = dso_local local_unnamed_addr global i8* null, align 8
@@ -75,3 +85,23 @@
 attributes #0 = { nounwind sspreq uwtable writeonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
 attributes #1 = { argmemonly nounwind willreturn }
 attributes #2 = { nounwind }
+
+;--- a.ll
+;--- b.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard", !"tls"}
+;--- c.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard", !"global"}
+;--- d.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-reg", !"fs"}
+;--- e.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-reg", !"gs"}
+;--- f.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-offset", i32 20}
+;--- g.ll
+!llvm.module.flags = !{!1}
+!1 = !{i32 2, !"stack-protector-guard-offset", i32 -20}
Index: llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
===
--- llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
+++ llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
@@ -1,46 +1,39 @@
-; RUN: llc %s --stack-protector-guard=sysreg \
-; RUN:   --stack-protector-guard-reg=sp_el0 \
-; RUN:   --stack-protector-guard-offset=0 -verify-machineinstrs -o - | \
+; RUN: split-file %s %t
+; RUN: cat %t/main.ll %t/a.ll > %t/a2.ll
+; RUN: 

[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Reid Kleckner 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 rG8f20ac9595c8: [PGO] Dont reference functions unless 
value profiling is enabled (authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/CodeGen/CodeGenPGO.h
  compiler-rt/test/profile/instrprof-value-prof-2.c
  compiler-rt/test/profile/instrprof-value-prof.c
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -748,7 +748,26 @@
   return (Prefix + Name + "." + Twine(FuncHash)).str();
 }
 
+static uint64_t getIntModuleFlagOrZero(Module *M, StringRef Flag) {
+  auto *MD = dyn_cast_or_null(M->getModuleFlag(Flag));
+  if (!MD)
+return 0;
+
+  // If the flag is a ConstantAsMetadata, it should be an integer representable
+  // in 64-bits.
+  return cast(MD->getValue())->getZExtValue();
+}
+
 static inline bool shouldRecordFunctionAddr(Function *F) {
+  // Only record function addresses if IR PGO is enabled or if clang value
+  // profiling is enabled. Recording function addresses greatly increases 
object
+  // file size, because it prevents the inliner from deleting functions that
+  // have been inlined everywhere.
+  if (!isIRPGOFlagSet(F->getParent()) &&
+  getIntModuleFlagOrZero(F->getParent(), "EnableValueProfiling") == 0) {
+return false;
+  }
+
   // Check the linkage
   bool HasAvailableExternallyLinkage = F->hasAvailableExternallyLinkage();
   if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
Index: compiler-rt/test/profile/instrprof-value-prof.c
===
--- compiler-rt/test/profile/instrprof-value-prof.c
+++ compiler-rt/test/profile/instrprof-value-prof.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -mllvm -vp-static-alloc=false  -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -mllvm 
-vp-static-alloc=false  -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t DO_NOT_INSTRUMENT
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
Index: compiler-rt/test/profile/instrprof-value-prof-2.c
===
--- compiler-rt/test/profile/instrprof-value-prof-2.c
+++ compiler-rt/test/profile/instrprof-value-prof-2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
 // RUN: llvm-profdata show --all-functions -ic-targets  %t.profdata > %t.out
Index: clang/lib/CodeGen/CodeGenPGO.h
===
--- clang/lib/CodeGen/CodeGenPGO.h
+++ clang/lib/CodeGen/CodeGenPGO.h
@@ -87,6 +87,10 @@
   // Insert instrumentation or attach profile metadata at value sites
   void valueProfile(CGBuilderTy , uint32_t ValueKind,
 llvm::Instruction *ValueSite, llvm::Value *ValuePtr);
+
+  // Set a module flag indicating if value profiling is enabled.
+  void setValueProfilingFlag(llvm::Module );
+
 private:
   void setFuncName(llvm::Function *Fn);
   void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage);
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -962,6 +962,12 @@
 makeArrayRef(Args));
 }
 
+void CodeGenPGO::setValueProfilingFlag(llvm::Module ) {
+  if (CGM.getCodeGenOpts().hasProfileClangInstr())
+M.addModuleFlag(llvm::Module::Warning, "EnableValueProfiling",
+uint32_t(EnableValueProfiling));
+}
+
 // This method either inserts a call to the profile run-time during
 // instrumentation or puts profile data into metadata for PGO use.
 void CodeGenPGO::valueProfile(CGBuilderTy , uint32_t ValueKind,
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -511,6 +511,7 @@
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
   EmitDeferredUnusedCoverageMappings();
+  CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
 CoverageMapping->emit();
   if (CodeGenOpts.SanitizeCfiCrossDso) {


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- 

[clang] 8f20ac9 - [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2021-05-20T11:09:24-07:00
New Revision: 8f20ac9595c8b279641dace6f212b8a9673b24e4

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

LOG: [PGO] Don't reference functions unless value profiling is enabled

This reduces the size of chrome.dll.pdb built with optimizations,
coverage, and line table info from 4,690,210,816 to 2,181,128,192, which
makes it possible to fit under the 4GB limit.

This change can greatly reduce binary size in coverage builds, which do
not need value profiling. IR PGO builds are unaffected. There is a minor
behavior change for frontend PGO.

PGO and coverage both use InstrProfiling to create profile data with
counters. PGO records the address of each function in the __profd_
global. It is used later to map runtime function pointer values back to
source-level function names. Coverage does not appear to use this
information.

Recording the address of every function with code coverage drastically
increases code size. Consider this program:

  void foo();
  void bar();
  inline void inlineMe(int x) {
if (x > 0)
  foo();
else
  bar();
  }
  int getVal();
  int main() { inlineMe(getVal()); }

With code coverage, the InstrProfiling pass runs before inlining, and it
captures the address of inlineMe in the __profd_ global. This greatly
increases code size, because now the compiler can no longer delete
trivial code.

One downside to this approach is that users of frontend PGO must apply
the -mllvm -enable-value-profiling flag globally in TUs that enable PGO.
Otherwise, some inline virtual method addresses may not be recorded and
will not be able to be promoted. My assumption is that this mllvm flag
is not popular, and most frontend PGO users don't enable it.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h
compiler-rt/test/profile/instrprof-value-prof-2.c
compiler-rt/test/profile/instrprof-value-prof.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e38dee92db293..03920982ee086 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -511,6 +511,7 @@ void CodeGenModule::Release() {
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
   EmitDeferredUnusedCoverageMappings();
+  CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
 CoverageMapping->emit();
   if (CodeGenOpts.SanitizeCfiCrossDso) {

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 49b38a404f5dc..d828ac0eb5e98 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -962,6 +962,12 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
, const Stmt *S,
 makeArrayRef(Args));
 }
 
+void CodeGenPGO::setValueProfilingFlag(llvm::Module ) {
+  if (CGM.getCodeGenOpts().hasProfileClangInstr())
+M.addModuleFlag(llvm::Module::Warning, "EnableValueProfiling",
+uint32_t(EnableValueProfiling));
+}
+
 // This method either inserts a call to the profile run-time during
 // instrumentation or puts profile data into metadata for PGO use.
 void CodeGenPGO::valueProfile(CGBuilderTy , uint32_t ValueKind,

diff  --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 906c5e406d77c..f740692ac205b 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -87,6 +87,10 @@ class CodeGenPGO {
   // Insert instrumentation or attach profile metadata at value sites
   void valueProfile(CGBuilderTy , uint32_t ValueKind,
 llvm::Instruction *ValueSite, llvm::Value *ValuePtr);
+
+  // Set a module flag indicating if value profiling is enabled.
+  void setValueProfilingFlag(llvm::Module );
+
 private:
   void setFuncName(llvm::Function *Fn);
   void setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage);

diff  --git a/compiler-rt/test/profile/instrprof-value-prof-2.c 
b/compiler-rt/test/profile/instrprof-value-prof-2.c
index 88a2de039979e..abc990ac8b052 100644
--- a/compiler-rt/test/profile/instrprof-value-prof-2.c
+++ b/compiler-rt/test/profile/instrprof-value-prof-2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -O2 -o %t %s
+// RUN: %clang_profgen -mllvm -enable-value-profiling -O2 -o %t %s
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
 // RUN: llvm-profdata show --all-functions -ic-targets  %t.profdata > %t.out

diff  --git a/compiler-rt/test/profile/instrprof-value-prof.c 
b/compiler-rt/test/profile/instrprof-value-prof.c

[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

In D102801#2769619 , @tra wrote:

> Tentative LGTM as we need it to fix the regression soon.
>
> Summoning @rsmith for the 'big picture' opinion. 
> While the patch may fix this particular regression, I wonder if there's a 
> better way to deal with this. We're growing a bit too many nuances that would 
> be hard to explain and may cause more corner cases to appear.

In the updated patch I have a simpler solution which is easier to explain to 
the users. Basically we classify variables by how they are emitted: device side 
only, host side only, both sides as different entities (e.g. default constexpr 
var), and both sides as unified entity (e.g. managed var). For variables 
emitted on both sides as separate entities, we have limited knowledge and we 
limit what we can do for them. I think users should understand the compiler's 
limitation in such cases. And they can easily workaround that by making the 
variable explicitly device variable.


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

https://reviews.llvm.org/D102801

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

In D102801#2769936 , @tra wrote:

> This patch does not appear to fix the second regression introduced by the 
> D102237 .
>
> Trying to compile the following code triggers an assertion in CGExpr.cpp:
>
>   class a {
>   public:
> a(char *);
>   };
>   void b() {
> [](char *c) {
>   static a d(c);
>   d;
> };
>   }
>
> With assertions disabled it eventually leads to a different error: 
> `Module has a nontrivial global ctor, which NVPTX does not support.`
> https://godbolt.org/z/sYE1dKr1W

The root cause is similar to the last regression. Basically when a variable is 
emitted on both sides but as different entities, we should not treat it as a 
device variable on host side. I have updated the patch to fix both regressions.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2386
+  };
+  if (!HasImplicitConstantAttr(V))
+DeferredDeclsToEmit.push_back(V);

tra wrote:
> IIUIC, The idea here is that we do not want to emit `constexpr int foo;` on 
> device, even if we happen to ODR-use it there.
> And the way we detect this is by checking for implicit `__constant__` we 
> happen to add to constexpr variables.
> 
> I think this may be relying on the implementation details too much. It also 
> makes compiler's behavior somewhat surprising -- we would potentially emit 
> other variables that do not get any device attributes attribute, but would 
> not emit the variables with implicit `__constant__`, which is a device 
> attribute.
> 
> I'm not sure if we have any good options here. This may be an acceptable 
> compromise, but I wonder if there's a better way to deal with this.
> 
> That said, this patch is OK to fix the regression we have now, but we may 
> need to revisit this.
> 
we need to differentiate `constexpr int a` and `__constant__ constexpr int a`, 
since the former is emitted on both sides, and the later is only emitted on 
device side. It seems the only way to differentiate them is to check whether 
the constant attribute is explicit or not.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:103-131
+// Check implicit constant variable ODR-used by host code is not emitted.
+// DEV-NEG-NOT: _ZN16TestConstexprVar1oE
+namespace TestConstexprVar {
+char o;
+class ou {
+public:
+  ou(char) { __builtin_strlen(); }

tra wrote:
> This definitely needs some comments. Otherwise this is nearly 
> incomprehensible and it's impossible to tell what's going on.
done


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

https://reviews.llvm.org/D102801

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


[PATCH] D102517: [clang] Add support for the "abstract" contextual keyword of MSVC

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

@hans, can you review this? I am trying to offload clang reviews.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102517

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


[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added a comment.
This revision now requires changes to proceed.

So I will hide it from "Ready to Review" list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

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


[PATCH] D102801: [CUDA][HIP] Fix device variables used by host

2021-05-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 346796.
yaxunl retitled this revision from "[CUDA][HIP] Fix implicit constant variable" 
to "[CUDA][HIP] Fix device variables used by host".
yaxunl edited the summary of this revision.
yaxunl added a comment.

Fix the other regression


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

https://reviews.llvm.org/D102801

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-constant-var.cu
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/SemaCUDA/static-device-var.cu

Index: clang/test/SemaCUDA/static-device-var.cu
===
--- clang/test/SemaCUDA/static-device-var.cu
+++ clang/test/SemaCUDA/static-device-var.cu
@@ -1,16 +1,14 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=dev,com
 
-// RUN: %clang_cc1 -triple x86_64-gnu-linux \
-// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
+// RUN:-emit-llvm -o - %s -fsyntax-only -verify=host,com
 
 // Checks allowed usage of file-scope and function-scope static variables.
 
-// host-no-diagnostics
-
 #include "Inputs/cuda.h"
 
 // Checks static variables are allowed in device functions.
@@ -42,6 +40,28 @@
   // dev-error@-1 {{reference to __host__ variable 'z' in __global__ function}}
 }
 
+// Check dynamic initialization of static device variable is not allowed.
+
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+class B {
+public:
+  __device__ B(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ B var2(c);
+// com-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+(void) var1;
+(void) var2;
+  };
+}
+}
+
 int* getDeviceSymbol(int *x);
 
 void foo() {
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -66,30 +66,148 @@
 template 
 __device__ func_t p_add_func = add_func;
 
+// Check non-constant constexpr variables ODR-used by host code only is not emitted.
+// DEV-NEG-NOT: constexpr_var1a
+// DEV-NEG-NOT: constexpr_var1b
+constexpr int constexpr_var1a = 1;
+inline constexpr int constexpr_var1b = 1;
+
+// Check constant constexpr variables ODR-used by host code only.
+// Non-inline constexpr variable has internal linkage, therefore it is not accessible by host and not kept.
+// Inline constexpr variable has linkonce_ord linkage, therefore it can be accessed by host and kept.
+// DEV-NEG-NOT: constexpr_var2a
+// DEV-DAG: @constexpr_var2b = linkonce_odr addrspace(4) externally_initialized constant i32 2
+__constant__ constexpr int constexpr_var2a = 2;
+inline __constant__ constexpr int constexpr_var2b = 2;
+
 void use(func_t p);
-void use(int *p);
+__host__ __device__ void use(const int *p);
 
+// Check static device variable in host function.
+// DEV-DAG:  @_ZZ4fun1vE11static_var1 = dso_local addrspace(1) externally_initialized global i32 3
 void fun1() {
+  static __device__ int static_var1 = 3;
   use();
   use();
   use();
   use(_var);
   use(_var);
   use(p_add_func);
+  use(_var1a);
+  use(_var1b);
+  use(_var2a);
+  use(_var2b);
+  use(_var1);
+}
+
+// Check static variable in host device function.
+// DEV-DAG:  @_ZZ4fun2vE11static_var2 = internal addrspace(1) global i32 4
+// DEV-DAG:  @_ZZ4fun2vE11static_var3 = dso_local addrspace(1) global i32 4
+__host__ __device__ void fun2() {
+  static int static_var2 = 4;
+  static __device__ int static_var3 = 4;
+  use(_var2);
+  use(_var3);
 }
 
 __global__ void kern1(int **x) {
   *x = 
+  fun2();
+}
+
+// Check static variables of lambda functions.
+
+// Lambda functions are implicit host device functions.
+// Default static variables in lambda functions should be treated
+// as host variables on host side, therefore should not be forced
+// to be emitted on device.
+
+// DEV-DAG: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var2 = dso_local addrspace(1) externally_initialized global i32 5
+// DEV-NEG-NOT: @_ZZZN21TestStaticVarInLambda3funEvENKUlPcE_clES0_E4var1
+namespace TestStaticVarInLambda {
+class A {
+public:
+  A(char *);
+};
+void fun() {
+  (void) [](char *c) {
+static A var1(c);
+static __device__ int var2 = 5;
+(void) var1;
+(void) var2;
+  };
+}
+}
+
+// Check implicit constant variable ODR-used by host code is not emitted.
+
+// AST 

[PATCH] D102812: [clang] Don't pass multiple backend options if mixing -mimplicit-it and -Wa,-mimplicit-it

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



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2369
 
-static bool AddARMImplicitITArgs(const ArgList , ArgStringList ,
+static bool CheckARMImplicitITArg(StringRef Value) {
+  return Value == "always" || Value == "never" || Value == "arm" ||

Use `functionName` for new functions.



Comment at: clang/test/Driver/arm-target-as-mimplicit-it.s:39
 // ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
 // NEVER: "-mllvm" "-arm-implicit-it=never"

mstorsjo wrote:
> DavidSpickett wrote:
> > mstorsjo wrote:
> > > This pattern wouldn't detct if there's e.g. `-arm-implicit-it=never 
> > > -arm-implicit-it=always`, but I added test cases that pass 
> > > `-Wa,-mimplicit-it=always` twice, where this check should be able to 
> > > verify that we only output it once.
> > Could you do:
> > ```
> > // ALWAYS-NOT: "-mllvm" "-arm-implicit-it=never"
> > // ALWAYS: "-mllvm" "-arm-implicit-it=always"
> > ```
> > 
> > Not sure if doing the NOT moves the check forward to beyond where the 
> > always would be.
> Thanks, I think that could work to further guard against that case.
The NOT pattern can omit the value to catch more cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102812

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


[PATCH] D102814: [AIX] Print printable byte list as quoted string

2021-05-20 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346794.
jsji added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102814

Files:
  clang/test/CodeGenCXX/debug-info-byval.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll
  llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable.ll
  llvm/test/CodeGen/PowerPC/aix-exception.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/DebugInfo/XCOFF/empty.ll
  llvm/test/DebugInfo/XCOFF/explicit-section.ll
  llvm/test/DebugInfo/XCOFF/function-sections.ll

Index: llvm/test/DebugInfo/XCOFF/function-sections.ll
===
--- llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -72,7 +72,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..foo0-.foo[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'f,'o,'o# Function Name
+; CHECK-NEXT:  .byte   "foo"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect .bar[PR],2
@@ -108,7 +108,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar[PR] # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -258,10 +258,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '1,'.,'c
+; CHECK-NEXT:  .byte   "1.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/explicit-section.ll
===
--- llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -77,7 +77,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..bar0-.bar # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0003   # Function name len = 3
-; CHECK-NEXT:  .byte   'b,'a,'r# Function Name
+; CHECK-NEXT:  .byte   "bar"   # Function Name
 ; CHECK-NEXT:  L..func_end0:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  .csect explicit_main_sec[PR],2
@@ -125,7 +125,7 @@
 ; CHECK-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; CHECK-NEXT:  .vbyte  4, L..main0-.main   # Function size
 ; CHECK-NEXT:  .vbyte  2, 0x0004   # Function name len = 4
-; CHECK-NEXT:  .byte   'm,'a,'i,'n # Function Name
+; CHECK-NEXT:  .byte   "main"  # Function Name
 ; CHECK-NEXT:  L..func_end1:
 ; CHECK-NEXT:  # -- End function
 ; CHECK-NEXT:  L..sec_end0:
@@ -271,10 +271,10 @@
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
-; CHECK-NEXT:  .byte   'd,'e,'b,'u,'g
+; CHECK-NEXT:  .byte   "debug"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   0
-; CHECK-NEXT:  .byte   '2,'.,'c
+; CHECK-NEXT:  .byte   "2.c"
 ; CHECK-NEXT:  .byte   0
 ; CHECK-NEXT:  .byte   1
 ; CHECK-NEXT:  .byte   0
Index: llvm/test/DebugInfo/XCOFF/empty.ll
===
--- llvm/test/DebugInfo/XCOFF/empty.ll
+++ llvm/test/DebugInfo/XCOFF/empty.ll
@@ -71,7 +71,7 @@
 ; ASM32-NEXT:  .byte   0x01# NumberOfFPParms = 0, +HasParmsOnStack
 ; ASM32-NEXT:  .vbyte  4, L..main0-.main   # Function size
 ; ASM32-NEXT:  .vbyte  2, 0x0004   # Function name len = 4

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

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

lgtm, sorry for the delay, this fell off the end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101479

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


[PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2021-05-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In D20401#2770059 , @nickdesaulniers 
wrote:

> I know this was sped up slightly in 3339c568c43e4644f02289e5edfc78c860f19c9f, 
> but this change makes `updateConsecutiveMacroArgTokens` the hottest function 
> in clang in a bottom up profile of an entire build of the Linux kernel.  It 
> thrashes the one entry LastFileIDLookup cache, and we end up looking up the 
> same FileID again and again and again for each token when we expand nested 
> function like macros.
>
> Is there anything we can do to speed this up?  Is there any way to record 
> which FileID corresponds to a given Token so that we don't have to keep 
> rematerializing that?  Is it possible to find whether two SourceLocations 
> correspond to the same FileID without having to figure out which FileID in 
> particular each belongs to?

Perhaps you could try:

- using SourceManager::isInFileID(NextLoc, getFileID(CurLoc), ...) (to halve 
the number of necessary getFileID lookups), or
- using a 2-element cache in getFileID?

>> I discussed this bug with Argyrios off-list, who lgtm'd on the condition 
>> that it doesn't introduce a performance regression.
>
> Well, I'd say it's a performance regression, though perhaps reported 5 years 
> too late.

If the performance issue manifests on Linux kernel sources from 5 years ago, 
then sure, I'd agree :).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20401

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


[PATCH] D102853: [OpenCL] Align definition of __IMAGE_SUPPORT__ feature macro with OpenCL version and __opencl_c_images feature macro definition

2021-05-20 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov created this revision.
azabaznov added reviewers: Anastasia, svenvh.
Herald added subscribers: ldrumm, yaxunl.
azabaznov 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/D102853

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros.c
  clang/test/SemaOpenCL/features.cl


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=-all \
-// RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
+// RUN:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=+all \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
 // RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 \
-// RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
+// RUN:   | FileCheck -match-full-lines %s  
--check-prefixes=NO-FEATURES,NO-FEATURES-CL30
 // RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -cl-ext=+all \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=FEATURES
 
@@ -21,6 +21,7 @@
 // Note that __opencl_c_int64 is always defined assuming
 // always compiling for FULL OpenCL profile
 
+// FEATURES: #define __IMAGE_SUPPORT__ 1
 // FEATURES: #define __opencl_c_3d_image_writes 1
 // FEATURES: #define __opencl_c_atomic_order_acq_rel 1
 // FEATURES: #define __opencl_c_atomic_order_seq_cst 1
@@ -46,3 +47,4 @@
 // NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
 // NO-FEATURES-NOT: __opencl_c_read_write_images
 // NO-FEATURES-NOT: __opencl_c_subgroups
+// NO-FEATURES-CL30-NOT: __IMAGE_SUPPORT__
Index: clang/test/Preprocessor/predefined-macros.c
===
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -188,14 +188,12 @@
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR-DAG: #define __SPIR__ 1
 // CHECK-SPIR-DAG: #define __SPIR32__ 1
 // CHECK-SPIR-NOT: #define __SPIR64__ 1
 
 // RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
 // CHECK-SPIR64-DAG: #define __SPIR__ 1
 // CHECK-SPIR64-DAG: #define __SPIR64__ 1
 // CHECK-SPIR64-NOT: #define __SPIR32__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -603,9 +603,9 @@
 
 /// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
 /// settings and language version
-void InitializeOpenCLFeatureTestMacros(const TargetInfo ,
-   const LangOptions ,
-   MacroBuilder ) {
+static void InitializeOpenCLFeatureTestMacros(const TargetInfo ,
+  const LangOptions ,
+  MacroBuilder ) {
   const llvm::StringMap  = TI.getSupportedOpenCLOpts();
   // FIXME: OpenCL options which affect language semantics/syntax
   // should be moved into LangOptions.
@@ -622,6 +622,10 @@
 
   // Assume compiling for FULL profile
   Builder.defineMacro("__opencl_c_int64");
+
+  if (Opts.OpenCLCPlusPlus || Opts.OpenCLVersion < 300 ||
+  TI.hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_images"))
+Builder.defineMacro("__IMAGE_SUPPORT__");
 }
 
 static void InitializePredefinedMacros(const TargetInfo ,
@@ -1159,13 +1163,9 @@
   }
 
   // OpenCL definitions.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL)
 InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
 
-if (TI.getTriple().isSPIR())
-  Builder.defineMacro("__IMAGE_SUPPORT__");
-  }
-
   if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
 // For each extended integer type, g++ defines a macro mapping the
 // index of the type (0 in this case) in some list of extended types


Index: clang/test/SemaOpenCL/features.cl
===
--- clang/test/SemaOpenCL/features.cl
+++ clang/test/SemaOpenCL/features.cl
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=-all \
-// RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
+// 

[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

2021-05-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.

Thanks, lgtm as well. On Darwin, the __llvm_prf_data section is marked with 
S_ATTR_LIVE_SUPPORT to allow the linker to dead strip functions even if they 
are pointed-to by a profd global. Removing the reference altogether should 
yield even better size benefits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

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


[PATCH] D102818: [PGO] Don't reference functions unless value profiling is enabled

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

Thanks! I'll wait to see if I can get an ack from the Apple folks who indicated 
that they are using frontend PGO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102818

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


[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-20 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D102479

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


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG136ced498ba8: When vector is found as a type or non-type id, 
check if it is really the… (authored by jamieschmeiser).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100991

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/altivec-non-type-vector.c
  clang/test/Parser/altivec-template-vector.cpp
  clang/test/Parser/altivec-typedef-vector.c


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}
Index: clang/test/Parser/altivec-non-type-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature 

[clang] 136ced4 - When vector is found as a type or non-type id, check if it is really the altivec vector token.

2021-05-20 Thread Jamie Schmeiser via cfe-commits

Author: Jamie Schmeiser
Date: 2021-05-20T12:39:04-04:00
New Revision: 136ced498ba84f6b6126051626e319f18ba740f5

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

LOG: When vector is found as a type or non-type id, check if it is really the 
altivec vector token.

Summary:
Call TryAltiVecVectorToken when an identifier is seen in the parser before
annotating the token.  This checks the next token where necessary to ensure
that vector is properly handled as the altivec token.

Author: Jamie Schmeiser 
Reviewed By: ZarkoCA (Zarko Todorovski)
Differential Revision: https://reviews.llvm.org/D100991

Added: 
clang/test/Parser/altivec-non-type-vector.c
clang/test/Parser/altivec-template-vector.cpp
clang/test/Parser/altivec-typedef-vector.c

Modified: 
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 389180ea01f7..cbcbca127c9d 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback 
*CCC) {
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback 
*CCC) {
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);

diff  --git a/clang/test/Parser/altivec-non-type-vector.c 
b/clang/test/Parser/altivec-non-type-vector.c
new file mode 100644
index ..d0868a60d0c3
--- /dev/null
+++ b/clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}

diff  --git a/clang/test/Parser/altivec-template-vector.cpp 
b/clang/test/Parser/altivec-template-vector.cpp
new file mode 100644
index ..f0c1d86563fe
--- /dev/null
+++ b/clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}

diff  --git a/clang/test/Parser/altivec-typedef-vector.c 
b/clang/test/Parser/altivec-typedef-vector.c
new file mode 100644
index ..5e00824b4de7
--- /dev/null
+++ b/clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}



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


[PATCH] D102756: [clang-repl] Tell the LLJIT the exact target triple we use.

2021-05-20 Thread Lang Hames via Phabricator via cfe-commits
lhames accepted this revision.
lhames added a comment.
This revision is now accepted and ready to land.

LGTM. :)


Repository:
  rC Clang

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

https://reviews.llvm.org/D102756

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


[PATCH] D102623: [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

2021-05-20 Thread Peter Waller 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 rG2d574a110440: [CodeGen][AArch64][SVE] Canonicalize intrinsic 
rdffr{ = _z} (authored by peterwaller-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102623

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Test that rdffr is substituted with predicated form which enables ptest optimization later.
+define  @predicate_rdffr() #0 {
+; CHECK-LABEL: @predicate_rdffr(
+; CHECK-NEXT:[[TMP1:%.*]] = call  @llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
+; CHECK-NEXT:[[OUT:%.*]] = call  @llvm.aarch64.sve.rdffr.z( [[TMP1]])
+; CHECK-NEXT:ret  [[OUT]]
+;
+  %out = call  @llvm.aarch64.sve.rdffr()
+  ret  %out
+}
+
+declare  @llvm.aarch64.sve.rdffr()
+
+attributes #0 = { "target-features"="+sve" }
Index: llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
@@ -1,33 +1,51 @@
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
 
 ;
 ; RDFFR
 ;
 
-define  @rdffr() {
+define  @rdffr() #0 {
 ; CHECK-LABEL: rdffr:
-; CHECK: rdffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr()
   ret  %out
 }
 
-define  @rdffr_z( %pg) {
+define  @rdffr_z( %pg) #0 {
 ; CHECK-LABEL: rdffr_z:
-; CHECK: rdffr p0.b, p0/z
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b, p0/z
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr.z( %pg)
   ret  %out
 }
 
+; Test that rdffr.z followed by ptest optimizes to flags-setting rdffrs.
+define i1 @rdffr_z_ptest( %pg) #0 {
+; CHECK-LABEL: rdffr_z_ptest:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffrs p0.b, p0/z
+; CHECK-NEXT:cset w0, ne
+; CHECK-NEXT:ret
+  %rdffr = call  @llvm.aarch64.sve.rdffr.z( %pg)
+  %out = call i1 @llvm.aarch64.sve.ptest.any.nxv16i1( %pg,  %rdffr)
+  ret i1 %out
+}
+
 ;
 ; SETFFR
 ;
 
-define void @set_ffr() {
+define void @set_ffr() #0 {
 ; CHECK-LABEL: set_ffr:
-; CHECK: setffr
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:setffr
+; CHECK-NEXT:ret
   call void @llvm.aarch64.sve.setffr()
   ret void
 }
@@ -36,10 +54,11 @@
 ; WRFFR
 ;
 
-define void @wrffr( %a) {
+define void @wrffr( %a) #0 {
 ; CHECK-LABEL: wrffr:
-; CHECK: wrffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:wrffr p0.b
+; CHECK-NEXT:ret
   call void @llvm.aarch64.sve.wrffr( %a)
   ret void
 }
@@ -48,3 +67,7 @@
 declare  @llvm.aarch64.sve.rdffr.z()
 declare void @llvm.aarch64.sve.setffr()
 declare void @llvm.aarch64.sve.wrffr()
+
+declare i1 @llvm.aarch64.sve.ptest.any.nxv16i1(, )
+
+attributes #0 = { "target-features"="+sve" }
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -470,6 +470,23 @@
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineRDFFR(InstCombiner ,
+IntrinsicInst ) {
+  LLVMContext  = II.getContext();
+  IRBuilder<> Builder(Ctx);
+  Builder.SetInsertPoint();
+  // Replace rdffr with predicated rdffr.z intrinsic, so that optimizePTestInstr
+  // can work with RDFFR_PP for ptest elimination.
+  auto *AllPat =
+  ConstantInt::get(Type::getInt32Ty(Ctx), AArch64SVEPredPattern::all);
+  auto *PTrue = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_ptrue,
+{II.getType()}, {AllPat});
+  auto *RDFFR =
+  Builder.CreateIntrinsic(Intrinsic::aarch64_sve_rdffr_z, {}, {PTrue});
+  RDFFR->takeName();
+  return IC.replaceInstUsesWith(II, RDFFR);
+}
+
 Optional
 AArch64TTIImpl::instCombineIntrinsic(InstCombiner ,
  

[clang] 2d574a1 - [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

2021-05-20 Thread Peter Waller via cfe-commits

Author: Peter Waller
Date: 2021-05-20T16:22:50Z
New Revision: 2d574a110440597eefe1b2a8b6144e4e89c21d05

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

LOG: [CodeGen][AArch64][SVE] Canonicalize intrinsic rdffr{ => _z}

Follow up to D101357 / 3fa6510f6.
Supersedes D102330.

Goal: Use flags setting rdffrs instead of rdffr + ptest.

Problem: RDFFR_P doesn't have have a flags setting equivalent.

Solution: in instcombine, canonicalize to RDFFR_PP at the IR level, and
rely on RDFFR_PP+PTEST => RDFFRS_PP optimization in
AArch64InstrInfo::optimizePTestInstr.

While here:

* Test that rdffr.z+ptest generates a rdffrs.
* Use update_{test,llc}_checks.py on the tests.
* Use sve attribute on functions.

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

Added: 
llvm/test/Transforms/InstCombine/AArch64/sve-intrinsics-rdffr-predication.ll

Modified: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
index 9b871ee3a8dc..a85ac7bb5cef 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_rdffr.c
@@ -7,7 +7,8 @@
 svbool_t test_svrdffr()
 {
   // CHECK-LABEL: test_svrdffr
-  // CHECK: %[[INTRINSIC:.*]] = call  
@llvm.aarch64.sve.rdffr()
+  // CHECK: %[[INTRINSIC:.*]] = call  
@llvm.aarch64.sve.rdffr.z(
+  // CHECK-NOT: rdffr
   // CHECK: ret  %[[INTRINSIC]]
   return svrdffr();
 }

diff  --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 90762052dc3a..846c07863467 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -470,6 +470,23 @@ static Optional 
instCombineSVELast(InstCombiner ,
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineRDFFR(InstCombiner ,
+IntrinsicInst ) {
+  LLVMContext  = II.getContext();
+  IRBuilder<> Builder(Ctx);
+  Builder.SetInsertPoint();
+  // Replace rdffr with predicated rdffr.z intrinsic, so that 
optimizePTestInstr
+  // can work with RDFFR_PP for ptest elimination.
+  auto *AllPat =
+  ConstantInt::get(Type::getInt32Ty(Ctx), AArch64SVEPredPattern::all);
+  auto *PTrue = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_ptrue,
+{II.getType()}, {AllPat});
+  auto *RDFFR =
+  Builder.CreateIntrinsic(Intrinsic::aarch64_sve_rdffr_z, {}, {PTrue});
+  RDFFR->takeName();
+  return IC.replaceInstUsesWith(II, RDFFR);
+}
+
 Optional
 AArch64TTIImpl::instCombineIntrinsic(InstCombiner ,
  IntrinsicInst ) const {
@@ -481,6 +498,8 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner ,
 return instCombineConvertFromSVBool(IC, II);
   case Intrinsic::aarch64_sve_dup:
 return instCombineSVEDup(IC, II);
+  case Intrinsic::aarch64_sve_rdffr:
+return instCombineRDFFR(IC, II);
   case Intrinsic::aarch64_sve_lasta:
   case Intrinsic::aarch64_sve_lastb:
 return instCombineSVELast(IC, II);

diff  --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll 
b/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
index 7460037078d1..bc07c972e5fb 100644
--- a/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
+++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-ffr-manipulation.ll
@@ -1,33 +1,51 @@
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
 
 ;
 ; RDFFR
 ;
 
-define  @rdffr() {
+define  @rdffr() #0 {
 ; CHECK-LABEL: rdffr:
-; CHECK: rdffr p0.b
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr()
   ret  %out
 }
 
-define  @rdffr_z( %pg) {
+define  @rdffr_z( %pg) #0 {
 ; CHECK-LABEL: rdffr_z:
-; CHECK: rdffr p0.b, p0/z
-; CHECK-NEXT: ret
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffr p0.b, p0/z
+; CHECK-NEXT:ret
   %out = call  @llvm.aarch64.sve.rdffr.z( 
%pg)
   ret  %out
 }
 
+; Test that rdffr.z followed by ptest optimizes to flags-setting rdffrs.
+define i1 @rdffr_z_ptest( %pg) #0 {
+; CHECK-LABEL: rdffr_z_ptest:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:rdffrs p0.b, p0/z
+; CHECK-NEXT:cset w0, ne
+; CHECK-NEXT:ret
+  %rdffr = call  @llvm.aarch64.sve.rdffr.z( %pg)
+  %out = call i1 

[PATCH] D102850: [C++4OpenCL] Allow address space conversion in reinterpret_cast

2021-05-20 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm created this revision.
olestrohm added reviewers: Anastasia, svenvh.
olestrohm added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
olestrohm requested review of this revision.
Herald added a subscriber: cfe-commits.

This fixes the prioritization of address spaces when choosing a constructor,
stopping them from being considered equally good, which made the construction
of types that could be constructed by more than one of the constructors.

It does this by preferring the most specific address space, which is decided by 
seeing
if one of the address spaces is a superset of the other, and preferring the 
other.

Fixes: PR50329


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102850

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -11,8 +11,7 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  // FIXME: __private and __generic constructors clash for __private variable
-  // X() /*__generic*/ = default;
+  X() /*__generic*/ = default;
   X() __private : x(0) {}
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
@@ -30,7 +29,7 @@
 // CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
 
 kernel void k() {
-  // Check that the constructor for px is executed
+  // Check that the constructor for px calls the __private constructor
   // CHECK: %px = alloca %struct.X
   // CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
   __private X px;
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9867,6 +9867,16 @@
S.IdentifyCUDAPreference(Caller, Cand2.Function);
   }
 
+  if (S.getLangOpts().OpenCL) {
+if (const auto *CD1 = 
dyn_cast_or_null(Cand1.Function)) {
+  if (const auto *CD2 = 
dyn_cast_or_null(Cand2.Function)) {
+return Qualifiers::isAddressSpaceSupersetOf(
+CD2->getMethodQualifiers().getAddressSpace(),
+CD1->getMethodQualifiers().getAddressSpace());
+  }
+}
+  }
+
   return false;
 }
 


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -11,8 +11,7 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  // FIXME: __private and __generic constructors clash for __private variable
-  // X() /*__generic*/ = default;
+  X() /*__generic*/ = default;
   X() __private : x(0) {}
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
@@ -30,7 +29,7 @@
 // CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
 
 kernel void k() {
-  // Check that the constructor for px is executed
+  // Check that the constructor for px calls the __private constructor
   // CHECK: %px = alloca %struct.X
   // CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
   __private X px;
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9867,6 +9867,16 @@
S.IdentifyCUDAPreference(Caller, Cand2.Function);
   }
 
+  if (S.getLangOpts().OpenCL) {
+if (const auto *CD1 = dyn_cast_or_null(Cand1.Function)) {
+  if (const auto *CD2 = dyn_cast_or_null(Cand2.Function)) {
+return Qualifiers::isAddressSpaceSupersetOf(
+CD2->getMethodQualifiers().getAddressSpace(),
+CD1->getMethodQualifiers().getAddressSpace());
+  }
+}
+  }
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102849: [flang][driver] Add support for the "-init-only" option

2021-05-20 Thread Stuart Ellis via Phabricator via cfe-commits
stuartellis created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
Herald added a reviewer: awarzynski.
stuartellis requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding the -init-only option and corresponding frontend action
to generate a diagnostic.

It also adds a Driver test to check this action.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102849

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/init-only.f90

Index: flang/test/Driver/init-only.f90
===
--- /dev/null
+++ flang/test/Driver/init-only.f90
@@ -0,0 +1,5 @@
+! Verify that -init-only flag generates a diagnostic as expected
+
+! RUN: %flang_fc1 -init-only 2>&1 | FileCheck %s
+
+! CHECK: warning: Use `-init-only` for testing purposes only
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -104,6 +104,7 @@
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -init-only Only execute frontend initialization
 ! 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 Disable predefined and command line preprocessor macros
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -73,6 +73,9 @@
   case GetSymbolsSources:
 return std::make_unique();
 break;
+  case InitializationOnly:
+return std::make_unique();
+break;
   default:
 break;
 // TODO:
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -447,3 +447,11 @@
   clang::DiagnosticsEngine::Error, "code-generation is not available yet");
   ci.diagnostics().Report(DiagID);
 }
+
+void InitializationOnlyAction::ExecuteAction() {
+  CompilerInstance  = this->instance();
+  unsigned DiagID =
+  ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
+  "Use `-init-only` for testing purposes only");
+  ci.diagnostics().Report(DiagID);
+}
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -162,9 +162,12 @@
 case clang::driver::options::OPT_fget_definition:
   opts.programAction_ = GetDefinition;
   break;
+case clang::driver::options::OPT_init_only:
+  opts.programAction_ = InitializationOnly;
+  break;
 
   // TODO:
-  // case calng::driver::options::OPT_emit_llvm:
+  // case clang::driver::options::OPT_emit_llvm:
   // case clang::driver::options::OPT_emit_llvm_only:
   // case clang::driver::options::OPT_emit_codegen_only:
   // case clang::driver::options::OPT_emit_module:
Index: flang/include/flang/Frontend/FrontendOptions.h
===
--- flang/include/flang/Frontend/FrontendOptions.h
+++ flang/include/flang/Frontend/FrontendOptions.h
@@ -71,7 +71,10 @@
   GetDefinition,
 
   /// Parse, run semantics and then dump symbol sources map
-  GetSymbolsSources
+  GetSymbolsSources,
+
+  /// Only execute frontend initialization
+  InitializationOnly
 
   /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
   /// EmitCodeGenOnly, EmitAssembly, (...)
Index: flang/include/flang/Frontend/FrontendActions.h
===
--- flang/include/flang/Frontend/FrontendActions.h
+++ flang/include/flang/Frontend/FrontendActions.h
@@ -38,6 +38,10 @@
   void ExecuteAction() override;
 };
 
+class InitializationOnlyAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 //===--===//
 // Prescan Actions
 //===--===//
Index: clang/include/clang/Driver/Options.td
===
--- 

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

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 346751.
jamieschmeiser added a comment.

Fix formatting.


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

https://reviews.llvm.org/D98798

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/Inputs/pointer-subtraction.h
  clang/test/Sema/pointer-subtraction.c
  clang/test/Sema/pointer-subtraction.cpp

Index: clang/test/Sema/pointer-subtraction.cpp
===
--- /dev/null
+++ clang/test/Sema/pointer-subtraction.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c++11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c++11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+
+#include 
+
+void a() {
+  char *f = (char *)0;
+  f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+  f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+  f = (char *)((char *)0 - (char *)0); // valid in C++
+
+#ifndef SYSTEM_WARNINGS
+  SYSTEM_MACRO(f);
+#else
+  SYSTEM_MACRO(f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+#endif
+}
Index: clang/test/Sema/pointer-subtraction.c
===
--- /dev/null
+++ clang/test/Sema/pointer-subtraction.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c11 -isystem %S/Inputs
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wnull-pointer-subtraction -std=c11 -isystem %S/Inputs -Wsystem-headers -DSYSTEM_WARNINGS
+
+#include 
+
+void a() {
+  char *f = (char *)0;
+  f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  f = (char *)((char *)0 - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+
+#ifndef SYSTEM_WARNINGS
+  SYSTEM_MACRO(f);
+#else
+  SYSTEM_MACRO(f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+#endif
+}
Index: clang/test/Sema/Inputs/pointer-subtraction.h
===
--- /dev/null
+++ clang/test/Sema/Inputs/pointer-subtraction.h
@@ -0,0 +1 @@
+#define SYSTEM_MACRO(x) (x) = (char *)((char *)0 - (x))
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10366,6 +10366,22 @@
   << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
 }
 
+/// Diagnose invalid subraction on a null pointer.
+///
+static void diagnoseSubtractionOnNullPointer(Sema , SourceLocation Loc,
+ Expr *Pointer, bool BothNull) {
+  // Null - null is valid in C++ [expr.add]p7
+  if (BothNull && S.getLangOpts().CPlusPlus)
+return;
+
+  // Is this s a macro from a system header?
+  if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc))
+return;
+
+  S.Diag(Loc, diag::warn_pointer_sub_null_ptr)
+  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+}
+
 /// Diagnose invalid arithmetic on two function pointers.
 static void diagnoseArithmeticOnTwoFunctionPointers(Sema , SourceLocation Loc,
 Expr *LHS, Expr *RHS) {
@@ -10797,7 +10813,16 @@
LHS.get(), RHS.get()))
 return QualType();
 
-  // FIXME: Add warnings for nullptr - ptr.
+  bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+  bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant(
+  Context, Expr::NPC_ValueDependentIsNotNull);
+
+  // Subtracting nullptr or from nullptr is suspect
+  if (LHSIsNullPtr)
+ 

[clang] beb5a3a - Correct some thread safety analysis diagnostics; NFC.

2021-05-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-05-20T11:30:21-04:00
New Revision: beb5a3a298a1bb2687b421cb960d36a5e9b3ad43

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

LOG: Correct some thread safety analysis diagnostics; NFC.

The diagnostics were not following the usual style rules.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/SemaCXX/warn-thread-safety-verbose.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9dd9b1b5118b..fff6b62f3b7f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3634,13 +3634,13 @@ def warn_fun_requires_lock_precise :
 def note_found_mutex_near_match : Note<"found near match '%0'">;
 
 // Verbose thread safety warnings
-def warn_thread_safety_verbose : Warning<"Thread safety verbose warning.">,
+def warn_thread_safety_verbose : Warning<"thread safety verbose warning">,
   InGroup, DefaultIgnore;
-def note_thread_warning_in_fun : Note<"Thread warning in function %0">;
-def note_guarded_by_declared_here : Note<"Guarded_by declared here.">;
+def note_thread_warning_in_fun : Note<"thread warning in function %0">;
+def note_guarded_by_declared_here : Note<"guarded_by declared here">;
 
 // Dummy warning that will trigger "beta" warnings from the analysis if 
enabled.
-def warn_thread_safety_beta : Warning<"Thread safety beta warning.">,
+def warn_thread_safety_beta : Warning<"thread safety beta warning">,
   InGroup, DefaultIgnore;
 
 // Consumed warnings

diff  --git a/clang/test/SemaCXX/warn-thread-safety-verbose.cpp 
b/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
index 2f892cd1e175..e8b229f3373b 100644
--- a/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-verbose.cpp
@@ -21,41 +21,41 @@ class LOCKABLE Mutex {
 
 class Test {
   Mutex mu;
-  int a GUARDED_BY(mu);  // expected-note3 {{Guarded_by declared here.}}
+  int a GUARDED_BY(mu);  // expected-note3 {{guarded_by declared here}}
 
   void foo1() EXCLUSIVE_LOCKS_REQUIRED(mu);
   void foo2() SHARED_LOCKS_REQUIRED(mu);
   void foo3() LOCKS_EXCLUDED(mu);
 
-  void test1() {  // expected-note {{Thread warning in function 'test1'}}
+  void test1() {  // expected-note {{thread warning in function 'test1'}}
 a = 0;// expected-warning {{writing variable 'a' requires holding 
mutex 'mu' exclusively}}
   }
 
-  void test2() {  // expected-note {{Thread warning in function 'test2'}}
+  void test2() {  // expected-note {{thread warning in function 'test2'}}
 int b = a;// expected-warning {{reading variable 'a' requires holding 
mutex 'mu'}}
   }
 
-  void test3() {  // expected-note {{Thread warning in function 'test3'}}
+  void test3() {  // expected-note {{thread warning in function 'test3'}}
 foo1();   // expected-warning {{calling function 'foo1' requires 
holding mutex 'mu' exclusively}}
   }
 
-  void test4() {  // expected-note {{Thread warning in function 'test4'}}
+  void test4() {  // expected-note {{thread warning in function 'test4'}}
 foo2();   // expected-warning {{calling function 'foo2' requires 
holding mutex 'mu'}}
   }
 
-  void test5() {  // expected-note {{Thread warning in function 'test5'}}
+  void test5() {  // expected-note {{thread warning in function 'test5'}}
 mu.ReaderLock();
 foo1();   // expected-warning {{calling function 'foo1' requires 
holding mutex 'mu' exclusively}}
 mu.Unlock();
   }
 
-  void test6() {  // expected-note {{Thread warning in function 'test6'}}
+  void test6() {  // expected-note {{thread warning in function 'test6'}}
 mu.ReaderLock();
 a = 0;// expected-warning {{writing variable 'a' requires holding 
mutex 'mu' exclusively}}
 mu.Unlock();
   }
 
-  void test7() {  // expected-note {{Thread warning in function 'test7'}}
+  void test7() {  // expected-note {{thread warning in function 'test7'}}
 mu.Lock();
 foo3();   // expected-warning {{cannot call function 'foo3' while 
mutex 'mu' is held}}
 mu.Unlock();



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


[PATCH] D100546: [ARM][AArch64] SLSHardening: make non-comdat thunks possible

2021-05-20 Thread Daniel Kiss via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
danielkiss marked an inline comment as done.
Closed by commit rG801ab71032e1: [ARM][AArch64] SLSHardening: make non-comdat 
thunks possible (authored by danielkiss).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100546

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/sls-hardening-options.c
  llvm/include/llvm/CodeGen/IndirectThunks.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSLSHardening.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
  llvm/test/CodeGen/ARM/speculation-hardening-sls.ll

Index: llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
===
--- llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
+++ llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
@@ -1,15 +1,23 @@
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,ISBDSB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,ISBDSB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,SB -dump-input-context=100
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT-OFF,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT-OFF,ISBDSB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -mattr=+sb -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT-OFF,SB -dump-input-context=100
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -mattr=harden-sls-nocomdat -mattr=+sb -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,HARDEN-COMDAT-OFF,SB -dump-input-context=100
 ; RUN: llc -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,NOHARDENARM -dump-input-context=100
 ; RUN: llc -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,NOHARDENTHUMB
-; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,ISBDSB
-; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=thumbv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,THUMB,HARDENTHUMB,HARDEN,ISBDSB
+; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s --check-prefixes=CHECK,ARM,HARDEN,HARDEN-COMDAT,ISBDSB
+; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr 

[clang] 801ab71 - [ARM][AArch64] SLSHardening: make non-comdat thunks possible

2021-05-20 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2021-05-20T17:07:05+02:00
New Revision: 801ab71032e157eb7bcd38efeb6486742a7c53bb

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

LOG: [ARM][AArch64] SLSHardening: make non-comdat thunks possible

Linker scripts might not handle COMDAT sections. SLSHardeing adds
new section for each __llvm_slsblr_thunk_xN. This new option allows
the generation of the thunks into the normal text section to handle these
exceptional cases.
,comdat or ,noncomdat can be added to harden-sls to control the codegen.
-mharden-sls=[all|retbr|blr],nocomdat.

Reviewed By: kristof.beyls

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/Driver/sls-hardening-options.c
llvm/include/llvm/CodeGen/IndirectThunks.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMSLSHardening.cpp
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
llvm/test/CodeGen/ARM/speculation-hardening-sls.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 4ce797f9bc73..503685ab533a 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -235,11 +235,17 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -248,19 +254,27 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr)
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
   // En/disable crc

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 16d72e5367f5..4ab547fabe43 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -796,11 +796,17 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
 StringRef Scope = A->getValue();
 bool EnableRetBr = false;
 bool EnableBlr = false;
-if (Scope != "none" && Scope != "all") {
+bool DisableComdat = false;
+if (Scope != "none") {
   SmallVector Opts;
   Scope.split(Opts, ",");
   for (auto Opt : Opts) {
 Opt = Opt.trim();
+if (Opt == "all") {
+  EnableBlr = true;
+  EnableRetBr = true;
+  continue;
+}
 if (Opt == "retbr") {
   EnableRetBr = true;
   continue;
@@ -809,13 +815,18 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
   EnableBlr = true;
   continue;
 }
+if (Opt == "comdat") {
+  DisableComdat = false;
+  continue;
+}
+if (Opt == "nocomdat") {
+  DisableComdat = true;
+  continue;
+}
 D.Diag(diag::err_invalid_sls_hardening)
 << Scope << A->getAsString(Args);
 break;
   }
-} else if (Scope == "all") {
-  EnableRetBr = true;
-  EnableBlr = true;
 }
 
 if (EnableRetBr || EnableBlr)
@@ -827,6 +838,9 @@ void arm::getARMTargetFeatures(const Driver , const 
llvm::Triple ,
   Features.push_back("+harden-sls-retbr");
 if (EnableBlr)
   Features.push_back("+harden-sls-blr");
+if (DisableComdat) {
+  Features.push_back("+harden-sls-nocomdat");
+}
   }
 
 }

diff  --git a/clang/test/Driver/sls-hardening-options.c 
b/clang/test/Driver/sls-hardening-options.c
index c48b694bc8b7..cb35d8b5f99d 100644

[PATCH] D102689: [C++4OpenCL] Allow address space conversion in reinterpret_cast

2021-05-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Just to move the discussion from https://reviews.llvm.org/D101519 here. First 
of all I think this change should not be OpenCL specific i.e. there is not 
reason to do something different from  C++ in general.

Embedded C doesn't regulate the conversions between non-pointer types with 
different address spaces but in OpenCL C we have allowed them apparently 
https://godbolt.org/z/9f75zxj7v. I am not sure whether this was done 
intentionally or not.

However, in C there are no references and other features that might create 
problems.

At the same time it seems C++ allows casting away const 
https://godbolt.org/z/fo3axbq3e

But it contradicts the comment in the code:

> // C++ 5.2.10p2 has a note that mentions that, subject to all other
> // restrictions, a cast to the same type is allowed so long as it does not
> // cast away constness. In C++98, the intent was not entirely clear here,
> // since all other paragraphs explicitly forbid casts to the same type.
> // C++11 clarifies this case with p2.

I would like to see if @rjmccall  has any opinion on whether reinterpreting 
between non-pointer types with different address spaces is reasonable?

In general it makes sense to follow logic for other type qualifier here but I  
was thinking of whether we can allow something weird to be written by relaxing 
this for address spaces

  local int i;
  const global int & ii = reinterpret_cast(i);

I think this code is completely meaningless as it requires creating a temporary 
in global address space? I am not sure what we will even emit in IR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102689

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


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA accepted this revision.
ZarkoCA added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


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

https://reviews.llvm.org/D100991

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


[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 346737.
tbaeder added a comment.

Use `hasFlag()` instead of `hasArg()` in Driver.cpp


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

https://reviews.llvm.org/D102479

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/lto.c


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -77,3 +77,11 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+//
+// -flto=auto and -flto=jobserver pass along -flto=full
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | 
FileCheck --check-prefix=FLTO-AUTO %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | 
FileCheck --check-prefix=FLTO-JOBSERVER %s
+//
+// FLTO-AUTO: -flto=full
+// FLTO-JOBSERVER: -flto=full
+//
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4454,7 +4454,14 @@
JA.isDeviceOffloading(Action::OFK_Host));
 
 if (D.isUsingLTO() && !isDeviceOffloadAction) {
-  Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
+  if (Args.hasArg(options::OPT_flto))
+CmdArgs.push_back("-flto");
+  else {
+if (D.getLTOMode() == LTOK_Thin)
+  CmdArgs.push_back("-flto=thin");
+else
+  CmdArgs.push_back("-flto=full");
+  }
   CmdArgs.push_back("-flto-unit");
 }
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -598,7 +598,10 @@
 void Driver::setLTOMode(const llvm::opt::ArgList ) {
   LTOMode = LTOK_None;
   if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ,
-options::OPT_fno_lto, false))
+options::OPT_fno_lto, false) &&
+  !Args.hasFlag(options::OPT_flto_EQ_auto, options::OPT_fno_lto, false) &&
+  !Args.hasFlag(options::OPT_flto_EQ_jobserver, options::OPT_fno_lto,
+false))
 return;
 
   StringRef LTOName("full");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1958,6 +1958,8 @@
   HelpText<"Force linking the clang builtins runtime library">;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
   HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
+def flto_EQ_jobserver : Flag<["-"], "flto=jobserver">, Group;
+def flto_EQ_auto : Flag<["-"], "flto=auto">, Group;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, 
Group,
@@ -4252,8 +4254,6 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
-def : Flag<["-"], "flto=auto">, Group;
-def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;


Index: clang/test/Driver/lto.c
===
--- clang/test/Driver/lto.c
+++ clang/test/Driver/lto.c
@@ -77,3 +77,11 @@
 //
 // CHECK-TUNING-LLDB:   "-plugin-opt=-debugger-tune=lldb"
 // CHECK-NO-TUNING-NOT: "-plugin-opt=-debugger-tune
+//
+// -flto=auto and -flto=jobserver pass along -flto=full
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=auto 2>&1 | FileCheck --check-prefix=FLTO-AUTO %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=jobserver 2>&1 | FileCheck --check-prefix=FLTO-JOBSERVER %s
+//
+// FLTO-AUTO: -flto=full
+// FLTO-JOBSERVER: -flto=full
+//
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4454,7 +4454,14 @@
JA.isDeviceOffloading(Action::OFK_Host));
 
 if (D.isUsingLTO() && !isDeviceOffloadAction) {
-  Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
+  if (Args.hasArg(options::OPT_flto))
+CmdArgs.push_back("-flto");
+  else {
+if (D.getLTOMode() == LTOK_Thin)
+  CmdArgs.push_back("-flto=thin");
+else
+  CmdArgs.push_back("-flto=full");
+  }
   

[PATCH] D99455: [AST] Store regular ValueDecl* in BindingDecl

2021-05-20 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 rGa5c2ec96e5f9: [AST] Store regular ValueDecl* in BindingDecl 
(NFC) (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99455

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/DeclCXX.cpp


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.


Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a5c2ec9 - [AST] Store regular ValueDecl* in BindingDecl (NFC)

2021-05-20 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2021-05-20T16:28:58+02:00
New Revision: a5c2ec96e5f9f14b31b705e40bcb267257612316

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

LOG: [AST] Store regular ValueDecl* in BindingDecl (NFC)

We were always storing a regular ValueDecl* as decomposition declaration
and haven't been using the opportunity to initialize it lazily.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c3c326b50397..07c4eb261aac 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3827,7 +3827,7 @@ class StaticAssertDecl : public Decl {
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
   /// The declaration that this binding binds to part of.
-  LazyDeclPtr Decomp;
+  ValueDecl *Decomp;
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
@@ -3853,7 +3853,7 @@ class BindingDecl : public ValueDecl {
 
   /// Get the decomposition declaration that this binding represents a
   /// decomposition of.
-  ValueDecl *getDecomposedDecl() const;
+  ValueDecl *getDecomposedDecl() const { return Decomp; }
 
   /// Get the variable (if any) that holds the value of evaluating the binding.
   /// Only present for user-defined bindings for tuple-like types.

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 3d1faee0ab11..2bb7acc21a93 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -3179,12 +3179,6 @@ BindingDecl *BindingDecl::CreateDeserialized(ASTContext 
, unsigned ID) {
   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
-ValueDecl *BindingDecl::getDecomposedDecl() const {
-  ExternalASTSource *Source =
-  Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
-  return cast_or_null(Decomp.get(Source));
-}
-
 VarDecl *BindingDecl::getHoldingVar() const {
   Expr *B = getBinding();
   if (!B)



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


[PATCH] D100991: Fix parsing of vector keyword in presence of conflicting uses.

2021-05-20 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 346722.
jamieschmeiser added a comment.

Remove unnecessary tests.


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

https://reviews.llvm.org/D100991

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/altivec-non-type-vector.c
  clang/test/Parser/altivec-template-vector.cpp
  clang/test/Parser/altivec-typedef-vector.c


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+template  class vector {
+public:
+  vector(int) {}
+};
+
+void f() {
+  vector int v = {0};
+  vector vi = {0};
+}
Index: clang/test/Parser/altivec-non-type-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-non-type-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 
powerpc-linux-gnu
+
+int vector();
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1695,6 +1695,11 @@
 break;
 
   case Sema::NC_Type: {
+if (TryAltiVecVectorToken())
+  // vector has been found as a type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 SourceLocation BeginLoc = NameLoc;
 if (SS.isNotEmpty())
   BeginLoc = SS.getBeginLoc();
@@ -1736,6 +1741,11 @@
 return ANK_Success;
 
   case Sema::NC_NonType:
+if (TryAltiVecVectorToken())
+  // vector has been found as a non-type id when altivec is enabled but
+  // this is followed by a declaration specifier so this is really the
+  // altivec vector token.  Leave it unannotated.
+  break;
 Tok.setKind(tok::annot_non_type);
 setNonTypeAnnotation(Tok, Classification.getNonTypeDecl());
 Tok.setLocation(NameLoc);


Index: clang/test/Parser/altivec-typedef-vector.c
===
--- /dev/null
+++ clang/test/Parser/altivec-typedef-vector.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu
+
+typedef int vector;
+
+void test() {
+  vector unsigned int v = {0};
+}
Index: clang/test/Parser/altivec-template-vector.cpp
===
--- /dev/null
+++ clang/test/Parser/altivec-template-vector.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu
+// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple 

[PATCH] D102791: [WebAssembly] Warn on exception spec for Emscripten EH

2021-05-20 Thread Alon Zakai via Phabricator via cfe-commits
kripken accepted this revision.
kripken added a comment.
This revision is now accepted and ready to land.

I'm not very familiar with this code, but it looks right, and sgtm to add a 
warning here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102791

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


  1   2   >