[PATCH] D77534: [clangd] DefineOutline: removes static token from static CXXMethodDecl

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77534



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-07 Thread Wenlei He via Phabricator via cfe-commits
wenlei created this revision.
Herald added subscribers: cfe-commits, dexonsmith, hiraditya.
Herald added a project: clang.
wenlei edited the summary of this revision.
wenlei added reviewers: tejohnson, hoyFB, spatel, gchatelet.

Encode `-fveclib` setting as per-function attribute so it can be threaded 
through to LTO backends. Accordingly, per-function TLI now reads the attribute 
and populated available vector function list based on that. Note that we expect 
functions within the same module to share `fveclib` setting, so vector function 
list is still shared between functions, as part of the shared 
`TargetLibraryInfoImpl`. Inlining between functions with different vect lib 
attribute is now blocked.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77632

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/libcalls-veclib.c
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp

Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1528,8 +1528,29 @@
   llvm::sort(ScalarDescs, compareByVectorFnName);
 }
 
+void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
+const StringRef &VecLibName) {
+  VectorLibrary VecLib = NoLibrary;
+  if (VecLibName == "Accelerate")
+VecLib = Accelerate;
+  else if (VecLibName == "MASSV")
+VecLib = MASSV;
+  else if (VecLibName == "SVML")
+VecLib = SVML;
+  else
+return;
+  addVectorizableFunctionsFromVecLib(VecLib);
+}
+
 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
 enum VectorLibrary VecLib) {
+  if (VectLibrary != NoLibrary) {
+assert(VectLibrary == VecLib && 
+   "Conflicting VectorLibrary detected");
+return;
+  }
+
+  VectLibrary = VecLib;
   switch (VecLib) {
   case Accelerate: {
 const VecDesc VecFuncs[] = {
@@ -1604,6 +1625,11 @@
   if (!BaselineInfoImpl)
 BaselineInfoImpl =
 TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+
+  StringRef VectLibName = F.getFnAttribute("vect-lib").getValueAsString();
+  if (!VectLibName.empty())
+BaselineInfoImpl->addVectorizableFunctionsFromVecLib(VectLibName);
+
   return TargetLibraryInfo(*BaselineInfoImpl, &F);
 }
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -48,6 +48,21 @@
 class TargetLibraryInfoImpl {
   friend class TargetLibraryInfo;
 
+public:
+  /// List of known vector-functions libraries.
+  ///
+  /// The vector-functions library defines, which functions are vectorizable
+  /// and with which factor. The library can be specified by either frontend,
+  /// or a commandline option, and then used by
+  /// addVectorizableFunctionsFromVecLib for filling up the tables of
+  /// vectorizable functions.
+  enum VectorLibrary {
+NoLibrary,  // Don't use any vector library.
+Accelerate, // Use Accelerate framework.
+MASSV,  // IBM MASS vector library.
+SVML// Intel short vector math library.
+  };
+
   unsigned char AvailableArray[(NumLibFuncs+3)/4];
   llvm::DenseMap CustomNames;
   static StringLiteral const StandardNames[NumLibFuncs];
@@ -71,6 +86,8 @@
   /// Scalarization descriptors - same content as VectorDescs but sorted based
   /// on VectorFnName rather than ScalarFnName.
   std::vector ScalarDescs;
+  /// Vector library available for vectorization.
+  VectorLibrary VectLibrary = NoLibrary;
 
   /// Return true if the function type FTy is valid for the library function
   /// F, regardless of whether the function is available.
@@ -78,20 +95,6 @@
   const DataLayout *DL) const;
 
 public:
-  /// List of known vector-functions libraries.
-  ///
-  /// The vector-functions library defines, which functions are vectorizable
-  /// and with which factor. The library can be specified by either frontend,
-  /// or a commandline option, and then used by
-  /// addVectorizableFunctionsFromVecLib for filling up the tables of
-  /// vectorizable functions.
-  enum VectorLibrary {
-NoLibrary,  // Don't use any vector library.
-Accelerate, // Use Accelerate framework.
-MASSV,  // IBM MASS vector library.
-SVML// Intel short vector math library.
-  };
-
   TargetLibraryInfoImpl();
   explicit TargetLibraryInfoImpl(const Triple &T);
 
@@ -148,6 +151,7 @@
   /// Calls addVectorizableFunctions with a known preset of functions for the
   /// given vector library.
   void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib);
+  void addVectorizableFunctionsFromVecLib(const StringRef &VecLibName);
 
   /// Return true if the function F has a vector equivalent with vectorization
   /// factor VF.
@@ -261,18 +265,20 @@
   }
 
   /// Determine whether a ca

[PATCH] D77484: [Vector] Pass VectLib to LTO backend so TLI build correct vector function list

2020-04-07 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a comment.

In D77484#1965976 , @tejohnson wrote:

> In D77484#1965629 , @wenlei wrote:
>
> > > Ok then it does sound like these could be handled on a per-function 
> > > basis, similar to how -fno-builtin* are handled. I.e. a function 
> > > attribute to indicate the veclib, which would then be naturally preserved 
> > > during LTO even after merging/importing across modules. Similar to how 
> > > -fno-builtin* are handled, these would need to be examined when inlining 
> > > (see the new TargetLibraryInfo::areInlineCompatible). Presumably we would 
> > > want to block inlining between functions with different veclib attributes 
> > > in the LTO backends.
> >
> > @tejohnson, we could do that. But then on the other hand, technically 
> > almost everything for module or whole program can be passed as a function 
> > attribute, and yet we have switches passed to backend for many of those 
> > things. Wondering what's the convention or rule (if there's one) we want to 
> > follow? Specifically, if we only use function attributes for stuff that's 
> > indeed going to be different between functions, then vectlib isn't in that 
> > category; or if we use function attributes for the greatest flexibility 
> > whenever we can, then many other things should be function attributes too 
> > (though it's essentially duplication in IR, and probably not the most 
> > efficient).
>
>
> Passing the option through the driver to the linker is the legacy approach. 
> But it isn't really scalable and has other issues, so we've been moving 
> towards having all the necessary info in the IR itself. For one, this helps 
> deal with cases where different options were specified for different source 
> files. For another, it keeps the same build behavior with LTO and non-LTO. 
> I.e. for this option, if the build system specified it for the cc compiles 
> but not the links, it would work for O2 
>  but not for LTO if it had to be 
> propagated via the linker. It would work for LTO if it was propagated via the 
> IR.


Makes sense, thanks for clarification. I created D77632 
 to make vect lib setting a per-function 
attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77484



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


[PATCH] D77379: [FPEnv] Use single enum to represent rounding mode

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



Comment at: llvm/include/llvm/ADT/FloatingPointMode.h:26
+/// assigned to the rounding modes must agree with the values used by 
FLT_ROUNDS
+/// (C11, 5.2.4.2.2p8).
+enum class RoundingMode : int8_t {

rjmccall wrote:
> sepavloff wrote:
> > rjmccall wrote:
> > > I agree that we should use one enum across LLVM and Clang.  I'm not sure 
> > > that using the `FLT_ROUNDS` values is worthwhile, especially since (1) 
> > > `FLT_ROUNDS` doesn't specify a value for some of these (like 
> > > `NearestTiesToAway`) and (2) some of the values it does use (e.g. for 
> > > "indeterminable") make this actively more awkward to store.  And the most 
> > > useful thing we could do — matching the values of `FE_TONEAREST` and so 
> > > on — isn't possible because those values are unportable.  I'd rather we 
> > > just pick arbitrary, non-ABI-stable values, like we normally would, and 
> > > then make the places that rely on matching some external schema translate.
> > >  (1) FLT_ROUNDS doesn't specify a value for some of these (like 
> > > NearestTiesToAway)
> > 
> > In the recent C standard draft 
> > (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2454.pdf), there is 
> > support of all 5 rounding modes including values returned by `FLT_ROUNDS` 
> > (5.2.4.2.2p11), values used by `fegetround` and `fesetround` 
> > (FE_TONEARESTFROMZERO in 7.6p13)
> > 
> > >  (2) some of the values it does use (e.g. for "indeterminable") make this 
> > > actively more awkward to store.
> > 
> > This is not a rounding mode value, it is just error indicator returned by 
> > intrinsic functions, it does not need to be stored. Added comment about 
> > that.
> > 
> > > And the most useful thing we could do — matching the values of 
> > > FE_TONEAREST and so on — isn't possible because those values are 
> > > unportable.
> > 
> > I am working on patch that implements `fesetround` as intrinsic function. 
> > It introduces two intrinsic functions, one is `llvm.set_rounding` (D74729 
> > [FPEnv] Intrinsic for setting rounding mode) and the other is 
> > `llvm.convert_rounding` (unpublished yet). The latter translates 
> > platform-dependent values like FE_DOWNWARD into platform independent 
> > representation, which is the same as used by FLT_ROUNDS.
> > 
> > Actually the motivation for this patch was just the need to have 
> > platform-independent representation of rounding mode that could be used in 
> > IR, which is more or less platform-independent. The representation used by 
> > `FLT_ROUNDS` fits these purposes because:
> > * it is platform-neutral,
> > * it is defined by standard, and
> > * it encodes all IEEE rounding modes. 
> Okay.  I'm just worried that trying to match `FLT_ROUNDS` in our internal 
> representation is ultimately going to cause unnecessary problems.  If C has 
> standardized a value for NearesetTiesToAway, that certainly helps avoid that. 
>  `FLT_ROUNDS` allows targets to add implementation-defined values; are there 
> any targets that support other rounding modes that aren't currently described?
There are 10 possible "arithmetic" rounding modes 
(https://upload.wikimedia.org/wikipedia/commons/8/8a/Comparison_rounding_graphs_SMIL.svg).
  Current implementation of glibc does not define anything beyond the standard. 
I know there are cores that use non-IEEE modes "stochastic rounding to nearest" 
and "away from zero", don't know if they expose these modes through standard 
interface like FLT_ROUNDS. It looks like there is no precedent of extending the 
value set returned by FLT_ROUNDS.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77379



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


[PATCH] D77574: [OpenMP] Fix layering problem with FrontendOpenMP

2020-04-07 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

@lebedev.ri @jdoerfert Looks like it might have caused:
https://bugs.llvm.org/show_bug.cgi?id=45453


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77574



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


[PATCH] D77502: [clang][CodeGen] Handle throw expression in conditional operator constant folding

2020-04-07 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 255607.
tambre marked an inline comment as done.
tambre added a comment.

Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77502

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGenCXX/throw-expressions.cpp


Index: clang/test/CodeGenCXX/throw-expressions.cpp
===
--- clang/test/CodeGenCXX/throw-expressions.cpp
+++ clang/test/CodeGenCXX/throw-expressions.cpp
@@ -79,6 +79,12 @@
   // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
   // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} 
@_ZGRN6DR15601rE
   // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
+
+  // PR28184
+  void conditional_throw() {
+int a;
+(true ? throw 0 : a) = 0; // CHECK: call void @__cxa_throw({{.*}})
+  }
 }
 
 // CHECK-LABEL: define void @_Z5test7b(
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -4331,6 +4331,16 @@
   // If the true case is live, we need to track its region.
   if (CondExprBool)
 incrementProfileCounter(expr);
+  // If a throw expression we emit it and return an undefined lvalue
+  // because it can't be used.
+  if (auto *ThrowExpr = dyn_cast(live->IgnoreParens())) {
+EmitCXXThrowExpr(ThrowExpr);
+llvm::Type *Ty =
+llvm::PointerType::getUnqual(ConvertType(dead->getType()));
+return MakeAddrLValue(
+Address(llvm::UndefValue::get(Ty), CharUnits::One()),
+dead->getType());
+  }
   return EmitLValue(live);
 }
   }


Index: clang/test/CodeGenCXX/throw-expressions.cpp
===
--- clang/test/CodeGenCXX/throw-expressions.cpp
+++ clang/test/CodeGenCXX/throw-expressions.cpp
@@ -79,6 +79,12 @@
   // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
   // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} @_ZGRN6DR15601rE
   // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
+
+  // PR28184
+  void conditional_throw() {
+int a;
+(true ? throw 0 : a) = 0; // CHECK: call void @__cxa_throw({{.*}})
+  }
 }
 
 // CHECK-LABEL: define void @_Z5test7b(
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -4331,6 +4331,16 @@
   // If the true case is live, we need to track its region.
   if (CondExprBool)
 incrementProfileCounter(expr);
+  // If a throw expression we emit it and return an undefined lvalue
+  // because it can't be used.
+  if (auto *ThrowExpr = dyn_cast(live->IgnoreParens())) {
+EmitCXXThrowExpr(ThrowExpr);
+llvm::Type *Ty =
+llvm::PointerType::getUnqual(ConvertType(dead->getType()));
+return MakeAddrLValue(
+Address(llvm::UndefValue::get(Ty), CharUnits::One()),
+dead->getType());
+  }
   return EmitLValue(live);
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75364: [clang-format] Handle macros in function params and return value

2020-04-07 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz marked 2 inline comments as done.
tamas.petz added a comment.

@all, thank you for the review so far.

The case I am trying to handle is way too ambiguous.
IMHO looking at tokens only is not going to lead to a "perfect" formatter.
The case I am trying to handle is quite common but it can lead to incorrect 
formatting in other cases.

I had a weak hope that passing all tests is "safe enough" but it is 
unfortunately not.

Should we just note that cases similar to the one in the description are just 
too ambiguous to handle correctly?
Does anyone see a way the highlighted formatting issue can be solved?

Many thanks,

- Tamas




Comment at: clang/lib/Format/TokenAnnotator.cpp:313
+// for example:
+//   void f(volatile ElfW(Addr)* addr = nullptr);
+if (HasStarToken) {

MyDeveloperDay wrote:
> I assume it could be almost anything?
> 
> void f(volatile ElfW(Addr)& addr);
> void f(volatile ElfW(Addr)&& addr);
> void f(volatile ElfW(Addr) const & addr);
> 
> void f(volatile ElfW(Addr,foo)* addr);
> void f(volatile ElfW(Addr,ElfW(Addr) *foo)* addr);
> 
> ? you seem to handle only the * case
Yes, I am handling this case only at the moment.
I am not sure this patch is going to land at all so I spared some work until we 
figure it out.



Comment at: clang/unittests/Format/FormatTest.cpp:7360
+  verifyFormat("int f(M(x) *p1 = nullptr, M(x) *p2, volatile M(x) *p3);");
+  verifyFormat("M(x) *foo();");
+  verifyFormat("const M(x) *foo(M(x) *a = nullptr);");

krasimir wrote:
> This is ambiguous: the `*` could be a binary operator: 
> https://godbolt.org/z/n7Jr-h
This case is ambiguous. Like the case at line 7324, which could also be 
"MACRO()* ptr;"


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

https://reviews.llvm.org/D75364



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


[PATCH] D77502: [clang][CodeGen] Handle throw expression in conditional operator constant folding

2020-04-07 Thread Raul Tambre via Phabricator via cfe-commits
tambre marked an inline comment as done.
tambre added a comment.

Updated the comment.

Please commit this for me, as I lack commit privileges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77502



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


[PATCH] D77491: [Sema] Fix incompatible builtin redeclarations in non-global scope

2020-04-07 Thread Yuichiro Utsumi via Phabricator via cfe-commits
yutsumi accepted this revision.
yutsumi added a comment.
This revision is now accepted and ready to land.

Thank you very much. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491



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


[PATCH] D77491: [Sema] Fix incompatible builtin redeclarations in non-global scope

2020-04-07 Thread Yuichiro Utsumi via Phabricator via cfe-commits
yutsumi added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491



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


[PATCH] D77585: Stop passing site cfg files via --param to llvm-lit.

2020-04-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clang/test/CMakeLists.txt:113
 
-set(ANALYZER_TEST_PARAMS
-  USE_Z3_SOLVER=0)

This and ANALYZER_TEST_PARAMS_Z3 are just dropped because they're unused, right?


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

https://reviews.llvm.org/D77585



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


[PATCH] D77209: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 255609.
hlopko marked 6 inline comments as done.
hlopko added a comment.

Adressing comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77209

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp
  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
@@ -1215,6 +1215,9 @@
 |   `-}
 `-}
)txt");
+}
+
+TEST_F(SyntaxTreeTest, ModifiableNodes) {
   // All nodes can be mutated.
   expectTreeDumpEqual(
   R"cpp(
Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -57,6 +57,7 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::Not;
 using ::testing::Pointee;
@@ -185,10 +186,14 @@
   template 
   llvm::ArrayRef findSubrange(llvm::ArrayRef Subrange,
  llvm::ArrayRef Range, Eq F) {
-for (auto Begin = Range.begin(); Begin < Range.end(); ++Begin) {
+assert(Subrange.size() >= 1);
+if (Range.size() < Subrange.size())
+  return llvm::makeArrayRef(Range.end(), Range.end());
+for (auto Begin = Range.begin(), Last = Range.end() - Subrange.size();
+ Begin <= Last; ++Begin) {
   auto It = Begin;
-  for (auto ItSub = Subrange.begin();
-   ItSub != Subrange.end() && It != Range.end(); ++ItSub, ++It) {
+  for (auto ItSub = Subrange.begin(); ItSub != Subrange.end();
+   ++ItSub, ++It) {
 if (!F(*ItSub, *It))
   goto continue_outer;
   }
@@ -889,4 +894,111 @@
   ASSERT_EQ(Code.points().size(), 8u);
 }
 
+TEST_F(TokenBufferTest, ExpandedBySpelled) {
+  recordTokens(R"cpp(
+a1 a2 a3 b1 b2
+  )cpp");
+  // Sanity check: expanded and spelled tokens are stored separately.
+  EXPECT_THAT(findExpanded("a1 a2"), Not(SameRange(findSpelled("a1 a2";
+  // Searching for subranges of expanded tokens should give the corresponding
+  // spelled ones.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3 b1 b2")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("b1 b2")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Test search on simple macro expansions.
+  recordTokens(R"cpp(
+#define A a1 a2 a3
+#define B b1 b2
+
+A split B
+  )cpp");
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split B")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split").drop_back()),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("split B").drop_front()),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Ranges not fully covering macro expansions should fail.
+  recordTokens(R"cpp(
+#define ID(x) x
+
+ID(a)
+  )cpp");
+  // Spelled don't cover entire mapping (missing ID token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("( a )")), IsEmpty());
+  // Spelled don't cover entire mapping (missing ) token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a")), IsEmpty());
+
+  // Recursive macro invocations.
+  recordTokens(R"cpp(
+#define ID(x) x
+#define B b1 b2
+
+ID(ID(ID(a1) a2 a3)) split ID(B)
+  )cpp");
+
+  EXPECT_THAT(
+  Buffer.expandedForSpelled(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( B )")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(
+  findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) ) split ID ( B )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  // FIXME: these should succeed, but we do not support macro arguments yet.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1")), IsEmpty());
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a1 ) a2")),
+  IsEmpty());
+
+  // Empty macro expansions.
+  recordTokens(R"cpp(
+#define EMPTY
+#define ID(X) X
+
+EMPTY EMPTY ID(1 2 3) EMPTY EMPTY split1
+EMPTY EMPTY ID(4 5 6) split2
+ID(7 8 9) EMPTY EMPTY
+  )cpp");
+  //

[PATCH] D77209: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko added inline comments.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:264
+  auto *FrontMapping = mappingStartingBeforeSpelled(File, &Spelled.front());
+  unsigned SpelledFrontI = &Spelled.front() - File.SpelledTokens.data();
+  unsigned ExpandedBegin;

gribozavr2 wrote:
> hlopko wrote:
> > gribozavr2 wrote:
> > > Or assert that SpelledFrontI is less than File.SpelledTokens.size().
> > I think the assert I added is good enough?
> The assertion that I suggested is stronger, because it would prevent an 
> out-of-bounds read from even happening, and would not rely on 
> `isBeforeInTranslationUnit` returning false on garbage data.
Great points! Done.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:602
+for (auto &pair : Result.Files) {
+  auto &mappings = pair.second.Mappings;
+  assert(std::is_sorted(

gribozavr2 wrote:
> We'd get an "unused variable" warning here when assertions are disabled. 
> Please wrap the whole loop in `#ifndef NDEBUG`.
Done, added ifndef also above for T1/T2 variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77209



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


[PATCH] D77209: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 255610.
hlopko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77209

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp
  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
@@ -1215,6 +1215,9 @@
 |   `-}
 `-}
)txt");
+}
+
+TEST_F(SyntaxTreeTest, ModifiableNodes) {
   // All nodes can be mutated.
   expectTreeDumpEqual(
   R"cpp(
Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -57,6 +57,7 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::Not;
 using ::testing::Pointee;
@@ -185,10 +186,14 @@
   template 
   llvm::ArrayRef findSubrange(llvm::ArrayRef Subrange,
  llvm::ArrayRef Range, Eq F) {
-for (auto Begin = Range.begin(); Begin < Range.end(); ++Begin) {
+assert(Subrange.size() >= 1);
+if (Range.size() < Subrange.size())
+  return llvm::makeArrayRef(Range.end(), Range.end());
+for (auto Begin = Range.begin(), Last = Range.end() - Subrange.size();
+ Begin <= Last; ++Begin) {
   auto It = Begin;
-  for (auto ItSub = Subrange.begin();
-   ItSub != Subrange.end() && It != Range.end(); ++ItSub, ++It) {
+  for (auto ItSub = Subrange.begin(); ItSub != Subrange.end();
+   ++ItSub, ++It) {
 if (!F(*ItSub, *It))
   goto continue_outer;
   }
@@ -889,4 +894,111 @@
   ASSERT_EQ(Code.points().size(), 8u);
 }
 
+TEST_F(TokenBufferTest, ExpandedBySpelled) {
+  recordTokens(R"cpp(
+a1 a2 a3 b1 b2
+  )cpp");
+  // Sanity check: expanded and spelled tokens are stored separately.
+  EXPECT_THAT(findExpanded("a1 a2"), Not(SameRange(findSpelled("a1 a2";
+  // Searching for subranges of expanded tokens should give the corresponding
+  // spelled ones.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3 b1 b2")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("b1 b2")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Test search on simple macro expansions.
+  recordTokens(R"cpp(
+#define A a1 a2 a3
+#define B b1 b2
+
+A split B
+  )cpp");
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split B")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split").drop_back()),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("split B").drop_front()),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Ranges not fully covering macro expansions should fail.
+  recordTokens(R"cpp(
+#define ID(x) x
+
+ID(a)
+  )cpp");
+  // Spelled don't cover entire mapping (missing ID token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("( a )")), IsEmpty());
+  // Spelled don't cover entire mapping (missing ) token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a")), IsEmpty());
+
+  // Recursive macro invocations.
+  recordTokens(R"cpp(
+#define ID(x) x
+#define B b1 b2
+
+ID(ID(ID(a1) a2 a3)) split ID(B)
+  )cpp");
+
+  EXPECT_THAT(
+  Buffer.expandedForSpelled(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( B )")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(
+  findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) ) split ID ( B )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  // FIXME: these should succeed, but we do not support macro arguments yet.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1")), IsEmpty());
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a1 ) a2")),
+  IsEmpty());
+
+  // Empty macro expansions.
+  recordTokens(R"cpp(
+#define EMPTY
+#define ID(X) X
+
+EMPTY EMPTY ID(1 2 3) EMPTY EMPTY split1
+EMPTY EMPTY ID(4 5 6) split2
+ID(7 8 9) EMPTY EMPTY
+  )cpp");
+  // Covered by empty expansions on one of both of the si

[PATCH] D77633: [Parser] Improve diagnostic and error recovery when C++ keywords are used as identifiers.

2020-04-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

Previously, clang emitted a less-usefull diagnostic and didnt recover
well when the keywords is used as identifier in function paramter.

  void foo(int case, int x); // previously we drop all parameters after
  `int case`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77633

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/cxx-keyword-identifiers.cpp


Index: clang/test/Parser/cxx-keyword-identifiers.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-keyword-identifiers.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+
+int foo(int case, int throw, int y) { // expected-error {{using keyword 'case' 
as an identifier is not permitted}} \
+ expected-error {{using keyword 
'throw' as}}
+  // Trailing parameters should be recovered.
+  y = 1;
+}
+
+void test() {
+  // FIXME: we shoud improve the dianostics for the following cases.
+  int case; // expected-error {{expected unqualified-id}}
+  struct X {
+int case; // expected-error {{expected member name or ';'}}
+  };
+}
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -6869,6 +6869,13 @@
 }
   }
 
+  // Recovery if a keyword is used as an identifier.
+  if (Tok.getIdentifierInfo() &&
+  Tok.getIdentifierInfo()->isKeyword(getLangOpts())) {
+Diag(Tok, diag::err_keyword_as_ident) << PP.getSpelling(Tok);
+// Consume the keyword.
+ConsumeToken();
+  }
   ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
   ParmDeclarator.getIdentifierLoc(),
   Param, std::move(DefArgToks)));
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -591,6 +591,8 @@
 def warn_empty_init_statement : Warning<
   "empty initialization statement of '%select{if|switch|range-based for}0' "
   "has no effect">, InGroup, DefaultIgnore;
+def err_keyword_as_ident : Error <
+  "using keyword '%0' as an identifier is not permitted">;
 
 // C++ derived classes
 def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;


Index: clang/test/Parser/cxx-keyword-identifiers.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-keyword-identifiers.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+
+int foo(int case, int throw, int y) { // expected-error {{using keyword 'case' as an identifier is not permitted}} \
+ expected-error {{using keyword 'throw' as}}
+  // Trailing parameters should be recovered.
+  y = 1;
+}
+
+void test() {
+  // FIXME: we shoud improve the dianostics for the following cases.
+  int case; // expected-error {{expected unqualified-id}}
+  struct X {
+int case; // expected-error {{expected member name or ';'}}
+  };
+}
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -6869,6 +6869,13 @@
 }
   }
 
+  // Recovery if a keyword is used as an identifier.
+  if (Tok.getIdentifierInfo() &&
+  Tok.getIdentifierInfo()->isKeyword(getLangOpts())) {
+Diag(Tok, diag::err_keyword_as_ident) << PP.getSpelling(Tok);
+// Consume the keyword.
+ConsumeToken();
+  }
   ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
   ParmDeclarator.getIdentifierLoc(),
   Param, std::move(DefArgToks)));
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -591,6 +591,8 @@
 def warn_empty_init_statement : Warning<
   "empty initialization statement of '%select{if|switch|range-based for}0' "
   "has no effect">, InGroup, DefaultIgnore;
+def err_keyword_as_ident : Error <
+  "using keyword '%0' as an identifier is not permitted">;
 
 // C++ derived classes
 def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63616: Implement `-fsanitize-coverage-whitelist` and `-fsanitize-coverage-blacklist` for clang

2020-04-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:218
   Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
-  PM.add(createSanitizerCoverageModulePass(Opts));
+  PM.add(createSanitizerCoverageModulePass(Opts, 
CGOpts.SanitizeCoverageWhitelistFiles, CGOpts.SanitizeCoverageBlacklistFiles));
 }

morehouse wrote:
> Please run `clang-format --style=LLVM` on the patch.
it should be -style=file
"arc diff" should also invoke clang-format, check utils/arcanist/clang-format.sh


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63616



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


[PATCH] D75661: Remove SequentialType from the type heirarchy.

2020-04-07 Thread Alex Zinenko via Phabricator via cfe-commits
ftynse added a comment.

LGTM for MLIR part.




Comment at: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp:60
+  } else {
 emitError(loc) << "expected sequential LLVM types wrapping a scalar";
 return nullptr;

Nit: can we update the error message not to mention "sequential LLVM type" 
anymore if sequential type is no longer a thing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75661



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


[PATCH] D77615: [Syntax] Merge overlapping top-level macros in TokenBuffer

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:452
+
+// The *last* token of the macro reference is in the main file for A and B.
+if (Range.getEnd().isMacroID())

instead of saying `A and B` maybe say something like, a `the last token for a 
top-level macro expansion must be inside a file` and invert the following 
condition:

`if(!Range.getEnd().isFileID()) return;`



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:461
+
+// If the macro invocation B starts in a macro A but ends in a file, we'll
+// create a merged mapping for A & B by overwriting the endpoint for A's

maybe put As and Bs in parentheses, i.e:
```
// If the macro invocation (B) starts in a macro (A) but ends in a file, we'll
// create a merged mapping (for A & B) by overwriting the endpoint for 
parent's (A's)
// startpoint.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77615



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:560
+   SpelledTokens[NextSpelled].location() < Target) {
+  // If we know of mapping bounds at [Next, KnownEnd] (e.g. macro 
expansion)
+  // then we want to partition our (empty) mapping.

s/Next/NextSpelled

in following lines as well



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:588
+auto &NextSpelled = this->NextSpelled[File];
+
+if (Tok.location().isFileID()) {

nit: maybe create mapping here and increment NextSpelled and NextExpanded 
explicitly here.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:594
+ SpelledTokens[NextSpelled].location() ==
+ Result.ExpandedTokens[NextExpanded].location()) {
+++NextSpelled;

maybe also explicitly spell the assumption:
`assert(ExpandedTok.location().isFileID())` ?



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:645
   TokenBuffer Result;
-  /// For each file, a position of the next spelled token we will consume.
+  // Cursor within the expanded token stream, and each file.
+  unsigned NextExpanded = 0;

i suppose `and each file` part refers to `NextSpelled` but it seems to be 
confusing maybe have a separate one below ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 255618.
sammccall added a comment.

Crash with a nice message if our loop gets stuck.

Looks like

  ok Token(`void`, void, length = 4)
  ok Token(`test`, identifier, length = 4)
  ok Token(`(`, l_paren, length = 1)
  ok Token(`int`, int, length = 3)
  ok Token(`*`, star, length = 1)
  ok Token(`List`, identifier, length = 4)
  ok Token(`)`, r_paren, length = 1)
  ok Token(`{`, l_brace, length = 1)
  ok Token(`0`, numeric_constant, length = 1)
  !! Token(``, eof, length = 0)
 Token(`}`, r_brace, length = 1)
 Token(``, eof, length = 0)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -500,196 +500,168 @@
   }
 
   TokenBuffer build() && {
-buildSpelledTokens();
-
-// Walk over expanded tokens and spelled tokens in parallel, building the
-// mappings between those using source locations.
-// To correctly recover empty macro expansions, we also take locations
-// reported to PPCallbacks::MacroExpands into account as we do not have any
-// expanded tokens with source locations to guide us.
-
-// The 'eof' token is special, it is not part of spelled token stream. We
-// handle it separately at the end.
 assert(!Result.ExpandedTokens.empty());
 assert(Result.ExpandedTokens.back().kind() == tok::eof);
-for (unsigned I = 0; I < Result.ExpandedTokens.size() - 1; ++I) {
-  // (!) I might be updated by the following call.
-  processExpandedToken(I);
-}
 
-// 'eof' not handled in the loop, do it here.
-assert(SM.getMainFileID() ==
-   SM.getFileID(Result.ExpandedTokens.back().location()));
-fillGapUntil(Result.Files[SM.getMainFileID()],
- Result.ExpandedTokens.back().location(),
- Result.ExpandedTokens.size() - 1);
-Result.Files[SM.getMainFileID()].EndExpanded = Result.ExpandedTokens.size();
+// Tokenize every file that contributed tokens to the expanded stream.
+buildSpelledTokens();
 
-// Some files might have unaccounted spelled tokens at the end, add an empty
-// mapping for those as they did not have expanded counterparts.
-fillGapsAtEndOfFiles();
+// The expanded token stream consists of runs of tokens that came from
+// the same source (a macro expansion, part of a file etc).
+// Between these runs are the logical positions of spelled tokens that
+// didn't expand to anything.
+while (NextExpanded < Result.ExpandedTokens.size() - 1 /* eof */) {
+  // Create empty mappings for spelled tokens that expanded to nothing here.
+  // May advance NextSpelled, but NextExpanded is unchanged.
+  discard();
+  // Create mapping for a contiguous run of expanded tokens.
+  // Advances NextExpanded past the run, and NextSpelled accordingly.
+  unsigned OldPosition = NextExpanded;
+  advance();
+  if (NextExpanded == OldPosition)
+diagnoseAdvanceFailure();
+}
+// If any tokens remain in any of the files, they didn't expand to anything.
+// Create empty mappings up until the end of the file.
+for (const auto& File : Result.Files)
+  discard(File.first);
 
 return std::move(Result);
   }
 
 private:
-  /// Process the next token in an expanded stream and move corresponding
-  /// spelled tokens, record any mapping if needed.
-  /// (!) \p I will be updated if this had to skip tokens, e.g. for macros.
-  void processExpandedToken(unsigned &I) {
-auto L = Result.ExpandedTokens[I].location();
-if (L.isMacroID()) {
-  processMacroExpansion(SM.getExpansionRange(L), I);
-  return;
+  // Consume a sequence of spelled tokens that didn't expand to anything.
+  // In the simplest case, skips spelled tokens until finding one that produced
+  // the NextExpanded token, and creates an empty mapping for them.
+  // If Drain is provided, skips remaining tokens from that file instead.
+  void discard(llvm::Optional Drain = llvm::None) {
+SourceLocation Target =
+Drain ? SM.getLocForEndOfFile(*Drain)
+  : SM.getExpansionLoc(
+Result.ExpandedTokens[NextExpanded].location());
+FileID File = SM.getFileID(Target);
+const auto &SpelledTokens = Result.Files[File].SpelledTokens;
+auto &NextSpelled = this->NextSpelled[File];
+
+TokenBuffer::Mapping Mapping;
+Mapping.BeginSpelled = NextSpelled;
+// When dropping trailing tokens from a file, the empty mapping should
+// be positioned within the file's expanded-token range (at the end).
+Mapping.BeginExpanded = Mapping.EndExpanded =
+Drain ? Result.Files[*Drain].EndExpanded : NextExpanded;
+// We may want to split into s

[PATCH] D77244: [part 1] sancov/inline-bool-flag instrumentation.

2020-04-07 Thread Pratyai Mazumder via Phabricator via cfe-commits
pratyai updated this revision to Diff 255619.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77244

Files:
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
  llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
  llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
  llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll

Index: llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-trace-pc-guard -sanitizer-coverage-inline-bool-flag -S | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-trace-pc-guard -sanitizer-coverage-inline-bool-flag -S | FileCheck %s
+
+; Module ctors should have stable names across modules, not something like
+; @sancov.module_ctor.3 that may cause duplicate ctors after linked together.
+
+; CHECK: define internal void @sancov.module_ctor_trace_pc_guard() comdat {
+; CHECK: define internal void @sancov.module_ctor_bool_flag() comdat {
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+define void @foo() {
+  ret void
+}
Index: llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
@@ -1,8 +1,10 @@
 ; Test -sanitizer-coverage-pc-table=1
 ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard   -sanitizer-coverage-pc-table=1 -S | FileCheck %s
 ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-inline-8bit-counters -sanitizer-coverage-pc-table=1 -S | FileCheck %s
+; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-inline-bool-flag -sanitizer-coverage-pc-table=1 -S | FileCheck %s
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard   -sanitizer-coverage-pc-table=1 -S | FileCheck %s
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-inline-8bit-counters -sanitizer-coverage-pc-table=1 -S | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-inline-bool-flag -sanitizer-coverage-pc-table=1 -S | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-gnu"
Index: llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
@@ -0,0 +1,13 @@
+; Test -sanitizer-coverage-inline-bool-flag=1
+; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1  -S | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1  -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+define void @foo() {
+entry:
+; CHECK: @__sancov_gen_ = private global [1 x i1] zeroinitializer, section "__sancov_bool_flag", comdat($foo), align 1, !associated !0
+; CHECK: store i1 true, i1* getelementptr inbounds ([1 x i1], [1 x i1]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize !1
+  ret void
+}
+; CHECK: call void @__sanitizer_cov_bool_flag_init(i1* bitcast (i1** @__start___sancov_bool_flag to i1*), i1* bitcast (i1** @__stop___sancov_bool_flag to i1*))
Index: llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
@@ -0,0 +1,13 @@
+; Checks that the PC and 8-bit Counter Arrays are placed in their own sections in COFF binaries.
+; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -sanitizer-coverage-pc-table=1 -S | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -sanitiz

[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 255621.
sammccall added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -500,197 +500,168 @@
   }
 
   TokenBuffer build() && {
-buildSpelledTokens();
-
-// Walk over expanded tokens and spelled tokens in parallel, building the
-// mappings between those using source locations.
-// To correctly recover empty macro expansions, we also take locations
-// reported to PPCallbacks::MacroExpands into account as we do not have any
-// expanded tokens with source locations to guide us.
-
-// The 'eof' token is special, it is not part of spelled token stream. We
-// handle it separately at the end.
 assert(!Result.ExpandedTokens.empty());
 assert(Result.ExpandedTokens.back().kind() == tok::eof);
-for (unsigned I = 0; I < Result.ExpandedTokens.size() - 1; ++I) {
-  // (!) I might be updated by the following call.
-  processExpandedToken(I);
-}
 
-// 'eof' not handled in the loop, do it here.
-assert(SM.getMainFileID() ==
-   SM.getFileID(Result.ExpandedTokens.back().location()));
-fillGapUntil(Result.Files[SM.getMainFileID()],
- Result.ExpandedTokens.back().location(),
- Result.ExpandedTokens.size() - 1);
-Result.Files[SM.getMainFileID()].EndExpanded = Result.ExpandedTokens.size();
+// Tokenize every file that contributed tokens to the expanded stream.
+buildSpelledTokens();
 
-// Some files might have unaccounted spelled tokens at the end, add an empty
-// mapping for those as they did not have expanded counterparts.
-fillGapsAtEndOfFiles();
+// The expanded token stream consists of runs of tokens that came from
+// the same source (a macro expansion, part of a file etc).
+// Between these runs are the logical positions of spelled tokens that
+// didn't expand to anything.
+while (NextExpanded < Result.ExpandedTokens.size() - 1 /* eof */) {
+  // Create empty mappings for spelled tokens that expanded to nothing here.
+  // May advance NextSpelled, but NextExpanded is unchanged.
+  discard();
+  // Create mapping for a contiguous run of expanded tokens.
+  // Advances NextExpanded past the run, and NextSpelled accordingly.
+  unsigned OldPosition = NextExpanded;
+  advance();
+  if (NextExpanded == OldPosition)
+diagnoseAdvanceFailure();
+}
+// If any tokens remain in any of the files, they didn't expand to anything.
+// Create empty mappings up until the end of the file.
+for (const auto& File : Result.Files)
+  discard(File.first);
 
 return std::move(Result);
   }
 
 private:
-  /// Process the next token in an expanded stream and move corresponding
-  /// spelled tokens, record any mapping if needed.
-  /// (!) \p I will be updated if this had to skip tokens, e.g. for macros.
-  void processExpandedToken(unsigned &I) {
-auto L = Result.ExpandedTokens[I].location();
-if (L.isMacroID()) {
-  processMacroExpansion(SM.getExpansionRange(L), I);
-  return;
+  // Consume a sequence of spelled tokens that didn't expand to anything.
+  // In the simplest case, skips spelled tokens until finding one that produced
+  // the NextExpanded token, and creates an empty mapping for them.
+  // If Drain is provided, skips remaining tokens from that file instead.
+  void discard(llvm::Optional Drain = llvm::None) {
+SourceLocation Target =
+Drain ? SM.getLocForEndOfFile(*Drain)
+  : SM.getExpansionLoc(
+Result.ExpandedTokens[NextExpanded].location());
+FileID File = SM.getFileID(Target);
+const auto &SpelledTokens = Result.Files[File].SpelledTokens;
+auto &NextSpelled = this->NextSpelled[File];
+
+TokenBuffer::Mapping Mapping;
+Mapping.BeginSpelled = NextSpelled;
+// When dropping trailing tokens from a file, the empty mapping should
+// be positioned within the file's expanded-token range (at the end).
+Mapping.BeginExpanded = Mapping.EndExpanded =
+Drain ? Result.Files[*Drain].EndExpanded : NextExpanded;
+// We may want to split into several adjacent empty mappings.
+// FlushMapping() emits the current mapping and starts a new one.
+auto FlushMapping = [&, this] {
+  Mapping.EndSpelled = NextSpelled;
+  if (Mapping.BeginSpelled != Mapping.EndSpelled)
+Result.Files[File].Mappings.push_back(Mapping);
+  Mapping.BeginSpelled = NextSpelled;
+};
+
+while (NextSpelled < SpelledTokens.size() &&
+   SpelledTokens[NextSpelled].location() < Target) {
+  // If we know mapping bounds at

[PATCH] D77615: [Syntax] Merge overlapping top-level macros in TokenBuffer

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



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:461
+
+// If the macro invocation B starts in a macro A but ends in a file, we'll
+// create a merged mapping for A & B by overwriting the endpoint for A's

kadircet wrote:
> maybe put As and Bs in parentheses, i.e:
> ```
> // If the macro invocation (B) starts in a macro (A) but ends in a file, we'll
> // create a merged mapping (for A & B) by overwriting the endpoint for 
> parent's (A's)
> // startpoint.
> ```
Done, except for "parent" - the point here is there isn't really a parent/child 
relationship here: the arg list isn't part of the A expansion in any sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77615



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 4 inline comments as done.
sammccall added inline comments.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:588
+auto &NextSpelled = this->NextSpelled[File];
+
+if (Tok.location().isFileID()) {

kadircet wrote:
> nit: maybe create mapping here and increment NextSpelled and NextExpanded 
> explicitly here.
Not quite sure what you mean here, my guesses...

Hoisting mapping creation to here: If we have file tokens, we're not creating a 
mapping. Only nontrivial mappings are stored (where the spelled and expanded 
locations differ). This may be a design mistake but it's not one I'm fixing in 
this patch :-)

Incrementing NextSpelled and NextExpanded eagerly: if our invariants hold 
(expanded and spelled tokens really do correspond) then we will indeed 
increment each of these at least once, so we could structure the code that way. 
However those invariants are ridiculously subtle and fragile (basically depends 
on the correctness of the TokenWatcher impl in Preprocessor) so in practice 
it's good not to advance if our assumptions aren't met so we can actually debug 
the result. The latest version of the patch makes use of this to detect and 
crash with a useful message (diagnoseAdvanceFailure).



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:594
+ SpelledTokens[NextSpelled].location() ==
+ Result.ExpandedTokens[NextExpanded].location()) {
+++NextSpelled;

kadircet wrote:
> maybe also explicitly spell the assumption:
> `assert(ExpandedTok.location().isFileID())` ?
This is very weak compared to the explicitly checked equality in the while 
loop, which I think spells out the assumption better (these are consecutive 
spelled tokens).

That assertion would effectively be checking that SpelledTokens doesn't contain 
any tokens with macro locations, which is trivially true by construction and 
not really sensible to check in all the places we rely on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614



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


[clang] 08fab9e - [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread Pierre Gousseau via cfe-commits
Author: Pierre Gousseau
Date: 2020-04-07T11:25:08+01:00
New Revision: 08fab9ebecf72a682279d75489dc2460121cbeed

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

LOG: [X86] Fix implicit sign conversion warnings in X86 headers.

Warnings in emmintrin.h and xmmintrin.h are reported by
-fsanitize=implicit-integer-sign-change.

Reviewed By: RKSimon, craig.topper

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

Added: 
clang/test/Headers/x86-header-warnings.c

Modified: 
clang/lib/Headers/emmintrin.h
clang/lib/Headers/xmmintrin.h

Removed: 




diff  --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 993c688ce818..73a777b107c6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -4970,10 +4970,10 @@ void _mm_pause(void);
 
 #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
 
-#define _MM_DENORMALS_ZERO_ON   (0x0040)
-#define _MM_DENORMALS_ZERO_OFF  (0x)
+#define _MM_DENORMALS_ZERO_ON   (0x0040U)
+#define _MM_DENORMALS_ZERO_OFF  (0xU)
 
-#define _MM_DENORMALS_ZERO_MASK (0x0040)
+#define _MM_DENORMALS_ZERO_MASK (0x0040U)
 
 #define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
 #define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & 
~_MM_DENORMALS_ZERO_MASK) | (x)))

diff  --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 9b8de63f04d5..f4686691c7ed 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -2931,31 +2931,31 @@ _mm_movemask_ps(__m128 __a)
 
 #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
 
-#define _MM_EXCEPT_INVALID(0x0001)
-#define _MM_EXCEPT_DENORM (0x0002)
-#define _MM_EXCEPT_DIV_ZERO   (0x0004)
-#define _MM_EXCEPT_OVERFLOW   (0x0008)
-#define _MM_EXCEPT_UNDERFLOW  (0x0010)
-#define _MM_EXCEPT_INEXACT(0x0020)
-#define _MM_EXCEPT_MASK   (0x003f)
-
-#define _MM_MASK_INVALID  (0x0080)
-#define _MM_MASK_DENORM   (0x0100)
-#define _MM_MASK_DIV_ZERO (0x0200)
-#define _MM_MASK_OVERFLOW (0x0400)
-#define _MM_MASK_UNDERFLOW(0x0800)
-#define _MM_MASK_INEXACT  (0x1000)
-#define _MM_MASK_MASK (0x1f80)
-
-#define _MM_ROUND_NEAREST (0x)
-#define _MM_ROUND_DOWN(0x2000)
-#define _MM_ROUND_UP  (0x4000)
-#define _MM_ROUND_TOWARD_ZERO (0x6000)
-#define _MM_ROUND_MASK(0x6000)
-
-#define _MM_FLUSH_ZERO_MASK   (0x8000)
-#define _MM_FLUSH_ZERO_ON (0x8000)
-#define _MM_FLUSH_ZERO_OFF(0x)
+#define _MM_EXCEPT_INVALID(0x0001U)
+#define _MM_EXCEPT_DENORM (0x0002U)
+#define _MM_EXCEPT_DIV_ZERO   (0x0004U)
+#define _MM_EXCEPT_OVERFLOW   (0x0008U)
+#define _MM_EXCEPT_UNDERFLOW  (0x0010U)
+#define _MM_EXCEPT_INEXACT(0x0020U)
+#define _MM_EXCEPT_MASK   (0x003fU)
+
+#define _MM_MASK_INVALID  (0x0080U)
+#define _MM_MASK_DENORM   (0x0100U)
+#define _MM_MASK_DIV_ZERO (0x0200U)
+#define _MM_MASK_OVERFLOW (0x0400U)
+#define _MM_MASK_UNDERFLOW(0x0800U)
+#define _MM_MASK_INEXACT  (0x1000U)
+#define _MM_MASK_MASK (0x1f80U)
+
+#define _MM_ROUND_NEAREST (0xU)
+#define _MM_ROUND_DOWN(0x2000U)
+#define _MM_ROUND_UP  (0x4000U)
+#define _MM_ROUND_TOWARD_ZERO (0x6000U)
+#define _MM_ROUND_MASK(0x6000U)
+
+#define _MM_FLUSH_ZERO_MASK   (0x8000U)
+#define _MM_FLUSH_ZERO_ON (0x8000U)
+#define _MM_FLUSH_ZERO_OFF(0xU)
 
 #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
 #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)

diff  --git a/clang/test/Headers/x86-header-warnings.c 
b/clang/test/Headers/x86-header-warnings.c
new file mode 100644
index ..ec7cfc6adaad
--- /dev/null
+++ b/clang/test/Headers/x86-header-warnings.c
@@ -0,0 +1,43 @@
+// Fix sign conversion warnings found by fsanitize=implicit-integer-sign-change
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \
+// RUN: | %clang_cc1 -x c - -triple x86_64-pc-linux-gnu -ffreestanding 
-Wsign-conversion -E -o - 2>&1 \
+// RUN: | FileCheck --allow-empty %s
+// REQUIRES: x86-registered-target
+
+#include 
+
+void test0() {
+  // CHECK-LABEL: test0
+  // CHECK-NOT: warning:
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_MASK);
+
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INVALID);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DENORM);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DIV_ZERO);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_OVERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_UNDERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INEXACT);
+  _MM_SET_EXCEPTIO

[PATCH] D75936: Add a Pass to X86 that builds a Condensed CFG for Load Value Injection (LVI) Gadgets [4/6]

2020-04-07 Thread Matthew Riley via Phabricator via cfe-commits
mattdr added inline comments.



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:318
+}
+auto *VertexArray = new Node[VertexSize + 1 /* terminator node */];
+auto *EdgeArray = new Edge[EdgeSize];

sconstab wrote:
> mattdr wrote:
> > sconstab wrote:
> > > mattdr wrote:
> > > > As a general rule `new` is a code-smell in modern C++. This should be a 
> > > > `vector`.
> > > @mattdr I do agree with the general rule. I also think that in this case 
> > > where the structure is immutable, std::vector is wasteful because it 
> > > needs to keep separate values for the current number of elements and the 
> > > current capacity. At local scope within a function the unneeded value 
> > > would likely be optimized away, but then there would be an awkward 
> > > handoff to transfer the data from the vector to the array members.
> > > 
> > > I would not want to see the array members changed to vectors, unless LLVM 
> > > provides an encapsulated array structure that does not need to grow and 
> > > shrink.
> > So, first: I'm glad you removed the unnecessary use of `new[]` here and the 
> > corresponding (and error-prone!) use of `delete[]` later. That removes a 
> > memory leak LLVM won't have to debug.
> > 
> > You suggest here that something other than `std::vector` would be more 
> > efficient. If so, would `std::array` suffice? If not, can you explain why 
> > static allocation is impossible but dynamic allocation would be too 
> > expensive?
> A statically sized array (e.g., std::array) is insufficient because the size 
> in this case is not compiler determinable; a dynamically sized and 
> dynamically resizable array (e.g., std::vector) is sufficient but overly 
> costly; a dynamically sized and dynamically //unresizable// array is 
> sufficient and has minimal cost.
I'm not sure we allocate enough of these in the course of a compilation for the 
one extra word in a `std::vector` to matter, but I won't press the point.



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:17
+///implemented as a bit vector, wherein each bit corresponds to one edge in
+///the edge array. This implies a lower bound of 64x spacial improvement
+///over, e.g., an llvm::DenseSet or llvm::SmallSet. It also means that

"spatial"



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:41
+class ImmutableGraph {
+  using Traits = GraphTraits *>;
+  template  friend class ImmutableGraphBuilder;

I think this self-reference to `ImmutableGraph` dropped the `SizeT` parameter.



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:73
+// The end of this Node's edges is the beginning of the next node's edges.
+const Edge *edges_end() const { return (this + 1)->Edges; }
+ArrayRef edges() const {

Seems like you also want to add a comment here that we know we will never be 
asked for `edges_end` for the last stored node -- that is, we know that `this + 
1` always refers to a valid Node (which is presumably a dummy/sentinel)



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:79
+
+protected:
+  ImmutableGraph(std::unique_ptr Nodes, std::unique_ptr Edges,

Why "protected" rather than "private"? Usually seeing "protected" makes me 
think subclassing is expected, but that doesn't seem to be the case here.



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:117
+NodeSet(const ImmutableGraph &G, bool ContainsAll = false)
+: G{G}, V{static_cast(G.nodes_size()), ContainsAll} {}
+bool insert(const Node &N) {

How do we know that a value of `size_type` (aka `SizeT`) can be cast to 
`unsigned` without truncation?



Comment at: llvm/lib/Target/X86/ImmutableGraph.h:298
+  static_assert(
+  std::is_base_of,
+  GraphT>::value,

this will also break if a non-default `SizeT` is provided. Maybe a good 
argument to just leave out `SizeT` for now, and it can be added in the future 
as needed?



Comment at: llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp:113
+  NumFences(NumFences), NumGadgets(NumGadgets) {}
+MachineFunction &getMF() { // FIXME: This function should be cleaner
+  for (const Node &N : nodes())

Cleaner how?



Comment at: llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp:233
+  if (!STI->useLVILoadHardening() || !STI->is64Bit())
+return false; // FIXME: support 32-bit
+

If the user requests hardening and we can't do it, it seems better to fail 
loudly so they don't accidentally deploy an unmitigated binary.


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

https://reviews.llvm.org/D75936



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

[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau updated this revision to Diff 255626.
pgousseau added a comment.

Added label


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

https://reviews.llvm.org/D77393

Files:
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/xmmintrin.h
  clang/test/Headers/x86-header-warnings.c

Index: clang/test/Headers/x86-header-warnings.c
===
--- /dev/null
+++ clang/test/Headers/x86-header-warnings.c
@@ -0,0 +1,43 @@
+// Fix sign conversion warnings found by fsanitize=implicit-integer-sign-change
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \
+// RUN: | %clang_cc1 -x c - -triple x86_64-pc-linux-gnu -ffreestanding -Wsign-conversion -E -o - 2>&1 \
+// RUN: | FileCheck --allow-empty %s
+// REQUIRES: x86-registered-target
+
+#include 
+
+void test0() {
+  // CHECK-LABEL: test0
+  // CHECK-NOT: warning:
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_MASK);
+
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INVALID);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DENORM);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DIV_ZERO);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_OVERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_UNDERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INEXACT);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_MASK);
+
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INVALID);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DENORM);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DIV_ZERO);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_OVERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_UNDERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
+
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_UP);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_TOWARD_ZERO);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_MASK);
+
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_MASK);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
+}
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -2931,31 +2931,31 @@
 
 #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
 
-#define _MM_EXCEPT_INVALID(0x0001)
-#define _MM_EXCEPT_DENORM (0x0002)
-#define _MM_EXCEPT_DIV_ZERO   (0x0004)
-#define _MM_EXCEPT_OVERFLOW   (0x0008)
-#define _MM_EXCEPT_UNDERFLOW  (0x0010)
-#define _MM_EXCEPT_INEXACT(0x0020)
-#define _MM_EXCEPT_MASK   (0x003f)
-
-#define _MM_MASK_INVALID  (0x0080)
-#define _MM_MASK_DENORM   (0x0100)
-#define _MM_MASK_DIV_ZERO (0x0200)
-#define _MM_MASK_OVERFLOW (0x0400)
-#define _MM_MASK_UNDERFLOW(0x0800)
-#define _MM_MASK_INEXACT  (0x1000)
-#define _MM_MASK_MASK (0x1f80)
-
-#define _MM_ROUND_NEAREST (0x)
-#define _MM_ROUND_DOWN(0x2000)
-#define _MM_ROUND_UP  (0x4000)
-#define _MM_ROUND_TOWARD_ZERO (0x6000)
-#define _MM_ROUND_MASK(0x6000)
-
-#define _MM_FLUSH_ZERO_MASK   (0x8000)
-#define _MM_FLUSH_ZERO_ON (0x8000)
-#define _MM_FLUSH_ZERO_OFF(0x)
+#define _MM_EXCEPT_INVALID(0x0001U)
+#define _MM_EXCEPT_DENORM (0x0002U)
+#define _MM_EXCEPT_DIV_ZERO   (0x0004U)
+#define _MM_EXCEPT_OVERFLOW   (0x0008U)
+#define _MM_EXCEPT_UNDERFLOW  (0x0010U)
+#define _MM_EXCEPT_INEXACT(0x0020U)
+#define _MM_EXCEPT_MASK   (0x003fU)
+
+#define _MM_MASK_INVALID  (0x0080U)
+#define _MM_MASK_DENORM   (0x0100U)
+#define _MM_MASK_DIV_ZERO (0x0200U)
+#define _MM_MASK_OVERFLOW (0x0400U)
+#define _MM_MASK_UNDERFLOW(0x0800U)
+#define _MM_MASK_INEXACT  (0x1000U)
+#define _MM_MASK_MASK (0x1f80U)
+
+#define _MM_ROUND_NEAREST (0xU)
+#define _MM_ROUND_DOWN(0x2000U)
+#define _MM_ROUND_UP  (0x4000U)
+#define _MM_ROUND_TOWARD_ZERO (0x6000U)
+#define _MM_ROUND_MASK(0x6000U)
+
+#define _MM_FLUSH_ZERO_MASK   (0x8000U)
+#define _MM_FLUSH_ZERO_ON (0x8000U)
+#define _MM_FLUSH_ZERO_OFF(0xU)
 
 #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
 #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)
Index: clang/lib/Headers/emmintrin.h
===
--- clang/lib/Headers/emmintrin.h
+++ clang/lib/Headers/emmintrin.h
@@ -4970,10 +4970,10 @@
 
 #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
 
-#define _MM_DENORMALS_ZERO_ON   (0x0040)
-#define _MM_DENORMALS_ZERO_OFF  (0x)
+#define _MM_DENORMALS_ZERO_ON   (0x0040U)
+#define _MM_DENORMALS_ZERO_OFF  (0xU)
 
-#define _MM_DENORMALS_ZERO_MASK (0x0040)
+#define _MM_DENORMALS_ZERO_MASK (0x0040U)
 
 #define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)

[PATCH] D77309: [clangd] Get rid of ASTWorker::getCurrentFileInputs

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:459
   /// be consumed by clients of ASTWorker.
-  std::shared_ptr FileInputs; /* GUARDED_BY(Mutex) */
+  ParseInputs FileInputs; /* GUARDED_BY(Mutex) */
   /// Times of recent AST rebuilds, used for UpdateDebounce computation.

this GUARDED_BY comment is a bit misleading.
I'd be more explicit here as it's a bit unusual:
// Writes and reads from unknown threads are locked.
// Reads from the worker thread are not locked as it's the only writer thread.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77309



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


[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08fab9ebecf7: [X86] Fix implicit sign conversion warnings in 
X86 headers. (authored by Pierre Gousseau ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77393

Files:
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/xmmintrin.h
  clang/test/Headers/x86-header-warnings.c

Index: clang/test/Headers/x86-header-warnings.c
===
--- /dev/null
+++ clang/test/Headers/x86-header-warnings.c
@@ -0,0 +1,43 @@
+// Fix sign conversion warnings found by fsanitize=implicit-integer-sign-change
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \
+// RUN: | %clang_cc1 -x c - -triple x86_64-pc-linux-gnu -ffreestanding -Wsign-conversion -E -o - 2>&1 \
+// RUN: | FileCheck --allow-empty %s
+// REQUIRES: x86-registered-target
+
+#include 
+
+void test0() {
+  // CHECK-LABEL: test0
+  // CHECK-NOT: warning:
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_MASK);
+
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INVALID);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DENORM);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DIV_ZERO);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_OVERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_UNDERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INEXACT);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_MASK);
+
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INVALID);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DENORM);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DIV_ZERO);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_OVERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_UNDERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
+
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_UP);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_TOWARD_ZERO);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_MASK);
+
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_MASK);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
+}
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -2931,31 +2931,31 @@
 
 #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
 
-#define _MM_EXCEPT_INVALID(0x0001)
-#define _MM_EXCEPT_DENORM (0x0002)
-#define _MM_EXCEPT_DIV_ZERO   (0x0004)
-#define _MM_EXCEPT_OVERFLOW   (0x0008)
-#define _MM_EXCEPT_UNDERFLOW  (0x0010)
-#define _MM_EXCEPT_INEXACT(0x0020)
-#define _MM_EXCEPT_MASK   (0x003f)
-
-#define _MM_MASK_INVALID  (0x0080)
-#define _MM_MASK_DENORM   (0x0100)
-#define _MM_MASK_DIV_ZERO (0x0200)
-#define _MM_MASK_OVERFLOW (0x0400)
-#define _MM_MASK_UNDERFLOW(0x0800)
-#define _MM_MASK_INEXACT  (0x1000)
-#define _MM_MASK_MASK (0x1f80)
-
-#define _MM_ROUND_NEAREST (0x)
-#define _MM_ROUND_DOWN(0x2000)
-#define _MM_ROUND_UP  (0x4000)
-#define _MM_ROUND_TOWARD_ZERO (0x6000)
-#define _MM_ROUND_MASK(0x6000)
-
-#define _MM_FLUSH_ZERO_MASK   (0x8000)
-#define _MM_FLUSH_ZERO_ON (0x8000)
-#define _MM_FLUSH_ZERO_OFF(0x)
+#define _MM_EXCEPT_INVALID(0x0001U)
+#define _MM_EXCEPT_DENORM (0x0002U)
+#define _MM_EXCEPT_DIV_ZERO   (0x0004U)
+#define _MM_EXCEPT_OVERFLOW   (0x0008U)
+#define _MM_EXCEPT_UNDERFLOW  (0x0010U)
+#define _MM_EXCEPT_INEXACT(0x0020U)
+#define _MM_EXCEPT_MASK   (0x003fU)
+
+#define _MM_MASK_INVALID  (0x0080U)
+#define _MM_MASK_DENORM   (0x0100U)
+#define _MM_MASK_DIV_ZERO (0x0200U)
+#define _MM_MASK_OVERFLOW (0x0400U)
+#define _MM_MASK_UNDERFLOW(0x0800U)
+#define _MM_MASK_INEXACT  (0x1000U)
+#define _MM_MASK_MASK (0x1f80U)
+
+#define _MM_ROUND_NEAREST (0xU)
+#define _MM_ROUND_DOWN(0x2000U)
+#define _MM_ROUND_UP  (0x4000U)
+#define _MM_ROUND_TOWARD_ZERO (0x6000U)
+#define _MM_ROUND_MASK(0x6000U)
+
+#define _MM_FLUSH_ZERO_MASK   (0x8000U)
+#define _MM_FLUSH_ZERO_ON (0x8000U)
+#define _MM_FLUSH_ZERO_OFF(0xU)
 
 #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
 #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)
Index: clang/lib/Headers/emmintrin.h
===
--- clang/lib/Headers/emmintrin.h
+++ clang/lib/Headers/emmintrin.h
@@ -4970,10 +4970,10 @@
 
 #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
 
-#define _MM_DENORMALS_ZERO_ON   (0x0040)
-#define _MM_DENORMALS_ZERO_OFF  (0x)
+#define _MM_DENORMALS_ZERO_ON   (0x0040U)
+#define _MM_DENORMALS_ZERO_OFF  (0

[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/test/Headers/x86-header-warnings.c:3
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \

Does Wsystem-headers add too much noise?


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

https://reviews.llvm.org/D77393



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


[clang-tools-extra] 353a988 - [clangd] DefineOutline: removes static token from static CXXMethodDecl

2020-04-07 Thread Nathan James via cfe-commits
Author: Nathan James
Date: 2020-04-07T11:57:43+01:00
New Revision: 353a9883680e9d9666d02516a6692e8319af6d66

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

LOG: [clangd] DefineOutline: removes static token from static CXXMethodDecl

Summary: Removes the `static` token when defining a function out of line if the 
function is a `CXXMethodDecl`

Reviewers: sammccall, kadircet, hokein

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang, #clang-tools-extra

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index d9e07a001d23..c2d344a3a46e 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -239,21 +239,22 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
   DelAttr(FD->getAttr());
   DelAttr(FD->getAttr());
 
-  if (FD->isVirtualAsWritten()) {
-SourceRange SpecRange{FD->getBeginLoc(), FD->getLocation()};
-bool HasErrors = true;
-
-// Clang allows duplicating virtual specifiers so check for multiple
-// occurrences.
-for (const auto &Tok : TokBuf.expandedTokens(SpecRange)) {
-  if (Tok.kind() != tok::kw_virtual)
+  auto DelKeyword = [&](tok::TokenKind Kind, SourceRange FromRange) {
+bool FoundAny = false;
+for (const auto &Tok : TokBuf.expandedTokens(FromRange)) {
+  if (Tok.kind() != Kind)
 continue;
+  FoundAny = true;
   auto Spelling = TokBuf.spelledForExpanded(llvm::makeArrayRef(Tok));
   if (!Spelling) {
-HasErrors = true;
+Errors = llvm::joinErrors(
+std::move(Errors),
+llvm::createStringError(
+llvm::inconvertibleErrorCode(),
+llvm::formatv("define outline: couldn't remove `{0}` keyword.",
+  tok::getKeywordSpelling(Kind;
 break;
   }
-  HasErrors = false;
   CharSourceRange DelRange =
   syntax::Token::range(SM, Spelling->front(), Spelling->back())
   .toCharRange(SM);
@@ -261,13 +262,22 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
   DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
 Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
-if (HasErrors) {
+if (!FoundAny) {
   Errors = llvm::joinErrors(
   std::move(Errors),
-  llvm::createStringError(llvm::inconvertibleErrorCode(),
-  "define outline: Can't move out of line as "
-  "function has a macro `virtual` 
specifier."));
+  llvm::createStringError(
+  llvm::inconvertibleErrorCode(),
+  llvm::formatv(
+  "define outline: couldn't find `{0}` keyword to remove.",
+  tok::getKeywordSpelling(Kind;
 }
+  };
+
+  if (const auto *MD = dyn_cast(FD)) {
+if (MD->isVirtualAsWritten())
+  DelKeyword(tok::kw_virtual, {FD->getBeginLoc(), FD->getLocation()});
+if (MD->isStatic())
+  DelKeyword(tok::kw_static, {FD->getBeginLoc(), FD->getLocation()});
   }
 
   if (Errors)

diff  --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp 
b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index e91ff22d3533..979ee44f4474 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2142,6 +2142,28 @@ TEST_F(DefineOutlineTest, ApplyTest) {
 };)cpp",
   "void B::foo()   {}\n",
   },
+  {
+  R"cpp(
+struct A {
+  static void fo^o() {}
+};)cpp",
+  R"cpp(
+struct A {
+  static void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  static static void fo^o() {}
+};)cpp",
+  R"cpp(
+struct A {
+  static static void foo() ;
+};)cpp",
+  "  void A::foo() {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2236,6 +2258,24 @@ TEST_F(DefineOutlineTest, HandleMacros) {
 STUPID_MACRO(sizeof sizeof int) void foo() ;
   };)cpp",
" void A::foo() {}\n"},
+  {R"cpp(#define STAT static
+  struct A {
+STAT void f^oo() {}
+ 

[clang] 3d1424b - Fixed licenses in dynamic ast matchers

2020-04-07 Thread Nathan James via cfe-commits
Author: Nathan James
Date: 2020-04-07T12:08:06+01:00
New Revision: 3d1424bc7a0e9a6f9887727e2bc93a10f50e1709

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

LOG: Fixed licenses in dynamic ast matchers

Added: 


Modified: 
clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/ASTMatchers/Dynamic/VariantValue.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h 
b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
index e317d3339e5b..e47b42a4f38c 100644
--- a/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ b/clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -1,4 +1,5 @@
-//===--- VariantValue.h - Polymorphic value type -*- C++ -*-===/
+//===--- VariantValue.h - Polymorphic value type *- 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

diff  --git a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp 
b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
index 969bd5f31789..88c2279afb2e 100644
--- a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
@@ -1,4 +1,4 @@
-//===--- Diagnostics.cpp - Helper class for error diagnostics -*- C++ 
-*-===//
+//===--- Diagnostics.cpp - Helper class for error diagnostics ---*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
index 64ff0dfb690e..46312284e088 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -1,3 +1,11 @@
+//===--- Marshallers.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 "Marshallers.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"

diff  --git a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp 
b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
index 7d0fb6ae2038..866e2d0e3491 100644
--- a/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -1,4 +1,4 @@
-//===--- VariantValue.cpp - Polymorphic value type -*- C++ -*-===/
+//===--- VariantValue.cpp - Polymorphic value type --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

still LG




Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:588
+auto &NextSpelled = this->NextSpelled[File];
+
+if (Tok.location().isFileID()) {

sammccall wrote:
> kadircet wrote:
> > nit: maybe create mapping here and increment NextSpelled and NextExpanded 
> > explicitly here.
> Not quite sure what you mean here, my guesses...
> 
> Hoisting mapping creation to here: If we have file tokens, we're not creating 
> a mapping. Only nontrivial mappings are stored (where the spelled and 
> expanded locations differ). This may be a design mistake but it's not one I'm 
> fixing in this patch :-)
> 
> Incrementing NextSpelled and NextExpanded eagerly: if our invariants hold 
> (expanded and spelled tokens really do correspond) then we will indeed 
> increment each of these at least once, so we could structure the code that 
> way. However those invariants are ridiculously subtle and fragile (basically 
> depends on the correctness of the TokenWatcher impl in Preprocessor) so in 
> practice it's good not to advance if our assumptions aren't met so we can 
> actually debug the result. The latest version of the patch makes use of this 
> to detect and crash with a useful message (diagnoseAdvanceFailure).
i was talking about the latter (eagerly incrementing).

With the latest diagnosing mechanism, i also agree that it should stay that way.



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:526
+// Create empty mappings up until the end of the file.
+for (const auto& File : Result.Files)
+  discard(File.first);

nit: formatting



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:641
 
+
   /// Initializes TokenBuffer::Files and fills spelled tokens and expanded

nit: format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614



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


[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau marked 2 inline comments as done.
pgousseau added inline comments.



Comment at: clang/test/Headers/x86-header-warnings.c:12
+void test() {
+  // CHECK-NOT: warning:
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

RKSimon wrote:
> Add a LABEL check as well
Adding label sounds good, went ahead and commited without checking the test was 
not failing anymore, sorry will revert.



Comment at: clang/test/Headers/x86-header-warnings.c:3
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \

thakis wrote:
> Does Wsystem-headers add too much noise?
Thanks for the suggestion, I did not thought about adding Wsystem-headers, I 
tested Wsystem-headers now though and cant seem to pick up on that particular 
issue without the preprocessing step.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77393



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


[PATCH] D77309: [clangd] Get rid of ASTWorker::getCurrentFileInputs

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 255632.
kadircet marked an inline comment as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77309

Files:
  clang-tools-extra/clangd/TUScheduler.cpp

Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -423,10 +423,6 @@
   Deadline scheduleLocked();
   /// Should the first task in the queue be skipped instead of run?
   bool shouldSkipHeadLocked() const;
-  /// This is private because `FileInputs.FS` is not thread-safe and thus not
-  /// safe to share. Callers should make sure not to expose `FS` via a public
-  /// interface.
-  std::shared_ptr getCurrentFileInputs() const;
 
   struct Request {
 llvm::unique_function Action;
@@ -458,9 +454,9 @@
   /// Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
   /// File inputs, currently being used by the worker.
-  /// Inputs are written and read by the worker thread, compile command can also
-  /// be consumed by clients of ASTWorker.
-  std::shared_ptr FileInputs; /* GUARDED_BY(Mutex) */
+  /// Writes and reads from unknown threads are locked. Reads from the worker
+  /// thread are not locked, as it's the only writer.
+  ParseInputs FileInputs; /* GUARDED_BY(Mutex) */
   /// Times of recent AST rebuilds, used for UpdateDebounce computation.
   llvm::SmallVector
   RebuildTimes; /* GUARDED_BY(Mutex) */
@@ -556,12 +552,10 @@
// FIXME: Run PreamblePeer asynchronously once ast patching
// is available.
/*RunSync=*/true, Status, *this) {
-  auto Inputs = std::make_shared();
   // Set a fallback command because compile command can be accessed before
   // `Inputs` is initialized. Other fields are only used after initialization
   // from client inputs.
-  Inputs->CompileCommand = CDB.getFallbackCommand(FileName);
-  FileInputs = std::move(Inputs);
+  FileInputs.CompileCommand = CDB.getFallbackCommand(FileName);
 }
 
 ASTWorker::~ASTWorker() {
@@ -590,7 +584,7 @@
   Inputs.CompileCommand = CDB.getFallbackCommand(FileName);
 
 bool InputsAreTheSame =
-std::tie(FileInputs->CompileCommand, FileInputs->Contents) ==
+std::tie(FileInputs.CompileCommand, FileInputs.Contents) ==
 std::tie(Inputs.CompileCommand, Inputs.Contents);
 // Cached AST is invalidated.
 if (!InputsAreTheSame) {
@@ -601,7 +595,7 @@
 // Update current inputs so that subsequent reads can see them.
 {
   std::lock_guard Lock(Mutex);
-  FileInputs = std::make_shared(Inputs);
+  FileInputs = Inputs;
 }
 
 log("ASTWorker building file {0} version {1} with command {2}\n[{3}]\n{4}",
@@ -655,21 +649,20 @@
 if (isCancelled())
   return Action(llvm::make_error());
 llvm::Optional> AST = IdleASTs.take(this);
-auto CurrentInputs = getCurrentFileInputs();
 if (!AST) {
   StoreDiags CompilerInvocationDiagConsumer;
-  std::unique_ptr Invocation = buildCompilerInvocation(
-  *CurrentInputs, CompilerInvocationDiagConsumer);
+  std::unique_ptr Invocation =
+  buildCompilerInvocation(FileInputs, CompilerInvocationDiagConsumer);
   // Try rebuilding the AST.
   vlog("ASTWorker rebuilding evicted AST to run {0}: {1} version {2}", Name,
-   FileName, CurrentInputs->Version);
+   FileName, FileInputs.Version);
   // FIXME: We might need to build a patched ast once preamble thread starts
   // running async. Currently getPossiblyStalePreamble below will always
   // return a compatible preamble as ASTWorker::update blocks.
   llvm::Optional NewAST =
   Invocation ? buildAST(FileName, std::move(Invocation),
 CompilerInvocationDiagConsumer.take(),
-*CurrentInputs, getPossiblyStalePreamble())
+FileInputs, getPossiblyStalePreamble())
  : None;
   AST = NewAST ? std::make_unique(std::move(*NewAST)) : nullptr;
 }
@@ -681,8 +674,8 @@
   return Action(llvm::make_error(
   "invalid AST", llvm::errc::invalid_argument));
 vlog("ASTWorker running {0} on version {2} of {1}", Name, FileName,
- CurrentInputs->Version);
-Action(InputsAndAST{*CurrentInputs, **AST});
+ FileInputs.Version);
+Action(InputsAndAST{FileInputs, **AST});
   };
   startTask(Name, std::move(Task), /*UpdateType=*/None, Invalidation);
 }
@@ -782,7 +775,7 @@
   }
   // Used to check whether we can update AST cache.
   bool InputsAreLatest =
-  std::tie(FileInputs->CompileCommand, FileInputs->Contents) ==
+  std::tie(FileInputs.CompileCommand, FileInputs.Contents) ==
   std::tie(Inputs.CompileCommand, I

[PATCH] D77534: [clangd] DefineOutline: removes static token from static CXXMethodDecl

2020-04-07 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG353a9883680e: [clangd] DefineOutline: removes static token 
from static CXXMethodDecl (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77534

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2142,6 +2142,28 @@
 };)cpp",
   "void B::foo()   {}\n",
   },
+  {
+  R"cpp(
+struct A {
+  static void fo^o() {}
+};)cpp",
+  R"cpp(
+struct A {
+  static void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  static static void fo^o() {}
+};)cpp",
+  R"cpp(
+struct A {
+  static static void foo() ;
+};)cpp",
+  "  void A::foo() {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2236,6 +2258,24 @@
 STUPID_MACRO(sizeof sizeof int) void foo() ;
   };)cpp",
" void A::foo() {}\n"},
+  {R"cpp(#define STAT static
+  struct A {
+STAT void f^oo() {}
+  };)cpp",
+   R"cpp(#define STAT static
+  struct A {
+STAT void foo() ;
+  };)cpp",
+   " void A::foo() {}\n"},
+  {R"cpp(#define STUPID_MACRO(X) static
+  struct A {
+STUPID_MACRO(sizeof sizeof int) void f^oo() {}
+  };)cpp",
+   R"cpp(#define STUPID_MACRO(X) static
+  struct A {
+STUPID_MACRO(sizeof sizeof int) void foo() ;
+  };)cpp",
+   " void A::foo() {}\n"},
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2360,8 +2400,7 @@
   struct A {
 VIRT fo^o() {}
   };)cpp",
-  "fail: define outline: Can't move out of line as function has a "
-  "macro `virtual` specifier."},
+  "fail: define outline: couldn't remove `virtual` keyword."},
   {
   R"cpp(
   #define OVERFINAL final override
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -239,21 +239,22 @@
   DelAttr(FD->getAttr());
   DelAttr(FD->getAttr());
 
-  if (FD->isVirtualAsWritten()) {
-SourceRange SpecRange{FD->getBeginLoc(), FD->getLocation()};
-bool HasErrors = true;
-
-// Clang allows duplicating virtual specifiers so check for multiple
-// occurrences.
-for (const auto &Tok : TokBuf.expandedTokens(SpecRange)) {
-  if (Tok.kind() != tok::kw_virtual)
+  auto DelKeyword = [&](tok::TokenKind Kind, SourceRange FromRange) {
+bool FoundAny = false;
+for (const auto &Tok : TokBuf.expandedTokens(FromRange)) {
+  if (Tok.kind() != Kind)
 continue;
+  FoundAny = true;
   auto Spelling = TokBuf.spelledForExpanded(llvm::makeArrayRef(Tok));
   if (!Spelling) {
-HasErrors = true;
+Errors = llvm::joinErrors(
+std::move(Errors),
+llvm::createStringError(
+llvm::inconvertibleErrorCode(),
+llvm::formatv("define outline: couldn't remove `{0}` keyword.",
+  tok::getKeywordSpelling(Kind;
 break;
   }
-  HasErrors = false;
   CharSourceRange DelRange =
   syntax::Token::range(SM, Spelling->front(), Spelling->back())
   .toCharRange(SM);
@@ -261,13 +262,22 @@
   DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
 Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
-if (HasErrors) {
+if (!FoundAny) {
   Errors = llvm::joinErrors(
   std::move(Errors),
-  llvm::createStringError(llvm::inconvertibleErrorCode(),
-  "define outline: Can't move out of line as "
-  "function has a macro `virtual` specifier."));
+  llvm::createStringError(
+  llvm::inconvertibleErrorCode(),
+  llvm::formatv(
+  "define outline: couldn't find `{0}` keyword to remove.",
+  tok::getKeywordSpelling(Kind;
 }
+  };
+
+  if (const auto *MD = dyn_cast(FD)) {
+if (MD->isVirtualAsWritten())
+  DelKeyword(tok::kw_virtual, {FD->getBeginLoc(), FD->getLocation()});
+if (MD->isStatic())
+  DelKey

[clang] a010ef8 - Add map-type check for target and target data directive, by Chi Chun

2020-04-07 Thread Alexey Bataev via cfe-commits
Author: cchen
Date: 2020-04-07T07:15:52-04:00
New Revision: a010ef8bd88fe28908c48362b04f59b89ad41250

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

LOG: Add map-type check for target and target data directive, by Chi Chun
Chen

Reviewers: ABataev, jdoerfert

Reviewed By: ABataev

Subscribers: cfe-commits, dreachem, sandoval

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/Analysis/cfg-openmp.cpp
clang/test/OpenMP/target_data_messages.c
clang/test/OpenMP/target_map_messages.cpp
clang/test/OpenMP/target_parallel_for_map_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
clang/test/OpenMP/target_parallel_map_messages.cpp
clang/test/OpenMP/target_simd_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
clang/test/OpenMP/target_teams_map_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index dfb809e0aaa1..e9b18f6e9307 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -16998,6 +16998,21 @@ static void checkMappableExpressionList(
 continue;
   }
 
+  // target, target data
+  // OpenMP 5.0 [2.12.2, Restrictions, p. 163]
+  // OpenMP 5.0 [2.12.5, Restrictions, p. 174]
+  // A map-type in a map clause must be to, from, tofrom or alloc
+  if ((DKind == OMPD_target_data ||
+   isOpenMPTargetExecutionDirective(DKind)) &&
+  !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
+MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc)) {
+SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive)
+<< (IsMapTypeImplicit ? 1 : 0)
+<< getOpenMPSimpleClauseTypeName(OMPC_map, MapType)
+<< getOpenMPDirectiveName(DKind);
+continue;
+  }
+
   // OpenMP 4.5 [2.15.5.1, Restrictions, p.3]
   // A list item cannot appear in both a map clause and a data-sharing
   // attribute clause on the same construct

diff  --git a/clang/test/Analysis/cfg-openmp.cpp 
b/clang/test/Analysis/cfg-openmp.cpp
index 51107e52a7ad..9e61d656698b 100644
--- a/clang/test/Analysis/cfg-openmp.cpp
+++ b/clang/test/Analysis/cfg-openmp.cpp
@@ -462,10 +462,10 @@ void ttd(int argc) {
 // CHECK-DAG:  [[#TTD+4]]: rd
 // CHECK-DAG:  [[#TTD+5]]: [B3.[[#TTDB+2]]]
 // CHECK-DAG:  [[#TTD+6]]: [B3.[[#TTDB]]]
-// CHECK-DAG:  [[#TTD+7]]: #pragma omp target teams distribute if(cond) 
firstprivate(fp) reduction(+: rd) map(release: map)
+// CHECK-DAG:  [[#TTD+7]]: #pragma omp target teams distribute if(cond) 
firstprivate(fp) reduction(+: rd) map(alloc: map)
 // CHECK-DAG:for (int i = 0;
 // CHECK-DAG:[B3.[[#TTDB+3]]];
-#pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+:rd) 
map(release:map)
+#pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+:rd) 
map(alloc:map)
   for (int i = 0; i < 10; ++i)
 argc = x;
 }
@@ -486,10 +486,10 @@ void ttdpf(int argc) {
 // CHECK-DAG:  [[#TTDPF+4]]: rd
 // CHECK-DAG:  [[#TTDPF+5]]: [B3.[[#TTDPFB+2]]]
 // CHECK-DAG:  [[#TTDPF+6]]: [B3.[[#TTDPFB]]]
-// CHECK-DAG:  [[#TTDPF+7]]: #pragma omp target teams distribute parallel for 
if(cond) firstprivate(fp) reduction(+: rd) map(delete: map)
+// CHECK-DAG:  [[#TTDPF+7]]: #pragma omp target teams distribute parallel for 
if(cond) firstprivate(fp) reduction(+: rd) map(alloc: map)
 // CHECK-DAG:for (int i = 0;
 // CHECK-DAG:[B3.[[#TTDPFB+3]]];
-#pragma omp target teams distribute parallel for if(cond) firstprivate(fp) 
reduction(+:rd) map(delete:map)
+#pragma omp target teams distribute parallel for if(cond) firstprivate(fp) 
reduction(+:rd) map(alloc:map)
   for (int i = 0; i < 10; ++i)
 argc = x;
 }

diff  --git a/clang/test/OpenMP/target_data_messages.c 
b/clang/test/OpenMP/target_data_messages.c
index 7dd48f7e507e..32d2c130d4e9 100644
--- a/clang/test/OpenMP/target_data_messages.c
+++ b/clang/test/OpenMP/target_data_messages.c
@@ -35,5 +35,13 @@ int main(int argc, char **argv) {
   {
 foo();
   }
+  #pragma omp target data map(delete: a) // expected-error {{map type 'delete' 
is not allowed for '#pragma omp target data'}}
+  {
+foo();
+  }
+  #pragma omp target data map(release: a) // expected-error {{map type 
'release' is not allowed for '#pragma omp target data'}}
+  {
+foo();
+  }
   return 0;
 }

diff  --git a/clang/test/OpenMP/target_map_messages.cpp 
b/clang/test/OpenMP/target_map_messages.cpp
index a18590fc85fe..556df1cf3e14 100644

[clang-tools-extra] 4ac7b80 - [clangd] Get rid of ASTWorker::getCurrentFileInputs

2020-04-07 Thread Kadir Cetinkaya via cfe-commits
Author: Kadir Cetinkaya
Date: 2020-04-07T13:48:00+02:00
New Revision: 4ac7b805b7c4aa7af0a82d6187e3bd6ac0cf38cd

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

LOG: [clangd] Get rid of ASTWorker::getCurrentFileInputs

Summary:
FileInputs are only written by ASTWorker thread, therefore it is safe
to read them without the lock inside that thread. It can still be read by other
threads through ASTWorker::getCurrentCompileCommand though.

This patch also gets rid of the smart pointer wrapping FileInputs as there is
never mutliple owners.

Reviewers: sammccall

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index bf847c1c86b4..be4d52e7d881 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -423,10 +423,6 @@ class ASTWorker {
   Deadline scheduleLocked();
   /// Should the first task in the queue be skipped instead of run?
   bool shouldSkipHeadLocked() const;
-  /// This is private because `FileInputs.FS` is not thread-safe and thus not
-  /// safe to share. Callers should make sure not to expose `FS` via a public
-  /// interface.
-  std::shared_ptr getCurrentFileInputs() const;
 
   struct Request {
 llvm::unique_function Action;
@@ -458,9 +454,9 @@ class ASTWorker {
   /// Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
   /// File inputs, currently being used by the worker.
-  /// Inputs are written and read by the worker thread, compile command can 
also
-  /// be consumed by clients of ASTWorker.
-  std::shared_ptr FileInputs; /* GUARDED_BY(Mutex) */
+  /// Writes and reads from unknown threads are locked. Reads from the worker
+  /// thread are not locked, as it's the only writer.
+  ParseInputs FileInputs; /* GUARDED_BY(Mutex) */
   /// Times of recent AST rebuilds, used for UpdateDebounce computation.
   llvm::SmallVector
   RebuildTimes; /* GUARDED_BY(Mutex) */
@@ -556,12 +552,10 @@ ASTWorker::ASTWorker(PathRef FileName, const 
GlobalCompilationDatabase &CDB,
// FIXME: Run PreamblePeer asynchronously once ast patching
// is available.
/*RunSync=*/true, Status, *this) {
-  auto Inputs = std::make_shared();
   // Set a fallback command because compile command can be accessed before
   // `Inputs` is initialized. Other fields are only used after initialization
   // from client inputs.
-  Inputs->CompileCommand = CDB.getFallbackCommand(FileName);
-  FileInputs = std::move(Inputs);
+  FileInputs.CompileCommand = CDB.getFallbackCommand(FileName);
 }
 
 ASTWorker::~ASTWorker() {
@@ -590,7 +584,7 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics 
WantDiags) {
   Inputs.CompileCommand = CDB.getFallbackCommand(FileName);
 
 bool InputsAreTheSame =
-std::tie(FileInputs->CompileCommand, FileInputs->Contents) ==
+std::tie(FileInputs.CompileCommand, FileInputs.Contents) ==
 std::tie(Inputs.CompileCommand, Inputs.Contents);
 // Cached AST is invalidated.
 if (!InputsAreTheSame) {
@@ -601,7 +595,7 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics 
WantDiags) {
 // Update current inputs so that subsequent reads can see them.
 {
   std::lock_guard Lock(Mutex);
-  FileInputs = std::make_shared(Inputs);
+  FileInputs = Inputs;
 }
 
 log("ASTWorker building file {0} version {1} with command {2}\n[{3}]\n{4}",
@@ -655,21 +649,20 @@ void ASTWorker::runWithAST(
 if (isCancelled())
   return Action(llvm::make_error());
 llvm::Optional> AST = IdleASTs.take(this);
-auto CurrentInputs = getCurrentFileInputs();
 if (!AST) {
   StoreDiags CompilerInvocationDiagConsumer;
-  std::unique_ptr Invocation = buildCompilerInvocation(
-  *CurrentInputs, CompilerInvocationDiagConsumer);
+  std::unique_ptr Invocation =
+  buildCompilerInvocation(FileInputs, CompilerInvocationDiagConsumer);
   // Try rebuilding the AST.
   vlog("ASTWorker rebuilding evicted AST to run {0}: {1} version {2}", 
Name,
-   FileName, CurrentInputs->Version);
+   FileName, FileInputs.Version);
   // FIXME: We might need to build a patched ast once preamble thread 
starts
   // running async. Currently getPossiblyStalePreamble below will always
   // return a compatible preamble as ASTWorker::update blocks.
   llvm::Optional NewAST =
   Invocation ? buildAST(FileName, std::move(Invocation),
  

[clang-tools-extra] 59c2810 - [clangd] Fix printing for Inclusion

2020-04-07 Thread Kadir Cetinkaya via cfe-commits
Author: Kadir Cetinkaya
Date: 2020-04-07T13:48:00+02:00
New Revision: 59c28103a4a4d05db036157605a52a8075d60082

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

LOG: [clangd] Fix printing for Inclusion

Added: 


Modified: 
clang-tools-extra/clangd/Headers.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index e94a768e9eb7..295d6e67477d 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -227,7 +227,7 @@ IncludeInserter::insert(llvm::StringRef VerbatimHeader) 
const {
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Inclusion &Inc) {
   return OS << Inc.Written << " = "
-<< (Inc.Resolved.empty() ? Inc.Resolved : "[unresolved]") << " at "
+<< (!Inc.Resolved.empty() ? Inc.Resolved : "[unresolved]") << " at 
"
 << Inc.R;
 }
 



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


[PATCH] D77637: [part 2] sancov/inline-bool-flag clang flags.

2020-04-07 Thread Pratyai Mazumder via Phabricator via cfe-commits
pratyai updated this revision to Diff 255638.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77637

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  clang/test/Driver/fsanitize-coverage.c

Index: clang/test/Driver/fsanitize-coverage.c
===
--- clang/test/Driver/fsanitize-coverage.c
+++ clang/test/Driver/fsanitize-coverage.c
@@ -105,9 +105,18 @@
 // CHECK_INLINE8BIT-NOT: warning
 // CHECK_INLINE8BIT: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// CHECK_PC_TABLE: -fsanitize-coverage-pc-table
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=bb,inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// CHECK_INLINE_BOOL_FLAG-NOT: warning
+// CHECK_INLINE_BOOL_FLAG: -fsanitize-coverage-inline-bool-flag
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// CHECK_PC_TABLE_FOR_INLINE8BIT: -fsanitize-coverage-pc-table
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// CHECK_PC_TABLE_FOR_INLINEBOOL: -fsanitize-coverage-pc-table
 
 // RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address -fsanitize-coverage=func,trace-pc-guard -c -### -- %s 2>&1 | FileCheck %s -check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -54,6 +54,7 @@
 // FNOSANICOVERALL-NEXT: func
 // FNOSANICOVERALL-NEXT: indirect-calls
 // FNOSANICOVERALL-NEXT: inline-8bit-counters
+// FNOSANICOVERALL-NEXT: inline-bool-flag
 // FNOSANICOVERALL-NEXT: no-prune
 // FNOSANICOVERALL-NEXT: trace-bb
 // FNOSANICOVERALL-NEXT: trace-cmp
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1175,6 +1175,8 @@
   Opts.SanitizeCoverageNoPrune = Args.hasArg(OPT_fsanitize_coverage_no_prune);
   Opts.SanitizeCoverageInline8bitCounters =
   Args.hasArg(OPT_fsanitize_coverage_inline_8bit_counters);
+  Opts.SanitizeCoverageInlineBoolFlag =
+  Args.hasArg(OPT_fsanitize_coverage_inline_bool_flag);
   Opts.SanitizeCoveragePCTable = Args.hasArg(OPT_fsanitize_coverage_pc_table);
   Opts.SanitizeCoverageStackDepth =
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -77,17 +77,18 @@
   CoverageBB = 1 << 1,
   CoverageEdge = 1 << 2,
   CoverageIndirCall = 1 << 3,
-  CoverageTraceBB = 1 << 4,  // Deprecated.
+  CoverageTraceBB = 1 << 4, // Deprecated.
   CoverageTraceCmp = 1 << 5,
   CoverageTraceDiv = 1 << 6,
   CoverageTraceGep = 1 << 7,
-  Coverage8bitCounters = 1 << 8,  // Deprecated.
+  Coverage8bitCounters = 1 << 8, // Deprecated.
   CoverageTracePC = 1 << 9,
   CoverageTracePCGuard = 1 << 10,
   CoverageNoPrune = 1 << 11,
   CoverageInline8bitCounters = 1 << 12,
   CoveragePCTable = 1 << 13,
   CoverageStackDepth = 1 << 14,
+  CoverageInlineBoolFlag = 1 << 15,
 };
 
 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
@@ -380,7 +381,8 @@
 
   // Enable coverage if the fuzzing flag is set.
   if (Add & SanitizerKind::FuzzerNoLink) {
-CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
+CoverageFeatures |= CoverageInline8bitCounters |
+CoverageInlineBoolFlag | CoverageIndirCall |
 Cove

[PATCH] D77385: [clangd] Add index export to dexp

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, this looks pretty good!




Comment at: clang-tools-extra/clangd/index/YAMLSerialization.cpp:36
 
 namespace {
 using RefBundle =

this is independent of adding the dump command - can we split this into a 
separate patch?
Partly because it will need to have some basic testing :-(



Comment at: clang-tools-extra/clangd/index/YAMLSerialization.cpp:355
+
+  FileDigest denormalize(IO &I) {
+auto Digest = fromStr(HexString);

this + 2 helpers seems a bit verbose/indirect.

```
FileDigest D;
if (HexString.size() == D.size() && llvm::all_of(HexString, llvm:isHexDigit)) {
  memcpy(Digest.data(), llvm::fromHex(HexString).data(), Digest.size());
} else {
  I.setError("Bad hex file digest");
}
return D;
```



Comment at: clang-tools-extra/clangd/index/YAMLSerialization.cpp:380
+
+template <> struct MappingTraits {
+  static void mapping(IO &IO, CompileCommand &Cmd) {

Unfortunately we don't own the CompileCommand type, so we shouldn't specialize 
traits for it (risk ODR violation if someone else does the same).
Wrap or inherit it in a trivial struct `struct CompileCommandYAML : 
tooling::CompileCommand {}` to make this safe.



Comment at: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp:288
+IndexOut.Format = Format;
+llvm::outs() << IndexOut;
+return 0;

Writing it to stdout doesn't seem unreasonable but maybe not the right default.
What about requiring a filename arg, and creating a `raw_fd_ostream` - then you 
can pass `-` to get stdout.



Comment at: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp:322
+  // Make Export command option(s) available on command line.
+  // That allows for convenient (piping/redirecting) a dump non-interactively
+  // without passing through REPL.

I wonder if we should generalize this instead to running an arbitrary command 
non-interactively: `dexp -c "dump"`

No need to do that in this patch but maybe leave a TODO


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

https://reviews.llvm.org/D77385



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


[PATCH] D77637: [part 2] sancov/inline-bool-flag clang flags.

2020-04-07 Thread Pratyai Mazumder via Phabricator via cfe-commits
pratyai created this revision.
pratyai added reviewers: kcc, vitalybuka.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
pratyai updated this revision to Diff 255638.

(must follow part 1: https://reviews.llvm.org/D77244)

In the previous part, we implemented the instrumentation of 
sancov/inline-bool-flag.

Here, we're wiring the instrumentation to the compiler (mostly following the 
pattern of `inline-8bit-counters`).

One test in compiler-rt/... will be added in a subsequent diff (as discussed in 
part-1[D77244 ] comments).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77637

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  clang/test/Driver/fsanitize-coverage.c

Index: clang/test/Driver/fsanitize-coverage.c
===
--- clang/test/Driver/fsanitize-coverage.c
+++ clang/test/Driver/fsanitize-coverage.c
@@ -105,9 +105,18 @@
 // CHECK_INLINE8BIT-NOT: warning
 // CHECK_INLINE8BIT: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// CHECK_PC_TABLE: -fsanitize-coverage-pc-table
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=bb,inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// CHECK_INLINE_BOOL_FLAG-NOT: warning
+// CHECK_INLINE_BOOL_FLAG: -fsanitize-coverage-inline-bool-flag
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// CHECK_PC_TABLE_FOR_INLINE8BIT: -fsanitize-coverage-pc-table
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// CHECK_PC_TABLE_FOR_INLINEBOOL: -fsanitize-coverage-pc-table
 
 // RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address -fsanitize-coverage=func,trace-pc-guard -c -### -- %s 2>&1 | FileCheck %s -check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -54,6 +54,7 @@
 // FNOSANICOVERALL-NEXT: func
 // FNOSANICOVERALL-NEXT: indirect-calls
 // FNOSANICOVERALL-NEXT: inline-8bit-counters
+// FNOSANICOVERALL-NEXT: inline-bool-flag
 // FNOSANICOVERALL-NEXT: no-prune
 // FNOSANICOVERALL-NEXT: trace-bb
 // FNOSANICOVERALL-NEXT: trace-cmp
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1175,6 +1175,8 @@
   Opts.SanitizeCoverageNoPrune = Args.hasArg(OPT_fsanitize_coverage_no_prune);
   Opts.SanitizeCoverageInline8bitCounters =
   Args.hasArg(OPT_fsanitize_coverage_inline_8bit_counters);
+  Opts.SanitizeCoverageInlineBoolFlag =
+  Args.hasArg(OPT_fsanitize_coverage_inline_bool_flag);
   Opts.SanitizeCoveragePCTable = Args.hasArg(OPT_fsanitize_coverage_pc_table);
   Opts.SanitizeCoverageStackDepth =
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -77,17 +77,18 @@
   CoverageBB = 1 << 1,
   CoverageEdge = 1 << 2,
   CoverageIndirCall = 1 << 3,
-  CoverageTraceBB = 1 << 4,  // Deprecated.
+  CoverageTraceBB = 1 << 4, // Deprecated.
   CoverageTraceCmp = 1 << 5,
   CoverageTraceDiv = 1 << 6,
   CoverageTraceGep = 1 << 7,
-  Coverage8bitCounters = 1 << 8,  // Deprecated.
+  Coverage8bitCounters = 1 << 8, // Deprecated.
   CoverageTracePC = 1 << 9,
   CoverageTracePCGuard = 1 << 10,
   CoverageNoPrune = 1 << 11,
   CoverageInline8bitCounters = 1 << 12,
   CoveragePCTable = 1 << 13,
   CoverageStackDepth = 1 << 14,
+  Covera

[PATCH] D69088: [Lex] #pragma clang transform

2020-04-07 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69088



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


[PATCH] D76342: [OpenMP] Implement '#pragma omp tile'

2020-04-07 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.
Herald added a subscriber: yaxunl.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76342



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


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

2020-04-07 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 255641.
baloghadamsoftware added a comment.

Experimenting...


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

https://reviews.llvm.org/D77229

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/test/Analysis/iterator-modeling.cpp

Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -28,7 +28,7 @@
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
 
-void begin(const std::vector &v) {
+/*void begin(const std::vector &v) {
   auto i = v.begin();
 
   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
@@ -1773,7 +1773,7 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning{{$i1 + 2}} FIXME: Should be $i1 + 1
   // clang_analyzer_express(clang_analyzer_iterator_position(i5)); FIXME: expect warning $i1 + 1
   clang_analyzer_express(clang_analyzer_iterator_position(i4)); // expected-warning{{$FL.end()}}
-}
+  }*/
 
 struct simple_iterator_base {
   simple_iterator_base();
@@ -1812,7 +1812,7 @@
   }
 }
 
-void iter_diff(std::vector &V) {
+/*void iter_diff(std::vector &V) {
   auto i0 = V.begin(), i1 = V.end();
   ptrdiff_t len = i1 - i0; // no-crash
 }
@@ -1880,3 +1880,4 @@
 // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
 }
+*/
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -109,6 +109,96 @@
   return LValue;
 }
 
+Optional ExprEngine::retrieveFromConstructionContext(
+ProgramStateRef State, const LocationContext *LCtx,
+const ConstructionContext *CC) const {
+  if (CC) {
+switch (CC->getKind()) {
+case ConstructionContext::CXX17ElidedCopyVariableKind:
+case ConstructionContext::SimpleVariableKind: {
+  const auto *DSCC = cast(CC);
+  const auto *DS = DSCC->getDeclStmt();
+  return getObjectUnderConstruction(State, DS, LCtx);
+}
+case ConstructionContext::CXX17ElidedCopyConstructorInitializerKind:
+case ConstructionContext::SimpleConstructorInitializerKind: {
+  const auto *ICC = cast(CC);
+  const auto *Init = ICC->getCXXCtorInitializer();
+  return getObjectUnderConstruction(State, Init, LCtx);
+}
+case ConstructionContext::SimpleReturnedValueKind:
+case ConstructionContext::CXX17ElidedCopyReturnedValueKind: {
+  const StackFrameContext *SFC = LCtx->getStackFrame();
+  if (const LocationContext *CallerLCtx = SFC->getParent()) {
+auto RTC = (*SFC->getCallSiteBlock())[SFC->getIndex()]
+   .getAs();
+if (!RTC) {
+  // We were unable to find the correct construction context for the
+  // call in the parent stack frame. This is equivalent to not being
+  // able to find construction context at all.
+  break;
+}
+if (isa(CallerLCtx)) {
+  // Unwrap block invocation contexts. They're mostly part of
+  // the current stack frame.
+  CallerLCtx = CallerLCtx->getParent();
+  assert(!isa(CallerLCtx));
+}
+return retrieveFromConstructionContext(
+  State, CallerLCtx, RTC->getConstructionContext());
+  }
+  break;
+}
+case ConstructionContext::ElidedTemporaryObjectKind: {
+  assert(AMgr.getAnalyzerOptions().ShouldElideConstructors);
+  const auto *TCC = cast(CC);
+  Optional RetVal = retrieveFromConstructionContext(
+  State, LCtx, TCC->getConstructionContextAfterElision());
+  if (RetVal.hasValue())
+return RetVal;
+  
+  LLVM_FALLTHROUGH;
+}
+case ConstructionContext::SimpleTemporaryObjectKind: {
+  const auto *TCC = cast(CC);
+  const CXXBindTemporaryExpr *BTE = TCC->getCXXBindTemporaryExpr();
+  Optional RetVal;
+  if (BTE) {
+RetVal = getObjectUnderConstruction(State, BTE, LCtx);
+if (RetVal.hasValue())
+  return RetVal;
+  }
+  
+  const MaterializeTemporaryExpr *MTE = TCC->getMaterializedTemporaryExpr();
+  if (MTE)
+RetVal = getObjectUnderConstruction(State, MTE, LCtx);
+
+  return RetVal;
+}
+ca

[PATCH] D77581: Add map-type check for target and target data directive

2020-04-07 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa010ef8bd88f: Add map-type check for target and target data 
directive, by Chi Chun Chen (authored by cchen, committed by ABataev).

Changed prior to commit:
  https://reviews.llvm.org/D77581?vs=255497&id=255642#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77581

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/Analysis/cfg-openmp.cpp
  clang/test/OpenMP/target_data_messages.c
  clang/test/OpenMP/target_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_parallel_map_messages.cpp
  clang/test/OpenMP/target_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -580,6 +580,11 @@
 #pragma omp target teams map(*(1+*a+*a)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
   {}
 
+#pragma omp target teams map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams'}}
+  {}
+#pragma omp target teams map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams'}}
+  {}
+
   return tmain(argc)+tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
 #endif
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
@@ -288,6 +288,12 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute parallel for simd map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   for (i = 0; i < argc; ++i) foo();
+#pragma omp target teams distribute parallel for simd map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute parallel for simd'}}
+  for (i = 0; i < argc; ++i)
+foo();
+#pragma omp target teams distribute parallel for simd map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute parallel for simd'}}
+  for (i = 0; i < argc; ++i)
+foo();
 
   return tmain(argc)+tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
@@ -288,6 +288,12 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   for (i = 0; i < argc; ++i) foo();
+#pragma omp target teams distribute parallel for map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute parallel for'}}
+  for (i = 0; i < argc; ++i)
+foo();
+#pragma omp target teams distribute parallel for map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute parallel for'}}
+  for (i = 0; i < argc; ++i)
+foo();
 
   return tmain(argc)+tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
Index: clang/test/OpenMP/target_teams_distribute_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_map_messages.cpp
@@ -288,6 +288,12 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   for (i = 0; i < argc; ++i) foo();
+#pragma omp target teams distribute map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute'}}
+  

[PATCH] D77058: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

2020-04-07 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

LGTM, since it continues current practice. `optnone` will always be the more 
annoying.

In D77058#1964714 , @fhahn wrote:

> IIUC we don't need a patch similar like this one for optnone, as it already 
> gets added to the function attributes (for -O0) and has an option to disable 
> adding it (-Xclang -disable-O0-optnone) on a per-TU basis.


My question was the other way around: Do we need something like `-xclang 
-disable-fno-unroll-loops-metadata`.

I documented for Polly 
 
how to get the IR for further processing. There is `clang -Xclang 
-disable-O0-optnone` and another is `clang -O1 -Xclang -disable-llvm-passes`. 
Both avoid the optnone attribute, but will yield different results with 
`-fno-unroll-loops`. Which is the 'correct' way?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77058



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


[PATCH] D77309: [clangd] Get rid of ASTWorker::getCurrentFileInputs

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ac7b805b7c4: [clangd] Get rid of 
ASTWorker::getCurrentFileInputs (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77309

Files:
  clang-tools-extra/clangd/TUScheduler.cpp

Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -423,10 +423,6 @@
   Deadline scheduleLocked();
   /// Should the first task in the queue be skipped instead of run?
   bool shouldSkipHeadLocked() const;
-  /// This is private because `FileInputs.FS` is not thread-safe and thus not
-  /// safe to share. Callers should make sure not to expose `FS` via a public
-  /// interface.
-  std::shared_ptr getCurrentFileInputs() const;
 
   struct Request {
 llvm::unique_function Action;
@@ -458,9 +454,9 @@
   /// Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
   /// File inputs, currently being used by the worker.
-  /// Inputs are written and read by the worker thread, compile command can also
-  /// be consumed by clients of ASTWorker.
-  std::shared_ptr FileInputs; /* GUARDED_BY(Mutex) */
+  /// Writes and reads from unknown threads are locked. Reads from the worker
+  /// thread are not locked, as it's the only writer.
+  ParseInputs FileInputs; /* GUARDED_BY(Mutex) */
   /// Times of recent AST rebuilds, used for UpdateDebounce computation.
   llvm::SmallVector
   RebuildTimes; /* GUARDED_BY(Mutex) */
@@ -556,12 +552,10 @@
// FIXME: Run PreamblePeer asynchronously once ast patching
// is available.
/*RunSync=*/true, Status, *this) {
-  auto Inputs = std::make_shared();
   // Set a fallback command because compile command can be accessed before
   // `Inputs` is initialized. Other fields are only used after initialization
   // from client inputs.
-  Inputs->CompileCommand = CDB.getFallbackCommand(FileName);
-  FileInputs = std::move(Inputs);
+  FileInputs.CompileCommand = CDB.getFallbackCommand(FileName);
 }
 
 ASTWorker::~ASTWorker() {
@@ -590,7 +584,7 @@
   Inputs.CompileCommand = CDB.getFallbackCommand(FileName);
 
 bool InputsAreTheSame =
-std::tie(FileInputs->CompileCommand, FileInputs->Contents) ==
+std::tie(FileInputs.CompileCommand, FileInputs.Contents) ==
 std::tie(Inputs.CompileCommand, Inputs.Contents);
 // Cached AST is invalidated.
 if (!InputsAreTheSame) {
@@ -601,7 +595,7 @@
 // Update current inputs so that subsequent reads can see them.
 {
   std::lock_guard Lock(Mutex);
-  FileInputs = std::make_shared(Inputs);
+  FileInputs = Inputs;
 }
 
 log("ASTWorker building file {0} version {1} with command {2}\n[{3}]\n{4}",
@@ -655,21 +649,20 @@
 if (isCancelled())
   return Action(llvm::make_error());
 llvm::Optional> AST = IdleASTs.take(this);
-auto CurrentInputs = getCurrentFileInputs();
 if (!AST) {
   StoreDiags CompilerInvocationDiagConsumer;
-  std::unique_ptr Invocation = buildCompilerInvocation(
-  *CurrentInputs, CompilerInvocationDiagConsumer);
+  std::unique_ptr Invocation =
+  buildCompilerInvocation(FileInputs, CompilerInvocationDiagConsumer);
   // Try rebuilding the AST.
   vlog("ASTWorker rebuilding evicted AST to run {0}: {1} version {2}", Name,
-   FileName, CurrentInputs->Version);
+   FileName, FileInputs.Version);
   // FIXME: We might need to build a patched ast once preamble thread starts
   // running async. Currently getPossiblyStalePreamble below will always
   // return a compatible preamble as ASTWorker::update blocks.
   llvm::Optional NewAST =
   Invocation ? buildAST(FileName, std::move(Invocation),
 CompilerInvocationDiagConsumer.take(),
-*CurrentInputs, getPossiblyStalePreamble())
+FileInputs, getPossiblyStalePreamble())
  : None;
   AST = NewAST ? std::make_unique(std::move(*NewAST)) : nullptr;
 }
@@ -681,8 +674,8 @@
   return Action(llvm::make_error(
   "invalid AST", llvm::errc::invalid_argument));
 vlog("ASTWorker running {0} on version {2} of {1}", Name, FileName,
- CurrentInputs->Version);
-Action(InputsAndAST{*CurrentInputs, **AST});
+ FileInputs.Version);
+Action(InputsAndAST{FileInputs, **AST});
   };
   startTask(Name, std::move(Task), /*UpdateType=*/None, Invalidation);
 }
@@ -782,7 +775,7 @@
   }
   // Used to check whether we can update AST cache.
   bool InputsAreLatest =
-  std::tie(FileInputs->CompileCommand, FileInputs->Contents) ==
+  std::tie(FileInputs.CompileCommand, FileInputs.Conten

[PATCH] D75364: [clang-format] Handle macros in function params and return value

2020-04-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Did you try putting 'ElfW and 'M' in the list of TypenameMacros?

  ---
  Language: Cpp
  BasedOnStyle: LLVM
  TypenameMacros: ['ElfW']
  PointerAlignment: Left



  const ElfW(Addr)* foo(ElfW(Addr)* addr);
  const M(Addr) * foo(M(Addr) * addr);



  $ clang-format macros.cpp
  const ElfW(Addr)* foo(ElfW(Addr)* addr);
  const M(Addr) * foo(M(Addr) * addr);

Simply extend the list to include the macros you need

  TypenameMacros: ['ElfW','M']



  $ clang-format macros.cpp
  const ElfW(Addr)* foo(ElfW(Addr)* addr);
  const M(Addr)* foo(M(Addr)* addr);

F11683170: image.png 


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

https://reviews.llvm.org/D75364



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


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

2020-04-07 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

Any idea for `LazyCompoundVal` parameters of functions not inlined?




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:231-235
+if (dyn_cast_or_null(LCtx->getParentMap().getParent(E))) 
{
+  MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
+  return std::make_pair(
+  State, loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx)));
+}

Did you mean this piece of code? It returns `&temp_object{struct 
simple_iterator_base, S44016}`. Is this correct? If so, I will factor out this 
code and put it into a common function to be used by both this function and the 
original one.


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] 448b777 - Stop passing site cfg files via --param to llvm-lit.

2020-04-07 Thread Nico Weber via cfe-commits
Author: Nico Weber
Date: 2020-04-07T08:20:40-04:00
New Revision: 448b777b864a312e3b2ceae1e0cd59752a1fe90e

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

LOG: Stop passing site cfg files via --param to llvm-lit.

This has been unnecessary since https://reviews.llvm.org/D37756.

https://reviews.llvm.org/D37838 removed it for llvm.

This removes it from clang, lld, clang-tools-extra (and the GN build).

No intended behavior change.

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

Added: 


Modified: 
clang-tools-extra/clangd/test/CMakeLists.txt
clang/test/CMakeLists.txt
lld/test/CMakeLists.txt
llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
llvm/utils/gn/secondary/clang/test/BUILD.gn
llvm/utils/gn/secondary/lld/test/BUILD.gn
llvm/utils/gn/secondary/llvm/test/BUILD.gn

Removed: 




diff  --git a/clang-tools-extra/clangd/test/CMakeLists.txt 
b/clang-tools-extra/clangd/test/CMakeLists.txt
index 1054fd593bfa..c5cc7e3ec097 100644
--- a/clang-tools-extra/clangd/test/CMakeLists.txt
+++ b/clang-tools-extra/clangd/test/CMakeLists.txt
@@ -35,5 +35,8 @@ configure_lit_site_cfg(
   )
 
 add_lit_testsuite(check-clangd "Running the Clangd regression tests"
+  # clangd doesn't put unittest configs in test/unit like every other project.
+  # Because of that, this needs to pass two folders here, while every other
+  # project only needs to pass CMAKE_CURRENT_BINARY_DIR.
   ${CMAKE_CURRENT_BINARY_DIR}/../unittests;${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS ${CLANGD_TEST_DEPS})

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index ca326fea8066..38bbc5be90d5 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -106,16 +106,9 @@ if (CLANG_BUILD_EXAMPLES)
 endif ()
 
 set(CLANG_TEST_PARAMS
-  clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
   USE_Z3_SOLVER=0
   )
 
-set(ANALYZER_TEST_PARAMS
-  USE_Z3_SOLVER=0)
-
-set(ANALYZER_TEST_PARAMS_Z3
-  USE_Z3_SOLVER=1)
-
 if( NOT CLANG_BUILT_STANDALONE )
   list(APPEND CLANG_TEST_DEPS
 llvm-config

diff  --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt
index 8be42c46dd8a..80721384c287 100644
--- a/lld/test/CMakeLists.txt
+++ b/lld/test/CMakeLists.txt
@@ -44,14 +44,8 @@ if (LLVM_INCLUDE_TESTS)
   list(APPEND LLD_TEST_DEPS LLDUnitTests)
 endif()
 
-set(LLD_TEST_PARAMS
-  lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-  )
-
 add_lit_testsuite(check-lld "Running lld test suite"
   ${CMAKE_CURRENT_BINARY_DIR}
-  PARAMS lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-   lld_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
   DEPENDS ${LLD_TEST_DEPS}
   )
 
@@ -59,8 +53,6 @@ add_custom_target(lld-test-depends DEPENDS ${LLD_TEST_DEPS})
 set_target_properties(lld-test-depends PROPERTIES FOLDER "lld tests")
 
 add_lit_testsuites(LLD ${CMAKE_CURRENT_SOURCE_DIR}
-  PARAMS lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-   lld_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
   DEPENDS ${LLD_TEST_DEPS}
   )
 

diff  --git a/llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn 
b/llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
index 22a76a826f65..4dc4c278ebcd 100644
--- a/llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
@@ -21,8 +21,9 @@ write_lit_config("lit_site_cfg") {
   output = clangd_lit_site_cfg_file
 
   extra_values = [
-"CMAKE_CURRENT_BINARY_DIR=" + rebase_path(
-get_label_info("//clang-tools-extra/clangd/test", 
"target_out_dir")),
+"CMAKE_CURRENT_BINARY_DIR=" +
+rebase_path(get_label_info("//clang-tools-extra/clangd/test",
+   "target_out_dir")),
 "CMAKE_CURRENT_SOURCE_DIR=" +
 rebase_path("//clang-tools-extra/clangd/test"),
 
@@ -91,6 +92,10 @@ action("check-clangd") {
   }
   args = [
 "-sv",
+
+# clangd doesn't put unittest configs in test/unit like every other 
project.
+# Because of that, this needs to pass two folders here, while every other
+# project only needs to pass CMAKE_CURRENT_BINARY_DIR.
 rebase_path(get_path_info(clangd_lit_site_cfg_file, "dir"), root_out_dir),
 rebase_path(get_path_info(clangd_lit_unit_site_cfg_file, "dir"),
 root_out_dir),

diff  --git a/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn 
b/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
index 6646ef112750..97715cf8d9c9 100644
--- a/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -90,12 +90,6 @@ action("check-clang-tools") {
   }
   args = [
 

[PATCH] D75682: [Analyzer][StreamChecker] Introduction of stream error handling.

2020-04-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.

Whoo!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75682



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


[PATCH] D77585: Stop passing site cfg files via --param to llvm-lit.

2020-04-07 Thread Nico Weber via Phabricator via cfe-commits
thakis marked an inline comment as done.
thakis added a comment.

Thanks!




Comment at: clang/test/CMakeLists.txt:113
 
-set(ANALYZER_TEST_PARAMS
-  USE_Z3_SOLVER=0)

hans wrote:
> This and ANALYZER_TEST_PARAMS_Z3 are just dropped because they're unused, 
> right?
Yes. It looks like the uses of them were dropped accidentally in D62445. If we 
restore the uses, we can restore this too.


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

https://reviews.llvm.org/D77585



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


[PATCH] D75364: [clang-format] Handle macros in function params and return value

2020-04-07 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz added a comment.

Wow, I have missed that configuration option.
I will try it, I assume it should work.

Looks like this change should be abandoned.


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

https://reviews.llvm.org/D75364



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


[PATCH] D77641: [analyzer] StdLibraryFunctionsChecker: Associate summaries to FunctionDecls

2020-04-07 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: NoQ, Szelethus, balazske.
Herald added subscribers: cfe-commits, ASDenysPetrov, uenoku, steakhal, 
Charusso, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, 
szepet, baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: uenoku.
Herald added a project: clang.
martong marked an inline comment as done.
martong added inline comments.
martong marked an inline comment as not done.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:570
+llvm::Optional
+lookupGlobalCFunction(StringRef Name, const ASTContext &ACtx) {
+  IdentifierInfo &II = ACtx.Idents.get(Name);

Ups, this function is unused I'll remove.


Currently we map function summaries to names (i.e. strings). We can
associate more summaries with different signatures to one name, this way
we support overloading. During a call event we check whether the
signature of the summary matches the signature of the callee and we
apply the summary only in that case.

In this patch we change this mapping to associate a summary to a
FunctionDecl. We do lookup operations when the summary map is
initialized. We lookup the given name and we match the signature of the
given summary against the lookup results. If the summary matches the
FunctionDecl (got from the lookup result) then we add that to the
summary map. During a call event we compare FunctionDecl pointers.
Advantages of this new refactor:

- Cleaner mapping and structure for the checker.
- Possibly way more efficient handling of call events.
- A summary is added only if that is relevant for the given TU.
- We can get the concrete FunctionDecl by the time when we create the summary, 
this opens up possibilities of further sanity checks regarding the summary 
cases and argument constraints.
- Opens up to future work when we'd like to store summaries from IR to a 
FunctionDecl (or from the Attributor results of the given FunctionDecl).

Note, we cannot support old C functions without prototypes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77641

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
@@ -266,21 +266,15 @@
   return T;
 }
 
-/// Try our best to figure out if the call expression is the call of
+/// Try our best to figure out if the summary's signature matches
 /// *the* library function to which this specification applies.
-bool matchesCall(const FunctionDecl *FD) const;
+bool matchesSignature(const FunctionDecl *FD) const;
   };
 
-  // The same function (as in, function identifier) may have different
-  // summaries assigned to it, with different argument and return value types.
-  // We call these "variants" of the function. This can be useful for handling
-  // C++ function overloads, and also it can be used when the same function
-  // may have different definitions on different platforms.
-  typedef std::vector Summaries;
-
   // The map of all functions supported by the checker. It is initialized
   // lazily, and it doesn't change after initialization.
-  mutable llvm::StringMap FunctionSummaryMap;
+  using FunctionSummaryMapType = llvm::DenseMap;
+  mutable FunctionSummaryMapType FunctionSummaryMap;
 
   mutable std::unique_ptr BT_InvalidArg;
 
@@ -289,14 +283,6 @@
   static QualType getArgType(const Summary &Summary, ArgNo ArgN) {
 return Summary.getArgType(ArgN);
   }
-  static QualType getArgType(const CallEvent &Call, ArgNo ArgN) {
-return ArgN == Ret ? Call.getResultType().getCanonicalType()
-   : Call.getArgExpr(ArgN)->getType().getCanonicalType();
-  }
-  static QualType getArgType(const CallExpr *CE, ArgNo ArgN) {
-return ArgN == Ret ? CE->getType().getCanonicalType()
-   : CE->getArg(ArgN)->getType().getCanonicalType();
-  }
   static SVal getArgSVal(const CallEvent &Call, ArgNo ArgN) {
 return ArgN == Ret ? Call.getReturnValue() : Call.getArgSVal(ArgN);
   }
@@ -440,7 +426,7 @@
   BinaryOperator::Opcode Op = getOpcode();
   ArgNo OtherArg = getOtherArgNo();
   SVal OtherV = getArgSVal(Call, OtherArg);
-  QualType OtherT = getArgType(Call, OtherArg);
+  QualType OtherT = getArgType(Summary, OtherArg);
   // Note: we avoid integral promotion for comparison.
   OtherV = SVB.evalCast(OtherV, T, OtherT);
   if (auto CompV = SVB.evalBinOp(State, Op, V, OtherV, CondT)
@@ -530,7 +516,7 @@
   llvm_unreachable("Unknown invalidation kind!");
 }
 
-bool StdLibraryFunctionsChecker::Summary::matchesCall(
+bool StdLibraryFunctionsChecker::Summary::matchesSignature(
 const Function

[PATCH] D77641: [analyzer] StdLibraryFunctionsChecker: Associate summaries to FunctionDecls

2020-04-07 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:570
+llvm::Optional
+lookupGlobalCFunction(StringRef Name, const ASTContext &ACtx) {
+  IdentifierInfo &II = ACtx.Idents.get(Name);

Ups, this function is unused I'll remove.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77641



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


[PATCH] D77585: Stop passing site cfg files via --param to llvm-lit.

2020-04-07 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG448b777b864a: Stop passing site cfg files via --param to 
llvm-lit. (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77585

Files:
  clang-tools-extra/clangd/test/CMakeLists.txt
  clang/test/CMakeLists.txt
  lld/test/CMakeLists.txt
  llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  llvm/utils/gn/secondary/lld/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/test/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -289,11 +289,6 @@
   }
   args = [
 "-sv",
-"--param",
-"llvm_site_config=" + rebase_path(llvm_lit_site_cfg_file, root_out_dir),
-"--param",
-"llvm_unit_site_config=" +
-rebase_path(llvm_lit_unit_site_cfg_file, root_out_dir),
 rebase_path(".", root_out_dir),
   ]
   outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
Index: llvm/utils/gn/secondary/lld/test/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/test/BUILD.gn
+++ llvm/utils/gn/secondary/lld/test/BUILD.gn
@@ -110,11 +110,6 @@
   }
   args = [
 "-sv",
-"--param",
-"lld_site_config=" + rebase_path(lld_lit_site_cfg_file, root_out_dir),
-"--param",
-"lld_unit_site_config=" +
-rebase_path(lld_lit_unit_site_cfg_file, root_out_dir),
 rebase_path(".", root_out_dir),
   ]
   outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -189,11 +189,6 @@
   }
   args = [
 "-sv",
-"--param",
-"clang_site_config=" + rebase_path(clang_lit_site_cfg_file, root_out_dir),
-"--param",
-"clang_unit_site_config=" +
-rebase_path(clang_lit_unit_site_cfg_file, root_out_dir),
 rebase_path(".", root_out_dir),
   ]
   outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -90,12 +90,6 @@
   }
   args = [
 "-sv",
-"--param",
-"clang_site_config=" +
-rebase_path(clang_tools_extra_lit_site_cfg_file, root_out_dir),
-"--param",
-"clang_unit_site_config=" +
-rebase_path(clang_tools_extra_lit_unit_site_cfg_file, root_out_dir),
 rebase_path(".", root_out_dir),
   ]
   outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn
@@ -21,8 +21,9 @@
   output = clangd_lit_site_cfg_file
 
   extra_values = [
-"CMAKE_CURRENT_BINARY_DIR=" + rebase_path(
-get_label_info("//clang-tools-extra/clangd/test", "target_out_dir")),
+"CMAKE_CURRENT_BINARY_DIR=" +
+rebase_path(get_label_info("//clang-tools-extra/clangd/test",
+   "target_out_dir")),
 "CMAKE_CURRENT_SOURCE_DIR=" +
 rebase_path("//clang-tools-extra/clangd/test"),
 
@@ -91,6 +92,10 @@
   }
   args = [
 "-sv",
+
+# clangd doesn't put unittest configs in test/unit like every other project.
+# Because of that, this needs to pass two folders here, while every other
+# project only needs to pass CMAKE_CURRENT_BINARY_DIR.
 rebase_path(get_path_info(clangd_lit_site_cfg_file, "dir"), root_out_dir),
 rebase_path(get_path_info(clangd_lit_unit_site_cfg_file, "dir"),
 root_out_dir),
Index: lld/test/CMakeLists.txt
===
--- lld/test/CMakeLists.txt
+++ lld/test/CMakeLists.txt
@@ -44,14 +44,8 @@
   list(APPEND LLD_TEST_DEPS LLDUnitTests)
 endif()
 
-set(LLD_TEST_PARAMS
-  lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-  )
-
 add_lit_testsuite(check-lld "Running lld test suite"
   ${CMAKE_CURRENT_BINARY_DIR}
-  PARAMS lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-   lld_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
   DEPENDS ${LLD_TEST_DEPS}
   )
 
@@ -59,8 +53,6 @@
 set_target_properties(lld-test-depends PROPERTI

[clang] 041080c - [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-04-07 Thread Haojian Wu via cfe-commits
Author: Haojian Wu
Date: 2020-04-07T14:29:38+02:00
New Revision: 041080c247351da15b6bb21a7196c8dc9bc6babc

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

LOG: [AST] Fix a crash on invalid constexpr Ctorinitializer when building 
RecoveryExpr.

Summary:
crash stack:

```

lang:  workspace/llvm-project/clang/lib/AST/ExprConstant.cpp:13704: bool 
EvaluateInPlace(clang::APValue &, (anonymous namespace)::EvalInfo &, const 
(anonymous namespace)::LValue &, const clang::Expr *, bool): Assertion 
`!E->isValueDependent()' failed.
 #8  EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, 
(anonymous namespace)::LValue const&, clang::Expr const*, bool)  
workspace/llvm-project/clang/lib/AST/ExprConstant.cpp:0:0
 #9  HandleConstructorCall(clang::Expr const*, (anonymous namespace)::LValue 
const&, clang::APValue*, clang::CXXConstructorDecl const*, (anonymous 
namespace)::EvalInfo&, clang::APValue&)  
workspace/llvm-project/clang/lib/AST/ExprConstant.cpp:5779:57
#10  HandleConstructorCall(clang::Expr const*, (anonymous namespace)::LValue 
const&, llvm::ArrayRef, clang::CXXConstructorDecl const*, 
(anonymous namespace)::EvalInfo&, clang::APValue&)  
workspace/llvm-project/clang/lib/AST/ExprConstant.cpp:5819:10
#11  clang::Expr::isPotentialConstantExpr(clang::FunctionDecl const*, 
llvm::SmallVectorImpl >&) 
workspace/llvm-project/clang/lib/AST/ExprConstant.cpp:14746:5
#12  CheckConstexprFunctionBody(clang::Sema&, clang::FunctionDecl const*, 
clang::Stmt*, clang::Sema::CheckConstexprKind)  
workspace/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:2306:7
#13  clang::Sema::CheckConstexprFunctionDefinition(clang::FunctionDecl const*, 
clang::Sema::CheckConstexprKind)  
workspace/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:1766:0
#14  clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool)  
workspace/llvm-project/clang/lib/Sema/SemaDecl.cpp:14357:9
#15  clang::Parser::ParseFunctionStatementBody(clang::Decl*, 
clang::Parser::ParseScope&)  
workspace/llvm-project/clang/lib/Parse/ParseStmt.cpp:2213:18
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: rsmith, cfe-commits

Tags: #clang

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

Added: 
clang/test/SemaCXX/invalid-constructor-init.cpp

Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 9ebde22f7a58..628f22ae2053 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4976,6 +4976,13 @@ static bool CheckConstexprFunction(EvalInfo &Info, 
SourceLocation CallLoc,
 return false;
   }
 
+  if (const auto *CtorDecl = dyn_cast_or_null(Definition)) 
{
+for (const auto *InitExpr : CtorDecl->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
+
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() && Body)
 return true;
@@ -14709,6 +14716,15 @@ bool Expr::isPotentialConstantExpr(const FunctionDecl 
*FD,
   if (FD->isDependentContext())
 return true;
 
+  // Bail out if a constexpr constructor has an initializer that contains an
+  // error. We deliberately don't produce a diagnostic, as we have produced a
+  // relevant diagnostic when parsing the error initializer.
+  if (const auto *Ctor = dyn_cast(FD)) {
+for (const auto *InitExpr : Ctor->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
   Expr::EvalStatus Status;
   Status.Diag = &Diags;
 

diff  --git a/clang/test/SemaCXX/invalid-constructor-init.cpp 
b/clang/test/SemaCXX/invalid-constructor-init.cpp
new file mode 100644
index ..8fda9cc525ba
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+struct X {
+  int Y;
+  constexpr X() // expected-error {{constexpr constructor never produces}}
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+};
+// no crash on evaluating the constexpr ctor.
+constexpr int Z = X().Y; // expected-error {{constexpr variable 'Z' must be 
initialized by a constant expression}}
+
+struct X2 {
+  int Y = foo();// expected-error {{use of undeclared identifier 'foo'}} \
+ // expected-note {{subexpression not valid in a constant 
expression}}
+  constexpr X2() {} // expected-error {{constexpr constructor never produces a 
constant expression}}
+};
+
+struct CycleDelegate {
+  int Y;
+  CycleDelegate(int)
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+  // no bogus "delegation cycle" diagnostic
+  CycleDelegate(float) : CycleDelegate(1) {}
+};



_

[PATCH] D77527: [AST] Adjust existing tests for recovery-exprs

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'm a bit leery about this because we lose test coverage of the "live" 
configuration.
I know it's a pain, but maybe it's possible to keep this as a local 
patch/branch? :-(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77527



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


[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-04-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, mgrang, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

Depends on D77392 .

Enables building ASTs with stale preambles by handling additional preamble
includes. Sets the correct location information for those imaginary includes so
that features like gotodef/documentlink keeps functioning propoerly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77644

Files:
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -17,7 +17,9 @@
 #include "Annotations.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
+#include "Headers.h"
 #include "ParsedAST.h"
+#include "Preamble.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -28,6 +30,7 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Token.h"
 #include "clang/Tooling/Syntax/Tokens.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock-matchers.h"
@@ -82,6 +85,13 @@
   return arg.beginOffset() == R.Begin && arg.endOffset() == R.End;
 }
 
+MATCHER(EqInc, "") {
+  Inclusion Actual = testing::get<0>(arg);
+  Inclusion Expected = testing::get<1>(arg);
+  return std::tie(Actual.HashOffset, Actual.R, Actual.Written) ==
+ std::tie(Expected.HashOffset, Expected.R, Expected.Written);
+}
+
 TEST(ParsedASTTest, TopLevelDecls) {
   TestTU TU;
   TU.HeaderCode = R"(
@@ -420,6 +430,73 @@
   }
 }
 
+TEST(ParsedASTTest, AdditionalIncludes) {
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["sub/baz.h"] = "void baz();";
+  TU.AdditionalFiles["sub/aux.h"] = "void aux();";
+  TU.ExtraArgs = {"-I" + testPath("sub")};
+  TU.Code = R"cpp(
+#include "baz.h"
+#include "foo.h"
+#include "sub/aux.h"
+void bar() {
+  foo();
+  baz();
+  aux();
+})cpp";
+  auto ExpectedAST = TU.build();
+
+  // Build preamble with no includes.
+  TU.Code = R"cpp(
+void bar() {
+  foo();
+  baz();
+  aux();
+})cpp";
+  StoreDiags Diags;
+  auto Inputs = TU.inputs();
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  auto Preamble = buildPreamble("foo.cpp", *CI, Inputs, true, nullptr);
+  ASSERT_TRUE(Preamble);
+  EXPECT_THAT(Preamble->Includes.MainFileIncludes, testing::IsEmpty());
+
+  // Now build an AST using additional includes and check that locations are
+  // correctly parsed.
+  TU.Code = R"cpp(
+#include "baz.h"
+#include "foo.h"
+#include "sub/aux.h"
+void bar() {
+  foo();
+  baz();
+  aux();
+})cpp";
+  Inputs = TU.inputs();
+  Inputs.Opts.AdditionalIncludes =
+  getPreambleIncludes(TU.Code, ExpectedAST.getLangOpts());
+  auto PatchedAST = buildAST("foo.cpp", std::move(CI), {}, Inputs, Preamble);
+  ASSERT_TRUE(PatchedAST);
+
+  // Ensure source location information is correct.
+  EXPECT_THAT(PatchedAST->getIncludeStructure().MainFileIncludes,
+  testing::Pointwise(
+  EqInc(), ExpectedAST.getIncludeStructure().MainFileIncludes));
+  auto StringMapToVector = [](const llvm::StringMap SM) {
+std::vector> Res;
+for (const auto &E : SM)
+  Res.push_back({E.first().str(), E.second});
+llvm::sort(Res);
+return Res;
+  };
+  // Ensure file proximity signals are correct.
+  EXPECT_EQ(StringMapToVector(PatchedAST->getIncludeStructure().includeDepth(
+testPath("foo.cpp"))),
+StringMapToVector(ExpectedAST.getIncludeStructure().includeDepth(
+testPath("foo.cpp";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -262,6 +262,15 @@
   std::string Filename =
   std::string(Buffer->getBufferIdentifier()); // Absolute.
 
+  // Process additional includes as implicit includes to ensure AST is built
+  // with necessary symbol information.
+  for (const auto &Inc : Opts.AdditionalIncludes) {
+// Inc.Written contains quotes or angles, preprocessor requires them to be
+// stripped.
+CI->getPreprocessorOpts().Includes.emplace_back(
+llvm::StringRef(Inc.Written).drop_back().drop_front());
+  }
+
   auto Clang = prepareCompilerInstance(std::move(CI), PreamblePCH,
std::move(Buffer), VFS, ASTDiags);
   if (!Clang)
@@ -431,6 +440,31 @@
 std::vector D = ASTDiags

[PATCH] D77209: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 255654.
hlopko added a comment.

Assert the Spelled subrange more effectively


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77209

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp
  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
@@ -1215,6 +1215,9 @@
 |   `-}
 `-}
)txt");
+}
+
+TEST_F(SyntaxTreeTest, ModifiableNodes) {
   // All nodes can be mutated.
   expectTreeDumpEqual(
   R"cpp(
Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -57,6 +57,7 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::Not;
 using ::testing::Pointee;
@@ -185,10 +186,14 @@
   template 
   llvm::ArrayRef findSubrange(llvm::ArrayRef Subrange,
  llvm::ArrayRef Range, Eq F) {
-for (auto Begin = Range.begin(); Begin < Range.end(); ++Begin) {
+assert(Subrange.size() >= 1);
+if (Range.size() < Subrange.size())
+  return llvm::makeArrayRef(Range.end(), Range.end());
+for (auto Begin = Range.begin(), Last = Range.end() - Subrange.size();
+ Begin <= Last; ++Begin) {
   auto It = Begin;
-  for (auto ItSub = Subrange.begin();
-   ItSub != Subrange.end() && It != Range.end(); ++ItSub, ++It) {
+  for (auto ItSub = Subrange.begin(); ItSub != Subrange.end();
+   ++ItSub, ++It) {
 if (!F(*ItSub, *It))
   goto continue_outer;
   }
@@ -889,4 +894,111 @@
   ASSERT_EQ(Code.points().size(), 8u);
 }
 
+TEST_F(TokenBufferTest, ExpandedBySpelled) {
+  recordTokens(R"cpp(
+a1 a2 a3 b1 b2
+  )cpp");
+  // Sanity check: expanded and spelled tokens are stored separately.
+  EXPECT_THAT(findExpanded("a1 a2"), Not(SameRange(findSpelled("a1 a2";
+  // Searching for subranges of expanded tokens should give the corresponding
+  // spelled ones.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3 b1 b2")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("b1 b2")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Test search on simple macro expansions.
+  recordTokens(R"cpp(
+#define A a1 a2 a3
+#define B b1 b2
+
+A split B
+  )cpp");
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split B")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split").drop_back()),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("split B").drop_front()),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Ranges not fully covering macro expansions should fail.
+  recordTokens(R"cpp(
+#define ID(x) x
+
+ID(a)
+  )cpp");
+  // Spelled don't cover entire mapping (missing ID token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("( a )")), IsEmpty());
+  // Spelled don't cover entire mapping (missing ) token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a")), IsEmpty());
+
+  // Recursive macro invocations.
+  recordTokens(R"cpp(
+#define ID(x) x
+#define B b1 b2
+
+ID(ID(ID(a1) a2 a3)) split ID(B)
+  )cpp");
+
+  EXPECT_THAT(
+  Buffer.expandedForSpelled(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( B )")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(
+  findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) ) split ID ( B )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  // FIXME: these should succeed, but we do not support macro arguments yet.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1")), IsEmpty());
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a1 ) a2")),
+  IsEmpty());
+
+  // Empty macro expansions.
+  recordTokens(R"cpp(
+#define EMPTY
+#define ID(X) X
+
+EMPTY EMPTY ID(1 2 3) EMPTY EMPTY split1
+EMPTY EMPTY ID(4 5 6) split2
+ID(7 8 9) EMPTY EMPTY
+  )cpp");
+  // Covered by emp

[PATCH] D77507: [clangd] Fix HitMapping assertion in Tokens.cpp

2020-04-07 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

ayup, no problem and thanks for the fix. I'll abandon this change. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77507



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


[PATCH] D77519: Fix __is_pointer builtin type trait to work with Objective-C pointer types.

2020-04-07 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: clang/test/SemaObjCXX/type-traits-is-pointer.mm:1
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify %s
+// expected-no-diagnostics

ldionne wrote:
> Why do you run this through `-verify`? Can't you just drop that and the `// 
> expected-no-diagnostics` bit too?
Actually, never mind this. Someone pointed to me offline that using 
`clang-verify` has the benefit that no other diagnostics are going to be 
emitted, which is true. This is fine by me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77519



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


[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-04-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG041080c24735: [AST] Fix a crash on invalid constexpr 
Ctorinitializer when building… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/invalid-constructor-init.cpp


Index: clang/test/SemaCXX/invalid-constructor-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+struct X {
+  int Y;
+  constexpr X() // expected-error {{constexpr constructor never produces}}
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+};
+// no crash on evaluating the constexpr ctor.
+constexpr int Z = X().Y; // expected-error {{constexpr variable 'Z' must be 
initialized by a constant expression}}
+
+struct X2 {
+  int Y = foo();// expected-error {{use of undeclared identifier 'foo'}} \
+ // expected-note {{subexpression not valid in a constant 
expression}}
+  constexpr X2() {} // expected-error {{constexpr constructor never produces a 
constant expression}}
+};
+
+struct CycleDelegate {
+  int Y;
+  CycleDelegate(int)
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+  // no bogus "delegation cycle" diagnostic
+  CycleDelegate(float) : CycleDelegate(1) {}
+};
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4976,6 +4976,13 @@
 return false;
   }
 
+  if (const auto *CtorDecl = dyn_cast_or_null(Definition)) 
{
+for (const auto *InitExpr : CtorDecl->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
+
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() && Body)
 return true;
@@ -14709,6 +14716,15 @@
   if (FD->isDependentContext())
 return true;
 
+  // Bail out if a constexpr constructor has an initializer that contains an
+  // error. We deliberately don't produce a diagnostic, as we have produced a
+  // relevant diagnostic when parsing the error initializer.
+  if (const auto *Ctor = dyn_cast(FD)) {
+for (const auto *InitExpr : Ctor->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
   Expr::EvalStatus Status;
   Status.Diag = &Diags;
 


Index: clang/test/SemaCXX/invalid-constructor-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+struct X {
+  int Y;
+  constexpr X() // expected-error {{constexpr constructor never produces}}
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+};
+// no crash on evaluating the constexpr ctor.
+constexpr int Z = X().Y; // expected-error {{constexpr variable 'Z' must be initialized by a constant expression}}
+
+struct X2 {
+  int Y = foo();// expected-error {{use of undeclared identifier 'foo'}} \
+ // expected-note {{subexpression not valid in a constant expression}}
+  constexpr X2() {} // expected-error {{constexpr constructor never produces a constant expression}}
+};
+
+struct CycleDelegate {
+  int Y;
+  CycleDelegate(int)
+  : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+  // no bogus "delegation cycle" diagnostic
+  CycleDelegate(float) : CycleDelegate(1) {}
+};
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -4976,6 +4976,13 @@
 return false;
   }
 
+  if (const auto *CtorDecl = dyn_cast_or_null(Definition)) {
+for (const auto *InitExpr : CtorDecl->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
+
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() && Body)
 return true;
@@ -14709,6 +14716,15 @@
   if (FD->isDependentContext())
 return true;
 
+  // Bail out if a constexpr constructor has an initializer that contains an
+  // error. We deliberately don't produce a diagnostic, as we have produced a
+  // relevant diagnostic when parsing the error initializer.
+  if (const auto *Ctor = dyn_cast(FD)) {
+for (const auto *InitExpr : Ctor->inits()) {
+  if (InitExpr->getInit() && InitExpr->getInit()->containsErrors())
+return false;
+}
+  }
   Expr::EvalStatus Status;
   Status.Diag = &Diags;
 
___
cfe-commits mailing list
cfe-commits@lists

[clang] cfd388d - [analyzer] Try to lift 'REQUIRES: shell' for scan-build tests.

2020-04-07 Thread Artem Dergachev via cfe-commits
Author: Denys Petrov
Date: 2020-04-07T15:56:50+03:00
New Revision: cfd388d344ab29ad5e311ac96e382d96bd85d994

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

LOG: [analyzer] Try to lift 'REQUIRES: shell' for scan-build tests.

This is the second part of Denys's patch, committed separately
due to being more risky.

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

Added: 


Modified: 
clang/test/Analysis/scan-build/exclude_directories.test
clang/test/Analysis/scan-build/help.test
clang/test/Analysis/scan-build/html_output.test
clang/test/Analysis/scan-build/plist_html_output.test
clang/test/Analysis/scan-build/plist_output.test

Removed: 




diff  --git a/clang/test/Analysis/scan-build/exclude_directories.test 
b/clang/test/Analysis/scan-build/exclude_directories.test
index c161e51b6d26..2c79ed842af1 100644
--- a/clang/test/Analysis/scan-build/exclude_directories.test
+++ b/clang/test/Analysis/scan-build/exclude_directories.test
@@ -1,6 +1,3 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
-
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S \
 RUN: %S/Inputs/multidirectory_project/directory1/file1.c \

diff  --git a/clang/test/Analysis/scan-build/help.test 
b/clang/test/Analysis/scan-build/help.test
index 61915d326094..d1f17cd69f51 100644
--- a/clang/test/Analysis/scan-build/help.test
+++ b/clang/test/Analysis/scan-build/help.test
@@ -1,6 +1,3 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
-
 RUN: %scan-build -h | FileCheck %s
 RUN: %scan-build --help | FileCheck %s
 

diff  --git a/clang/test/Analysis/scan-build/html_output.test 
b/clang/test/Analysis/scan-build/html_output.test
index eed2051d4df6..2eca2c013a55 100644
--- a/clang/test/Analysis/scan-build/html_output.test
+++ b/clang/test/Analysis/scan-build/html_output.test
@@ -1,6 +1,3 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
-
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT

diff  --git a/clang/test/Analysis/scan-build/plist_html_output.test 
b/clang/test/Analysis/scan-build/plist_html_output.test
index c07891e35fbf..b995aa6d5d36 100644
--- a/clang/test/Analysis/scan-build/plist_html_output.test
+++ b/clang/test/Analysis/scan-build/plist_html_output.test
@@ -1,6 +1,3 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
-
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist-html -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT

diff  --git a/clang/test/Analysis/scan-build/plist_output.test 
b/clang/test/Analysis/scan-build/plist_output.test
index 0112e84630ed..1e7bef1035b5 100644
--- a/clang/test/Analysis/scan-build/plist_output.test
+++ b/clang/test/Analysis/scan-build/plist_output.test
@@ -1,6 +1,3 @@
-// FIXME: Actually, "perl".
-REQUIRES: shell
-
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT



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


[clang] ec0b990 - [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Sam McCall via cfe-commits
Author: Sam McCall
Date: 2020-04-07T15:01:34+02:00
New Revision: ec0b9908952a9f4a19c3eb92ba0fc01cffcb8614

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

LOG: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. 
NFC

Summary:
The motivation here is fixing https://bugs.llvm.org/show_bug.cgi?id=45428, see
D77507. The fundamental problem is that a "top-level" expansion wasn't precisely
defined. Repairing this concept means that TokenBuffer's "top-level expansion"
may not correspond to a single macro expansion. Example:

```
M(2); // expands to 1+2
```

The expansions overlap, but neither expansion alone yields all the tokens.
We need a TokenBuffer::Mapping that corresponds to their union.

This is fairly easy to fix in CollectPPExpansions, but the current design of
TokenCollector::Builder needs a fix too as it relies on the macro's expansion
range rather than the captured expansion bounds. This fix is hard to make due
to the way code is reused within Builder. And honestly, I found that code pretty
hard to reason about too.

The new approach doesn't use the expansion range, but only the expansion
location: it assumes an expansion is the contiguous set of expanded tokens with
the same expansion location, which seems like a reasonable formalization of
the "top-level" notion.

And hopefully the control flow is easier to follow too, it's considerably
shorter even with more documentation.

Reviewers: kadircet

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/Tokens.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index af11f25b1058..b780c1ca801f 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -500,197 +500,167 @@ class TokenCollector::Builder {
   }
 
   TokenBuffer build() && {
-buildSpelledTokens();
-
-// Walk over expanded tokens and spelled tokens in parallel, building the
-// mappings between those using source locations.
-// To correctly recover empty macro expansions, we also take locations
-// reported to PPCallbacks::MacroExpands into account as we do not have any
-// expanded tokens with source locations to guide us.
-
-// The 'eof' token is special, it is not part of spelled token stream. We
-// handle it separately at the end.
 assert(!Result.ExpandedTokens.empty());
 assert(Result.ExpandedTokens.back().kind() == tok::eof);
-for (unsigned I = 0; I < Result.ExpandedTokens.size() - 1; ++I) {
-  // (!) I might be updated by the following call.
-  processExpandedToken(I);
-}
 
-// 'eof' not handled in the loop, do it here.
-assert(SM.getMainFileID() ==
-   SM.getFileID(Result.ExpandedTokens.back().location()));
-fillGapUntil(Result.Files[SM.getMainFileID()],
- Result.ExpandedTokens.back().location(),
- Result.ExpandedTokens.size() - 1);
-Result.Files[SM.getMainFileID()].EndExpanded = 
Result.ExpandedTokens.size();
+// Tokenize every file that contributed tokens to the expanded stream.
+buildSpelledTokens();
 
-// Some files might have unaccounted spelled tokens at the end, add an 
empty
-// mapping for those as they did not have expanded counterparts.
-fillGapsAtEndOfFiles();
+// The expanded token stream consists of runs of tokens that came from
+// the same source (a macro expansion, part of a file etc).
+// Between these runs are the logical positions of spelled tokens that
+// didn't expand to anything.
+while (NextExpanded < Result.ExpandedTokens.size() - 1 /* eof */) {
+  // Create empty mappings for spelled tokens that expanded to nothing 
here.
+  // May advance NextSpelled, but NextExpanded is unchanged.
+  discard();
+  // Create mapping for a contiguous run of expanded tokens.
+  // Advances NextExpanded past the run, and NextSpelled accordingly.
+  unsigned OldPosition = NextExpanded;
+  advance();
+  if (NextExpanded == OldPosition)
+diagnoseAdvanceFailure();
+}
+// If any tokens remain in any of the files, they didn't expand to 
anything.
+// Create empty mappings up until the end of the file.
+for (const auto &File : Result.Files)
+  discard(File.first);
 
 return std::move(Result);
   }
 
 private:
-  /// Process the next token in an expanded stream and move corresponding
-  /// spelled tokens, record any mapping if needed.
-  /// (!) \p I will be updated if this had to skip tokens, e.g. for macros.
-  void processExpandedToken(unsigned &I) {
-auto L = Result.ExpandedTokens[I].location();
-if (L.isMacroID()) {
-  processM

[clang] 338be9c - [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

2020-04-07 Thread Florian Hahn via cfe-commits
Author: Florian Hahn
Date: 2020-04-07T14:01:55+01:00
New Revision: 338be9c59527c3d172f64e8861bcbb472297d52d

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

LOG: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

Currently Clang does not respect -fno-unroll-loops during LTO. During
D76916 it was suggested to respect -fno-unroll-loops on a TU basis.

This patch uses the existing llvm.loop.unroll.disable metadata to
disable loop unrolling explicitly for each loop in the TU if
unrolling is disabled. This should ensure that loops from TUs compiled
with -fno-unroll-loops are skipped by the unroller during LTO.

This also means that if a loop from a TU with -fno-unroll-loops
gets inlined into a TU without this option, the loop won't be
unrolled.

Due to the fact that some transforms might drop loop metadata, there
potentially are cases in which we still unroll loops from TUs with
-fno-unroll-loops. I think we should fix those issues rather than
introducing a function attribute to disable loop unrolling during LTO.
Improving the metadata handling will benefit other use cases, like
various loop pragmas, too. And it is an improvement to clang completely
ignoring -fno-unroll-loops during LTO.

If that direction looks good, we can use a similar approach to also
respect -fno-vectorize during LTO, at least for LoopVectorize.

In the future, this might also allow us to remove the UnrollLoops option
LLVM's PassManagerBuilder.

Reviewers: Meinersbur, hfinkel, dexonsmith, tejohnson

Reviewed By: Meinersbur, tejohnson

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

Added: 
clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp

Modified: 
clang/lib/CodeGen/CGLoopInfo.cpp
clang/lib/CodeGen/CGLoopInfo.h
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGenCXX/pragma-unroll.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGLoopInfo.cpp 
b/clang/lib/CodeGen/CGLoopInfo.cpp
index 5addf1976168..78da72eda0cf 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/CodeGenOptions.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
@@ -573,6 +574,7 @@ void LoopInfoStack::push(BasicBlock *Header, const 
llvm::DebugLoc &StartLoc,
 }
 
 void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
+ const clang::CodeGenOptions &CGOpts,
  ArrayRef Attrs,
  const llvm::DebugLoc &StartLoc,
  const llvm::DebugLoc &EndLoc) {
@@ -753,6 +755,14 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 }
   }
 
+  if (CGOpts.OptimizationLevel > 0)
+// Disable unrolling for the loop, if unrolling is disabled (via
+// -fno-unroll-loops) and no pragmas override the decision.
+if (!CGOpts.UnrollLoops &&
+(StagedAttrs.UnrollEnable == LoopAttributes::Unspecified &&
+ StagedAttrs.UnrollCount == 0))
+  setUnrollState(LoopAttributes::Disable);
+
   /// Stage the attributes.
   push(Header, StartLoc, EndLoc);
 }

diff  --git a/clang/lib/CodeGen/CGLoopInfo.h b/clang/lib/CodeGen/CGLoopInfo.h
index 5abcf37c5433..e379c64c99a8 100644
--- a/clang/lib/CodeGen/CGLoopInfo.h
+++ b/clang/lib/CodeGen/CGLoopInfo.h
@@ -29,6 +29,7 @@ class MDNode;
 namespace clang {
 class Attr;
 class ASTContext;
+class CodeGenOptions;
 namespace CodeGen {
 
 /// Attributes that may be specified on loops.
@@ -202,6 +203,7 @@ class LoopInfoStack {
   /// Begin a new structured loop. Stage attributes from the Attrs list.
   /// The staged attributes are applied to the loop and then cleared.
   void push(llvm::BasicBlock *Header, clang::ASTContext &Ctx,
+const clang::CodeGenOptions &CGOpts,
 llvm::ArrayRef Attrs, const llvm::DebugLoc &StartLoc,
 const llvm::DebugLoc &EndLoc);
 

diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 85c3bcca0647..ceecbd4dc137 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -728,8 +728,8 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
   EmitBlock(LoopHeader.getBlock());
 
   const SourceRange &R = S.getSourceRange();
-  LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), WhileAttrs,
- SourceLocToDebugLoc(R.getBegin()),
+  LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), CGM.getCodeGenOpts(),
+ WhileAttrs, SourceLocToDebugLoc(R.getBegin()),
  SourceLocToDebugLoc(R.getEnd()));
 
   // Create an exit block for when the condition fails, which will
@@ -830,7 +830,7 @@ void CodeGenFun

[clang] d66afd6 - [Syntax] Merge overlapping top-level macros in TokenBuffer

2020-04-07 Thread Sam McCall via cfe-commits
Author: Sam McCall
Date: 2020-04-07T15:06:04+02:00
New Revision: d66afd6dde542dc373f87e07fe764c071fe20d76

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

LOG: [Syntax] Merge overlapping top-level macros in TokenBuffer

Summary:
Our previous definition of "top-level" was too informal, and didn't
allow for overlapping macros that each directly produce expanded tokens.
See D77507 for previous discussion.

Fixes http://bugs.llvm.org/show_bug.cgi?id=45428

Reviewers: kadircet, vabridgers

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index b780c1ca801f..f214afb5c85e 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -436,14 +436,38 @@ class TokenCollector::CollectPPExpansions : public 
PPCallbacks {
 SourceRange Range, const MacroArgs *Args) override {
 if (!Collector)
   return;
-// Only record top-level expansions, not those where:
+const auto &SM = Collector->PP.getSourceManager();
+// Only record top-level expansions that directly produce expanded tokens.
+// This excludes those where:
 //   - the macro use is inside a macro body,
 //   - the macro appears in an argument to another macro.
-if (!MacroNameTok.getLocation().isFileID() ||
-(LastExpansionEnd.isValid() &&
- Collector->PP.getSourceManager().isBeforeInTranslationUnit(
- Range.getBegin(), LastExpansionEnd)))
+// However macro expansion isn't really a tree, it's token rewrite rules,
+// so there are other cases, e.g.
+//   #define B(X) X
+//   #define A 1 + B
+//   A(2)
+// Both A and B produce expanded tokens, though the macro name 'B' comes
+// from an expansion. The best we can do is merge the mappings for both.
+
+// The *last* token of any top-level macro expansion must be in a file.
+// (In the example above, see the closing paren of the expansion of B).
+if (!Range.getEnd().isFileID())
   return;
+// If there's a current expansion that encloses this one, this one can't be
+// top-level.
+if (LastExpansionEnd.isValid() &&
+!SM.isBeforeInTranslationUnit(LastExpansionEnd, Range.getEnd()))
+  return;
+
+// If the macro invocation (B) starts in a macro (A) but ends in a file,
+// we'll create a merged mapping for A + B by overwriting the endpoint for
+// A's startpoint.
+if (!Range.getBegin().isFileID()) {
+  Range.setBegin(SM.getExpansionLoc(Range.getBegin()));
+  assert(Collector->Expansions.count(Range.getBegin().getRawEncoding()) &&
+ "Overlapping macros should have same expansion location");
+}
+
 Collector->Expansions[Range.getBegin().getRawEncoding()] = Range.getEnd();
 LastExpansionEnd = Range.getEnd();
   }

diff  --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 256096d6a83e..a89d67fc6a76 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -497,11 +497,28 @@ file './input.cpp'
   mappings:
 ['#'_0, 'int'_7) => ['int'_0, 'int'_0)
 ['FOO'_10, ''_11) => ['10'_3, ''_7)
-)"}};
+)"},
+  {R"cpp(
+ #define NUM 42
+ #define ID(a) a
+ #define M 1 + ID
+ M(NUM)
+   )cpp",
+   R"(expanded tokens:
+  1 + 42
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define ID ( a ) a # define M 1 + ID M ( NUM )
+  mappings:
+['#'_0, 'M'_17) => ['1'_0, '1'_0)
+['M'_17, ''_21) => ['1'_0, ''_3)
+)"},
+  };
 
-  for (auto &Test : TestCases)
-EXPECT_EQ(Test.second, collectAndDump(Test.first))
-<< collectAndDump(Test.first);
+  for (auto &Test : TestCases) {
+std::string Dump = collectAndDump(Test.first);
+EXPECT_EQ(Test.second, Dump) << Dump;
+  }
 }
 
 TEST_F(TokenCollectorTest, SpecialTokens) {



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


[clang] 1bf055c - [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Dmitri Gribenko via cfe-commits
Author: Marcel Hlopko
Date: 2020-04-07T15:07:16+02:00
New Revision: 1bf055c9891f1a5ab2ff6a04348bd83fcc0a9cde

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

LOG: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

Summary:
Same restrictions apply as in the other direction: macro arguments are
not supported yet, only full macro expansions can be mapped.

Taking over from https://reviews.llvm.org/D72581.

Reviewers: gribozavr2, sammccall

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tokens.h 
b/clang/include/clang/Tooling/Syntax/Tokens.h
index 7e50892284f4..a7f9369ddfff 100644
--- a/clang/include/clang/Tooling/Syntax/Tokens.h
+++ b/clang/include/clang/Tooling/Syntax/Tokens.h
@@ -171,7 +171,6 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const 
Token &T);
 /// To build a token buffer use the TokenCollector class. You can also compute
 /// the spelled tokens of a file using the tokenize() helper.
 ///
-/// FIXME: allow to map from spelled to expanded tokens when use-case shows up.
 /// FIXME: allow mappings into macro arguments.
 class TokenBuffer {
 public:
@@ -228,6 +227,36 @@ class TokenBuffer {
   llvm::Optional>
   spelledForExpanded(llvm::ArrayRef Expanded) const;
 
+  /// Find the subranges of expanded tokens, corresponding to \p Spelled.
+  ///
+  /// Some spelled tokens may not be present in the expanded token stream, so
+  /// this function can return an empty vector, e.g. for tokens of macro
+  /// directives or disabled preprocessor branches.
+  ///
+  /// Some spelled tokens can be duplicated in the expanded token stream
+  /// multiple times and this function will return multiple results in those
+  /// cases. This happens when \p Spelled is inside a macro argument.
+  ///
+  /// FIXME: return correct results on macro arguments. For now, we return an
+  ///empty list.
+  ///
+  /// (!) will return empty vector on tokens from #define body:
+  /// E.g. for the following example:
+  ///
+  ///   #define FIRST(A) f1 A = A f2
+  ///   #define SECOND s
+  ///
+  ///   a FIRST(arg) b SECOND c // expanded tokens are: a f1 arg = arg f2 b s
+  /// The results would be
+  ///   spelled   => expanded
+  ///   
+  ///   #define FIRST => {}
+  ///   a FIRST(arg)  => {a f1 arg = arg f2}
+  ///   arg   => {arg, arg} // arg #1 is before `=` and arg #2 is
+  ///   // after `=` in the expanded tokens.
+  llvm::SmallVector, 1>
+  expandedForSpelled(llvm::ArrayRef Spelled) const;
+
   /// An expansion produced by the preprocessor, includes macro expansions and
   /// preprocessor directives. Preprocessor always maps a non-empty range of
   /// spelled tokens to a (possibly empty) range of expanded tokens. Here is a
@@ -317,6 +346,12 @@ class TokenBuffer {
   std::pair
   spelledForExpandedToken(const syntax::Token *Expanded) const;
 
+  /// Returns a mapping starting before \p Spelled token, or nullptr if no
+  /// such mapping exists.
+  static const Mapping *
+  mappingStartingBeforeSpelled(const MarkedFile &F,
+   const syntax::Token *Spelled);
+
   /// Token stream produced after preprocessing, conceputally this captures the
   /// same stream as 'clang -E' (excluding the preprocessor directives like
   /// #file, etc.).

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index f214afb5c85e..1464d97d037d 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -213,19 +213,109 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
   // Our token could only be produced by the previous mapping.
   if (It == File.Mappings.begin()) {
 // No previous mapping, no need to modify offsets.
-return {&File.SpelledTokens[ExpandedIndex - File.BeginExpanded], nullptr};
+return {&File.SpelledTokens[ExpandedIndex - File.BeginExpanded],
+/*Mapping=*/nullptr};
   }
   --It; // 'It' now points to last mapping that started before our token.
 
   // Check if the token is part of the mapping.
   if (ExpandedIndex < It->EndExpanded)
-return {&File.SpelledTokens[It->BeginSpelled], /*Mapping*/ &*It};
+return {&File.SpelledTokens[It->BeginSpelled], /*Mapping=*/&*It};
 
   // Not part of the mapping, use the index from previous mapping to compute 
the
   // corresponding spelled token.
   return {

[PATCH] D77440: [Hexagon] Update include paths for linux/musl

2020-04-07 Thread Sid Manning via Phabricator via cfe-commits
sidneym updated this revision to Diff 255655.
sidneym added a comment.
Herald added a subscriber: ormris.

Break out linux parts of hexagon-toolchain-elf.c into hexagon-toolchain-linux.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77440

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hexagon.h
  
clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme
  clang/test/Driver/hexagon-toolchain-elf.c
  clang/test/Driver/hexagon-toolchain-linux.c

Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- /dev/null
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -0,0 +1,101 @@
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK000 %s
+// CHECK000-NOT:  {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
+// CHECK000:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK000:  "{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK000:  "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK001 %s
+// CHECK001-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK001:"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o"
+// CHECK001:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK001-NOT:{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK002 %s
+// CHECK002:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK002-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
+// CHECK002-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// CHECK002-NOT:   -lclang_rt.builtins-hexagon
+// CHECK002-NOT:   -lc
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK003 %s
+// CHECK003:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK003-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}Scrt1.o
+// CHECK003-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// CHECK003:   "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK004 %s
+// CHECK004:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK004:   "{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK004-NOT:   -lclang_rt.builtins-hexagon
+// CHECK004-NOT:   -lc
+// -
+// Not Passing -fno-use-init-array when musl is selected
+// -
+// RU

[PATCH] D76768: [analyzer] Added support of scan-build and exploded-graph-rewriter regression tests for Windows

2020-04-07 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This seems to break tests on Windows: http://45.33.8.238/win/12320/step_7.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76768



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


[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I'm not familiar with the code, but this patch does fix the large-preamble 
crashes we encountered internally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594



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


[PATCH] D75364: [clang-format] Handle macros in function params and return value

2020-04-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D75364#1966743 , @tamas.petz wrote:

> Wow, I have missed that configuration option.
>  I will try it, I assume it should work.
>
> Looks like this change should be abandoned.


To be honest, I forget what we've got too! ;-) I was just writing a reply that 
said "how about adding an option with a list of type macros", I was looking for 
an example of other places we do that, and stumbled on it.


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

https://reviews.llvm.org/D75364



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


[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.
Closed by commit rGec0b9908952a: [Syntax] Simplify TokenCollector::Builder, use 
captured expansion bounds. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D77614?vs=255621&id=255661#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77614

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -500,197 +500,167 @@
   }
 
   TokenBuffer build() && {
-buildSpelledTokens();
-
-// Walk over expanded tokens and spelled tokens in parallel, building the
-// mappings between those using source locations.
-// To correctly recover empty macro expansions, we also take locations
-// reported to PPCallbacks::MacroExpands into account as we do not have any
-// expanded tokens with source locations to guide us.
-
-// The 'eof' token is special, it is not part of spelled token stream. We
-// handle it separately at the end.
 assert(!Result.ExpandedTokens.empty());
 assert(Result.ExpandedTokens.back().kind() == tok::eof);
-for (unsigned I = 0; I < Result.ExpandedTokens.size() - 1; ++I) {
-  // (!) I might be updated by the following call.
-  processExpandedToken(I);
-}
 
-// 'eof' not handled in the loop, do it here.
-assert(SM.getMainFileID() ==
-   SM.getFileID(Result.ExpandedTokens.back().location()));
-fillGapUntil(Result.Files[SM.getMainFileID()],
- Result.ExpandedTokens.back().location(),
- Result.ExpandedTokens.size() - 1);
-Result.Files[SM.getMainFileID()].EndExpanded = Result.ExpandedTokens.size();
+// Tokenize every file that contributed tokens to the expanded stream.
+buildSpelledTokens();
 
-// Some files might have unaccounted spelled tokens at the end, add an empty
-// mapping for those as they did not have expanded counterparts.
-fillGapsAtEndOfFiles();
+// The expanded token stream consists of runs of tokens that came from
+// the same source (a macro expansion, part of a file etc).
+// Between these runs are the logical positions of spelled tokens that
+// didn't expand to anything.
+while (NextExpanded < Result.ExpandedTokens.size() - 1 /* eof */) {
+  // Create empty mappings for spelled tokens that expanded to nothing here.
+  // May advance NextSpelled, but NextExpanded is unchanged.
+  discard();
+  // Create mapping for a contiguous run of expanded tokens.
+  // Advances NextExpanded past the run, and NextSpelled accordingly.
+  unsigned OldPosition = NextExpanded;
+  advance();
+  if (NextExpanded == OldPosition)
+diagnoseAdvanceFailure();
+}
+// If any tokens remain in any of the files, they didn't expand to anything.
+// Create empty mappings up until the end of the file.
+for (const auto &File : Result.Files)
+  discard(File.first);
 
 return std::move(Result);
   }
 
 private:
-  /// Process the next token in an expanded stream and move corresponding
-  /// spelled tokens, record any mapping if needed.
-  /// (!) \p I will be updated if this had to skip tokens, e.g. for macros.
-  void processExpandedToken(unsigned &I) {
-auto L = Result.ExpandedTokens[I].location();
-if (L.isMacroID()) {
-  processMacroExpansion(SM.getExpansionRange(L), I);
-  return;
+  // Consume a sequence of spelled tokens that didn't expand to anything.
+  // In the simplest case, skips spelled tokens until finding one that produced
+  // the NextExpanded token, and creates an empty mapping for them.
+  // If Drain is provided, skips remaining tokens from that file instead.
+  void discard(llvm::Optional Drain = llvm::None) {
+SourceLocation Target =
+Drain ? SM.getLocForEndOfFile(*Drain)
+  : SM.getExpansionLoc(
+Result.ExpandedTokens[NextExpanded].location());
+FileID File = SM.getFileID(Target);
+const auto &SpelledTokens = Result.Files[File].SpelledTokens;
+auto &NextSpelled = this->NextSpelled[File];
+
+TokenBuffer::Mapping Mapping;
+Mapping.BeginSpelled = NextSpelled;
+// When dropping trailing tokens from a file, the empty mapping should
+// be positioned within the file's expanded-token range (at the end).
+Mapping.BeginExpanded = Mapping.EndExpanded =
+Drain ? Result.Files[*Drain].EndExpanded : NextExpanded;
+// We may want to split into several adjacent empty mappings.
+// FlushMapping() emits the current mapping and starts a new one.
+auto FlushMapping = [&, this] {
+  Mapping.EndSpelled = NextSpelled;
+  if (Mapping.BeginSpelled != Mapping.EndSpelled)
+Result

[PATCH] D77615: [Syntax] Merge overlapping top-level macros in TokenBuffer

2020-04-07 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 rGd66afd6dde54: [Syntax] Merge overlapping top-level macros in 
TokenBuffer (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D77615?vs=25&id=255663#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77615

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -497,11 +497,28 @@
   mappings:
 ['#'_0, 'int'_7) => ['int'_0, 'int'_0)
 ['FOO'_10, ''_11) => ['10'_3, ''_7)
-)"}};
+)"},
+  {R"cpp(
+ #define NUM 42
+ #define ID(a) a
+ #define M 1 + ID
+ M(NUM)
+   )cpp",
+   R"(expanded tokens:
+  1 + 42
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define ID ( a ) a # define M 1 + ID M ( NUM )
+  mappings:
+['#'_0, 'M'_17) => ['1'_0, '1'_0)
+['M'_17, ''_21) => ['1'_0, ''_3)
+)"},
+  };
 
-  for (auto &Test : TestCases)
-EXPECT_EQ(Test.second, collectAndDump(Test.first))
-<< collectAndDump(Test.first);
+  for (auto &Test : TestCases) {
+std::string Dump = collectAndDump(Test.first);
+EXPECT_EQ(Test.second, Dump) << Dump;
+  }
 }
 
 TEST_F(TokenCollectorTest, SpecialTokens) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -436,14 +436,38 @@
 SourceRange Range, const MacroArgs *Args) override {
 if (!Collector)
   return;
-// Only record top-level expansions, not those where:
+const auto &SM = Collector->PP.getSourceManager();
+// Only record top-level expansions that directly produce expanded tokens.
+// This excludes those where:
 //   - the macro use is inside a macro body,
 //   - the macro appears in an argument to another macro.
-if (!MacroNameTok.getLocation().isFileID() ||
-(LastExpansionEnd.isValid() &&
- Collector->PP.getSourceManager().isBeforeInTranslationUnit(
- Range.getBegin(), LastExpansionEnd)))
+// However macro expansion isn't really a tree, it's token rewrite rules,
+// so there are other cases, e.g.
+//   #define B(X) X
+//   #define A 1 + B
+//   A(2)
+// Both A and B produce expanded tokens, though the macro name 'B' comes
+// from an expansion. The best we can do is merge the mappings for both.
+
+// The *last* token of any top-level macro expansion must be in a file.
+// (In the example above, see the closing paren of the expansion of B).
+if (!Range.getEnd().isFileID())
   return;
+// If there's a current expansion that encloses this one, this one can't be
+// top-level.
+if (LastExpansionEnd.isValid() &&
+!SM.isBeforeInTranslationUnit(LastExpansionEnd, Range.getEnd()))
+  return;
+
+// If the macro invocation (B) starts in a macro (A) but ends in a file,
+// we'll create a merged mapping for A + B by overwriting the endpoint for
+// A's startpoint.
+if (!Range.getBegin().isFileID()) {
+  Range.setBegin(SM.getExpansionLoc(Range.getBegin()));
+  assert(Collector->Expansions.count(Range.getBegin().getRawEncoding()) &&
+ "Overlapping macros should have same expansion location");
+}
+
 Collector->Expansions[Range.getBegin().getRawEncoding()] = Range.getEnd();
 LastExpansionEnd = Range.getEnd();
   }


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -497,11 +497,28 @@
   mappings:
 ['#'_0, 'int'_7) => ['int'_0, 'int'_0)
 ['FOO'_10, ''_11) => ['10'_3, ''_7)
-)"}};
+)"},
+  {R"cpp(
+ #define NUM 42
+ #define ID(a) a
+ #define M 1 + ID
+ M(NUM)
+   )cpp",
+   R"(expanded tokens:
+  1 + 42
+file './input.cpp'
+  spelled tokens:
+# define NUM 42 # define ID ( a ) a # define M 1 + ID M ( NUM )
+  mappings:
+['#'_0, 'M'_17) => ['1'_0, '1'_0)
+['M'_17, ''_21) => ['1'_0, ''_3)
+)"},
+  };
 
-  for (auto &Test : TestCases)
-EXPECT_EQ(Test.second, collectAndDump(Test.first))
-<< collectAndDump(Test.first);
+  for (auto &Test : TestCases) {
+std::string Dump = collectAndDump(Test.first);
+EXPECT_EQ(Test.second, Dump) << Dump;
+  }
 }
 
 TEST_F(TokenCollectorTest, SpecialTokens) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/

[PATCH] D77058: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

2020-04-07 Thread Florian Hahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG338be9c59527: [Clang] Add llvm.loop.unroll.disable to loops 
with -fno-unroll-loops. (authored by fhahn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77058

Files:
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
  clang/test/CodeGenCXX/pragma-unroll.cpp

Index: clang/test/CodeGenCXX/pragma-unroll.cpp
===
--- clang/test/CodeGenCXX/pragma-unroll.cpp
+++ clang/test/CodeGenCXX/pragma-unroll.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
 
+// Check that passing -fno-unroll-loops does not impact the decision made using pragmas.
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - -O1 -disable-llvm-optzns -fno-unroll-loops %s | FileCheck %s
+
 // Verify while loop is recognized after unroll pragma.
 void while_test(int *List, int Length) {
   // CHECK: define {{.*}} @_Z10while_test
Index: clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O0 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=NO_UNROLL_MD %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O1 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O2 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns | FileCheck --check-prefix=NO_UNROLL_MD %s
+
+// NO_UNROLL_MD-NOT: llvm.loop
+
+// Verify unroll.disable metadata is added to while loop with -fno-unroll-loops
+// and optlevel > 0.
+void while_test(int *List, int Length) {
+  // UNROLL_DISABLED_MD: define {{.*}} @_Z10while_test
+  int i = 0;
+
+  while (i < Length) {
+// UNROLL_DISABLED_MD: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
+List[i] = i * 2;
+i++;
+  }
+}
+
+// Verify unroll.disable metadata is added to do-while loop with
+// -fno-unroll-loops and optlevel > 0.
+void do_test(int *List, int Length) {
+  // UNROLL_DISABLED_MD: define {{.*}} @_Z7do_test
+  int i = 0;
+
+  do {
+// UNROLL_DISABLED_MD: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]
+List[i] = i * 2;
+i++;
+  } while (i < Length);
+}
+
+// Verify unroll.disable metadata is added to while loop with -fno-unroll-loops
+// and optlevel > 0.
+void for_test(int *List, int Length) {
+  // UNROLL_DISABLED_MD: define {{.*}} @_Z8for_test
+  for (int i = 0; i < Length; i++) {
+// UNROLL_DISABLED_MD: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
+List[i] = i * 2;
+  }
+}
+
+// UNROLL_DISABLED_MD: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[UNROLL_DISABLE:.*]]}
+// UNROLL_DISABLED_MD: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
+// UNROLL_DISABLED_MD: ![[LOOP_2]] = distinct !{![[LOOP_2:.*]], ![[UNROLL_DISABLE:.*]]}
+// UNROLL_DISABLED_MD: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNROLL_DISABLE:.*]]}
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -728,8 +728,8 @@
   EmitBlock(LoopHeader.getBlock());
 
   const SourceRange &R = S.getSourceRange();
-  LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), WhileAttrs,
- SourceLocToDebugLoc(R.getBegin()),
+  LoopStack.push(LoopHeader.getBlock(), CGM.getContext(), CGM.getCodeGenOpts(),
+ WhileAttrs, SourceLocToDebugLoc(R.getBegin()),
  SourceLocToDebugLoc(R.getEnd()));
 
   // Create an exit block for when the condition fails, which will
@@ -830,7 +830,7 @@
   EmitBlock(LoopCond.getBlock());
 
   const SourceRange &R = S.getSourceRange();
-  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
+  LoopStack.push(LoopBody, CGM.getContext(), CGM.getCodeGenOpts(), DoAttrs,
  SourceLocToDebugLoc(R.getBegin()),
  SourceLocToDebugLoc(R.getEnd()));
 
@@ -888,7 +888,7 @@
   EmitBlock(CondBlock);
 
   const SourceRange &R = S.getSourceRange();
-  LoopStack.push(CondBlock, CGM.getContext(), ForAttrs,
+  LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(), ForAttrs,
  SourceLocToDebugLoc(R.getBegin()),
 

[PATCH] D77645: [clangd] Support dexp -c "some command"

2020-04-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: mnauw, kbobyrev.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

It runs one command and exits.
See D77385  for motivation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77645

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp

Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -14,6 +14,7 @@
 #include "SourceCode.h"
 #include "index/Serialization.h"
 #include "index/dex/Dex.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -29,6 +30,9 @@
  llvm::cl::desc("Path to the index"),
  llvm::cl::Positional, llvm::cl::Required);
 
+llvm::cl::opt
+ExecCommand("c", llvm::cl::desc("Command to execute and then exit"));
+
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
 queries over given symbol collection obtained via clangd-indexer. The
@@ -78,6 +82,7 @@
   llvm::cl::opt> Help{
   "help", llvm::cl::desc("Display available options"),
   llvm::cl::ValueDisallowed, llvm::cl::cat(llvm::cl::GeneralCategory)};
+  // FIXME: allow commands to signal failure.
   virtual void run() = 0;
 
 protected:
@@ -85,25 +90,27 @@
 
 public:
   virtual ~Command() = default;
-  virtual void parseAndRun(llvm::ArrayRef Argv,
-   const char *Overview, const SymbolIndex &Index) {
+  bool parseAndRun(llvm::ArrayRef Argv, const char *Overview,
+   const SymbolIndex &Index) {
 std::string ParseErrs;
 llvm::raw_string_ostream OS(ParseErrs);
 bool Ok = llvm::cl::ParseCommandLineOptions(Argv.size(), Argv.data(),
 Overview, &OS);
+// must do this before opts are destroyed
+auto Cleanup = llvm::make_scope_exit(llvm::cl::ResetCommandLineParser);
 if (Help.getNumOccurrences() > 0) {
   // Avoid printing parse errors in this case.
   // (Well, in theory. A bunch get printed to llvm::errs() regardless!)
   llvm::cl::PrintHelpMessage();
-} else {
-  llvm::outs() << OS.str();
-  if (Ok) {
-this->Index = &Index;
-reportTime(Argv[0], [&] { run(); });
-  }
+  return true;
+}
+
+llvm::outs() << OS.str();
+if (Ok) {
+  this->Index = &Index;
+  reportTime(Argv[0], [&] { run(); });
 }
-llvm::cl::ResetCommandLineParser(); // must do this before opts are
-// destroyed.
+return Ok;
   }
 };
 
@@ -268,6 +275,34 @@
   return loadIndex(Index, /*UseDex=*/true);
 }
 
+bool runCommand(std::string Request, const SymbolIndex &Index) {
+  // Split on spaces and add required null-termination.
+  std::replace(Request.begin(), Request.end(), ' ', '\0');
+  llvm::SmallVector Args;
+  llvm::StringRef(Request).split(Args, '\0', /*MaxSplit=*/-1,
+ /*KeepEmpty=*/false);
+  if (Args.empty())
+return false;
+  if (Args.front() == "help") {
+llvm::outs() << "dexp - Index explorer\nCommands:\n";
+for (const auto &C : CommandInfo)
+  llvm::outs() << llvm::formatv("{0,16} - {1}\n", C.Name, C.Description);
+llvm::outs() << "Get detailed command help with e.g. `find -help`.\n";
+return true;
+  }
+  llvm::SmallVector FakeArgv;
+  for (llvm::StringRef S : Args)
+FakeArgv.push_back(S.data()); // Terminated by separator or end of string.
+
+  for (const auto &Cmd : CommandInfo) {
+if (Cmd.Name == Args.front())
+  return Cmd.Implementation()->parseAndRun(FakeArgv, Cmd.Description,
+   Index);
+  }
+  llvm::outs() << "Unknown command. Try 'help'.\n";
+  return false;
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
@@ -289,38 +324,11 @@
 return -1;
   }
 
-  llvm::LineEditor LE("dexp");
-
-  while (llvm::Optional Request = LE.readLine()) {
-// Split on spaces and add required null-termination.
-std::replace(Request->begin(), Request->end(), ' ', '\0');
-llvm::SmallVector Args;
-llvm::StringRef(*Request).split(Args, '\0', /*MaxSplit=*/-1,
-/*KeepEmpty=*/false);
-if (Args.empty())
-  continue;
-if (Args.front() == "help") {
-  llvm::outs() << "dexp - Index explorer\nCommands:\n";
-  for (const auto &C : CommandInfo)
-llvm::outs() << llvm::formatv("{0,16} - {1}\n", C.Name, C.Description);
-  llvm::outs() << "Get detailed command help with e.g. `find -help`.\n";
-  continue;
-}
-llvm::SmallVector FakeArgv;
-for (llv

[PATCH] D77209: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bf055c9891f: [Syntax] Add mapping from spelled to expanded 
tokens for TokenBuffer (authored by hlopko, committed by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D77209?vs=255654&id=255664#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77209

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp
  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
@@ -1215,6 +1215,9 @@
 |   `-}
 `-}
)txt");
+}
+
+TEST_F(SyntaxTreeTest, ModifiableNodes) {
   // All nodes can be mutated.
   expectTreeDumpEqual(
   R"cpp(
Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -57,6 +57,7 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::Not;
 using ::testing::Pointee;
@@ -185,10 +186,14 @@
   template 
   llvm::ArrayRef findSubrange(llvm::ArrayRef Subrange,
  llvm::ArrayRef Range, Eq F) {
-for (auto Begin = Range.begin(); Begin < Range.end(); ++Begin) {
+assert(Subrange.size() >= 1);
+if (Range.size() < Subrange.size())
+  return llvm::makeArrayRef(Range.end(), Range.end());
+for (auto Begin = Range.begin(), Last = Range.end() - Subrange.size();
+ Begin <= Last; ++Begin) {
   auto It = Begin;
-  for (auto ItSub = Subrange.begin();
-   ItSub != Subrange.end() && It != Range.end(); ++ItSub, ++It) {
+  for (auto ItSub = Subrange.begin(); ItSub != Subrange.end();
+   ++ItSub, ++It) {
 if (!F(*ItSub, *It))
   goto continue_outer;
   }
@@ -906,4 +911,111 @@
   ASSERT_EQ(Code.points().size(), 8u);
 }
 
+TEST_F(TokenBufferTest, ExpandedBySpelled) {
+  recordTokens(R"cpp(
+a1 a2 a3 b1 b2
+  )cpp");
+  // Sanity check: expanded and spelled tokens are stored separately.
+  EXPECT_THAT(findExpanded("a1 a2"), Not(SameRange(findSpelled("a1 a2";
+  // Searching for subranges of expanded tokens should give the corresponding
+  // spelled ones.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3 b1 b2")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1 a2 a3")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("b1 b2")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Test search on simple macro expansions.
+  recordTokens(R"cpp(
+#define A a1 a2 a3
+#define B b1 b2
+
+A split B
+  )cpp");
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split B")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("A split").drop_back()),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("split B").drop_front()),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+
+  // Ranges not fully covering macro expansions should fail.
+  recordTokens(R"cpp(
+#define ID(x) x
+
+ID(a)
+  )cpp");
+  // Spelled don't cover entire mapping (missing ID token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("( a )")), IsEmpty());
+  // Spelled don't cover entire mapping (missing ) token) -> empty result
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a")), IsEmpty());
+
+  // Recursive macro invocations.
+  recordTokens(R"cpp(
+#define ID(x) x
+#define B b1 b2
+
+ID(ID(ID(a1) a2 a3)) split ID(B)
+  )cpp");
+
+  EXPECT_THAT(
+  Buffer.expandedForSpelled(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3";
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( B )")),
+  ElementsAre(SameRange(findExpanded("b1 b2";
+  EXPECT_THAT(Buffer.expandedForSpelled(
+  findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) ) split ID ( B )")),
+  ElementsAre(SameRange(findExpanded("a1 a2 a3 split b1 b2";
+  // FIXME: these should succeed, but we do not support macro arguments yet.
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("a1")), IsEmpty());
+  EXPECT_THAT(Buffer.expandedForSpelled(findSpelled("ID ( a1 ) a2")),
+  IsEmpty());
+
+  // Empty macro expansions.
+  recordTok

[clang] 6b3353e - Revert "[analyzer] Try to lift 'REQUIRES: shell' for scan-build tests."

2020-04-07 Thread Artem Dergachev via cfe-commits
Author: Artem Dergachev
Date: 2020-04-07T16:37:42+03:00
New Revision: 6b3353e832940e9484bba7b8017b8ea1f0c63806

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

LOG: Revert "[analyzer] Try to lift 'REQUIRES: shell' for scan-build tests."

This reverts commit cfd388d344ab29ad5e311ac96e382d96bd85d994.

Added: 


Modified: 
clang/test/Analysis/scan-build/exclude_directories.test
clang/test/Analysis/scan-build/help.test
clang/test/Analysis/scan-build/html_output.test
clang/test/Analysis/scan-build/plist_html_output.test
clang/test/Analysis/scan-build/plist_output.test

Removed: 




diff  --git a/clang/test/Analysis/scan-build/exclude_directories.test 
b/clang/test/Analysis/scan-build/exclude_directories.test
index 2c79ed842af1..c161e51b6d26 100644
--- a/clang/test/Analysis/scan-build/exclude_directories.test
+++ b/clang/test/Analysis/scan-build/exclude_directories.test
@@ -1,3 +1,6 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S \
 RUN: %S/Inputs/multidirectory_project/directory1/file1.c \

diff  --git a/clang/test/Analysis/scan-build/help.test 
b/clang/test/Analysis/scan-build/help.test
index d1f17cd69f51..61915d326094 100644
--- a/clang/test/Analysis/scan-build/help.test
+++ b/clang/test/Analysis/scan-build/help.test
@@ -1,3 +1,6 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
 RUN: %scan-build -h | FileCheck %s
 RUN: %scan-build --help | FileCheck %s
 

diff  --git a/clang/test/Analysis/scan-build/html_output.test 
b/clang/test/Analysis/scan-build/html_output.test
index 2eca2c013a55..eed2051d4df6 100644
--- a/clang/test/Analysis/scan-build/html_output.test
+++ b/clang/test/Analysis/scan-build/html_output.test
@@ -1,3 +1,6 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT

diff  --git a/clang/test/Analysis/scan-build/plist_html_output.test 
b/clang/test/Analysis/scan-build/plist_html_output.test
index b995aa6d5d36..c07891e35fbf 100644
--- a/clang/test/Analysis/scan-build/plist_html_output.test
+++ b/clang/test/Analysis/scan-build/plist_html_output.test
@@ -1,3 +1,6 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist-html -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT

diff  --git a/clang/test/Analysis/scan-build/plist_output.test 
b/clang/test/Analysis/scan-build/plist_output.test
index 1e7bef1035b5..0112e84630ed 100644
--- a/clang/test/Analysis/scan-build/plist_output.test
+++ b/clang/test/Analysis/scan-build/plist_output.test
@@ -1,3 +1,6 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
 RUN: rm -rf %t.output_dir && mkdir %t.output_dir
 RUN: %scan-build -plist -o %t.output_dir %clang -S 
%S/Inputs/single_null_dereference.c \
 RUN: | FileCheck %s -check-prefix CHECK-STDOUT



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


[clang] c97be2c - [hip] Remove `hip_pinned_shadow`.

2020-04-07 Thread Michael Liao via cfe-commits
Author: Michael Liao
Date: 2020-04-07T09:51:49-04:00
New Revision: c97be2c377852fad7eb38409aae5692fa417e49b

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

LOG: [hip] Remove `hip_pinned_shadow`.

Summary:
- Use `device_builtin_surface` and `device_builtin_texture` for
  surface/texture reference support. So far, both the host and device
  use the same reference type, which could be revised later when
  interface/implementation is stablized.

Reviewers: yaxunl

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/ToolChains/HIP.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Driver/hip-toolchain-no-rdc.hip
clang/test/Driver/hip-toolchain-rdc.hip
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 
clang/test/AST/ast-dump-hip-pinned-shadow.cu
clang/test/SemaCUDA/hip-pinned-shadow.cu



diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f55ce2cc84dd..c586f9b9466a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -322,7 +322,6 @@ class LangOpt {
 def MicrosoftExt : LangOpt<"MicrosoftExt">;
 def Borland : LangOpt<"Borland">;
 def CUDA : LangOpt<"CUDA">;
-def HIP : LangOpt<"HIP">;
 def SYCL : LangOpt<"SYCLIsDevice">;
 def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
 def CPlusPlus : LangOpt<"CPlusPlus">;
@@ -1052,13 +1051,6 @@ def CUDADevice : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
-def HIPPinnedShadow : InheritableAttr {
-  let Spellings = [GNU<"hip_pinned_shadow">, 
Declspec<"__hip_pinned_shadow__">];
-  let Subjects = SubjectList<[Var]>;
-  let LangOpts = [HIP];
-  let Documentation = [HIPPinnedShadowDocs];
-}
-
 def CUDADeviceBuiltin : IgnoredAttr {
   let Spellings = [GNU<"device_builtin">, Declspec<"__device_builtin__">];
   let LangOpts = [CUDA];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fb1c82a80115..36561c04d395 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4613,18 +4613,6 @@ only call one function.
 }];
 }
 
-def HIPPinnedShadowDocs : Documentation {
-  let Category = DocCatType;
-  let Content = [{
-The GNU style attribute __attribute__((hip_pinned_shadow)) or MSVC style 
attribute
-__declspec(hip_pinned_shadow) can be added to the definition of a global 
variable
-to indicate it is a HIP pinned shadow variable. A HIP pinned shadow variable 
can
-be accessed on both device side and host side. It has external linkage and is
-not initialized on device side. It has internal linkage and is initialized by
-the initializer on host side.
-  }];
-}
-
 def CUDADeviceBuiltinSurfaceTypeDocs : Documentation {
   let Category = DocCatType;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 1645a9eb17de..8b7d52b88146 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1955,9 +1955,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, 
llvm::Function *F,
   }
 }
 
-void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) {
-  assert(SkipCheck || (!GV->isDeclaration() &&
-   "Only globals with definition can force usage."));
+void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
+  assert(!GV->isDeclaration() &&
+ "Only globals with definition can force usage.");
   LLVMUsed.emplace_back(GV);
 }
 
@@ -2520,7 +2520,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   !Global->hasAttr() &&
   !Global->hasAttr() &&
   !Global->hasAttr() &&
-  !(LangOpts.HIP && Global->hasAttr()) &&
   !Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
   !Global->getType()->isCUDADeviceBuiltinTextureType())
 return;
@@ -3928,10 +3927,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
D->getType()->isCUDADeviceBuiltinTextureType());
   // HIP pinned shadow of initialized host-side global variables are also
   // left undefined.
-  bool IsHIPPinnedShadowVar =
-  getLangOpts().CUDAIsDevice && D->hasAttr();
-  if (getLangOpts().CUDA && (IsCUDASharedVar || IsCUDAShadowVar ||
- IsCUDADeviceShadowVar || IsHIPPinnedShadowVar))
+  if (getLangOpts().CUDA &&
+  (IsCUDASharedVar || IsCUDAShadowVar || IsCUDADeviceShadowVar))
 Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy));
   else if (D->hasAttr())

[PATCH] D73290: [PowerPC] Add clang -msvr4-struct-return for 32-bit ELF

2020-04-07 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA added a comment.

@jhibbits is this patch going to be committed soon? I have a patch 
(https://reviews.llvm.org/D76360) that I will need to rebase once this is in.  
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73290



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


[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau updated this revision to Diff 255666.
pgousseau added a comment.

Fix false negative test introduce while attempting to add label check.


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

https://reviews.llvm.org/D77393

Files:
  clang/lib/Headers/emmintrin.h
  clang/lib/Headers/xmmintrin.h
  clang/test/Headers/x86-header-warnings.c

Index: clang/test/Headers/x86-header-warnings.c
===
--- /dev/null
+++ clang/test/Headers/x86-header-warnings.c
@@ -0,0 +1,44 @@
+// Fix sign conversion warnings found by fsanitize=implicit-integer-sign-change
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \
+// RUN: | %clang_cc1 -x c - -triple x86_64-pc-linux-gnu -ffreestanding -Wsign-conversion 2>&1 \
+// RUN: | FileCheck --allow-empty %s
+// REQUIRES: x86-registered-target
+
+#include 
+
+void test0() {
+  // CHECK-LABEL: implicit declaration of function 'label0'
+  // CHECK-NOT: warning: implicit conversion
+  label0();
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
+  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_MASK);
+
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INVALID);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DENORM);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DIV_ZERO);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_OVERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_UNDERFLOW);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INEXACT);
+  _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_MASK);
+
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INVALID);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DENORM);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_DIV_ZERO);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_OVERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_UNDERFLOW);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT);
+  _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
+
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_UP);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_TOWARD_ZERO);
+  _MM_SET_ROUNDING_MODE(_MM_ROUND_MASK);
+
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_MASK);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
+}
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -2931,31 +2931,31 @@
 
 #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
 
-#define _MM_EXCEPT_INVALID(0x0001)
-#define _MM_EXCEPT_DENORM (0x0002)
-#define _MM_EXCEPT_DIV_ZERO   (0x0004)
-#define _MM_EXCEPT_OVERFLOW   (0x0008)
-#define _MM_EXCEPT_UNDERFLOW  (0x0010)
-#define _MM_EXCEPT_INEXACT(0x0020)
-#define _MM_EXCEPT_MASK   (0x003f)
-
-#define _MM_MASK_INVALID  (0x0080)
-#define _MM_MASK_DENORM   (0x0100)
-#define _MM_MASK_DIV_ZERO (0x0200)
-#define _MM_MASK_OVERFLOW (0x0400)
-#define _MM_MASK_UNDERFLOW(0x0800)
-#define _MM_MASK_INEXACT  (0x1000)
-#define _MM_MASK_MASK (0x1f80)
-
-#define _MM_ROUND_NEAREST (0x)
-#define _MM_ROUND_DOWN(0x2000)
-#define _MM_ROUND_UP  (0x4000)
-#define _MM_ROUND_TOWARD_ZERO (0x6000)
-#define _MM_ROUND_MASK(0x6000)
-
-#define _MM_FLUSH_ZERO_MASK   (0x8000)
-#define _MM_FLUSH_ZERO_ON (0x8000)
-#define _MM_FLUSH_ZERO_OFF(0x)
+#define _MM_EXCEPT_INVALID(0x0001U)
+#define _MM_EXCEPT_DENORM (0x0002U)
+#define _MM_EXCEPT_DIV_ZERO   (0x0004U)
+#define _MM_EXCEPT_OVERFLOW   (0x0008U)
+#define _MM_EXCEPT_UNDERFLOW  (0x0010U)
+#define _MM_EXCEPT_INEXACT(0x0020U)
+#define _MM_EXCEPT_MASK   (0x003fU)
+
+#define _MM_MASK_INVALID  (0x0080U)
+#define _MM_MASK_DENORM   (0x0100U)
+#define _MM_MASK_DIV_ZERO (0x0200U)
+#define _MM_MASK_OVERFLOW (0x0400U)
+#define _MM_MASK_UNDERFLOW(0x0800U)
+#define _MM_MASK_INEXACT  (0x1000U)
+#define _MM_MASK_MASK (0x1f80U)
+
+#define _MM_ROUND_NEAREST (0xU)
+#define _MM_ROUND_DOWN(0x2000U)
+#define _MM_ROUND_UP  (0x4000U)
+#define _MM_ROUND_TOWARD_ZERO (0x6000U)
+#define _MM_ROUND_MASK(0x6000U)
+
+#define _MM_FLUSH_ZERO_MASK   (0x8000U)
+#define _MM_FLUSH_ZERO_ON (0x8000U)
+#define _MM_FLUSH_ZERO_OFF(0xU)
 
 #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
 #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)
Index: clang/lib/Headers/emmintrin.h
===
--- clang/lib/Headers/emmintrin.h
+++ clang/lib/Headers/emmintrin.h
@@ -4970,10 +4970,10 @@
 
 #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
 
-#define _MM_DENORMALS_ZERO_ON   (0x0040)
-#define _MM_DENORMALS_ZERO_OFF  (0x)
+#define _MM_DENORMALS_ZERO_ON   (0x0040U)
+#define _MM_DENORMALS_ZERO_OFF  (0xU)
 
-#define _MM_DENORMALS_ZERO_MASK (0x0040)
+#de

[PATCH] D77393: [X86] Fix implicit sign conversion warnings in X86 headers.

2020-04-07 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau reopened this revision.
pgousseau added a comment.
This revision is now accepted and ready to land.

Reopening to fix false negative test.


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

https://reviews.llvm.org/D77393



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


[PATCH] D76768: [analyzer] Added support of scan-build and exploded-graph-rewriter regression tests for Windows

2020-04-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D76768#1966813 , @thakis wrote:

> This seems to break tests on Windows: http://45.33.8.238/win/12320/step_7.txt


Thank you! Reverted.




Comment at: clang/test/Analysis/scan-build/exclude_directories.test:1-2
-// FIXME: Actually, "perl".
-REQUIRES: shell
-

ASDenysPetrov wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Well, let's hope this actually works :)
> > +1 beware.
> As I figured out this might protect us from crashes (from lit.config.cfg):
> 
> ```
> use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
> config.test_format = lit.formats.ShTest(use_lit_shell == "0")
> ```
Ok, so i only reverted the part where `REQUIRES: shell` is removed 
(rGcfd388d344ab) because that's when the buildbot problems started. The part 
that removes `UNSUPPORTED: system-windows` (rG2ddd3325c4d7) is still in. So i 
guess `REQUIRES: shell` can't be //entirely// removed. The error doesn't look 
like it's about not being able to run scan-build though; scan-build started 
just fine and produced some output. So it's likely a smaller bug.

@ASDenysPetrov any immediate thoughts? Do tests actually run on your machine 
when `REQUIRES: shell` is still in? I.e., do we get at least some testing on 
user's machines on the current trunk after my latest revert?

Here's a snapshot of the failure:
```lines=20
ninja: Entering directory `out/gn'
[0/2] ACTION //clang/test:check-clang(//llvm/utils/gn/build/toolchain:win)
llvm-lit.py: C:/src/llvm-project/llvm\utils\lit\lit\llvm\config.py:343: note: 
using clang: c:\src\llvm-project\out\gn\bin\clang.exe
-- Testing: 17064 tests, 32 workers --
Testing:  0
FAIL: Clang :: Analysis/scan-build/html_output.test (974 of 17064)
 TEST 'Clang :: Analysis/scan-build/html_output.test' 
FAILED 
Script:
--
: 'RUN: at line 1';   rm -rf 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir
 && mkdir 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir
: 'RUN: at line 2';   
'c:\src\llvm-project\clang\tools\scan-build\bin\scan-build.bat' 
--use-analyzer=c:\src\llvm-project\out\gn\bin\clang.exe  -o 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir
 c:\src\llvm-project\out\gn\bin\clang.exe -S 
C:\src\llvm-project\clang\test\Analysis\scan-build/Inputs/single_null_dereference.c
  | c:\src\llvm-project\out\gn\bin\filecheck.exe 
C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test 
-check-prefix CHECK-STDOUT
: 'RUN: at line 12';   ls 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir/*/
 | c:\src\llvm-project\out\gn\bin\filecheck.exe 
C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test 
-check-prefix CHECK-FILENAMES
: 'RUN: at line 21';   cat 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir/*/index.html
  | c:\src\llvm-project\out\gn\bin\filecheck.exe 
C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test 
-check-prefix CHECK-INDEX-HTML
: 'RUN: at line 27';   cat 
C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir/*/report-*.html
  | c:\src\llvm-project\out\gn\bin\filecheck.exe 
C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test 
-check-prefix CHECK-REPORT-HTML
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "rm" "-rf" 
"C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir"
$ "mkdir" 
"C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir"
$ ":" "RUN: at line 2"
$ "c:\src\llvm-project\clang\tools\scan-build\bin\scan-build.bat" 
"--use-analyzer=c:\src\llvm-project\out\gn\bin\clang.exe" "-o" 
"C:\src\llvm-project\out\gn\obj\clang\test\Analysis\scan-build\Output\html_output.test.tmp.output_dir"
 "c:\src\llvm-project\out\gn\bin\clang.exe" "-S" 
"C:\src\llvm-project\clang\test\Analysis\scan-build/Inputs/single_null_dereference.c"
$ "c:\src\llvm-project\out\gn\bin\filecheck.exe" 
"C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test" 
"-check-prefix" "CHECK-STDOUT"
# command stderr:
C:\src\llvm-project\clang\test\Analysis\scan-build\html_output.test:8:15: 
error: CHECK-STDOUT: expected string not found in input
CHECK-STDOUT: scan-build: 1 bug found.
  ^
:4:1: note: scanning from here
scan-build: Removing directory 
'/c/src/llvm-project/out/gn/obj/clang/test/Analysis/scan-build/Output/html_output.test.tmp.output_dir/2020-04-07-090114-54704-1'
 because it contains no reports.
^
:5:1: note: possible intended match here
scan-build: No bugs found.
^

error: command failed with exit status: 1

--


Testing:  0
FAIL: Clang :: Analysis/scan-build/plist_html_out

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

2020-04-07 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D77229#1966711 , 
@baloghadamsoftware wrote:

> Any idea for `LazyCompoundVal` parameters of functions not inlined?


OK, I can reach them from the `ConstructionContext` of the arguments. However, 
they are temporaries and for some strange reason not alive which means that 
`checkDeadSymbols()` removes the iterator positions associated to them before 
the `postCall()` of the call itself. How to correctly prolong their lives until 
the end of the `postCall()`?


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] D76238: [SveEmitter] Implement builtins for contiguous loads/stores

2020-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
Andrzej added inline comments.



Comment at: clang/include/clang/Basic/arm_sve.td:186
+def SVLDFF1   : MInst<"svldff1[_{2}]", "dPc", "csilUcUsUiUlhfd", [IsLoad], 
  MemEltTyDefault, "aarch64_sve_ldff1">;
+def SVLDFF1SB : MInst<"svldff1sb_{d}", "dPS", "silUsUiUl",   [IsLoad], 
  MemEltTyInt8,"aarch64_sve_ldff1">;
+def SVLDFF1UB : MInst<"svldff1ub_{d}", "dPW", "silUsUiUl",   [IsLoad, 
IsZExtReturn], MemEltTyInt8,"aarch64_sve_ldff1">;

Tests for `ldff1sb` seem to be missing.


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

https://reviews.llvm.org/D76238



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


[PATCH] D76605: [analyzer] Display the checker name in the text output

2020-04-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 255668.
Szelethus marked 8 inline comments as done.
Szelethus added a comment.

Fixing according to the reviews!


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

https://reviews.llvm.org/D76605

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/dispatch-once.m
  clang/test/Analysis/explain-svals.c
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/explain-svals.m
  clang/test/Analysis/incorrect-checker-names.cpp
  clang/test/Analysis/incorrect-checker-names.mm

Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- /dev/null
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -0,0 +1,116 @@
+// RUN: %clang_analyze_cc1 -fblocks -verify %s -Wno-objc-root-class \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=nullability \
+// RUN:   -analyzer-checker=osx
+
+#include "Inputs/system-header-simulator-for-nullability.h"
+#include "os_object_base.h"
+
+struct OSIterator : public OSObject {
+  static const OSMetaClass * const metaClass;
+};
+
+@interface TestObject : NSObject
+- (int *_Nonnull)returnsNonnull;
+- (int *_Nullable)returnsNullable;
+- (int *)returnsUnspecified;
+- (void)takesNonnull:(int *_Nonnull)p;
+- (void)takesNullable:(int *_Nullable)p;
+- (void)takesUnspecified:(int *)p;
+@property(readonly, strong) NSString *stuff;
+@end
+
+TestObject * getUnspecifiedTestObject();
+TestObject *_Nonnull getNonnullTestObject();
+TestObject *_Nullable getNullableTestObject();
+
+int getRandom();
+
+typedef struct Dummy { int val; } Dummy;
+
+void takesNullable(Dummy *_Nullable);
+void takesNonnull(Dummy *_Nonnull);
+void takesUnspecified(Dummy *);
+
+Dummy *_Nullable returnsNullable();
+Dummy *_Nonnull returnsNonnull();
+Dummy *returnsUnspecified();
+int *_Nullable returnsNullableInt();
+
+template  T *eraseNullab(T *p) { return p; }
+
+void takesAttrNonnull(Dummy *p) __attribute((nonnull(1)));
+
+void testBasicRules() {
+  // FIXME: None of these should be tied to a modeling checker.
+  Dummy *p = returnsNullable();
+  int *ptr = returnsNullableInt();
+  // Make every dereference a different path to avoid sinks after errors.
+  switch (getRandom()) {
+  case 0: {
+Dummy &r = *p; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 1: {
+int b = p->val; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 2: {
+int stuff = *ptr; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 3:
+takesNonnull(p); // expected-warning {{Nullable pointer is passed to a callee that requires a non-null 1st parameter [nullability.NullabilityBase]}}
+break;
+  case 4: {
+Dummy d;
+takesNullable(&d);
+Dummy dd(d);
+break;
+  }
+  case 5: takesAttrNonnull(p); break; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null [nullability.NullabilityBase]}}
+  default: { Dummy d = *p; } break; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  }
+  if (p) {
+takesNonnull(p);
+if (getRandom()) {
+  Dummy &r = *p;
+} else {
+  int b = p->val;
+}
+  }
+  Dummy *q = 0;
+  if (getRandom()) {
+takesNullable(q);
+  // FIXME: This shouldn't be tied to a modeling checker.
+takesNonnull(q); // expected-warning {{Null passed to a callee that requires a non-null 1st parameter [nullability.NullabilityBase]}}
+  }
+  Dummy a;
+  Dummy *_Nonnull nonnull = &a;
+  // FIXME: This shouldn't be tied to a modeling checker.
+  nonnull = q; // expected-warning {{Null assigned to a pointer which is expected to have non-null value [nullability.NullabilityBase]}}
+  q = &a;
+  takesNullable(q);
+  takesNonnull(q);
+}
+
+typedef int NSInteger;
+typedef struct _NSZone NSZone;
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+@class NSDictionary;
+@interface NSError : NSObject  {}
++ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
+@end
+
+struct __CFError {};
+typedef struct __CFError* CFErrorRef;
+
+void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
+  // FIXME: This shouldn't be tied to a modeling checker.
+  *error = 0;  // expected-warning {{Potential null dereference.  According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.NSOrCFErrorDerefChecker]}}
+}
+
+bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
+
+void use_out_param_leak() {
+  OSObject *obj;
+  // FIXME: This shouldn't be tied to a modeling chec

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

2020-04-07 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D77229#1966885 , 
@baloghadamsoftware wrote:

> OK, I can reach them from the `ConstructionContext` of the arguments. 
> However, they are temporaries and for some strange reason not alive which 
> means that `checkDeadSymbols()` removes the iterator positions associated to 
> them before the `postCall()` of the call itself. How to correctly prolong 
> their lives until the end of the `postCall()`?


Not so strange, of course, they are destructed before the `postCall()` as they 
should be, but the question still remains: how to keep them alive for 
post-checking the call, but not forever.


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] D76605: [analyzer] Display the checker name in the text output

2020-04-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp:112
 reportPiece(NoteID, Piece->getLocation().asLocation(),
-Piece->getString(), Piece->getRanges(), 
Piece->getFixits());
+Piece->getString().str(), Piece->getRanges(),
+Piece->getFixits());

Szelethus wrote:
> NoQ wrote:
> > Szelethus wrote:
> > > martong wrote:
> > > > Why the `.str()` ?
> > > `StringRef` no longer converts to `std::string` implicitly.
> > But it seems to have been fine before(?)
> Mind that I changed the parameter of `reportPiece` to `std::string` from 
> `StringRef`.
Couldn't see the forest behind the trees :^)


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

https://reviews.llvm.org/D76605



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


[PATCH] D76768: [analyzer] Added support of scan-build and exploded-graph-rewriter regression tests for Windows

2020-04-07 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ 
Yes, I have some thoughts. I am on revision master from [02.04.2020 10:29:20] 
(5 days ago). I've check these test and all passes on my PC.

As you can see in the log :

  scan-build: Removing directory 
'/c/src/llvm-project/out/gn/obj/clang/test/Analysis/scan-build/Output/plist_html_output.test.tmp.output_dir/2020-04-07-090114-54706-1'
 because it contains no reports.
  ^
  :7:1: note: possible intended match here
  scan-build: No bugs found.

That means that **Inputs/single_null_dereference.c** is somewhat differs from 
mine or clang behavior was changed since my revision.

> Do tests actually run on your machine when REQUIRES: shell is still in?

No they don't. They are marked as unsuported if **REQUIRES: shell** is in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76768



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


[PATCH] D77440: [Hexagon] Update include paths for linux/musl

2020-04-07 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77440



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


[PATCH] D77583: [hip] Remove `hip_pinned_shadow`.

2020-04-07 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc97be2c37785: [hip] Remove `hip_pinned_shadow`. (authored by 
hliao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77583

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/ast-dump-hip-pinned-shadow.cu
  clang/test/Driver/hip-toolchain-no-rdc.hip
  clang/test/Driver/hip-toolchain-rdc.hip
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/hip-pinned-shadow.cu

Index: clang/test/SemaCUDA/hip-pinned-shadow.cu
===
--- clang/test/SemaCUDA/hip-pinned-shadow.cu
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility hidden -fapply-global-visibility-to-externs \
-// RUN: -emit-llvm -o - -x hip %s -fsyntax-only -verify
-// RUN: %clang_cc1 -triple x86_64 -std=c++11 \
-// RUN: -emit-llvm -o - -x hip %s -fsyntax-only -verify
-
-#define __device__ __attribute__((device))
-#define __constant__ __attribute__((constant))
-#define __hip_pinned_shadow__ __attribute((hip_pinned_shadow))
-
-struct textureReference {
-  int a;
-};
-
-template 
-struct texture : public textureReference {
-texture() { a = 1; }
-};
-
-__hip_pinned_shadow__ texture tex;
-__device__ __hip_pinned_shadow__ texture tex2; // expected-error{{'hip_pinned_shadow' and 'device' attributes are not compatible}}
-// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables}}
-// expected-note@-2{{conflicting attribute is here}}
-__constant__ __hip_pinned_shadow__ texture tex3; // expected-error{{'hip_pinned_shadow' and 'constant' attributes are not compatible}}
-  // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables}}
-  // expected-note@-2{{conflicting attribute is here}}
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
@@ -61,7 +61,6 @@
 // CHECK-NEXT: FlagEnum (SubjectMatchRule_enum)
 // CHECK-NEXT: Flatten (SubjectMatchRule_function)
 // CHECK-NEXT: GNUInline (SubjectMatchRule_function)
-// CHECK-NEXT: HIPPinnedShadow (SubjectMatchRule_variable)
 // CHECK-NEXT: Hot (SubjectMatchRule_function)
 // CHECK-NEXT: IBAction (SubjectMatchRule_objc_method_is_instance)
 // CHECK-NEXT: IFunc (SubjectMatchRule_function)
Index: clang/test/Driver/hip-toolchain-rdc.hip
===
--- clang/test/Driver/hip-toolchain-rdc.hip
+++ clang/test/Driver/hip-toolchain-rdc.hip
@@ -44,7 +44,7 @@
 // CHECK-SAME: "-filetype=obj"
 // CHECK-SAME: "-o" [[OBJ_DEV1:".*-gfx803-.*o"]]
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV1:.*out]]" [[OBJ_DEV1]]
 
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
@@ -77,7 +77,7 @@
 // CHECK-SAME: "-filetype=obj"
 // CHECK-SAME: "-o" [[OBJ_DEV2:".*-gfx900-.*o"]]
 
-// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV2:.*out]]" [[OBJ_DEV2]]
 
 // CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -38,7 +38,7 @@
 // CHECK-SAME: "-filetype=obj"
 // CHECK-SAME: "-o" [[OBJ_DEV_A_803:".*-gfx803-.*o"]]
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 //
@@ -67,7 +67,7 @@
 // CHECK-SAME: "-filetype=obj"
 // CHECK-SAME: "-o" [[OBJ_DEV_A_900:".*-gfx900-.*o"]]
 
-// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 //
@@ -112,7 +112,7 @@
 // CHECK-SAME: "-filetype=obj"
 // CHECK-SAME: "-o" [[OBJ_DEV_B_803:".*-gfx803-.*o"]]
 
-// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
+// CHECK: 

[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2020-04-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/Format.cpp:2700
+  if (std::error_code EC = Text.getError())
+return make_string_error(EC.message());
+  std::error_code ParserErrorCode =

if you return here IsSuitable will be true..



Comment at: clang/lib/Format/Format.cpp:2707
+  } else if (ParserErrorCode != ParseError::Success) {
+return make_string_error("Error reading " + ConfigFile + ": " +
+ ParserErrorCode.message());

again here you need to set IsSutable to false



Comment at: clang/lib/Format/Format.cpp:2709
+ ParserErrorCode.message());
+  }
+  return Style;

maybe its better just to set this to true here *IsSuitable = true; and set it 
to false on line @2695



Comment at: clang/lib/Format/Format.cpp:2792
+  } else {
+return *ConfigStyle;
   }

this could then mean you return with something wrong here..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72326



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


[PATCH] D73290: [PowerPC] Add clang -msvr4-struct-return for 32-bit ELF

2020-04-07 Thread Justin Hibbits via Phabricator via cfe-commits
jhibbits added a reviewer: nemanjai.
jhibbits added a comment.

@ZarkoCA I think someone else should also review this, so added @nemanjai as a 
potential reviewer.  He might have more insight to the code in question.  I'd 
like to see this go in soon, though, so that it gets into 11, and we can use it 
in FreeBSD.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73290



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


[PATCH] D76768: [analyzer] Added support of scan-build and exploded-graph-rewriter regression tests for Windows

2020-04-07 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ 
I've just pulled all from github and make a build. Then I ran the tests, and 
they successfully passed. 
Namely, **scan-build** analyzed inputs and create //stdout //with diagnostics. 
Then **filecheck **checked without fails. But in case of **buildbot **it didn't 
create any diagnostic //stdout//.

According to buildbot's logs I assume that smth is wrong on its side.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76768



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


[PATCH] D75044: [AArch64] __builtin_extract_return_addr for PAuth.

2020-04-07 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

Needs a test in `clang/test` that `__builtin_extract_return_address` is 
translated to `llvm.extractreturnaddress`.

What if LLVM IR contains a call to `llvm.extractreturnaddress`, but the target 
is not AArch64?




Comment at: llvm/include/llvm/CodeGen/ISDOpcodes.h:74
 /// the parent's frame or return address, and so on.
-FRAMEADDR, RETURNADDR, ADDROFRETURNADDR, SPONENTRY,
+FRAMEADDR, RETURNADDR, ADDROFRETURNADDR, EXTRACTRETURNADDR, SPONENTRY,
 

Needs a comment about `EXTRACTRETURNADDR`. And also a slightly different 
grouping, so the non-commented/undocumented things stand out.


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

https://reviews.llvm.org/D75044



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


[PATCH] D75044: [AArch64] __builtin_extract_return_addr for PAuth.

2020-04-07 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

In D75044#1966997 , @chill wrote:

> Needs a test in `clang/test` that `__builtin_extract_return_address` is 
> translated to `llvm.extractreturnaddress`.


Nevermind, I'm blind.


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

https://reviews.llvm.org/D75044



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


[PATCH] D77632: [TLI] Per-function fveclib for math library used for vectorization

2020-04-07 Thread Wenlei He via Phabricator via cfe-commits
wenlei updated this revision to Diff 255679.
wenlei added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77632

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/libcalls-veclib.c
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp

Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1528,8 +1528,29 @@
   llvm::sort(ScalarDescs, compareByVectorFnName);
 }
 
+void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
+const StringRef &VecLibName) {
+  VectorLibrary VecLib = NoLibrary;
+  if (VecLibName == "Accelerate")
+VecLib = Accelerate;
+  else if (VecLibName == "MASSV")
+VecLib = MASSV;
+  else if (VecLibName == "SVML")
+VecLib = SVML;
+  else
+return;
+  addVectorizableFunctionsFromVecLib(VecLib);
+}
+
 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
 enum VectorLibrary VecLib) {
+  if (VectLibrary != NoLibrary) {
+assert(VectLibrary == VecLib && 
+   "Conflicting VectorLibrary detected");
+return;
+  }
+
+  VectLibrary = VecLib;
   switch (VecLib) {
   case Accelerate: {
 const VecDesc VecFuncs[] = {
@@ -1604,6 +1625,11 @@
   if (!BaselineInfoImpl)
 BaselineInfoImpl =
 TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+
+  StringRef VectLibName = F.getFnAttribute("vect-lib").getValueAsString();
+  if (!VectLibName.empty())
+BaselineInfoImpl->addVectorizableFunctionsFromVecLib(VectLibName);
+
   return TargetLibraryInfo(*BaselineInfoImpl, &F);
 }
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -48,6 +48,22 @@
 class TargetLibraryInfoImpl {
   friend class TargetLibraryInfo;
 
+public:
+  /// List of known vector-functions libraries.
+  ///
+  /// The vector-functions library defines, which functions are vectorizable
+  /// and with which factor. The library can be specified by either frontend,
+  /// or a commandline option, and then used by
+  /// addVectorizableFunctionsFromVecLib for filling up the tables of
+  /// vectorizable functions.
+  enum VectorLibrary {
+NoLibrary,  // Don't use any vector library.
+Accelerate, // Use Accelerate framework.
+MASSV,  // IBM MASS vector library.
+SVML// Intel short vector math library.
+  };
+
+private:
   unsigned char AvailableArray[(NumLibFuncs+3)/4];
   llvm::DenseMap CustomNames;
   static StringLiteral const StandardNames[NumLibFuncs];
@@ -71,6 +87,8 @@
   /// Scalarization descriptors - same content as VectorDescs but sorted based
   /// on VectorFnName rather than ScalarFnName.
   std::vector ScalarDescs;
+  /// Vector library available for vectorization.
+  VectorLibrary VectLibrary = NoLibrary;
 
   /// Return true if the function type FTy is valid for the library function
   /// F, regardless of whether the function is available.
@@ -78,20 +96,6 @@
   const DataLayout *DL) const;
 
 public:
-  /// List of known vector-functions libraries.
-  ///
-  /// The vector-functions library defines, which functions are vectorizable
-  /// and with which factor. The library can be specified by either frontend,
-  /// or a commandline option, and then used by
-  /// addVectorizableFunctionsFromVecLib for filling up the tables of
-  /// vectorizable functions.
-  enum VectorLibrary {
-NoLibrary,  // Don't use any vector library.
-Accelerate, // Use Accelerate framework.
-MASSV,  // IBM MASS vector library.
-SVML// Intel short vector math library.
-  };
-
   TargetLibraryInfoImpl();
   explicit TargetLibraryInfoImpl(const Triple &T);
 
@@ -148,6 +152,7 @@
   /// Calls addVectorizableFunctions with a known preset of functions for the
   /// given vector library.
   void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib);
+  void addVectorizableFunctionsFromVecLib(const StringRef &VecLibName);
 
   /// Return true if the function F has a vector equivalent with vectorization
   /// factor VF.
@@ -261,18 +266,20 @@
   }
 
   /// Determine whether a callee with the given TLI can be inlined into
-  /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
-  /// allow inlining into a caller with a superset of the callee's nobuiltin
-  /// attributes, which is conservatively correct.
+  /// caller with this TLI, based on 'nobuiltin', `vect-lib` attributes.
+  /// When requested, allow inlining into a caller with a superset of the
+  /// callee's attributes, which is conservatively correct.
   bool areInlineCompatible(const TargetLibraryInfo &CalleeTLI,
bool 

[PATCH] D77440: [Hexagon] Update include paths for linux/musl

2020-04-07 Thread Sid Manning via Phabricator via cfe-commits
sidneym updated this revision to Diff 255680.
sidneym added a comment.

Fix formatting issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77440

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hexagon.h
  
clang/test/Driver/Inputs/hexagon_tree/Tools/target/hexagon/include/c++/v1/readme
  clang/test/Driver/hexagon-toolchain-elf.c
  clang/test/Driver/hexagon-toolchain-linux.c

Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- /dev/null
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -0,0 +1,101 @@
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK000 %s
+// CHECK000-NOT:  {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
+// CHECK000:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK000:  "{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK000:  "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK001 %s
+// CHECK001-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK001:"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o"
+// CHECK001:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK001-NOT:{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK002 %s
+// CHECK002:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK002-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
+// CHECK002-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// CHECK002-NOT:   -lclang_rt.builtins-hexagon
+// CHECK002-NOT:   -lc
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK003 %s
+// CHECK003:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK003-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}Scrt1.o
+// CHECK003-NOT:   {{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
+// CHECK003:   "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK004 %s
+// CHECK004:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK004:   "{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK004-NOT:   -lclang_rt.builtins-hexagon
+// CHECK004-NOT:   -lc
+// -
+// Not Passing -fno-use-init-array when musl is selected
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/he

  1   2   3   >