[PATCH] D77229: [Analyzer] Avoid handling of LazyCompundVals in IteratorModeling

2020-09-22 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp:330-336
+SVal getReturnIterator(const CallEvent &Call) {
+  Optional RetValUnderConstr = Call.getReturnValueUnderConstruction();
+  if (RetValUnderConstr.hasValue())
+return *RetValUnderConstr;
+
+  return Call.getReturnValue();
+}

baloghadamsoftware wrote:
> NoQ wrote:
> > baloghadamsoftware wrote:
> > > NoQ wrote:
> > > > NoQ wrote:
> > > > > NoQ wrote:
> > > > > > I still believe you have not addressed the problem while moving the 
> > > > > > functions from D81718 to this patch. The caller of this function 
> > > > > > has no way of knowing whether the return value is the prvalue of 
> > > > > > the iterator or the glvalue of the iterator.
> > > > > > 
> > > > > > Looks like most callers are safe because they expect the object of 
> > > > > > interest to also be already tracked. But it's quite possible that 
> > > > > > both are tracked, say:
> > > > > > 
> > > > > > ```lang=c++
> > > > > >   Container1 container1 = ...;
> > > > > >   Container2 container2 = { 
> > > > > > container1.begin() };
> > > > > >   container2.begin(); // ???
> > > > > > ```
> > > > > > 
> > > > > > Suppose `Container1::iterator` is implemented as an object and 
> > > > > > `Container2::iterator` is implemented as a pointer. In this case 
> > > > > > `getIteratorPosition(getReturnIterator())` would yield the position 
> > > > > > of `container1.begin()` whereas the correct answer is the position 
> > > > > > of `container2.begin()`.
> > > > > > 
> > > > > > This problem may seem artificial but it is trivial to avoid if you 
> > > > > > simply stop defending your convoluted solution of looking at value 
> > > > > > classes instead of AST types.
> > > > > Ugh, the problem is much worse. D82185 is entirely broken for the 
> > > > > exact reason i described above and you only didn't notice it because 
> > > > > you wrote almost no tests.
> > > > > 
> > > > > Consider the test you've added in D82185:
> > > > > 
> > > > > ```lang=c++
> > > > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > > > >   auto i = c.begin();
> > > > > 
> > > > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > > > expected-warning{{TRUE}}
> > > > > }
> > > > > ```
> > > > > 
> > > > > It breaks very easily if you modify it slightly:
> > > > > ```lang=c++
> > > > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > > > >   auto i = c.begin();
> > > > >   ++i; // <==
> > > > > 
> > > > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > > > Says FALSE!
> > > > > }
> > > > > ```
> > > > > The iterator obviously still points to the same container, so why 
> > > > > does the test fail? Because you're tracking the wrong iterator: you 
> > > > > treated your `&SymRegion{conj_$3}` as a glvalue whereas you should 
> > > > > have treated it as a prvalue. In other words, your checker thinks 
> > > > > that `&SymRegion{conj_$3}` is the location of an iterator object 
> > > > > rather than the iterator itself, and after you increment the pointer 
> > > > > it thinks that it's a completely unrelated iterator.
> > > > > 
> > > > > There's a separate concern about why does it say `FALSE` (should be 
> > > > > `UNKNOWN`) but you get the point.
> > > > The better way to test D82185 would be to make all existing tests with 
> > > > iterator objects pass with iterator pointers as well. Like, make 
> > > > existing container mocks use either iterator objects or iterator 
> > > > pointers depending on a macro and make two run-lines in each test file, 
> > > > one with `-D` and one without it. Most of the old tests should have 
> > > > worked out of the box if you did it right; the few that don't pass 
> > > > would be hidden under #ifdef for future investigation.
> > > Thank you for your review and especially for this tip! It is really a 
> > > good idea. I changed it now and it indeed shows the problem you reported. 
> > > It seems that my checker mixes up the region of the pointer-typed 
> > > variable (`&i` and `&j`) with the region they point to 
> > > (`&SymRegion{reg_$1 & 
> > > v>}._start>}` for `i` before the increment and 
> > > `&Element{SymRegion{reg_$1 
> > > & v>}._start>},1 S64b,int}` for both `i` and `j` after the increment).
> > > 
> > > What I fail to see and I am asking you help in it is that the relation 
> > > between this problem and the `getReturnIterator()` function. This 
> > > function retrieves the object from the construction context if there is 
> > > one, but for plain pointers there is never one. Thus this function is 
> > > always `Call.getReturnValue()` like before this patch.
> > > I am asking you help
> > 
> > I spent way more time on that already than i find reasonable. Please figure 
> > this out on your own by fixing the bug.
> I do not see why I got so a rude answer. I was just asking help in //seeing 
> the relation betw

[PATCH] D77229: [Analyzer] Avoid handling of LazyCompundVals in IteratorModeling

2020-09-22 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp:330-336
+SVal getReturnIterator(const CallEvent &Call) {
+  Optional RetValUnderConstr = Call.getReturnValueUnderConstruction();
+  if (RetValUnderConstr.hasValue())
+return *RetValUnderConstr;
+
+  return Call.getReturnValue();
+}

NoQ wrote:
> baloghadamsoftware wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > NoQ wrote:
> > > > > I still believe you have not addressed the problem while moving the 
> > > > > functions from D81718 to this patch. The caller of this function has 
> > > > > no way of knowing whether the return value is the prvalue of the 
> > > > > iterator or the glvalue of the iterator.
> > > > > 
> > > > > Looks like most callers are safe because they expect the object of 
> > > > > interest to also be already tracked. But it's quite possible that 
> > > > > both are tracked, say:
> > > > > 
> > > > > ```lang=c++
> > > > >   Container1 container1 = ...;
> > > > >   Container2 container2 = { container1.begin() 
> > > > > };
> > > > >   container2.begin(); // ???
> > > > > ```
> > > > > 
> > > > > Suppose `Container1::iterator` is implemented as an object and 
> > > > > `Container2::iterator` is implemented as a pointer. In this case 
> > > > > `getIteratorPosition(getReturnIterator())` would yield the position 
> > > > > of `container1.begin()` whereas the correct answer is the position of 
> > > > > `container2.begin()`.
> > > > > 
> > > > > This problem may seem artificial but it is trivial to avoid if you 
> > > > > simply stop defending your convoluted solution of looking at value 
> > > > > classes instead of AST types.
> > > > Ugh, the problem is much worse. D82185 is entirely broken for the exact 
> > > > reason i described above and you only didn't notice it because you 
> > > > wrote almost no tests.
> > > > 
> > > > Consider the test you've added in D82185:
> > > > 
> > > > ```lang=c++
> > > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > > >   auto i = c.begin();
> > > > 
> > > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > > expected-warning{{TRUE}}
> > > > }
> > > > ```
> > > > 
> > > > It breaks very easily if you modify it slightly:
> > > > ```lang=c++
> > > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > > >   auto i = c.begin();
> > > >   ++i; // <==
> > > > 
> > > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > > Says FALSE!
> > > > }
> > > > ```
> > > > The iterator obviously still points to the same container, so why does 
> > > > the test fail? Because you're tracking the wrong iterator: you treated 
> > > > your `&SymRegion{conj_$3}` as a glvalue whereas you should have treated 
> > > > it as a prvalue. In other words, your checker thinks that 
> > > > `&SymRegion{conj_$3}` is the location of an iterator object rather than 
> > > > the iterator itself, and after you increment the pointer it thinks that 
> > > > it's a completely unrelated iterator.
> > > > 
> > > > There's a separate concern about why does it say `FALSE` (should be 
> > > > `UNKNOWN`) but you get the point.
> > > The better way to test D82185 would be to make all existing tests with 
> > > iterator objects pass with iterator pointers as well. Like, make existing 
> > > container mocks use either iterator objects or iterator pointers 
> > > depending on a macro and make two run-lines in each test file, one with 
> > > `-D` and one without it. Most of the old tests should have worked out of 
> > > the box if you did it right; the few that don't pass would be hidden 
> > > under #ifdef for future investigation.
> > Thank you for your review and especially for this tip! It is really a good 
> > idea. I changed it now and it indeed shows the problem you reported. It 
> > seems that my checker mixes up the region of the pointer-typed variable 
> > (`&i` and `&j`) with the region they point to (`&SymRegion{reg_$1 > SymRegion{reg_$0 & v>}._start>}` for `i` before the 
> > increment and `&Element{SymRegion{reg_$1 > std::vector & v>}._start>},1 S64b,int}` for both `i` and `j` after the 
> > increment).
> > 
> > What I fail to see and I am asking you help in it is that the relation 
> > between this problem and the `getReturnIterator()` function. This function 
> > retrieves the object from the construction context if there is one, but for 
> > plain pointers there is never one. Thus this function is always 
> > `Call.getReturnValue()` like before this patch.
> > I am asking you help
> 
> I spent way more time on that already than i find reasonable. Please figure 
> this out on your own by fixing the bug.
I do not see why I got so a rude answer. I was just asking help in //seeing the 
relation between the bug and this function//. Because I do not see any. I think 
the bug is somewhere in handling unary and binary operators for pointers. I 
struggled with that part for this same rea

[clang] d7eb917 - [PowerPC] Implementation of 128-bit Binary Vector Mod and Sign Extend builtins

2020-09-22 Thread Albion Fung via cfe-commits

Author: Albion Fung
Date: 2020-09-23T01:18:14-05:00
New Revision: d7eb917a7cb793f49e16841fc24826b988dd5c8f

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

LOG: [PowerPC] Implementation of 128-bit Binary Vector Mod and Sign Extend 
builtins

This patch implements 128-bit Binary Vector Mod and Sign Extend builtins for 
PowerPC10.

Differential: https://reviews.llvm.org/D87394#inline-815858

Added: 
llvm/test/CodeGen/PowerPC/p10-vector-sign-extend.ll
llvm/test/CodeGen/PowerPC/p9-vector-sign-extend.ll

Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-p10vector.c
clang/test/CodeGen/builtins-ppc-p9vector.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/PowerPC/PPCInstrAltivec.td
llvm/lib/Target/PowerPC/PPCInstrPrefix.td
llvm/test/CodeGen/PowerPC/p10-vector-modulo.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index b571454cfc7a..5de3584a2755 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -303,6 +303,16 @@ BUILTIN(__builtin_altivec_vrldmi, 
"V2ULLiV2ULLiV2ULLiV2ULLi", "")
 BUILTIN(__builtin_altivec_vrlwnm, "V4UiV4UiV4Ui", "")
 BUILTIN(__builtin_altivec_vrldnm, "V2ULLiV2ULLiV2ULLi", "")
 
+// P9 Vector extend sign builtins.
+BUILTIN(__builtin_altivec_vextsb2w, "V4SiV16Sc", "")
+BUILTIN(__builtin_altivec_vextsb2d, "V2SLLiV16Sc", "")
+BUILTIN(__builtin_altivec_vextsh2w, "V4SiV8Ss", "")
+BUILTIN(__builtin_altivec_vextsh2d, "V2SLLiV8Ss", "")
+BUILTIN(__builtin_altivec_vextsw2d, "V2SLLiV4Si", "")
+
+// P10 Vector extend sign builtins.
+BUILTIN(__builtin_altivec_vextsd2q, "V1SLLLiV2SLLi", "")
+
 // P10 Vector Extract with Mask built-ins.
 BUILTIN(__builtin_altivec_vextractbm, "UiV16Uc", "")
 BUILTIN(__builtin_altivec_vextracthm, "UiV8Us", "")

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 2c09e477bd3c..b07e45d3c5a5 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -3007,6 +3007,42 @@ static __inline__ vector double __ATTRS_o_ai 
vec_cpsgn(vector double __a,
 
 #define vec_vctuxs __builtin_altivec_vctuxs
 
+/* vec_signext */
+
+#ifdef __POWER9_VECTOR__
+static __inline__ vector signed int __ATTRS_o_ai
+vec_signexti(vector signed char __a) {
+  return __builtin_altivec_vextsb2w(__a);
+}
+
+static __inline__ vector signed int __ATTRS_o_ai
+vec_signexti(vector signed short __a) {
+  return __builtin_altivec_vextsh2w(__a);
+}
+
+static __inline__ vector signed long long __ATTRS_o_ai
+vec_signextll(vector signed char __a) {
+  return __builtin_altivec_vextsb2d(__a);
+}
+
+static __inline__ vector signed long long __ATTRS_o_ai
+vec_signextll(vector signed short __a) {
+  return __builtin_altivec_vextsh2d(__a);
+}
+
+static __inline__ vector signed long long __ATTRS_o_ai
+vec_signextll(vector signed int __a) {
+  return __builtin_altivec_vextsw2d(__a);
+}
+#endif
+
+#ifdef __POWER10_VECTOR__
+static __inline__ vector signed __int128 __ATTRS_o_ai
+vec_signextq(vector signed long long __a) {
+  return __builtin_altivec_vextsd2q(__a);
+}
+#endif
+
 /* vec_signed */
 
 static __inline__ vector signed int __ATTRS_o_ai
@@ -17269,6 +17305,16 @@ vec_mod(vector unsigned long long __a, vector unsigned 
long long __b) {
   return __a % __b;
 }
 
+static __inline__ vector signed __int128 __ATTRS_o_ai
+vec_mod(vector signed __int128 __a, vector signed __int128 __b) {
+  return __a % __b;
+}
+
+static __inline__ vector unsigned __int128 __ATTRS_o_ai
+vec_mod(vector unsigned __int128 __a, vector unsigned __int128 __b) {
+  return  __a % __b;
+}
+
 /* vec_sldbi */
 
 #define vec_sldb(__a, __b, __c) __builtin_altivec_vsldbi(__a, __b, (__c & 0x7))

diff  --git a/clang/test/CodeGen/builtins-ppc-p10vector.c 
b/clang/test/CodeGen/builtins-ppc-p10vector.c
index 89f49adf28e9..b6788d783a5d 100644
--- a/clang/test/CodeGen/builtins-ppc-p10vector.c
+++ b/clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -1481,3 +1481,21 @@ vector unsigned __int128 test_vec_xl_zext_i64(void) {
   // CHECK: ret <1 x i128>
   return vec_xl_zext(llb, ullap);
 }
+
+vector signed __int128 test_vec_signextq_s128(void) {
+// CHECK: @llvm.ppc.altivec.vextsd2q(<2 x i64>
+// CHECK-NEXT: ret <1 x i128>
+return vec_signextq(vslla);
+}
+
+vector unsigned __int128 test_vec_mod_u128(void) {
+// CHECK: urem <1 x i128>
+// CHECK-NEXT: ret <1 x i128>
+return vec_mod(vui128a, vui128b);
+}
+
+vector signed __int128 test_vec_mod_s128(void) {
+// CHECK: srem <1 x i128>
+// CHECK-NEXT: ret <1 x i128>
+return vec_mod(vsi128a, vsi128b);
+}

diff  --git a/clang/test/CodeGen/builtins-ppc-p9vector

[PATCH] D88100: [analyzer][StdLibraryFunctionsChecker] Separate the signature from the summaries

2020-09-22 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Yup, we've talked about this before. This is indeed a better interface design. 
LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88100

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


[PATCH] D88092: [analyzer][StdLibraryFunctionsChecker] Fix getline/getdelim signatures

2020-09-22 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

A joy of reviewing C++ code is that you get to marvel in all the great things 
the language has, without having to pull fistfuls of hair out to get get to 
that point. These patches are always a treat. LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88092

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


[PATCH] D88133: [Analyzer][WebKit] Use tri-state types for relevant predicates

2020-09-22 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

Created this for eventual post-commit review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88133

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


[PATCH] D88133: [Analyzer][WebKit] Use tri-state types for relevant predicates

2020-09-22 Thread Jan Korous via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG47e6851423fd: [Analyzer][WebKit] Use tri-state types for 
relevant predicates (authored by jkorous).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88133

Files:
  clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
  clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -169,7 +169,8 @@
 if (!ArgType)
   return;
 
-if (isUncountedPtr(ArgType)) {
+Optional IsUncountedPtr = isUncountedPtr(ArgType);
+if (IsUncountedPtr && *IsUncountedPtr) {
   const Expr *const InitExpr = V->getInit();
   if (!InitExpr)
 return; // FIXME: later on we might warn on uninitialized vars too
Index: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -59,7 +59,8 @@
   if (C.capturesVariable()) {
 VarDecl *CapturedVar = C.getCapturedVar();
 if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) {
-  if (isUncountedPtr(CapturedVarType)) {
+  Optional IsUncountedPtr = isUncountedPtr(CapturedVarType);
+  if (IsUncountedPtr && *IsUncountedPtr) {
 reportBug(C, CapturedVar, CapturedVarType);
   }
 }
Index: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -86,7 +86,8 @@
   continue; // FIXME? Should we bail?
 
 // FIXME: more complex types (arrays, references to raw pointers, etc)
-if (!isUncountedPtr(ArgType))
+Optional IsUncounted = isUncountedPtr(ArgType);
+if (!IsUncounted || !(*IsUncounted))
   continue;
 
 const auto *Arg = CE->getArg(ArgIdx);
Index: clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -76,19 +76,15 @@
   (AccSpec == AS_none && RD->isClass()))
 return false;
 
-  llvm::Optional MaybeRefCntblBaseRD =
+  llvm::Optional RefCntblBaseRD =
   isRefCountable(Base);
-  if (!MaybeRefCntblBaseRD.hasValue())
+  if (!RefCntblBaseRD || !(*RefCntblBaseRD))
 return false;
 
-  const CXXRecordDecl *RefCntblBaseRD = MaybeRefCntblBaseRD.getValue();
-  if (!RefCntblBaseRD)
-return false;
-
-  const auto *Dtor = RefCntblBaseRD->getDestructor();
+  const auto *Dtor = (*RefCntblBaseRD)->getDestructor();
   if (!Dtor || !Dtor->isVirtual()) {
 ProblematicBaseSpecifier = Base;
-ProblematicBaseClass = RefCntblBaseRD;
+ProblematicBaseClass = *RefCntblBaseRD;
 return true;
   }
 
Index: clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
 #define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
 
+#include "llvm/ADT/APInt.h"
+
 namespace clang {
 class CXXBaseSpecifier;
 class CXXMethodDecl;
@@ -25,30 +27,31 @@
 // Ref.
 
 /// \returns CXXRecordDecl of the base if the type is ref-countable, nullptr if
-/// not.
-const clang::CXXRecordDecl *isRefCountable(const clang::CXXBaseSpecifier *Base);
+/// not, None if inconclusi

[clang] 47e6851 - [Analyzer][WebKit] Use tri-state types for relevant predicates

2020-09-22 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2020-09-22T21:57:24-07:00
New Revision: 47e6851423fd32f0685a643236ad946e23ab14ff

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

LOG: [Analyzer][WebKit] Use tri-state types for relevant predicates

Some of the predicates can't always be decided - for example when a type
definition isn't available. At the same time it's necessary to let
client code decide what to do about such cases - specifically we can't
just use true or false values as there are callees with
conflicting strategies how to handle this.

This is a speculative fix for PR47276.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 34c072ac2241..9c7a59971763 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -34,7 +34,9 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
 }
 if (auto *call = dyn_cast(E)) {
   if (auto *memberCall = dyn_cast(call)) {
-if (isGetterOfRefCounted(memberCall->getMethodDecl())) {
+Optional IsGetterOfRefCt =
+isGetterOfRefCounted(memberCall->getMethodDecl());
+if (IsGetterOfRefCt && *IsGetterOfRefCt) {
   E = memberCall->getImplicitObjectArgument();
   if (StopAtFirstRefCountedObj) {
 return {E, true};

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
index 3956db933b35..97f75135bf92 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
@@ -76,8 +76,11 @@ class NoUncountedMemberChecker
 
   if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl()) {
 // If we don't see the definition we just don't know.
-if (MemberCXXRD->hasDefinition() && isRefCountable(MemberCXXRD))
-  reportBug(Member, MemberType, MemberCXXRD, RD);
+if (MemberCXXRD->hasDefinition()) {
+  llvm::Optional isRCAble = isRefCountable(MemberCXXRD);
+  if (isRCAble && *isRCAble)
+reportBug(Member, MemberType, MemberCXXRD, RD);
+}
   }
 }
   }

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 168cfd511170..a198943c9433 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprCXX.h"
+#include "llvm/ADT/Optional.h"
 
 using llvm::Optional;
 using namespace clang;
@@ -20,6 +21,7 @@ namespace {
 
 bool hasPublicRefAndDeref(const CXXRecordDecl *R) {
   assert(R);
+  assert(R->hasDefinition());
 
   bool hasRef = false;
   bool hasDeref = false;
@@ -43,25 +45,29 @@ bool hasPublicRefAndDeref(const CXXRecordDecl *R) {
 
 namespace clang {
 
-const CXXRecordDecl *isRefCountable(const CXXBaseSpecifier *Base) {
+llvm::Optional
+isRefCountable(const CXXBaseSpecifier *Base) {
   assert(Base);
 
   const Type *T = Base->getType().getTypePtrOrNull();
   if (!T)
-return nullptr;
+return llvm::None;
 
   const CXXRecordDecl *R = T->getAsCXXRecordDecl();
   if (!R)
-return nullptr;
+return llvm::None;
+  if (!R->hasDefinition())
+return llvm::None;
 
   return hasPublicRefAndDeref(R) ? R : nullptr;
 }
 
-bool isRefCountable(const CXXRecordDecl *R) {
+llvm::Optional isRefCountable(const CXXRecordDecl *R) {
   assert(R);
 
   R = R->getDefinition();
-  assert(R);
+  if (!R)
+return llvm::None;
 
   if (hasPublicRefAndDeref(R))
 return true;
@@ -69,13 +75,24 @@ bool isRefCountable(const CXXRecordDecl *R) {
   CXXBasePaths Paths;
   Paths.setOrigin(const_cast(R));
 
-  const auto isRefCountableBase = [](const CXXBaseSpecifier *Base,
- CXXBasePath &) {
-return clang::isRefCounta

[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

It turns out that the culprit for the PPC bot failures is actually 
https://reviews.llvm.org/rG144e57fc9535
But this just took a while to manifest.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

When you recommit, consider adding the header to the description. The original 
message started with "The wrong placement of add pass with optimizations led to 
-funique-internal-linkage-names being disabled." The header was missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D87921#2288686 , @morehouse wrote:

> The revert did not fix the PPC bots.  I suspect there is some kind of 
> resource issue from the logs:
>
>   msgget:: No space left on device
>   sysmsg.c.tmp: 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:15:
>  int main(): Assertion `msgq != -1' failed.
>
> http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt
> http://lab.llvm.org:8011/builders/sanitizer-ppc64be-linux

I am sorry, please feel free to recommit this. I just looked at the machine. 
Somehow we ended up with 32004 System V message queues created by the buildbots 
on the machine. Something didn't clean up properly. This patch has nothing to 
do with it, it just happened to hit the limit when this patch landed. Really 
sorry for the noise here. I'll see if I can get the machine fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D87953: [xray] Function coverage groups

2020-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1136
+  if (Opts.XRayTotalFunctionGroups < 1) {
+const Arg *A = Args.getLastArg(OPT_fxray_function_groups);
+Diags.Report(diag::err_drv_invalid_value)

Errors here are not necessary. The driver has reported errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87953

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


[PATCH] D88130: [PPC] [AIX] Implement calling convention IR for C99 complex types on AIX

2020-09-22 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm created this revision.
cebowleratibm added reviewers: ZarkoCA, daltenty, sfertile.
Herald added subscribers: cfe-commits, nemanjai.
Herald added a project: clang.
cebowleratibm requested review of this revision.

Builds on D88105  to add AIX calling 
convention logic to Clang for C99 complex types on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88130

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-complex.c
  clang/test/CodeGen/powerpc-c99complex.c


Index: clang/test/CodeGen/powerpc-c99complex.c
===
--- clang/test/CodeGen/powerpc-c99complex.c
+++ clang/test/CodeGen/powerpc-c99complex.c
@@ -1,11 +1,13 @@
-// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
-// RUN: %clang_cc1 -triple ppc64le-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-NOLDBL128
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm %s -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-NOLDBL128
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-LDBL128
+// RUN: %clang_cc1 -triple ppc64le-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-LDBL128
 // RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefix=PPC32LNX
 
 _Complex float foo1(_Complex float x) {
   return x;
-// PPC64LNX-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float 
%x.{{.*}}) #0 {
-// PPC64LNX: ret { float, float }
+// CHECK-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float 
%x.{{.*}}) #0 {
+// CHECK: ret { float, float }
 
 // PPC32LNX-LABEL:  define void @foo1({ float, float }* noalias sret align 4 
%agg.result, { float, float }* byval({ float, float }) align 4 %x) #0 {
 // PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { float, float }, 
{ float, float }* %agg.result, i32 0, i32 0
@@ -16,8 +18,8 @@
 
 _Complex double foo2(_Complex double x) {
   return x;
-// PPC64LNX-LABEL:   define { double, double } @foo2(double %x.{{.*}}, 
double %x.{{.*}}) #0 {
-// PPC64LNX: ret { double, double }
+// CHECK-LABEL:   define { double, double } @foo2(double %x.{{.*}}, double 
%x.{{.*}}) #0 {
+// CHECK: ret { double, double }
 
 // PPC32LNX-LABEL:  define void @foo2({ double, double }* noalias sret align 8 
%agg.result, { double, double }* byval({ double, double }) align 8 %x) #0 {
 // PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { double, double 
}, { double, double }* %agg.result, i32 0, i32 0
@@ -28,8 +30,11 @@
 
 _Complex long double foo3(_Complex long double x) {
   return x;
-// PPC64LNX-LDBL128-LABEL:define { ppc_fp128, ppc_fp128 } @foo3(ppc_fp128 
%x.{{.*}}, ppc_fp128 %x.{{.*}}) #0 {
-// PPC64LNX-LDBL128:  ret { ppc_fp128, ppc_fp128 }
+// CHECK-NOLDBL128-LABEL:  define { double, double } @foo3(double %x.{{.*}}, 
double %x.{{.*}}) #0 {
+// CHECK-NOLDBL128:ret { double, double }
+
+// CHECK-LDBL128-LABEL:define { ppc_fp128, ppc_fp128 } @foo3(ppc_fp128 
%x.{{.*}}, ppc_fp128 %x.{{.*}}) #0 {
+// CHECK-LDBL128:  ret { ppc_fp128, ppc_fp128 }
 
 // PPC32LNX-LABEL: define void @foo3({ ppc_fp128, ppc_fp128 }* noalias sret 
align 16 %agg.result, { ppc_fp128, ppc_fp128 }* byval({ ppc_fp128, ppc_fp128 }) 
align 16 %x) #0 {
 // PPC32LNX:   [[RETREAL:%.*]] = getelementptr inbounds { ppc_fp128, 
ppc_fp128 }, { ppc_fp128, ppc_fp128 }* %agg.result, i32 0, i32 0
Index: clang/test/CodeGen/aix-complex.c
===
--- clang/test/CodeGen/aix-complex.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// REQUIRES: powerpc-registered-target
-// RUN: not %clang_cc1 -triple powerpc-unknown-aix \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-// RUN: not %clang_cc1 -triple powerpc64-unknown-aix \
-// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
-
-// CHECK: fatal error: error in backend: complex type is not supported on AIX 
yet
-_Complex float foo_float(_Complex float x) {
-  return x;
-}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4504,7 +4504,7 @@
 
 ABIArgInfo AIXABIInfo::classifyReturnType(QualType RetTy) const {
   if (RetTy->isAnyComplexType())
-llvm::report_fatal_error("complex type is not supported on AIX yet");
+return ABIArgInfo::getDirect();
 
   if (RetTy->isVectorType())
 llvm::report_fatal_error("vector type is not supported on AIX yet");
@@ -4525,7 +4525,7 @@
   Ty = useFirstFieldIfTransparentUnion(Ty);
 
   if (Ty->isAnyComplexType())
-llvm::report_fatal_er

[PATCH] D88105: [NFC] [PPC] Add PowerPC expected IR tests for C99 complex

2020-09-22 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm updated this revision to Diff 293625.
cebowleratibm marked an inline comment as done.
cebowleratibm added a comment.

Added ppc64le target.


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

https://reviews.llvm.org/D88105

Files:
  clang/test/CodeGen/powerpc-c99complex.c


Index: clang/test/CodeGen/powerpc-c99complex.c
===
--- /dev/null
+++ clang/test/CodeGen/powerpc-c99complex.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple ppc64le-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefix=PPC32LNX
+
+_Complex float foo1(_Complex float x) {
+  return x;
+// PPC64LNX-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float 
%x.{{.*}}) #0 {
+// PPC64LNX: ret { float, float }
+
+// PPC32LNX-LABEL:  define void @foo1({ float, float }* noalias sret align 4 
%agg.result, { float, float }* byval({ float, float }) align 4 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { float, float }, 
{ float, float }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { float, float }, 
{ float, float }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETREAL]], align 4
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETIMAG]], align 4
+}
+
+_Complex double foo2(_Complex double x) {
+  return x;
+// PPC64LNX-LABEL:   define { double, double } @foo2(double %x.{{.*}}, 
double %x.{{.*}}) #0 {
+// PPC64LNX: ret { double, double }
+
+// PPC32LNX-LABEL:  define void @foo2({ double, double }* noalias sret align 8 
%agg.result, { double, double }* byval({ double, double }) align 8 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { double, double 
}, { double, double }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { double, double 
}, { double, double }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store double %{{.*}}, double* [[RETREAL]], align 8
+// PPC32LNX-NEXT:   store double %{{.*}}, double* [[RETIMAG]], align 8
+}
+
+_Complex long double foo3(_Complex long double x) {
+  return x;
+// PPC64LNX-LDBL128-LABEL:define { ppc_fp128, ppc_fp128 } @foo3(ppc_fp128 
%x.{{.*}}, ppc_fp128 %x.{{.*}}) #0 {
+// PPC64LNX-LDBL128:  ret { ppc_fp128, ppc_fp128 }
+
+// PPC32LNX-LABEL: define void @foo3({ ppc_fp128, ppc_fp128 }* noalias sret 
align 16 %agg.result, { ppc_fp128, ppc_fp128 }* byval({ ppc_fp128, ppc_fp128 }) 
align 16 %x) #0 {
+// PPC32LNX:   [[RETREAL:%.*]] = getelementptr inbounds { ppc_fp128, 
ppc_fp128 }, { ppc_fp128, ppc_fp128 }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:  [[RETIMAG:%.*]] = getelementptr inbounds { ppc_fp128, 
ppc_fp128 }, { ppc_fp128, ppc_fp128 }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:  store ppc_fp128 %{{.*}}, ppc_fp128* [[RETREAL]], align 16
+// PPC32LNX-NEXT:  store ppc_fp128 %{{.*}}, ppc_fp128* [[RETIMAG]], align 16
+}


Index: clang/test/CodeGen/powerpc-c99complex.c
===
--- /dev/null
+++ clang/test/CodeGen/powerpc-c99complex.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple ppc64le-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=PPC32LNX
+
+_Complex float foo1(_Complex float x) {
+  return x;
+// PPC64LNX-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float %x.{{.*}}) #0 {
+// PPC64LNX: ret { float, float }
+
+// PPC32LNX-LABEL:  define void @foo1({ float, float }* noalias sret align 4 %agg.result, { float, float }* byval({ float, float }) align 4 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { float, float }, { float, float }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { float, float }, { float, float }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETREAL]], align 4
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETIMAG]], align 4
+}
+
+_Complex double foo2(_Complex double x) {
+  return x;
+// PPC64LNX-LABEL:   define { double, double } @foo2(double %x.{{.*}}, double %x.{{.*}}) #0 {
+// PPC64LNX: ret { double, double }
+
+// PPC32LNX-LABEL:  define void @foo2({ double, double }* noalias sret align 8 %agg.result, { double, double }* byval({ double, double }) align 8 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { double, double }, { double, double }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]]

[PATCH] D88003: Fix typos in ASTMatchers.h

2020-09-22 Thread YangZhihui via Phabricator via cfe-commits
YangZhihui added a comment.

In D88003#2287580 , @aaron.ballman 
wrote:

> LGTM!

I don't have commit access
maybe you can help me commit it 
Thanks : )


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

https://reviews.llvm.org/D88003

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


[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2292-2300
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }

akhuang wrote:
> rsmith wrote:
> > dblaikie wrote:
> > > rsmith wrote:
> > > > This looks pretty similar to:
> > > > 
> > > > ```
> > > > return RD->hasUserDeclaredConstructor() && 
> > > > !RD->hasTrivialDefaultConstructor();
> > > > ```
> > > > 
> > > > (other than its treatment of user-declared copy or move constructors), 
> > > > but I have to admit I don't really understand what the "at least one 
> > > > constructor and no trivial or constexpr constructors" rule aims to 
> > > > achieve, so it's hard to know if this is the right interpretation. The 
> > > > rule as written in the comment above is presumably not exactly right -- 
> > > > all classes have at least one constructor, and we're not excluding 
> > > > classes with trivial copy or move constructors, only those with trivial 
> > > > default constructors.
> > > > 
> > > > I wonder if the intent would be better captured by "at least one 
> > > > non-inline constructor" (that is, assuming all declared functions are 
> > > > defined, there is at least one translation unit in which a constructor 
> > > > is defined that can be used as a home for the class info).
> > > So the general goal is to detect any type where the construction of that 
> > > type somewhere must invoke a constructor that will be IR-generated.
> > > 
> > > Move and copy constructors are ignored because the assumption is they 
> > > must be moving/copying from some other object, which must've been 
> > > constructed, ultimately, by a non-move/copy constructor.
> > > 
> > > Ideally this would be usable even for inline ctors - even if the ctor 
> > > calls get optimized away later[^1], they'd still allow us to reduce the 
> > > number of places the type is emitted to only those places that call the 
> > > ctor.
> > > 
> > > 
> > > 
> > > [^1] actually, the way that should work doesn't seem to be working right 
> > > now (eg:
> > > type.cpp
> > > ```
> > > struct t1 { t1() { } };
> > > void f1(void*);
> > > int main() {
> > >   f1(new t1());
> > > }
> > > ```
> > > type2.cpp
> > > ```
> > > struct t1 { t1() { } };
> > > void f1(void* v) {
> > >   delete (t1*)v;
> > > }
> > > ```
> > > build: `clang++ type.cpp -g -Xclang -fuse-ctor-homing type2.cpp && 
> > > llvm-dwarfdump a.out`
> > > -> definition of "t1" in the DWARF
> > > build with optimizations: `clang++ -O3 type.cpp -g -Xclang 
> > > -fuse-ctor-homing type2.cpp && llvm-dwarfdump a.out`
> > > -> missing definition of "t1"
> > > `type.cpp` is chosen as a home for `t1` because it calls a user-defined 
> > > ctor, but then that ctor gets optimized away and there's no other mention 
> > > of `t1` in `type.cpp` so the type is dropped entirely. This could happen 
> > > even with a non-inline definition - under LTO the ctor could get 
> > > optimized away (though this would be safe in FullLTO - the other 
> > > references to `t1` would be made to refer to the definition and keep it 
> > > alive - but in ThinLTO the TU defining the ctor might be imported and 
> > > nothing else - leaving the type unused/dropped)
> > > To fix this we should put 'homed' types in the retained types list so 
> > > they are preserved even if all other code/references to the type are 
> > > dropped. I think I implemented this homed type pinning for explicit 
> > > template specialization definitions, because they have no code attachment 
> > > point, so similar logic could be used for ctor homing. (vtable homing 
> > > /might/ benefit from this with aggressive/whole program devirtualization? 
> > > Not sure - harder to actually optimize away all the references to a type, 
> > > but possible maybe?)
> > Oh, I see, that's clever and very neat.
> > 
> > So the intent is to identify types for which we know that either no 
> > instances are ever created, or some constructor must be actually emitted in 
> > some translation unit (prior to optimizations running). And that's why we 
> > want to ignore copy and move constructors [and could in fact ignore any 
> > constructor taking the class type by value or reference, directly or 
> > indirectly] (they cannot be the only place that creates an object) and also 
> > why we don't want to do this if there's a constexpr constructor or trivial 
> > default constructor (we might not generate code for them). And the "no 
> > constructors" check seems to effectively be checking whether aggregate 
> > initialization could be performed.
> > 
> > I think we can replace the loop with `return !RD->isAggregate() && 
> > !RD->hasTrivialDefaultConstructor();`.
> > 
> > (Minor aside, it is possible to create an instance of a type if its only 
> > constructor is a copy constructor, eg with `st

[PATCH] D87974: [Builtin] Add __builtin_zero_non_value_bits.

2020-09-22 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver updated this revision to Diff 293606.
zoecarver edited the summary of this revision.
zoecarver added a comment.

- Add more test cases.
- Fix typo.
- Add codegen tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87974

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/builtin-zero-non-value-bits-codegen.cpp
  clang/test/CodeGenCXX/builtin-zero-non-value-bits.cpp
  clang/test/SemaCXX/builtin-zero-non-value-bits.cpp

Index: clang/test/SemaCXX/builtin-zero-non-value-bits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-zero-non-value-bits.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct Foo { };
+
+struct Incomplete; // expected-note {{forward declaration of 'Incomplete'}}
+
+void test(int a, Foo b, void* c, int *d, Foo *e, const Foo *f, Incomplete *g) {
+  __builtin_zero_non_value_bits(a); // expected-error {{passing 'int' to parameter of incompatible type structure pointer: type mismatch at 1st parameter ('int' vs structure pointer)}}
+  __builtin_zero_non_value_bits(b); // expected-error {{passing 'Foo' to parameter of incompatible type structure pointer: type mismatch at 1st parameter ('Foo' vs structure pointer)}}
+  __builtin_zero_non_value_bits(c); // expected-error {{passing 'void *' to parameter of incompatible type structure pointer: type mismatch at 1st parameter ('void *' vs structure pointer)}}
+  __builtin_zero_non_value_bits(d); // expected-error {{passing 'int *' to parameter of incompatible type structure pointer: type mismatch at 1st parameter ('int *' vs structure pointer)}}
+  __builtin_zero_non_value_bits(e); // This should not error.
+  __builtin_zero_non_value_bits(f); // expected-error {{read-only variable is not assignable}}
+  __builtin_zero_non_value_bits(g); // expected-error {{variable has incomplete type 'Incomplete'}}
+}
Index: clang/test/CodeGenCXX/builtin-zero-non-value-bits.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/builtin-zero-non-value-bits.cpp
@@ -0,0 +1,249 @@
+// RUN: mkdir -p %t
+// RUN: %clang++ %s -o %t/run
+// RUN: %t/run
+
+#include 
+#include 
+#include 
+#include 
+
+template
+struct alignas(A1) BasicWithPadding {
+  T x;
+  alignas(A2) T y;
+};
+
+template
+struct alignas(A1) SpacedArrayMembers {
+  T x[N];
+  alignas(A2) char c;
+  T y[N];
+};
+
+template
+struct alignas(A1) PaddedPointerMembers {
+  T *x;
+  alignas(A2) T *y;
+};
+
+template
+struct alignas(A1) ThreeMembers {
+  T x;
+  alignas(A2) T y;
+  alignas(A3) T z;
+};
+
+template
+struct Normal {
+  T a;
+  T b;
+};
+
+template
+struct X {
+  T x;
+};
+
+template
+struct Z {
+  T z;
+};
+
+template
+struct YZ : public Z {
+  alignas(A) T y;
+};
+
+template
+struct alignas(A1) HasBase : public X, public YZ {
+  T a;
+  alignas(A2) T b;
+};
+
+template
+void testAllForType(T a, T b, T c, T d) {
+  using B = BasicWithPadding;
+  B basic1;
+  memset(&basic1, 0, sizeof(B));
+  basic1.x = a;
+  basic1.y = b;
+  B basic2;
+  memset(&basic2, 42, sizeof(B));
+  basic2.x = a;
+  basic2.y = b;
+  assert(memcmp(&basic1, &basic2, sizeof(B)) != 0);
+  __builtin_zero_non_value_bits(&basic2);
+  assert(memcmp(&basic1, &basic2, sizeof(B)) == 0);
+
+  using A = SpacedArrayMembers;
+  A arr1;
+  memset(&arr1, 0, sizeof(A));
+  arr1.x[0] = a;
+  arr1.x[1] = b;
+  arr1.y[0] = c;
+  arr1.y[1] = d;
+  A arr2;
+  memset(&arr2, 42, sizeof(A));
+  arr2.x[0] = a;
+  arr2.x[1] = b;
+  arr2.y[0] = c;
+  arr2.y[1] = d;
+  arr2.c = 0;
+  assert(memcmp(&arr1, &arr2, sizeof(A)) != 0);
+  __builtin_zero_non_value_bits(&arr2);
+  assert(memcmp(&arr1, &arr2, sizeof(A)) == 0);
+
+  using P = PaddedPointerMembers;
+  P ptr1;
+  memset(&ptr1, 0, sizeof(P));
+  ptr1.x = &a;
+  ptr1.y = &b;
+  P ptr2;
+  memset(&ptr2, 42, sizeof(P));
+  ptr2.x = &a;
+  ptr2.y = &b;
+  assert(memcmp(&ptr1, &ptr2, sizeof(P)) != 0);
+  __builtin_zero_non_value_bits(&ptr2);
+  assert(memcmp(&ptr1, &ptr2, sizeof(P)) == 0);
+
+  using Three = ThreeMembers;
+  Three three1;
+  memset(&three1, 0, sizeof(Three));
+  three1.x = a;
+  three1.y = b;
+  three1.z = c;
+  Three three2;
+  memset(&three2, 42, sizeof(Three));
+  three2.x = a;
+  three2.y = b;
+  three2.z = c;
+  __builtin_zero_non_value_bits(&three2);
+  assert(memcmp(&three1, &three2, sizeof(Three)) == 0);
+
+  using N = Normal;
+  N normal1;
+  memset(&normal1, 0, sizeof(N));
+  normal1.a = a;
+  normal1.b = b;
+  N normal2;
+  memset(&normal2, 42, sizeof(N));
+  normal2.a = a;
+  normal2.b = b;
+  __builtin_zero_non_value_bits(&normal2);
+  assert(memcmp(&normal1, &normal2, sizeof(N)) == 0);
+
+  using H = HasBase;
+  H base1;
+  memset(&base1, 0, sizeof(H));
+  base1.a = a;
+  base1.b = b;
+  base1.x = c;
+  base1.y = d;
+  base1.z = a;
+  H base2;
+  memse

[clang] 15d94a7 - Revert "Canonicalize declaration pointers when forming APValues."

2020-09-22 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2020-09-22T17:40:53-07:00
New Revision: 15d94a7d0f8f0d6b3b5308fff51b286957e45650

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

LOG: Revert "Canonicalize declaration pointers when forming APValues."

This reverts commit 905b9ca26c94fa86339451a528cedde5004fc1bb.

Reverting because this strips `weak` attributes off function
declarations, leading to the linker error we see at
https://ci.chromium.org/p/fuchsia/builders/ci/clang_toolchain.fuchsia-arm64-debug-subbuild/b8868932035091473008.

See https://reviews.llvm.org/rG905b9ca26c94 for reproducer details.

Added: 


Modified: 
clang/include/clang/AST/APValue.h
clang/lib/AST/APValue.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/ExprConstant.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
clang/test/OpenMP/ordered_messages.cpp

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index 6307f8a92e5a..5103cfa8604e 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -174,7 +174,6 @@ class APValue {
   return !(LHS == RHS);
 }
 friend llvm::hash_code hash_value(const LValueBase &Base);
-friend struct llvm::DenseMapInfo;
 
   private:
 PtrTy Ptr;
@@ -202,7 +201,8 @@ class APValue {
 
   public:
 LValuePathEntry() : Value() {}
-LValuePathEntry(BaseOrMemberType BaseOrMember);
+LValuePathEntry(BaseOrMemberType BaseOrMember)
+: Value{reinterpret_cast(BaseOrMember.getOpaqueValue())} {}
 static LValuePathEntry ArrayIndex(uint64_t Index) {
   LValuePathEntry Result;
   Result.Value = Index;

diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 32d3ff7ce1d0..08ae0ff3c67d 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -38,7 +38,7 @@ static_assert(
 "Type is insufficiently aligned");
 
 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
-: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
+: Ptr(P), Local{I, V} {}
 APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
 : Ptr(P), Local{I, V} {}
 
@@ -82,19 +82,13 @@ bool operator==(const APValue::LValueBase &LHS,
 const APValue::LValueBase &RHS) {
   if (LHS.Ptr != RHS.Ptr)
 return false;
-  if (LHS.is() || LHS.is())
+  if (LHS.is())
 return true;
   return LHS.Local.CallIndex == RHS.Local.CallIndex &&
  LHS.Local.Version == RHS.Local.Version;
 }
 }
 
-APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
-  if (const Decl *D = BaseOrMember.getPointer())
-BaseOrMember.setPointer(D->getCanonicalDecl());
-  Value = reinterpret_cast(BaseOrMember.getOpaqueValue());
-}
-
 namespace {
   struct LVBase {
 APValue::LValueBase Base;
@@ -119,16 +113,14 @@ APValue::LValueBase::operator bool () const {
 
 clang::APValue::LValueBase
 llvm::DenseMapInfo::getEmptyKey() {
-  clang::APValue::LValueBase B;
-  B.Ptr = DenseMapInfo::getEmptyKey();
-  return B;
+  return clang::APValue::LValueBase(
+  DenseMapInfo::getEmptyKey());
 }
 
 clang::APValue::LValueBase
 llvm::DenseMapInfo::getTombstoneKey() {
-  clang::APValue::LValueBase B;
-  B.Ptr = DenseMapInfo::getTombstoneKey();
-  return B;
+  return clang::APValue::LValueBase(
+  DenseMapInfo::getTombstoneKey());
 }
 
 namespace clang {
@@ -781,10 +773,8 @@ void APValue::MakeMemberPointer(const ValueDecl *Member, 
bool IsDerivedMember,
   assert(isAbsent() && "Bad state change");
   MemberPointerData *MPD = new ((void*)(char*)Data.buffer) MemberPointerData;
   Kind = MemberPointer;
-  MPD->MemberAndIsDerivedMember.setPointer(
-  Member ? cast(Member->getCanonicalDecl()) : nullptr);
+  MPD->MemberAndIsDerivedMember.setPointer(Member);
   MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
   MPD->resizePath(Path.size());
-  for (unsigned I = 0; I != Path.size(); ++I)
-MPD->getPath()[I] = Path[I]->getCanonicalDecl();
+  memcpy(MPD->getPath(), Path.data(), Path.size()*sizeof(const 
CXXRecordDecl*));
 }

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index ae38e3dd2a72..0ee1399d42df 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4686,7 +4686,7 @@ char *Buffer = new (getASTContext(), 1) char[Name.size() 
+ 1];
 void ValueDecl::anchor() {}
 
 bool ValueDecl::isWeak() const {
-  for (const auto *I : getMostRecentDecl()->attrs())
+  for (const auto *I : attrs())
 if (isa(I) || isa(I))
   return true;
 

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index ab2b55c0762e..f4314d0bd961 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -720,7 +720,7 @@ bool Decl::isWeakImporte

[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-09-22 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

Master branch has too many false positives for tidy - would it be possible to 
create a branch that contains this patch set on top of llvm-11.0-rc3? I would 
then add this to our internal CI.

For the legacy code (see previous reports) we found quite a few false 
positives. For a new code base that we're developing from scratch with C++20, 
there have been no false positives - it catches missed 'const' much better than 
human reviewers - we still keep a Clang10 around that I built from source with 
the previous version of the patches :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[clang] 1009229 - [Clang] Fix a typo in implicit-int-float-conversion.c

2020-09-22 Thread via cfe-commits

Author: Yuanfang Chen
Date: 2020-09-22T16:51:23-07:00
New Revision: 10092291d7a770fee9eec8d8c7f60aeca9a8d7fb

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

LOG: [Clang] Fix a typo in implicit-int-float-conversion.c

Added: 


Modified: 
clang/test/Sema/implicit-int-float-conversion.c

Removed: 




diff  --git a/clang/test/Sema/implicit-int-float-conversion.c 
b/clang/test/Sema/implicit-int-float-conversion.c
index f3ad08e4111a..94714de3f39c 100644
--- a/clang/test/Sema/implicit-int-float-conversion.c
+++ b/clang/test/Sema/implicit-int-float-conversion.c
@@ -16,7 +16,7 @@ void testAssignment() {
   float  = UL; // expected-warning {{changes value from 
 to 1312}}
 
   long l = L;
-#ifdef NONCOST
+#ifdef NONCONST
   float fff = l; // expected-warning {{implicit conversion from 'long' to 
'float' may lose precision}}
 #endif
 }



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


[PATCH] D88121: [X86] Add a memory clobber to the bittest intrinsic inline asm. Get default clobbers from the target

2020-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, rnk, echristo.
craig.topper requested review of this revision.

I believe the inline asm emitted here should have a memory clobber since it 
writes to memory.

It was also missing the dirflag clobber that we use by default along with flags 
and fpsr. To avoid missing defaults in the future, get the default list from 
the target


https://reviews.llvm.org/D88121

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/bittest-intrin.c


Index: clang/test/CodeGen/bittest-intrin.c
===
--- clang/test/CodeGen/bittest-intrin.c
+++ clang/test/CodeGen/bittest-intrin.c
@@ -34,12 +34,12 @@
 #endif
 
 // X64-LABEL: define dso_local void @test32(i32* %base, i32 %idx)
-// X64: call i8 asm sideeffect "btl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btcl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btrl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btsl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "lock btrl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "lock btsl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btcl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btrl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btsl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "lock btrl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "lock btsl $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
 
 // X64-LABEL: define dso_local void @test64(i64* %base, i64 %idx)
 // X64: call i8 asm sideeffect "btq $2, ($1)\0A\09setc ${0:b}", 
"=r,r,r,~{{.*}}"(i64* %{{.*}}, i64 {{.*}})
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -808,8 +808,12 @@
   AsmOS << SizeSuffix << " $2, ($1)\n\tsetc ${0:b}";
 
   // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints =
-  "=r,r,r,~{cc},~{memory},~{fpsr},~{dirflag},~{flags}";
+  std::string Constraints = "=r,r,r,~{cc},~{memory}";
+  std::string MachineClobbers = CGF.getTarget().getClobbers();
+  if (!MachineClobbers.empty()) {
+Constraints += ',';
+Constraints += MachineClobbers;
+  }
   llvm::IntegerType *IntType = llvm::IntegerType::get(
   CGF.getLLVMContext(),
   CGF.getContext().getTypeSize(E->getArg(1)->getType()));


Index: clang/test/CodeGen/bittest-intrin.c
===
--- clang/test/CodeGen/bittest-intrin.c
+++ clang/test/CodeGen/bittest-intrin.c
@@ -34,12 +34,12 @@
 #endif
 
 // X64-LABEL: define dso_local void @test32(i32* %base, i32 %idx)
-// X64: call i8 asm sideeffect "btl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btcl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btrl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "btsl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "lock btrl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
-// X64: call i8 asm sideeffect "lock btsl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{{.*}}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btcl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btrl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "btsl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32 {{.*}})
+// X64: call i8 asm sideeffect "lock btrl $2, ($1)\0A\09setc ${0:b}", "=r,r,r,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"

[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2020-09-22 Thread Ten Tzen via Phabricator via cfe-commits
tentzen added a comment.

In D80344#2286838 , @rjmccall wrote:

> In D80344#228 , @tentzen wrote:
>
>> Thank you for prompt reply again.
>>
>>> [rjmccall] And I agree with him that the potential benefits are 
>>> substantial. I'm just saying that one barely-trafficked RFC thread is not 
>>> evidence of a community consensus.
>>
>> OK, thanks.  it's good to know you are also supportive in adding this 
>> feature.
>>
>>> [rjmccall] As I understand it, you are creating implicit edges within the 
>>> function to the active SEH handler (potentially part of the same function) 
>>> from arbitrary places within covered basic blocks, turning basic blocks 
>>> from a single-entry single-(internal-)exit representation to a single-entry 
>>> multiple-exit representation. That is a huge change. How do you expect LLVM 
>>> transformations to preserve or merge this information across blocks? How do 
>>> you expect transformations to not move code between blocks in problematic 
>>> ways, or reorder code within blocks in ways that will suddenly be visible 
>>> to the optimizer? These are the standard objections to supporting features 
>>> like this, that they have basically unspecified behavior and appear to work 
>>> by good intentions and happy thoughts.
>>
>> There is absolutely NO explicit edge added in this design.
>
> I didn't say there was.  I said that there was an *implicit* edge: from the 
> memory access to the handler.  It's precisely because that edge is implicit 
> that it's problematic for analysis and optimization.

Oh, sorry I misread it.
For HW exceptions the 'implicit' edge is unavoidable unless an explicit 
approach (like previous iload/istore) is employed.  iload approach was 
extensively discussed and evaluated when it's proposed. As far as I know, the 
concerns were that it could create many Invokes, complicate flow graph and 
possibly result in negative performance impact for downstream optimization and 
code generation. Making all optimizations be aware of the new semantic is also 
substantial.
So this design applies an IMPLICT approach. I respectfully disagree that it's 
problematic because as long as volatile attribute is honored it's robust. 
please see the C & C++ SEH rule stated in patch description section.

>> For LLVM transformations/optimizations, the only constrain added is 
>> **volatile** attribute on memory operations within a SEH region.
>
> When is this attribute applied?  Because you can't just apply it at a single 
> point; you also need to mark operations when they're copied/inlined into the 
> region.  We once had a similar attempt at handling exceptions with a 
> setjmp-based ABI (not the "SJLJ" exceptions supported by the backends, 
> something frontend-centric) that had persistent problems because of poor 
> modeling in the IR, which it feels like this is doomed to repeat.

This is applied only once in FE. Consider it's like from the source code. So NO 
there is no other place we need to change. Per SEH semantic, the inline code is 
immune from volatile constraint.
I don't think this is the same as SJLJ story.  I did once look into SJLJ 
problem when I found every single test in MSVC Setjmp suite was broken.  it's 
because the implicit back edge from longjmp (or a callee with longjump) was not 
modeled properly.  actually I have a simple idea that can fix this SJLJ problem 
robustly, but I've been clogged in this SEH task.

>>> [rjmccall] Does it pass under all combinations of optimization and 
>>> code-generation settings? How do LLVM contributors ensure that this test 
>>> suite continues to pass?
>>
>> Yes. this is just the first patch.  there will be second patch to land LLVM 
>> code-gen part in, then 3rd patch to add some test cases (Ex, xcpt4u.c from 
>> MSVC). Without option -EHa, the patch is a zero-impact change for now.
>
> Do you expect to maintain a CI bot that runs the full test suite continuously 
> as changes go into LLVM?  Because this sort of thing is extremely easy to 
> break.

Yes, as long as it's a bug/flaw in the design/implementation.  New 
opt/analysis/tools that violates original basic volatile/cleanup/EH-framework 
exposed by SEH test cases is not included.  Isn't this the policy of Clang/LLVM 
community?

>>> [rjmccall] There is a major difference between HW exceptions and non-HW 
>>> exceptions, which is that non-HW exceptions are observed only at call 
>>> sites. It is quite easy to write code in IRGen that works because the code 
>>> emitted at a certain point isn't totally arbitrary
>>
>> still not completely sure what you are referring to. let me guess. Are you 
>> concerned that the Cleanup mechanism of a SEH region may not be setup 
>> properly if there is no call instruction in the region? This is actually a 
>> good question. The answer is that the presence of seh.try.begin() intrinsic 
>> will ensure that a Cleanup stack is established properly because th

[PATCH] D78075: [Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

@jdoerfert Ready to be reviewed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

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


[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-22 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 293579.
akhuang added a comment.

Update ctor homing check, and add some test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87808

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-limited-ctor.cpp


Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===
--- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -20,14 +20,37 @@
 };
 D::D() {}
 
+// Test for constexpr constructor.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"E"{{.*}}DIFlagTypePassByValue
 struct E {
   constexpr E(){};
 } TestE;
 
+// Tests for trivial constructors.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"F"{{.*}}DIFlagTypePassByValue
 struct F {
   F() = default;
   F(int) {}
   int i;
 } TestF;
+
+// CHECK-DAG: ![[G:.*]] ={{.*}}!DICompositeType({{.*}}name: 
"G"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[G]], {{.*}}DIFlagTypePassByValue
+struct G {
+  G() : g_(0) {}
+  struct {
+int g_;
+  };
+} TestG;
+
+// CHECK-DAG: !DICompositeType({{.*}}name: "H",{{.*}}DIFlagTypePassByValue
+struct H {
+  B b;
+};
+void f(H h) {}
+
+// CHECK-DAG: !DICompositeType({{.*}}name: "I",{{.*}}DIFlagTypePassByValue
+struct I {
+  B b;
+};
+void f(decltype(I()) i) {}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2281,22 +2281,18 @@
 }
 
 static bool canUseCtorHoming(const CXXRecordDecl *RD) {
-  // Constructor homing can be used for classes that have at least one
-  // constructor and have no trivial or constexpr constructors.
+  // Constructor homing can be used for classes that don't have any implicit,
+  // trivial default constructors or constexpr constructors.
+  // In other words, the class cannot be constructed without emitting code for
+  // one of its constructors.
+  //
   // Skip this optimization if the class or any of its methods are marked
   // dllimport.
-  if (RD->isLambda() || RD->hasConstexprNonCopyMoveConstructor() ||
-  isClassOrMethodDLLImport(RD))
+  if (RD->isLambda() || isClassOrMethodDLLImport(RD))
 return false;
 
-  if (RD->ctors().empty())
-return false;
-
-  for (const auto *Ctor : RD->ctors())
-if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
-  return false;
-
-  return true;
+  return !RD->isAggregate() && !RD->hasTrivialDefaultConstructor() &&
+ !RD->hasConstexprNonCopyMoveConstructor();
 }
 
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,


Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===
--- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -20,14 +20,37 @@
 };
 D::D() {}
 
+// Test for constexpr constructor.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "E"{{.*}}DIFlagTypePassByValue
 struct E {
   constexpr E(){};
 } TestE;
 
+// Tests for trivial constructors.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "F"{{.*}}DIFlagTypePassByValue
 struct F {
   F() = default;
   F(int) {}
   int i;
 } TestF;
+
+// CHECK-DAG: ![[G:.*]] ={{.*}}!DICompositeType({{.*}}name: "G"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[G]], {{.*}}DIFlagTypePassByValue
+struct G {
+  G() : g_(0) {}
+  struct {
+int g_;
+  };
+} TestG;
+
+// CHECK-DAG: !DICompositeType({{.*}}name: "H",{{.*}}DIFlagTypePassByValue
+struct H {
+  B b;
+};
+void f(H h) {}
+
+// CHECK-DAG: !DICompositeType({{.*}}name: "I",{{.*}}DIFlagTypePassByValue
+struct I {
+  B b;
+};
+void f(decltype(I()) i) {}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2281,22 +2281,18 @@
 }
 
 static bool canUseCtorHoming(const CXXRecordDecl *RD) {
-  // Constructor homing can be used for classes that have at least one
-  // constructor and have no trivial or constexpr constructors.
+  // Constructor homing can be used for classes that don't have any implicit,
+  // trivial default constructors or constexpr constructors.
+  // In other words, the class cannot be constructed without emitting code for
+  // one of its constructors.
+  //
   // Skip this optimization if the class or any of its methods are marked
   // dllimport.
-  if (RD->isLambda() || RD->hasConstexprNonCopyMoveConstructor() ||
-  isClassOrMethodDLLImport(RD))
+  if (RD->isLambda() || isClassOrMethodDLLImport(RD))
 return false;
 
-  if (RD->ctors().empty())
-return false;
-
-  for (const auto *Ctor : RD->ctor

[PATCH] D87451: add new clang option -mno-xcoff-visibility

2020-09-22 Thread David Tenty via Phabricator via cfe-commits
daltenty added inline comments.



Comment at: llvm/include/llvm/Target/TargetMachine.h:265
+  /// corresponding to -mno-xcoff-visibility.
+  bool getNoXCOFFVisibility() const { return Options.NoXCOFFVisibility; }
+

This seems like it needs the corresponding comand-line option for llc added and 
an llc test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87451

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


[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

Ok, I guess we are on the same page. The idea sounds fine to me.

I would suggest just check that the output matches the input file as much as 
possible, rather than just check a label and a call instruction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88114

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


[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added a comment.

In D88114#2288749 , @steven_wu wrote:

> In D88114#2288737 , @mtrofin wrote:
>
>> In D88114#2288732 , @steven_wu 
>> wrote:
>>
>>> I am not sure what exactly is expected here. What is your definition for 
>>> pre-optimized bitcode and how your test case ensures that? Can you explain 
>>> a bit more for context?
>>
>> Pre-optimized meaning before the llvm optimization pipeline is called. 
>> That's the current implementation, and the test explicitly checks that the 
>> inlining of bar into foo doesn't happen.
>>
>> I could add an "alwaysinline" to bar, to further stress that.
>
> I think the current implementation does run optimization passes if the input 
> is c family language and we need to keep it that way (just so that we don't 
> do most of the optimization again). The reason you don't see it running 
> because you are using IR as input. For Apple's implementation, we actually 
> pass `-disable-llvm-passes` when the input is IR to ensure no optimization 
> passes are running.

Afaik, today's implementation has 2 parts: driver and cc1. The cc1 part always 
emits before opt passes. The driver part, upon seeing -fembed-bitcode, splits 
compilation in 2 stages. Stage 1 performs ops and emits bc to a file 
(-emit-llvm). Stage 1 doesn't expose -fembed-bitcode to cc1. Stage 2 takes the 
output from stage1, disables optimizations, and adds -fembed-bitcode. So 
together, this gives the semantics you mentioned, but it happens that if you 
skip the driver and pass -fembed-bitcode to cc1, we get the pre-opt bitcode, 
which helps my scenario.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88114

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


[PATCH] D78075: [Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 293577.
tianshilei1992 added a comment.

Rebased the source code and refined `declare_mapper_codegen.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
@@ -66,7 +66,11 @@
 #ifndef HEADER
 #define HEADER
 
-// CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CHECK-DAG: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %{{[^,]+}}, %{{[^,]+}} }
+// CHECK-32-DAG: [[KMP_PRIVATES_T]] = type { [3 x i64], [3 x i8*], [3 x i8*], [3 x i8*], i16 }
+// CHECK-64-DAG: [[KMP_PRIVATES_T]] = type { [3 x i8*], [3 x i8*], [3 x i64], [3 x i8*], i16 }
 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
 // CHECK-DAG: [[DEF_LOC:@.+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
 
@@ -132,33 +136,26 @@
   double cn[5][n];
   TT d;
 
-  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target_teams_nowait_mapper(i64 -1, i8* @{{[^,]+}}, i32 3, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[SIZET]], i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[MAPT]], i32 0, i32 0), i8** null, i32 {{[^,]+}}, i32 {{[^)]+}})
-  // CHECK-DAG:   [[BP]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[P]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]]
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX0]]
-  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]]
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR1]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR2]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR2]]
-  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
-  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
-  // CHECK:   [[FAIL]]
-  // CHECK:   call void [[HVT0:@.+]](i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^)]+}})
-  // CHECK-NEXT:  br label %[[END]]
-  // CHECK:   [[END]]
+  // CHECK-DAG: call i32 @__kmpc_omp_task([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i8* [[TASK:%.+]])
+  // CHECK-32-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i32 84, i32 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-64-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 144, i64 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-DAG: [[TASK_CAST:%.+]] = bitcast i8*

[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-22 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2292-2300
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }

rsmith wrote:
> dblaikie wrote:
> > rsmith wrote:
> > > This looks pretty similar to:
> > > 
> > > ```
> > > return RD->hasUserDeclaredConstructor() && 
> > > !RD->hasTrivialDefaultConstructor();
> > > ```
> > > 
> > > (other than its treatment of user-declared copy or move constructors), 
> > > but I have to admit I don't really understand what the "at least one 
> > > constructor and no trivial or constexpr constructors" rule aims to 
> > > achieve, so it's hard to know if this is the right interpretation. The 
> > > rule as written in the comment above is presumably not exactly right -- 
> > > all classes have at least one constructor, and we're not excluding 
> > > classes with trivial copy or move constructors, only those with trivial 
> > > default constructors.
> > > 
> > > I wonder if the intent would be better captured by "at least one 
> > > non-inline constructor" (that is, assuming all declared functions are 
> > > defined, there is at least one translation unit in which a constructor is 
> > > defined that can be used as a home for the class info).
> > So the general goal is to detect any type where the construction of that 
> > type somewhere must invoke a constructor that will be IR-generated.
> > 
> > Move and copy constructors are ignored because the assumption is they must 
> > be moving/copying from some other object, which must've been constructed, 
> > ultimately, by a non-move/copy constructor.
> > 
> > Ideally this would be usable even for inline ctors - even if the ctor calls 
> > get optimized away later[^1], they'd still allow us to reduce the number of 
> > places the type is emitted to only those places that call the ctor.
> > 
> > 
> > 
> > [^1] actually, the way that should work doesn't seem to be working right 
> > now (eg:
> > type.cpp
> > ```
> > struct t1 { t1() { } };
> > void f1(void*);
> > int main() {
> >   f1(new t1());
> > }
> > ```
> > type2.cpp
> > ```
> > struct t1 { t1() { } };
> > void f1(void* v) {
> >   delete (t1*)v;
> > }
> > ```
> > build: `clang++ type.cpp -g -Xclang -fuse-ctor-homing type2.cpp && 
> > llvm-dwarfdump a.out`
> > -> definition of "t1" in the DWARF
> > build with optimizations: `clang++ -O3 type.cpp -g -Xclang 
> > -fuse-ctor-homing type2.cpp && llvm-dwarfdump a.out`
> > -> missing definition of "t1"
> > `type.cpp` is chosen as a home for `t1` because it calls a user-defined 
> > ctor, but then that ctor gets optimized away and there's no other mention 
> > of `t1` in `type.cpp` so the type is dropped entirely. This could happen 
> > even with a non-inline definition - under LTO the ctor could get optimized 
> > away (though this would be safe in FullLTO - the other references to `t1` 
> > would be made to refer to the definition and keep it alive - but in ThinLTO 
> > the TU defining the ctor might be imported and nothing else - leaving the 
> > type unused/dropped)
> > To fix this we should put 'homed' types in the retained types list so they 
> > are preserved even if all other code/references to the type are dropped. I 
> > think I implemented this homed type pinning for explicit template 
> > specialization definitions, because they have no code attachment point, so 
> > similar logic could be used for ctor homing. (vtable homing /might/ benefit 
> > from this with aggressive/whole program devirtualization? Not sure - harder 
> > to actually optimize away all the references to a type, but possible maybe?)
> Oh, I see, that's clever and very neat.
> 
> So the intent is to identify types for which we know that either no instances 
> are ever created, or some constructor must be actually emitted in some 
> translation unit (prior to optimizations running). And that's why we want to 
> ignore copy and move constructors [and could in fact ignore any constructor 
> taking the class type by value or reference, directly or indirectly] (they 
> cannot be the only place that creates an object) and also why we don't want 
> to do this if there's a constexpr constructor or trivial default constructor 
> (we might not generate code for them). And the "no constructors" check seems 
> to effectively be checking whether aggregate initialization could be 
> performed.
> 
> I think we can replace the loop with `return !RD->isAggregate() && 
> !RD->hasTrivialDefaultConstructor();`.
> 
> (Minor aside, it is possible to create an instance of a type if its only 
> constructor is a copy constructor, eg with `struct A { A(const A&) {} } a = 
> a;`, but I doubt that's a practical concern for your purposes.)
> So the intent is to identify types for which we know that either no instances 
> are ever created, or some construc

[PATCH] D87652: Sema: add support for `__attribute__((__swift_newtype__))`

2020-09-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 293574.
compnerd marked 6 inline comments as done.
compnerd added a comment.

Update for feedback from @aaron.ballman 
The `ParseAttrCommonArgs` refactoring still needs to be looked at, but this 
should address the feedback, and doesn't need to be predicated on the 
refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87652

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/attr-swift_newtype.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/attr-swift_newtype.m

Index: clang/test/SemaObjC/attr-swift_newtype.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_newtype.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef int Bad1 __attribute__((swift_newtype(invalid)));
+// expected-warning@-1 {{'swift_newtype' attribute argument not supported: 'invalid'}}
+typedef int Bad2 __attribute__((swift_newtype()));
+// expected-error@-1 {{argument required after attribute}}
+typedef int Bad3 __attribute__((swift_newtype(invalid, ignored)));
+// expected-error@-1 {{expected ')'}}
+// expected-note@-2 {{to match this '('}}
+// expected-warning@-3 {{'swift_newtype' attribute argument not supported: 'invalid'}}
+
+struct __attribute__((__swift_newtype__(struct))) Bad4 { };
+// expected-error@-1 {{'__swift_newtype__' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -151,6 +151,7 @@
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: SwiftNewType (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
Index: clang/test/AST/attr-swift_newtype.m
===
--- /dev/null
+++ clang/test/AST/attr-swift_newtype.m
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+
+typedef int T1 __attribute__((__swift_newtype__(struct)));
+typedef int T2 __attribute__((__swift_newtype__(enum)));
+
+typedef int T3 __attribute__((__swift_wrapper__(struct)));
+typedef int T4 __attribute__((__swift_wrapper__(enum)));
+
+typedef int T5;
+typedef int T5 __attribute__((__swift_wrapper__(struct)));
+typedef int T5;
+// CHECK-LABEL: TypedefDecl {{.+}} T5 'int'
+// CHECK-NEXT: BuiltinType {{.+}} 'int'
+// CHECK-NEXT: TypedefDecl {{.+}} T5 'int'
+// CHECK-NEXT: BuiltinType {{.+}} 'int'
+// CHECK-NEXT: SwiftNewTypeAttr {{.+}} NK_Struct
+// CHECK-NEXT: TypedefDecl {{.+}} T5 'int'
+// CHECK-NEXT: BuiltinType {{.+}} 'int'
+// CHECK-NEXT: SwiftNewTypeAttr {{.+}} NK_Struct
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5942,6 +5942,33 @@
   D->addAttr(::new (S.Context) SwiftNameAttr(S.Context, AL, Name));
 }
 
+static void handleSwiftNewType(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // Make sure that there is an identifier as the annotation's single argument.
+  if (!checkAttributeNumArgs(S, AL, 1))
+return;
+
+  if (!AL.isArgIdent(0)) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_type) << AL
+<< AANT_ArgumentIdentifier;
+return;
+  }
+
+  SwiftNewTypeAttr::NewtypeKind Kind;
+  IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
+  if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) {
+S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
+return;
+  }
+
+  if (!isa(D)) {
+S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
+<< AL << /* typedefs */13;
+return;
+  }
+
+  D->addAttr(::new (S.Context) SwiftNewTypeAttr(S.Context, AL, Kind));
+}
+
 //===--===//
 // Microsoft specific attribute handlers.
 //===--===//
@@ -7867,6 +7894,9 @@
   case ParsedAttr::AT_SwiftName:
 handleSwiftName(S, D, AL);
 break;
+  case ParsedAttr::AT_SwiftNewType:
+handleSwiftNewType(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftObjCMembers:
 handleSimpleAttribute(S

[PATCH] D87451: add new clang option -mno-xcoff-visibility

2020-09-22 Thread Digger via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 293571.
DiggerLin added a comment.
Herald added subscribers: llvm-commits, kbarton, hiraditya, nemanjai.
Herald added a project: LLVM.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87451

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/ignore-xcoff-visibility.cpp
  llvm/include/llvm/Target/TargetMachine.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -1686,17 +1686,19 @@
   assert(LinkageAttr != MCSA_Invalid && "LinkageAttr should not MCSA_Invalid.");
 
   MCSymbolAttr VisibilityAttr = MCSA_Invalid;
-  switch (GV->getVisibility()) {
+  if (!TM.getNoXCOFFVisibility()) {
+switch (GV->getVisibility()) {
 
-  // TODO: "exported" and "internal" Visibility needs to go here.
-  case GlobalValue::DefaultVisibility:
-break;
-  case GlobalValue::HiddenVisibility:
-VisibilityAttr = MAI->getHiddenVisibilityAttr();
-break;
-  case GlobalValue::ProtectedVisibility:
-VisibilityAttr = MAI->getProtectedVisibilityAttr();
-break;
+// TODO: "exported" and "internal" Visibility needs to go here.
+case GlobalValue::DefaultVisibility:
+  break;
+case GlobalValue::HiddenVisibility:
+  VisibilityAttr = MAI->getHiddenVisibilityAttr();
+  break;
+case GlobalValue::ProtectedVisibility:
+  VisibilityAttr = MAI->getProtectedVisibilityAttr();
+  break;
+}
   }
 
   OutStreamer->emitXCOFFSymbolLinkageWithVisibility(GVSym, LinkageAttr,
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -123,9 +123,10 @@
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
   DisableIntegratedAS(false), RelaxELFRelocations(false),
   FunctionSections(false), DataSections(false),
-  UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
-  TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
-  EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
+  NoXCOFFVisibility(false), UniqueSectionNames(true),
+  UniqueBasicBlockSectionNames(false), TrapUnreachable(false),
+  NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false),
+  ExplicitEmulatedTLS(false), EnableIPRA(false),
   EmitStackSizeSection(false), EnableMachineOutliner(false),
   EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
   EmitAddrsig(false), EmitCallSiteInfo(false),
@@ -230,6 +231,9 @@
 /// Emit data into separate sections.
 unsigned DataSections : 1;
 
+/// Do not emit visibility attribute for xcoff.
+unsigned NoXCOFFVisibility : 1;
+
 unsigned UniqueSectionNames : 1;
 
 /// Use unique names for basic block sections.
Index: llvm/include/llvm/Target/TargetMachine.h
===
--- llvm/include/llvm/Target/TargetMachine.h
+++ llvm/include/llvm/Target/TargetMachine.h
@@ -260,6 +260,10 @@
 return Options.FunctionSections;
   }
 
+  /// Return true if visibility attribute should not be emitted in xcoff,
+  /// corresponding to -mno-xcoff-visibility.
+  bool getNoXCOFFVisibility() const { return Options.NoXCOFFVisibility; }
+
   /// If basic blocks should be emitted into their own section,
   /// corresponding to -fbasic-block-sections.
   llvm::BasicBlockSection getBBSectionsType() const {
Index: clang/test/Driver/ignore-xcoff-visibility.cpp
===
--- /dev/null
+++ clang/test/Driver/ignore-xcoff-visibility.cpp
@@ -0,0 +1,110 @@
+// RUN: %clang -target powerpc-unknown-aix -emit-llvm -o - -S  %s  |\
+// RUN:   FileCheck --check-prefix=VISIBILITY-IR %s
+
+// RUN: %clang -target powerpc-unknown-aix -o - -S  %s  |\
+// RUN:   FileCheck --check-prefix=NOVISIBILITY-ASM %s
+
+// RUN: %clang -target powerpc-unknown-linux  -emit-llvm  -o - -S %s  | \
+// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
+
+// RUN: %clang -mno-xcoff-visibility -target powerpc-unknown-aix -emit-llvm -o - -S %s  | \
+// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
+
+// RUN: %clang -mno-xcoff-visibility -target powerpc-unknown-aix -o - -S %s  | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-ASM %s
+
+// RUN: not %clang -mno-xcoff-visibility -target powerpc-unknown-linux -emit

[PATCH] D88103: [JSON] Add error reporting facility, used in fromJSON and ObjectMapper.

2020-09-22 Thread walter erquinigo via Phabricator via cfe-commits
wallace added a comment.

I like this a lot!! Amazing work. I think it'll be useful for my Trace patch. 
I'll do a corresponding refactor using probably this new functionality.
I find the diff straightforward to follow. Unless anyone has objections, I'm 
fine with the patch at it is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88103

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


[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

In D88114#2288737 , @mtrofin wrote:

> In D88114#2288732 , @steven_wu wrote:
>
>> I am not sure what exactly is expected here. What is your definition for 
>> pre-optimized bitcode and how your test case ensures that? Can you explain a 
>> bit more for context?
>
> Pre-optimized meaning before the llvm optimization pipeline is called. That's 
> the current implementation, and the test explicitly checks that the inlining 
> of bar into foo doesn't happen.
>
> I could add an "alwaysinline" to bar, to further stress that.

I think the current implementation does run optimization passes if the input is 
c family language and we need to keep it that way (just so that we don't do 
most of the optimization again). The reason you don't see it running because 
you are using IR as input. For Apple's implementation, we actually pass 
`-disable-llvm-passes` when the input is IR to ensure no optimization passes 
are running.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88114

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


[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin added a comment.

In D88114#2288732 , @steven_wu wrote:

> I am not sure what exactly is expected here. What is your definition for 
> pre-optimized bitcode and how your test case ensures that? Can you explain a 
> bit more for context?

Pre-optimized meaning before the llvm optimization pipeline is called. That's 
the current implementation, and the test explicitly checks that the inlining of 
bar into foo doesn't happen.

I could add an "alwaysinline" to bar, to further stress that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88114

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


[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

I am not sure what exactly is expected here. What is your definition for 
pre-optimized bitcode and how your test case ensures that? Can you explain a 
bit more for context?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88114

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


[PATCH] D88115: [CUDA][HIP] Fix static device var used by host code only

2020-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

A static device variable may be accessed in host code through
cudaMemCpyFromSymbol etc. Currently clang does not
emit the static device variable if it is only referenced by
host code, which causes host code to fail at run time.

This patch fixes that.


https://reviews.llvm.org/D88115

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/static-device-var-no-rdc.cu


Index: clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
===
--- clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
+++ clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
@@ -63,6 +63,13 @@
 // externalized nor registered.
 // DEV-DAG: @_ZZ6devfunPPKiE1p = linkonce_odr addrspace(4) constant i32 2, 
comdat
 
+// Check a static device variable referenced by host function only is 
externalized.
+// DEV-DAG: @_ZL1w = addrspace(1) externally_initialized global i32 0
+// HOST-DAG: @_ZL1w = internal global i32 undef
+// HOST-DAG: @[[DEVNAMEW:[0-9]+]] = {{.*}}c"_ZL1w\00"
+
+static __device__ int w;
+
 inline __device__ void devfun(const int ** b) {
   const static int p = 2;
   b[0] = &p;
@@ -92,11 +99,13 @@
   getDeviceSymbol(&x);
   getDeviceSymbol(&x5);
   getDeviceSymbol(&y);
+  getDeviceSymbol(&w);
   z = 123;
   a[0] = &z2;
 }
 
 // HOST: __hipRegisterVar({{.*}}@_ZL1x {{.*}}@[[DEVNAMEX]]
 // HOST: __hipRegisterVar({{.*}}@_ZL1y {{.*}}@[[DEVNAMEY]]
+// HOST: __hipRegisterVar({{.*}}@_ZL1w {{.*}}@[[DEVNAMEW]]
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6kernelPiPPKiE1w
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6devfunPPKiE1p
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2195,6 +2195,11 @@
 assert(DeferredVTables.empty());
   }
 
+  // Emit CUDA/HIP static device variables referenced by host code only.
+  if (getLangOpts().CUDA)
+for (auto V : getContext().CUDAStaticDeviceVarReferencedByHost)
+  DeferredDeclsToEmit.push_back(V);
+
   // Stop if we're out of both deferred vtables and deferred declarations.
   if (DeferredDeclsToEmit.empty())
 return;


Index: clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
===
--- clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
+++ clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
@@ -63,6 +63,13 @@
 // externalized nor registered.
 // DEV-DAG: @_ZZ6devfunPPKiE1p = linkonce_odr addrspace(4) constant i32 2, comdat
 
+// Check a static device variable referenced by host function only is externalized.
+// DEV-DAG: @_ZL1w = addrspace(1) externally_initialized global i32 0
+// HOST-DAG: @_ZL1w = internal global i32 undef
+// HOST-DAG: @[[DEVNAMEW:[0-9]+]] = {{.*}}c"_ZL1w\00"
+
+static __device__ int w;
+
 inline __device__ void devfun(const int ** b) {
   const static int p = 2;
   b[0] = &p;
@@ -92,11 +99,13 @@
   getDeviceSymbol(&x);
   getDeviceSymbol(&x5);
   getDeviceSymbol(&y);
+  getDeviceSymbol(&w);
   z = 123;
   a[0] = &z2;
 }
 
 // HOST: __hipRegisterVar({{.*}}@_ZL1x {{.*}}@[[DEVNAMEX]]
 // HOST: __hipRegisterVar({{.*}}@_ZL1y {{.*}}@[[DEVNAMEY]]
+// HOST: __hipRegisterVar({{.*}}@_ZL1w {{.*}}@[[DEVNAMEW]]
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6kernelPiPPKiE1w
 // HOST-NOT: __hipRegisterVar({{.*}}@_ZZ6devfunPPKiE1p
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2195,6 +2195,11 @@
 assert(DeferredVTables.empty());
   }
 
+  // Emit CUDA/HIP static device variables referenced by host code only.
+  if (getLangOpts().CUDA)
+for (auto V : getContext().CUDAStaticDeviceVarReferencedByHost)
+  DeferredDeclsToEmit.push_back(V);
+
   // Stop if we're out of both deferred vtables and deferred declarations.
   if (DeferredDeclsToEmit.empty())
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86790: [FE] Use preferred alignment instead of ABI alignment for complete object when applicable

2020-09-22 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L updated this revision to Diff 293561.
Xiangling_L marked 16 inline comments as done.
Xiangling_L added a comment.

Addressed the comments;


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

https://reviews.llvm.org/D86790

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-alignment.c
  clang/test/CodeGenCXX/aix-alignment.cpp

Index: clang/test/CodeGenCXX/aix-alignment.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/aix-alignment.cpp
@@ -0,0 +1,30 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN: -emit-llvm -o - -x c++ %s | \
+// RUN:   FileCheck %s --check-prefixes=AIX,AIX32
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
+// RUN: -emit-llvm -o - %s -x c++| \
+// RUN:   FileCheck %s --check-prefixes=AIX,AIX64
+
+struct B {
+  double d;
+  ~B() {}
+};
+
+// AIX32: %call = call noalias nonnull i8* @_Znam(i32 8)
+// AIX64: %call = call noalias nonnull i8* @_Znam(i64 8)
+B *allocBp() { return new B[0]; }
+
+typedef struct D {
+  double d;
+  int i;
+
+  ~D(){};
+} D;
+
+// AIX: define void @_Z3foo1D(%struct.D* noalias sret align 4 %agg.result, %struct.D* %x)
+// AIX:   %1 = bitcast %struct.D* %agg.result to i8*
+// AIX:   %2 = bitcast %struct.D* %x to i8*
+// AIX32  call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 %2, i32 16, i1 false)
+// AIX64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %2, i64 16, i1 false)
+D foo(D x) { return x; }
Index: clang/test/CodeGen/aix-alignment.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-alignment.c
@@ -0,0 +1,41 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefixes=AIX,AIX32
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefixes=AIX,AIX64
+
+// AIX: @d = global double 0.00e+00, align 8
+double d;
+
+typedef struct {
+  double d;
+  int i;
+} StructDouble;
+
+// AIX: @d1 = global %struct.StructDouble zeroinitializer, align 8
+StructDouble d1;
+
+// AIX: double @retDouble(double %x)
+// AIX: %x.addr = alloca double, align 8
+// AIX: store double %x, double* %x.addr, align 8
+// AIX: load double, double* %x.addr, align 8
+// AIX: ret double %0
+double retDouble(double x) { return x; }
+
+// AIX32: define void @bar(%struct.StructDouble* noalias sret align 4 %agg.result, %struct.StructDouble* byval(%struct.StructDouble) align 4 %x)
+// AIX64: define void @bar(%struct.StructDouble* noalias sret align 4 %agg.result, %struct.StructDouble* byval(%struct.StructDouble) align 8 %x)
+// AIX: %0 = bitcast %struct.StructDouble* %agg.result to i8*
+// AIX: %1 = bitcast %struct.StructDouble* %x to i8*
+// AIX32:   call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %0, i8* align 4 %1, i32 16, i1 false)
+// AIX64:   call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 8 %1, i64 16, i1 false)
+StructDouble bar(StructDouble x) { return x; }
+
+// AIX:   define void @foo(double* %out, double* %in)
+// AIX32:   %0 = load double*, double** %in.addr, align 4
+// AIX64:   %0 = load double*, double** %in.addr, align 8
+// AIX: %1 = load double, double* %0, align 4
+// AIX: %mul = fmul double %1, 2.00e+00
+// AIX32:   %2 = load double*, double** %out.addr, align 4
+// AIX64:   %2 = load double*, double** %out.addr, align 8
+// AIX: store double %mul, double* %2, align 4
+void foo(double *out, double *in) { *out = *in * 2; }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4512,8 +4512,6 @@
   if (RetTy->isVoidType())
 return ABIArgInfo::getIgnore();
 
-  // TODO:  Evaluate if AIX power alignment rule would have an impact on the
-  // alignment here.
   if (isAggregateTypeForABI(RetTy))
 return getNaturalAlignIndirect(RetTy);
 
@@ -4530,8 +4528,6 @@
   if (Ty->isVectorType())
 llvm::report_fatal_error("vector type is not supported on AIX yet");
 
-  // TODO:  Evaluate if AIX power alignment rule would have an impact on the
-  // alignment here.
   if (isAggregateTypeForABI(Ty)) {
 // Records with non-trivial destructors/copy-constructors should not be
 // passed by value.
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2111,7 +2111,7 @@
   // The array cookie is a size_t; pad that up to the element alignment.
   // The cookie is actually right-justified in that space.
   return std::max(CharUnits::fromQu

[PATCH] D88084: [clang-format] Changed default styles BraceWrappping bool table to directly use variables

2020-09-22 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 added a comment.

In D88084#2287450 , @MyDeveloperDay 
wrote:

> I noticed the pre-merge tests failed!

Yeah I just noticed that too, not sure what's up but I'll check into it, and 
yeah that's a good idea about initializing some of these duplicate variables in 
the constructor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88084

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


[PATCH] D87956: [WIP][IR] add fn attr for no_stack_protector; prevent inlining ssp into no-ssp

2020-09-22 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

I obviously have a few todos left to resolve, but CC'ing reviewers now for 
general feedback.

One thing I'm unsure of; it felt curious to me that nothing was enforcing that 
these different levels of stack protection were mutually exclusive.  I've added 
that here, though I could fork that out to a separate patch.  I do think it 
would be better if this was a "key"="value" attribute, which would simplify 
ensuring these were mutually exclusive (I think).  I guess that would run afoul 
that previous IR would no longer be forward compatible; does LLVM have a policy 
on IR "breaks" like that?  I guess making the mutually exclusive technically is 
a subtle change in behavior...should I not do that?  Or if I do, should I 
document that somewhere else in addition?

Does the patch itself seem to be in good shape; and does the problem it solves 
make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87956

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


[PATCH] D87953: [xray] Function coverage groups

2020-09-22 Thread Ian Levesque via Phabricator via cfe-commits
ianlevesque added a comment.

This is ready for another review, I think I addressed everything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87953

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


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

The revert did not fix the PPC bots.  I suspect there is some kind of resource 
issue from the logs:

  msgget:: No space left on device
  sysmsg.c.tmp: 
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:15:
 int main(): Assertion `msgq != -1' failed.

http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt
http://lab.llvm.org:8011/builders/sanitizer-ppc64be-linux


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D87956: [WIP][IR] add fn attr for no_stack_protector; prevent inlining ssp into no-ssp

2020-09-22 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 293559.
nickdesaulniers added a comment.
Herald added a reviewer: whitequark.
Herald added a reviewer: aaron.ballman.

- add tests, make fn attrs mutually exclusive


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87956

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/stack-protector.c
  llvm/bindings/go/llvm/ir_test.go
  llvm/bindings/ocaml/llvm/llvm.ml
  llvm/docs/BitCodeFormat.rst
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/StackProtector.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/CodeGen/X86/stack-protector-2.ll
  llvm/test/Transforms/CodeExtractor/PartialInlineAttributes.ll
  llvm/test/Transforms/Inline/inline-stack-protector.ll
  llvm/test/Transforms/Inline/inline_ssp.ll
  llvm/test/Verifier/function-attribute-nossp-ssp-sspreq-sspstrong.ll
  llvm/utils/emacs/llvm-mode.el
  llvm/utils/kate/llvm.xml
  llvm/utils/llvm.grm
  llvm/utils/vim/syntax/llvm.vim
  llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml

Index: llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
===
--- llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
+++ llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
@@ -244,6 +244,7 @@
 \\bspir_func\\b|\
 \\bspir_kernel\\b|\
 \\bsret\\b|\
+\\bnossp\\b|\
 \\bssp\\b|\
 \\bsspreq\\b|\
 \\bsspstrong\\b|\
Index: llvm/utils/vim/syntax/llvm.vim
===
--- llvm/utils/vim/syntax/llvm.vim
+++ llvm/utils/vim/syntax/llvm.vim
@@ -147,6 +147,7 @@
   \ spir_func
   \ spir_kernel
   \ sret
+  \ nossp
   \ ssp
   \ sspreq
   \ sspstrong
Index: llvm/utils/llvm.grm
===
--- llvm/utils/llvm.grm
+++ llvm/utils/llvm.grm
@@ -168,6 +168,7 @@
  | noinline
  | alwaysinline
  | optsize
+ | nossp
  | ssp
  | sspreq
  | returns_twice
Index: llvm/utils/kate/llvm.xml
===
--- llvm/utils/kate/llvm.xml
+++ llvm/utils/kate/llvm.xml
@@ -92,6 +92,7 @@
optsize 
readnone 
readonly 
+   nossp 
ssp 
sspreq 
sspstrong 
Index: llvm/utils/emacs/llvm-mode.el
===
--- llvm/utils/emacs/llvm-mode.el
+++ llvm/utils/emacs/llvm-mode.el
@@ -26,7 +26,7 @@
  "inaccessiblemem_or_argmemonly" "inlinehint" "jumptable" "minsize" "naked" "nobuiltin"
  "noduplicate" "nofree" "noimplicitfloat" "noinline" "nonlazybind" "noredzone" "noreturn"
  "norecurse" "noundef" "nounwind" "optnone" "optsize" "readnone" "readonly" "returns_twice"
- "speculatable" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
+ "speculatable" "nossp" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
  "sanitize_thread" "sanitize_memory" "strictfp" "uwtable" "willreturn" "writeonly" "immarg") 'symbols) . font-lock-constant-face)
;; Variables
'("%[-a-zA-Z$._][-a-zA-Z$._0-9]*" . font-lock-variable-name-face)
Index: llvm/test/Verifier/function-attribute-nossp-ssp-sspreq-sspstrong.ll
===
--- /dev/null
+++ llvm/test/Verifier/function-attribute-nossp-ssp-sspreq-sspstrong.ll
@@ -0,0 +1,58 @@
+; RUN: not opt -verify -o - %s 2>&1 | FileCheck %s
+define void @test_1 () #1 { ret void }
+define void @test_2 () #2 { ret void }
+define void @test_3 () #3 { ret void }
+define void @test_4 () #4 { ret void }
+define void @test_5 () #5 { ret void }
+define void @test_6 () #6 { ret void }
+define void @test_7 () #7 { ret void }
+define void @test_8 () #8 { ret void }
+define void @test_9 () #9 { ret void }
+define void @test_10 () #10 { ret void }
+define void @test_11 () #10 { ret void }
+define void @test_12 () #10 { ret void }
+define void @test_13 () #10 { ret void }
+define void @test_14 () #10 { ret void }
+
+attributes #0 = { nossp }
+attributes #1 = { ssp }
+attributes #2 = { sspreq }
+attributes #3 = { sspstrong }
+
+attributes #4 = { nossp ssp }
+attributes #5 = { nossp sspreq }
+attributes #6 = { nossp sspstrong }
+
+attributes #7 = { ssp sspreq }
+attributes #8 = { ssp sspstrong }
+
+attributes #9 = { sspreq sspstrong }
+
+attributes #10 = {

[PATCH] D88114: [clang]Test ensuring -fembed-bitcode passed to cc1 captures pre-opt bitcode.

2020-09-22 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin created this revision.
mtrofin added reviewers: steven_wu, tejohnson.
Herald added a reviewer: alexshap.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
mtrofin requested review of this revision.

This is important to not regress because it allows us to capture 
pre-optimization
bitcode and options, and replay the full optimization pipeline.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88114

Files:
  clang/test/Frontend/embed-bitcode-noopt.ll


Index: clang/test/Frontend/embed-bitcode-noopt.ll
===
--- /dev/null
+++ clang/test/Frontend/embed-bitcode-noopt.ll
@@ -0,0 +1,22 @@
+; Ensure calling bypassing the driver with -fembed-bitcode embeds bitcode pre-
+; optimizations
+
+; RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o 
-fembed-bitcode=all
+; RUN: llvm-objcopy --dump-section=.llvmbc=%t.bc %t.o /dev/null
+
+; Also check that the .llvmcmd section captures the optimization options.
+; RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefix=CHECK-BC
+; RUN: llvm-objcopy --dump-section=.llvmcmd=- %t.o /dev/null | FileCheck %s 
--check-prefix=CHECK-CMD
+
+; CHECK-BC-LABEL: @foo
+; CHECK-BC-NEXT: call void @bar
+; CHECK-CMD: -O2
+
+define void @bar() {
+ret void
+}
+
+define void @foo() {
+  call void @bar()
+  ret void
+}


Index: clang/test/Frontend/embed-bitcode-noopt.ll
===
--- /dev/null
+++ clang/test/Frontend/embed-bitcode-noopt.ll
@@ -0,0 +1,22 @@
+; Ensure calling bypassing the driver with -fembed-bitcode embeds bitcode pre-
+; optimizations
+
+; RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -emit-obj %s -o %t.o -fembed-bitcode=all
+; RUN: llvm-objcopy --dump-section=.llvmbc=%t.bc %t.o /dev/null
+
+; Also check that the .llvmcmd section captures the optimization options.
+; RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefix=CHECK-BC
+; RUN: llvm-objcopy --dump-section=.llvmcmd=- %t.o /dev/null | FileCheck %s --check-prefix=CHECK-CMD
+
+; CHECK-BC-LABEL: @foo
+; CHECK-BC-NEXT: call void @bar
+; CHECK-CMD: -O2
+
+define void @bar() {
+ret void
+}
+
+define void @foo() {
+  call void @bar()
+  ret void
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D87808#2288186 , @dblaikie wrote:

> In D87808#2286664 , @rsmith wrote:
>
>> But I think this code should give the same outcome either way, because a 
>> class with any constructor other than a default/copy/move constructor must 
>> have a user-declared constructor of some kind, and so will never have an 
>> implicit default constructor.
>
> Hmm, trying to parse this. So if we're in the subtle case of having an 
> implicit default constructor (and no other (necessarily user-declared, as you 
> say) constructors) - if it's not been declared, then this function will 
> return false. If it has been declared, it'll return false... hmm, nope, then 
> it'll return true.

Hmm, yes, you're right, if the implicit default constructor would not be 
trivial, we could get different answers depending on whether we triggered its 
implicit declaration or not. And for:

  struct A { A(); };
  struct X { A a; };
  struct Y { A a; };
  void f(X x) {}
  void f(decltype(Y()) y) {}

... I see we get different debug information for `X` and `Y`, and it doesn't 
look like this patch will fix that, but querying 
`hasTrivialDefaultConstructor()` would.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2292-2300
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }

dblaikie wrote:
> rsmith wrote:
> > This looks pretty similar to:
> > 
> > ```
> > return RD->hasUserDeclaredConstructor() && 
> > !RD->hasTrivialDefaultConstructor();
> > ```
> > 
> > (other than its treatment of user-declared copy or move constructors), but 
> > I have to admit I don't really understand what the "at least one 
> > constructor and no trivial or constexpr constructors" rule aims to achieve, 
> > so it's hard to know if this is the right interpretation. The rule as 
> > written in the comment above is presumably not exactly right -- all classes 
> > have at least one constructor, and we're not excluding classes with trivial 
> > copy or move constructors, only those with trivial default constructors.
> > 
> > I wonder if the intent would be better captured by "at least one non-inline 
> > constructor" (that is, assuming all declared functions are defined, there 
> > is at least one translation unit in which a constructor is defined that can 
> > be used as a home for the class info).
> So the general goal is to detect any type where the construction of that type 
> somewhere must invoke a constructor that will be IR-generated.
> 
> Move and copy constructors are ignored because the assumption is they must be 
> moving/copying from some other object, which must've been constructed, 
> ultimately, by a non-move/copy constructor.
> 
> Ideally this would be usable even for inline ctors - even if the ctor calls 
> get optimized away later[^1], they'd still allow us to reduce the number of 
> places the type is emitted to only those places that call the ctor.
> 
> 
> 
> [^1] actually, the way that should work doesn't seem to be working right now 
> (eg:
> type.cpp
> ```
> struct t1 { t1() { } };
> void f1(void*);
> int main() {
>   f1(new t1());
> }
> ```
> type2.cpp
> ```
> struct t1 { t1() { } };
> void f1(void* v) {
>   delete (t1*)v;
> }
> ```
> build: `clang++ type.cpp -g -Xclang -fuse-ctor-homing type2.cpp && 
> llvm-dwarfdump a.out`
> -> definition of "t1" in the DWARF
> build with optimizations: `clang++ -O3 type.cpp -g -Xclang -fuse-ctor-homing 
> type2.cpp && llvm-dwarfdump a.out`
> -> missing definition of "t1"
> `type.cpp` is chosen as a home for `t1` because it calls a user-defined ctor, 
> but then that ctor gets optimized away and there's no other mention of `t1` 
> in `type.cpp` so the type is dropped entirely. This could happen even with a 
> non-inline definition - under LTO the ctor could get optimized away (though 
> this would be safe in FullLTO - the other references to `t1` would be made to 
> refer to the definition and keep it alive - but in ThinLTO the TU defining 
> the ctor might be imported and nothing else - leaving the type unused/dropped)
> To fix this we should put 'homed' types in the retained types list so they 
> are preserved even if all other code/references to the type are dropped. I 
> think I implemented this homed type pinning for explicit template 
> specialization definitions, because they have no code attachment point, so 
> similar logic could be used for ctor homing. (vtable homing /might/ benefit 
> from this with aggressive/whole program devirtualization? Not sure - harder 
> to actually optimize away all the references to a type, but possible maybe?)
Oh, I see, that's clever and very neat.

So the intent is to identify types for which we know that either no instances 
are ever created, or some constructor mu

[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-22 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

I'm also in favor, I think this is good direction ahead. It'd be nice if 
following issues were fixed -- in subsequent patches if you wish:

- Stage1 `ninja check-scudo` fails many tests for me, see F13037612: errors.txt 
.
- Stage2 `ninja check-llvm` fails after a while on high-core machines (4TB 
issue mentionned in comments above). Lowering `AllocatorSize` to 256GB would 
fix the issue on the short-term.
- Fix & test the "exclusive" mode (or just skip to scudo-standalone if it's too 
complicated).




Comment at: compiler-rt/lib/scudo/scudo_platform.h:67
 #if SANITIZER_CAN_USE_ALLOCATOR64
 # if defined(__aarch64__) && SANITIZER_ANDROID
 const uptr AllocatorSize = 0x40ULL;  // 256G.

`&& SANITIZER_WINDOWS` ?



Comment at: compiler-rt/test/scudo/lit.cfg.py:19
 # C & CXX flags.
 c_flags = ([config.target_cflags] +
+c_flags = ([config.target_cflags] +

Remove this line (duplicate).



Comment at: llvm/lib/Support/CMakeLists.txt:76
   if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}")
-message(FATAL_ERROR "Cannot find the path to `git clone` for the CRT 
allocator! (${LLVM_INTEGRATED_CRT_ALLOC}). Currently, rpmalloc, snmalloc and 
mimalloc are supported.")
+message(FATAL_ERROR "Cannot find the path to `git clone` for the CRT 
allocator! (${LLVM_INTEGRATED_CRT_ALLOC}). Currently, rpmalloc, snmalloc, 
mimalloc and scudo are supported.")
   endif()

Please also mention scudo in corresponding `LLVM_INTEGRATED_CRT_ALLOC` section 
in `llvm/docs/CMake.rst`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86694

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


[PATCH] D77229: [Analyzer] Avoid handling of LazyCompundVals in IteratorModeling

2020-09-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp:330-336
+SVal getReturnIterator(const CallEvent &Call) {
+  Optional RetValUnderConstr = Call.getReturnValueUnderConstruction();
+  if (RetValUnderConstr.hasValue())
+return *RetValUnderConstr;
+
+  return Call.getReturnValue();
+}

baloghadamsoftware wrote:
> NoQ wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > I still believe you have not addressed the problem while moving the 
> > > > functions from D81718 to this patch. The caller of this function has no 
> > > > way of knowing whether the return value is the prvalue of the iterator 
> > > > or the glvalue of the iterator.
> > > > 
> > > > Looks like most callers are safe because they expect the object of 
> > > > interest to also be already tracked. But it's quite possible that both 
> > > > are tracked, say:
> > > > 
> > > > ```lang=c++
> > > >   Container1 container1 = ...;
> > > >   Container2 container2 = { container1.begin() };
> > > >   container2.begin(); // ???
> > > > ```
> > > > 
> > > > Suppose `Container1::iterator` is implemented as an object and 
> > > > `Container2::iterator` is implemented as a pointer. In this case 
> > > > `getIteratorPosition(getReturnIterator())` would yield the position of 
> > > > `container1.begin()` whereas the correct answer is the position of 
> > > > `container2.begin()`.
> > > > 
> > > > This problem may seem artificial but it is trivial to avoid if you 
> > > > simply stop defending your convoluted solution of looking at value 
> > > > classes instead of AST types.
> > > Ugh, the problem is much worse. D82185 is entirely broken for the exact 
> > > reason i described above and you only didn't notice it because you wrote 
> > > almost no tests.
> > > 
> > > Consider the test you've added in D82185:
> > > 
> > > ```lang=c++
> > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > >   auto i = c.begin();
> > > 
> > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > expected-warning{{TRUE}}
> > > }
> > > ```
> > > 
> > > It breaks very easily if you modify it slightly:
> > > ```lang=c++
> > > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> > >   auto i = c.begin();
> > >   ++i; // <==
> > > 
> > >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > > Says FALSE!
> > > }
> > > ```
> > > The iterator obviously still points to the same container, so why does 
> > > the test fail? Because you're tracking the wrong iterator: you treated 
> > > your `&SymRegion{conj_$3}` as a glvalue whereas you should have treated 
> > > it as a prvalue. In other words, your checker thinks that 
> > > `&SymRegion{conj_$3}` is the location of an iterator object rather than 
> > > the iterator itself, and after you increment the pointer it thinks that 
> > > it's a completely unrelated iterator.
> > > 
> > > There's a separate concern about why does it say `FALSE` (should be 
> > > `UNKNOWN`) but you get the point.
> > The better way to test D82185 would be to make all existing tests with 
> > iterator objects pass with iterator pointers as well. Like, make existing 
> > container mocks use either iterator objects or iterator pointers depending 
> > on a macro and make two run-lines in each test file, one with `-D` and one 
> > without it. Most of the old tests should have worked out of the box if you 
> > did it right; the few that don't pass would be hidden under #ifdef for 
> > future investigation.
> Thank you for your review and especially for this tip! It is really a good 
> idea. I changed it now and it indeed shows the problem you reported. It seems 
> that my checker mixes up the region of the pointer-typed variable (`&i` and 
> `&j`) with the region they point to (`&SymRegion{reg_$1 SymRegion{reg_$0 & v>}._start>}` for `i` before the 
> increment and `&Element{SymRegion{reg_$1 std::vector & v>}._start>},1 S64b,int}` for both `i` and `j` after the 
> increment).
> 
> What I fail to see and I am asking you help in it is that the relation 
> between this problem and the `getReturnIterator()` function. This function 
> retrieves the object from the construction context if there is one, but for 
> plain pointers there is never one. Thus this function is always 
> `Call.getReturnValue()` like before this patch.
> I am asking you help

I spent way more time on that already than i find reasonable. Please figure 
this out on your own by fixing the bug.


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

https://reviews.llvm.org/D77229

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


[clang] cf11238 - [ThinLTO] Option to bypass function importing.

2020-09-22 Thread Mircea Trofin via cfe-commits

Author: Mircea Trofin
Date: 2020-09-22T13:12:11-07:00
New Revision: cf112382ddd0d717edf0b8a3e5b061de925258e9

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

LOG: [ThinLTO] Option to bypass function importing.

This completes the circle, complementing -lto-embed-bitcode
(specifically, post-merge-pre-opt). Using -thinlto-assume-merged skips
function importing. The index file is still needed for the other data it
contains.

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

Added: 


Modified: 
clang/include/clang/CodeGen/BackendUtil.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/test/CodeGen/thinlto_embed_bitcode.ll
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/LTO/LTOBackend.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/BackendUtil.h 
b/clang/include/clang/CodeGen/BackendUtil.h
index 01b1f5bbd6ee..43de07cc145b 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -45,11 +45,6 @@ namespace clang {
 
   void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
 llvm::MemoryBufferRef Buf);
-
-  llvm::Expected
-  FindThinLTOModule(llvm::MemoryBufferRef MBRef);
-  llvm::BitcodeModule *
-  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 01f7e239f790..44f0434f2021 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1497,29 +1497,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 DwoOS->keep();
 }
 
-Expected clang::FindThinLTOModule(MemoryBufferRef MBRef) {
-  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
-  if (!BMsOrErr)
-return BMsOrErr.takeError();
-
-  // The bitcode file may contain multiple modules, we want the one that is
-  // marked as being the ThinLTO module.
-  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
-return *Bm;
-
-  return make_error("Could not find module summary",
- inconvertibleErrorCode());
-}
-
-BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
-  for (BitcodeModule &BM : BMs) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return &BM;
-  }
-  return nullptr;
-}
-
 static void runThinLTOBackend(
 DiagnosticsEngine &Diags, ModuleSummaryIndex *CombinedIndex, Module *M,
 const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts,
@@ -1536,46 +1513,12 @@ static void runThinLTOBackend(
   // we should only invoke this using the individual indexes written out
   // via a WriteIndexesThinBackend.
   FunctionImporter::ImportMapTy ImportList;
-  for (auto &GlobalList : *CombinedIndex) {
-// Ignore entries for undefined references.
-if (GlobalList.second.SummaryList.empty())
-  continue;
-
-auto GUID = GlobalList.first;
-for (auto &Summary : GlobalList.second.SummaryList) {
-  // Skip the summaries for the importing module. These are included to
-  // e.g. record required linkage changes.
-  if (Summary->modulePath() == M->getModuleIdentifier())
-continue;
-  // Add an entry to provoke importing by thinBackend.
-  ImportList[Summary->modulePath()].insert(GUID);
-}
-  }
-
   std::vector> OwnedImports;
   MapVector ModuleMap;
+  if (!lto::loadReferencedModules(*M, *CombinedIndex, ImportList, ModuleMap,
+  OwnedImports))
+return;
 
-  for (auto &I : ImportList) {
-ErrorOr> MBOrErr =
-llvm::MemoryBuffer::getFile(I.first());
-if (!MBOrErr) {
-  errs() << "Error loading imported file '" << I.first()
- << "': " << MBOrErr.getError().message() << "\n";
-  return;
-}
-
-Expected BMOrErr = FindThinLTOModule(**MBOrErr);
-if (!BMOrErr) {
-  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {
-errs() << "Error loading imported file '" << I.first()
-   << "': " << EIB.message() << '\n';
-  });
-  return;
-}
-ModuleMap.insert({I.first(), *BMOrErr});
-
-OwnedImports.push_back(std::move(*MBOrErr));
-  }
   auto AddStream = [&](size_t Task) {
 return std::make_unique(std::move(OS));
   };

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index eda4beff78b7..5ea2fc23ee11 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -35,6 +35,7 @@
 #include "llvm/IR/LLVMRemarkStreamer.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IRReader/IRReader.h"
+#include "llvm/LTO/LTOBackend.h"
 #include "llvm/Linker/Linker.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -1066,7 +1067,

[PATCH] D87949: [ThinLTO] Option to bypass function importing.

2020-09-22 Thread Mircea Trofin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf112382ddd0: [ThinLTO] Option to bypass function importing. 
(authored by mtrofin).

Changed prior to commit:
  https://reviews.llvm.org/D87949?vs=293506&id=293555#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87949

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_embed_bitcode.ll
  llvm/include/llvm/LTO/LTOBackend.h
  llvm/lib/LTO/LTOBackend.cpp

Index: llvm/lib/LTO/LTOBackend.cpp
===
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -69,6 +69,11 @@
   "Embed post merge, but before optimizations")),
 cl::desc("Embed LLVM bitcode in object files produced by LTO"));
 
+static cl::opt ThinLTOAssumeMerged(
+"thinlto-assume-merged", cl::init(false),
+cl::desc("Assume the input has already undergone ThinLTO function "
+ "importing and the other pre-optimization pipeline changes."));
+
 LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
   errs() << "failed to open " << Path << ": " << Msg << '\n';
   errs().flush();
@@ -583,6 +588,21 @@
   if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
+  auto OptimizeAndCodegen =
+  [&](Module &Mod, TargetMachine *TM,
+  std::unique_ptr DiagnosticOutputFile) {
+if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
+ /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
+ CmdArgs))
+  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+
+codegen(Conf, TM, AddStream, Task, Mod, CombinedIndex);
+return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  };
+
+  if (ThinLTOAssumeMerged)
+return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+
   // When linking an ELF shared object, dso_local should be dropped. We
   // conservatively do this for -fpic.
   bool ClearDSOLocalOnDeclarations =
@@ -623,11 +643,81 @@
   if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
-  if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
-   /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
-   CmdArgs))
-return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+}
+
+BitcodeModule *lto::findThinLTOModule(MutableArrayRef BMs) {
+  if (ThinLTOAssumeMerged && BMs.size() == 1)
+return BMs.begin();
 
-  codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);
-  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
 }
+
+Expected lto::findThinLTOModule(MemoryBufferRef MBRef) {
+  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+  if (!BMsOrErr)
+return BMsOrErr.takeError();
+
+  // The bitcode file may contain multiple modules, we want the one that is
+  // marked as being the ThinLTO module.
+  if (const BitcodeModule *Bm = lto::findThinLTOModule(*BMsOrErr))
+return *Bm;
+
+  return make_error("Could not find module summary",
+ inconvertibleErrorCode());
+}
+
+bool lto::loadReferencedModules(
+const Module &M, const ModuleSummaryIndex &CombinedIndex,
+FunctionImporter::ImportMapTy &ImportList,
+MapVector &ModuleMap,
+std::vector>
+&OwnedImportsLifetimeManager) {
+  if (ThinLTOAssumeMerged)
+return true;
+  // We can simply import the values mentioned in the combined index, since
+  // we should only invoke this using the individual indexes written out
+  // via a WriteIndexesThinBackend.
+  for (const auto &GlobalList : CombinedIndex) {
+// Ignore entries for undefined references.
+if (GlobalList.second.SummaryList.empty())
+  continue;
+
+auto GUID = GlobalList.first;
+for (const auto &Summary : GlobalList.second.SummaryList) {
+  // Skip the summaries for the importing module. These are included to
+  // e.g. record required linkage changes.
+  if (Summary->modulePath() == M.getModuleIdentifier())
+continue;
+  // Add an entry to provoke importing by thinBackend.
+  ImportList[Summary->modulePath()].insert(GUID);
+}
+  }
+
+  for (auto &I : ImportList) {
+ErrorOr> MBOrErr =
+llvm::MemoryBuffer::getFile(I.first());
+if (!MBOrErr) {
+  errs() << "Error loading imported file '" << I.first()
+

[PATCH] D87949: [ThinLTO] Option to bypass function importing.

2020-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm with comment typo fix




Comment at: llvm/include/llvm/LTO/LTOBackend.h:59
+
+/// Distributed ThinlTO: load the referenced modules, keeping their buffers
+/// alive in the provided OwnedImportLifetimeManager. Returns false if the

s/lTO/LTO/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87949

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


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D87921#2288395 , @Conanap wrote:

> It looks like this commit is causing a few failures on nearly all PPC bots 
> and a sanitizer bot; would it be possible to revert this commit for now until 
> the issue is resolved?

It would be helpful if you provide a link. (My confidence level with this patch 
is still high and I think we really need good reasons to revert it. Though it 
has been reverted now.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[clang] b89059a - Revert "The wrong placement of add pass with optimizations led to -funique-internal-linkage-names being disabled."

2020-09-22 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-09-22T12:32:43-07:00
New Revision: b89059a31347dd09b55a96b99b3dbe38d7749908

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

LOG: Revert "The wrong placement of add pass with optimizations led to 
-funique-internal-linkage-names being disabled."

This reverts commit 6950db36d33d85d18e3241ab6c87494c05ebe0fb.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 07c476218bb0..01f7e239f790 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,6 +1262,12 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (CodeGenOpts.UniqueInternalLinkageNames) {
+MPM.addPass(UniqueInternalLinkageNamesPass());
+  }
+
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1357,6 +1363,12 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (CodeGenOpts.UniqueInternalLinkageNames) {
+MPM.addPass(UniqueInternalLinkageNamesPass());
+  }
+
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1373,11 +1385,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   }
 }
 
-// Add UniqueInternalLinkageNames Pass which renames internal linkage
-// symbols with unique names.
-if (CodeGenOpts.UniqueInternalLinkageNames)
-  MPM.addPass(UniqueInternalLinkageNamesPass());
-
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 6bef338b5f1d..271d30e4e6fb 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,10 +1,8 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
 
 static int glob;
 static int foo() {
@@ -61,7 +59,3 @@ int mver_call() {
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
-// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
-// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}



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


[PATCH] D87946: [OpenMP] Add Location Fields to Libomptarget Runtime for Debugging

2020-09-22 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 293550.
jhuber6 added a comment.

Updated runtime library to have legacy calls into the new functions with source 
location information. Because the library interface requires C function naming 
this required adding a suffix to all the functions clang generates. Now 
__tgt_*_mapper becomes __tgt_*_mapper_loc. It's not a great solution but it's 
required if we want to keep this backwards compatible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87946

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/capturing_in_templates.cpp
  clang/test/OpenMP/declare_target_link_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
  clang/test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
  clang/test/OpenMP/openmp_offload_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen.cpp
  clang/test/OpenMP/target_device_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  clang/test/OpenMP/target_map_codegen_00.cpp
  clang/test/OpenMP/target_map_codegen_01.cpp
  clang/test/OpenMP/target_map_codegen_02.cpp
  clang/test/OpenMP/target_map_codegen_03.cpp
  clang/test/OpenMP/target_map_codegen_04.cpp
  clang/test/OpenMP/target_map_codegen_05.cpp
  clang/test/OpenMP/target_map_codegen_06.cpp
  clang/test/OpenMP/target_map_codegen_07.cpp
  clang/test/OpenMP/target_map_codegen_08.cpp
  clang/test/OpenMP/target_map_codegen_09.cpp
  clang/test/OpenMP/target_map_codegen_10.cpp
  clang/test/OpenMP/target_map_codegen_11.cpp
  clang/test/OpenMP/target_map_codegen_12.cpp
  clang/test/OpenMP/target_map_codegen_13.cpp
  clang/test/OpenMP/target_map_codegen_14.cpp
  clang/test/OpenMP/target_map_codegen_15.cpp
  clang/test/OpenMP/target_map_codegen_16.cpp
  clang/test/OpenMP/target_map_codegen_17.cpp
  clang/test/OpenMP/target_map_codegen_18.inc
  clang/test/OpenMP/target_map_codegen_19.cpp
  clang/test/OpenMP/target_map_codegen_20.cpp
  clang/test/OpenMP/target_map_codegen_21.cpp
  clang/test/OpenMP/target_map_codegen_22.cpp
  clang/test/OpenMP/target_map_codegen_23.cpp
  clang/test/OpenMP/target_map_codegen_24.cpp
  clang/test/OpenMP/target_map_codegen_25.cpp
  clang/test/OpenMP/target_map_codegen_26.cpp
  clang/test/OpenMP/target_map_codegen_27.cpp
  clang/test/OpenMP/target_map_codegen_28.cpp
  clang/test/OpenMP/target_map_codegen_29.cpp
  clang/test/OpenMP/target_map_codegen_30.cpp
  clang/test/OpenMP/target_map_codegen_31.cpp
  clang/test/OpenMP/target_map_codegen_32.cpp
  clang/test/OpenMP/target_map_codegen_33.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_sim

Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Sriraman Tallam via cfe-commits
On Tue, Sep 22, 2020 at 11:28 AM Albion Fung via Phabricator
 wrote:
>
> Conanap added a comment.
>
> It looks like this commit is causing a few failures on nearly all PPC bots 
> and a sanitizer bot; would it be possible to revert this commit for now until 
> the issue is resolved?

Ya sure, I can revert this. I do not have access to a PPC machine and
I could use some help to get it back in at an appropriate time.

Thanks
Sri

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D87921/new/
>
> https://reviews.llvm.org/D87921
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

2020-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

@rsmith this patch should be ready for another round of review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84637

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


[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

2020-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 293538.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84637

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/invalid-constructor-init.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp

Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -53,14 +53,12 @@
 return 2;
   }
   static constexpr int foo2() {
-return AA::getB(); // expected-error{{no matching function for call to 'getB'}} \
-  // expected-note {{subexpression not valid in a constant expression}}
+return AA::getB(); // expected-error{{no matching function for call to 'getB'}}
   }
 };
 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic?
 constexpr auto x2 = AA::foo2(); // expected-error {{be initialized by a constant expression}} \
- // expected-note {{in instantiation of member function}} \
- // expected-note {{in call to}}
+ // expected-note {{in instantiation of member function}}
 }
 
 // verify no assertion failure on violating value category.
Index: clang/test/SemaCXX/invalid-constructor-init.cpp
===
--- clang/test/SemaCXX/invalid-constructor-init.cpp
+++ clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -2,7 +2,7 @@
 
 struct X {
   int Y;
-  constexpr X() // expected-error {{constexpr constructor never produces}}
+  constexpr X()
   : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
 };
 // no crash on evaluating the constexpr ctor.
@@ -10,12 +10,12 @@
 
 struct X2 {
   int Y = foo();// expected-error {{use of undeclared identifier 'foo'}}
-  constexpr X2() {} // expected-error {{constexpr constructor never produces a constant expression}}
+  constexpr X2() {}
 };
 
 struct X3 {
   int Y;
-  constexpr X3() // expected-error {{constexpr constructor never produces}}
+  constexpr X3()
   : Y(({foo();})) {} // expected-error {{use of undeclared identifier 'foo'}}
 };
 
Index: clang/test/SemaCXX/enable_if.cpp
===
--- clang/test/SemaCXX/enable_if.cpp
+++ clang/test/SemaCXX/enable_if.cpp
@@ -414,8 +414,8 @@
 
 template  constexpr int callTemplated() { return templated(); }
 
-constexpr int B = 10 + // expected-error {{initialized by a constant expression}}
-callTemplated<0>(); // expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}} expected-note {{in call to 'callTemplated()'}} expected-note@-3 {{subexpression not valid in a constant expression}}
+constexpr int B = 10 +// expected-error {{initialized by a constant expression}}
+  callTemplated<0>(); // expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
 
Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify
+
+// verify no value-dependent-assertion crash in constexpr function body.
+class Foo {
+  constexpr Foo() {
+while (invalid()) {} // expected-error {{use of undeclared identifier}}
+if (invalid()) {} // expected-error {{use of undeclared identifier}}
+  }
+};
+
+constexpr void test1() {
+  while (invalid()) {} // expected-error {{use of undeclared identifier}}
+  if (invalid()) {} // expected-error {{use of undeclared identifier}}
+}
+
+struct A {
+  int *p = new int(invalid()); // expected-error {{use of undeclared identifier}}
+  constexpr ~A() { delete p; }
+};
+constexpr int test2() {
+  A a;
+  return 1;
+}
+
+constexpr int test3() {
+  return invalid(); // expected-error {{use of undeclared identifier}}
+}
+
+constexpr int test4() {
+  if (invalid()) // expected-error {{use of undeclared identifier}}
+return 1;
+  else
+return 0;
+}
+
+constexpr int test5() {
+  for (;; a++); // expected-error {{use of undeclared identifier}}
+  return 1;
+}
+
+constexpr int test6() {
+  int n = 0;
+  switch (n) {
+for (;; a++) { // expected-error {{use of undeclared identifier}}
+case 0:;
+}
+  }
+  return 0;
+}
Index: clang/lib/AST/ExprConstant.cpp
===

[PATCH] D83296: [clang-format] Add a MacroExpander.

2020-09-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Ship it!




Comment at: clang/lib/Format/FormatToken.h:177
+/// EndOfExpansion:   0  0 0   21 0 1
+struct MacroContext {
+  MacroContext(MacroRole Role) : Role(Role) {}

klimek wrote:
> sammccall wrote:
> > "context" is often pretty vague - "MacroSource" isn't a brilliant name but 
> > at least seems to hint at the direction (that the FormatToken is the 
> > expanded token and the MacroSource gives information about what it was 
> > expanded from)
> > 
> > I don't feel strongly about this though, up to you.
> MacroSource sounds like it is about the macro source (i.e. the tokens written 
> for the macro).
> I'd be happy to rename to MacroExpansion or MacroExpansionInfo or somesuch if 
> you think that helps?
Oops, accidental "source" pun. MacroOrigin would be another name in the same 
spirit. But MacroExpansion sounds good to me, too.



Comment at: clang/lib/Format/MacroExpander.cpp:190
+  return true;
+for (const auto &Arg : Args[I->getValue()]) {
+  // A token can be part of a macro argument at multiple levels.

nit: this is confusingly a const reference to a non-const pointer... `auto *` 
or `FormatToken *`?



Comment at: clang/lib/Format/MacroExpander.cpp:142
+  auto Definition = Parser.parse();
+  Definitions[Definition.Name] = Definition;
+}

klimek wrote:
> sammccall wrote:
> > nit: this is a copy for what seems like no reason - move `Parser.parse()` 
> > inline to this line?
> Reason is that we need the name.
oops, right.
std::move() the RHS? (mostly I just find the copies surprising, so draws 
attention)



Comment at: clang/unittests/Format/MacroExpanderTest.cpp:183
+  EXPECT_ATTRIBUTES(Result, Attributes);
+}
+

may want a test that uses of an arg after the first are not expanded, because 
that "guards" a bunch of nasty potential bugs



Comment at: clang/unittests/Format/TestLexer.h:15
+
+#ifndef CLANG_UNITTESTS_FORMAT_TEST_LEXER_H
+#define CLANG_UNITTESTS_FORMAT_TEST_LEXER_H

I guess clang-tidy wants ..._TESTLEXER_H here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83296

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


[PATCH] D86895: [Modules] Add stats to measure performance of building and loading modules.

2020-09-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D86895#2288262 , @tschuett wrote:

> Where is the test?

`ALWAYS_ENABLED_STATISTIC` has its own unit tests. And tests that use added 
stats are in another revision in the stack D86896 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86895

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


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap added a comment.

It looks like this commit is causing a few failures on nearly all PPC bots and 
a sanitizer bot; would it be possible to revert this commit for now until the 
issue is resolved?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 293537.
tianshilei1992 added a comment.

Refined the case `declare_mapper_codegen.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
@@ -66,7 +66,11 @@
 #ifndef HEADER
 #define HEADER
 
-// CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CHECK-DAG: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %{{[^,]+}}, %{{[^,]+}} }
+// CHECK-32-DAG: [[KMP_PRIVATES_T]] = type { [3 x i64], [3 x i8*], [3 x i8*], [3 x i8*], i16 }
+// CHECK-64-DAG: [[KMP_PRIVATES_T]] = type { [3 x i8*], [3 x i8*], [3 x i64], [3 x i8*], i16 }
 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
 // CHECK-DAG: [[DEF_LOC:@.+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
 
@@ -132,33 +136,26 @@
   double cn[5][n];
   TT d;
 
-  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target_teams_nowait_mapper(i64 -1, i8* @{{[^,]+}}, i32 3, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[SIZET]], i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[MAPT]], i32 0, i32 0), i8** null, i32 {{[^,]+}}, i32 {{[^)]+}})
-  // CHECK-DAG:   [[BP]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[P]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]]
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX0]]
-  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]]
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR1]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR2]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR2]]
-  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
-  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
-  // CHECK:   [[FAIL]]
-  // CHECK:   call void [[HVT0:@.+]](i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^)]+}})
-  // CHECK-NEXT:  br label %[[END]]
-  // CHECK:   [[END]]
+  // CHECK-DAG: call i32 @__kmpc_omp_task([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i8* [[TASK:%.+]])
+  // CHECK-32-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i32 84, i32 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-64-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 144, i64 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-DAG: [[TASK_CAST:%.+]] = bitcast i8* [[TASK]] to [[KMP_

[clang] 16ca711 - [clang] Fix a typo-correction crash

2020-09-22 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-09-22T20:21:21+02:00
New Revision: 16ca711803300bd966acf8759876a1ccd478c616

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

LOG: [clang] Fix a typo-correction crash

We leave a dangling TypoExpr when typo-correction is performed
successfully in `checkArgsForPlaceholders`, which leads a crash in the
later TypoCorrection.

This code was added in 
https://github.com/llvm/llvm-project/commit/1586782767938df3a20f7abc4d8335c48b100bc4,
and it didn't seem to have enough test coverage.
The fix is to remove this part, and no failuer tests.

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/typo-correction-crash.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 736a6c166eb3..9cd5a35660d9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6068,8 +6068,6 @@ static bool checkArgsForPlaceholders(Sema &S, 
MultiExprArg args) {
   ExprResult result = S.CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
-} else if (hasInvalid) {
-  (void)S.CorrectDelayedTyposInExpr(args[i]);
 }
   }
   return hasInvalid;

diff  --git a/clang/test/SemaCXX/typo-correction-crash.cpp 
b/clang/test/SemaCXX/typo-correction-crash.cpp
index fce10800f2b6..10c0c11aaa6b 100644
--- a/clang/test/SemaCXX/typo-correction-crash.cpp
+++ b/clang/test/SemaCXX/typo-correction-crash.cpp
@@ -32,3 +32,12 @@ FooRecord::NestedNamespace::type x; // expected-error {{no 
member named 'NestedN
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared 
identifier 'n'}}
 
 void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error 
{{undeclared identifier '_test_'}}
+
+namespace NoCrash {
+class S {
+  void Function(int a) {
+unknown1(unknown2, Function, unknown3); // expected-error 2{{use of 
undeclared identifier}} \
+   expected-error {{reference to 
non-static member function must be called}}
+  }
+};
+}



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


[PATCH] D87815: [clang] Fix a typo-correction crash

2020-09-22 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16ca71180330: [clang] Fix a typo-correction crash (authored 
by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87815

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/typo-correction-crash.cpp


Index: clang/test/SemaCXX/typo-correction-crash.cpp
===
--- clang/test/SemaCXX/typo-correction-crash.cpp
+++ clang/test/SemaCXX/typo-correction-crash.cpp
@@ -32,3 +32,12 @@
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared 
identifier 'n'}}
 
 void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error 
{{undeclared identifier '_test_'}}
+
+namespace NoCrash {
+class S {
+  void Function(int a) {
+unknown1(unknown2, Function, unknown3); // expected-error 2{{use of 
undeclared identifier}} \
+   expected-error {{reference to 
non-static member function must be called}}
+  }
+};
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6068,8 +6068,6 @@
   ExprResult result = S.CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
-} else if (hasInvalid) {
-  (void)S.CorrectDelayedTyposInExpr(args[i]);
 }
   }
   return hasInvalid;


Index: clang/test/SemaCXX/typo-correction-crash.cpp
===
--- clang/test/SemaCXX/typo-correction-crash.cpp
+++ clang/test/SemaCXX/typo-correction-crash.cpp
@@ -32,3 +32,12 @@
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared identifier 'n'}}
 
 void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error {{undeclared identifier '_test_'}}
+
+namespace NoCrash {
+class S {
+  void Function(int a) {
+unknown1(unknown2, Function, unknown3); // expected-error 2{{use of undeclared identifier}} \
+   expected-error {{reference to non-static member function must be called}}
+  }
+};
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6068,8 +6068,6 @@
   ExprResult result = S.CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
-} else if (hasInvalid) {
-  (void)S.CorrectDelayedTyposInExpr(args[i]);
 }
   }
   return hasInvalid;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir added a comment.

In D87921#2288096 , @morehouse wrote:

> Thanks for looking.  Indeed, it looks like an issue with the disk being full 
> on the bot.

Hi, I checked the disk is not full on the bot. I am not sure what is going on 
here but its definitely not a disk space issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[PATCH] D83004: [UpdateCCTestChecks] Include generated functions if asked

2020-09-22 Thread dmajor via Phabricator via cfe-commits
dmajor added a comment.

The expensive-checks bots have been red for several days. Could you please take 
a look or revert?

riscv_generated_funcs.test:

  *** Bad machine code: MBB exits via unconditional fall-through but ends with 
a barrier instruction! ***
  - function:check_boundaries
  - basic block: %bb.4  (0x5653e22035b8)
  LLVM ERROR: Found 1 machine code errors.

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-ubuntu/builds/9171/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3Ariscv_generated_funcs.test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83004

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


[clang] 8a64689 - [Analyzer][WebKit] UncountedLocalVarsChecker

2020-09-22 Thread Jan Korous via cfe-commits

Author: Jan Korous
Date: 2020-09-22T11:05:04-07:00
New Revision: 8a64689e264ce039e4fb0a09c3e136a1c8451838

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

LOG: [Analyzer][WebKit] UncountedLocalVarsChecker

Differential Review: https://reviews.llvm.org/D83259

Added: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 9fb6782cf5a5..dbbd49085dac 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2538,6 +2538,53 @@ We also define a set of safe transformations which if 
passed a safe value as an
 - casts
 - unary operators like ``&`` or ``*``
 
+alpha.webkit.UncountedLocalVarsChecker
+""
+The goal of this rule is to make sure that any uncounted local variable is 
backed by a ref-counted object with lifetime that is strictly larger than the 
scope of the uncounted local variable. To be on the safe side we require the 
scope of an uncounted variable to be embedded in the scope of ref-counted 
object that backs it.
+
+These are examples of cases that we consider safe:
+
+  .. code-block:: cpp
+void foo1() {
+  RefPtr counted;
+  // The scope of uncounted is EMBEDDED in the scope of counted.
+  {
+RefCountable* uncounted = counted.get(); // ok
+  }
+}
+
+void foo2(RefPtr counted_param) {
+  RefCountable* uncounted = counted_param.get(); // ok
+}
+
+void FooClass::foo_method() {
+  RefCountable* uncounted = this; // ok
+}
+
+Here are some examples of situations that we warn about as they *might* be 
potentially unsafe. The logic is that either we're able to guarantee that an 
argument is safe or it's considered if not a bug then bug-prone.
+
+  .. code-block:: cpp
+
+void foo1() {
+  RefCountable* uncounted = new RefCountable; // warn
+}
+
+RefCountable* global_uncounted;
+void foo2() {
+  RefCountable* uncounted = global_uncounted; // warn
+}
+
+void foo3() {
+  RefPtr counted;
+  // The scope of uncounted is not EMBEDDED in the scope of counted.
+  RefCountable* uncounted = counted.get(); // warn
+}
+
+We don't warn about these cases - we don't consider them necessarily safe but 
since they are very common and usually safe we'd introduce a lot of false 
positives otherwise:
+- variable defined in condition part of an ```if``` statement
+- variable defined in init statement condition of a ```for``` statement
+
+For the time being we also don't warn about uninitialized uncounted local 
variables.
 
 Debug Checkers
 ---

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 3540fe5fe55c..444b00d73f0b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1668,4 +1668,8 @@ def UncountedCallArgsChecker : 
Checker<"UncountedCallArgsChecker">,
   HelpText<"Check uncounted call arguments.">,
   Documentation;
 
+def UncountedLocalVarsChecker : Checker<"UncountedLocalVarsChecker">,
+  HelpText<"Check uncounted local variables.">,
+  Documentation;
+
 } // end alpha.webkit

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 31f971e33cb2..eb4f30137732 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -128,6 +128,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
   WebKit/UncountedCallArgsChecker.cpp
   WebKit/UncountedLambdaCapturesChecker.cpp
+  WebKit/UncountedLocalVarsChecker.cpp
 
   LINK_LIBS
   clangAST

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
new file mode 100644
index ..101aba732aea
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -0,0 +1,250 @@
+//===- UncountedLocalVarsChecker.cpp -*- C++ 
-*-==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ASTUtils.h"
+#inc

[PATCH] D87949: [ThinLTO] Option to bypass function importing.

2020-09-22 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin updated this revision to Diff 293506.
mtrofin added a comment.

clang tidy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87949

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_embed_bitcode.ll
  llvm/include/llvm/LTO/LTOBackend.h
  llvm/lib/LTO/LTOBackend.cpp

Index: llvm/lib/LTO/LTOBackend.cpp
===
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -69,6 +69,11 @@
   "Embed post merge, but before optimizations")),
 cl::desc("Embed LLVM bitcode in object files produced by LTO"));
 
+static cl::opt ThinLTOAssumeMerged(
+"thinlto-assume-merged", cl::init(false),
+cl::desc("Assume the input has already undergone ThinLTO function "
+ "importing and the other pre-optimization pipeline changes."));
+
 LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
   errs() << "failed to open " << Path << ": " << Msg << '\n';
   errs().flush();
@@ -583,6 +588,21 @@
   if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
+  auto OptimizeAndCodegen =
+  [&](Module &Mod, TargetMachine *TM,
+  std::unique_ptr DiagnosticOutputFile) {
+if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
+ /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
+ CmdArgs))
+  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+
+codegen(Conf, TM, AddStream, Task, Mod, CombinedIndex);
+return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  };
+
+  if (ThinLTOAssumeMerged)
+return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+
   // When linking an ELF shared object, dso_local should be dropped. We
   // conservatively do this for -fpic.
   bool ClearDSOLocalOnDeclarations =
@@ -623,11 +643,81 @@
   if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
-  if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
-   /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
-   CmdArgs))
-return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+}
+
+BitcodeModule *lto::findThinLTOModule(MutableArrayRef BMs) {
+  if (ThinLTOAssumeMerged && BMs.size() == 1)
+return BMs.begin();
 
-  codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);
-  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
 }
+
+Expected lto::findThinLTOModule(MemoryBufferRef MBRef) {
+  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+  if (!BMsOrErr)
+return BMsOrErr.takeError();
+
+  // The bitcode file may contain multiple modules, we want the one that is
+  // marked as being the ThinLTO module.
+  if (const BitcodeModule *Bm = lto::findThinLTOModule(*BMsOrErr))
+return *Bm;
+
+  return make_error("Could not find module summary",
+ inconvertibleErrorCode());
+}
+
+bool lto::loadReferencedModules(
+const Module &M, const ModuleSummaryIndex &CombinedIndex,
+FunctionImporter::ImportMapTy &ImportList,
+MapVector &ModuleMap,
+std::vector>
+&OwnedImportsLifetimeManager) {
+  if (ThinLTOAssumeMerged)
+return true;
+  // We can simply import the values mentioned in the combined index, since
+  // we should only invoke this using the individual indexes written out
+  // via a WriteIndexesThinBackend.
+  for (const auto &GlobalList : CombinedIndex) {
+// Ignore entries for undefined references.
+if (GlobalList.second.SummaryList.empty())
+  continue;
+
+auto GUID = GlobalList.first;
+for (const auto &Summary : GlobalList.second.SummaryList) {
+  // Skip the summaries for the importing module. These are included to
+  // e.g. record required linkage changes.
+  if (Summary->modulePath() == M.getModuleIdentifier())
+continue;
+  // Add an entry to provoke importing by thinBackend.
+  ImportList[Summary->modulePath()].insert(GUID);
+}
+  }
+
+  for (auto &I : ImportList) {
+ErrorOr> MBOrErr =
+llvm::MemoryBuffer::getFile(I.first());
+if (!MBOrErr) {
+  errs() << "Error loading imported file '" << I.first()
+ << "': " << MBOrErr.getError().message() << "\n";
+  return false;
+}
+
+Expected BMOrErr = findThinLTOModule(**MBOrErr);
+if (!BMOrErr) {
+  handleAllEr

[PATCH] D83154: clang: Add -fcoverage-prefix-map

2020-09-22 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

Should we wait for that one to land and then pick this one up? Otherwise any 
thoughts on the outstanding discussion?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83154

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


[PATCH] D86895: [Modules] Add stats to measure performance of building and loading modules.

2020-09-22 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Where is the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86895

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


[PATCH] D86895: [Modules] Add stats to measure performance of building and loading modules.

2020-09-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.

This looks pretty useful, thanks for adding this Volodymyr. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86895

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 293505.
tianshilei1992 added a comment.

Fixed the case `target_parallel_for_codegen.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
@@ -66,7 +66,11 @@
 #ifndef HEADER
 #define HEADER
 
-// CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CHECK-DAG: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %{{[^,]+}}, %{{[^,]+}} }
+// CHECK-32-DAG: [[KMP_PRIVATES_T]] = type { [3 x i64], [3 x i8*], [3 x i8*], [3 x i8*], i16 }
+// CHECK-64-DAG: [[KMP_PRIVATES_T]] = type { [3 x i8*], [3 x i8*], [3 x i64], [3 x i8*], i16 }
 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
 // CHECK-DAG: [[DEF_LOC:@.+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
 
@@ -132,33 +136,26 @@
   double cn[5][n];
   TT d;
 
-  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target_teams_nowait_mapper(i64 -1, i8* @{{[^,]+}}, i32 3, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[SIZET]], i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[MAPT]], i32 0, i32 0), i8** null, i32 {{[^,]+}}, i32 {{[^)]+}})
-  // CHECK-DAG:   [[BP]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[P]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]]
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX0]]
-  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]]
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR1]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR2]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR2]]
-  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
-  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
-  // CHECK:   [[FAIL]]
-  // CHECK:   call void [[HVT0:@.+]](i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^)]+}})
-  // CHECK-NEXT:  br label %[[END]]
-  // CHECK:   [[END]]
+  // CHECK-DAG: call i32 @__kmpc_omp_task([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i8* [[TASK:%.+]])
+  // CHECK-32-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i32 84, i32 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-64-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 144, i64 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-DAG: [[TASK_CAST:%.+]] = bitcast i8* [[TASK]] to [[K

[PATCH] D86964: [ASTMatchers] Avoid recursion in ancestor matching to save stack space.

2020-09-22 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG625761825620: [ASTMatchers] Avoid recursion in ancestor 
matching to save stack space. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D86964?vs=289232&id=293504#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86964

Files:
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -544,8 +544,9 @@
 // don't invalidate any iterators.
 if (ResultCache.size() > MaxMemoizationEntries)
   ResultCache.clear();
-return memoizedMatchesAncestorOfRecursively(Node, Ctx, Matcher, Builder,
-MatchMode);
+if (MatchMode == AncestorMatchMode::AMM_ParentOnly)
+  return matchesParentOf(Node, Matcher, Builder);
+return matchesAnyAncestorOf(Node, Ctx, Matcher, Builder);
   }
 
   // Matches all registered matchers on the given node and calls the
@@ -699,9 +700,23 @@
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
+  // Returns whether a direct parent of \p Node matches \p Matcher.
+  // Unlike matchesAnyAncestorOf there's no memoization: it doesn't save much.
+  bool matchesParentOf(const DynTypedNode &Node, const DynTypedMatcher &Matcher,
+   BoundNodesTreeBuilder *Builder) {
+for (const auto &Parent : ActiveASTContext->getParents(Node)) {
+  BoundNodesTreeBuilder BuilderCopy = *Builder;
+  if (Matcher.matches(Parent, this, &BuilderCopy)) {
+*Builder = std::move(BuilderCopy);
+return true;
+  }
+}
+return false;
+  }
+
   // Returns whether an ancestor of \p Node matches \p Matcher.
   //
-  // The order of matching ((which can lead to different nodes being bound in
+  // The order of matching (which can lead to different nodes being bound in
   // case there are multiple matches) is breadth first search.
   //
   // To allow memoization in the very common case of having deeply nested
@@ -712,51 +727,64 @@
   // Once there are multiple parents, the breadth first search order does not
   // allow simple memoization on the ancestors. Thus, we only memoize as long
   // as there is a single parent.
-  bool memoizedMatchesAncestorOfRecursively(const DynTypedNode &Node,
-ASTContext &Ctx,
-const DynTypedMatcher &Matcher,
-BoundNodesTreeBuilder *Builder,
-AncestorMatchMode MatchMode) {
-// For AST-nodes that don't have an identity, we can't memoize.
-// When doing a single-level match, we don't need to memoize because
-// ParentMap (in ASTContext) already memoizes the result.
-if (!Builder->isComparable() ||
-MatchMode == AncestorMatchMode::AMM_ParentOnly)
-  return matchesAncestorOfRecursively(Node, Ctx, Matcher, Builder,
-  MatchMode);
-
-MatchKey Key;
-Key.MatcherID = Matcher.getID();
-Key.Node = Node;
-Key.BoundNodes = *Builder;
-Key.Traversal = Ctx.getParentMapContext().getTraversalKind();
-Key.Type = MatchType::Ancestors;
-
-// Note that we cannot use insert and reuse the iterator, as recursive
-// calls to match might invalidate the result cache iterators.
-MemoizationMap::iterator I = ResultCache.find(Key);
-if (I != ResultCache.end()) {
-  *Builder = I->second.Nodes;
-  return I->second.ResultOfMatch;
-}
+  //
+  // We avoid a recursive implementation to prevent excessive stack use on
+  // very deep ASTs (similarly to RecursiveASTVisitor's data recursion).
+  bool matchesAnyAncestorOf(DynTypedNode Node, ASTContext &Ctx,
+const DynTypedMatcher &Matcher,
+BoundNodesTreeBuilder *Builder) {
 
-MemoizedMatchResult Result;
-Result.Nodes = *Builder;
-Result.ResultOfMatch = matchesAncestorOfRecursively(
-Node, Ctx, Matcher, &Result.Nodes, MatchMode);
+// Memoization keys that can be updated with the result.
+// These are the memoizable nodes in the chain of unique parents, which
+// terminates when a node has multiple parents, or matches, or is the root.
+std::vector Keys;
+// When returning, update the memoization cache.
+auto Finish = [&](bool Matched) {
+  for (const auto &Key : Keys) {
+MemoizedMatchResult &CachedResult = ResultCache[Key];
+CachedResult.ResultOfMatch = Matched;
+CachedResult.Nodes = *Builder;
+  }
+  return Matched;
+};
+
+// Loop while there's a single parent and we want to attempt

[clang] 6257618 - [ASTMatchers] Avoid recursion in ancestor matching to save stack space.

2020-09-22 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-09-22T19:43:41+02:00
New Revision: 625761825620f19a44c7a1482ce05d678a1b0deb

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

LOG: [ASTMatchers] Avoid recursion in ancestor matching to save stack space.

A recent change increased the stack size of memoizedMatchesAncestorOfRecursively
leading to stack overflows on real code involving large fold expressions.
It's not totally unreasonable to choke on very deep ASTs, but as common
infrastructure it's be nice if ASTMatchFinder is more robust.
(It already uses data recursion for the regular "downward" traversal.)

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

Added: 


Modified: 
clang/lib/ASTMatchers/ASTMatchFinder.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index dc937dde88e3..b9b38923495a 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -544,8 +544,9 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
 // don't invalidate any iterators.
 if (ResultCache.size() > MaxMemoizationEntries)
   ResultCache.clear();
-return memoizedMatchesAncestorOfRecursively(Node, Ctx, Matcher, Builder,
-MatchMode);
+if (MatchMode == AncestorMatchMode::AMM_ParentOnly)
+  return matchesParentOf(Node, Matcher, Builder);
+return matchesAnyAncestorOf(Node, Ctx, Matcher, Builder);
   }
 
   // Matches all registered matchers on the given node and calls the
@@ -699,9 +700,23 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
+  // Returns whether a direct parent of \p Node matches \p Matcher.
+  // Unlike matchesAnyAncestorOf there's no memoization: it doesn't save much.
+  bool matchesParentOf(const DynTypedNode &Node, const DynTypedMatcher 
&Matcher,
+   BoundNodesTreeBuilder *Builder) {
+for (const auto &Parent : ActiveASTContext->getParents(Node)) {
+  BoundNodesTreeBuilder BuilderCopy = *Builder;
+  if (Matcher.matches(Parent, this, &BuilderCopy)) {
+*Builder = std::move(BuilderCopy);
+return true;
+  }
+}
+return false;
+  }
+
   // Returns whether an ancestor of \p Node matches \p Matcher.
   //
-  // The order of matching ((which can lead to 
diff erent nodes being bound in
+  // The order of matching (which can lead to 
diff erent nodes being bound in
   // case there are multiple matches) is breadth first search.
   //
   // To allow memoization in the very common case of having deeply nested
@@ -712,51 +727,64 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   // Once there are multiple parents, the breadth first search order does not
   // allow simple memoization on the ancestors. Thus, we only memoize as long
   // as there is a single parent.
-  bool memoizedMatchesAncestorOfRecursively(const DynTypedNode &Node,
-ASTContext &Ctx,
-const DynTypedMatcher &Matcher,
-BoundNodesTreeBuilder *Builder,
-AncestorMatchMode MatchMode) {
-// For AST-nodes that don't have an identity, we can't memoize.
-// When doing a single-level match, we don't need to memoize because
-// ParentMap (in ASTContext) already memoizes the result.
-if (!Builder->isComparable() ||
-MatchMode == AncestorMatchMode::AMM_ParentOnly)
-  return matchesAncestorOfRecursively(Node, Ctx, Matcher, Builder,
-  MatchMode);
-
-MatchKey Key;
-Key.MatcherID = Matcher.getID();
-Key.Node = Node;
-Key.BoundNodes = *Builder;
-Key.Traversal = Ctx.getParentMapContext().getTraversalKind();
-Key.Type = MatchType::Ancestors;
-
-// Note that we cannot use insert and reuse the iterator, as recursive
-// calls to match might invalidate the result cache iterators.
-MemoizationMap::iterator I = ResultCache.find(Key);
-if (I != ResultCache.end()) {
-  *Builder = I->second.Nodes;
-  return I->second.ResultOfMatch;
-}
+  //
+  // We avoid a recursive implementation to prevent excessive stack use on
+  // very deep ASTs (similarly to RecursiveASTVisitor's data recursion).
+  bool matchesAnyAncestorOf(DynTypedNode Node, ASTContext &Ctx,
+const DynTypedMatcher &Matcher,
+BoundNodesTreeBuilder *Builder) {
 
-MemoizedMatchResult Result;
-Result.Nodes = *Builder;
-Result.ResultOfMatch = matchesAncestorOfRecursively(
-Node, Ctx, Matcher, &Result.Nodes, MatchMode);
+ 

[PATCH] D88105: [NFC] [PPC] Add PowerPC expected IR tests for C99 complex

2020-09-22 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA added inline comments.



Comment at: clang/test/CodeGen/powerpc-c99complex.c:1
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefix=PPC32LNX

Can you add ppc64le as well? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88105

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


[PATCH] D86964: [ASTMatchers] Avoid recursion in ancestor matching to save stack space.

2020-09-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 3 inline comments as done.
sammccall added inline comments.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:705
+  // Unlike matchesAnyAncestorOf there's no memoization: it doesn't save much.
+  bool matchesParentOf(const DynTypedNode &Node, const DynTypedMatcher 
&Matcher,
+   BoundNodesTreeBuilder *Builder) {

hokein wrote:
> this API makes sense, I'm wondering whether we should do it further (more 
> aligned with `matchesChildOf` pattern):
> 
> - make `matchesParentOf` public;
> - introduce a new `matchesParentOf` interface in ASTMatcherFinder, which 
> calls this function here;
> - then we can remove the special parent case in 
> `MatchASTVisitor::matchesAncestorOf`, and the `AncestorMatchMode` enum is 
> also not needed anymore;
> 
> I'm also ok with the current way.
I'm happy with that change, but I'd rather not bundle it into this one.
The goal here is to fix weird production characteristics (rather than APIs or 
algorithm output) and those are slippery, so let's change one thing at a time.



Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:740
+// When returning, update the memoization cache.
+auto Finish = [&](bool Result) {
+  for (const auto &Key : Keys) {

hokein wrote:
> maybe
> 
> Finish => Memorize
> Result => IsMatched
> Finish => Memorize

Memoize and Memorize are different words, and memoize doesn't act on results 
but rather on functions. So I think this rename is confusing.

> Result => IsMatched
Done



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86964

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


[PATCH] D87989: [Flang][Driver] Add InputOutputTest frontend action with new -test-IO flag

2020-09-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@CarolineConcatto , thank you for this patch! It implements some really 
important functionality and IMO the overall structure is solid.

I've left quite a few comments, but mostly nits and suggestions for more 
detailed comments. There's a few, but it's a relatively big patch :)

One suggestion - IMO this patch first and foremost creates the scaffolding for 
writing frontend actions. The `test-IO` flag is only really there to facilitate 
testing. Perhaps it's worth updating the commit message to reflect that? I 
would definitely like to see a bit more emphasis on the fact that this patch 
introduces the necessary APIs for reading and writing files. For me that's the 
key functionality here.

Also, I tested this patch and currently `-test-IO` is listed together with 
other `clang` options (check `clang --help-hidden`). Please, could you fix that?




Comment at: clang/include/clang/Driver/Options.td:3514
+//===--===//
+def TEST_IO : Flag<["-"], "test-IO">, Flags<[HelpHidden, FlangOption, 
FC1Option]>,Group,
+HelpText<"Only run the InputOutputTest action">;

I think that `test-io` would be more consistent with other options in the file.



Comment at: clang/include/clang/Driver/Options.td:3515
+def TEST_IO : Flag<["-"], "test-IO">, Flags<[HelpHidden, FlangOption, 
FC1Option]>,Group,
+HelpText<"Only run the InputOutputTest action">;
+

I would help to make this a bit more specific. What about: `Run the 
InputOuputTest action. Use for development and testing only`?



Comment at: clang/lib/Driver/ToolChains/Flang.cpp:39-40
   } else if (isa(JA) || isa(JA)) {
+CmdArgs.push_back("-triple");
+CmdArgs.push_back(Args.MakeArgString(TripleStr));
 if (JA.getType() == types::TY_Nothing) {

It would be helpful to have a note that explains this change. Perhaps something 
like this:

```
// TODO: Note that eventually all actions will require a triple (e.g. `-triple 
aarch64-unknown-linux-gnu`). However, `-triple` is currently not supported by 
`flang-new -fc1`, so we only add it to actions that we don't support/execute 
just yet. 
```

Probably above line 33. What do you think?



Comment at: clang/lib/Driver/Types.cpp:329
   if (Driver.CCCIsCPP() || DAL.getLastArg(options::OPT_E) ||
+  DAL.getLastArg(options::OPT_TEST_IO) ||
   DAL.getLastArg(options::OPT__SLASH_EP) ||

This should probably be the last option here (as it's the latest to be added). 
Also, worth adding a comment about, e.g.:
```
-test-io is used by Flang to run InputOutputTest action
```



Comment at: flang/include/flang/Frontend/CompilerInstance.h:26
 
+  /// The Fortran  file  manager.
+  std::shared_ptr allSources_;

[nit] Forrtran or Flang?



Comment at: flang/include/flang/Frontend/CompilerInstance.h:33
+  /// Holds the name of the output file.
+  /// Helps to go through the list when working with the outputFiles_
+  struct OutputFile {

[nit] 'the outputFiles_' -> 'outputFiles_'



Comment at: flang/include/flang/Frontend/CompilerInstance.h:40-42
+  /// If the output doesn't support seeking (terminal, pipe), we switch
+  /// the stream to a buffer_ostream. These are the buffer and the original
+  /// stream.

[nit] 
```
/// If the output doesn't support seeking (terminal, pipe), we switch
/// the stream to a buffer_ostream. These are the buffer and the original
/// stream.
```
vvv
```
/// Output stream that doesn't support seeking (e.g. terminal, pipe). This 
stream is normally wrapped
/// in buffer_ostream before being passed to users (e.g. via CreateOutputFile).
```



Comment at: flang/include/flang/Frontend/CompilerInstance.h:48
+
+  /// Force an output buffer.
+  std::unique_ptr outputStream_;

I think that:
```
This field holds the output stream provided by the user. Normally, users of 
CompilerInstance will call CreateOutputFile to obtain/create an output stream. 
If they want to provide their own output stream, this field will facilitate 
this. It is optional and will normally be just a nullptr.
```
would be a bit more informative :)



Comment at: flang/include/flang/Frontend/CompilerInstance.h:65
 
+  /// setInvocation - Replace the current invocation.
+  void SetInvocation(std::shared_ptr value);

[nit] Delete



Comment at: flang/include/flang/Frontend/CompilerInstance.h:68
+
+  /// Return the current source manager.
+  Fortran::parser::AllSources &GetAllSources() const { return *allSources_; }

[nit] There is no source manager here.

It's probably worth decorating everything related to `AllSources` with:
```
/// }
/// @name File manager
/// {
```



Comment at: flang/include/flang/Frontend/

[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D87808#2286664 , @rsmith wrote:

> In D87808#2280197 , @dblaikie wrote:
>
>> @rsmith What's the deal with these anonymous structs/unions? Why do they 
>> have copy/move constructors (are those technically called from the enclosing 
>> class's copy/move constructors?) but no default constructor to be called 
>> from the other ctors of the enclosing class?
>
> Let's use the class `G` in the example. `G::G` directly initializes the field 
> `g_`, so it can't call any kind of constructor for the anonymous struct 
> member. Instead, anonymous structs and unions are "expanded" when building 
> the constructor initializer lists for all cases other than a copy or move 
> constructor (no initialization action is taken for union members by default, 
> though -- not unless they have a default member initializer or an explicit 
> mem-initializer). So the default constructor of an anonymous struct or union 
> is never really used for anything[*].
>
> But now consider the copy or move constructor for a type like this:
>
>   struct X {
> Y y;
> union { ... };
>   };
>
> That copy or move constructor needs to build a member initializer list that 
> (a) calls the `Y` copy/move constructor for `y`, and (b) performs a bytewise 
> copy for the anonymous union. We can't express this in the "expanded" form, 
> because we wouldn't know which union member to initialize.
>
> So for the non-copy/move case, we build `CXXCtorInitializers` for expanded 
> members, and in the copy/move case, we build `CXXCtorInitializers` calling 
> the copy/move constructors for the anonymous structs/unions themselves.

OK - I /mostly/ follow all that.

> [*]: It's not entirely true that the default constructor is never used for 
> anything. When we look up special members for the anonymous struct / union 
> (looking for the copy or move constructor) we can trigger the implicit 
> declaration of the default constructor. And it's actually even possible to 
> *call* that default constructor, if you're tricksy enough: 
> https://godbolt.org/z/Tq56bz

Good to know! Makes things more interesting. (any case where something could 
get constructed without calling the constructor is something this feature needs 
to be aware of/careful about)

> In D87808#2282223 , @rnk wrote:
>
>> Maybe the issue is that this code is running into the lazy implicit special 
>> member declaration optimization. Maybe the class in question has an 
>> implicit, trivial, default constructor, but we there is no 
>> CXXConstructorDecl present in the ctors list for the loop to find.
>
> That seems very likely. The existing check:
>
>   if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
> return false;
>
> is skating on thin ice in this regard: a class with an implicit default 
> constructor might or might not have had that default constructor implicitly 
> declared.

Yeah, that's subtle & probably best not to rely on being able to gloss over 
that case.

> But I think this code should give the same outcome either way, because a 
> class with any constructor other than a default/copy/move constructor must 
> have a user-declared constructor of some kind, and so will never have an 
> implicit default constructor.

Hmm, trying to parse this. So if we're in the subtle case of having an implicit 
default constructor (and no other (necessarily user-declared, as you say) 
constructors) - if it's not been declared, then this function will return 
false. If it has been declared, it'll return false... hmm, nope, then it'll 
return true.

It sounds like there's an assumption related to "a class with any constructor 
other than a default/copy/move" - a default constructor would be nice to use as 
a constructor home. (certainly a user-defined one, but even an implicit one - 
so long as it gets IRGen'd when called, and not skipped (as in the anonymous 
struct/class case) or otherwise frontend-optimized away)

> (Inherited constructors introduce some complications here, but we don't do 
> lazy constructor declaration for classes with inherited constructors, so I 
> think that's OK too.)

Ah, handy!




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2292-2300
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }

rsmith wrote:
> This looks pretty similar to:
> 
> ```
> return RD->hasUserDeclaredConstructor() && 
> !RD->hasTrivialDefaultConstructor();
> ```
> 
> (other than its treatment of user-declared copy or move constructors), but I 
> have to admit I don't really understand what the "at least one constructor 
> and no trivial or constexpr constructors" rule aims to achieve, so it's hard 
> to know if this is the right interpretati

[clang] c3c08bf - [SyntaxTree] Test the List API

2020-09-22 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-22T17:07:41Z
New Revision: c3c08bfdfd6244e0429753ee56df39c90187d772

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

LOG: [SyntaxTree] Test the List API

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tree.h
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tree.h 
b/clang/include/clang/Tooling/Syntax/Tree.h
index a544fc1827b7..5840a86199eb 100644
--- a/clang/include/clang/Tooling/Syntax/Tree.h
+++ b/clang/include/clang/Tooling/Syntax/Tree.h
@@ -218,12 +218,16 @@ class List : public Tree {
   /// and delimiters are represented as null pointers.
   ///
   /// For example, in a separated list:
-  /// "a, b, c" <=> [("a", ","), ("b", ","), ("c", null)]
-  /// "a, , c" <=> [("a", ","), (null, ","), ("c", ",)]
-  /// "a, b," <=> [("a", ","), ("b", ","), (null, null)]
+  /// "a, b, c"  <=> [("a" , ","), ("b" , "," ), ("c" , null)]
+  /// "a,  , c"  <=> [("a" , ","), (null, "," ), ("c" , null)]
+  /// "a, b  c"  <=> [("a" , ","), ("b" , null), ("c" , null)]
+  /// "a, b,"<=> [("a" , ","), ("b" , "," ), (null, null)]
   ///
   /// In a terminated or maybe-terminated list:
-  /// "a, b," <=> [("a", ","), ("b", ",")]
+  /// "a; b; c;" <=> [("a" , ";"), ("b" , ";" ), ("c" , ";" )]
+  /// "a;  ; c;" <=> [("a" , ";"), (null, ";" ), ("c" , ";" )]
+  /// "a; b  c;" <=> [("a" , ";"), ("b" , null), ("c" , ";" )]
+  /// "a; b; c"  <=> [("a" , ";"), ("b" , ";" ), ("c" , null)]
   std::vector> getElementsAsNodesAndDelimiters();
 
   /// Returns the elements of the list. Missing elements are represented

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 6e777b353b04..fba3164e5966 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
+#include "llvm/ADT/STLExtras.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -122,4 +124,231 @@ TEST_P(TreeTest, LastLeaf) {
   }
 }
 
+class ListTest : public SyntaxTreeTest {
+private:
+  std::string dumpQuotedTokensOrNull(const Node *N) {
+return N ? "'" +
+   StringRef(N->dumpTokens(Arena->getSourceManager()))
+   .trim()
+   .str() +
+   "'"
+ : "null";
+  }
+
+protected:
+  std::string
+  dumpElementsAndDelimiters(ArrayRef> EDs) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(
+EDs, OS, [&OS, this](const List::ElementAndDelimiter &ED) {
+  OS << "(" << dumpQuotedTokensOrNull(ED.element) << ", "
+ << dumpQuotedTokensOrNull(ED.delimiter) << ")";
+});
+
+OS << "]";
+
+return OS.str();
+  }
+
+  std::string dumpNodes(ArrayRef Nodes) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(Nodes, OS, [&OS, this](const Node *N) {
+  OS << dumpQuotedTokensOrNull(N);
+});
+
+OS << "]";
+
+return OS.str();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, ListTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", null)]
+TEST_P(ListTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', 'b', 'c']");
+}
+
+/// "a,  , c"  <=> [("a", ","), (null, ","), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::

[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-22 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3c08bfdfd62: [SyntaxTree] Test the List API (authored by 
eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87839

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
+#include "llvm/ADT/STLExtras.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -122,4 +124,231 @@
   }
 }
 
+class ListTest : public SyntaxTreeTest {
+private:
+  std::string dumpQuotedTokensOrNull(const Node *N) {
+return N ? "'" +
+   StringRef(N->dumpTokens(Arena->getSourceManager()))
+   .trim()
+   .str() +
+   "'"
+ : "null";
+  }
+
+protected:
+  std::string
+  dumpElementsAndDelimiters(ArrayRef> EDs) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(
+EDs, OS, [&OS, this](const List::ElementAndDelimiter &ED) {
+  OS << "(" << dumpQuotedTokensOrNull(ED.element) << ", "
+ << dumpQuotedTokensOrNull(ED.delimiter) << ")";
+});
+
+OS << "]";
+
+return OS.str();
+  }
+
+  std::string dumpNodes(ArrayRef Nodes) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(Nodes, OS, [&OS, this](const Node *N) {
+  OS << dumpQuotedTokensOrNull(N);
+});
+
+OS << "]";
+
+return OS.str();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, ListTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", null)]
+TEST_P(ListTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', 'b', 'c']");
+}
+
+/// "a,  , c"  <=> [("a", ","), (null, ","), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), (null, ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', null, 'c']");
+}
+
+/// "a, b  c"  <=> [("a", ","), ("b", null), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingDelimiter) {
+  buildTree("", GetParam());
+
+  // "a, b  c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', null), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', 'b', 'c']");
+}
+
+/// "a, b,"<=> [("a", ","), ("b", ","), (null, null)]
+TEST_P(ListTest, List_Separated_MissingLastElement) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {cre

[PATCH] D77229: [Analyzer] Avoid handling of LazyCompundVals in IteratorModeling

2020-09-22 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp:330-336
+SVal getReturnIterator(const CallEvent &Call) {
+  Optional RetValUnderConstr = Call.getReturnValueUnderConstruction();
+  if (RetValUnderConstr.hasValue())
+return *RetValUnderConstr;
+
+  return Call.getReturnValue();
+}

NoQ wrote:
> NoQ wrote:
> > NoQ wrote:
> > > I still believe you have not addressed the problem while moving the 
> > > functions from D81718 to this patch. The caller of this function has no 
> > > way of knowing whether the return value is the prvalue of the iterator or 
> > > the glvalue of the iterator.
> > > 
> > > Looks like most callers are safe because they expect the object of 
> > > interest to also be already tracked. But it's quite possible that both 
> > > are tracked, say:
> > > 
> > > ```lang=c++
> > >   Container1 container1 = ...;
> > >   Container2 container2 = { container1.begin() };
> > >   container2.begin(); // ???
> > > ```
> > > 
> > > Suppose `Container1::iterator` is implemented as an object and 
> > > `Container2::iterator` is implemented as a pointer. In this case 
> > > `getIteratorPosition(getReturnIterator())` would yield the position of 
> > > `container1.begin()` whereas the correct answer is the position of 
> > > `container2.begin()`.
> > > 
> > > This problem may seem artificial but it is trivial to avoid if you simply 
> > > stop defending your convoluted solution of looking at value classes 
> > > instead of AST types.
> > Ugh, the problem is much worse. D82185 is entirely broken for the exact 
> > reason i described above and you only didn't notice it because you wrote 
> > almost no tests.
> > 
> > Consider the test you've added in D82185:
> > 
> > ```lang=c++
> > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> >   auto i = c.begin();
> > 
> >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // 
> > expected-warning{{TRUE}}
> > }
> > ```
> > 
> > It breaks very easily if you modify it slightly:
> > ```lang=c++
> > void begin_ptr_iterator(const cont_with_ptr_iterator &c) {
> >   auto i = c.begin();
> >   ++i; // <==
> > 
> >   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // Says 
> > FALSE!
> > }
> > ```
> > The iterator obviously still points to the same container, so why does the 
> > test fail? Because you're tracking the wrong iterator: you treated your 
> > `&SymRegion{conj_$3}` as a glvalue whereas you should have treated it as a 
> > prvalue. In other words, your checker thinks that `&SymRegion{conj_$3}` is 
> > the location of an iterator object rather than the iterator itself, and 
> > after you increment the pointer it thinks that it's a completely unrelated 
> > iterator.
> > 
> > There's a separate concern about why does it say `FALSE` (should be 
> > `UNKNOWN`) but you get the point.
> The better way to test D82185 would be to make all existing tests with 
> iterator objects pass with iterator pointers as well. Like, make existing 
> container mocks use either iterator objects or iterator pointers depending on 
> a macro and make two run-lines in each test file, one with `-D` and one 
> without it. Most of the old tests should have worked out of the box if you 
> did it right; the few that don't pass would be hidden under #ifdef for future 
> investigation.
Thank you for your review and especially for this tip! It is really a good 
idea. I changed it now and it indeed shows the problem you reported. It seems 
that my checker mixes up the region of the pointer-typed variable (`&i` and 
`&j`) with the region they point to (`&SymRegion{reg_$1 & v>}._start>}` for `i` before the 
increment and `&Element{SymRegion{reg_$1 & v>}._start>},1 S64b,int}` for both `i` and `j` after the 
increment).

What I fail to see and I am asking you help in it is that the relation between 
this problem and the `getReturnIterator()` function. This function retrieves 
the object from the construction context if there is one, but for plain 
pointers there is never one. Thus this function is always 
`Call.getReturnValue()` like before this patch.


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

https://reviews.llvm.org/D77229

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


[PATCH] D87588: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-09-22 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D87588#2278948 , @ro wrote:

> As described in D87825 , this patch broke 
> `Debug` builds on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`.

Thank you for reporting this issue. I it is fixed now: 
https://reviews.llvm.org/rGf0546173fa4bdde03ecb21a174fcaa8a6490adbd (thanks for 
that!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87588

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


[PATCH] D54222: [clang-tidy] Add a check to detect returning static locals in public headers

2020-09-22 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54222#2281642 , 
@jranieri-grammatech wrote:

> @JonasToth It looks like there are some outstanding review comments that need 
> to be addressed. I've gotten some time allocated to work on this next week.

Great!


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D54222

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


[PATCH] D88105: [NFC] [PPC] Add PowerPC expected IR tests for C99 complex

2020-09-22 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm created this revision.
cebowleratibm added reviewers: daltenty, ZarkoCA, sfertile.
Herald added subscribers: cfe-commits, shchenz, nemanjai.
Herald added a project: clang.
cebowleratibm requested review of this revision.

Adding this test so that I can extend it in a follow on patch with expected IR 
for AIX when I implement complex handling in AIXABIInfo.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88105

Files:
  clang/test/CodeGen/powerpc-c99complex.c


Index: clang/test/CodeGen/powerpc-c99complex.c
===
--- /dev/null
+++ clang/test/CodeGen/powerpc-c99complex.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | 
FileCheck %s --check-prefix=PPC32LNX
+
+_Complex float foo1(_Complex float x) {
+  return x;
+// PPC64LNX-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float 
%x.{{.*}}) #0 {
+// PPC64LNX: ret { float, float }
+
+// PPC32LNX-LABEL:  define void @foo1({ float, float }* noalias sret align 4 
%agg.result, { float, float }* byval({ float, float }) align 4 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { float, float }, 
{ float, float }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { float, float }, 
{ float, float }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETREAL]], align 4
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETIMAG]], align 4
+}
+
+_Complex double foo2(_Complex double x) {
+  return x;
+// PPC64LNX-LABEL:   define { double, double } @foo2(double %x.{{.*}}, 
double %x.{{.*}}) #0 {
+// PPC64LNX: ret { double, double }
+
+// PPC32LNX-LABEL:  define void @foo2({ double, double }* noalias sret align 8 
%agg.result, { double, double }* byval({ double, double }) align 8 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { double, double 
}, { double, double }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { double, double 
}, { double, double }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store double %{{.*}}, double* [[RETREAL]], align 8
+// PPC32LNX-NEXT:   store double %{{.*}}, double* [[RETIMAG]], align 8
+}
+
+_Complex long double foo3(_Complex long double x) {
+  return x;
+// PPC64LNX-LDBL128-LABEL:define { ppc_fp128, ppc_fp128 } @foo3(ppc_fp128 
%x.{{.*}}, ppc_fp128 %x.{{.*}}) #0 {
+// PPC64LNX-LDBL128:  ret { ppc_fp128, ppc_fp128 }
+
+// PPC32LNX-LABEL: define void @foo3({ ppc_fp128, ppc_fp128 }* noalias sret 
align 16 %agg.result, { ppc_fp128, ppc_fp128 }* byval({ ppc_fp128, ppc_fp128 }) 
align 16 %x) #0 {
+// PPC32LNX:   [[RETREAL:%.*]] = getelementptr inbounds { ppc_fp128, 
ppc_fp128 }, { ppc_fp128, ppc_fp128 }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:  [[RETIMAG:%.*]] = getelementptr inbounds { ppc_fp128, 
ppc_fp128 }, { ppc_fp128, ppc_fp128 }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:  store ppc_fp128 %{{.*}}, ppc_fp128* [[RETREAL]], align 16
+// PPC32LNX-NEXT:  store ppc_fp128 %{{.*}}, ppc_fp128* [[RETIMAG]], align 16
+}


Index: clang/test/CodeGen/powerpc-c99complex.c
===
--- /dev/null
+++ clang/test/CodeGen/powerpc-c99complex.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefixes=PPC64LNX
+// RUN: %clang_cc1 -triple powerpc-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=PPC32LNX
+
+_Complex float foo1(_Complex float x) {
+  return x;
+// PPC64LNX-LABEL:   define { float, float } @foo1(float %x.{{.*}}, float %x.{{.*}}) #0 {
+// PPC64LNX: ret { float, float }
+
+// PPC32LNX-LABEL:  define void @foo1({ float, float }* noalias sret align 4 %agg.result, { float, float }* byval({ float, float }) align 4 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { float, float }, { float, float }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { float, float }, { float, float }* %agg.result, i32 0, i32 1
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETREAL]], align 4
+// PPC32LNX-NEXT:   store float %{{.*}}, float* [[RETIMAG]], align 4
+}
+
+_Complex double foo2(_Complex double x) {
+  return x;
+// PPC64LNX-LABEL:   define { double, double } @foo2(double %x.{{.*}}, double %x.{{.*}}) #0 {
+// PPC64LNX: ret { double, double }
+
+// PPC32LNX-LABEL:  define void @foo2({ double, double }* noalias sret align 8 %agg.result, { double, double }* byval({ double, double }) align 8 %x) #0 {
+// PPC32LNX:[[RETREAL:%.*]] = getelementptr inbounds { double, double }, { double, double }* %agg.result, i32 0, i32 0
+// PPC32LNX-NEXT:   [[RETIMAG:%.*]] = getelementptr inbounds { d

[PATCH] D88106: [SyntaxTree] Provide iterator-like functions for Lists

2020-09-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88106

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -294,46 +295,107 @@
   }
 }
 
-std::vector>
-syntax::List::getElementsAsNodesAndDelimiters() {
-  if (!getFirstChild())
-return {};
+syntax::List::ElementAndDelimiter
+syntax::List::getWithDelimiter(syntax::Node *Element) {
+  assert(Element && Element->getRole() == syntax::NodeRole::ListElement);
+  auto *Next = Element->getNextSibling();
+  if (!Next)
+return {Element, nullptr};
+  switch (Next->getRole()) {
+  case syntax::NodeRole::ListElement:
+return {Element, nullptr};
+  case syntax::NodeRole::ListDelimiter:
+return {Element, cast(Next)};
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as children.");
+  }
+}
 
-  std::vector> Children;
-  syntax::Node *ElementWithoutDelimiter = nullptr;
-  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
-switch (C->getRole()) {
-case syntax::NodeRole::ListElement: {
-  if (ElementWithoutDelimiter) {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-  }
-  ElementWithoutDelimiter = C;
-  break;
-}
-case syntax::NodeRole::ListDelimiter: {
-  Children.push_back({ElementWithoutDelimiter, cast(C)});
-  ElementWithoutDelimiter = nullptr;
-  break;
-}
-default:
-  llvm_unreachable(
-  "A list can have only elements and delimiters as children.");
+llvm::Optional>
+syntax::List::getElementAndDelimiterAfterDelimiter(syntax::Leaf *Delimiter) {
+  assert(Delimiter && Delimiter->getRole() == syntax::NodeRole::ListDelimiter);
+  auto *Next = Delimiter->getNextSibling();
+  if (!Next) {
+switch (getTerminationKind()) {
+// List is separated and ends with delimiter
+// => missing last ElementAndDelimiter.
+case syntax::List::TerminationKind::Separated:
+  return llvm::Optional>(
+  {nullptr, nullptr});
+case syntax::List::TerminationKind::Terminated:
+case syntax::List::TerminationKind::MaybeTerminated:
+  return None;
 }
   }
-
-  switch (getTerminationKind()) {
-  case syntax::List::TerminationKind::Separated: {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-break;
+  switch (Next->getRole()) {
+  case syntax::NodeRole::ListElement:
+return getWithDelimiter(Next);
+
+  // Consecutive Delimiters => missing Element
+  case syntax::NodeRole::ListDelimiter:
+return llvm::Optional>(
+{nullptr, cast(Next)});
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as children.");
   }
-  case syntax::List::TerminationKind::Terminated:
-  case syntax::List::TerminationKind::MaybeTerminated: {
-if (ElementWithoutDelimiter) {
-  Children.push_back({ElementWithoutDelimiter, nullptr});
-}
-break;
+}
+
+llvm::Optional>
+syntax::List::getElementAndDelimiterAfterElement(syntax::Node *Element) {
+  assert(Element && Element->getRole() == syntax::NodeRole::ListElement);
+  auto *Next = Element->getNextSibling();
+  // a  b, x => End of list, this was the last ElementAndDelimiter.
+  if (!Next)
+return None;
+
+  switch (Next->getRole()) {
+  // x  b, c => next ElementAndDelimiter starts with 'b'.
+  case syntax::NodeRole::ListElement:
+return getWithDelimiter(Next);
+
+  // a  x, c => next ElementAndDelimiter starts after ','.
+  case syntax::NodeRole::ListDelimiter:
+return getElementAndDelimiterAfterDelimiter(cast(Next));
+
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as children.");
   }
+}
+
+llvm::Optional>
+syntax::List::getNext(syntax::List::ElementAndDelimiter &ED) {
+  if (auto *Delimiter = ED.delimiter)
+return getElementAndDelimiterAfterDelimiter(Delimiter);
+  if (auto *Element = ED.element)
+return getElementAndDelimiterAfterElement(Element);
+  return None;
+}
+
+llvm::Optional>
+syntax::List::getFirst() {
+  auto *First = this->getFirstChild();
+  if (!First)
+return None;
+  switch (First->getRole()) {
+  case syntax::NodeRole::ListElement:
+return getWithDelimiter(First);
+  case syntax::NodeRole::ListDelimiter:
+return llvm::Optional>(
+{nullptr, cast(First)});
+  default:
+llvm_unreachable(
+"A list can have only elements and delimiters as childr

[PATCH] D87671: [PowerPC] Implement Vector String Isolate Builtins in Clang/LLVM

2020-09-22 Thread Amy Kwan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG079757b551f3: [PowerPC] Implement Vector String Isolate 
Builtins in Clang/LLVM (authored by amyk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87671

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/p10-string-ops.ll

Index: llvm/test/CodeGen/PowerPC/p10-string-ops.ll
===
--- llvm/test/CodeGen/PowerPC/p10-string-ops.ll
+++ llvm/test/CodeGen/PowerPC/p10-string-ops.ll
@@ -2,6 +2,9 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
 ; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
 ; RUN:   FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
 
 ; These test cases aim to test the vector string isolate builtins on Power10.
 
@@ -27,3 +30,97 @@
   %tmp = tail call <16 x i8> @llvm.ppc.altivec.vclrrb(<16 x i8> %a, i32 %n)
   ret <16 x i8> %tmp
 }
+
+declare <16 x i8> @llvm.ppc.altivec.vstribr(<16 x i8>)
+declare <16 x i8> @llvm.ppc.altivec.vstribl(<16 x i8>)
+declare <8 x i16> @llvm.ppc.altivec.vstrihr(<8 x i16>)
+declare <8 x i16> @llvm.ppc.altivec.vstrihl(<8 x i16>)
+
+declare i32 @llvm.ppc.altivec.vstribr.p(i32, <16 x i8>)
+declare i32 @llvm.ppc.altivec.vstribl.p(i32, <16 x i8>)
+declare i32 @llvm.ppc.altivec.vstrihr.p(i32, <8 x i16>)
+declare i32 @llvm.ppc.altivec.vstrihl.p(i32, <8 x i16>)
+
+define <16 x i8> @test_vstribr(<16 x i8> %a) {
+; CHECK-LABEL: test_vstribr:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstribr v2, v2
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call <16 x i8> @llvm.ppc.altivec.vstribr(<16 x i8> %a)
+  ret <16 x i8> %tmp
+}
+
+define <16 x i8> @test_vstribl(<16 x i8> %a) {
+; CHECK-LABEL: test_vstribl:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstribl v2, v2
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call <16 x i8> @llvm.ppc.altivec.vstribl(<16 x i8>%a)
+  ret <16 x i8> %tmp
+}
+
+define <8 x i16> @test_vstrihr(<8 x i16> %a) {
+; CHECK-LABEL: test_vstrihr:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstrihr v2, v2
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call <8 x i16> @llvm.ppc.altivec.vstrihr(<8 x i16> %a)
+  ret <8 x i16> %tmp
+}
+
+define <8 x i16> @test_vstrihl(<8 x i16> %a) {
+; CHECK-LABEL: test_vstrihl:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstrihl v2, v2
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call <8 x i16> @llvm.ppc.altivec.vstrihl(<8 x i16> %a)
+  ret <8 x i16> %tmp
+}
+
+define i32 @test_vstribr_p(<16 x i8> %a) {
+; CHECK-LABEL: test_vstribr_p:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstribr. v2, v2
+; CHECK-NEXT:setbc r3, 4*cr6+eq
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call i32 @llvm.ppc.altivec.vstribr.p(i32 1, <16 x i8> %a)
+  ret i32 %tmp
+}
+
+define i32 @test_vstribl_p(<16 x i8> %a) {
+; CHECK-LABEL: test_vstribl_p:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstribl. v2, v2
+; CHECK-NEXT:setbc r3, 4*cr6+eq
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call i32 @llvm.ppc.altivec.vstribl.p(i32 1, <16 x i8> %a)
+  ret i32 %tmp
+}
+
+define i32 @test_vstrihr_p(<8 x i16> %a) {
+; CHECK-LABEL: test_vstrihr_p:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstrihr. v2, v2
+; CHECK-NEXT:setbc r3, 4*cr6+eq
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call i32 @llvm.ppc.altivec.vstrihr.p(i32 1, <8 x i16> %a)
+  ret i32 %tmp
+}
+
+define i32 @test_vstrihl_p(<8 x i16> %a) {
+; CHECK-LABEL: test_vstrihl_p:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vstrihl. v2, v2
+; CHECK-NEXT:setbc r3, 4*cr6+eq
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call i32 @llvm.ppc.altivec.vstrihl.p(i32 1, <8 x i16> %a)
+  ret i32 %tmp
+}
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -1020,13 +1020,21 @@
   v16i8:$VRB, 
   i32:$SH))]>;
   defm VSTRIBR : VXForm_VTB5_RCr<13, 1, (outs vrrc:$vT), (ins vrrc:$vB),
- "vstribr", "$vT, $vB", IIC_VecGeneral, []>;
+ "vstribr", "$vT, $vB", IIC_VecGeneral,
+ [(set v16i8:$vT,
+   (int_ppc_altivec_vstribr v16i8:$vB))]>;
   defm VSTRIBL : VXForm_VTB5_RCr<13, 0, (outs v

[clang] b314705 - [PowerPC] Implement the 128-bit Vector Divide Extended Builtins in Clang/LLVM

2020-09-22 Thread Amy Kwan via cfe-commits

Author: Amy Kwan
Date: 2020-09-22T11:31:44-05:00
New Revision: b3147058dec7d42ae0284d6e6edf25eb762c8b89

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

LOG: [PowerPC] Implement the 128-bit Vector Divide Extended Builtins in 
Clang/LLVM

This patch implements the 128-bit vector divide extended builtins in Clang/LLVM.
These builtins map to the vdivesq and vdiveuq instructions respectively.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-p10vector.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCInstrPrefix.td
llvm/test/CodeGen/PowerPC/p10-vector-divide.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 777932a2e910..dea547a6e121 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -315,6 +315,8 @@ BUILTIN(__builtin_altivec_vdivesw, "V4SiV4SiV4Si", "")
 BUILTIN(__builtin_altivec_vdiveuw, "V4UiV4UiV4Ui", "")
 BUILTIN(__builtin_altivec_vdivesd, "V2LLiV2LLiV2LLi", "")
 BUILTIN(__builtin_altivec_vdiveud, "V2ULLiV2ULLiV2ULLi", "")
+BUILTIN(__builtin_altivec_vdivesq, "V1SLLLiV1SLLLiV1SLLLi", "")
+BUILTIN(__builtin_altivec_vdiveuq, "V1ULLLiV1ULLLiV1ULLLi", "")
 
 // P10 Vector Multiply High built-ins.
 BUILTIN(__builtin_altivec_vmulhsw, "V4SiV4SiV4Si", "")

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 905d06bdae68..010a00e15b74 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -3366,6 +3366,16 @@ static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_dive(vector unsigned long long __a, vector unsigned long long __b) {
   return __builtin_altivec_vdiveud(__a, __b);
 }
+
+static __inline__ vector unsigned __int128 __ATTRS_o_ai
+vec_dive(vector unsigned __int128 __a, vector unsigned __int128 __b) {
+  return __builtin_altivec_vdiveuq(__a, __b);
+}
+
+static __inline__ vector signed __int128 __ATTRS_o_ai
+vec_dive(vector signed __int128 __a, vector signed __int128 __b) {
+  return __builtin_altivec_vdivesq(__a, __b);
+}
 #endif
 
 #ifdef __POWER10_VECTOR__

diff  --git a/clang/test/CodeGen/builtins-ppc-p10vector.c 
b/clang/test/CodeGen/builtins-ppc-p10vector.c
index 8557446de800..2f96cdfd9d68 100644
--- a/clang/test/CodeGen/builtins-ppc-p10vector.c
+++ b/clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -106,6 +106,18 @@ vector unsigned long long test_vec_dive_ull(void) {
   return vec_dive(vulla, vullb);
 }
 
+vector unsigned __int128 test_vec_dive_u128(void) {
+  // CHECK: @llvm.ppc.altivec.vdiveuq(<1 x i128> %{{.+}}, <1 x i128> %{{.+}})
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_dive(vui128a, vui128b);
+}
+
+vector signed __int128 test_vec_dive_s128(void) {
+  // CHECK: @llvm.ppc.altivec.vdivesq(<1 x i128> %{{.+}}, <1 x i128> %{{.+}})
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_dive(vsi128a, vsi128b);
+}
+
 vector signed int test_vec_mulh_si(void) {
   // CHECK: @llvm.ppc.altivec.vmulhsw(<4 x i32> %{{.+}}, <4 x i32> %{{.+}})
   // CHECK-NEXT: ret <4 x i32>

diff  --git a/llvm/include/llvm/IR/IntrinsicsPowerPC.td 
b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
index dc7fa581fd45..79cf3efbfac4 100644
--- a/llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1007,6 +1007,8 @@ def int_ppc_altivec_vdivesw : 
PowerPC_Vec_WWW_Intrinsic<"vdivesw">;
 def int_ppc_altivec_vdiveuw : PowerPC_Vec_WWW_Intrinsic<"vdiveuw">;
 def int_ppc_altivec_vdivesd : PowerPC_Vec_DDD_Intrinsic<"vdivesd">;
 def int_ppc_altivec_vdiveud : PowerPC_Vec_DDD_Intrinsic<"vdiveud">;
+def int_ppc_altivec_vdivesq : PowerPC_Vec_QQQ_Intrinsic<"vdivesq">;
+def int_ppc_altivec_vdiveuq : PowerPC_Vec_QQQ_Intrinsic<"vdiveuq">;
 
 // Vector Multiply High Intrinsics.
 def int_ppc_altivec_vmulhsw : PowerPC_Vec_WWW_Intrinsic<"vmulhsw">;

diff  --git a/llvm/lib/Target/PowerPC/PPCInstrPrefix.td 
b/llvm/lib/Target/PowerPC/PPCInstrPrefix.td
index 351f08dadadb..114213321f35 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ b/llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -1427,9 +1427,13 @@ let Predicates = [IsISA3_1] in {
 "vdivuq $vD, $vA, $vB", IIC_VecGeneral,
 [(set v1i128:$vD, (udiv v1i128:$vA, v1i128:$vB))]>;
   def VDIVESQ : VXForm_1<779, (outs vrrc:$vD), (ins vrrc:$vA, vrrc:$vB),
- "vdivesq $vD, $vA, $vB", IIC_VecGeneral, []>;
+ "vdivesq $vD, $vA, $vB", IIC_VecGeneral,
+ [(set v1i128:$vD, (int_ppc_altivec_vdivesq v1i128:$vA,
+  v1i128:$vB))]>;
   def VDIVEUQ : VXForm_1<523, (outs

[PATCH] D87729: [PowerPC] Implement the 128-bit Vector Divide Extended Builtins in Clang/LLVM

2020-09-22 Thread Amy Kwan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3147058dec7: [PowerPC] Implement the 128-bit Vector Divide 
Extended Builtins in Clang/LLVM (authored by amyk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87729

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/p10-vector-divide.ll

Index: llvm/test/CodeGen/PowerPC/p10-vector-divide.ll
===
--- llvm/test/CodeGen/PowerPC/p10-vector-divide.ll
+++ llvm/test/CodeGen/PowerPC/p10-vector-divide.ll
@@ -9,6 +9,7 @@
 ; This test case aims to test the vector divide instructions on Power10.
 ; This includes the low order and extended versions of vector divide,
 ; that operate on signed and unsigned words and doublewords.
+; This also includes 128 bit vector divide instructions.
 
 define <2 x i64> @test_vdivud(<2 x i64> %a, <2 x i64> %b) {
 ; CHECK-LABEL: test_vdivud:
@@ -113,3 +114,25 @@
   %div = tail call <2 x i64> @llvm.ppc.altivec.vdiveud(<2 x i64> %a, <2 x i64> %b)
   ret <2 x i64> %div
 }
+
+declare <1 x i128> @llvm.ppc.altivec.vdivesq(<1 x i128>, <1 x i128>) nounwind readnone
+declare <1 x i128> @llvm.ppc.altivec.vdiveuq(<1 x i128>, <1 x i128>) nounwind readnone
+
+define <1 x i128> @test_vdivesq(<1 x i128> %x, <1 x i128> %y) nounwind readnone {
+; CHECK-LABEL: test_vdivesq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vdivesq v2, v2, v3
+; CHECK-NEXT:blr
+  %tmp = tail call <1 x i128> @llvm.ppc.altivec.vdivesq(<1 x i128> %x, <1 x i128> %y)
+  ret <1 x i128> %tmp
+}
+
+
+define <1 x i128> @test_vdiveuq(<1 x i128> %x, <1 x i128> %y) nounwind readnone {
+; CHECK-LABEL: test_vdiveuq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vdiveuq v2, v2, v3
+; CHECK-NEXT:blr
+  %tmp = call <1 x i128> @llvm.ppc.altivec.vdiveuq(<1 x i128> %x, <1 x i128> %y)
+  ret <1 x i128> %tmp
+}
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -1427,9 +1427,13 @@
 "vdivuq $vD, $vA, $vB", IIC_VecGeneral,
 [(set v1i128:$vD, (udiv v1i128:$vA, v1i128:$vB))]>;
   def VDIVESQ : VXForm_1<779, (outs vrrc:$vD), (ins vrrc:$vA, vrrc:$vB),
- "vdivesq $vD, $vA, $vB", IIC_VecGeneral, []>;
+ "vdivesq $vD, $vA, $vB", IIC_VecGeneral,
+ [(set v1i128:$vD, (int_ppc_altivec_vdivesq v1i128:$vA,
+			   v1i128:$vB))]>;
   def VDIVEUQ : VXForm_1<523, (outs vrrc:$vD), (ins vrrc:$vA, vrrc:$vB),
- "vdiveuq $vD, $vA, $vB", IIC_VecGeneral, []>;
+ "vdiveuq $vD, $vA, $vB", IIC_VecGeneral,
+ [(set v1i128:$vD, (int_ppc_altivec_vdiveuq v1i128:$vA,
+			   v1i128:$vB))]>;
   def VCMPEQUQ : VCMP <455, "vcmpequq $vD, $vA, $vB" , v1i128>;
   def VCMPGTSQ : VCMP <903, "vcmpgtsq $vD, $vA, $vB" , v1i128>;
   def VCMPGTUQ : VCMP <647, "vcmpgtuq $vD, $vA, $vB" , v1i128>;
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -1007,6 +1007,8 @@
 def int_ppc_altivec_vdiveuw : PowerPC_Vec_WWW_Intrinsic<"vdiveuw">;
 def int_ppc_altivec_vdivesd : PowerPC_Vec_DDD_Intrinsic<"vdivesd">;
 def int_ppc_altivec_vdiveud : PowerPC_Vec_DDD_Intrinsic<"vdiveud">;
+def int_ppc_altivec_vdivesq : PowerPC_Vec_QQQ_Intrinsic<"vdivesq">;
+def int_ppc_altivec_vdiveuq : PowerPC_Vec_QQQ_Intrinsic<"vdiveuq">;
 
 // Vector Multiply High Intrinsics.
 def int_ppc_altivec_vmulhsw : PowerPC_Vec_WWW_Intrinsic<"vmulhsw">;
Index: clang/test/CodeGen/builtins-ppc-p10vector.c
===
--- clang/test/CodeGen/builtins-ppc-p10vector.c
+++ clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -106,6 +106,18 @@
   return vec_dive(vulla, vullb);
 }
 
+vector unsigned __int128 test_vec_dive_u128(void) {
+  // CHECK: @llvm.ppc.altivec.vdiveuq(<1 x i128> %{{.+}}, <1 x i128> %{{.+}})
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_dive(vui128a, vui128b);
+}
+
+vector signed __int128 test_vec_dive_s128(void) {
+  // CHECK: @llvm.ppc.altivec.vdivesq(<1 x i128> %{{.+}}, <1 x i128> %{{.+}})
+  // CHECK-NEXT: ret <1 x i128>
+  return vec_dive(vsi128a, vsi128b);
+}
+
 vector signed int test_vec_mulh_si(void) {
   // CHECK: @llvm.ppc.altivec.vmulhsw(<4 x i32> %{{.+}}, <4 x i32> %{{.+}})
   // CHECK-NEXT: ret <4 x i32>
Index: clang/lib/Headers/altivec.h
===

[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

Thanks for looking.  Indeed, it looks like an issue with the disk being full on 
the bot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

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


[clang] 079757b - [PowerPC] Implement Vector String Isolate Builtins in Clang/LLVM

2020-09-22 Thread Amy Kwan via cfe-commits

Author: Amy Kwan
Date: 2020-09-22T11:31:44-05:00
New Revision: 079757b551f3ab5218af7344a7ab3c79976ec478

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

LOG: [PowerPC] Implement Vector String Isolate Builtins in Clang/LLVM

This patch implements the vector string isolate (predicate and non-predicate
versions) builtins. The predicate builtins are custom selected within 
PPCISelDAGToDAG.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-p10vector.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
llvm/lib/Target/PowerPC/PPCInstrPrefix.td
llvm/test/CodeGen/PowerPC/p10-string-ops.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index dea547a6e121..b571454cfc7a 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -348,6 +348,16 @@ BUILTIN(__builtin_altivec_mtvsrqm, "V1ULLLiULLi", "")
 BUILTIN(__builtin_altivec_vpdepd, "V2ULLiV2ULLiV2ULLi", "")
 BUILTIN(__builtin_altivec_vpextd, "V2ULLiV2ULLiV2ULLi", "")
 
+// P10 Vector String Isolate Built-ins.
+BUILTIN(__builtin_altivec_vstribr, "V16cV16c", "")
+BUILTIN(__builtin_altivec_vstribl, "V16cV16c", "")
+BUILTIN(__builtin_altivec_vstrihr, "V8sV8s", "")
+BUILTIN(__builtin_altivec_vstrihl, "V8sV8s", "")
+BUILTIN(__builtin_altivec_vstribr_p, "iiV16c", "")
+BUILTIN(__builtin_altivec_vstribl_p, "iiV16c", "")
+BUILTIN(__builtin_altivec_vstrihr_p, "iiV8s", "")
+BUILTIN(__builtin_altivec_vstrihl_p, "iiV8s", "")
+
 // P10 Vector Centrifuge built-in.
 BUILTIN(__builtin_altivec_vcfuged, "V2ULLiV2ULLiV2ULLi", "")
 

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 010a00e15b74..2c09e477bd3c 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -17636,6 +17636,150 @@ vec_test_lsbb_all_zeros(vector unsigned char __a) {
 }
 #endif /* __VSX__ */
 
+/* vec_stril */
+
+static __inline__ vector unsigned char __ATTRS_o_ai
+vec_stril(vector unsigned char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribr((vector signed char)__a);
+#else
+  return __builtin_altivec_vstribl((vector signed char)__a);
+#endif
+}
+
+static __inline__ vector signed char __ATTRS_o_ai
+vec_stril(vector signed char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribr(__a);
+#else
+  return __builtin_altivec_vstribl(__a);
+#endif
+}
+
+static __inline__ vector unsigned short __ATTRS_o_ai
+vec_stril(vector unsigned short __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstrihr((vector signed short)__a);
+#else
+  return __builtin_altivec_vstrihl((vector signed short)__a);
+#endif
+}
+
+static __inline__ vector signed short __ATTRS_o_ai
+vec_stril(vector signed short __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstrihr(__a);
+#else
+  return __builtin_altivec_vstrihl(__a);
+#endif
+}
+
+/* vec_stril_p */
+
+static __inline__ int __ATTRS_o_ai vec_stril_p(vector unsigned char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribr_p(__CR6_EQ, (vector signed char)__a);
+#else
+  return __builtin_altivec_vstribl_p(__CR6_EQ, (vector signed char)__a);
+#endif
+}
+
+static __inline__ int __ATTRS_o_ai vec_stril_p(vector signed char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribr_p(__CR6_EQ, __a);
+#else
+  return __builtin_altivec_vstribl_p(__CR6_EQ, __a);
+#endif
+}
+
+static __inline__ int __ATTRS_o_ai vec_stril_p(vector unsigned short __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstrihr_p(__CR6_EQ, (vector signed short)__a);
+#else
+  return __builtin_altivec_vstrihl_p(__CR6_EQ, (vector signed short)__a);
+#endif
+}
+
+static __inline__ int __ATTRS_o_ai vec_stril_p(vector signed short __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstrihr_p(__CR6_EQ, __a);
+#else
+  return __builtin_altivec_vstrihl_p(__CR6_EQ, __a);
+#endif
+}
+
+/* vec_strir */
+
+static __inline__ vector unsigned char __ATTRS_o_ai
+vec_strir(vector unsigned char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribl((vector signed char)__a);
+#else
+  return __builtin_altivec_vstribr((vector signed char)__a);
+#endif
+}
+
+static __inline__ vector signed char __ATTRS_o_ai
+vec_strir(vector signed char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstribl(__a);
+#else
+  return __builtin_altivec_vstribr(__a);
+#endif
+}
+
+static __inline__ vector unsigned short __ATTRS_o_ai
+vec_strir(vector unsigned short __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vstrihl((vector signed short)__a);
+#else
+  

Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Sriraman Tallam via cfe-commits
On Tue, Sep 22, 2020 at 8:34 AM Fāng-ruì Sòng  wrote:
>
> FWIW I tested check-msan in a -DCMAKE_BUILD_TYPE=Release build on a
> powerpc64le machine. All tests passed. I cannot connect the failure to
> the clang patch.

Thanks for doing this! Much appreciated!

>
> On Mon, Sep 21, 2020 at 10:02 PM Sriraman Tallam  wrote:
> >
> > On Mon, Sep 21, 2020 at 5:58 PM Matt Morehouse via Phabricator
> >  wrote:
> > >
> > > morehouse added a comment.
> > >
> > > This change appears to trigger an assertion failure in sysmsg.c on the 
> > > PPC bot:  
> > > http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/26845/steps/ninja%20check%
> > >
> > >    TEST 'SanitizerCommon-msan-powerpc64le-Linux :: 
> > > Linux/sysmsg.c' FAILED 
> > >   Script:
> > >   --
> > >   : 'RUN: at line 1';  
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang
> > >   -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections  -ldl 
> > > -O1 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c
> > >  -o 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >  &&  
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >   --
> > >   Exit Code: 134
> > >
> > >   Command Output (stderr):
> > >   --
> > >   sysmsg.c.tmp: 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:14:
> > >  int main(): Assertion `msgq != -1' failed.
> > >   
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.script:
> > >  line 1: 2982426 Aborted (core dumped) 
> > > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> > >
> > >   --
> > >
> > > It's not immediately obvious to me what is going wrong.  If you could 
> > > take a look, I'd appreciate it.  Otherwise I will look closer tomorrow.
> >
> > I am having trouble getting access to a PPC machine,  this is going to
> > take me longer. Should I revert the patch?
> >
> > Thanks
> > Sri
> >
> > >
> > >
> > > Repository:
> > >   rG LLVM Github Monorepo
> > >
> > > CHANGES SINCE LAST ACTION
> > >   https://reviews.llvm.org/D87921/new/
> > >
> > > https://reviews.llvm.org/D87921
> > >
>
>
>
> --
> 宋方睿
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked an inline comment as done.
eduucaldas added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:224
+  /// "a, b  c"  <=> [("a", ","), ("b", nul), ("c", nul)]
+  /// "a, b,"<=> [("a", ","), ("b", ","), (nul, nul)]
   ///

gribozavr2 wrote:
> I'd slightly prefer "null" b/c "nul" refers to the ASCII character. Feel free 
> to add more spaces to make columns line up :)
Thanks for providing my solution to my crazyness ^^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87839

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


[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293490.
eduucaldas added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87839

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
+#include "llvm/ADT/STLExtras.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -122,4 +124,231 @@
   }
 }
 
+class ListTest : public SyntaxTreeTest {
+private:
+  std::string dumpQuotedTokensOrNull(const Node *N) {
+return N ? "'" +
+   StringRef(N->dumpTokens(Arena->getSourceManager()))
+   .trim()
+   .str() +
+   "'"
+ : "null";
+  }
+
+protected:
+  std::string
+  dumpElementsAndDelimiters(ArrayRef> EDs) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(
+EDs, OS, [&OS, this](const List::ElementAndDelimiter &ED) {
+  OS << "(" << dumpQuotedTokensOrNull(ED.element) << ", "
+ << dumpQuotedTokensOrNull(ED.delimiter) << ")";
+});
+
+OS << "]";
+
+return OS.str();
+  }
+
+  std::string dumpNodes(ArrayRef Nodes) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(Nodes, OS, [&OS, this](const Node *N) {
+  OS << dumpQuotedTokensOrNull(N);
+});
+
+OS << "]";
+
+return OS.str();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, ListTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", null)]
+TEST_P(ListTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', 'b', 'c']");
+}
+
+/// "a,  , c"  <=> [("a", ","), (null, ","), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), (null, ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', null, 'c']");
+}
+
+/// "a, b  c"  <=> [("a", ","), ("b", null), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingDelimiter) {
+  buildTree("", GetParam());
+
+  // "a, b  c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', null), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()), "['a', 'b', 'c']");
+}
+
+/// "a, b,"<=> [("a", ","), ("b", ","), (null, null)]
+TEST_P(ListTest, List_Separated_MissingLastElement) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  },
+  NodeKind::Ca

[PATCH] D87839: [SyntaxTree] Test the List API

2020-09-22 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293489.
eduucaldas marked 3 inline comments as done.
eduucaldas added a comment.

Answer code review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87839

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/Tooling/Syntax/Tree.h"
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
+#include "llvm/ADT/STLExtras.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -122,4 +124,239 @@
   }
 }
 
+class ListTest : public SyntaxTreeTest {
+private:
+  std::string dumpQuotedTokensOrNull(const Node *N) {
+return N ? "'" +
+   StringRef(N->dumpTokens(Arena->getSourceManager()))
+   .trim()
+   .str() +
+   "'"
+ : "null";
+  }
+
+protected:
+  std::string
+  dumpElementsAndDelimiters(ArrayRef> EDs) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(
+EDs, OS, [&OS, this](const List::ElementAndDelimiter &ED) {
+  OS << "(" << dumpQuotedTokensOrNull(ED.element) << ", "
+ << dumpQuotedTokensOrNull(ED.delimiter) << ")";
+});
+
+OS << "]";
+
+return OS.str();
+  }
+
+  std::string dumpNodes(ArrayRef Nodes) {
+std::string Storage;
+llvm::raw_string_ostream OS(Storage);
+
+OS << "[";
+
+llvm::interleaveComma(Nodes, OS, [&OS, this](const Node *N) {
+  OS << dumpQuotedTokensOrNull(N);
+});
+
+OS << "]";
+
+return OS.str();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, ListTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+/// "a, b, c"  <=> [("a", ","), ("b", ","), ("c", null)]
+TEST_P(ListTest, List_Separated_WellFormed) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()),
+"['a', 'b', 'c']");
+}
+
+/// "a,  , c"  <=> [("a", ","), (null, ","), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingElement) {
+  buildTree("", GetParam());
+
+  // "a,  , c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), (null, ','), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()),
+"['a', null, 'c']");
+}
+
+/// "a, b  c"  <=> [("a", ","), ("b", null), ("c", null)]
+TEST_P(ListTest, List_Separated_MissingDelimiter) {
+  buildTree("", GetParam());
+
+  // "a, b  c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::identifier, "c"), NodeRole::ListElement},
+  },
+  NodeKind::CallArguments));
+
+  EXPECT_EQ(dumpElementsAndDelimiters(List->getElementsAsNodesAndDelimiters()),
+"[('a', ','), ('b', null), ('c', null)]");
+  EXPECT_EQ(dumpNodes(List->getElementsAsNodes()),
+"['a', 'b', 'c']");
+}
+
+/// "a, b,"<=> [("a", ","), ("b", ","), (null, null)]
+TEST_P(ListTest, List_Separated_MissingLastElement) {
+  buildTree("", GetParam());
+
+  // "a, b, c"
+  auto *List = dyn_cast(syntax::createTree(
+  *Arena,
+  {
+  {createLeaf(*Arena, tok::identifier, "a"), NodeRole::ListElement},
+  {createLeaf(*Arena, tok::comma), NodeRole::ListDelimiter},
+  {createLeaf(*Arena, tok::identifier, "b"), NodeRole::ListElement

[PATCH] D88103: [JSON] Add error reporting facility, used in fromJSON and ObjectMapper.

2020-09-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: clayborg, kadircet, wallace.
Herald added subscribers: llvm-commits, cfe-commits, usaxena95, arphaman, 
mgrang, hiraditya.
Herald added projects: clang, LLVM.
sammccall requested review of this revision.
Herald added a subscriber: ilya-biryukov.

Translating between JSON objects and C++ strutctures is common.
>From experience in clangd, fromJSON/ObjectMapper work well and save a lot of
code, but aren't adopted elsewhere at least partly due to total lack of error
reporting beyond "ok"/"bad".

This new error model should be rich enough for most applications. It comprises:

- a name for the root object, so the user knows what we're parsing
- a path from the root object to the JSON node most associated with the error
- a local error message

These can be presented in two ways:

- An llvm::Error like "expected string at ConfigFile.credentials[0].username"
- A truncated dump of the original object with the error marked, like: { 
"credentials": [ { "username": /* error: expected string */ 42, "password": 
"secret" }, { ... } ] "backups": { ... } }

To track the locations, we exploit the fact that the call graph of recursive
parse functions mirror the structure of the JSON itself.
The current path is represented as a linked list of segments, each of which is
on the stack as a parameter. Concretely, fromJSON now looks like:

  bool fromJSON(const Value&, T&, Path);

The heavy parts mostly stay out of the way:

- building path segments is mostly handled in library code for common cases 
(arrays mapped as std::vector, objects mapped using ObjectMapper)
- no heap allocation at all unless an error is encountered, then one small one
- llvm::Error and error-in-context are created only if needed

The general top-level interface (Path::Root) is independent of fromJSON etc, and
ends up being a bit clunky.
I've added high-level parse(StringRef) -> Expected, but it's not general
enough to be the primary interface I think (at least, not usable in clangd).

---

This can be split into several separate patches if desired:

- the comment support in json::OStream (used to show errors in context)
- the Path type, including llvm::Error representation
- the fromJSON/ObjectMapper changes (and clangd usages - hard to separate)
- support for printing errors in context

I wanted to show it all together first, though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88103

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Index.h
  llvm/include/llvm/Support/JSON.h
  llvm/lib/Support/JSON.cpp
  llvm/unittests/Support/JSONTest.cpp

Index: llvm/unittests/Support/JSONTest.cpp
===
--- llvm/unittests/Support/JSONTest.cpp
+++ llvm/unittests/Support/JSONTest.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Error.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -372,8 +373,8 @@
   return OS << "(" << S.S << ", " << (S.I ? std::to_string(*S.I) : "None")
 << ", " << S.B << ")";
 }
-bool fromJSON(const Value &E, CustomStruct &R) {
-  ObjectMapper O(E);
+bool fromJSON(const Value &E, CustomStruct &R, Path P) {
+  ObjectMapper O(E, P);
   if (!O || !O.map("str", R.S) || !O.map("int", R.I))
 return false;
   O.map("bool", R.B);
@@ -403,16 +404,80 @@
   CustomStruct("bar", llvm::None, false),
   CustomStruct("baz", llvm::None, false),
   };
-  ASSERT_TRUE(fromJSON(J, R));
+  Path::Root Root("CustomStruct");
+  ASSERT_TRUE(fromJSON(J, R, Root));
   EXPECT_EQ(R, Expected);
 
   CustomStruct V;
-  EXPECT_FALSE(fromJSON(nullptr, V)) << "Not an object " << V;
-  EXPECT_FALSE(fromJSON(Object{}, V)) << "Missing required field " << V;
-  EXPECT_FALSE(fromJSON(Object{{"str", 1}}, V)) << "Wrong type " << V;
+  EXPECT_FALSE(fromJSON(nullptr, V, Root));
+  EXPECT_EQ("expected object when parsing CustomStruct",
+toString(Root.getError()));
+
+  EXPECT_FALSE(fromJSON(Object{}, V, Root));
+  EXPECT_EQ("missing value at CustomStruct.str", toString(Root.getError()));
+
+  EXPECT_FALSE(fromJSON(Object{{"str", 1}}, V, Root));
+  EXPECT_EQ("expected string at CustomStruct.str", toString(Root.getError()));
+
   // Optional must parse as the correct type if present.
-  EXPECT_FALSE(fromJSON(Object{{"str", 1}, {"int", "string"}}, V))
-  << "Wrong type for Optional " << V;
+  EXPECT_FALSE(fromJSON(Object{{"str", "1"}, {"int", "string"}}, V, Root));
+  EXPECT_EQ("expected integer at CustomStruct.int", toString(Root.getError()));
+}
+
+static std::string errorContext(const Value &V, const Path::Root &R) {
+  std::string Context;
+  llvm::raw_string_ostream OS(Context);
+  R.printErrorContext(V, OS);
+  return OS.str(

[PATCH] D86819: [PowerPC][Power10] Implementation of 128-bit Binary Vector Rotate builtins

2020-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 293474.
Conanap marked 2 inline comments as done.
Conanap added a comment.

Changed implementation for vrlqnm as per Nemanja


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

https://reviews.llvm.org/D86819

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/p10-vector-rotate.ll

Index: llvm/test/CodeGen/PowerPC/p10-vector-rotate.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/p10-vector-rotate.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
+
+; This test case aims to test the builtins for vector rotate instructions
+; on Power10.
+
+
+define <1 x i128> @test_vrlq(<1 x i128> %x, <1 x i128> %y) {
+; CHECK-LABEL: test_vrlq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vrlq v2, v3, v2
+; CHECK-NEXT:blr
+  %shl.i = shl <1 x i128> %y, %x
+  %sub.i = sub <1 x i128> , %x
+  %lshr.i = lshr <1 x i128> %y, %sub.i
+  %tmp = or <1 x i128> %shl.i, %lshr.i
+  ret <1 x i128> %tmp
+}
+
+define <1 x i128> @test_vrlq_cost_mult8(<1 x i128> %x) {
+; CHECK-LABEL: test_vrlq_cost_mult8:
+; CHECK: # %bb.0:
+; CHECK: vrlq v2, v3, v2
+; CHECK-NEXT: blr
+  %shl.i = shl <1 x i128> , %x
+  %sub.i = sub <1 x i128> , %x
+  %lshr.i = lshr <1 x i128> , %sub.i
+  %tmp = or <1 x i128> %shl.i, %lshr.i
+  ret <1 x i128> %tmp
+}
+
+define <1 x i128> @test_vrlq_cost_non_mult8(<1 x i128> %x) {
+; CHECK-LABEL: test_vrlq_cost_non_mult8:
+; CHECK: # %bb.0:
+; CHECK: vrlq v2, v3, v2
+; CHECK-NEXT: blr
+  %shl.i = shl <1 x i128> , %x
+  %sub.i = sub <1 x i128> , %x
+  %lshr.i = lshr <1 x i128> , %sub.i
+  %tmp = or <1 x i128> %shl.i, %lshr.i
+  ret <1 x i128> %tmp
+}
+
+; Function Attrs: nounwind readnone
+define <1 x i128> @test_vrlqmi(<1 x i128> %a, <1 x i128> %b, <1 x i128> %c) {
+; CHECK-LABEL: test_vrlqmi:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vrlqmi v3, v2, v4
+; CHECK-NEXT:vmr v2, v3
+; CHECK-NEXT:blr
+entry:
+  %tmp = tail call <1 x i128> @llvm.ppc.altivec.vrlqmi(<1 x i128> %a, <1 x i128> %c, <1 x i128> %b)
+  ret <1 x i128> %tmp
+}
+
+; Function Attrs: nounwind readnone
+define <1 x i128> @test_vrlqnm(<1 x i128> %a, <1 x i128> %b, <1 x i128> %c) {
+; CHECK-LABEL: test_vrlqnm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vrlqnm v2, v2, v3
+; CHECK-NEXT:xxland v2, v2, v4
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call <1 x i128> @llvm.ppc.altivec.vrlqnm(<1 x i128> %a, <1 x i128> %b)
+  %tmp = and <1 x i128> %0, %c
+  ret <1 x i128> %tmp
+}
+
+; Function Attrs: nounwind readnone
+declare <1 x i128> @llvm.ppc.altivec.vrlqmi(<1 x i128>, <1 x i128>, <1 x i128>)
+
+; Function Attrs: nounwind readnone
+declare <1 x i128> @llvm.ppc.altivec.vrlqnm(<1 x i128>, <1 x i128>)
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -1446,19 +1446,25 @@
"vcmpuq $BF, $vA, $vB", IIC_VecGeneral, []>;
   def VCMPSQ : VXForm_BF3_VAB5<321, (outs crrc:$BF), (ins vrrc:$vA, vrrc:$vB),
"vcmpsq $BF, $vA, $vB", IIC_VecGeneral, []>;
-  def VRLQNM : VX1_VT5_VA5_VB5<325, "vrlqnm", []>;
-  def VRLQMI : VXForm_1<69, (outs vrrc:$vD),
-(ins vrrc:$vA, vrrc:$vB, vrrc:$vDi),
-"vrlqmi $vD, $vA, $vB", IIC_VecFP, []>,
-RegConstraint<"$vDi = $vD">, NoEncode<"$vDi">;
   def VSLQ : VX1_VT5_VA5_VB5<261, "vslq", []>;
   def VSRAQ : VX1_VT5_VA5_VB5<773, "vsraq", []>;
   def VSRQ : VX1_VT5_VA5_VB5<517, "vsrq", []>;
-  def VRLQ : VX1_VT5_VA5_VB5<5, "vrlq", []>;
   def XSCVQPUQZ : X_VT5_XO5_VB5<63, 0, 836, "xscvqpuqz", []>;
   def XSCVQPSQZ : X_VT5_XO5_VB5<63, 8, 836, "xscvqpsqz", []>;
   def XSCVUQQP : X_VT5_XO5_VB5<63, 3, 836, "xscvuqqp", []>;
   def XSCVSQQP : X_VT5_XO5_VB5<63, 11, 836, "xscvsqqp", []>;
+  def VRLQ : VX1_VT5_VA5_VB5<5, "vrlq", []>;
+  def VRLQNM : VX1_VT5_VA5_VB5<325, "vrlqnm",
+   [(set v1i128:$vD,
+   (int_ppc_altivec_vrlqnm v1i128:$vA,
+   v1i128:$vB))]>;
+  def VRLQMI : VXForm_1<69, (outs vrrc:$vD),
+(ins vrrc:$vA, vrrc:$vB, vrrc:$vDi),
+"vrlqmi $vD, $vA, $vB", IIC_VecFP,
+[(set v1i128:$vD,
+   (int_ppc_altivec_vrlqmi v1i128:$vA, v1i128:$vB,
+  

[clang] 9bb5ecf - Sema: introduce `__attribute__((__swift_name__))`

2020-09-22 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2020-09-22T15:32:23Z
New Revision: 9bb5ecf1f760e1b1fe4697189e4db99100baffad

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

LOG: Sema: introduce `__attribute__((__swift_name__))`

This introduces the new `swift_name` attribute that allows annotating
APIs with an alternate spelling for Swift.  This is used as part of the
importing mechanism to allow interfaces to be imported with a new name
into Swift.  It takes a parameter which is the Swift function name.
This parameter is validated to check if it matches the possible
transformed signature in Swift.

This is based on the work of the original changes in
https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c

Differential Revision: https://reviews.llvm.org/D87534
Reviewed By: Aaron Ballman, Dmitri Gribenko

Added: 
clang/test/SemaObjC/attr-swift_name.m

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c2073e68be2c..e8ac819c8b55 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2162,6 +2162,12 @@ def SwiftError : InheritableAttr {
   let Documentation = [SwiftErrorDocs];
 }
 
+def SwiftName : InheritableAttr {
+  let Spellings = [GNU<"swift_name">];
+  let Args = [StringArgument<"Name">];
+  let Documentation = [SwiftNameDocs];
+}
+
 def NoDeref : TypeAttr {
   let Spellings = [Clang<"noderef">];
   let Documentation = [NoDerefDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index aab337a4e24a..9c119218656d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3572,6 +3572,30 @@ The return type is left unmodified.
   }];
 }
 
+def SwiftNameDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_name";
+  let Content = [{
+The ``swift_name`` attribute provides the name of the declaration in Swift. If
+this attribute is absent, the name is transformed according to the algorithm
+built into the Swift compiler.
+
+The argument is a string literal that contains the Swift name of the function,
+variable, or type. When renaming a function, the name may be a compound Swift
+name.  For a type, enum constant, property, or variable declaration, the name
+must be a simple or qualified identifier.
+
+  .. code-block:: c
+
+@interface URL
+- (void) initWithString:(NSString *)s 
__attribute__((__swift_name__("URL.init(_:)")))
+@end
+
+void __attribute__((__swift_name__("squareRoot()"))) sqrt(double v) {
+}
+  }];
+}
+
 def OMPDeclareSimdDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "#pragma omp declare simd";

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d826e26bea53..a2f5aeafd457 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -557,6 +557,7 @@ def StringCompare : DiagGroup<"string-compare">;
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
 def StrncatSize : DiagGroup<"strncat-size">;
+def SwiftNameAttribute : DiagGroup<"swift-name-attribute">;
 def IntInBoolContext : DiagGroup<"int-in-bool-context">;
 def TautologicalTypeLimitCompare : 
DiagGroup<"tautological-type-limit-compare">;
 def TautologicalUnsignedZeroCompare : 
DiagGroup<"tautological-unsigned-zero-compare">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 053aae7a6afa..0cb817df9db3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3974,6 +3974,46 @@ def err_objc_bridged_related_known_method : Error<
 def err_objc_attr_protocol_requires_definition : Error<
   "attribute %0 can only be applied to @protocol definitions, not forward 
declarations">;
 
+// Swift attributes.
+def warn_attr_swift_name_function
+  : Warning<"%0 attribute argument must be a string literal specifying a Swift 
function name">,
+InGroup;
+def warn_attr_swift_name_invalid_identifier
+  : Warning<"%0 attribute has invalid identifier for the 
%select{base|context|parameter}1 name">,
+InGroup;
+def warn_attr_swift_name_decl_kind
+  : Warning<"%0 attribute cannot be applied to this declaration">,
+InGroup;
+def warn_attr_swift_name_subscript_invalid_parame

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
compnerd marked 4 inline comments as done.
Closed by commit rG9bb5ecf1f760: Sema: introduce 
`__attribute__((__swift_name__))` (authored by compnerd).

Changed prior to commit:
  https://reviews.llvm.org/D87534?vs=292548&id=293470#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_name.m

Index: clang/test/SemaObjC/attr-swift_name.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_name.m
@@ -0,0 +1,174 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s
+
+#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))
+
+typedef struct {
+  float x, y, z;
+} Point3D;
+
+__attribute__((__swift_name__("PType")))
+@protocol P
+@end
+
+__attribute__((__swift_name__("IClass")))
+@interface I
+- (instancetype)init SWIFT_NAME("init()");
+- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");
+
++ (void)refresh SWIFT_NAME("refresh()");
+
+- (instancetype)i SWIFT_NAME("i()");
+
+- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");
+- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");
+- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");
+
++ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
+
++ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2}}
+
++ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning
+
++ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning
++ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning
+
++ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (instancetype)specialI SWIFT_NAME("init(options:)");
++ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 2)}}
++ (instancetype)specialK SWIFT_NAME("init(_:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
++ (instancetype)specialL SWIFT_NAME("i(options:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
+
++ (instancetype)trailingParen SWIFT_NAME("foo(");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
++ (instancetype)trailingColon SWIFT_NAME("foo:");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
++ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for the base name}}
++ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for the parameter name}}
+
+@property(strong) id someProp SWIFT_NAME("prop");
+@end
+
+enum SWIFT_NAME("E") E {
+  value1,
+  value2,
+  value3 SWIFT_NAME("three"),
+  value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for the base name}}
+};
+
+struct SWIFT_NAME("TStruct") SStruct {
+  int i, j, k SWIFT_NAME("kay");
+};
+
+int i SWIFT_NAME("g_i");
+
+void f0(int i) SWIFT_NAME("f_0");
+// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}
+
+void f1(int i) SWIFT_NAME("f_1()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
+void f2(int i) SWIFT_NAME("f_2(a:b:)");
+// expected-warning@

[PATCH] D87774: [flang] Introduce DiagnosticConsumer classes in libflangFrontend

2020-09-22 Thread sameeran joshi via Phabricator via cfe-commits
sameeranjoshi added a comment.

Thanks for working on it.
Few comments inline:

1. For an out-of-tree build, I see `check-flang` target failing with

  /unittests/Frontend/CompilerInstanceTest.cpp:17:10: fatal error: filesystem: 
No such file or directory
   #include 
^~~~

I used gcc/g++ 7.5 version.
I haven't checked in-tree still, and others/bots might have checked it.

2. Either the documentation comments are wrong or code.

`README` mentions `DBUILD_FLANG_NEW_DRIVER` where as cmake ignores the flag for 
me.
Whereas, `CMakeLists.txt` mentions `FLANG_BUILD_NEW_DRIVER`.




Comment at: flang/include/flang/Frontend/TextDiagnosticBuffer.h:36
+  /// level and an index into the corresponding DiagList above.
+  std::vector> all_;
+

How about simplifying this with `using` keyword?



Comment at: flang/include/flang/Frontend/TextDiagnosticPrinter.h:37
+  /// Handle to the currently active text diagnostic emitter.
+  std::unique_ptr textDiag_;
+

Where is this used? I don't see any reference.



Comment at: flang/lib/Frontend/TextDiagnostic.cpp:12
+#include "llvm/Support/raw_ostream.h"
+#include 
+

Is this header used ?



Comment at: flang/lib/Frontend/TextDiagnostic.cpp:26
+static const enum llvm::raw_ostream::Colors savedColor =
+llvm::raw_ostream::SAVEDCOLOR;
+

Unless Flang is not changing the color scheme w.r.t clang, can't the code be 
shared between both projects?




Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:24
+
+TextDiagnosticPrinter::TextDiagnosticPrinter(
+raw_ostream &os, clang::DiagnosticOptions *diags)

A silly question from what I see usually in Flang coding style.
Why isn't it defined in header file?



Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:37
+  // this later as we print out the diagnostic to the terminal.
+  SmallString<100> outStr;
+  info.FormatDiagnostic(outStr);

kiranchandramohan wrote:
> 100? Will this contain path names by any chance?
Can we use at places where LLVM data structures are used explicit `llvm::` so 
an unknown user can easily identify where they come from?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87774

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 293466.
tianshilei1992 added a comment.

Fixed the case `target_teams_distribute_simd_codegen.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp
@@ -66,7 +66,11 @@
 #ifndef HEADER
 #define HEADER
 
-// CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CHECK-DAG: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %{{[^,]+}}, %{{[^,]+}} }
+// CHECK-32-DAG: [[KMP_PRIVATES_T]] = type { [3 x i64], [3 x i8*], [3 x i8*], [3 x i8*], i16 }
+// CHECK-64-DAG: [[KMP_PRIVATES_T]] = type { [3 x i8*], [3 x i8*], [3 x i64], [3 x i8*], i16 }
 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
 // CHECK-DAG: [[DEF_LOC:@.+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
 
@@ -132,33 +136,26 @@
   double cn[5][n];
   TT d;
 
-  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target_teams_nowait_mapper(i64 -1, i8* @{{[^,]+}}, i32 3, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[SIZET]], i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[MAPT]], i32 0, i32 0), i8** null, i32 {{[^,]+}}, i32 {{[^)]+}})
-  // CHECK-DAG:   [[BP]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[P]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX0:[0-9]+]]
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX0]]
-  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR0]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR0]]
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR1]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 [[IDX1:[0-9]+]]
-  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 [[IDX1]]
-  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CBPADDR2]]
-  // CHECK-DAG:   store i[[SZ]] %{{.+}}, i[[SZ]]* [[CPADDR2]]
-  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
-  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
-  // CHECK:   [[FAIL]]
-  // CHECK:   call void [[HVT0:@.+]](i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^)]+}})
-  // CHECK-NEXT:  br label %[[END]]
-  // CHECK:   [[END]]
+  // CHECK-DAG: call i32 @__kmpc_omp_task([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i8* [[TASK:%.+]])
+  // CHECK-32-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i32 84, i32 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-64-DAG:  [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 144, i64 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-DAG: [[TASK_CAST:%.+]] = bitcast i8* [[TASK

Re: [PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-22 Thread Fāng-ruì Sòng via cfe-commits
FWIW I tested check-msan in a -DCMAKE_BUILD_TYPE=Release build on a
powerpc64le machine. All tests passed. I cannot connect the failure to
the clang patch.

On Mon, Sep 21, 2020 at 10:02 PM Sriraman Tallam  wrote:
>
> On Mon, Sep 21, 2020 at 5:58 PM Matt Morehouse via Phabricator
>  wrote:
> >
> > morehouse added a comment.
> >
> > This change appears to trigger an assertion failure in sysmsg.c on the PPC 
> > bot:  
> > http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/26845/steps/ninja%20check%
> >
> >    TEST 'SanitizerCommon-msan-powerpc64le-Linux :: 
> > Linux/sysmsg.c' FAILED 
> >   Script:
> >   --
> >   : 'RUN: at line 1';  
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang 
> >  -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections  -ldl 
> > -O1 
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c
> >  -o 
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> >  &&  
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> >   --
> >   Exit Code: 134
> >
> >   Command Output (stderr):
> >   --
> >   sysmsg.c.tmp: 
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Linux/sysmsg.c:14:
> >  int main(): Assertion `msgq != -1' failed.
> >   
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.script:
> >  line 1: 2982426 Aborted (core dumped) 
> > /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/sysmsg.c.tmp
> >
> >   --
> >
> > It's not immediately obvious to me what is going wrong.  If you could take 
> > a look, I'd appreciate it.  Otherwise I will look closer tomorrow.
>
> I am having trouble getting access to a PPC machine,  this is going to
> take me longer. Should I revert the patch?
>
> Thanks
> Sri
>
> >
> >
> > Repository:
> >   rG LLVM Github Monorepo
> >
> > CHANGES SINCE LAST ACTION
> >   https://reviews.llvm.org/D87921/new/
> >
> > https://reviews.llvm.org/D87921
> >



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


[PATCH] D88100: [analyzer][StdLibraryFunctionsChecker] Separate the signature from the summaries

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

The signature should not be part of the summaries as many FIXME comments
suggests. By separating the signature, we open up the way to a generic
matching implementation which could be used later under the hoods of
CallDescriptionMap.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88100

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -442,10 +442,6 @@
   ///   rules for the given parameter's type, those rules are checked once the
   ///   signature is matched.
   class Summary {
-// FIXME Probably the Signature should not be part of the Summary,
-// We can remove once all overload of addToFunctionSummaryMap requires the
-// Signature explicitly given.
-Optional Sign;
 const InvalidationKind InvalidationKd;
 Cases CaseConstraints;
 ConstraintSet ArgConstraints;
@@ -455,18 +451,8 @@
 const FunctionDecl *FD = nullptr;
 
   public:
-Summary(ArgTypes ArgTys, RetType RetTy, InvalidationKind InvalidationKd)
-: Sign(Signature(ArgTys, RetTy)), InvalidationKd(InvalidationKd) {}
-
 Summary(InvalidationKind InvalidationKd) : InvalidationKd(InvalidationKd) {}
 
-// FIXME Remove, once all overload of addToFunctionSummaryMap requires the
-// Signature explicitly given.
-Summary &setSignature(const Signature &S) {
-  Sign = S;
-  return *this;
-}
-
 Summary &Case(ConstraintSet &&CS) {
   CaseConstraints.push_back(std::move(CS));
   return *this;
@@ -488,10 +474,8 @@
 
 // Returns true if the summary should be applied to the given function.
 // And if yes then store the function declaration.
-bool matchesAndSet(const FunctionDecl *FD) {
-  assert(Sign &&
- "Signature must be set before comparing to a FunctionDecl");
-  bool Result = Sign->matches(FD) && validateByConstraints(FD);
+bool matchesAndSet(const Signature &Sign, const FunctionDecl *FD) {
+  bool Result = Sign.matches(FD) && validateByConstraints(FD);
   if (Result) {
 assert(!this->FD && "FD must not be set more than once");
 this->FD = FD;
@@ -499,13 +483,6 @@
   return Result;
 }
 
-// FIXME Remove, once all overload of addToFunctionSummaryMap requires the
-// Signature explicitly given.
-bool hasInvalidSignature() {
-  assert(Sign && "Signature must be set before this query");
-  return Sign->isInvalid();
-}
-
   private:
 // Once we know the exact type of the function then do sanity check on all
 // the given constraints.
@@ -1007,9 +984,8 @@
 // to the found FunctionDecl only if the signatures match.
 //
 // Returns true if the summary has been added, false otherwise.
-// FIXME remove all overloads without the explicit Signature parameter.
-bool operator()(StringRef Name, Summary S) {
-  if (S.hasInvalidSignature())
+bool operator()(StringRef Name, Signature Sign, Summary Sum) {
+  if (Sign.isInvalid())
 return false;
   IdentifierInfo &II = ACtx.Idents.get(Name);
   auto LookupRes = ACtx.getTranslationUnitDecl()->lookup(&II);
@@ -1017,8 +993,8 @@
 return false;
   for (Decl *D : LookupRes) {
 if (auto *FD = dyn_cast(D)) {
-  if (S.matchesAndSet(FD)) {
-auto Res = Map.insert({FD->getCanonicalDecl(), S});
+  if (Sum.matchesAndSet(Sign, FD)) {
+auto Res = Map.insert({FD->getCanonicalDecl(), Sum});
 assert(Res.second && "Function already has a summary set!");
 (void)Res;
 if (DisplayLoadedSummaries) {
@@ -1032,15 +1008,6 @@
   }
   return false;
 }
-// Add the summary with the Signature explicitly given.
-bool operator()(StringRef Name, Signature Sign, Summary Sum) {
-  return operator()(Name, Sum.setSignature(Sign));
-}
-// Add several summaries for the given name.
-void operator()(StringRef Name, const std::vector &Summaries) {
-  for (const Summary &S : Summaries)
-operator()(Name, S);
-}
 // Add the same summary for different names with the Signature explicitly
 // given.
 void operator()(std::vector Names, Signature Sign, Summary Sum) {
@@ -1109,8 +1076,8 @@
   // representable as unsigned char or is not equal to EOF. See e.g. C99
   // 7.4.1.2 The isalpha function (p: 181-182).
   addToFuncti

[PATCH] D68364: Implement C++20's P0784 (More constexpr containers)

2020-09-22 Thread Louis Dionne via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0724f8bf47f8: [libc++] Implement C++20's P0784 (More 
constexpr containers) (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68364

Files:
  libcxx/docs/FeatureTestMacroTable.rst
  libcxx/include/memory
  libcxx/include/new
  libcxx/include/version
  
libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
  
libcxx/test/std/language.support/support.limits/support.limits.general/memory.version.pass.cpp
  
libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.verify.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp
  
libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp
  libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
  
libcxx/test/std/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp
  
libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
  
libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
  
libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
  libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
  
libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp
  
libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy.pass.cpp
  
libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_at.pass.cpp
  
libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_n.pass.cpp
  libcxx/utils/generate_feature_test_macro_components.py
  libcxx/www/cxx2a_status.html

Index: libcxx/www/cxx2a_status.html
===
--- libcxx/www/cxx2a_status.html
+++ libcxx/www/cxx2a_status.html
@@ -164,7 +164,7 @@
 	https://wg21.link/P0631";>P0631LWGMath ConstantsCologneComplete11.0
 	https://wg21.link/P0645";>P0645LWGText FormattingCologne
 	https://wg21.link/P0660";>P0660LWGStop Token and Joining Thread, Rev 10Cologne
-	https://wg21.link/P0784";>P0784CWGMore constexpr containersCologne
+	https://wg21.link/P0784";>P0784CWGMore constexpr containersCologneComplete12.0
 	https://wg21.link/P0980";>P0980LWGMaking std::string constexprCologne
 	https://wg21.link/P1004";>P1004LWGMaking std::vector constexprCologne
 	https://wg21.link/P1035";>P1035LWGInput Range AdaptorsCologne
Index: libcxx/utils/generate_feature_test_macro_components.py
===
--- libcxx/utils/generate_feature_test_macro_components.py
+++ libcxx/utils/generate_feature_test_macro_components.py
@@ -664,6 +664,12 @@
"depends": "!defined(_LIBCPP_HAS_NO_THREADS)",
"internal_depends": "!defined(_LIBCPP_HAS_NO_THREADS)",
},
+   {"name": "__cpp_lib_constexpr_dynamic_alloc",
+"values": {
+  "c++2a": int(201907)
+},
+"headers": ["memory"]
+   },
 ]], key=lambda tc: tc["name"])
 
 def get_std_dialects():
Index: libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_n.pass.cpp
===
--- libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_n.pass.cpp
+++ libcxx/test/std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_n.pass.cpp
@@ -11,40 +11,52 @@
 // 
 
 // template 
-// ForwardIt destroy_n(ForwardIt, Size s);
+// constexpr ForwardIt destroy_n(ForwardIt, Size s);
 
 #include 
-#include 
 #include 
 
 #include "test_macros.h"
 #include "test_iterators.h"
 
 struct Counted {
-  static int count;
-  static void reset() { count = 0; }
-  Counted() { ++count; }
-  Counted(Counted const&) { ++count; }
-  ~Counted() { --count; }
-  friend void operator&(Counted) = delete;
+int* counter_;
+TEST_CONSTEXPR Counted(int* counter) : counter_(counter) { ++*counter_; }
+TEST_CONSTEXPR Counted(Counted const& other) : c

  1   2   >