[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-15 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbca347508c86: [WebAssembly] Handle exception specifications 
(authored by aheejin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  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
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,27 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING
+
+// Wasm ignores dynamic exception specifications with types at the moment.
+// Checks if a warning message is printed.
+void test9() throw(int) {
+}
+// 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.
+void test10() throw() {
+  throw 3;
+}
+// WARNING: warning: 'test10' has a non-throwing exception specification but 
can still throw
+// WARNING: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // 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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@
 // 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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.popTerminate();
+  return;
+}
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,6 +1590,8 @@
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed 

[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-15 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin marked an inline comment as done.
aheejin added inline comments.



Comment at: clang/test/CodeGenCXX/wasm-eh.cpp:399
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+

dschuff wrote:
> aheejin wrote:
> > This was preexisting just moved
> Is it common in these tests to have RUN lines throughout the file instead of 
> all together up at the top?
Not sure how common it is, but we have similar examples, such as 
https://github.com/llvm/llvm-project/blob/master/clang/test/Driver/wasm-toolchain.c.
 I moved them mainly for readability; because now we can check what prefix 
`WARNING`'s command line is like and what `WARNING`'s check lines like, and the 
same for `ASSEMBLY`. I don't have a strong opinion for this, so if you think 
it's better to merge them at the top, please let me know, I'll do that as a 
follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[clang] 945ad14 - Revert "[WebAssembly] Handle exception specifications"

2020-05-15 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2020-05-15T21:33:44-07:00
New Revision: 945ad141ce63c94b5822d52ad76c49aba906a4b8

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

LOG: Revert "[WebAssembly] Handle exception specifications"

This reverts commit bca347508c86647f9d44992275c9a364fbd9fb0d.

This broke clang/test/Misc/warning-flags.c, because the newly added
warning option in this commit didn't have a matching flag.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c559e3e2dcf3..0fe8b1e6abfc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,8 +1590,6 @@ def err_exception_spec_cycle : Error<
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed for member of incomplete class %0">;
-def warn_wasm_dynamic_exception_spec_ignored : Warning<
-  "dynamic exception specifications with types are currently ignored in wasm">;
 
 // C++ access checking
 def err_class_redeclared_with_
diff erent_access : Error<

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index d821eb2d5595..a5dae1b32e69 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -20,7 +20,6 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
-#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -469,18 +468,6 @@ 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
-// case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
-if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
-  if (EST == EST_DynamicNone)
-EHStack.pushTerminate();
-  else
-CGM.getDiags().Report(D->getLocation(),
-  diag::warn_wasm_dynamic_exception_spec_ignored)
-<< FD->getExceptionSpecSourceRange();
-  return;
-}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -557,14 +544,6 @@ void CodeGenFunction::EmitEndEHSpec(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
-// case of throw with types, we ignore it and print a warning for now.
-// TODO Correctly handle exception specification in wasm
-if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
-  if (EST == EST_DynamicNone)
-EHStack.popTerminate();
-  return;
-}
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();

diff  --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index 9bfc41516743..2d56c6bd0cb7 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,6 +1,7 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -384,27 +385,9 @@ void test8() {
 
 // CHECK:   unreachable
 
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING
-
-// Wasm ignores dynamic exception specifications with types at the moment.
-// Checks if a warning message is printed.
-void test9() throw(int) {
-}
-// WARNING: warning: 

[clang] bca3475 - [WebAssembly] Handle exception specifications

2020-05-15 Thread Heejin Ahn via cfe-commits

Author: Heejin Ahn
Date: 2020-05-15T21:03:38-07:00
New Revision: bca347508c86647f9d44992275c9a364fbd9fb0d

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

LOG: [WebAssembly] Handle exception specifications

Summary:
Wasm currently does not fully handle exception specifications. Rather
than crashing, this treats `throw()` in the same way as `noexcept`, and
ignores and prints a warning for `throw(type, ..)`, for a temporary
measure.

Reviewers: dschuff

Subscribers: sbc100, jgravelle-google, sunfish, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/wasm-eh.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0fe8b1e6abfc..c559e3e2dcf3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,6 +1590,8 @@ def err_exception_spec_cycle : Error<
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed for member of incomplete class %0">;
+def warn_wasm_dynamic_exception_spec_ignored : Warning<
+  "dynamic exception specifications with types are currently ignored in wasm">;
 
 // C++ access checking
 def err_class_redeclared_with_
diff erent_access : Error<

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index a5dae1b32e69..d821eb2d5595 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@ 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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@ void CodeGenFunction::EmitEndEHSpec(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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.popTerminate();
+  return;
+}
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();

diff  --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index 2d56c6bd0cb7..9bfc41516743 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,27 @@ void test8() {
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 

[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:264
+def warn_union_tail_padding_uninitialized : Warning<
+  "Initializing union %0 field %1 only initializes the first %2 of %3 bytes, 
leaving the remaining %4 bytes undefined">,
+  InGroup;

Something which I'm not sure matters:

```
union Unnamed {
  union {
int i;
float f;
  };
  char bytes[8];
};

union Unnamed unnamed = { 42 };
```

Will generate the following diagnostic:

```
warning: Initializing union 'Unnamed' field '' only initializes the first 4 of 
8 bytes, leaving the remaining 4 bytes undefined [-Wunion-tail-padding]
union Unnamed unnamed = { 42 };
^
```

I think that's generally how we handle unnamed members anyways?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80055



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


[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:825
+def Padding : DiagGroup<"padding", [UnionTailPadding]>,
+  DiagCategory<"Padding Issue">;
+

I'd like to hear what other diagnostics folks think should fit under the 
`Padding` group. I've focused not on declarations which have padding, but 
rather on initializations which leave uninitialized padding behind. It seems 
like internal padding for structs and between array elements would be desirable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80055



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


[PATCH] D68115: Zero initialize padding in unions

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

To get this unblocked a bit, I implemented a diagnostic: 
https://reviews.llvm.org/D80055


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: clang/test/CodeGen/union-tail-padding.c:28-36
+union Front {
+  int i;
+  long long ll;
+};
+
+union Front front1;
+union Front front2 = {};// expected-warning {{Initializing union 
'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the 
remaining 4 bytes undefined}}

dexonsmith wrote:
> Are these warnings actionable?  What should users do when they see this 
> warning?
Good point!

I was thinking about this, and was wondering if I should add a fixit which 
suggests using the first wider member of the union. The problem is to offer the 
same object representation... that's tricky on its own (there isn't always an 
exact match), and then we have to deal with type punning (in C++, not in C).

So I'd love ideas, because I'm not sure what to do. That being said, I wrote 
this partly because D68115 was surprising to folks, and partly because 
developers would like to opt-in to this diagnostic to find places where 
initialization isn't doing what they think.

Maybe instead we should suggest to leave uninitialized, and use an assignment, 
or `memset`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80055



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


[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/test/CodeGen/union-tail-padding.c:28-36
+union Front {
+  int i;
+  long long ll;
+};
+
+union Front front1;
+union Front front2 = {};// expected-warning {{Initializing union 
'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the 
remaining 4 bytes undefined}}

Are these warnings actionable?  What should users do when they see this warning?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80055



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


[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:71-72
+   binaryOperator(hasOperatorName("=="),
+  hasEitherOperand(ignoringParenImpCasts(StringNpos)),
+  hasEitherOperand(ignoringParenImpCasts(StringFind))),
+   change(cat("!absl::StrContains(", node("string_being_searched"),

njames93 wrote:
> This is dangerous, it will match on `std::string::npos == std::string::npos` 
> and (more importantly) `strA.find(...) == strB.find(...)`. See D80054.
Ignore me, its late.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:1-2
+//===--- StringFindStrContainsCheck.cc - clang-tidy---*- C++
+//-*-===//
+//

Don't need the C++ specifier in a cpp file.
```
//===--- StringFindStrContainsCheck.cpp - clang-tidy 
--===//```



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:71-72
+   binaryOperator(hasOperatorName("=="),
+  hasEitherOperand(ignoringParenImpCasts(StringNpos)),
+  hasEitherOperand(ignoringParenImpCasts(StringFind))),
+   change(cat("!absl::StrContains(", node("string_being_searched"),

This is dangerous, it will match on `std::string::npos == std::string::npos` 
and (more importantly) `strA.find(...) == strB.find(...)`. See D80054.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:78-79
+   binaryOperator(hasOperatorName("!="),
+  hasEitherOperand(ignoringParenImpCasts(StringNpos)),
+  hasEitherOperand(ignoringParenImpCasts(StringFind))),
+   change(cat("absl::StrContains(", node("string_being_searched"), ", 
",

Same as above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: clang/test/CodeGen/union-tail-padding.c:9
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++17 -triple 
aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++2a -triple 
aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+

This test, while it might be surprising, is testing the current behavior of 
clang. I haven't validated that it's correct for each standard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80055



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


[PATCH] D80054: [ASTMatchers] Added BinaryOperator hasOperands matcher

2020-05-15 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: klimek, aaron.ballman, gribozavr2, alexfh.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds a matcher called `hasOperands` for `BinaryOperator`'s when you need to 
match both sides but the order isn't important, usually on commutative 
operators.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80054

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


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1160,6 +1160,17 @@
   EXPECT_TRUE(notMatches("void x() { true || true; }", HasOperand));
 }
 
+TEST(MatchBinaryOperator, HasOperands) {
+  StatementMatcher HasOperands = binaryOperator(
+  hasOperands(integerLiteral(equals(1)), integerLiteral(equals(2;
+  EXPECT_TRUE(matches("void x() { 1 + 2; }", HasOperands));
+  EXPECT_TRUE(matches("void x() { 2 + 1; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 1 + 1; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 2 + 2; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 0 + 0; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 0 + 1; }", HasOperands));
+}
+
 TEST(Matcher, BinaryOperatorTypes) {
   // Integration test that verifies the AST provides all binary operators in
   // a way we expect.
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -294,6 +294,7 @@
   REGISTER_MATCHER(hasName);
   REGISTER_MATCHER(hasNullSelector);
   REGISTER_MATCHER(hasObjectExpression);
+  REGISTER_MATCHER(hasOperands);
   REGISTER_MATCHER(hasOperatorName);
   REGISTER_MATCHER(hasOverloadedOperatorName);
   REGISTER_MATCHER(hasParameter);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4869,6 +4869,23 @@
   return anyOf(hasLHS(InnerMatcher), hasRHS(InnerMatcher));
 }
 
+/// Matches if both matchers match with opposite sides of the binary operator.
+///
+/// Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),
+///  integerLiteral(equals(2)))
+/// \code
+///   1 + 2 // Match
+///   2 + 1 // Match
+///   1 + 1 // No match
+///   2 + 2 // No match
+/// \endcode
+inline internal::Matcher
+hasOperands(const internal::Matcher ,
+const internal::Matcher ) {
+  return anyOf(allOf(hasLHS(Matcher1), hasRHS(Matcher2)),
+   allOf(hasLHS(Matcher2), hasRHS(Matcher1)));
+}
+
 /// Matches if the operand of a unary operator matches.
 ///
 /// Example matches true (matcher = hasUnaryOperand(
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -5033,6 +5033,18 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html;>BinaryOperatorhasOperandsMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr  
Matcher1, Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr  
Matcher2
+Matches if both 
matchers match with opposite sides of the binary operator.
+
+Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),
+ integerLiteral(equals(2)))
+  1 + 2 // Match
+  2 + 1 // Match
+  1 + 1 // No match
+  2 + 2 // No match
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html;>BinaryOperatorhasRHSMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr 
InnerMatcher
 Matches the right hand side 
of binary operator expressions.
 


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1160,6 +1160,17 @@
   EXPECT_TRUE(notMatches("void x() { true || true; }", HasOperand));
 }
 
+TEST(MatchBinaryOperator, HasOperands) {
+  StatementMatcher HasOperands = binaryOperator(
+  hasOperands(integerLiteral(equals(1)), integerLiteral(equals(2;
+  EXPECT_TRUE(matches("void x() { 1 + 2; }", HasOperands));
+  EXPECT_TRUE(matches("void x() { 2 + 1; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 1 + 1; }", HasOperands));
+  EXPECT_TRUE(notMatches("void x() { 2 + 2; }", HasOperands));
+  

[PATCH] D80055: Diagnose union tail padding

2020-05-15 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
jfb added reviewers: rsmith, hubert.reinterpretcast.
Herald added subscribers: cfe-commits, ributzka, dexonsmith, jkorous.
Herald added a project: clang.
jfb marked an inline comment as done.
jfb added inline comments.



Comment at: clang/test/CodeGen/union-tail-padding.c:9
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++17 -triple 
aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++2a -triple 
aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+

This test, while it might be surprising, is testing the current behavior of 
clang. I haven't validated that it's correct for each standard.


>From a discussion in D68115 , it seems like 
>union tail padding is often surprising to folks, compiler implementors 
>included. This new diagnostic, -Wunion-tail-padding, emits a diagnostic when a 
>union's tail is left undefined when develoeprs might have reasonably expected 
>that it would not be. I've included -Wunion-tail-padding under the umbrella of 
>a new diagnostic group, -Wpadding, since it often seems like padding in 
>general is a source of pain. In particular, padding can leak secret 
>information to malicious attackers. Here we focus on the places where padding 
>is *unitialized*, not where a structure or union has padding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80055

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ConstantEmitter.h
  clang/test/CodeGen/union-tail-padding.c

Index: clang/test/CodeGen/union-tail-padding.c
===
--- /dev/null
+++ clang/test/CodeGen/union-tail-padding.c
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -Wunion-tail-padding -std=c99 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -std=c11 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -std=c17 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++98 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++03 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++11 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++14 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++17 -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+// RUN: %clang_cc1 -Wunion-tail-padding -xc++ -std=c++2a -triple aarch64-apple-darwin %s -emit-llvm -o /dev/null -verify
+
+union OK {
+  char c;
+  unsigned char uc;
+};
+
+union OK ok1;
+union OK ok2 = {};
+union OK ok3 = {42};
+union OK ok4 = {.c = 42};
+union OK ok5 = {.uc = 42};
+#if defined(__cplusplus)
+OK ok6 = OK();
+#if __cplusplus >= 201103
+OK ok7 = OK{};
+#endif
+#endif
+
+union Front {
+  int i;
+  long long ll;
+};
+
+union Front front1;
+union Front front2 = {};// expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+union Front front3 = {42};  // expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+union Front front4 = {.i = 42}; // expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+union Front front5 = {.ll = 42};
+#if defined(__cplusplus)
+#if __cplusplus < 201103
+Front front6 = Front();
+#elif __cplusplus < 201703
+Front front6 = Front(); // expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+Front front7 = Front{}; // expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+#else
+Front front6 = Front();
+Front front7 = Front{}; // expected-warning {{Initializing union 'Front' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+#endif
+#endif
+
+union Back {
+  long long ll;
+  int i;
+};
+
+union Back back1;
+union Back back2 = {};
+union Back back3 = {42};
+union Back back4 = {.i = 42}; // expected-warning {{Initializing union 'Back' field 'i' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined}}
+union Back back5 = {.ll = 42};
+#if defined(__cplusplus)
+Back back6 = Back();
+#if __cplusplus >= 201103
+Back back7 = Back{};
+#endif
+#endif

[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264397.
vitalybuka added a comment.

module flag


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-safe-flag.cpp
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/Other/new-pm-lto-defaults.ll

Index: llvm/test/Other/new-pm-lto-defaults.ll
===
--- llvm/test/Other/new-pm-lto-defaults.ll
+++ llvm/test/Other/new-pm-lto-defaults.ll
@@ -61,6 +61,7 @@
 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
 ; CHECK-O-NEXT: Running pass: GlobalSplitPass
 ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
+; CHECK-O-NEXT: Running pass: StackSafetyGlobalAnnotatorPass
 ; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PromotePass>
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/IR/DataLayout.h"
@@ -916,6 +917,10 @@
   // Apply whole-program devirtualization and virtual constant propagation.
   PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  PM.add(createStackSafetyGlobalInfoWrapperPass(
+  /*SetMetadata=*/true, /*Optional=*/true));
+
   // That's all we need at opt level 1.
   if (OptLevel == 1)
 return;
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -96,7 +96,7 @@
 MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
 MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
 MODULE_PASS("poison-checking", PoisonCheckingPass())
-MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass())
+MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass(/*Optional=*/false))
 #undef MODULE_PASS
 
 #ifndef CGSCC_ANALYSIS
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1288,6 +1288,9 @@
   // is fixed.
   MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  MPM.addPass(StackSafetyGlobalAnnotatorPass(true));
+
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
 // The LowerTypeTestsPass needs to run to lower type metadata and the
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -603,6 +603,12 @@
   return Changed;
 }
 
+bool isMetadataNeeded(const Module ) {
+  auto *CI =
+  mdconst::extract_or_null(M.getModuleFlag("stack-safe"));
+  return CI && CI->getZExtValue();
+}
+
 } // end anonymous namespace
 
 StackSafetyInfo::StackSafetyInfo() = default;
@@ -676,6 +682,8 @@
 
 PreservedAnalyses
 StackSafetyGlobalAnnotatorPass::run(Module , ModuleAnalysisManager ) {
+  if (Optional && !isMetadataNeeded(M))
+return PreservedAnalyses::all();
   auto  = AM.getResult(M);
   (void)setStackSafetyMetadata(M, SSGI);
   return PreservedAnalyses::all();
@@ -684,8 +692,8 @@
 char StackSafetyGlobalInfoWrapperPass::ID = 0;
 
 StackSafetyGlobalInfoWrapperPass::StackSafetyGlobalInfoWrapperPass(
-bool SetMetadata)
-: ModulePass(ID), SetMetadata(SetMetadata) {
+bool SetMetadata, bool Optional)
+: ModulePass(ID), SetMetadata(SetMetadata), Optional(Optional) {
   initializeStackSafetyGlobalInfoWrapperPassPass(
   *PassRegistry::getPassRegistry());
 }
@@ -701,6 +709,9 @@
 }
 
 bool StackSafetyGlobalInfoWrapperPass::runOnModule(Module ) {
+  if (Optional && !isMetadataNeeded(M))
+return false;
+
   StackSafetyDataFlowAnalysis SSDFA(
   M, [this](Function ) -> const StackSafetyInfo & {
 return getAnalysis(F).getResult();
@@ -709,8 +720,9 @@
   return SetMetadata ? setStackSafetyMetadata(M, SSGI) : false;
 }
 
-ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata) {
-  return new 

[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264399.
vitalybuka added a comment.

typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-safe-flag.cpp
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/Other/new-pm-lto-defaults.ll

Index: llvm/test/Other/new-pm-lto-defaults.ll
===
--- llvm/test/Other/new-pm-lto-defaults.ll
+++ llvm/test/Other/new-pm-lto-defaults.ll
@@ -61,6 +61,7 @@
 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
 ; CHECK-O-NEXT: Running pass: GlobalSplitPass
 ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
+; CHECK-O-NEXT: Running pass: StackSafetyGlobalAnnotatorPass
 ; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PromotePass>
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/IR/DataLayout.h"
@@ -916,6 +917,10 @@
   // Apply whole-program devirtualization and virtual constant propagation.
   PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  PM.add(createStackSafetyGlobalInfoWrapperPass(
+  /*SetMetadata=*/true, /*Optional=*/true));
+
   // That's all we need at opt level 1.
   if (OptLevel == 1)
 return;
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -96,7 +96,7 @@
 MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
 MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
 MODULE_PASS("poison-checking", PoisonCheckingPass())
-MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass())
+MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass(/*Optional=*/false))
 #undef MODULE_PASS
 
 #ifndef CGSCC_ANALYSIS
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1288,6 +1288,9 @@
   // is fixed.
   MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  MPM.addPass(StackSafetyGlobalAnnotatorPass(true));
+
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
 // The LowerTypeTestsPass needs to run to lower type metadata and the
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -603,6 +603,12 @@
   return Changed;
 }
 
+bool isMetadataNeeded(const Module ) {
+  auto *CI =
+  mdconst::extract_or_null(M.getModuleFlag("stack-safe"));
+  return CI && CI->getZExtValue();
+}
+
 } // end anonymous namespace
 
 StackSafetyInfo::StackSafetyInfo() = default;
@@ -676,6 +682,8 @@
 
 PreservedAnalyses
 StackSafetyGlobalAnnotatorPass::run(Module , ModuleAnalysisManager ) {
+  if (Optional && !isMetadataNeeded(M))
+return PreservedAnalyses::all();
   auto  = AM.getResult(M);
   (void)setStackSafetyMetadata(M, SSGI);
   return PreservedAnalyses::all();
@@ -684,8 +692,8 @@
 char StackSafetyGlobalInfoWrapperPass::ID = 0;
 
 StackSafetyGlobalInfoWrapperPass::StackSafetyGlobalInfoWrapperPass(
-bool SetMetadata)
-: ModulePass(ID), SetMetadata(SetMetadata) {
+bool SetMetadata, bool Optional)
+: ModulePass(ID), SetMetadata(SetMetadata), Optional(Optional) {
   initializeStackSafetyGlobalInfoWrapperPassPass(
   *PassRegistry::getPassRegistry());
 }
@@ -701,6 +709,9 @@
 }
 
 bool StackSafetyGlobalInfoWrapperPass::runOnModule(Module ) {
+  if (Optional && !isMetadataNeeded(M))
+return false;
+
   StackSafetyDataFlowAnalysis SSDFA(
   M, [this](Function ) -> const StackSafetyInfo & {
 return getAnalysis(F).getResult();
@@ -709,8 +720,9 @@
   return SetMetadata ? setStackSafetyMetadata(M, SSGI) : false;
 }
 
-ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata) {
-  return new 

[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264398.
vitalybuka added a comment.

new line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-safe-flag.cpp
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/Other/new-pm-lto-defaults.ll

Index: llvm/test/Other/new-pm-lto-defaults.ll
===
--- llvm/test/Other/new-pm-lto-defaults.ll
+++ llvm/test/Other/new-pm-lto-defaults.ll
@@ -61,6 +61,7 @@
 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
 ; CHECK-O-NEXT: Running pass: GlobalSplitPass
 ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
+; CHECK-O-NEXT: Running pass: StackSafetyGlobalAnnotatorPass
 ; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PromotePass>
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/IR/DataLayout.h"
@@ -916,6 +917,10 @@
   // Apply whole-program devirtualization and virtual constant propagation.
   PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  PM.add(createStackSafetyGlobalInfoWrapperPass(
+  /*SetMetadata=*/true, /*Optional=*/true));
+
   // That's all we need at opt level 1.
   if (OptLevel == 1)
 return;
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -96,7 +96,7 @@
 MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
 MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
 MODULE_PASS("poison-checking", PoisonCheckingPass())
-MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass())
+MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass(/*Optional=*/false))
 #undef MODULE_PASS
 
 #ifndef CGSCC_ANALYSIS
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1288,6 +1288,9 @@
   // is fixed.
   MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  MPM.addPass(StackSafetyGlobalAnnotatorPass(true));
+
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
 // The LowerTypeTestsPass needs to run to lower type metadata and the
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -603,6 +603,12 @@
   return Changed;
 }
 
+bool isMetadataNeeded(const Module ) {
+  auto *CI =
+  mdconst::extract_or_null(M.getModuleFlag("stack-safe"));
+  return CI && CI->getZExtValue();
+}
+
 } // end anonymous namespace
 
 StackSafetyInfo::StackSafetyInfo() = default;
@@ -676,6 +682,8 @@
 
 PreservedAnalyses
 StackSafetyGlobalAnnotatorPass::run(Module , ModuleAnalysisManager ) {
+  if (Optional && !isMetadataNeeded(M))
+return PreservedAnalyses::all();
   auto  = AM.getResult(M);
   (void)setStackSafetyMetadata(M, SSGI);
   return PreservedAnalyses::all();
@@ -684,8 +692,8 @@
 char StackSafetyGlobalInfoWrapperPass::ID = 0;
 
 StackSafetyGlobalInfoWrapperPass::StackSafetyGlobalInfoWrapperPass(
-bool SetMetadata)
-: ModulePass(ID), SetMetadata(SetMetadata) {
+bool SetMetadata, bool Optional)
+: ModulePass(ID), SetMetadata(SetMetadata), Optional(Optional) {
   initializeStackSafetyGlobalInfoWrapperPassPass(
   *PassRegistry::getPassRegistry());
 }
@@ -701,6 +709,9 @@
 }
 
 bool StackSafetyGlobalInfoWrapperPass::runOnModule(Module ) {
+  if (Optional && !isMetadataNeeded(M))
+return false;
+
   StackSafetyDataFlowAnalysis SSDFA(
   M, [this](Function ) -> const StackSafetyInfo & {
 return getAnalysis(F).getResult();
@@ -709,8 +720,9 @@
   return SetMetadata ? setStackSafetyMetadata(M, SSGI) : false;
 }
 
-ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata) {
-  return new 

[PATCH] D79916: Map -O to -O1 instead of -O2

2020-05-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added reviewers: arphaman, Gerolf.
dexonsmith accepted this revision.
dexonsmith added a comment.

IOW, this LGTM if Alex and Gerolf are happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916



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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-05-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added subscribers: arphaman, Gerolf.
dexonsmith added a comment.



In D79916#2039789 , @echristo wrote:

> I'm totally down, but you knew that already :)
>
> Duncan: Do you have any concerns? I doubt it, but just checking.


Xcode doesn't use `-O`. There could be some internal users, but I doubt it, and 
we can probably migrate them if this causes a problem.  @arphaman, WDYT?

@Gerolf, I don't imagine you have any concerns, but thought I should 
double-check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916



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


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 264394.
yaxunl marked an inline comment as done.
yaxunl added a comment.

fix constexpr var in templates


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

https://reviews.llvm.org/D79237

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCUDA/constexpr-variables.cu
  clang/test/SemaCUDA/constexpr-variables.cu

Index: clang/test/SemaCUDA/constexpr-variables.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/constexpr-variables.cu
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - -triple nvptx64-nvidia-cuda \
+// RUN:   -fcuda-is-device -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - -triple nvptx64-nvidia-cuda \
+// RUN:   -fcuda-is-device -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - \
+// RUN:   -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - \
+// RUN:   -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
+#include "Inputs/cuda.h"
+
+template
+__host__ __device__ void foo(const T **a) {
+  // expected-note@-1 {{declared here}}
+  static const T b = sizeof(a);
+  static constexpr T c = sizeof(a);
+  const T d = sizeof(a);
+  constexpr T e = sizeof(a);
+  constexpr T f = **a;
+  // expected-error@-1 {{constexpr variable 'f' must be initialized by a constant expression}}
+  // expected-note@-2 {{read of non-constexpr variable 'a' is not allowed in a constant expression}}
+  a[0] = 
+  a[1] = 
+  a[2] = 
+  a[3] = 
+}
+
+__device__ void device_fun(const int **a) {
+  // expected-note@-1 {{declared here}}
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  constexpr int d = **a;
+  // expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
+  // expected-note@-2 {{read of non-constexpr variable 'a' is not allowed in a constant expression}}
+  a[0] = 
+  a[1] = 
+  foo(a);
+  // expected-note@-1 {{in instantiation of function template specialization 'foo' requested here}}
+}
+
+void host_fun(const int **a) {
+  // expected-note@-1 {{declared here}}
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  constexpr int d = **a;
+  // expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
+  // expected-note@-2 {{read of non-constexpr variable 'a' is not allowed in a constant expression}}
+  a[0] = 
+  a[1] = 
+  foo(a);
+}
+
+__host__ __device__ void host_device_fun(const int **a) {
+  // expected-note@-1 {{declared here}}
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  constexpr int d = **a;
+  // expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
+  // expected-note@-2 {{read of non-constexpr variable 'a' is not allowed in a constant expression}}
+  a[0] = 
+  a[1] = 
+  foo(a);
+}
+
+template 
+struct A {
+  explicit A() = default;
+};
+template 
+constexpr A a{};
+
+struct B {
+  static constexpr bool value = true;
+};
+
+template
+struct C {
+  static constexpr bool value = T::value;
+};
+
+__constant__ const bool  = C::value;
Index: clang/test/CodeGenCUDA/constexpr-variables.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/constexpr-variables.cu
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - -triple nvptx \
+// RUN:   -fcuda-is-device | FileCheck --check-prefixes=CXX14 %s
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - -triple nvptx \
+// RUN:   -fcuda-is-device | FileCheck --check-prefixes=CXX17 %s
+
+#include "Inputs/cuda.h"
+
+// COM: @_ZL1a = internal {{.*}}constant i32 7
+constexpr int a = 7;
+__constant__ const int _a = a;
+
+namespace B {
+ // COM: @_ZN1BL1bE = internal {{.*}}constant i32 9
+  constexpr int b = 9;
+}
+__constant__ const int _B_b = B::b;
+
+struct Q {
+  // CXX14: @_ZN1Q2k2E = {{.*}}externally_initialized constant i32 6
+  // CXX17: @_ZN1Q2k2E = internal {{.*}}constant i32 6
+  // CXX14: @_ZN1Q2k1E = available_externally {{.*}}constant i32 5
+  // CXX17: @_ZN1Q2k1E = linkonce_odr {{.*}}constant i32 5
+  static constexpr int k1 = 5;
+  static constexpr int k2 = 6;
+};
+constexpr int Q::k2;
+
+__constant__ const int _Q_k1 = Q::k1;
+__constant__ const int _Q_k2 = Q::k2;
+
+template struct X {
+  // CXX14: @_ZN1XIiE1aE = available_externally {{.*}}constant i32 123
+  // CXX17: @_ZN1XIiE1aE = linkonce_odr {{.*}}constant i32 123
+  static constexpr int a = 123;
+};
+__constant__ const int _X_a = X::a;
+
+template  struct A {
+  // CXX14: @_ZN1AIiLi1ELi2EE1xE = available_externally {{.*}}constant i32 2
+  // CXX17: @_ZN1AIiLi1ELi2EE1xE = linkonce_odr {{.*}}constant i32 2
+  constexpr static T x = a * b;
+};
+__constant__ const int  = A::x;
Index: 

[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

> It could also be better, instead of iterating over all functions, simply run 
> the global pass, but make sure that it does not do too much work on 
> non-sanitize_memtag functions. I.e. the function pass should bail out on such 
> functions, and then the data flow will have no data to run on, so that should 
> also be pretty fast.

Actually I don't think it's right this to do. Function pass is analysis. If 
it's not needed, just don't query it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046



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


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In D79237#2039757 , @rsmith wrote:

> In D79237#2039559 , @tra wrote:
>
> > In D79237#2039417 , @tra wrote:
> >
> > >
> >
> >
> > Bad news -- it breaks the standard C++ library.
>
>
> [...]
>
> >   build/release+assert+zapcc/bin/../include/c++/v1/utility:937:51: error: 
> > dynamic initialization is not supported for __device__, __constant__, and 
> > __shared__ variables.
> >   _LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
> > ^~~
>
> This looks like a bug in that diagnostic: the instantiations of this variable 
> template certainly do not have dynamic initialization. The diagnostic is 
> missing an "in instantiation of" note, so I think the bug is that we're 
> performing this check on a dependent variable prior to instantiation. 
> Presumably we should delay the check to instantiation time if either the type 
> of the variable is dependent or the initializer is value-dependent.


right. fixed


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

https://reviews.llvm.org/D79237



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


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/test/SemaCUDA/constexpr-variables.cu:30-31
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);

tra wrote:
> yaxunl wrote:
> > tra wrote:
> > > Can we verify the diags for bad cases, too?
> > By bad cases you mean the constexpr var is not compile time constant?
> It's a general suggestion. It's good to have some negative testing thrown in, 
> too to make sure we didn't do too much by mistake.  E.g. allowing all 
> variables to become `__constant__` would be bad. :-)
> 
> I'm not sure what exactly would be a good addition here. If you can't think 
> of something, I guess we can leave it as is. C++ is largely oblivoius of 
> `__constant__`, so we may not have much to work with. It's probably 
> observable, but may be an overkill for the test.
> 
added tests where initializer is not compile time constant


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

https://reviews.llvm.org/D79237



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


[PATCH] D79916: Map -O to -O1 instead of -O2

2020-05-15 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a reviewer: dexonsmith.
echristo added a comment.
This revision is now accepted and ready to land.

I'm totally down, but you knew that already :)

Duncan: Do you have any concerns? I doubt it, but just checking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79916



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


[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

I think this is an OK approach.
Perhaps a module flag would be even better, then it can be decoupled from 
"sanitize_memtag", and it would not require iterating over the entire module. 
You can check how it is used in CFI: !"CFI Canonical Jump Tables".

It could also be better, instead of iterating over all functions, simply run 
the global pass, but make sure that it does not do too much work on 
non-sanitize_memtag functions. I.e. the function pass should bail out on such 
functions, and then the data flow will have no data to run on, so that should 
also be pretty fast.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046



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


[clang-tools-extra] 7af0c85 - [clang-tidy] Transformer checks now store IncludeStyle option

2020-05-15 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-05-16T01:14:55+01:00
New Revision: 7af0c8559b6d9426dd5e977370516d2baa4c206f

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

LOG: [clang-tidy] Transformer checks now store IncludeStyle option

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index 3f7edd659c63..a15c429b696f 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -112,6 +112,12 @@ void TransformerClangTidyCheck::check(
   }
 }
 
+void TransformerClangTidyCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle", IncludeStyle,
+IncludeSorter::getMapping());
+}
+
 } // namespace utils
 } // namespace tidy
 } // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
index 796222373eb5..d99f927a7973 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -67,6 +67,10 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) final;
   void check(const ast_matchers::MatchFinder::MatchResult ) final;
 
+  /// Derived classes that override this function should call this method from
+  /// the overridden method.
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
 private:
   Optional Rule;
   const IncludeSorter::IncludeStyle IncludeStyle;



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in both clang and llvm

2020-05-15 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

I believe we're also missing `IsISA3_1 = false;` in `PPCSubtarget.cpp`.




Comment at: llvm/lib/Target/PowerPC/PPC.td:338
+  // still exist with the exception of those we know are Power9 specific.
+  list P10AdditionalFeatures = [DirectivePwr10];
+  list P10SpecificFeatures =

Are we missing `FeatureISA3_1` in `P10AdditionalFeatures`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80020



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


[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264386.
vitalybuka added a comment.

pm test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80046

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/Other/new-pm-lto-defaults.ll

Index: llvm/test/Other/new-pm-lto-defaults.ll
===
--- llvm/test/Other/new-pm-lto-defaults.ll
+++ llvm/test/Other/new-pm-lto-defaults.ll
@@ -61,6 +61,7 @@
 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
 ; CHECK-O-NEXT: Running pass: GlobalSplitPass
 ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
+; CHECK-O-NEXT: Running pass: StackSafetyGlobalAnnotatorPass
 ; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PromotePass>
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/IR/DataLayout.h"
@@ -916,6 +917,10 @@
   // Apply whole-program devirtualization and virtual constant propagation.
   PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  PM.add(createStackSafetyGlobalInfoWrapperPass(
+  /*SetMetadata=*/true, /*Optional=*/true));
+
   // That's all we need at opt level 1.
   if (OptLevel == 1)
 return;
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -96,7 +96,7 @@
 MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
 MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
 MODULE_PASS("poison-checking", PoisonCheckingPass())
-MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass())
+MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass(/*Optional=*/false))
 #undef MODULE_PASS
 
 #ifndef CGSCC_ANALYSIS
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1288,6 +1288,9 @@
   // is fixed.
   MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  MPM.addPass(StackSafetyGlobalAnnotatorPass(true));
+
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
 // The LowerTypeTestsPass needs to run to lower type metadata and the
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -603,6 +603,13 @@
   return Changed;
 }
 
+bool hasInterestingFunctions(const Module ) {
+  for (auto  : M.functions())
+if (F.hasFnAttribute(Attribute::SanitizeMemTag))
+  return true;
+  return false;
+}
+
 } // end anonymous namespace
 
 StackSafetyInfo::StackSafetyInfo() = default;
@@ -676,6 +683,8 @@
 
 PreservedAnalyses
 StackSafetyGlobalAnnotatorPass::run(Module , ModuleAnalysisManager ) {
+  if (Optional && !hasInterestingFunctions(M))
+return PreservedAnalyses::all();
   auto  = AM.getResult(M);
   (void)setStackSafetyMetadata(M, SSGI);
   return PreservedAnalyses::all();
@@ -684,8 +693,8 @@
 char StackSafetyGlobalInfoWrapperPass::ID = 0;
 
 StackSafetyGlobalInfoWrapperPass::StackSafetyGlobalInfoWrapperPass(
-bool SetMetadata)
-: ModulePass(ID), SetMetadata(SetMetadata) {
+bool SetMetadata, bool Optional)
+: ModulePass(ID), SetMetadata(SetMetadata), Optional(Optional) {
   initializeStackSafetyGlobalInfoWrapperPassPass(
   *PassRegistry::getPassRegistry());
 }
@@ -701,6 +710,9 @@
 }
 
 bool StackSafetyGlobalInfoWrapperPass::runOnModule(Module ) {
+  if (Optional && !hasInterestingFunctions(M))
+return false;
+
   StackSafetyDataFlowAnalysis SSDFA(
   M, [this](Function ) -> const StackSafetyInfo & {
 return getAnalysis(F).getResult();
@@ -709,8 +721,9 @@
   return SetMetadata ? setStackSafetyMetadata(M, SSGI) : false;
 }
 
-ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata) {
-  return new StackSafetyGlobalInfoWrapperPass(SetMetadata);

[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D79237#2039559 , @tra wrote:

> In D79237#2039417 , @tra wrote:
>
> >
>
>
> Bad news -- it breaks the standard C++ library.


[...]

>   build/release+assert+zapcc/bin/../include/c++/v1/utility:937:51: error: 
> dynamic initialization is not supported for __device__, __constant__, and 
> __shared__ variables.
>   _LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
> ^~~

This looks like a bug in that diagnostic: the instantiations of this variable 
template certainly do not have dynamic initialization. The diagnostic is 
missing an "in instantiation of" note, so I think the bug is that we're 
performing this check on a dependent variable prior to instantiation. 
Presumably we should delay the check to instantiation time if either the type 
of the variable is dependent or the initializer is value-dependent.


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

https://reviews.llvm.org/D79237



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


[PATCH] D80046: [StackSafety] Make full LTO to attach metadata if MTE is enabled

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, steven_wu, 
hiraditya, inglorion.
Herald added projects: clang, LLVM.

Depends on D80039 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80046

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/IR/DataLayout.h"
@@ -916,6 +917,10 @@
   // Apply whole-program devirtualization and virtual constant propagation.
   PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  PM.add(createStackSafetyGlobalInfoWrapperPass(
+  /*SetMetadata=*/true, /*Optional=*/true));
+
   // That's all we need at opt level 1.
   if (OptLevel == 1)
 return;
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -96,7 +96,7 @@
 MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false))
 MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass())
 MODULE_PASS("poison-checking", PoisonCheckingPass())
-MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass())
+MODULE_PASS("stack-safety-annotator", StackSafetyGlobalAnnotatorPass(/*Optional=*/false))
 #undef MODULE_PASS
 
 #ifndef CGSCC_ANALYSIS
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1288,6 +1288,9 @@
   // is fixed.
   MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
 
+  // Add stack safety metatada if needed.
+  MPM.addPass(StackSafetyGlobalAnnotatorPass(true));
+
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
 // The LowerTypeTestsPass needs to run to lower type metadata and the
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -603,6 +603,13 @@
   return Changed;
 }
 
+bool hasInterestingFunctions(const Module ) {
+  for (auto  : M.functions())
+if (F.hasFnAttribute(Attribute::SanitizeMemTag))
+  return true;
+  return false;
+}
+
 } // end anonymous namespace
 
 StackSafetyInfo::StackSafetyInfo() = default;
@@ -676,6 +683,8 @@
 
 PreservedAnalyses
 StackSafetyGlobalAnnotatorPass::run(Module , ModuleAnalysisManager ) {
+  if (Optional && !hasInterestingFunctions(M))
+return PreservedAnalyses::all();
   auto  = AM.getResult(M);
   (void)setStackSafetyMetadata(M, SSGI);
   return PreservedAnalyses::all();
@@ -684,8 +693,8 @@
 char StackSafetyGlobalInfoWrapperPass::ID = 0;
 
 StackSafetyGlobalInfoWrapperPass::StackSafetyGlobalInfoWrapperPass(
-bool SetMetadata)
-: ModulePass(ID), SetMetadata(SetMetadata) {
+bool SetMetadata, bool Optional)
+: ModulePass(ID), SetMetadata(SetMetadata), Optional(Optional) {
   initializeStackSafetyGlobalInfoWrapperPassPass(
   *PassRegistry::getPassRegistry());
 }
@@ -701,6 +710,9 @@
 }
 
 bool StackSafetyGlobalInfoWrapperPass::runOnModule(Module ) {
+  if (Optional && !hasInterestingFunctions(M))
+return false;
+
   StackSafetyDataFlowAnalysis SSDFA(
   M, [this](Function ) -> const StackSafetyInfo & {
 return getAnalysis(F).getResult();
@@ -709,8 +721,9 @@
   return SetMetadata ? setStackSafetyMetadata(M, SSGI) : false;
 }
 
-ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata) {
-  return new StackSafetyGlobalInfoWrapperPass(SetMetadata);
+ModulePass *llvm::createStackSafetyGlobalInfoWrapperPass(bool SetMetadata,
+ bool Optional) {
+  return new StackSafetyGlobalInfoWrapperPass(SetMetadata, Optional);
 }
 
 static const char LocalPassArg[] = "stack-safety-local";
Index: llvm/include/llvm/Analysis/StackSafetyAnalysis.h
===
--- llvm/include/llvm/Analysis/StackSafetyAnalysis.h
+++ llvm/include/llvm/Analysis/StackSafetyAnalysis.h
@@ -98,11 +98,16 @@
   

[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/test/SemaCUDA/constexpr-variables.cu:30-31
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);

yaxunl wrote:
> tra wrote:
> > Can we verify the diags for bad cases, too?
> By bad cases you mean the constexpr var is not compile time constant?
It's a general suggestion. It's good to have some negative testing thrown in, 
too to make sure we didn't do too much by mistake.  E.g. allowing all variables 
to become `__constant__` would be bad. :-)

I'm not sure what exactly would be a good addition here. If you can't think of 
something, I guess we can leave it as is. C++ is largely oblivoius of 
`__constant__`, so we may not have much to work with. It's probably observable, 
but may be an overkill for the test.



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

https://reviews.llvm.org/D79237



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


[PATCH] D79942: [clang] Add an API to retrieve implicit constructor arguments.

2020-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

This looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79942



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


[PATCH] D80031: [clang-format] [NFC] release note placed in the wrong location and other rst linting errors

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:114
+  this occurs when the use of the ``extern`` keyword is neglected in the
+  declaration
   of a variable in a header file. In some cases, no specific translation unit

Eugene.Zelenko wrote:
> This and next line should be merged.
I knew you'd be perfect to review this...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80031



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


[PATCH] D79121: Add nomerge function attribute to clang

2020-05-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Ping


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

https://reviews.llvm.org/D79121



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


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-05-15 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3434-3435
+  if (Stack->getDefaultDSA() == DSA_firstprivate &&
+  VD->getStorageDuration() == SD_Static &&
+  CanonicalVD->getDeclContext()->isFileContext() &&
   !Stack->isLoopControlVariable(VD).first) {

ABataev wrote:
> Hmm, maybe move this check to `getDSA()`? If you do it, you can just modify 
> the check on line 3322 
> ```
>   if (DVar.CKind == OMPC_unknown && (Stack->getDefaultDSA() == DSA_none 
> || (Stack->getDefaultDSA() == DSA_firstprivate && 
> !Stack->isLoopControlVariable(VD).first)) &&
>   isImplicitOrExplicitTaskingRegion(DKind) &&
>   VarsWithInheritedDSA.count(VD) == 0) {
> VarsWithInheritedDSA[VD] = E;
> return;
>   }
> ```
Didn't we move it this far down to avoid processing it before all of the 
target-directive relevant checks?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3441-3446
+  // Create implicit firstprivate variables as necessary under
+  // default(firstprivate).
+  if (Stack->getDefaultDSA() == DSA_firstprivate) {
 ImplicitFirstprivate.push_back(E);
 return;
   }

ABataev wrote:
> Hmm, not sure that this check is needed here, the next if statement should 
> handle it already, no? `DVar.CKind` is set to `OMPC_firstprivate` and the 
> next check must work.
It doesn't work directly but I can simplify it further and merge them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75591



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


[PATCH] D80041: [clang-format] [PR45198] deletes whitespace inside of a noexcept specifier

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, rianquinn, JakeMerdichAMD, 
mitchell-stellar.
MyDeveloperDay added projects: clang, clang-format.

https://bugs.llvm.org/show_bug.cgi?id=45198

The following:

  template<
  typename T,
  enable_if_t::value> = true,
  enable_if_t::value> = true>
  constexpr void
  swap(T , T ) noexcept(
  is_nothrow_move_constructible::value && 
is_nothrow_move_assignable::value)

Results in this:

  template<
  typename T,
  enable_if_t::value> = true,
  enable_if_t::value> = true>
  constexpr void
  swap(T , T ) noexcept(
  is_nothrow_move_constructible::value 
&_nothrow_move_assignable::value)

This is because the `&&` in `is_nothrow_move_constructible::value 
&_nothrow_move_assignable::value` gets incorrectly determined to be a 
TT_PointerOrReference

This revision attempts to detect determine a cases where this cannot be true 
especially in a `noexcept` context where the result is expected to be boolean


https://reviews.llvm.org/D80041

Files:
  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
@@ -8005,6 +8005,8 @@
   verifyFormat("@[ [NSArray class] ];");
   verifyFormat("@[ [foo enum] ];");
 
+  verifyFormat("template  [[nodiscard]] int a() { return 1; }");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
@@ -8091,6 +8093,37 @@
   verifyFormat("#define A(a, b) (a && b)");
 }
 
+TEST_F(FormatTest, BinaryOperationsInANoExceptContext) {
+  verifyFormat("int f(int &) {}");
+  verifyFormat("template  void swap() noexcept(Bar && Foo);");
+  verifyFormat(
+  "template  void swap() noexcept(Bar::value && Foo);");
+  verifyFormat("template  void swap() noexcept(Bar::value && "
+   "Foo::value);");
+  verifyFormat("template  void foo(Bar::value &);");
+  verifyFormat("template  void swap() noexcept(Bar::value && "
+   "std::Foo);");
+  verifyFormat(
+  "template  void foo(Bar::value &, Foo &);");
+  verifyFormat("template  void swap() noexcept(Bar &);");
+  verifyFormat(
+  "template  void swap() noexcept(Bar && std::Foo);");
+  verifyFormat("template  void foo(Bar &, Foo &);");
+  verifyFormat("template  void swap() noexcept(Bar && b);");
+  verifyFormat(
+  "template  void swap() noexcept(Bar && std::Foo);");
+  verifyFormat("template  void foo(Bar &, Foo &);");
+  verifyFormat(
+  "template  void swap() noexcept(Bar() && Foo());");
+
+  verifyFormat("template  void swap() noexcept(a && b);");
+  verifyFormat("template  void swap() noexcept(/*A*/ a && b);");
+  verifyFormat("template  void swap() noexcept(a && b /*A*/);");
+  verifyFormat(
+  "template  void swap() noexcept(/*A*/ a && /*A*/ b);");
+  verifyFormat("template  void foo(Bar &);");
+}
+
 TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {
   verifyFormat("void f() {\n"
"  x[a -\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1918,8 +1918,32 @@
 return TT_BinaryOperator;
 }
 
-// It is very unlikely that we are going to find a pointer or reference type
-// definition on the RHS of an assignment.
+// Try to distinguish (A && B) from (A &), which is ambiguous without
+// other semantic information
+// However in a noexcept context where it is going to be a boolean
+// operation noexcept(A && b) resulting in a binary operation
+if (Tok.is(tok::ampamp) && PrevToken &&
+PrevToken->isOneOf(tok::identifier, TT_TemplateCloser) && NextToken) {
+  const FormatToken *NextNextToken = NextToken->getNextNonComment();
+  const FormatToken *PrevPrevToken = PrevToken->getPreviousNonComment();
+  if (NextToken->is(tok::identifier)) {
+if (NextNextToken && NextNextToken->isOneOf(tok::less, tok::coloncolon))
+  return TT_BinaryOperator;
+if (PrevPrevToken) {
+  const FormatToken *PrevPrevPrevToken =
+  PrevPrevToken->getPreviousNonComment();
+  // We already know its `x y identifier && identifer z`
+  // just need to confirm x,y,z
+  if (PrevPrevPrevToken && PrevPrevPrevToken->is(tok::kw_noexcept) &&
+  PrevPrevToken->is(tok::l_paren) &&
+  NextNextToken->is(tok::r_paren))
+return TT_BinaryOperator;
+}
+  }
+}
+
+// It is very unlikely that we are going to find a pointer or reference
+// type definition on the RHS of an assignment.
 if (IsExpression && !Contexts.back().CaretFound)
   

[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-15 Thread Derek Schuff via Phabricator via cfe-commits
dschuff accepted this revision.
dschuff added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeGenCXX/wasm-eh.cpp:399
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+

aheejin wrote:
> This was preexisting just moved
Is it common in these tests to have RUN lines throughout the file instead of 
all together up at the top?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-05-15 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 264365.
atmnpatel added a comment.

Necessary cleanups and adds a basic check for static local variables and static 
data members.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75591

Files:
  clang-tools-extra/docs/clang-tidy/checks/openmp-use-default-none.rst
  clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/driver.c
  clang/test/OpenMP/parallel_default_messages.cpp
  clang/test/OpenMP/parallel_for_default_messages.cpp
  clang/test/OpenMP/parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_master_default_messages.cpp
  clang/test/OpenMP/parallel_sections_default_messages.cpp
  clang/test/OpenMP/target_parallel_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/target_teams_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/task_default_messages.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/teams_default_messages.cpp
  clang/test/OpenMP/teams_distribute_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_default_messages.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -536,6 +536,7 @@
 
 __OMP_DEFAULT_KIND(none)
 __OMP_DEFAULT_KIND(shared)
+__OMP_DEFAULT_KIND(firstprivate)
 __OMP_DEFAULT_KIND(unknown)
 
 #undef __OMP_DEFAULT_KIND
Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -314,6 +314,20 @@
   return matchesConditionally(Code, AMatcher, false, "-fopenmp=libomp");
 }
 
+template 
+testing::AssertionResult matchesWithOpenMP51(const std::string ,
+ const T ) {
+  return matchesConditionally(Code, AMatcher, true,
+  {"-fopenmp=libomp", "-fopenmp-version=51"});
+}
+
+template 
+testing::AssertionResult notMatchesWithOpenMP51(const std::string ,
+const T ) {
+  return matchesConditionally(Code, AMatcher, false,
+  {"-fopenmp=libomp", "-fopenmp-version=51"});
+}
+
 template 
 testing::AssertionResult
 matchAndVerifyResultConditionally(const std::string , const T ,
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1843,11 +1843,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP51(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(MatchFinderAPI, matchesDynamic) {
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2819,11 +2819,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP51(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  

[PATCH] D80039: [NFC, StackSafety] LTO tests for MTE and StackSafety

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264361.
vitalybuka added a comment.

comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80039

Files:
  clang/test/Driver/memtag_lto.c

Index: clang/test/Driver/memtag_lto.c
===
--- /dev/null
+++ clang/test/Driver/memtag_lto.c
@@ -0,0 +1,147 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: rm -f %t*
+
+// -O1, no tagging: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+
+// Full LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -O1 \
+// RUN:  -r %t.lto1.bc,fn,plx \
+// RUN:  -r %t.lto1.bc,use,lx \
+// RUN:  -r %t.lto1.bc,use_local,plx \
+// RUN:  -r %t.lto1.bc,w, \
+// RUN:  -r %t.lto2.bc,use,plx \
+// RUN:  -r %t.lto2.bc,z,
+// RUN: llvm-dis %t.lto.0.5.precodegen.bc -o - | FileCheck %s
+
+// Full LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.ltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.ltonewpm1.bc,fn,plx \
+// RUN:  -r %t.ltonewpm1.bc,use,lx \
+// RUN:  -r %t.ltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.ltonewpm1.bc,w, \
+// RUN:  -r %t.ltonewpm2.bc,use,plx \
+// RUN:  -r %t.ltonewpm2.bc,z,
+// RUN: llvm-dis %t.ltonewpm.0.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinlto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinlto2.bc
+// RUN: llvm-lto2 run -o %t.thinlto %t.thinlto1.bc %t.thinlto2.bc -save-temps -O1 \
+// RUN:  -r %t.thinlto1.bc,fn,plx \
+// RUN:  -r %t.thinlto1.bc,use,lx \
+// RUN:  -r %t.thinlto1.bc,use_local,plx \
+// RUN:  -r %t.thinlto1.bc,w, \
+// RUN:  -r %t.thinlto2.bc,use,plx \
+// RUN:  -r %t.thinlto2.bc,z,
+// RUN: llvm-dis %t.thinlto.1.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.thinltonewpm1.bc,fn,plx \
+// RUN:  -r %t.thinltonewpm1.bc,use,lx \
+// RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.thinltonewpm1.bc,w, \
+// RUN:  -r %t.thinltonewpm2.bc,use,plx \
+// RUN:  -r %t.thinltonewpm2.bc,z,
+// RUN: llvm-dis %t.thinltonewpm.1.5.precodegen.bc -o - | FileCheck %s
+
+// Now with MTE.
+// RUN: rm -f %t*
+
+// -O0: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+
+// No LTO: just one is safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+
+// Full LTO: both are safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -O1 \
+// RUN:  -r %t.lto1.bc,fn,plx \
+// RUN:  -r %t.lto1.bc,use,lx \
+// RUN:  -r %t.lto1.bc,use_local,plx \
+// RUN:  -r %t.lto1.bc,w, \
+// RUN:  -r %t.lto2.bc,use,plx \
+// RUN:  -r %t.lto2.bc,z,
+// FIXME: Must be -check-prefixes=XSAFE,YSAFE
+// RUN: llvm-dis %t.lto.0.5.precodegen.bc -o - | FileCheck %s 

[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-05-15 Thread Zhi Zhuang via Phabricator via cfe-commits
LukeZhuang updated this revision to Diff 264357.
LukeZhuang added a comment.

updated 05/15/2020:
(1) add documents about __builtin_expect_with_probability
(2) modify SemaChecking to handle evaluate constant floating-point expression
(3) modify CGBuiltin to evaluate constant floating-point argument before 
passing it


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

https://reviews.llvm.org/D79830

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-expect-with-probability-switch.c
  clang/test/CodeGen/builtin-expect-with-probability.c
  llvm/docs/BranchWeightMetadata.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Index: llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
===
--- llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -55,13 +55,32 @@
 "unlikely-branch-weight", cl::Hidden, cl::init(1),
 cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
 
+std::pair setBranchWeight(Intrinsic::ID IntrinsicID,
+  CallInst *CI, int BranchCount) {
+  if (IntrinsicID == Intrinsic::expect) {
+// __builtin_expect
+return {LikelyBranchWeight, UnlikelyBranchWeight};
+  } else {
+// __builtin_expect_with_probability
+assert(CI->getNumOperands() >= 3 &&
+   "expect with probability must have 3 arguments");
+ConstantFP *Confidence = dyn_cast(CI->getArgOperand(2));
+double TrueProb = Confidence->getValueAPF().convertToDouble();
+double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
+uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
+uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
+return {LikelyBW, UnlikelyBW};
+  }
+}
+
 static bool handleSwitchExpect(SwitchInst ) {
   CallInst *CI = dyn_cast(SI.getCondition());
   if (!CI)
 return false;
 
   Function *Fn = CI->getCalledFunction();
-  if (!Fn || Fn->getIntrinsicID() != Intrinsic::expect)
+  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
+  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
 return false;
 
   Value *ArgValue = CI->getArgOperand(0);
@@ -71,15 +90,20 @@
 
   SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
   unsigned n = SI.getNumCases(); // +1 for default case.
-  SmallVector Weights(n + 1, UnlikelyBranchWeight);
+  std::pair WeightNums =
+  setBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
+  uint32_t LikelyBranchWeightVal = WeightNums.first;
+  uint32_t UnlikelyBranchWeightVal = WeightNums.second;
+
+  SmallVector Weights(n + 1, UnlikelyBranchWeightVal);
 
   uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
-  Weights[Index] = LikelyBranchWeight;
+  Weights[Index] = LikelyBranchWeightVal;
 
-  SI.setMetadata(
-  LLVMContext::MD_misexpect,
-  MDBuilder(CI->getContext())
-  .createMisExpect(Index, LikelyBranchWeight, UnlikelyBranchWeight));
+  SI.setMetadata(LLVMContext::MD_misexpect,
+ MDBuilder(CI->getContext())
+ .createMisExpect(Index, LikelyBranchWeightVal,
+  UnlikelyBranchWeightVal));
 
   SI.setCondition(ArgValue);
   misexpect::checkFrontendInstrumentation(SI);
@@ -223,15 +247,19 @@
 return true;
   return false;
 };
+std::pair WeightNums = setBranchWeight(
+Expect->getCalledFunction()->getIntrinsicID(), Expect, 2);
+uint32_t LikelyBranchWeightVal = WeightNums.first;
+uint32_t UnlikelyBranchWeightVal = WeightNums.second;
 
 if (IsOpndComingFromSuccessor(BI->getSuccessor(1)))
-  BI->setMetadata(
-  LLVMContext::MD_prof,
-  MDB.createBranchWeights(LikelyBranchWeight, UnlikelyBranchWeight));
+  BI->setMetadata(LLVMContext::MD_prof,
+  MDB.createBranchWeights(LikelyBranchWeightVal,
+  UnlikelyBranchWeightVal));
 else if (IsOpndComingFromSuccessor(BI->getSuccessor(0)))
-  BI->setMetadata(
-  LLVMContext::MD_prof,
-  MDB.createBranchWeights(UnlikelyBranchWeight, LikelyBranchWeight));
+  BI->setMetadata(LLVMContext::MD_prof,
+  MDB.createBranchWeights(UnlikelyBranchWeightVal,
+  LikelyBranchWeightVal));
   }
 }
 
@@ -277,7 +305,8 @@
   }
 
   Function *Fn = CI->getCalledFunction();
-  if (!Fn || Fn->getIntrinsicID() != Intrinsic::expect)
+  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
+  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
 return false;
 
   Value *ArgValue = CI->getArgOperand(0);
@@ -289,13 +318,22 @@
   MDNode *Node;
 

[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-05-15 Thread Zhi Zhuang via Phabricator via cfe-commits
LukeZhuang marked 15 inline comments as done.
LukeZhuang added inline comments.



Comment at: clang/include/clang/Basic/Builtins.def:567
 BUILTIN(__builtin_expect, "LiLiLi"   , "nc")
+BUILTIN(__builtin_expect_with_probability, "LiLiLid"   , "nc")
 BUILTIN(__builtin_prefetch, "vvC*.", "nc")

rsmith wrote:
> I assume we don't have any equivalent of the `I` flag to require a 
> floating-point constant expression? If not, it's probably not worth adding 
> that if this builtin would be the only user of it.
Seems there is currently no tag for constant floating-point



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2195
+Value *ExpectedValue = EmitScalarExpr(E->getArg(1));
+Value *Confidence = EmitScalarExpr(E->getArg(2));
+// Don't generate llvm.expect.with.probability on -O0 as the backend

rsmith wrote:
> LukeZhuang wrote:
> > rsmith wrote:
> > > If the intrinsic expects a `ConstantFP` value, this isn't enough to 
> > > guarantee that you get one (the set of cases that we fold to constants 
> > > during expression emission is much smaller than the set of cases we can 
> > > constant-evaluate). You should run the constant evaluator first, to 
> > > produce an `APFloat`, then emit that value as a constant. (Optionally you 
> > > can form a `ConstantExpr` as part of the check in `Sema` and store the 
> > > value in that object rather than recomputing it here.)
> > Thank you for commenting! I have a question about this. If I check this 
> > argument can be fold as constant float in `Sema`, why I need to check it 
> > here? Or do you mean I had better create a `ConstantFP` value here after 
> > constant emitting? 
> `EmitScalarExpr` will emit arbitrary IR that evaluates the argument. If the 
> argument isn't a simple floating-point literal, then you won't necessarily 
> get an IR-level constant back from that. For example:
> 
> ```
> struct die {
>   constexpr int sides() { return 6; }
>   int roll();
> } d6;
> bool rolled_a_one = __builtin_expect_with_probability(d6.roll(), 1, 1.0 / 
> d6.sides());
> ```
> 
> Here, we can evaluate `1.0 / d6.sides()`, but `EmitScalarExpr` will emit a 
> function call and a division, not a constant.
> 
> Instead, you could use `EvaluateAsFloat` here (you can assert it succeeds 
> because you already checked that in `Sema`) and then directly form a 
> `ConstantFP` from the `APFloat` result.
Fixed in lastest patch



Comment at: clang/lib/Sema/SemaChecking.cpp:1805
+const Expr *ProbArg = TheCall->getArg(2);
+if (ProbArg->EvaluateAsFloat(Confidence, Context)) {
+  double P = Confidence.convertToDouble();

rsmith wrote:
> LukeZhuang wrote:
> > LukeZhuang wrote:
> > > rsmith wrote:
> > > > What rules should be applied here? Do we just want to allow anything 
> > > > that we can evaluate (which might change over time), or do we want to 
> > > > use the underlying language's notion of floating-point constant 
> > > > expressions, if it has them?
> > > Thank you for commenting. I just read the llvm::Expr document and found 
> > > that it just have `isIntegerConstantExpr` without a float-point version. 
> > > Under `EvaluateAsFloat` it says "Return true if this is a constant which 
> > > we can fold and convert to a floating point value", thus I use this 
> > > function. Is there any better function to achieve this goal?
> > Hi, and I didn't find other builtin functions ever handle case like this, 
> > is there any example I could refer to?
> I think this is the first builtin (and maybe the first part of Clang) that 
> wants to enforce that it sees a floating-point constant expression.
> 
> The right thing to do is generally to call `EvaluateAsConstantExpr` and check 
> that it produces the right kind of value and doesn't generate any notes. See 
> the code at the end of `CheckConvertedConstantExpr` for how to do this.
> 
> You also need to check that `ProbArg` is not value-dependent before you try 
> to evaluate it; it's not meaningful to ask for the value of a value-dependent 
> expression.
fixed in lastest patch



Comment at: clang/lib/Sema/SemaChecking.cpp:1806
+if (ProbArg->EvaluateAsFloat(Confidence, Context)) {
+  double P = Confidence.convertToDouble();
+  if (P < 0.0 || P > 1.0) {

rsmith wrote:
> Converting to a host `double` here seems suspicious and unnecessary: can you 
> form a suitable `APFloat` representation of `1.0` and `0.0` instead, and 
> compare to those?
fixed in lastest patch



Comment at: clang/lib/Sema/SemaChecking.cpp:1807
+  double P = Confidence.convertToDouble();
+  if (P < 0.0 || P > 1.0) {
+Diag(ProbArg->getLocStart(), diag::err_probability_out_of_range)

rsmith wrote:
> This does not disallow NaN values. I think you want `if (!(P >= 0.0 && P <= 
> 1.0))` or equivalent instead.
fixed in lastest patch



Comment at: 

[PATCH] D80039: [NFC, StackSafety] LTO tests for MTE and StackSafety

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 264360.
vitalybuka added a comment.

remove fixme


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80039

Files:
  clang/test/Driver/memtag_lto.c

Index: clang/test/Driver/memtag_lto.c
===
--- /dev/null
+++ clang/test/Driver/memtag_lto.c
@@ -0,0 +1,147 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: rm -f %t*
+
+// -O1, no tagging: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+
+// Full LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -O1 \
+// RUN:  -r %t.lto1.bc,fn,plx \
+// RUN:  -r %t.lto1.bc,use,lx \
+// RUN:  -r %t.lto1.bc,use_local,plx \
+// RUN:  -r %t.lto1.bc,w, \
+// RUN:  -r %t.lto2.bc,use,plx \
+// RUN:  -r %t.lto2.bc,z,
+// RUN: llvm-dis %t.lto.0.5.precodegen.bc -o - | FileCheck %s
+
+// Full LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.ltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.ltonewpm1.bc,fn,plx \
+// RUN:  -r %t.ltonewpm1.bc,use,lx \
+// RUN:  -r %t.ltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.ltonewpm1.bc,w, \
+// RUN:  -r %t.ltonewpm2.bc,use,plx \
+// RUN:  -r %t.ltonewpm2.bc,z,
+// RUN: llvm-dis %t.ltonewpm.0.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinlto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinlto2.bc
+// RUN: llvm-lto2 run -o %t.thinlto %t.thinlto1.bc %t.thinlto2.bc -save-temps -O1 \
+// RUN:  -r %t.thinlto1.bc,fn,plx \
+// RUN:  -r %t.thinlto1.bc,use,lx \
+// RUN:  -r %t.thinlto1.bc,use_local,plx \
+// RUN:  -r %t.thinlto1.bc,w, \
+// RUN:  -r %t.thinlto2.bc,use,plx \
+// RUN:  -r %t.thinlto2.bc,z,
+// RUN: llvm-dis %t.thinlto.1.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.thinltonewpm1.bc,fn,plx \
+// RUN:  -r %t.thinltonewpm1.bc,use,lx \
+// RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.thinltonewpm1.bc,w, \
+// RUN:  -r %t.thinltonewpm2.bc,use,plx \
+// RUN:  -r %t.thinltonewpm2.bc,z,
+// RUN: llvm-dis %t.thinltonewpm.1.5.precodegen.bc -o - | FileCheck %s
+
+// Now with taging.
+// RUN: rm -f %t*
+
+// -O0: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+
+// No LTO: just one is safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+
+// Full LTO: both are safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -O1 \
+// RUN:  -r %t.lto1.bc,fn,plx \
+// RUN:  -r %t.lto1.bc,use,lx \
+// RUN:  -r %t.lto1.bc,use_local,plx \
+// RUN:  -r %t.lto1.bc,w, \
+// RUN:  -r %t.lto2.bc,use,plx \
+// RUN:  -r %t.lto2.bc,z,
+// FIXME: Must be -check-prefixes=XSAFE,YSAFE
+// RUN: llvm-dis %t.lto.0.5.precodegen.bc -o - | 

[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D79237#2039417 , @tra wrote:

> LGTM in general. Let me check the patch on our tensorflow build.


Bad news -- it breaks the standard C++ library.

Reproducer:

  $ bin/clang++ -x cuda /dev/null -fsyntax-only -include algorithm 
--cuda-path=$HOME/local/cuda-10.1 --cuda-device-only --cuda-gpu-arch=sm_60 
-std=c++17 -stdlib=libc++  
tra@art3:~/work/llvm/build/release+assert+zapcc
  
  In file included from :2:
  In file included from 
build/release+assert+zapcc/lib/clang/11.0.0/include/cuda_wrappers/algorithm:55:
  In file included from 
build/release+assert+zapcc/bin/../include/c++/v1/algorithm:642:
  build/release+assert+zapcc/bin/../include/c++/v1/utility:937:51: error: 
dynamic initialization is not supported for __device__, __constant__, and 
__shared__ variables.
  _LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
^~~
  build/release+assert+zapcc/bin/../include/c++/v1/utility:944:53: error: 
dynamic initialization is not supported for __device__, __constant__, and 
__shared__ variables.
  _LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
  ^ ~~
  2 errors generated when compiling for sm_60.


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

https://reviews.llvm.org/D79237



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


[PATCH] D80039: [NFC, StackSafety] LTO tests for MTE and StackSafety

2020-05-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: cfe-commits, dexonsmith, steven_wu, hiraditya, 
inglorion.
Herald added a project: clang.
vitalybuka updated this revision to Diff 264360.
vitalybuka added a comment.
vitalybuka updated this revision to Diff 264361.
vitalybuka edited the summary of this revision.

remove fixme


vitalybuka added a comment.

comment


The test demonstrates the current state of the compiler and
I am going to resolve FIXME in followup patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80039

Files:
  clang/test/Driver/memtag_lto.c

Index: clang/test/Driver/memtag_lto.c
===
--- /dev/null
+++ clang/test/Driver/memtag_lto.c
@@ -0,0 +1,147 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: rm -f %t*
+
+// -O1, no tagging: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -S -emit-llvm -c %s -o - | FileCheck %s
+
+// Full LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -O1 \
+// RUN:  -r %t.lto1.bc,fn,plx \
+// RUN:  -r %t.lto1.bc,use,lx \
+// RUN:  -r %t.lto1.bc,use_local,plx \
+// RUN:  -r %t.lto1.bc,w, \
+// RUN:  -r %t.lto2.bc,use,plx \
+// RUN:  -r %t.lto2.bc,z,
+// RUN: llvm-dis %t.lto.0.5.precodegen.bc -o - | FileCheck %s
+
+// Full LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.ltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.ltonewpm1.bc,fn,plx \
+// RUN:  -r %t.ltonewpm1.bc,use,lx \
+// RUN:  -r %t.ltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.ltonewpm1.bc,w, \
+// RUN:  -r %t.ltonewpm2.bc,use,plx \
+// RUN:  -r %t.ltonewpm2.bc,z,
+// RUN: llvm-dis %t.ltonewpm.0.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinlto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinlto2.bc
+// RUN: llvm-lto2 run -o %t.thinlto %t.thinlto1.bc %t.thinlto2.bc -save-temps -O1 \
+// RUN:  -r %t.thinlto1.bc,fn,plx \
+// RUN:  -r %t.thinlto1.bc,use,lx \
+// RUN:  -r %t.thinlto1.bc,use_local,plx \
+// RUN:  -r %t.thinlto1.bc,w, \
+// RUN:  -r %t.thinlto2.bc,use,plx \
+// RUN:  -r %t.thinlto2.bc,z,
+// RUN: llvm-dis %t.thinlto.1.5.precodegen.bc -o - | FileCheck %s
+
+// Thin LTO, new PM: both are unsafe.
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinltonewpm1.bc
+// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
+// RUN: llvm-lto2 run -use-new-pm -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -O1 \
+// RUN:  -r %t.thinltonewpm1.bc,fn,plx \
+// RUN:  -r %t.thinltonewpm1.bc,use,lx \
+// RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
+// RUN:  -r %t.thinltonewpm1.bc,w, \
+// RUN:  -r %t.thinltonewpm2.bc,use,plx \
+// RUN:  -r %t.thinltonewpm2.bc,z,
+// RUN: llvm-dis %t.thinltonewpm.1.5.precodegen.bc -o - | FileCheck %s
+
+// Now with MTE.
+// RUN: rm -f %t*
+
+// -O0: both are unsafe.
+// RUN: %clang -fno-experimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+// RUN: %clang-fexperimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s
+
+// No LTO: just one is safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+// RUN: %clang-fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -S -emit-llvm -c %s -o - | FileCheck %s -check-prefixes=XUNSAFE,YSAFE
+
+// Full LTO: both are safe.
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=full -o %t.lto1.bc
+// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=full -o %t.lto2.bc
+// 

[libunwind] b31cb3a - unwind: fix unwind build without heap

2020-05-15 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2020-05-15T14:45:22-07:00
New Revision: b31cb3aa5ee7ea92d830b06a0a7e42c7f2791dd4

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

LOG: unwind: fix unwind build without heap

Add a missing guard for `_LIBUNWIND_NO_HEAP` around code dealing with the
`.cfi_remember_state` and `.cfi_restore_state` instructions.

Patch by Amanieu d'Antras!

Added: 


Modified: 
libunwind/src/DwarfParser.hpp

Removed: 




diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 4a64c219255c..d05ac468367f 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -401,6 +401,7 @@ bool CFI_Parser::parseFDEInstructions(A ,
 fdeInfo.fdeStart + fdeInfo.fdeLength, cieInfo,
 upToPC - fdeInfo.pcStart, rememberStack, arch, 
results);
 
+#if !defined(_LIBUNWIND_NO_HEAP)
   // Clean up rememberStack. Even in the case where every DW_CFA_remember_state
   // is paired with a DW_CFA_restore_state, parseInstructions can skip restore
   // opcodes if it reaches the target PC and stops interpreting, so we have to
@@ -410,6 +411,7 @@ bool CFI_Parser::parseFDEInstructions(A ,
 free(rememberStack);
 rememberStack = next;
   }
+#endif
 
   return returnValue;
 }



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


[PATCH] D79694: [tests][Driver] Set `--sysroot=""` to allow `DEFAULT_SYSROOT` build

2020-05-15 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG15f0f824b36e: [tests][Driver] Set `--sysroot=` 
to allow `DEFAULT_SYSROOT` build (authored by hubert.reinterpretcast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79694

Files:
  clang/test/Driver/darwin-header-search-libcxx.cpp
  clang/test/Driver/darwin-header-search-system.cpp
  clang/test/Driver/mingw-sysroot.cpp


Index: clang/test/Driver/mingw-sysroot.cpp
===
--- clang/test/Driver/mingw-sysroot.cpp
+++ clang/test/Driver/mingw-sysroot.cpp
@@ -17,7 +17,7 @@
 // If we find a gcc in the path with the right triplet prefix, pick that as
 // sysroot:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %clang -target 
x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ -c -### %s 2>&1 | 
FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
+// 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"
@@ -27,7 +27,7 @@
 // If there's a matching sysroot next to the clang binary itself, prefer that
 // over a gcc in the path:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
 // CHECK_TESTROOT_CLANG: 
"{{.*}}/testroot-clang{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 
@@ -35,4 +35,4 @@
 // happens to be in the same directory as gcc, make sure we still can pick up
 // the libgcc directory:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-gcc/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=platform -stdlib=libstdc++ -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-gcc/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC %s
Index: clang/test/Driver/darwin-header-search-system.cpp
===
--- clang/test/Driver/darwin-header-search-system.cpp
+++ clang/test/Driver/darwin-header-search-system.cpp
@@ -95,6 +95,7 @@
 // RUN: -target x86_64-apple-darwin \
 // RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot="" \
 // RUN:   | FileCheck -DRESOURCE=%S/Inputs/resource_dir \
 // RUN:   --check-prefix=CHECK-NOSYSROOT %s
 // CHECK-NOSYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -20,6 +20,7 @@
 // RUN: -target x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN: --sysroot="" \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain 
--check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s
 // CHECK-LIBCXX-TOOLCHAIN-1: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
 // CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"


Index: clang/test/Driver/mingw-sysroot.cpp
===
--- clang/test/Driver/mingw-sysroot.cpp
+++ clang/test/Driver/mingw-sysroot.cpp
@@ -17,7 +17,7 @@
 // If we find a gcc in the path with the right triplet prefix, pick that as
 // sysroot:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %clang -target x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
+// 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: 

[PATCH] D79693: [test][ARM][CMSE] Use clang_cc1 in arm_cmse.h tests

2020-05-15 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3f5fc73a9d52: [test][ARM][CMSE] Use clang_cc1 in arm_cmse.h 
tests (authored by hubert.reinterpretcast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79693

Files:
  clang/test/CodeGen/arm-cmse-nonsecure.c
  clang/test/CodeGen/arm-cmse-secure.c


Index: clang/test/CodeGen/arm-cmse-secure.c
===
--- clang/test/CodeGen/arm-cmse-secure.c
+++ clang/test/CodeGen/arm-cmse-secure.c
@@ -1,5 +1,5 @@
-// RUN: %clang -mlittle-endian -mcmse -target thumbv8m.base-eabi -emit-llvm -S 
-o - %s | FileCheck %s
-// RUN: %clang -mbig-endian-mcmse -target thumbv8m.base-eabi -emit-llvm -S 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm 
-mrelocation-model static -mcmse -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm 
-mrelocation-model static -mcmse -o - %s | FileCheck %s
 
 #include 
 
Index: clang/test/CodeGen/arm-cmse-nonsecure.c
===
--- clang/test/CodeGen/arm-cmse-nonsecure.c
+++ clang/test/CodeGen/arm-cmse-nonsecure.c
@@ -1,5 +1,5 @@
-// RUN: %clang  -mlittle-endian -target thumbv8m.base-eabi  -emit-llvm -S -o - 
%s | FileCheck %s
-// RUN: %clang  -mbig-endian-target thumbv8m.base-eabi  -emit-llvm -S -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm 
-mrelocation-model static -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm 
-mrelocation-model static -o - %s | FileCheck %s
 
 #include 
 


Index: clang/test/CodeGen/arm-cmse-secure.c
===
--- clang/test/CodeGen/arm-cmse-secure.c
+++ clang/test/CodeGen/arm-cmse-secure.c
@@ -1,5 +1,5 @@
-// RUN: %clang -mlittle-endian -mcmse -target thumbv8m.base-eabi -emit-llvm -S -o - %s | FileCheck %s
-// RUN: %clang -mbig-endian-mcmse -target thumbv8m.base-eabi -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm -mrelocation-model static -mcmse -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm -mrelocation-model static -mcmse -o - %s | FileCheck %s
 
 #include 
 
Index: clang/test/CodeGen/arm-cmse-nonsecure.c
===
--- clang/test/CodeGen/arm-cmse-nonsecure.c
+++ clang/test/CodeGen/arm-cmse-nonsecure.c
@@ -1,5 +1,5 @@
-// RUN: %clang  -mlittle-endian -target thumbv8m.base-eabi  -emit-llvm -S -o - %s | FileCheck %s
-// RUN: %clang  -mbig-endian-target thumbv8m.base-eabi  -emit-llvm -S -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm -mrelocation-model static -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm -mrelocation-model static -o - %s | FileCheck %s
 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/test/SemaCUDA/constexpr-variables.cu:30-31
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);

tra wrote:
> Can we verify the diags for bad cases, too?
By bad cases you mean the constexpr var is not compile time constant?


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

https://reviews.llvm.org/D79237



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


[clang] 3f5fc73 - [test][ARM][CMSE] Use clang_cc1 in arm_cmse.h tests

2020-05-15 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2020-05-15T17:34:00-04:00
New Revision: 3f5fc73a9d52fc7f128dc4e53ccc63b88fc44fb6

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

LOG: [test][ARM][CMSE] Use clang_cc1 in arm_cmse.h tests

Summary:
The `arm_cmse.h` header includes standard headers, but some tests that
include this header explicitly specify a target. The standard headers
found via the standard include paths need not be compatible with the
explicitly-specified target from the tests. In order to avoid test
failures caused by such incompatibility, this patch uses `%clang_cc1`,
which doesn't pick up the host system headers.

Reviewed By: chill

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

Added: 


Modified: 
clang/test/CodeGen/arm-cmse-nonsecure.c
clang/test/CodeGen/arm-cmse-secure.c

Removed: 




diff  --git a/clang/test/CodeGen/arm-cmse-nonsecure.c 
b/clang/test/CodeGen/arm-cmse-nonsecure.c
index 2a483a71f593..c0b33f50ee88 100644
--- a/clang/test/CodeGen/arm-cmse-nonsecure.c
+++ b/clang/test/CodeGen/arm-cmse-nonsecure.c
@@ -1,5 +1,5 @@
-// RUN: %clang  -mlittle-endian -target thumbv8m.base-eabi  -emit-llvm -S -o - 
%s | FileCheck %s
-// RUN: %clang  -mbig-endian-target thumbv8m.base-eabi  -emit-llvm -S -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm 
-mrelocation-model static -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm 
-mrelocation-model static -o - %s | FileCheck %s
 
 #include 
 

diff  --git a/clang/test/CodeGen/arm-cmse-secure.c 
b/clang/test/CodeGen/arm-cmse-secure.c
index 716887254e57..da60f2ed9294 100644
--- a/clang/test/CodeGen/arm-cmse-secure.c
+++ b/clang/test/CodeGen/arm-cmse-secure.c
@@ -1,5 +1,5 @@
-// RUN: %clang -mlittle-endian -mcmse -target thumbv8m.base-eabi -emit-llvm -S 
-o - %s | FileCheck %s
-// RUN: %clang -mbig-endian-mcmse -target thumbv8m.base-eabi -emit-llvm -S 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8m.base-unknown-unknown-eabi   -emit-llvm 
-mrelocation-model static -mcmse -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbebv8m.base-unknown-unknown-eabi -emit-llvm 
-mrelocation-model static -mcmse -o - %s | FileCheck %s
 
 #include 
 



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


[clang] 15f0f82 - [tests][Driver] Set `--sysroot=""` to allow `DEFAULT_SYSROOT` build

2020-05-15 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2020-05-15T17:34:00-04:00
New Revision: 15f0f824b36ea06fcb17bc56ecd181520b4bfbcf

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

LOG: [tests][Driver] Set `--sysroot=""` to allow `DEFAULT_SYSROOT` build

Summary:
If `DEFAULT_SYSROOT` is configured to some path, some tests would fail.
This patch overrides `sysroot` to be the empty string in the style of
D66834 so that the tests will pass even when the build is configured
with a `DEFAULT_SYSROOT`.

Reviewed By: mstorsjo

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

Added: 


Modified: 
clang/test/Driver/darwin-header-search-libcxx.cpp
clang/test/Driver/darwin-header-search-system.cpp
clang/test/Driver/mingw-sysroot.cpp

Removed: 




diff  --git a/clang/test/Driver/darwin-header-search-libcxx.cpp 
b/clang/test/Driver/darwin-header-search-libcxx.cpp
index a54d8adfbda8..6bdbbd11908a 100644
--- a/clang/test/Driver/darwin-header-search-libcxx.cpp
+++ b/clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -20,6 +20,7 @@
 // RUN: -target x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN: --sysroot="" \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain 
--check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s
 // CHECK-LIBCXX-TOOLCHAIN-1: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
 // CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"

diff  --git a/clang/test/Driver/darwin-header-search-system.cpp 
b/clang/test/Driver/darwin-header-search-system.cpp
index a8cd48755179..272d778c2a24 100644
--- a/clang/test/Driver/darwin-header-search-system.cpp
+++ b/clang/test/Driver/darwin-header-search-system.cpp
@@ -95,6 +95,7 @@
 // RUN: -target x86_64-apple-darwin \
 // RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot="" \
 // RUN:   | FileCheck -DRESOURCE=%S/Inputs/resource_dir \
 // RUN:   --check-prefix=CHECK-NOSYSROOT %s
 // CHECK-NOSYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"

diff  --git a/clang/test/Driver/mingw-sysroot.cpp 
b/clang/test/Driver/mingw-sysroot.cpp
index eb62b6fe5d0c..63f970fb1e10 100644
--- a/clang/test/Driver/mingw-sysroot.cpp
+++ b/clang/test/Driver/mingw-sysroot.cpp
@@ -17,7 +17,7 @@
 // If we find a gcc in the path with the right triplet prefix, pick that as
 // sysroot:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" %clang -target 
x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ -c -### %s 2>&1 | 
FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
+// 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"
@@ -27,7 +27,7 @@
 // If there's a matching sysroot next to the clang binary itself, prefer that
 // over a gcc in the path:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-clang/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_CLANG %s
 // CHECK_TESTROOT_CLANG: 
"{{.*}}/testroot-clang{{/|}}x86_64-w64-mingw32{{/|}}include"
 
 
@@ -35,4 +35,4 @@
 // happens to be in the same directory as gcc, make sure we still can pick up
 // the libgcc directory:
 
-// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-gcc/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=platform -stdlib=libstdc++ -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC %s
+// RUN: env "PATH=%T/testroot-gcc/bin:%PATH%" 
%T/testroot-gcc/bin/x86_64-w64-mingw32-clang -target x86_64-w64-mingw32 
-rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_TESTROOT_GCC %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-15 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 264335.
aheejin added a comment.

Handle `throw()` in the same way as `noexcept`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  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
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,27 @@
 
 // CHECK:   unreachable
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s 
--check-prefix=WARNING
+
+// Wasm ignores dynamic exception specifications with types at the moment.
+// Checks if a warning message is printed.
+void test9() throw(int) {
+}
+// 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.
+void test10() throw() {
+  throw 3;
+}
+// WARNING: warning: 'test10' has a non-throwing exception specification but 
can still throw
+// WARNING: function declared non-throwing here
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions 
-fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature 
+exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
@@ -468,6 +469,18 @@
 // 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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.pushTerminate();
+  else
+CGM.getDiags().Report(D->getLocation(),
+  diag::warn_wasm_dynamic_exception_spec_ignored)
+<< FD->getExceptionSpecSourceRange();
+  return;
+}
 unsigned NumExceptions = Proto->getNumExceptions();
 EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +557,14 @@
 // 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
+// case of throw with types, we ignore it and print a warning for now.
+// TODO Correctly handle exception specification in wasm
+if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+  if (EST == EST_DynamicNone)
+EHStack.popTerminate();
+  return;
+}
 EHFilterScope  = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,6 +1590,8 @@
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed for member of incomplete class %0">;
+def 

[PATCH] D80031: [clang-format] [NFC] release note placed in the wrong location and other rst linting errors

2020-05-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:114
+  this occurs when the use of the ``extern`` keyword is neglected in the
+  declaration
   of a variable in a header file. In some cases, no specific translation unit

This and next line should be merged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80031



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


[PATCH] D79655: [WebAssembly] Handle exception specifications

2020-05-15 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

Now this handles `throw()` in the same way as `noexcept`, and prints a warning 
only in case of `throw(type, ..)`, as you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79655



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


[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:15
 
-   `abseil-duration-addition `_, "Yes"
-   `abseil-duration-comparison `_, "Yes"
-   `abseil-duration-conversion-cast `_, 
"Yes"
-   `abseil-duration-division `_, "Yes"
-   `abseil-duration-factory-float `_, "Yes"
-   `abseil-duration-factory-scale `_, "Yes"
-   `abseil-duration-subtraction `_, "Yes"
-   `abseil-duration-unnecessary-conversion 
`_, "Yes"
-   `abseil-faster-strsplit-delimiter 
`_, "Yes"
+   `abseil-duration-addition `_,
+   `abseil-duration-comparison `_,

tdl-g wrote:
> Eugene.Zelenko wrote:
> > Unrelated and incorrect changes.
> Agreed, these were generated by "clang-tidy/add_new_check.py abseil 
> string-find-str-contains", still trying to figure out why.
Did you invoke the python script from the clang-tidy folder or the 
clang-tools-extra folder. The script is sensitive to the working directory it 
was executed from, it must be executed from the clang-tidy folder otherwise it 
fails when trying to detect auto fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

LGTM in general. Let me check the patch on our tensorflow build.




Comment at: clang/test/SemaCUDA/constexpr-variables.cu:30-31
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);

Can we verify the diags for bad cases, too?


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

https://reviews.llvm.org/D79237



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


[PATCH] D80031: [clang-format] [NFC] release note placed in the wrong location and other rst linting errors

2020-05-15 Thread Kanglei Fang via Phabricator via cfe-commits
ghvg1313 accepted this revision.
ghvg1313 added a comment.
This revision is now accepted and ready to land.

Thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80031



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


[PATCH] D79905: [clang-format] [PR44476] Add space between template and attribute

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 264327.
MyDeveloperDay edited the summary of this revision.
MyDeveloperDay added a comment.

Correct the typo


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

https://reviews.llvm.org/D79905

Files:
  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
@@ -8005,6 +8005,8 @@
   verifyFormat("@[ [NSArray class] ];");
   verifyFormat("@[ [foo enum] ];");
 
+  verifyFormat("template  [[nodiscard]] int a() { return 1; }");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2896,6 +2896,11 @@
 // No whitespace in x(/*foo=*/1), except for JavaScript.
 return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
+
+  // Space between template and attribute.
+  // e.g. template  [[nodiscard]] ...
+  if (Left.is(TT_TemplateCloser) && Right.is(TT_AttributeSquare))
+return true;
   if (Right.is(tok::l_paren)) {
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8005,6 +8005,8 @@
   verifyFormat("@[ [NSArray class] ];");
   verifyFormat("@[ [foo enum] ];");
 
+  verifyFormat("template  [[nodiscard]] int a() { return 1; }");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2896,6 +2896,11 @@
 // No whitespace in x(/*foo=*/1), except for JavaScript.
 return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
+
+  // Space between template and attribute.
+  // e.g. template  [[nodiscard]] ...
+  if (Left.is(TT_TemplateCloser) && Right.is(TT_AttributeSquare))
+return true;
   if (Right.is(tok::l_paren)) {
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80031: [clang-format] [NFC] release note placed in the wrong location and other rst linting errors

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: ghvg1313, krasimir, jolesiak, Eugene.Zelenko.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay edited the summary of this revision.

The release notes for `ObjCBreakBeforeNestedBlockParam` was placed between the 
release note for `IndentCaseBlocks` and its example code

Remove other whitespace and line limit issues and double blank line issues 
(@Eugene.Zelenko)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80031

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,8 +67,9 @@
 - clang adds support for a set of  extended integer types (``_ExtInt(N)``) that
   permit non-power of 2 integers, exposing the LLVM integer types. Since a major
   motivating use case for these types is to limit 'bit' usage, these types don't
-  automatically promote to 'int' when operations are done between two ``ExtInt(N)``
-  types, instead math occurs at the size of the largest ``ExtInt(N)`` type.
+  automatically promote to 'int' when operations are done between two
+  ``ExtInt(N)`` types, instead math occurs at the size of the largest
+  ``ExtInt(N)`` type.
 
 - Users of UBSan, PGO, and coverage on Windows will now need to add clang's
   library resource directory to their library search path. These features all
@@ -81,17 +82,15 @@
   linker. If the user links the program with the ``clang`` or ``clang-cl``
   drivers, the driver will pass this flag for them.
 
-
 New Compiler Flags
 --
 
-
 - -fstack-clash-protection will provide a protection against the stack clash
   attack for x86 architecture through automatic probing of each page of
   allocated stack.
 
 - -ffp-exception-behavior={ignore,maytrap,strict} allows the user to specify
-  the floating-point exception behavior.  The default setting is ``ignore``.
+  the floating-point exception behavior. The default setting is ``ignore``.
 
 - -ffp-model={precise,strict,fast} provides the user an umbrella option to
   simplify access to the many single purpose floating point options. The default
@@ -110,11 +109,12 @@
 
 - -fno-common has been enabled as the default for all targets.  Therefore, C
   code that uses tentative definitions as definitions of a variable in multiple
-  translation units will trigger multiple-definition linker errors.  Generally,
-  this occurs when the use of the ``extern`` keyword is neglected in the declaration
+  translation units will trigger multiple-definition linker errors. Generally,
+  this occurs when the use of the ``extern`` keyword is neglected in the
+  declaration
   of a variable in a header file. In some cases, no specific translation unit
-  provides a definition of the variable. The previous behavior can be restored by
-  specifying ``-fcommon``.
+  provides a definition of the variable. The previous behavior can be restored
+  by specifying ``-fcommon``.
 - -Wasm-ignored-qualifier (ex. `asm const ("")`) has been removed and replaced
   with an error (this matches a recent change in GCC-9).
 - -Wasm-file-asm-volatile (ex. `asm volatile ("")` at global scope) has been
@@ -176,7 +176,7 @@
   Previous versions of Clang rejected some constructs of this form
   (specifically, where the linkage of the type happened to be computed
   before the parser reached the typedef name); those cases are still rejected
-  in Clang 11.  In addition, cases that previous versions of Clang did not
+  in Clang 11. In addition, cases that previous versions of Clang did not
   reject now produce an extension warning. This warning can be disabled with
   the warning flag ``-Wno-non-c-typedef-for-linkage``.
 
@@ -207,7 +207,6 @@
 Objective-C Language Changes in Clang
 -
 
-
 OpenCL C Language Changes in Clang
 --
 
@@ -216,7 +215,6 @@
 ABI Changes in Clang
 
 
-
 OpenMP Support in Clang
 ---
 
@@ -234,7 +232,6 @@
 Clang. If upgrading an external codebase that uses Clang as a library,
 this section should help get you past the largest hurdles of upgrading.
 
-
 Build System Changes
 
 
@@ -255,15 +252,11 @@
 clang-format
 
 
-
 - Option ``IndentCaseBlocks`` has been added to support treating the block
   following a switch case label as a scope block which gets indented itself.
   It helps avoid having the closing bracket align with the switch statement's
   closing bracket (when ``IndentCaseLabels`` is ``false``).
 
-- Option ``ObjCBreakBeforeNestedBlockParam`` has been added to optionally apply
-  linebreaks for function arguments declarations before nested blocks.
-
   .. code-block:: c++
 
 switch (fool) {vs. switch (fool) {
@@ -278,6 +271,9 @@
   }
 }
 
+- Option ``ObjCBreakBeforeNestedBlockParam`` has been 

[PATCH] D80008: [clang-format] [PR45942] [[nodiscard]] causes && to be miss interpreted as BinaryOperators

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 264325.
MyDeveloperDay added a comment.

pre-merge tests showed I wasn't quite rebased however it overlaps with D79354: 
[clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration 


However I feel I made a mistake with the previous fix because the l_square and 
r_square haven't always been assigned to be of type TT_AttributeSquare yet.

Update this patch so the test from both revision still work.


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

https://reviews.llvm.org/D80008

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8014,6 +8014,30 @@
MultiLineFunctions);
 }
 
+TEST_F(FormatTest, AttributeClass) {
+  FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp);
+  verifyFormat("class S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("class [[nodiscard]] S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("class __attribute((maybeunused)) S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("struct S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("struct [[nodiscard]] S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, AttributePenaltyBreaking) {
   FormatStyle Style = getLLVMStyle();
   verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2404,7 +2404,7 @@
   // An [[attribute]] can be before the identifier.
   while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
 tok::kw___attribute, tok::kw___declspec,
-tok::kw_alignas, TT_AttributeSquare) ||
+tok::kw_alignas, tok::l_square, tok::r_square) ||
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8014,6 +8014,30 @@
MultiLineFunctions);
 }
 
+TEST_F(FormatTest, AttributeClass) {
+  FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp);
+  verifyFormat("class S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("class [[nodiscard]] S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("class __attribute((maybeunused)) S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("struct S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+  verifyFormat("struct [[nodiscard]] S {\n"
+   "  S(S&&) = default;\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, AttributePenaltyBreaking) {
   FormatStyle Style = getLLVMStyle();
   verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2404,7 +2404,7 @@
   // An [[attribute]] can be before the identifier.
   while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
 tok::kw___attribute, tok::kw___declspec,
-tok::kw_alignas, TT_AttributeSquare) ||
+tok::kw_alignas, tok::l_square, tok::r_square) ||
  ((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79237: [CUDA][HIP] Fix constexpr variables for C++17

2020-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 264329.
yaxunl edited the summary of this revision.
yaxunl added a comment.

add implicit constant attribute to constexpr file scope variables and constexpr 
static data members in device compilation.


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

https://reviews.llvm.org/D79237

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCUDA/constexpr-variables.cu
  clang/test/SemaCUDA/constexpr-variables.cu

Index: clang/test/SemaCUDA/constexpr-variables.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/constexpr-variables.cu
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - -triple nvptx64-nvidia-cuda \
+// RUN:   -fcuda-is-device -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - -triple nvptx64-nvidia-cuda \
+// RUN:   -fcuda-is-device -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - \
+// RUN:   -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - \
+// RUN:   -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+#include "Inputs/cuda.h"
+
+// Check constexpr local variable is not made static variable.
+template
+__host__ __device__ void foo(const T **a) {
+  static const T b = sizeof(a);
+  static constexpr T c = sizeof(a);
+  const T d = sizeof(a);
+  constexpr T e = sizeof(a);
+  a[0] = 
+  a[1] = 
+  a[2] = 
+  a[3] = 
+}
+
+__device__ void device_fun(const int **a) {
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);
+}
+
+void host_fun(const int **a) {
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);
+}
+
+__host__ __device__ void host_device_fun(const int **a) {
+  constexpr int b = sizeof(a);
+  static constexpr int c = sizeof(a);
+  a[0] = 
+  a[1] = 
+  foo(a);
+}
+
Index: clang/test/CodeGenCUDA/constexpr-variables.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/constexpr-variables.cu
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - -triple nvptx \
+// RUN:   -fcuda-is-device | FileCheck --check-prefixes=CXX14 %s
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - -triple nvptx \
+// RUN:   -fcuda-is-device | FileCheck --check-prefixes=CXX17 %s
+
+#include "Inputs/cuda.h"
+
+// COM: @_ZL1a = internal {{.*}}constant i32 7
+constexpr int a = 7;
+__constant__ const int _a = a;
+
+namespace B {
+ // COM: @_ZN1BL1bE = internal {{.*}}constant i32 9
+  constexpr int b = 9;
+}
+__constant__ const int _B_b = B::b;
+
+struct Q {
+  // CXX14: @_ZN1Q2k2E = {{.*}}externally_initialized constant i32 6
+  // CXX17: @_ZN1Q2k2E = internal {{.*}}constant i32 6
+  // CXX14: @_ZN1Q2k1E = available_externally {{.*}}constant i32 5
+  // CXX17: @_ZN1Q2k1E = linkonce_odr {{.*}}constant i32 5
+  static constexpr int k1 = 5;
+  static constexpr int k2 = 6;
+};
+constexpr int Q::k2;
+
+__constant__ const int _Q_k1 = Q::k1;
+__constant__ const int _Q_k2 = Q::k2;
+
+template struct X {
+  // CXX14: @_ZN1XIiE1aE = available_externally {{.*}}constant i32 123
+  // CXX17: @_ZN1XIiE1aE = linkonce_odr {{.*}}constant i32 123
+  static constexpr int a = 123;
+};
+__constant__ const int _X_a = X::a;
+
+template  struct A {
+  // CXX14: @_ZN1AIiLi1ELi2EE1xE = available_externally {{.*}}constant i32 2
+  // CXX17: @_ZN1AIiLi1ELi2EE1xE = linkonce_odr {{.*}}constant i32 2
+  constexpr static T x = a * b;
+};
+__constant__ const int  = A::x;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4836,6 +4836,7 @@
   NewVar->setCXXForRangeDecl(OldVar->isCXXForRangeDecl());
   NewVar->setObjCForDecl(OldVar->isObjCForDecl());
   NewVar->setConstexpr(OldVar->isConstexpr());
+  MaybeAddCUDAConstantAttr(NewVar);
   NewVar->setInitCapture(OldVar->isInitCapture());
   NewVar->setPreviousDeclInSameBlockScope(
   OldVar->isPreviousDeclInSameBlockScope());
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7081,6 +7081,7 @@
 
   case CSK_constexpr:
 NewVD->setConstexpr(true);
+MaybeAddCUDAConstantAttr(NewVD);
 // C++1z [dcl.spec.constexpr]p1:
 //   A static data member declared with the constexpr specifier is
 //   implicitly an inline variable.
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -528,9 +528,12 @@
 // constructor according to CUDA rules. This 

[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2020-05-15 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D71726#1801346 , @__simt__ wrote:

> In D71726#1792852 , @yaxunl wrote:
>
> > In D71726#1791904 , @jfb wrote:
> >
> > > This generally seems fine. Does it work on most backends? I want to make 
> > > sure it doesn't fail in backends :)
> >
> >
> > For x86_64, amdgcn, aarch64, armv7, mips64, it is translated to cmpxchg by 
> > AtomicExpandPass and backends did codegen successfully.
> >
> > For hexagon, riscv32, it is translated to call of `__atomic_fetch_add_4` 
> > for fadd float. This is concerning. Probably we need to add 
> > `__atomic_fetch_{add|sub}_{f16|f32|f64}` ?
>
>
> For systems that have load-link/store-conditional architectures, like ARM / 
> PPC / base RISC-V without extension, I would imagine that using a cmpxchg 
> loop is much worse than simply doing the floating-point add/sub in the middle 
> of the atomic mini-transaction. I'm sure that we want back-ends to be capable 
> of implementing this better than what this pass is doing, even when they 
> don't have "native" fp atomics.
>
> You listed amdgcn... what does this do on nvptx?


Targets can implement shouldExpandAtomicRMWInIR for the desired behavior, which 
NVPTX currently does not implement. Looking at AtomicExpandPass, it looks like 
either cmpxchg or LLSC expansions should work for the FP atomics already


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

https://reviews.llvm.org/D71726



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


[PATCH] D79935: [clang-format] [PR44345] Long namespace closing comment is duplicated endlessly

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8ea35e63f50: [clang-format] [PR44345] Long namespace 
closing comment is duplicated endlessly (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79935

Files:
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16238,6 +16238,74 @@
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 }
 
+TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
+  // These tests are not in NamespaceFixer because that doesn't
+  // test its interaction with line wrapping
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 80;
+  verifyFormat("namespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace",
+   Style);
+
+  verifyFormat("namespace AAA {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace AAA",
+   Style);
+
+  EXPECT_EQ("namespace Averyveryveryverylongnamespace {\n"
+"int i;\n"
+"int j;\n"
+"} // namespace Averyveryveryverylongnamespace",
+format("namespace Averyveryveryverylongnamespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "}",
+   Style));
+
+  EXPECT_EQ(
+  "namespace "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+  "int j;\n"
+  "} // namespace\n"
+  "  // "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::"
+  "went::mad::now",
+  format("namespace "
+ "would::it::save::you::a::lot::of::time::if_::i::"
+ "just::gave::up::and_::went::mad::now {\n"
+ "int i;\n"
+ "int j;\n"
+ "}",
+ Style));
+
+  // This used to duplicate the comment again and again on subsequent runs
+  EXPECT_EQ(
+  "namespace "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+  "int j;\n"
+  "} // namespace\n"
+  "  // "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::"
+  "went::mad::now",
+  format("namespace "
+ "would::it::save::you::a::lot::of::time::if_::i::"
+ "just::gave::up::and_::went::mad::now {\n"
+ "int i;\n"
+ "int j;\n"
+ "} // namespace\n"
+ "  // "
+ "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::"
+ "and_::went::mad::now",
+ Style));
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -121,7 +121,25 @@
   // Named namespace comments must not mention anonymous namespace.
   if (!NamespaceName.empty() && !AnonymousInComment.empty())
 return false;
-  return NamespaceNameInComment == NamespaceName;
+  if (NamespaceNameInComment == NamespaceName)
+return true;
+
+  // Has namespace comment flowed onto the next line.
+  // } // namespace
+  //   // verylongnamespacenamethatdidnotfitonthepreviouscommentline
+  if (!(Comment->Next && Comment->Next->is(TT_LineComment)))
+return false;
+
+  static const llvm::Regex CommentPattern = llvm::Regex(
+  "^/[/*] *( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase);
+
+  // Pull out just the comment text.
+  if (!CommentPattern.match(Comment->Next->TokenText, )) {
+return false;
+  }
+  NamespaceNameInComment = Groups.size() > 2 ? Groups[2] : "";
+
+  return (NamespaceNameInComment == NamespaceName);
 }
 
 void addEndComment(const FormatToken *RBraceTok, StringRef EndCommentText,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79935: [clang-format] [PR44345] Long namespace closing comment is duplicated endlessly

2020-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 264319.
MyDeveloperDay added a comment.

Fix typo


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

https://reviews.llvm.org/D79935

Files:
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15890,6 +15890,74 @@
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 }
 
+TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
+  // These tests are not in NamespaceFixer because that doesn't
+  // test its interaction with line wrapping
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 80;
+  verifyFormat("namespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace",
+   Style);
+
+  verifyFormat("namespace AAA {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace AAA",
+   Style);
+
+  EXPECT_EQ("namespace Averyveryveryverylongnamespace {\n"
+"int i;\n"
+"int j;\n"
+"} // namespace Averyveryveryverylongnamespace",
+format("namespace Averyveryveryverylongnamespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "}",
+   Style));
+
+  EXPECT_EQ(
+  "namespace "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+  "int j;\n"
+  "} // namespace\n"
+  "  // "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::"
+  "went::mad::now",
+  format("namespace "
+ "would::it::save::you::a::lot::of::time::if_::i::"
+ "just::gave::up::and_::went::mad::now {\n"
+ "int i;\n"
+ "int j;\n"
+ "}",
+ Style));
+
+  // This used to duplicate the comment again and again on subsequent runs
+  EXPECT_EQ(
+  "namespace "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+  "int j;\n"
+  "} // namespace\n"
+  "  // "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::"
+  "went::mad::now",
+  format("namespace "
+ "would::it::save::you::a::lot::of::time::if_::i::"
+ "just::gave::up::and_::went::mad::now {\n"
+ "int i;\n"
+ "int j;\n"
+ "} // namespace\n"
+ "  // "
+ "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::"
+ "and_::went::mad::now",
+ Style));
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -121,7 +121,25 @@
   // Named namespace comments must not mention anonymous namespace.
   if (!NamespaceName.empty() && !AnonymousInComment.empty())
 return false;
-  return NamespaceNameInComment == NamespaceName;
+  if (NamespaceNameInComment == NamespaceName)
+return true;
+
+  // Has namespace comment flowed onto the next line.
+  // } // namespace
+  //   // verylongnamespacenamethatdidnotfitonthepreviouscommentline
+  if (!(Comment->Next && Comment->Next->is(TT_LineComment)))
+return false;
+
+  static const llvm::Regex CommentPattern = llvm::Regex(
+  "^/[/*] *( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase);
+
+  // Pull out just the comment text.
+  if (!CommentPattern.match(Comment->Next->TokenText, )) {
+return false;
+  }
+  NamespaceNameInComment = Groups.size() > 2 ? Groups[2] : "";
+
+  return (NamespaceNameInComment == NamespaceName);
 }
 
 void addEndComment(const FormatToken *RBraceTok, StringRef EndCommentText,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Tom Lokovic via Phabricator via cfe-commits
tdl-g added a comment.

Eugene, thank you for the comments, I'll address them soon.  For the moment I'm 
trying to figure out what's up with the list.rst changes.




Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:15
 
-   `abseil-duration-addition `_, "Yes"
-   `abseil-duration-comparison `_, "Yes"
-   `abseil-duration-conversion-cast `_, 
"Yes"
-   `abseil-duration-division `_, "Yes"
-   `abseil-duration-factory-float `_, "Yes"
-   `abseil-duration-factory-scale `_, "Yes"
-   `abseil-duration-subtraction `_, "Yes"
-   `abseil-duration-unnecessary-conversion 
`_, "Yes"
-   `abseil-faster-strsplit-delimiter 
`_, "Yes"
+   `abseil-duration-addition `_,
+   `abseil-duration-comparison `_,

Eugene.Zelenko wrote:
> Unrelated and incorrect changes.
Agreed, these were generated by "clang-tidy/add_new_check.py abseil 
string-find-str-contains", still trying to figure out why.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D78508: [Clang] Allow long as size_t printf argument on 32-bit Windows platforms.

2020-05-15 Thread Jacek Caban via Phabricator via cfe-commits
jacek added a comment.

I don't mind dropping the patch, we can mitigate the problem in Wine. My 
understanding is that we could use "pedantic" logic similar to NSInteger in 
checkFormatExpr, please let me know if you'd like something like that.

I still think that using casts in such cases is not the right pattern. For an 
example, if developer knows that SIZE_T is a type that will always be 
compatible with %z, the code:
printf("%zd", size);
is not wrong. Proposed casts would change all such cases to:
printf("%zd", (size_t)size);
Now imagine that I made a mistake and changed type of size to a type of 
different size. In the first variant, clang will issue a warning. In the second 
case, the cast will hide the warning, but I'm probably interested in changing 
the format instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78508



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


[clang] e8ea35e - [clang-format] [PR44345] Long namespace closing comment is duplicated endlessly

2020-05-15 Thread via cfe-commits

Author: mydeveloperday
Date: 2020-05-15T21:00:55+01:00
New Revision: e8ea35e63f50486fe497d8565abb8cd5b2820a96

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

LOG: [clang-format] [PR44345] Long namespace closing comment is duplicated 
endlessly

Summary:
https://bugs.llvm.org/show_bug.cgi?id=44345

When namespaces get long the namespace end comment wraps onto the next line

```
namespace would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::
went::mad::now {
void foo();
void bar();
} // namespace
  // 
would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::went::mad::now
```

If clang-format it applied successively it will duplicate the end comment

```
namespace would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::
went::mad::now {
void foo();
void bar();
} // namespace
  // 
would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::went::mad::now
  // 
would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::went::mad::now
```

This revision checks to ensure the end comment is not on the next line before 
adding yet another comment

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

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

Added: 


Modified: 
clang/lib/Format/NamespaceEndCommentsFixer.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/NamespaceEndCommentsFixer.cpp 
b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
index 20b424f86077..92707150fcdb 100644
--- a/clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -121,7 +121,25 @@ bool validEndComment(const FormatToken *RBraceTok, 
StringRef NamespaceName,
   // Named namespace comments must not mention anonymous namespace.
   if (!NamespaceName.empty() && !AnonymousInComment.empty())
 return false;
-  return NamespaceNameInComment == NamespaceName;
+  if (NamespaceNameInComment == NamespaceName)
+return true;
+
+  // Has namespace comment flowed onto the next line.
+  // } // namespace
+  //   // verylongnamespacenamethatdidnotfitonthepreviouscommentline
+  if (!(Comment->Next && Comment->Next->is(TT_LineComment)))
+return false;
+
+  static const llvm::Regex CommentPattern = llvm::Regex(
+  "^/[/*] *( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase);
+
+  // Pull out just the comment text.
+  if (!CommentPattern.match(Comment->Next->TokenText, )) {
+return false;
+  }
+  NamespaceNameInComment = Groups.size() > 2 ? Groups[2] : "";
+
+  return (NamespaceNameInComment == NamespaceName);
 }
 
 void addEndComment(const FormatToken *RBraceTok, StringRef EndCommentText,

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f6f4ea825086..a421ca9f131c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16238,6 +16238,74 @@ TEST_F(FormatTest, OperatorSpacing) {
   verifyFormat("operator&&(int(&&)(), class Foo);", Style);
 }
 
+TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
+  // These tests are not in NamespaceFixer because that doesn't
+  // test its interaction with line wrapping
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 80;
+  verifyFormat("namespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace",
+   Style);
+
+  verifyFormat("namespace AAA {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace AAA",
+   Style);
+
+  EXPECT_EQ("namespace Averyveryveryverylongnamespace {\n"
+"int i;\n"
+"int j;\n"
+"} // namespace Averyveryveryverylongnamespace",
+format("namespace Averyveryveryverylongnamespace {\n"
+   "int i;\n"
+   "int j;\n"
+   "}",
+   Style));
+
+  EXPECT_EQ(
+  "namespace "
+  
"would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+  "int j;\n"
+  "} // namespace\n"
+  "  // "
+  "would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::"
+  "went::mad::now",
+  format("namespace "
+ "would::it::save::you::a::lot::of::time::if_::i::"
+ "just::gave::up::and_::went::mad::now {\n"
+ "int i;\n"
+ "int j;\n"
+ "}",
+ Style));
+
+  // This used to duplicate the comment again and again on subsequent runs
+  EXPECT_EQ(
+  "namespace "
+  
"would::it::save::you::a::lot::of::time::if_::i::just::gave::up::and_::\n"
+  "went::mad::now {\n"
+  "int i;\n"
+ 

[PATCH] D79894: [clang][slh] Add test for SLH feature checking macro

2020-05-15 Thread Zola Bridges via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG18a855da431e: [clang][slh] Add test for SLH feature checking 
macro (authored by zbrid).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79894

Files:
  clang/test/Lexer/has_feature_speculative_load_hardening.cpp


Index: clang/test/Lexer/has_feature_speculative_load_hardening.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_speculative_load_hardening.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang -E -mspeculative-load-hardening %s -o - | FileCheck 
--check-prefix=CHECK-SLH %s
+// RUN: %clang -E -mno-speculative-load-hardening %s -o - | FileCheck 
--check-prefix=CHECK-NOSLH %s
+// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-DEFAULT %s
+
+#if __has_feature(speculative_load_hardening)
+int SpeculativeLoadHardeningEnabled();
+#else
+int SpeculativeLoadHardeningDisabled();
+#endif
+
+// CHECK-SLH: SpeculativeLoadHardeningEnabled
+
+// CHECK-NOSLH: SpeculativeLoadHardeningDisabled
+
+// CHECK-DEFAULT: SpeculativeLoadHardeningDisabled


Index: clang/test/Lexer/has_feature_speculative_load_hardening.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_speculative_load_hardening.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang -E -mspeculative-load-hardening %s -o - | FileCheck --check-prefix=CHECK-SLH %s
+// RUN: %clang -E -mno-speculative-load-hardening %s -o - | FileCheck --check-prefix=CHECK-NOSLH %s
+// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-DEFAULT %s
+
+#if __has_feature(speculative_load_hardening)
+int SpeculativeLoadHardeningEnabled();
+#else
+int SpeculativeLoadHardeningDisabled();
+#endif
+
+// CHECK-SLH: SpeculativeLoadHardeningEnabled
+
+// CHECK-NOSLH: SpeculativeLoadHardeningDisabled
+
+// CHECK-DEFAULT: SpeculativeLoadHardeningDisabled
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78508: [Clang] Allow long as size_t printf argument on 32-bit Windows platforms.

2020-05-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/AST/FormatString.cpp:407
+if ((isSizeT() || isPtrdiffT()) &&
+C.getTargetInfo().getTriple().isOSMSVCRT() &&
+C.getTargetInfo().getTriple().isArch32Bit())

amccarth wrote:
> I'm not convinced `isOSMSVCRT` is the right check.  The troubling typedefs 
> are [[ 
> https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#size-t
>  | `SIZE_T` and `SSIZE_T` ]], which come from the Windows API and are 
> unrelated to Microsoft's C run-time library.  I think `isOSWindows` would be 
> more precise.
We already care about typedef-names used to spell argument types in some cases 
(see `namedTyoeToLengthModifier`. If this is a case of MSVC providing a typedef 
that people *think* is `size_t`, that is always the same size and 
representation as `size_t`, and that is intended to be fully interchangeable 
with `size_t`, but sometimes is a different type, then it might be reasonable 
to detect whether the type was spelled using that `SIZE_T` typedef when 
targeting Windows, and exempt only that case.

I mean, assuming that we want to allow such code at all and not push people to 
cast explicitly from `SIZE_T` to `size_t`. I don't have a strong opinion on 
that; I think it rather depends on intended idiomatic usage on that platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78508



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


[clang] 18a855d - [clang][slh] Add test for SLH feature checking macro

2020-05-15 Thread Zola Bridges via cfe-commits

Author: Zola Bridges
Date: 2020-05-15T12:23:31-07:00
New Revision: 18a855da431e74499695ce43a8db23a1755ba632

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

LOG: [clang][slh] Add test for SLH feature checking macro

Summary:
I forgot to include a test in this commit:
https://reviews.llvm.org/rG379e68a763097bed6c6dc7453e4b732e3d68

Here's the test. It passes after that commit and fails before that commit.

Reviewed By: mattdr

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

Added: 
clang/test/Lexer/has_feature_speculative_load_hardening.cpp

Modified: 


Removed: 




diff  --git a/clang/test/Lexer/has_feature_speculative_load_hardening.cpp 
b/clang/test/Lexer/has_feature_speculative_load_hardening.cpp
new file mode 100644
index ..3bc743f286c7
--- /dev/null
+++ b/clang/test/Lexer/has_feature_speculative_load_hardening.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang -E -mspeculative-load-hardening %s -o - | FileCheck 
--check-prefix=CHECK-SLH %s
+// RUN: %clang -E -mno-speculative-load-hardening %s -o - | FileCheck 
--check-prefix=CHECK-NOSLH %s
+// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-DEFAULT %s
+
+#if __has_feature(speculative_load_hardening)
+int SpeculativeLoadHardeningEnabled();
+#else
+int SpeculativeLoadHardeningDisabled();
+#endif
+
+// CHECK-SLH: SpeculativeLoadHardeningEnabled
+
+// CHECK-NOSLH: SpeculativeLoadHardeningDisabled
+
+// CHECK-DEFAULT: SpeculativeLoadHardeningDisabled



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in both clang and llvm

2020-05-15 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 264303.
lei retitled this revision from " [PowerPC] Add support for -mcpu=pwr10 in both 
clang and llvm" to "[PowerPC] Add support for -mcpu=pwr10 in both clang and 
llvm".
lei added a comment.

missed a file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80020

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/test/CodeGen/PowerPC/check-cpu.ll

Index: llvm/test/CodeGen/PowerPC/check-cpu.ll
===
--- llvm/test/CodeGen/PowerPC/check-cpu.ll
+++ llvm/test/CodeGen/PowerPC/check-cpu.ll
@@ -2,6 +2,10 @@
 ; RUN: -mcpu=future < %s | FileCheck %s
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN: -mcpu=future < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=power10 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr10 < %s | FileCheck %s
 
 
 ; Test mcpu=future that should be recognized on PowerPC.
Index: llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
@@ -654,7 +654,8 @@
   unsigned Directive = ST->getCPUDirective();
   // Assume that Future CPU has the same cache line size as the others.
   if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8 ||
-  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR_FUTURE)
+  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR10 ||
+  Directive == PPC::DIR_PWR_FUTURE)
 return 128;
 
   // On other processors return a default of 64 bytes.
@@ -688,7 +689,8 @@
   // FIXME: the same for P9 as previous gen until POWER9 scheduling is ready
   // Assume that future is the same as the others.
   if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8 ||
-  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR_FUTURE)
+  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR10 ||
+  Directive == PPC::DIR_PWR_FUTURE)
 return 12;
 
   // For most things, modern systems have two execution units (and
Index: llvm/lib/Target/PowerPC/PPCSubtarget.h
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -34,32 +34,33 @@
 
 namespace PPC {
   // -m directive values.
-  enum {
-DIR_NONE,
-DIR_32,
-DIR_440,
-DIR_601,
-DIR_602,
-DIR_603,
-DIR_7400,
-DIR_750,
-DIR_970,
-DIR_A2,
-DIR_E500,
-DIR_E500mc,
-DIR_E5500,
-DIR_PWR3,
-DIR_PWR4,
-DIR_PWR5,
-DIR_PWR5X,
-DIR_PWR6,
-DIR_PWR6X,
-DIR_PWR7,
-DIR_PWR8,
-DIR_PWR9,
-DIR_PWR_FUTURE,
-DIR_64
-  };
+enum {
+  DIR_NONE,
+  DIR_32,
+  DIR_440,
+  DIR_601,
+  DIR_602,
+  DIR_603,
+  DIR_7400,
+  DIR_750,
+  DIR_970,
+  DIR_A2,
+  DIR_E500,
+  DIR_E500mc,
+  DIR_E5500,
+  DIR_PWR3,
+  DIR_PWR4,
+  DIR_PWR5,
+  DIR_PWR5X,
+  DIR_PWR6,
+  DIR_PWR6X,
+  DIR_PWR7,
+  DIR_PWR8,
+  DIR_PWR9,
+  DIR_PWR10,
+  DIR_PWR_FUTURE,
+  DIR_64
+};
 }
 
 class GlobalValue;
@@ -138,6 +139,7 @@
   bool HasAddiLoadFusion;
   bool HasAddisLoadFusion;
   bool IsISA3_0;
+  bool IsISA3_1;
   bool UseLongCalls;
   bool SecurePlt;
   bool VectorsUseTwoUnits;
@@ -308,6 +310,7 @@
   bool hasHTM() const { return HasHTM; }
   bool hasFloat128() const { return HasFloat128; }
   bool isISA3_0() const { return IsISA3_0; }
+  bool isISA3_1() const { return IsISA3_1; }
   bool useLongCalls() const { return UseLongCalls; }
   bool hasFusion() const { return HasFusion; }
   bool hasAddiLoadFusion() const { return HasAddiLoadFusion; }
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -1305,6 +1305,7 @@
   case PPC::DIR_PWR7:
   case PPC::DIR_PWR8:
   case PPC::DIR_PWR9:
+  case PPC::DIR_PWR10:
   case PPC::DIR_PWR_FUTURE:
 setPrefLoopAlignment(Align(16));
 setPrefFunctionAlignment(Align(16));
@@ -14896,6 +14897,7 @@
   case PPC::DIR_PWR7:
   case PPC::DIR_PWR8:
   case PPC::DIR_PWR9:
+  case PPC::DIR_PWR10:
   case PPC::DIR_PWR_FUTURE: {
 if (!ML)
   break;
@@ -16085,6 +16087,7 @@
   // vector7   2  2
   return true;
 case PPC::DIR_PWR9:
+case PPC::DIR_PWR10:
 

[PATCH] D79967: Fix debug info for NoDebug attr

2020-05-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: vsk.
dblaikie added a comment.

Could you check the commit history for this feature and rope in some folks who 
added the function declaration work (it's for debug call sites) - maybe @vsk is 
the right person, or knows who is, to check this is the right fix for 
it/doesn't adversely affect the feature this code was added to implement.




Comment at: clang/test/CodeGen/nodebug-attr.c:5-6
+
+// CHECK-NOT: define {{.*}}@foo{{.*}}!dbg
+// CHECK-LABEL: define {{.*}}@foo
+// CHECK-NOT: ret {{.*}}!dbg

Does this test fail when the bug is present? I'd have thought not - my 
understanding was that CHECK-LABEL is found first, then CHECK-NOT is tested 
between labels/other checks, so it wouldn't find @foo.*!dbg anyway.

I think maybe it'd be better to tighten up the CHECK-LABEL to include "#0 {" at 
the end and a comment saying how that CHECK part ensures there's no !dbg 
attached to it.



Comment at: clang/test/CodeGen/nodebug-attr.c:8-15
+__attribute__((nodebug)) void foo(int *a) {
+  *a = 1;
+}
+
+// CHECK-LABEL: define {{.*}}@bar{{.*}}!dbg
+void bar(int *a) {
+  foo(a);

It looks like this test case currently crashes LLVM:

h$ clang++-tot test.cpp -g -c -O3 && llvm-dwarfdump-tot test.o
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: clang++-tot test.cpp -g -c -O3 
1.   parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'test.cpp'.
4.  Running pass 'Debug Variable Analysis' on function '@_Z3fooPi'
 #0 0x06b49927 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/Unix/Signals.inc:564:11
 #1 0x06b49ac9 PrintStackTraceSignalHandler(void*) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x06b482db llvm::sys::RunSignalHandlers() 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/Signals.cpp:67:5
 #3 0x06b4921e llvm::sys::CleanupOnSignal(unsigned long) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/Unix/Signals.inc:362:1
 #4 0x06a7cae8 (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/CrashRecoveryContext.cpp:77:20
 #5 0x06a7cd6e CrashRecoverySignalHandler(int) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/Support/CrashRecoveryContext.cpp:383:1
 #6 0x7fc197167520 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #7 0x05a309ac llvm::DICompileUnit::getEmissionKind() const 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/include/llvm/IR/DebugInfoMetadata.h:1272:31
 #8 0x05a4a107 llvm::LexicalScopes::initialize(llvm::MachineFunction 
const&) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/CodeGen/LexicalScopes.cpp:53:70
 #9 0x05e128dd (anonymous namespace)::LDVImpl::computeIntervals() 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/CodeGen/LiveDebugVariables.cpp:972:17
#10 0x05e11284 (anonymous 
namespace)::LDVImpl::runOnMachineFunction(llvm::MachineFunction&) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/CodeGen/LiveDebugVariables.cpp:0:3
#11 0x05e10fe4 
llvm::LiveDebugVariables::runOnMachineFunction(llvm::MachineFunction&) 
/usr/local/google/home/blaikie/dev/llvm/src/llvm/lib/CodeGen/LiveDebugVariables.cpp:1014:3


Is that crash something this patch is intended to address, or unrelated? I 
guess it's intended to address that problem - because it's a DISubprogram for 
'foo' with no DICompileUnit attachment that causes the crash later on.


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

https://reviews.llvm.org/D79967



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in both clang and llvm

2020-05-15 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 264301.
lei added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Add support in llvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80020

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/init-ppc64.c
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/PowerPC/PPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/test/CodeGen/PowerPC/check-cpu.ll

Index: llvm/test/CodeGen/PowerPC/check-cpu.ll
===
--- llvm/test/CodeGen/PowerPC/check-cpu.ll
+++ llvm/test/CodeGen/PowerPC/check-cpu.ll
@@ -2,6 +2,10 @@
 ; RUN: -mcpu=future < %s | FileCheck %s
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN: -mcpu=future < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=power10 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr10 < %s | FileCheck %s
 
 
 ; Test mcpu=future that should be recognized on PowerPC.
Index: llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
@@ -654,7 +654,8 @@
   unsigned Directive = ST->getCPUDirective();
   // Assume that Future CPU has the same cache line size as the others.
   if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8 ||
-  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR_FUTURE)
+  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR10 ||
+  Directive == PPC::DIR_PWR_FUTURE)
 return 128;
 
   // On other processors return a default of 64 bytes.
@@ -688,7 +689,8 @@
   // FIXME: the same for P9 as previous gen until POWER9 scheduling is ready
   // Assume that future is the same as the others.
   if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8 ||
-  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR_FUTURE)
+  Directive == PPC::DIR_PWR9 || Directive == PPC::DIR_PWR10 ||
+  Directive == PPC::DIR_PWR_FUTURE)
 return 12;
 
   // For most things, modern systems have two execution units (and
Index: llvm/lib/Target/PowerPC/PPCSubtarget.h
===
--- llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -57,6 +57,7 @@
 DIR_PWR7,
 DIR_PWR8,
 DIR_PWR9,
+DIR_PWR10,
 DIR_PWR_FUTURE,
 DIR_64
   };
@@ -138,6 +139,7 @@
   bool HasAddiLoadFusion;
   bool HasAddisLoadFusion;
   bool IsISA3_0;
+  bool IsISA3_1;
   bool UseLongCalls;
   bool SecurePlt;
   bool VectorsUseTwoUnits;
@@ -308,6 +310,7 @@
   bool hasHTM() const { return HasHTM; }
   bool hasFloat128() const { return HasFloat128; }
   bool isISA3_0() const { return IsISA3_0; }
+  bool isISA3_1() const { return IsISA3_1; }
   bool useLongCalls() const { return UseLongCalls; }
   bool hasFusion() const { return HasFusion; }
   bool hasAddiLoadFusion() const { return HasAddiLoadFusion; }
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -1305,6 +1305,7 @@
   case PPC::DIR_PWR7:
   case PPC::DIR_PWR8:
   case PPC::DIR_PWR9:
+  case PPC::DIR_PWR10:
   case PPC::DIR_PWR_FUTURE:
 setPrefLoopAlignment(Align(16));
 setPrefFunctionAlignment(Align(16));
@@ -14896,6 +14897,7 @@
   case PPC::DIR_PWR7:
   case PPC::DIR_PWR8:
   case PPC::DIR_PWR9:
+  case PPC::DIR_PWR10:
   case PPC::DIR_PWR_FUTURE: {
 if (!ML)
   break;
@@ -16085,6 +16087,7 @@
   // vector7   2  2
   return true;
 case PPC::DIR_PWR9:
+case PPC::DIR_PWR10:
 case PPC::DIR_PWR_FUTURE:
   //  typemul addshl
   // scalar5   2  2
Index: llvm/lib/Target/PowerPC/PPC.td
===
--- llvm/lib/Target/PowerPC/PPC.td
+++ llvm/lib/Target/PowerPC/PPC.td
@@ -51,6 +51,7 @@
 def DirectivePwr7: SubtargetFeature<"", "CPUDirective", "PPC::DIR_PWR7", "">;
 def DirectivePwr8: SubtargetFeature<"", "CPUDirective", "PPC::DIR_PWR8", "">;
 def DirectivePwr9: SubtargetFeature<"", "CPUDirective", "PPC::DIR_PWR9", "">;
+def DirectivePwr10: SubtargetFeature<"", "CPUDirective", "PPC::DIR_PWR10", "">;
 def DirectivePwrFuture
 : SubtargetFeature<"", "CPUDirective", "PPC::DIR_PWR_FUTURE", "">;
 
@@ -205,6 +206,9 @@
 def FeatureISA3_0 : 

[PATCH] D79895: Add a new warning to warn when passing uninitialized variables as const reference parameters to a function

2020-05-15 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 264300.
zequanwu added a comment.

Since the new warning is controlled by `-Wuninitialized`, I disabled it in 
existing test case and added a separate test case for 
`-Wuninitialized-const-reference`.


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

https://reviews.llvm.org/D79895

Files:
  clang/include/clang/Analysis/Analyses/UninitializedValues.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UninitializedValues.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Misc/warning-wall.c
  clang/test/SemaCXX/uninit-variables.cpp
  clang/test/SemaCXX/uninitialized.cpp
  clang/test/SemaCXX/warn-uninitialized-const-reference.cpp

Index: clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-const-reference -verify %s
+
+class A {
+public:
+int i;
+A() {};
+A(const A& a) {};
+A(int i) {}
+bool operator!=(const A&);
+};
+
+A const_ref_use_A(const A& a);
+int const_ref_use(const int& i);
+A const_use_A(const A a);
+int const_use(const int i);
+
+void f() {
+int i;
+const_ref_use(i); // expected-warning {{variable 'i' is uninitialized when passes as a const reference parameter here}}
+int j = j + const_ref_use(j); // expected-warning {{variable 'j' is uninitialized when used within its own initialization}} expected-warning {{variable 'j' is uninitialized when passes as a const reference parameter here}}
+A a1 = const_ref_use_A(a1); // expected-warning {{variable 'a1' is uninitialized when passes as a const reference parameter here}}
+int k = const_use(k); // expected-warning {{variable 'k' is uninitialized when used within its own initialization}}
+A a2 = const_use_A(a2); // expected-warning {{variable 'a2' is uninitialized when used within its own initialization}}
+A a3(const_ref_use_A(a3)); // expected-warning {{variable 'a3' is uninitialized when passes as a const reference parameter here}}
+A a4 = a3 != a4; // expected-warning {{variable 'a4' is uninitialized when used within its own initialization}} expected-warning {{variable 'a4' is uninitialized when passes as a const reference parameter here}}
+
+A a5;
+const_ref_use_A(a5);
+}
Index: clang/test/SemaCXX/uninitialized.cpp
===
--- clang/test/SemaCXX/uninitialized.cpp
+++ clang/test/SemaCXX/uninitialized.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -std=c++1z -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z -verify %s
 
 // definitions for std::move
 namespace std {
Index: clang/test/SemaCXX/uninit-variables.cpp
===
--- clang/test/SemaCXX/uninit-variables.cpp
+++ clang/test/SemaCXX/uninit-variables.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fcxx-exceptions %s -verify -std=c++1y
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wno-uninitialized-const-reference -fsyntax-only -fcxx-exceptions %s -verify -std=c++1y
 
 // Stub out types for 'typeid' to work.
 namespace std { class type_info {}; }
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -55,6 +55,7 @@
 CHECK-NEXT:-Wuninitialized
 CHECK-NEXT:  -Wsometimes-uninitialized
 CHECK-NEXT:  -Wstatic-self-init
+CHECK-NEXT:  -Wuninitialized-const-reference
 CHECK-NEXT:-Wunknown-pragmas
 CHECK-NEXT:-Wunused
 CHECK-NEXT:  -Wunused-argument
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -974,6 +974,14 @@
 << Use.getUser()->getSourceRange();
 }
 
+/// Diagnose uninitialized const reference usages.
+static bool DiagnoseUninitializedConstRefUse(Sema , const VarDecl *VD,
+ const UninitUse ) {
+  S.Diag(Use.getUser()->getBeginLoc(), diag::warn_uninit_const_reference)
+  << VD->getDeclName() << Use.getUser()->getSourceRange();
+  return true;
+}
+
 /// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
 /// uninitialized variable. This manages the different forms of diagnostic
 /// emitted for particular types of uses. Returns true if the use was diagnosed
@@ -1000,8 +1008,9 @@
 
   ContainsReference CR(S.Context, DRE);
   CR.Visit(Initializer);
+  unsigned DiagID = 

[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:18
+#include "clang/Tooling/Transformer/Stencil.h"
+#include 
+

asserts are not used.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:35
+llvm::Optional
+MakeRule(const LangOptions ,
+ const ClangTidyCheck::OptionsView ) {

Please use static instead of anonymous namespace for functions.



Comment at: 
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp:38
+  // Only support C++.
+  if (!LangOpts.CPlusPlus)
+return llvm::None;

This belongs to isLanguageVersionSupported().



Comment at: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h:16
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+#include 

STL containers are not used in header.



Comment at: clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h:32
+  StringFindStrContainsCheck(StringRef Name, ClangTidyContext *Context);
+};
+

storeOptions() is missing.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:78
 ^^
+- New :doc:`abseil-string-find-str-contains
+  ` check.

Please separate with empty line.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:81
+
+   Finds string.find(...) == npos comparisons and suggests replacing with
+   absl::StrContains.

Please synchronize with first statement in documentation.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:15
 
-   `abseil-duration-addition `_, "Yes"
-   `abseil-duration-comparison `_, "Yes"
-   `abseil-duration-conversion-cast `_, 
"Yes"
-   `abseil-duration-division `_, "Yes"
-   `abseil-duration-factory-float `_, "Yes"
-   `abseil-duration-factory-scale `_, "Yes"
-   `abseil-duration-subtraction `_, "Yes"
-   `abseil-duration-unnecessary-conversion 
`_, "Yes"
-   `abseil-faster-strsplit-delimiter 
`_, "Yes"
+   `abseil-duration-addition `_,
+   `abseil-duration-comparison `_,

Unrelated and incorrect changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80023



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


[PATCH] D80025: [ASTMatcher] Correct memoization bug ignoring direction (descendants or ancestors)

2020-05-15 Thread Loïc Joly via Phabricator via cfe-commits
loic-joly-sonarsource created this revision.
loic-joly-sonarsource added a reviewer: klimek.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In ASTMatcher, when we have `has(...)` and `hasParent(...)` called with the 
same internal matcher on the same node, the memoization process will mix-up the 
two calls because the direction of the traversal is not part of the memoization 
key.

This patch adds this information.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80025

Files:
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2591,6 +2591,14 @@
 compoundStmt(hasParent(ifStmt();
 }
 
+TEST(MatcherMemoize, HasParentDiffersFromHas) {
+  // Test introduced after detecting a bug in memoization
+EXPECT_TRUE(matches(
+  "void f() { throw 1; }",
+  expr(eachOf(cxxThrowExpr(hasParent(expr())),
+  cxxThrowExpr(has(expr()));
+}
+
 TEST(HasAncestor, MatchesAllAncestors) {
   EXPECT_TRUE(matches(
 "template  struct C { static void f() { 42; } };"
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -43,6 +43,11 @@
 // optimize this on.
 static const unsigned MaxMemoizationEntries = 1;
 
+enum class MatchDirection {
+  Ancestors,
+  Descendants
+};
+
 // We use memoization to avoid running the same matcher on the same
 // AST node twice.  This struct is the key for looking up match
 // result.  It consists of an ID of the MatcherInterface (for
@@ -60,11 +65,12 @@
   ast_type_traits::DynTypedNode Node;
   BoundNodesTreeBuilder BoundNodes;
   ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs;
+  MatchDirection Direction;
 
   bool operator<(const MatchKey ) const {
-return std::tie(MatcherID, Node, BoundNodes, Traversal) <
+return std::tie(MatcherID, Node, BoundNodes, Traversal, Direction) <
std::tie(Other.MatcherID, Other.Node, Other.BoundNodes,
-Other.Traversal);
+Other.Traversal, Other.Direction);
   }
 };
 
@@ -457,6 +463,7 @@
 // Note that we key on the bindings *before* the match.
 Key.BoundNodes = *Builder;
 Key.Traversal = Ctx.getTraversalKind();
+Key.Direction = MatchDirection::Descendants;
 
 MemoizationMap::iterator I = ResultCache.find(Key);
 if (I != ResultCache.end()) {
@@ -706,6 +713,7 @@
 Key.Node = Node;
 Key.BoundNodes = *Builder;
 Key.Traversal = Ctx.getTraversalKind();
+Key.Direction = MatchDirection::Ancestors;
 
 // Note that we cannot use insert and reuse the iterator, as recursive
 // calls to match might invalidate the result cache iterators.


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2591,6 +2591,14 @@
 compoundStmt(hasParent(ifStmt();
 }
 
+TEST(MatcherMemoize, HasParentDiffersFromHas) {
+  // Test introduced after detecting a bug in memoization
+EXPECT_TRUE(matches(
+  "void f() { throw 1; }",
+  expr(eachOf(cxxThrowExpr(hasParent(expr())),
+  cxxThrowExpr(has(expr()));
+}
+
 TEST(HasAncestor, MatchesAllAncestors) {
   EXPECT_TRUE(matches(
 "template  struct C { static void f() { 42; } };"
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -43,6 +43,11 @@
 // optimize this on.
 static const unsigned MaxMemoizationEntries = 1;
 
+enum class MatchDirection {
+  Ancestors,
+  Descendants
+};
+
 // We use memoization to avoid running the same matcher on the same
 // AST node twice.  This struct is the key for looking up match
 // result.  It consists of an ID of the MatcherInterface (for
@@ -60,11 +65,12 @@
   ast_type_traits::DynTypedNode Node;
   BoundNodesTreeBuilder BoundNodes;
   ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs;
+  MatchDirection Direction;
 
   bool operator<(const MatchKey ) const {
-return std::tie(MatcherID, Node, BoundNodes, Traversal) <
+return std::tie(MatcherID, Node, BoundNodes, Traversal, Direction) <
std::tie(Other.MatcherID, Other.Node, Other.BoundNodes,
-Other.Traversal);
+Other.Traversal, Other.Direction);
   }
 };
 
@@ -457,6 +463,7 @@
 // Note that we key on the bindings *before* the match.
  

[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align

2020-05-15 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD updated this revision to Diff 264294.
JakeMerdichAMD added a comment.

Rebase to fix merge conflict


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79465

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11953,6 +11953,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -445,8 +445,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = Changes[i].TokenLength;
-for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11953,6 +11953,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -445,8 +445,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = Changes[i].TokenLength;
-for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80001: [RFC/WIP][clang] Fix printing of names of inherited constructors

2020-05-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

@rsmith - this changes printing the name of inherited constructors in general, 
not just for debug info - could you take a gander and make sure that's probably 
OK for other callers trying to print the name of an inheriting constructor?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80001



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


[PATCH] D79995: [clang] [MinGW] Fix libunwind extension

2020-05-15 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 updated this revision to Diff 264292.
mati865 added a comment.

Applied review comment and formatted.


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

https://reviews.llvm.org/D79995

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


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1234,7 +1234,14 @@
   case ToolChain::UNW_CompilerRT:
 if (LGT == LibGccType::StaticLibGcc)
   CmdArgs.push_back("-l:libunwind.a");
-else
+else if (TC.getTriple().isOSCygMing()) {
+  if (LGT == LibGccType::SharedLibGcc)
+CmdArgs.push_back("-l:libunwind.dll.a");
+  else
+// Let the linker choose between libunwind.dll.a and libunwind.a
+// depending on what's available, and depending on the -static flag
+CmdArgs.push_back("-lunwind");
+} else
   CmdArgs.push_back("-l:libunwind.so");
 break;
   }


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1234,7 +1234,14 @@
   case ToolChain::UNW_CompilerRT:
 if (LGT == LibGccType::StaticLibGcc)
   CmdArgs.push_back("-l:libunwind.a");
-else
+else if (TC.getTriple().isOSCygMing()) {
+  if (LGT == LibGccType::SharedLibGcc)
+CmdArgs.push_back("-l:libunwind.dll.a");
+  else
+// Let the linker choose between libunwind.dll.a and libunwind.a
+// depending on what's available, and depending on the -static flag
+CmdArgs.push_back("-lunwind");
+} else
   CmdArgs.push_back("-l:libunwind.so");
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80023: [clang-tidy] Add abseil-string-find-str-contains checker.

2020-05-15 Thread Tom Lokovic via Phabricator via cfe-commits
tdl-g created this revision.
tdl-g added a reviewer: ymandel.
Herald added subscribers: cfe-commits, phosek, Charusso, mgorny.
Herald added a project: clang.
Eugene.Zelenko edited reviewers, added: alexfh, hokein, aaron.ballman, 
njames93; removed: ymandel.
Eugene.Zelenko added a project: clang-tools-extra.
Eugene.Zelenko retitled this revision from "Add abseil-string-find-str-contains 
checker." to "[clang-tidy] Add abseil-string-find-str-contains checker.".
Herald added a subscriber: xazax.hun.

This adds a checker which suggests replacing string.find(...) == npos with 
absl::StrContains.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80023

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tools-extra/clang-tidy/abseil/CMakeLists.txt
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/abseil-string-find-str-contains.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-str-contains.cpp
@@ -0,0 +1,283 @@
+// RUN: %check_clang_tidy %s abseil-string-find-str-contains %t -- \
+// RUN:   -config="{CheckOptions: []}"
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+
+// Lightweight standin for std::string.
+template 
+class basic_string {
+public:
+  basic_string();
+  basic_string(const basic_string &);
+  basic_string(const C *);
+  ~basic_string();
+  int find(basic_string s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string string;
+
+// Lightweight standin for std::string_view.
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const basic_string_view &);
+  basic_string_view(const C *);
+  ~basic_string_view();
+  int find(basic_string_view s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string_view string_view;
+
+} // namespace std
+
+namespace absl {
+
+// Lightweight standin for absl::string_view.
+class string_view {
+public:
+  string_view();
+  string_view(const string_view &);
+  string_view(const char *);
+  ~string_view();
+  int find(string_view s, int pos = 0);
+  int find(const char *s, int pos = 0);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+
+} // namespace absl
+
+// Functions that take and return our various string-like types.
+std::string foo_ss(std::string);
+std::string_view foo_ssv(std::string_view);
+absl::string_view foo_asv(absl::string_view);
+std::string bar_ss();
+std::string_view bar_ssv();
+absl::string_view bar_asv();
+
+// Confirms that find==npos and find!=npos work for each supported type, when
+// npos comes from the correct type.
+void basic_tests() {
+  std::string ss;
+  ss.find("a") == std::string::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of find() == npos
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, "a");{{$}}
+
+  ss.find("a") != std::string::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of find() != npos
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}}
+
+  std::string::npos != ss.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}}
+
+  std::string_view ssv;
+  ssv.find("a") == std::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, "a");{{$}}
+
+  ssv.find("a") != std::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}}
+
+  std::string_view::npos != ssv.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}}
+
+  absl::string_view asv;
+  asv.find("a") == absl::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, "a");{{$}}
+
+  asv.find("a") != absl::string_view::npos;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}}
+
+  absl::string_view::npos != asv.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 

[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I'd be interested in the answer concerning why we need to avoid `git rev-parse 
HEAD`; it seems like the cleanest solution is to just always check if `git 
rev-parse HEAD` changes to determine whether to regenerate the header.

If that is not feasible for some reason, I would lean towards your option (2), 
but I think more is needed in this patch to ensure the generation script is 
always run, right? How does //removing// a dependency cause the target to be 
executed each build? Don't we need to detect the case where `.git/logs/HEAD` is 
missing and make the target depend on `ALL` or whatever the CMake notion of 
"always out of date" is? We will also need to be OK with the regression in what 
happens when you do a `repo` checkout in a read-write context, as that will 
always run the script whereas before it would have the same behavior as a 
normal checkout. I don't know what the implication of all of these changes are, 
though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400



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


[PATCH] D79973: [WebAssembly] Update latest implemented SIMD instructions

2020-05-15 Thread Thomas Lively via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc702d4bf4110: [WebAssembly] Update latest implemented SIMD 
instructions (authored by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79973

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/Headers/wasm_simd128.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-arith.ll
  llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
  llvm/test/CodeGen/WebAssembly/simd-offset.ll

Index: llvm/test/CodeGen/WebAssembly/simd-offset.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-offset.ll
+++ llvm/test/CodeGen/WebAssembly/simd-offset.ll
@@ -1,5 +1,4 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-keep-registers -wasm-disable-explicit-locals -mattr=+unimplemented-simd128 | FileCheck %s --check-prefixes CHECK,SIMD128
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-keep-registers -wasm-disable-explicit-locals -mattr=+simd128 | FileCheck %s --check-prefixes CHECK,SIMD128-VM
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-keep-registers -wasm-disable-explicit-locals -mattr=+simd128 | FileCheck %s --check-prefixes CHECK,SIMD128
 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-keep-registers -wasm-disable-explicit-locals | FileCheck %s --check-prefixes CHECK,NO-SIMD128
 
 ; Test SIMD loads and stores
@@ -21,7 +20,6 @@
 }
 
 ; CHECK-LABEL: load_splat_v16i8:
-; SIMD128-VM-NOT: v8x16.load_splat
 ; NO-SIMD128-NOT: v128
 ; SIMD128-NEXT: .functype load_splat_v16i8 (i32) -> (v128){{$}}
 ; SIMD128-NEXT: v8x16.load_splat $push[[R:[0-9]+]]=, 0($0){{$}}
@@ -1594,7 +1592,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64 (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i64x2.load32x2_u $push[[R:[0-9]+]]=, 0($0){{$}}
 ; SIMD128-NEXT: return $pop[[R]]{{$}}
@@ -1661,7 +1658,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_with_folded_offset:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_with_folded_offset (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i64x2.load32x2_u $push[[R:[0-9]+]]=, 16($0){{$}}
 ; SIMD128-NEXT: return $pop[[R]]{{$}}
@@ -1723,7 +1719,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_with_folded_gep_offset:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_with_folded_gep_offset (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i64x2.load32x2_u $push[[R:[0-9]+]]=, 8($0){{$}}
 ; SIMD128-NEXT: return $pop[[R]]{{$}}
@@ -1791,7 +1786,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_with_unfolded_gep_negative_offset:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_with_unfolded_gep_negative_offset (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i32.const $push[[L0:[0-9]+]]=, -8{{$}}
 ; SIMD128-NEXT: i32.add $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
@@ -1869,7 +1863,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_with_unfolded_offset:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_with_unfolded_offset (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i32.const $push[[L0:[0-9]+]]=, 16{{$}}
 ; SIMD128-NEXT: i32.add $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
@@ -1941,7 +1934,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_with_unfolded_gep_offset:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_with_unfolded_gep_offset (i32) -> (v128){{$}}
 ; SIMD128-NEXT: i32.const $push[[L0:[0-9]+]]=, 8{{$}}
 ; SIMD128-NEXT: i32.add $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
@@ -2007,7 +1999,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_from_numeric_address:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_from_numeric_address () -> (v128){{$}}
 ; SIMD128-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
 ; SIMD128-NEXT: i64x2.load32x2_u $push[[R:[0-9]+]]=, 32($pop[[L0]]){{$}}
@@ -2071,7 +2062,6 @@
 
 ; CHECK-LABEL: load_ext_v2i64_from_global_address:
 ; NO-SIMD128-NOT: v128
-; SIMD128-VM-NOT: load32x2
 ; SIMD128-NEXT: .functype load_ext_v2i64_from_global_address () -> (v128){{$}}
 ; SIMD128-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
 ; SIMD128-NEXT: i64x2.load32x2_u $push[[R:[0-9]+]]=, gv_v2i32($pop[[L0]]){{$}}
Index: llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
+++ llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
@@ -1,4 +1,5 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs 

[PATCH] D78862: [IR] Convert null-pointer-is-valid into an enum attribute

2020-05-15 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf89f7da999f3: [IR] Convert null-pointer-is-valid into an 
enum attribute (authored by nikic).

Changed prior to commit:
  https://reviews.llvm.org/D78862?vs=261375=264285#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78862

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/delete-null-pointer-checks.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/include/llvm/IR/AutoUpgrade.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Analysis/MemorySSA/cyclicphi.ll
  llvm/test/Analysis/ValueTracking/assume.ll
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
  llvm/test/Transforms/Attributor/align.ll
  llvm/test/Transforms/Attributor/nocapture-1.ll
  llvm/test/Transforms/Attributor/nonnull.ll
  llvm/test/Transforms/Attributor/norecurse.ll
  llvm/test/Transforms/Attributor/undefined_behavior.ll
  llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll
  llvm/test/Transforms/FunctionAttrs/nocapture.ll
  llvm/test/Transforms/FunctionAttrs/nonnull.ll
  llvm/test/Transforms/GVN/PRE/2018-06-08-pre-load-dbgloc-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/MallocSROA-section-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-1-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-1.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-2-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-2.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-3-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-3.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-4-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-4.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-phi-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-phi.ll
  llvm/test/Transforms/GlobalOpt/load-store-global-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/malloc-promote-1.ll
  llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/malloc-promote-2.ll
  llvm/test/Transforms/GlobalOpt/storepointer-compare-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/storepointer-no-null-opt.ll
  llvm/test/Transforms/IPConstantProp/PR26044.ll
  llvm/test/Transforms/Inline/attributes.ll
  llvm/test/Transforms/InstCombine/atomic.ll
  llvm/test/Transforms/InstCombine/invariant.group.ll
  llvm/test/Transforms/InstCombine/invoke.ll
  llvm/test/Transforms/InstCombine/lifetime-no-null-opt.ll
  llvm/test/Transforms/InstCombine/load.ll
  llvm/test/Transforms/InstCombine/mem-deref-bytes.ll
  llvm/test/Transforms/InstCombine/memchr.ll
  llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
  llvm/test/Transforms/InstCombine/memcpy-from-global.ll
  llvm/test/Transforms/InstCombine/memrchr.ll
  llvm/test/Transforms/InstCombine/select.ll
  llvm/test/Transforms/InstCombine/store.ll
  llvm/test/Transforms/InstCombine/strchr-1.ll
  llvm/test/Transforms/InstCombine/strcpy_chk-64.ll
  llvm/test/Transforms/InstCombine/strlen-1.ll
  llvm/test/Transforms/InstCombine/strncat-2.ll
  llvm/test/Transforms/InstCombine/strncmp-1.ll
  llvm/test/Transforms/InstCombine/strrchr-1.ll
  llvm/test/Transforms/InstCombine/strstr-1.ll
  llvm/test/Transforms/InstCombine/wcslen-1.ll
  llvm/test/Transforms/InstSimplify/compare.ll
  llvm/test/Transforms/LoopIdiom/pr28196.ll
  llvm/test/Transforms/LoopVersioning/lcssa.ll
  llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
  llvm/test/Transforms/SimplifyCFG/invoke.ll
  llvm/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll
  llvm/test/Transforms/SimplifyCFG/trap-no-null-opt-debugloc.ll
  llvm/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll
  llvm/test/Transforms/Util/assume-builder.ll
  mlir/test/Target/llvmir.mlir

Index: mlir/test/Target/llvmir.mlir
===
--- mlir/test/Target/llvmir.mlir
+++ mlir/test/Target/llvmir.mlir
@@ -1205,12 +1205,12 @@
 
 // CHECK-LABEL: @passthrough
 // CHECK: #[[ATTR_GROUP:[0-9]*]]
-llvm.func @passthrough() attributes {passthrough = ["noinline", ["alignstack", "4"], "null-pointer-is-valid", ["foo", "bar"]]} {
+llvm.func @passthrough() attributes {passthrough = ["noinline", ["alignstack", "4"], "null_pointer_is_valid", ["foo", "bar"]]} {
   llvm.return
 }
 
 // CHECK: attributes #[[ATTR_GROUP]] = {
 // CHECK-DAG: noinline
 // CHECK-DAG: alignstack=4
-// CHECK-DAG: "null-pointer-is-valid"
+// CHECK-DAG: null_pointer_is_valid
 // CHECK-DAG: "foo"="bar"
Index: 

[clang] c702d4b - [WebAssembly] Update latest implemented SIMD instructions

2020-05-15 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2020-05-15T10:53:02-07:00
New Revision: c702d4bf4110b65ba7a00daf3af3353ea5b74787

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

LOG: [WebAssembly] Update latest implemented SIMD instructions

Summary:
Move instructions that have recently been implemented in V8 from the
`unimplemented-simd128` target feature to the `simd128` target
feature. The updated instructions match the update at
https://github.com/WebAssembly/simd/pull/223.

Reviewers: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, 
cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/Headers/wasm_simd128.h
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-arith.ll
llvm/test/CodeGen/WebAssembly/simd-build-vector.ll
llvm/test/CodeGen/WebAssembly/simd-offset.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index 5955237a0f58..d03905fdb991 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -70,7 +70,7 @@ TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, 
"LLid", "nc", "nontrappi
 TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", 
"nontrapping-fptoint")
 
 // SIMD builtins
-TARGET_BUILTIN(__builtin_wasm_swizzle_v8x16, "V16cV16cV16c", "nc", 
"unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_swizzle_v8x16, "V16cV16cV16c", "nc", "simd128")
 
 TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc", "simd128")

diff  --git a/clang/lib/Headers/wasm_simd128.h 
b/clang/lib/Headers/wasm_simd128.h
index 51e2a07716b3..d79b83b21c0e 100644
--- a/clang/lib/Headers/wasm_simd128.h
+++ b/clang/lib/Headers/wasm_simd128.h
@@ -50,8 +50,6 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_v128_load(const void *__mem) {
   return ((const struct __wasm_v128_load_struct *)__mem)->__v;
 }
 
-#ifdef __wasm_unimplemented_simd128__
-
 static __inline__ v128_t __DEFAULT_FN_ATTRS
 wasm_v8x16_load_splat(const void *__mem) {
   struct __wasm_v8x16_load_splat_struct {
@@ -149,8 +147,6 @@ wasm_u64x2_load_32x2(const void *__mem) {
   return (v128_t) __builtin_convertvector(__v, __u64x2);
 }
 
-#endif // __wasm_unimplemented_simd128__
-
 static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store(void *__mem,
   v128_t __a) {
   // UB-free unaligned access copied from xmmintrin.h
@@ -564,15 +560,11 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS 
wasm_v128_xor(v128_t __a,
   return __a ^ __b;
 }
 
-#ifdef __wasm_unimplemented_simd128__
-
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_andnot(v128_t __a,
  v128_t __b) {
   return __a & ~__b;
 }
 
-#endif // __wasm_unimplemented_simd128__
-
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_bitselect(v128_t __a,
 v128_t __b,
 v128_t __mask) 
{
@@ -1066,15 +1058,11 @@ wasm_f32x4_convert_u32x4(v128_t __a) {
   __c1 * 8, __c1 * 8 + 1, __c1 * 8 + 2, __c1 * 8 + 3, __c1 * 8 + 4,
\
   __c1 * 8 + 5, __c1 * 8 + 6, __c1 * 8 + 7))
 
-#ifdef __wasm_unimplemented_simd128__
-
 static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v8x16_swizzle(v128_t __a,
v128_t __b) {
   return (v128_t)__builtin_wasm_swizzle_v8x16((__i8x16)__a, (__i8x16)__b);
 }
 
-#endif // __wasm_unimplemented_simd128__
-
 static __inline__ v128_t __DEFAULT_FN_ATTRS
 wasm_i8x16_narrow_i16x8(v128_t __a, v128_t __b) {
   return (v128_t)__builtin_wasm_narrow_s_i8x16_i16x8((__i16x8)__a,

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 4a4585814381..0f8bb91ac496 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -239,12 +239,10 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
   }
 }
 // But some vector extending loads are legal
-if (Subtarget->hasUnimplementedSIMD128()) {
-  for (auto Ext : {ISD::EXTLOAD, ISD::SEXTLOAD, ISD::ZEXTLOAD}) {
-setLoadExtAction(Ext, MVT::v8i16, MVT::v8i8, Legal);
-setLoadExtAction(Ext, MVT::v4i32, MVT::v4i16, Legal);
-  

[PATCH] D79995: [clang] [MinGW] Fix libunwind extension

2020-05-15 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a reviewer: rnk.
mstorsjo added a subscriber: rnk.
mstorsjo added a comment.

So, using `-l:libunwind.dll.a` is definitely more correct than 
`-l:libunwind.so` on this platform, so in that sense this is good.

In my toolchains I don't use this option at all so far, because I have 
libunwind bundled into libc++.a/libc++.dll.a, but I guess it would be nice to 
move towards this setup and stop bundling them. But the toolchains can be 
configured to omit either the shared or the static version of the libraries, 
and if libunwind only exists in static form, this would fail.

If there's only a shared version, and building with `-static-libgcc`, I guess 
it's ok to look for explicitly `libunwind.a` and fail in that case, but for the 
default case, I think the normal library resolution logic would be best, i.e. 
just doing `-lunwind`.

The ideal version from my point of view would be this:

  case ToolChain::UNW_CompilerRT:
if (LGT == LibGccType::StaticLibGcc)
  CmdArgs.push_back("-l:libunwind.a");
else if (TC.getTriple().isOSCygMing()) {
  if (LGT == LibGccType::SharedLibGcc)
CmdArgs.push_back("-l:libunwind.dll.a");
  else
CmdArgs.push_back("-lunwind"); // Let the linker choose between 
libunwind.dll.a and libunwind.a depending on what's available, and depending on 
the -static flag
} else
  CmdArgs.push_back("-l:libunwind.so");
break;

That's rather different than the other, non-mingw cases though, but I'm not 
familiar with the reasoning behind those.

Adding @rnk if he'd happen to have opinions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79995



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


[PATCH] D80020: [PowerPC] Add support for -mcpu=pwr10 in the front end

2020-05-15 Thread Lei Huang via Phabricator via cfe-commits
lei created this revision.
lei added reviewers: stefanp, nemanjai, amyk, hfinkel, power-llvm-team.
Herald added subscribers: shchenz, wuzish.
Herald added a project: clang.
jsji added a reviewer: PowerPC.
jsji added a project: PowerPC.

This patch simply adds support for the new CPU in anticipation of
Power10. There isn't really any functionality added so there are no
associated test cases at this time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80020

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/init-ppc64.c

Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -627,6 +627,22 @@
 // PPCPOWER9:#define _ARCH_PWR7 1
 // PPCPOWER9:#define _ARCH_PWR9 1
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu pwr10 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER10 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu power10 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER10 %s
+//
+// PPCPOWER10:#define _ARCH_PPC 1
+// PPCPOWER10:#define _ARCH_PPC64 1
+// PPCPOWER10:#define _ARCH_PPCGR 1
+// PPCPOWER10:#define _ARCH_PPCSQ 1
+// PPCPOWER10:#define _ARCH_PWR10 1
+// PPCPOWER10:#define _ARCH_PWR4 1
+// PPCPOWER10:#define _ARCH_PWR5 1
+// PPCPOWER10:#define _ARCH_PWR5X 1
+// PPCPOWER10:#define _ARCH_PWR6 1
+// PPCPOWER10-NOT:#define _ARCH_PWR6X 1
+// PPCPOWER10:#define _ARCH_PWR7 1
+// PPCPOWER10:#define _ARCH_PWR9 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu future -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCFUTURE %s
 //
 // PPCFUTURE:#define _ARCH_PPC 1
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -81,7 +81,7 @@
 // PPC-SAME: 603e, 603ev, 604, 604e, 620, 630, g3, 7400, g4, 7450, g4+, 750,
 // PPC-SAME: 8548, 970, g5, a2, a2q, e500, e500mc, e5500, power3, pwr3, power4,
 // PPC-SAME: pwr4, power5, pwr5, power5x, pwr5x, power6, pwr6, power6x, pwr6x,
-// PPC-SAME: power7, pwr7, power8, pwr8, power9, pwr9, powerpc, ppc, powerpc64,
+// PPC-SAME: power7, pwr7, power8, pwr8, power9, pwr9, power10, pwr10, powerpc, ppc, powerpc64,
 // PPC-SAME: ppc64, powerpc64le, ppc64le, future
 
 // RUN: not %clang_cc1 -triple mips--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix MIPS
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -70,6 +70,7 @@
 .Case("power7", "pwr7")
 .Case("power8", "pwr8")
 .Case("power9", "pwr9")
+.Case("power10", "pwr10")
 .Case("future", "future")
 .Case("pwr3", "pwr3")
 .Case("pwr4", "pwr4")
@@ -80,6 +81,7 @@
 .Case("pwr7", "pwr7")
 .Case("pwr8", "pwr8")
 .Case("pwr9", "pwr9")
+.Case("pwr10", "pwr10")
 .Case("powerpc", "ppc")
 .Case("powerpc64", "ppc64")
 .Case("powerpc64le", "ppc64le")
@@ -91,14 +93,16 @@
 
 const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
   return llvm::StringSwitch(Name)
-.Case("pwr7", "-mpower7")
-.Case("power7", "-mpower7")
-.Case("pwr8", "-mpower8")
-.Case("power8", "-mpower8")
-.Case("ppc64le", "-mpower8")
-.Case("pwr9", "-mpower9")
-.Case("power9", "-mpower9")
-.Default("-many");
+  .Case("pwr7", "-mpower7")
+  .Case("power7", "-mpower7")
+  .Case("pwr8", "-mpower8")
+  .Case("power8", "-mpower8")
+  .Case("ppc64le", "-mpower8")
+  .Case("pwr9", "-mpower9")
+  .Case("power9", "-mpower9")
+  .Case("pwr10", "-mpower10")
+  .Case("power10", "-mpower10")
+  .Default("-many");
 }
 
 void ppc::getPPCTargetFeatures(const Driver , const llvm::Triple ,
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -43,13 +43,13 @@
 ArchDefinePwr7 = 1 << 11,
 ArchDefinePwr8 = 1 << 12,
 ArchDefinePwr9 = 1 << 13,
-ArchDefineFuture = 1 << 14,
-ArchDefineA2 = 1 << 15,
-ArchDefineA2q = 1 << 16,
-ArchDefineE500 = 1 << 17
+ArchDefinePwr10 = 1 << 14,
+ArchDefineFuture = 1 << 15,
+ArchDefineA2 = 1 << 16,
+ArchDefineA2q = 1 << 17,
+ArchDefineE500 = 1 << 18
   } ArchDefineTypes;
 
-
   ArchDefineTypes ArchDefs = ArchDefineNone;
   static const Builtin::Info BuiltinInfo[];
   

[PATCH] D78508: [Clang] Allow long as size_t printf argument on 32-bit Windows platforms.

2020-05-15 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> clang issues a warning, leaving no good way to print SIZE_T (other than 
> disabling warnings or adding useless casts)

I also don't think Clang should change here though. The warning is legit for 
code that cares about portability, and inserting a cast is probably the best 
fix for such code. For code that doesn't care, disabling the warning seems like 
the way to go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78508



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


[clang] f89f7da - [IR] Convert null-pointer-is-valid into an enum attribute

2020-05-15 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2020-05-15T19:41:07+02:00
New Revision: f89f7da999f362e4213c69923328dd1033276e59

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

LOG: [IR] Convert null-pointer-is-valid into an enum attribute

The "null-pointer-is-valid" attribute needs to be checked by many
pointer-related combines. To make the check more efficient, convert
it from a string into an enum attribute.

In the future, this attribute may be replaced with data layout
properties.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/delete-null-pointer-checks.c
llvm/docs/LangRef.rst
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/include/llvm/IR/AutoUpgrade.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/AsmParser/LLToken.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Analysis/MemorySSA/cyclicphi.ll
llvm/test/Analysis/ValueTracking/assume.ll
llvm/test/Bitcode/attributes.ll
llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
llvm/test/Transforms/Attributor/align.ll
llvm/test/Transforms/Attributor/nocapture-1.ll
llvm/test/Transforms/Attributor/nonnull.ll
llvm/test/Transforms/Attributor/norecurse.ll
llvm/test/Transforms/Attributor/undefined_behavior.ll
llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll
llvm/test/Transforms/FunctionAttrs/nocapture.ll
llvm/test/Transforms/FunctionAttrs/nonnull.ll
llvm/test/Transforms/GVN/PRE/2018-06-08-pre-load-dbgloc-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/MallocSROA-section-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-1-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-1.ll
llvm/test/Transforms/GlobalOpt/heap-sra-2-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-2.ll
llvm/test/Transforms/GlobalOpt/heap-sra-3-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-3.ll
llvm/test/Transforms/GlobalOpt/heap-sra-4-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-4.ll
llvm/test/Transforms/GlobalOpt/heap-sra-phi-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/heap-sra-phi.ll
llvm/test/Transforms/GlobalOpt/load-store-global-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/malloc-promote-1.ll
llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/malloc-promote-2.ll
llvm/test/Transforms/GlobalOpt/storepointer-compare-no-null-opt.ll
llvm/test/Transforms/GlobalOpt/storepointer-no-null-opt.ll
llvm/test/Transforms/IPConstantProp/PR26044.ll
llvm/test/Transforms/Inline/attributes.ll
llvm/test/Transforms/InstCombine/atomic.ll
llvm/test/Transforms/InstCombine/invariant.group.ll
llvm/test/Transforms/InstCombine/invoke.ll
llvm/test/Transforms/InstCombine/lifetime-no-null-opt.ll
llvm/test/Transforms/InstCombine/load.ll
llvm/test/Transforms/InstCombine/mem-deref-bytes.ll
llvm/test/Transforms/InstCombine/memchr.ll
llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
llvm/test/Transforms/InstCombine/memcpy-from-global.ll
llvm/test/Transforms/InstCombine/memrchr.ll
llvm/test/Transforms/InstCombine/select.ll
llvm/test/Transforms/InstCombine/store.ll
llvm/test/Transforms/InstCombine/strchr-1.ll
llvm/test/Transforms/InstCombine/strcpy_chk-64.ll
llvm/test/Transforms/InstCombine/strlen-1.ll
llvm/test/Transforms/InstCombine/strncat-2.ll
llvm/test/Transforms/InstCombine/strncmp-1.ll
llvm/test/Transforms/InstCombine/strrchr-1.ll
llvm/test/Transforms/InstCombine/strstr-1.ll
llvm/test/Transforms/InstCombine/wcslen-1.ll
llvm/test/Transforms/InstSimplify/compare.ll
llvm/test/Transforms/LoopIdiom/pr28196.ll
llvm/test/Transforms/LoopVersioning/lcssa.ll
llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
llvm/test/Transforms/SimplifyCFG/invoke.ll
llvm/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll
llvm/test/Transforms/SimplifyCFG/trap-no-null-opt-debugloc.ll
llvm/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll
llvm/test/Transforms/Util/assume-builder.ll
mlir/test/Target/llvmir.mlir

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 32a9ba499ecb..068d053d17cc 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1744,7 +1744,7 @@ void 

[PATCH] D74668: [Clang][BPF] implement __builtin_btf_type_id() builtin function

2020-05-15 Thread Yonghong Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG072cde03aaa1: [Clang][BPF] implement __builtin_btf_type_id() 
builtin function (authored by yonghong-song).

Changed prior to commit:
  https://reviews.llvm.org/D74668?vs=261976=264273#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74668

Files:
  clang/include/clang/Basic/BuiltinsBPF.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-bpf-btf-type-id.c
  clang/test/Sema/builtin-bpf-btf-type-id.c
  llvm/include/llvm/IR/IntrinsicsBPF.td

Index: llvm/include/llvm/IR/IntrinsicsBPF.td
===
--- llvm/include/llvm/IR/IntrinsicsBPF.td
+++ llvm/include/llvm/IR/IntrinsicsBPF.td
@@ -23,4 +23,7 @@
   def int_bpf_preserve_field_info : GCCBuiltin<"__builtin_bpf_preserve_field_info">,
   Intrinsic<[llvm_i32_ty], [llvm_anyptr_ty, llvm_i64_ty],
   [IntrNoMem, ImmArg<1>]>;
+  def int_bpf_btf_type_id : GCCBuiltin<"__builtin_bpf_btf_type_id">,
+  Intrinsic<[llvm_i32_ty], [llvm_any_ty, llvm_any_ty, llvm_i64_ty],
+  [IntrNoMem]>;
 }
Index: clang/test/Sema/builtin-bpf-btf-type-id.c
===
--- /dev/null
+++ clang/test/Sema/builtin-bpf-btf-type-id.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x c -triple bpf-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
+
+struct {
+  char f1[100];
+  int f2;
+} tmp = {};
+
+unsigned invalid1() { return __builtin_btf_type_id(1, tmp); } // expected-error {{__builtin_btf_type_id argument 2 not a constant}}
+unsigned invalid2() { return __builtin_btf_type_id(1, 1, 1); } // expected-error {{too many arguments to function call, expected 2, have 3}}
+
+int valid1() { return __builtin_btf_type_id(tmp, 0); }
+int valid2() { return __builtin_btf_type_id(, 1); }
+int valid3() { return __builtin_btf_type_id(tmp.f1[4], 10); }
Index: clang/test/CodeGen/builtin-bpf-btf-type-id.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-bpf-btf-type-id.c
@@ -0,0 +1,13 @@
+// REQUIRES: bpf-registered-target
+// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s
+
+unsigned test1(int a) { return __builtin_btf_type_id(a, 0); }
+unsigned test2(int a) { return __builtin_btf_type_id(, 0); }
+
+// CHECK: define dso_local i32 @test1
+// CHECK: call i32 @llvm.bpf.btf.type.id.p0i32.i32(i32* %{{[0-9a-z.]+}}, i32 1, i64 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[INT:[0-9]+]]
+// CHECK: define dso_local i32 @test2
+// CHECK: call i32 @llvm.bpf.btf.type.id.p0i32.i32(i32* %{{[0-9a-z.]+}}, i32 0, i64 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[INT_POINTER:[0-9]+]]
+//
+// CHECK: ![[INT]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed
+// CHECK: ![[INT_POINTER]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[INT]], size: 64
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2487,17 +2487,33 @@
 
 bool Sema::CheckBPFBuiltinFunctionCall(unsigned BuiltinID,
CallExpr *TheCall) {
-  assert(BuiltinID == BPF::BI__builtin_preserve_field_info &&
+  assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
+  BuiltinID == BPF::BI__builtin_btf_type_id) &&
  "unexpected ARM builtin");
 
   if (checkArgCount(*this, TheCall, 2))
 return true;
 
+  Expr *Arg;
+  if (BuiltinID == BPF::BI__builtin_btf_type_id) {
+// The second argument needs to be a constant int
+llvm::APSInt Value;
+Arg = TheCall->getArg(1);
+if (!Arg->isIntegerConstantExpr(Value, Context)) {
+  Diag(Arg->getBeginLoc(), diag::err_btf_type_id_not_const)
+  << 2 << Arg->getSourceRange();
+  return true;
+}
+
+TheCall->setType(Context.UnsignedIntTy);
+return false;
+  }
+
   // The first argument needs to be a record field access.
   // If it is an array element access, we delay decision
   // to BPF backend to check whether the access is a
   // field access or not.
-  Expr *Arg = TheCall->getArg(0);
+  Arg = TheCall->getArg(0);
   if (Arg->getType()->getAsPlaceholderType() ||
   (Arg->IgnoreParens()->getObjectKind() != OK_BitField &&
!dyn_cast(Arg->IgnoreParens()) &&
@@ -2508,8 +2524,9 @@
   }
 
   // The second argument needs to be a constant int
+  Arg = TheCall->getArg(1);
   llvm::APSInt Value;
-  if (!TheCall->getArg(1)->isIntegerConstantExpr(Value, Context)) {
+  if (!Arg->isIntegerConstantExpr(Value, Context)) {
 Diag(Arg->getBeginLoc(), diag::err_preserve_field_info_not_const)
 << 2 << Arg->getSourceRange();
 return true;
Index: 

[PATCH] D79972: [OpenMP5.0] map item can be non-contiguous for target update

2020-05-15 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen updated this revision to Diff 264266.
cchen added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79972

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/target_update_ast_print.cpp
  clang/test/OpenMP/target_update_codegen.cpp

Index: clang/test/OpenMP/target_update_codegen.cpp
===
--- clang/test/OpenMP/target_update_codegen.cpp
+++ clang/test/OpenMP/target_update_codegen.cpp
@@ -1059,5 +1059,142 @@
   #pragma omp target update from(([sa][5])f)
 }
 
+#endif
+
+///==///
+// RUN: %clang_cc1 -DCK19 -verify -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s --check-prefix CK19 --check-prefix CK19-64
+// RUN: %clang_cc1 -DCK19 -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  --check-prefix CK19 --check-prefix CK19-64
+// RUN: %clang_cc1 -DCK19 -verify -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s  --check-prefix CK19 --check-prefix CK19-32
+// RUN: %clang_cc1 -DCK19 -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s  --check-prefix CK19 --check-prefix CK19-32
+
+// RUN: %clang_cc1 -DCK19 -verify -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY19 %s
+// RUN: %clang_cc1 -DCK19 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY19 %s
+// RUN: %clang_cc1 -DCK19 -verify -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY19 %s
+// RUN: %clang_cc1 -DCK19 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY19 %s
+// SIMD-ONLY19-NOT: {{__kmpc|__tgt}}
+#ifdef CK19
+
+// CK19: [[STRUCT_DESCRIPTOR:%.+]]  = type { i64, i64, i64 }
+
+// CK19: [[MSIZE:@.+]] = {{.+}}constant [1 x i64] [i64 3]
+// CK19: [[MTYPE:@.+]] = {{.+}}constant [1 x i64] [i64 2081]
+
+// CK19-LABEL: _Z3foo
+void foo(int arg) {
+  int arr[3][4][5];
+
+  // CK19: [[DIMS:%.+]] = alloca [3 x [[STRUCT_DESCRIPTOR]]],
+  // CK19: [[ARRAY_IDX:%.+]] = getelementptr inbounds [3 x [4 x [5 x i32]]], [3 x [4 x [5 x i32]]]* [[ARR:%.+]], {{.+}} 0, {{.+}} 0
+  // CK19: [[ARRAY_DECAY:%.+]] = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* [[ARRAY_IDX]], {{.+}} 0, {{.+}} 0
+  // CK19: [[ARRAY_IDX_1:%.+]] = getelementptr inbounds [5 x i32], [5 x i32]* [[ARRAY_DECAY]], {{.+}}
+  // CK19: [[ARRAY_DECAY_2:%.+]] = getelementptr inbounds [5 x i32], [5 x i32]* [[ARRAY_IDX_1]], {{.+}} 0, {{.+}} 0
+  // CK19: [[ARRAY_IDX_3:%.+]] = getelementptr inbounds {{.+}}, {{.+}}* [[ARRAY_DECAY_2]], {{.+}} 1
+  // CK19: [[LEN:%.+]] = sub nuw i64 4, [[ARG_ADDR:%.+]]
+  // CK19: [[BP0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[BP:%.+]], i{{.+}} 0, i{{.+}} 0
+  // CK19: [[P0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[P:%.+]], i{{.+}} 0, i{{.+}} 0
+  // CK19: [[DIM_1:%.+]] = getelementptr inbounds [3 x [[STRUCT_DESCRIPTOR]]], [3 x [[STRUCT_DESCRIPTOR]]]* [[DIMS]], {{.+}} 0, {{.+}} 0
+  // CK19: [[OFFSET:%.+]] = getelementptr inbounds [[STRUCT_DESCRIPTOR]], [[STRUCT_DESCRIPTOR]]* [[DIM_1]], {{.+}} 0, {{.+}} 0
+  // CK19: store i64 0, i64* [[OFFSET]],
+  // CK19: [[COUNT:%.+]] = getelementptr 

[PATCH] D78374: [Analyzer][StreamChecker] Added evaluation of fread and fwrite.

2020-05-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Created new revisions for parts of this change and a bit improved: D80009 
 and others in "Stack".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78374



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


[clang] 072cde0 - [Clang][BPF] implement __builtin_btf_type_id() builtin function

2020-05-15 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2020-05-15T09:44:54-07:00
New Revision: 072cde03aaa13a2c57acf62d79876bf79aa1919f

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

LOG: [Clang][BPF] implement __builtin_btf_type_id() builtin function

Such a builtin function is mostly useful to preserve btf type id
for non-global data. For example,
   extern void foo(..., void *data, int size);
   int test(...) {
 struct t { int a; int b; int c; } d;
 d.a = ...; d.b = ...; d.c = ...;
 foo(..., , sizeof(d));
   }

The function "foo" in the above only see raw data and does not
know what type of the data is. In certain cases, e.g., logging,
the additional type information will help pretty print.

This patch implemented a BPF specific builtin
  u32 btf_type_id = __builtin_btf_type_id(param, flag)
which will return a btf type id for the "param".
flag == 0 will indicate a BTF local relocation,
which means btf type_id only adjusted when bpf program BTF changes.
flag == 1 will indicate a BTF remote relocation,
which means btf type_id is adjusted against linux kernel or
future other entities.

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

Added: 
clang/test/CodeGen/builtin-bpf-btf-type-id.c
clang/test/Sema/builtin-bpf-btf-type-id.c

Modified: 
clang/include/clang/Basic/BuiltinsBPF.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
llvm/include/llvm/IR/IntrinsicsBPF.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsBPF.def 
b/clang/include/clang/Basic/BuiltinsBPF.def
index bd96b9ef531b..237e9dc8784b 100644
--- a/clang/include/clang/Basic/BuiltinsBPF.def
+++ b/clang/include/clang/Basic/BuiltinsBPF.def
@@ -20,5 +20,8 @@
 // Get record field information.
 TARGET_BUILTIN(__builtin_preserve_field_info, "Ui.", "t", "")
 
+// Get BTF type id.
+TARGET_BUILTIN(__builtin_btf_type_id, "Ui.", "t", "")
+
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 371e20183e1e..0fe8b1e6abfc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10749,6 +10749,8 @@ def err_preserve_field_info_not_field : Error<
   "__builtin_preserve_field_info argument %0 not a field access">;
 def err_preserve_field_info_not_const: Error<
   "__builtin_preserve_field_info argument %0 not a constant">;
+def err_btf_type_id_not_const: Error<
+  "__builtin_btf_type_id argument %0 not a constant">;
 
 def err_bit_cast_non_trivially_copyable : Error<
   "__builtin_bit_cast %select{source|destination}0 type must be trivially 
copyable">;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5166f91e252c..524924e36638 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10633,33 +10633,103 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 
 Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
const CallExpr *E) {
-  assert(BuiltinID == BPF::BI__builtin_preserve_field_info &&
- "unexpected ARM builtin");
+  assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
+  BuiltinID == BPF::BI__builtin_btf_type_id) &&
+ "unexpected BPF builtin");
 
-  const Expr *Arg = E->getArg(0);
-  bool IsBitField = Arg->IgnoreParens()->getObjectKind() == OK_BitField;
+  switch (BuiltinID) {
+  default:
+llvm_unreachable("Unexpected BPF builtin");
+  case BPF::BI__builtin_preserve_field_info: {
+const Expr *Arg = E->getArg(0);
+bool IsBitField = Arg->IgnoreParens()->getObjectKind() == OK_BitField;
 
-  if (!getDebugInfo()) {
-CGM.Error(E->getExprLoc(), "using builtin_preserve_field_info() without 
-g");
-return IsBitField ? EmitLValue(Arg).getBitFieldPointer()
-  : EmitLValue(Arg).getPointer(*this);
-  }
+if (!getDebugInfo()) {
+  CGM.Error(E->getExprLoc(),
+"using __builtin_preserve_field_info() without -g");
+  return IsBitField ? EmitLValue(Arg).getBitFieldPointer()
+: EmitLValue(Arg).getPointer(*this);
+}
+
+// Enable underlying preserve_*_access_index() generation.
+bool OldIsInPreservedAIRegion = IsInPreservedAIRegion;
+IsInPreservedAIRegion = true;
+Value *FieldAddr = IsBitField ? EmitLValue(Arg).getBitFieldPointer()
+  : EmitLValue(Arg).getPointer(*this);
+IsInPreservedAIRegion = OldIsInPreservedAIRegion;
+
+ConstantInt *C = cast(EmitScalarExpr(E->getArg(1)));
+Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue());
+
+// Built the IR for 

[PATCH] D80018: [Analyzer][StreamChecker] Added check for "indeterminate file position".

2020-05-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

According to the standard, after a `wread` or `fwrite` call the file position
becomes "indeterminate". It is assumable that a next read or write causes
undefined behavior, so a (fatal error) warning is added for this case.
The indeterminate position can be cleared by some operations, for example
`fseek` or `freopen`, not with `clearerr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80018

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-error.c

Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -76,7 +76,7 @@
 }
 if (ferror(F)) {
   clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
-  fread(Buf, 1, 10, F);   // no warning
+  fread(Buf, 1, 10, F);   // expected-warning {{might be 'indeterminate'}}
 }
   }
   fclose(F);
@@ -94,7 +94,7 @@
   } else {
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
-fwrite(0, 1, 10, F);// no warning
+fwrite(0, 1, 10, F);// expected-warning {{might be 'indeterminate'}}
   }
   fclose(F);
   Ret = fwrite(0, 1, 10, F); // expected-warning {{Stream might be already closed}}
@@ -166,3 +166,36 @@
   }
   fclose(F);
 }
+
+void error_fseek_indeterminate() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  const char *Buf = "123456789";
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+if (feof(F)) {
+  fwrite(Buf, 1, 10, F); // no warning
+} else if (ferror(F)) {
+  fwrite(Buf, 1, 10, F); // expected-warning {{might be 'indeterminate'}}
+} else {
+  fwrite(Buf, 1, 10, F); // expected-warning {{might be 'indeterminate'}}
+}
+  }
+  fclose(F);
+}
+
+void error_clearerr_indeterminate() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  const char *Buf = "123456789";
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+if (!feof(F)) {
+  clearerr(F);
+  fwrite(Buf, 1, 10, F); // expected-warning {{might be 'indeterminate'}}
+}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -97,6 +97,16 @@
   /// Ignored in non-opened stream state but must be NoError.
   StreamErrorState ErrorState;
 
+  /// Indicate if the file has an "indeterminate file position indicator".
+  /// This can be set at a failing read or write or seek operation.
+  /// If it is set no more read or write is allowed.
+  /// This value is not dependent on the stream error flags:
+  /// The error flag may be cleared with `clearerr` but the file position
+  /// remains still indeterminate.
+  /// This value applies to all error states in ErrorState except FEOF.
+  /// An EOF+indeterminate state is the same as EOF state.
+  bool FilePositionIndeterminate = false;
+
   bool isOpened() const { return State == Opened; }
   bool isClosed() const { return State == Closed; }
   bool isOpenFailed() const { return State == OpenFailed; }
@@ -105,12 +115,14 @@
 // In not opened state error state should always NoError, so comparison
 // here is no problem.
 return LastOperation == X.LastOperation && State == X.State &&
-   ErrorState == X.ErrorState;
+   ErrorState == X.ErrorState &&
+   FilePositionIndeterminate == X.FilePositionIndeterminate;
   }
 
   static StreamState getOpened(const FnDescription *L,
-   const StreamErrorState  = {}) {
-return StreamState{L, Opened, ES};
+   const StreamErrorState  = ErrorNone,
+   bool FPI = false) {
+return StreamState{L, Opened, ES, FPI};
   }
   static StreamState getClosed(const FnDescription *L) {
 return StreamState{L, Closed};
@@ -123,6 +135,7 @@
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
 ID.AddInteger(ErrorState);
+ID.AddBoolean(FilePositionIndeterminate);
   }
 };
 
@@ -176,7 +189,8 @@
 class StreamChecker
 : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak, BT_StreamEof;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak, BT_StreamEof,
+  BT_IndeterminatePosition;
 
 public:
   void checkPreCall(const CallEvent , CheckerContext ) const;
@@ -282,6 +296,16 @@
   ProgramStateRef ensureStreamOpened(SVal 

[PATCH] D78508: [Clang] Allow long as size_t printf argument on 32-bit Windows platforms.

2020-05-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D78508#2038793 , @amccarth wrote:

> I'll re-iterate my opinion that the casts currently required to bypass the 
> warnings are useful (e.g., if you ever want to port the code to 64-bit).  
> There are lots of places where the Windows API essentially required 
> uncomfortable conversions, and we can't paper over all of them.  The way to 
> get it right in all those other places is to be very aware of the underlying 
> types.  Hiding an uncomfortable detail here and there seems like a disservice.


+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78508



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


[PATCH] D79322: [FEnv] Small fixes to implementation of flt.rounds

2020-05-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff marked an inline comment as done.
sepavloff added inline comments.



Comment at: llvm/test/CodeGen/RISCV/flt-rounds.ll:23
+; RV64I-NEXT:sd ra, 8(sp)
+; RV64I-NEXT:call __flt_rounds
+; RV64I-NEXT:ld ra, 8(sp)

lenary wrote:
> I'm interested to understand how this function is provided. Is it part of 
> `compiler-rt` or `libgcc`, or is it provided another way?
At least musl library provides its implementation: 
https://git.musl-libc.org/cgit/musl/tree/src/fenv/__flt_rounds.c . Similar 
implementation exists in glibc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79322



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


[PATCH] D79754: [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 1

2020-05-15 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:1261
+  /// Currently only supports NVPTX and AMDGCN
+  static bool isOpenMPGPU(llvm::Triple ) {
+return T.isNVPTX() || T.isAMDGCN();

How is "OpenMP-compatible GPU" defined? I think it's too early to start 
designing predicates about whether a target is a GPU and whether it supports 
OpenMP.



Comment at: clang/lib/AST/Decl.cpp:3221
+!hasAttr()) ||
+   Context.getTargetInfo().getTriple().isAMDGCN()) &&
   !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))

This seems awkward to me. Why mix it up with only CUDA and HIP? The earlier 
factoring is better, where CUDA/HIP took care of their own business, and the 
catch-all case of AMDGCN was a separate clause by itself. It doesn't matter 
that the builtins being checked for AMDGCN on OpenMP are //currently// 
identical to CUDA/HIP. When this situation later changes (I am sure OpenMP will 
support more builtins), we will have to split it out again anyway.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3100
 
+  bool IsOpenMPGPU = clang::TargetInfo::isOpenMPGPU(T);
+

I am not particularly in favour of introducing a variable just because it looks 
smaller than a call at each appropriate location. If you really want it this 
way, at least make it a const.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3104
   // handling code for those requiring so.
-  if ((Opts.OpenMPIsDevice && T.isNVPTX()) || Opts.OpenCLCPlusPlus) {
+  if ((Opts.OpenMPIsDevice && IsOpenMPGPU) || Opts.OpenCLCPlusPlus) {
 Opts.Exceptions = 0;

Looking at the comment before this line, the correct predicate would "target 
supports exceptions with OpenMP". Is it always true that every GPU that 
supports OpenMP will not support exception handling? I would recommend just 
checking individual targets for now instead of inventing predicates.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3157
+  // Set CUDA mode for OpenMP target NVPTX/AMDGCN if specified in options
+  Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && IsOpenMPGPU &&
 Args.hasArg(options::OPT_fopenmp_cuda_mode);

Is there any reason to believe that every future GPU added to this predicate 
will also want the CUDA mode set? I would recommend using individual targets 
for now instead of inventing a new predicate.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3162
   Opts.OpenMPCUDAForceFullRuntime =
-  Opts.OpenMPIsDevice && T.isNVPTX() &&
+  Opts.OpenMPIsDevice && IsOpenMPGPU &&
   Args.hasArg(options::OPT_fopenmp_cuda_force_full_runtime);

Same doubt about this use of an artificial predicate as commented earlier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79754



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


[PATCH] D78508: [Clang] Allow long as size_t printf argument on 32-bit Windows platforms.

2020-05-15 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth added a comment.

I'll re-iterate my opinion that the casts currently required to bypass the 
warnings are useful (e.g., if you ever want to port the code to 64-bit).  There 
are lots of places where the Windows API essentially required uncomfortable 
conversions, and we can't paper over all of them.  The way to get it right in 
all those other places is to be very aware of the underlying types.  Hiding an 
uncomfortable detail here and there seems like a disservice.




Comment at: clang/lib/AST/FormatString.cpp:407
+if ((isSizeT() || isPtrdiffT()) &&
+C.getTargetInfo().getTriple().isOSMSVCRT() &&
+C.getTargetInfo().getTriple().isArch32Bit())

I'm not convinced `isOSMSVCRT` is the right check.  The troubling typedefs are 
[[ 
https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#size-t
 | `SIZE_T` and `SSIZE_T` ]], which come from the Windows API and are unrelated 
to Microsoft's C run-time library.  I think `isOSWindows` would be more precise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78508



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


[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align

2020-05-15 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD updated this revision to Diff 264259.
JakeMerdichAMD added a comment.

Add a comment explaining why checking IsInsideToken is needed here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79465

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11564,6 +11564,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -410,8 +410,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = -Changes[i].Spaces;
-for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11564,6 +11564,16 @@
"  x = 1;\n"
"y = 1;\n",
Alignment);
+
+  Alignment.ReflowComments = true;
+  Alignment.ColumnLimit = 50;
+  EXPECT_EQ("int x   = 0;\n"
+"int yy  = 1; /// specificlennospace\n"
+"int zzz = 2;\n",
+format("int x   = 0;\n"
+   "int yy  = 1; ///specificlennospace\n"
+   "int zzz = 2;\n",
+   Alignment));
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -410,8 +410,16 @@
 
 unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
 int LineLengthAfter = -Changes[i].Spaces;
-for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j)
-  LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
+for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) {
+  LineLengthAfter += Changes[j].Spaces;
+  // Changes are generally 1:1 with the tokens, but a change could also be
+  // inside of a token, in which case it's counted more than once: once for
+  // the whitespace surrounding the token (!IsInsideToken) and once for
+  // each whitespace change within it (IsInsideToken).
+  // Therefore, changes inside of a token should only count the space.
+  if (!Changes[j].IsInsideToken)
+LineLengthAfter += Changes[j].TokenLength;
+}
 unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
 
 // If we are restricted by the maximum column width, end the sequence.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79895: Fix warning about using uninitialized variable as function const reference parameter

2020-05-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

The summary of this change should be "add warning..." not "fix warning..."

Could you add more detail into the commit description? About newly introduced 
diagnostic groups, etc.

Also, I thought I saw tests in a previous revision but now they seem to be gone?


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

https://reviews.llvm.org/D79895



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


[PATCH] D80016: [analyzer] StdLibraryFunctionsChecker: Add support to lookup types

2020-05-15 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: xazax.hun, NoQ, Szelethus, balazske.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, whisperity.
Herald added a project: clang.

In this patch I am trying to get rid of the `Irrelevant` types from the
signatures of the functions from the standard C library. For that I've
introduced `lookupType()` to be able to lookup arbitrary types in the global
scope. This makes it possible to define the signatures precisely.

Note 1) `fread`'s signature is now fixed to have the proper `FILE *restrict`
type when C99 is the language.
Note 2) There are still existing `Irrelevant` types, but they are all from
POSIX. I am planning to address those together with the missing POSIX functions
(in D79433 ).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80016

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-lookup.c
  clang/test/Analysis/std-c-library-functions-lookup.cpp
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -53,10 +53,10 @@
 // CHECK-NEXT: Loaded summary for: int getc(FILE *)
 // CHECK-NEXT: Loaded summary for: int fgetc(FILE *)
 // CHECK-NEXT: Loaded summary for: int getchar()
+// CHECK-NEXT: Loaded summary for: unsigned int fread(void *restrict, size_t, size_t, FILE *restrict)
+// CHECK-NEXT: Loaded summary for: unsigned int fwrite(const void *restrict, size_t, size_t, FILE *restrict)
 // CHECK-NEXT: Loaded summary for: ssize_t read(int, void *, size_t)
 // CHECK-NEXT: Loaded summary for: ssize_t write(int, const void *, size_t)
-// CHECK-NEXT: Loaded summary for: unsigned int fread(void *restrict, size_t, size_t, FILE *)
-// CHECK-NEXT: Loaded summary for: unsigned int fwrite(const void *restrict, size_t, size_t, FILE *restrict)
 // CHECK-NEXT: Loaded summary for: ssize_t getline(char **, size_t *, FILE *)
 
 void clang_analyzer_eval(int);
@@ -104,7 +104,7 @@
   }
 }
 
-size_t fread(void *restrict, size_t, size_t, FILE *);
+size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 void test_fread_fwrite(FILE *fp, int *buf) {
 
Index: clang/test/Analysis/std-c-library-functions-lookup.cpp
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-lookup.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux 2>&1 | FileCheck %s
+
+//  CHECK: Loaded summary for: size_t fread(void *, size_t, size_t, FILE *)
+//  CHECK-NOT: Loaded summary for: size_t fread(void *, size_t, size_t, MyFile *)
+
+typedef unsigned int size_t;
+typedef struct FILE FILE;
+size_t fread(void *, size_t, size_t, FILE *);
+
+struct MyFile;
+size_t fread(void *, size_t, size_t, MyFile *);
+
+// Must have at least one call expression to initialize the summary map.
+int bar(void);
+void foo() {
+  bar();
+}
Index: clang/test/Analysis/std-c-library-functions-lookup.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-lookup.c
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux 2>&1 | FileCheck %s
+
+// CHECK: Loaded summary for: unsigned int fread(void *restrict, size_t, size_t, FILE *restrict)
+
+typedef typeof(sizeof(int)) size_t;
+typedef struct FILE FILE;
+size_t fread(void *restrict, size_t, size_t, FILE *restrict);
+
+// Must have at least one call expression to initialize the summary map.
+int bar(void);
+void foo() {
+  bar();
+}
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -64,7 +64,7 @@
 
 typedef struct FILE FILE;
 typedef typeof(sizeof(int)) size_t;
-size_t 

[PATCH] D80015: [Analyzer][StreamChecker] Added support for 'fread' and 'fwrite'.

2020-05-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

Stream functions `fread` and `fwrite` are evaluated
and preconditions checked.
A new bug type is added for a (non fatal) warning if `fread`
is called in EOF state.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80015

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-error.c

Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -7,6 +7,7 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
 void StreamTesterChecker_make_feof_stream(FILE *);
 void StreamTesterChecker_make_ferror_stream(FILE *);
 
@@ -57,6 +58,84 @@
   fclose(F);
 }
 
+void error_fread() {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  char Buf[10];
+  int Ret = fread(Buf, 1, 10, F);
+  if (Ret == 10) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{TRUE}}
+if (feof(F)) {
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  fread(Buf, 1, 10, F);   // expected-warning {{Read function called when stream is in EOF state}}
+  clang_analyzer_eval(feof(F));   // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+}
+if (ferror(F)) {
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  fread(Buf, 1, 10, F);   // no warning
+}
+  }
+  fclose(F);
+  Ret = fread(Buf, 1, 10, F); // expected-warning {{Stream might be already closed}}
+}
+
+void error_fwrite() {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  const char *Buf = "123456789";
+  int Ret = fwrite(Buf, 1, 10, F);
+  if (Ret == 10) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+fwrite(0, 1, 10, F);// no warning
+  }
+  fclose(F);
+  Ret = fwrite(0, 1, 10, F); // expected-warning {{Stream might be already closed}}
+}
+
+void freadwrite_zerosize(FILE *F) {
+  fwrite(0, 1, 0, F);
+  fwrite(0, 0, 1, F);
+  fread(0, 1, 0, F);
+  fread(0, 0, 1, F);
+}
+
+void freadwrite_zerosize_eofstate(FILE *F) {
+  fwrite(0, 1, 0, F);
+  fwrite(0, 0, 1, F);
+  fread(0, 1, 0, F); // expected-warning {{Read function called when stream is in EOF state}}
+  fread(0, 0, 1, F); // expected-warning {{Read function called when stream is in EOF state}}
+}
+
+void error_fread_fwrite_zerosize() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+
+  freadwrite_zerosize(F);
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+
+  StreamTesterChecker_make_ferror_stream(F);
+  freadwrite_zerosize(F);
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+
+  StreamTesterChecker_make_feof_stream(F);
+  freadwrite_zerosize_eofstate(F);
+  clang_analyzer_eval(feof(F));   // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+
+  fclose(F);
+}
+
 void error_fseek() {
   FILE *F = fopen("file", "r");
   if (!F)
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -52,6 +52,10 @@
 return NoError == ES.NoError && FEof == ES.FEof && FError == ES.FError;
   }
 
+  bool operator!=(const StreamErrorState ) const {
+return NoError != ES.NoError || FEof != ES.FEof || FError != ES.FError;
+  }
+
   StreamErrorState operator|(const StreamErrorState ) const {
 return {NoError || E.NoError, FEof || E.FEof, FError || E.FError};
   }
@@ -172,7 +176,7 @@
 class StreamChecker
 : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak, BT_StreamEof;
 
 public:
   void checkPreCall(const CallEvent , CheckerContext ) const;
@@ -190,8 +194,12 @@
   {{"tmpfile"}, {nullptr, ::evalFopen, ArgNone}},
   {{"fclose", 1},
{::preDefault, ::evalFclose, 0}},
-  {{"fread", 4}, {::preDefault, nullptr, 3}},
-  {{"fwrite", 4}, {::preDefault, nullptr, 3}},
+  {{"fread", 4},
+   {::preFread,
+

  1   2   >