Re: r333333 - Test commit; please ignore.

2018-05-25 Thread George Burgess IV via cfe-commits
Thanks. :)

On Fri, May 25, 2018, 7:56 PM Richard Smith  wrote:

> Congratulations?
>
> On Fri, 25 May 2018, 19:33 George Burgess IV via cfe-commits, <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: gbiv
>> Date: Fri May 25 19:29:14 2018
>> New Revision: 33
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=33=rev
>> Log:
>> Test commit; please ignore.
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaAttr.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=33=32=33=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri May 25 19:29:14 2018
>> @@ -330,7 +330,7 @@ void Sema::PragmaStack::Act(S
>>  Stack.erase(std::prev(I.base()), Stack.end());
>>}
>>  } else if (!Stack.empty()) {
>> -  // We don't have a label, just pop the last entry.
>> +  // We do not have a label, just pop the last entry.
>>CurrentValue = Stack.back().Value;
>>CurrentPragmaLocation = Stack.back().PragmaLocation;
>>Stack.pop_back();
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r333333 - Test commit; please ignore.

2018-05-25 Thread Richard Smith via cfe-commits
Congratulations?

On Fri, 25 May 2018, 19:33 George Burgess IV via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> Author: gbiv
> Date: Fri May 25 19:29:14 2018
> New Revision: 33
>
> URL: http://llvm.org/viewvc/llvm-project?rev=33=rev
> Log:
> Test commit; please ignore.
>
> Modified:
> cfe/trunk/lib/Sema/SemaAttr.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=33=32=33=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri May 25 19:29:14 2018
> @@ -330,7 +330,7 @@ void Sema::PragmaStack::Act(S
>  Stack.erase(std::prev(I.base()), Stack.end());
>}
>  } else if (!Stack.empty()) {
> -  // We don't have a label, just pop the last entry.
> +  // We do not have a label, just pop the last entry.
>CurrentValue = Stack.back().Value;
>CurrentPragmaLocation = Stack.back().PragmaLocation;
>Stack.pop_back();
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r333333 - Test commit; please ignore.

2018-05-25 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Fri May 25 19:29:14 2018
New Revision: 33

URL: http://llvm.org/viewvc/llvm-project?rev=33=rev
Log:
Test commit; please ignore.

Modified:
cfe/trunk/lib/Sema/SemaAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=33=32=33=diff
==
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri May 25 19:29:14 2018
@@ -330,7 +330,7 @@ void Sema::PragmaStack::Act(S
 Stack.erase(std::prev(I.base()), Stack.end());
   }
 } else if (!Stack.empty()) {
-  // We don't have a label, just pop the last entry.
+  // We do not have a label, just pop the last entry.
   CurrentValue = Stack.back().Value;
   CurrentPragmaLocation = Stack.back().PragmaLocation;
   Stack.pop_back();


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


[PATCH] D47341: [Sema] Disable creating new delayed typos while correcting existing.

2018-05-25 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai planned changes to this revision.
vsapsai added a comment.

After looking into this more, I think there are 2 different bugs: one with 
infinite loop and another with `DelayedTypos.empty() && "Uncorrected typos!"` 
assertion. And disabling typo correction happened to fix both of them.

Infinite loop seems to be avoidable by not using ~0U as the guard value, need 
to investigate further.

And uncorrected dangling delayed typo bug has a different cause. When we are 
checking potential corrections, we have roughly the following behaviour

  1. structVarTypo -> structVar; structVarTypo2 -> structVar;
   after correction discover more typos
   fieldNameTypo -> fieldName; fieldNameTypo2 -> fieldName;  // Overall 
correction fails but newly discovered typos are processed and removed.
  
  2. structVarTypo -> ; structVarTypo2 -> structVar;
   correction fails early, don't discover more typos
  
  3. structVarTypo -> structVar; structVarTypo2 -> ;
   correction fails but we discover fieldNameTypo and the way correction 
fails we don't attempt to correct this new delayed typo
  
  4. structVarTypo -> ; structVarTypo2 -> ;
   correction fails early, don't discover more typos

So the typo from step 3 is the one that remains till ~Sema.

I've spent some time looking into Richard's suggestion to correct typos 
immediately. That gets more involved than I expected and I want to finish 
investigating my other ideas. Now I think that my original approach with 
disabling typo correction just hides the issue instead of fixing it. And I feel 
like immediate typo correction can be hiding the actual issue too but it is too 
early to say.


https://reviews.llvm.org/D47341



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


[PATCH] D47405: [analyzer] Re-enable C++17-specific return value constructors.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: test/Analysis/cxx17-mandatory-elision.cpp:185-191
+// Check if the last destructor is an automatic destructor.
+// A temporary destructor would have fired by now.
+#if __cplusplus >= 201703L
+clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+#else
+clang_analyzer_eval(v.len == 3); // expected-warning{{TRUE}}
+#endif

This sounded like a good thing to check, so i added such checks in a few more 
places.


Repository:
  rC Clang

https://reviews.llvm.org/D47405



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


[PATCH] D47405: [analyzer] Re-enable C++17-specific return value constructors.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, 
rnkovacs.
Herald added subscribers: cfe-commits, baloghadamsoftware.

The refactoring conducted in https://reviews.llvm.org/D47304 made it easy for 
the analyzer to find the target region for the constructor across multiple 
stack frames. We ascend to the parent stack frame recursively until we find a 
construction context that doesn't represent yet another return value of a 
function. This is the semantics of copy elision in return statements that 
return the object by value: they return it directly to a memory region (eg., a 
variable) that may be located a few (indefinitely many) stack frames above the 
statement. In particular, this is how return statements work in C++17 where 
copy elision is mandatory. This commit enables this feature for the AST of 
C++17, but extra work is necessary to perform copy elision in the AST produced 
by older language standard modes.


Repository:
  rC Clang

https://reviews.llvm.org/D47405

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cxx17-mandatory-elision.cpp

Index: test/Analysis/cxx17-mandatory-elision.cpp
===
--- test/Analysis/cxx17-mandatory-elision.cpp
+++ test/Analysis/cxx17-mandatory-elision.cpp
@@ -150,9 +150,8 @@
   ClassWithoutDestructor c = make3(v);
 
 #if __cplusplus >= 201703L
-  // FIXME: Both should be TRUE.
   clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
-  clang_analyzer_eval(v.buf[0] == ); // expected-warning{{FALSE}}
+  clang_analyzer_eval(v.buf[0] == ); // expected-warning{{TRUE}}
 #else
   clang_analyzer_eval(v.len == 5); // expected-warning{{TRUE}}
   clang_analyzer_eval(v.buf[0] != v.buf[1]); // expected-warning{{TRUE}}
@@ -183,6 +182,13 @@
   AddressVector v;
   {
 ClassWithDestructor c = ClassWithDestructor(v);
+// Check if the last destructor is an automatic destructor.
+// A temporary destructor would have fired by now.
+#if __cplusplus >= 201703L
+clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+#else
+clang_analyzer_eval(v.len == 3); // expected-warning{{TRUE}}
+#endif
   }
 #if __cplusplus >= 201703L
   // 0. Construct the variable.
@@ -210,6 +216,13 @@
   AddressVector v;
   {
 TestCtorInitializer t(v);
+// Check if the last destructor is an automatic destructor.
+// A temporary destructor would have fired by now.
+#if __cplusplus >= 201703L
+clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+#else
+clang_analyzer_eval(v.len == 3); // expected-warning{{TRUE}}
+#endif
   }
 #if __cplusplus >= 201703L
   // 0. Construct the member variable.
@@ -227,4 +240,53 @@
 #endif
 }
 
+
+ClassWithDestructor make1(AddressVector ) {
+  return ClassWithDestructor(v);
+}
+ClassWithDestructor make2(AddressVector ) {
+  return make1(v);
+}
+ClassWithDestructor make3(AddressVector ) {
+  return make2(v);
+}
+
+void testMultipleReturnsWithDestructors() {
+  AddressVector v;
+  {
+ClassWithDestructor c = make3(v);
+// Check if the last destructor is an automatic destructor.
+// A temporary destructor would have fired by now.
+#if __cplusplus >= 201703L
+clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
+#else
+clang_analyzer_eval(v.len == 9); // expected-warning{{TRUE}}
+#endif
+  }
+
+#if __cplusplus >= 201703L
+  // 0. Construct the variable. Yes, constructor in make1() constructs
+  //the variable 'c'.
+  // 1. Destroy the variable.
+  clang_analyzer_eval(v.len == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] == v.buf[1]); // expected-warning{{TRUE}}
+#else
+  // 0. Construct the temporary in make1().
+  // 1. Construct the temporary in make2().
+  // 2. Destroy the temporary in make1().
+  // 3. Construct the temporary in make3().
+  // 4. Destroy the temporary in make2().
+  // 5. Construct the temporary here.
+  // 6. Destroy the temporary in make3().
+  // 7. Construct the variable.
+  // 8. Destroy the temporary here.
+  // 9. Destroy the variable.
+  clang_analyzer_eval(v.len == 10); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[0] == v.buf[2]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[1] == v.buf[4]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[3] == v.buf[6]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[5] == v.buf[8]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(v.buf[7] == v.buf[9]); // expected-warning{{TRUE}}
+#endif
+}
 } // namespace address_vector_tests
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -180,7 +180,8 @@
   }
   break;
 }
-case ConstructionContext::SimpleReturnedValueKind: {
+case ConstructionContext::SimpleReturnedValueKind:
+case 

[PATCH] D47402: [analyzer] Improve simplifySVal performance further.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

The remaining slowness is in `removeDead()`. It's going to be fun to optimize. 
Some parts of it are already memoized (eg. the live set in `SymbolReaper`).

Memory usage on the artificial test seems stable.


Repository:
  rC Clang

https://reviews.llvm.org/D47402



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


[PATCH] D47340: [ClangDiagnostics] Silence warning about fallthrough after PrintFatalError

2018-05-25 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu accepted this revision.
rtrieu added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D47340



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


[PATCH] D47402: [analyzer] Improve simplifySVal performance further.

2018-05-25 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@NoQ we should make sure the memory is not exploding and that we don't make the 
analyzer slower in other cases. Though we could commit this, and then let CI 
figure out potential regressions.


Repository:
  rC Clang

https://reviews.llvm.org/D47402



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


[PATCH] D47299: [CodeGenCXX] Emit strip.invariant.group with -fstrict-vtable-pointers

2018-05-25 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1626-1627
+
+  // Casting to pointer that does not carry dynamic information (provided 
by
+  // invariant.group) requires stripping it.
+  Src = Builder.CreateStripInvariantGroup(Src);

rsmith wrote:
> Are there any cases where we need a barrier when the destination type is a 
> dynamic type here?
No, I don't think so. I will also add test for that.


Repository:
  rL LLVM

https://reviews.llvm.org/D47299



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/Representation.h:138
+  SymbolID USR =
+  SymbolID(); // Unique identifier for the decl described by this Info.
+  const InfoType IT = InfoType::IT_default; // InfoType of this particular 
Info.

ioeric wrote:
> Shouldn't USR be `SymbolID()` by default?
It actually is garbage by default -- doing this zeroed it out.



Comment at: clang-doc/Representation.h:146
+protected:
+  bool mergeBase(Info &);
 };

ioeric wrote:
> It's a bit awkward that users have to dispatch from info types to the 
> corresponding `merge` function (as in `Reducer.cpp`). I think it would make 
> users' life easier if the library handles the dispatching.
> 
> I wonder if something like the following would be better:
> ```
> struct Info {
> std::unique_ptr merge(const Indo& LHS, const Info& RHS);
> };
> // A standalone function.
> std::unique_ptr mergeInfo(const Info , const Info& RHS) {
>   // merge base info.
>   ...
>   // merge subclass infos.
>   assert(LHS.IT == RHS.IT); // or return nullptr
>   switch (LHS.IT) {
>... 
> return Namespace::merge(LHS, RHS);
>   } 
> }
> 
> struct NamespaceInfo : public Info {
>   std::unique_ptr merge(LHS, RHS);
> };
> 
> ```
> 
> The unhandled switch case warning in compiler would help you catch 
> unimplemented `merge` when new info types are added.
Sort of addressed in this update. There's an issue with where we allocate the 
return pointer, because we need to know the type of info at allocation time -- 
let me know if what's here now is too far off of what you were suggesting.



Comment at: clang-doc/tool/ClangDocMain.cpp:181
+doc::writeInfo(I.get(), Buffer);
+  if (DumpResultToFile("bc", Group.getKey() + ".bc", Buffer))
+return 1;

ioeric wrote:
> (Sorry that I might be missing context here.)
> 
> Could you please explain the incentive for dumping each info group to one bc 
> file? If the key identifies a symbol (e.g. USR), wouldn't this result in a 
> bitcode file being created for each symbol? This doesn't seem very scalable.  
Yes, it would. This is mostly for debugging, since there's not really any tools 
outside the clang system that would actually want/be able to use this 
information.


https://reviews.llvm.org/D43341



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


[PATCH] D47402: [analyzer] Improve simplifySVal performance further.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, 
rnkovacs.
Herald added subscribers: cfe-commits, baloghadamsoftware.

Memoize `SValBuilder::simplifySVal()` so that it didn't try to re-simplify the 
same symbolic expression in the same program state.

Speeds up the analysis by ~25% on the artificial test in 
`test/Analysis/hangs.c`.


Repository:
  rC Clang

https://reviews.llvm.org/D47402

Files:
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1222,6 +1222,12 @@
 ProgramStateRef State;
 SValBuilder 
 
+// Cache results for the lifetime of the Simplifier. Results change every
+// time new constraints are added to the program state, which is the whole
+// point of simplifying, and for that very reason it's pointless to 
maintain
+// the same cache for the duration of the whole analysis.
+llvm::DenseMap Cached;
+
 static bool isUnchanged(SymbolRef Sym, SVal Val) {
   return Sym == Val.getAsSymbol();
 }
@@ -1242,9 +1248,16 @@
 // start producing them.
 
 SVal VisitSymIntExpr(const SymIntExpr *S) {
+  auto I = Cached.find(S);
+  if (I != Cached.end())
+return I->second;
+
   SVal LHS = Visit(S->getLHS());
-  if (isUnchanged(S->getLHS(), LHS))
-return SVB.makeSymbolVal(S);
+  if (isUnchanged(S->getLHS(), LHS)) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;
+return V;
+  }
   SVal RHS;
   // By looking at the APSInt in the right-hand side of S, we cannot
   // figure out if it should be treated as a Loc or as a NonLoc.
@@ -1263,15 +1276,27 @@
   } else {
 RHS = SVB.makeIntVal(S->getRHS());
   }
-  return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+
+  SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+  Cached[S] = V;
+  return V;
 }
 
 SVal VisitSymSymExpr(const SymSymExpr *S) {
+  auto I = Cached.find(S);
+  if (I != Cached.end())
+return I->second;
+
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
-  if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
-return SVB.makeSymbolVal(S);
-  return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+  if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;
+return V;
+  }
+  SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+  Cached[S] = V;
+  return V;
 }
 
 SVal VisitSymExpr(SymbolRef S) { return nonloc::SymbolVal(S); }


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1222,6 +1222,12 @@
 ProgramStateRef State;
 SValBuilder 
 
+// Cache results for the lifetime of the Simplifier. Results change every
+// time new constraints are added to the program state, which is the whole
+// point of simplifying, and for that very reason it's pointless to maintain
+// the same cache for the duration of the whole analysis.
+llvm::DenseMap Cached;
+
 static bool isUnchanged(SymbolRef Sym, SVal Val) {
   return Sym == Val.getAsSymbol();
 }
@@ -1242,9 +1248,16 @@
 // start producing them.
 
 SVal VisitSymIntExpr(const SymIntExpr *S) {
+  auto I = Cached.find(S);
+  if (I != Cached.end())
+return I->second;
+
   SVal LHS = Visit(S->getLHS());
-  if (isUnchanged(S->getLHS(), LHS))
-return SVB.makeSymbolVal(S);
+  if (isUnchanged(S->getLHS(), LHS)) {
+SVal V = SVB.makeSymbolVal(S);
+Cached[S] = V;
+return V;
+  }
   SVal RHS;
   // By looking at the APSInt in the right-hand side of S, we cannot
   // figure out if it should be treated as a Loc or as a NonLoc.
@@ -1263,15 +1276,27 @@
   } else {
 RHS = SVB.makeIntVal(S->getRHS());
   }
-  return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+
+  SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+  Cached[S] = V;
+  return V;
 }
 
 SVal VisitSymSymExpr(const SymSymExpr *S) {
+  auto I = Cached.find(S);
+  if (I != Cached.end())
+return I->second;
+
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
-  if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
-return SVB.makeSymbolVal(S);
-  return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
+ 

[libcxx] r333327 - Fix GCC handling of ATOMIC_VAR_INIT

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 17:13:53 2018
New Revision: 27

URL: http://llvm.org/viewvc/llvm-project?rev=27=rev
Log:
Fix GCC handling of ATOMIC_VAR_INIT

r25 from D47225 added warning checks, and the test was written to be C++11 
correct by using ATOMIC_VAR_INIT (note that the committee fixed that 
recently...). It seems like GCC can't handle ATOMIC_VAR_INIT well because it 
generates 'type 'std::atomic' cannot be initialized with an initializer 
list' on bot libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03. Drop the 
ATOMIC_VAR_INITs since they weren't required to test the diagnostics.

Modified:
libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp

Modified: libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp?rev=27=26=27=diff
==
--- libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp (original)
+++ libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp Fri May 25 
17:13:53 2018
@@ -17,8 +17,8 @@
 #include 
 
 int main() {
-  std::atomic ai = ATOMIC_VAR_INIT(0);
-  volatile std::atomic vai = ATOMIC_VAR_INIT(0);
+  std::atomic ai;
+  volatile std::atomic vai;
   int i = 42;
 
   atomic_is_lock_free((const volatile std::atomic*)0); // expected-error 
{{null passed to a callee that requires a non-null argument}}


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


[PATCH] D47225: Add nonnull; use it for atomics

2018-05-25 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

GCC in  libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03  seems to mis-handle 
ATOMIC_VAR_INIT:

  File 
/home/llvm-builder/llvm-buildslave-root/libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03/llvm/projects/libcxx/test/libcxx/atomics/diagnose_nonnull.fail.cpp
 Line 20: non-aggregate type 'std::atomic' cannot be initialized with an 
initializer list
  File 
/home/llvm-builder/llvm-buildslave-root/libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03/llvm/projects/libcxx/test/libcxx/atomics/diagnose_nonnull.fail.cpp
 Line 21: non-aggregate type 'volatile std::atomic' cannot be initialized 
with an initializer list

I'll drop the initialization for now, it's not required anyways.


Repository:
  rL LLVM

https://reviews.llvm.org/D47225



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


[PATCH] D41881: [analyzer] Flag bcmp, bcopy and bzero as obsolete

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Ouch, this one really got out of hand. Sorry.


Repository:
  rC Clang

https://reviews.llvm.org/D41881



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


[PATCH] D41881: [analyzer] Flag bcmp, bcopy and bzero as obsolete

2018-05-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC26: [analyzer] Add security checks for bcmp(), bcopy(), 
bzero(). (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41881

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  test/Analysis/security-syntax-checks.m
  www/analyzer/available_checks.html

Index: www/analyzer/available_checks.html
===
--- www/analyzer/available_checks.html
+++ www/analyzer/available_checks.html
@@ -1173,6 +1173,40 @@
 
 
 
+security.insecureAPI.bcmp
+(C)
+Warn on uses of the bcmp function.
+
+
+void test() {
+  bcmp(ptr0, ptr1, n); // warn
+}
+
+
+
+security.insecureAPI.bcopy
+(C)
+Warn on uses of the bcopy function.
+
+
+void test() {
+  bcopy(src, dst, n); // warn
+}
+
+
+
+security.insecureAPI.bzero
+(C)
+Warn on uses of the bzero function.
+
+
+void test() {
+  bzero(ptr, n); // warn
+}
+
+
+
+
 security.insecureAPI.getpw
 (C)
 Warn on uses of the getpw function.
Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -373,6 +373,15 @@
 //===--===//
 
 let ParentPackage = InsecureAPI in {
+  def bcmp : Checker<"bcmp">,
+HelpText<"Warn on uses of the 'bcmp' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
+  def bcopy : Checker<"bcopy">,
+HelpText<"Warn on uses of the 'bcopy' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
+  def bzero : Checker<"bzero">,
+HelpText<"Warn on uses of the 'bzero' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
   def gets : Checker<"gets">,
 HelpText<"Warn on uses of the 'gets' function">,
 DescFile<"CheckSecuritySyntaxOnly.cpp">;
Index: test/Analysis/security-syntax-checks.m
===
--- test/Analysis/security-syntax-checks.m
+++ test/Analysis/security-syntax-checks.m
@@ -37,6 +37,27 @@
   for (FooType x = 10001.0f; x <= 10010.0f; x++ ) {} // expected-warning{{Variable 'x' with floating point type 'FooType'}}
 }
 
+// Obsolete function bcmp
+int bcmp(void *, void *, size_t);
+
+int test_bcmp(void *a, void *b, size_t n) {
+  return bcmp(a, b, n); // expected-warning{{The bcmp() function is obsoleted by memcmp()}}
+}
+
+// Obsolete function bcopy
+void bcopy(void *, void *, size_t);
+
+void test_bcopy(void *a, void *b, size_t n) {
+  bcopy(a, b, n); // expected-warning{{The bcopy() function is obsoleted by memcpy() or memmove(}}
+}
+
+// Obsolete function bzero
+void bzero(void *, size_t);
+
+void test_bzero(void *a, size_t n) {
+  bzero(a, n); // expected-warning{{The bzero() function is obsoleted by memset()}}
+}
+
 //  rule request: gets() buffer overflow
 // Part of recommendation: 300-BSI (buildsecurityin.us-cert.gov)
 char* gets(char *buf);
Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -37,6 +37,9 @@
 
 namespace {
 struct ChecksFilter {
+  DefaultBool check_bcmp;
+  DefaultBool check_bcopy;
+  DefaultBool check_bzero;
   DefaultBool check_gets;
   DefaultBool check_getpw;
   DefaultBool check_mktemp;
@@ -47,6 +50,9 @@
   DefaultBool check_FloatLoopCounter;
   DefaultBool check_UncheckedReturn;
 
+  CheckName checkName_bcmp;
+  CheckName checkName_bcopy;
+  CheckName checkName_bzero;
   CheckName checkName_gets;
   CheckName checkName_getpw;
   CheckName checkName_mktemp;
@@ -89,6 +95,9 @@
 
   // Checker-specific methods.
   void checkLoopConditionForFloat(const ForStmt *FS);
+  void checkCall_bcmp(const CallExpr *CE, const FunctionDecl *FD);
+  void checkCall_bcopy(const CallExpr *CE, const FunctionDecl *FD);
+  void checkCall_bzero(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_gets(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_getpw(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_mktemp(const CallExpr *CE, const FunctionDecl *FD);
@@ -129,6 +138,9 @@
 
   // Set the evaluation function by switching on the callee name.
   FnCheck evalFunction = llvm::StringSwitch(Name)
+.Case("bcmp", ::checkCall_bcmp)
+.Case("bcopy", ::checkCall_bcopy)
+.Case("bzero", ::checkCall_bzero)
 .Case("gets", ::checkCall_gets)
 .Case("getpw", ::checkCall_getpw)
 .Case("mktemp", ::checkCall_mktemp)
@@ -296,6 +308,132 @@
 }
 
 //===--===//
+// Check: Any use of bcmp.
+// CWE-477: Use of Obsolete Functions
+// bcmp was deprecated in POSIX.1-2008

r333326 - [analyzer] Add security checks for bcmp(), bcopy(), bzero().

2018-05-25 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri May 25 17:04:26 2018
New Revision: 26

URL: http://llvm.org/viewvc/llvm-project?rev=26=rev
Log:
[analyzer] Add security checks for bcmp(), bcopy(), bzero().

These functions are obsolete. The analyzer would advice to replace them with
memcmp(), memcpy() or memmove(), or memset().

Patch by Tom Rix!

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
cfe/trunk/test/Analysis/security-syntax-checks.m
cfe/trunk/www/analyzer/available_checks.html

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=26=25=26=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Fri May 25 
17:04:26 2018
@@ -373,6 +373,15 @@ def PaddingChecker : Checker<"Padding">,
 
//===--===//
 
 let ParentPackage = InsecureAPI in {
+  def bcmp : Checker<"bcmp">,
+HelpText<"Warn on uses of the 'bcmp' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
+  def bcopy : Checker<"bcopy">,
+HelpText<"Warn on uses of the 'bcopy' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
+  def bzero : Checker<"bzero">,
+HelpText<"Warn on uses of the 'bzero' function">,
+DescFile<"CheckSecuritySyntaxOnly.cpp">;
   def gets : Checker<"gets">,
 HelpText<"Warn on uses of the 'gets' function">,
 DescFile<"CheckSecuritySyntaxOnly.cpp">;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=26=25=26=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp Fri May 
25 17:04:26 2018
@@ -37,6 +37,9 @@ static bool isArc4RandomAvailable(const
 
 namespace {
 struct ChecksFilter {
+  DefaultBool check_bcmp;
+  DefaultBool check_bcopy;
+  DefaultBool check_bzero;
   DefaultBool check_gets;
   DefaultBool check_getpw;
   DefaultBool check_mktemp;
@@ -47,6 +50,9 @@ struct ChecksFilter {
   DefaultBool check_FloatLoopCounter;
   DefaultBool check_UncheckedReturn;
 
+  CheckName checkName_bcmp;
+  CheckName checkName_bcopy;
+  CheckName checkName_bzero;
   CheckName checkName_gets;
   CheckName checkName_getpw;
   CheckName checkName_mktemp;
@@ -89,6 +95,9 @@ public:
 
   // Checker-specific methods.
   void checkLoopConditionForFloat(const ForStmt *FS);
+  void checkCall_bcmp(const CallExpr *CE, const FunctionDecl *FD);
+  void checkCall_bcopy(const CallExpr *CE, const FunctionDecl *FD);
+  void checkCall_bzero(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_gets(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_getpw(const CallExpr *CE, const FunctionDecl *FD);
   void checkCall_mktemp(const CallExpr *CE, const FunctionDecl *FD);
@@ -129,6 +138,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE
 
   // Set the evaluation function by switching on the callee name.
   FnCheck evalFunction = llvm::StringSwitch(Name)
+.Case("bcmp", ::checkCall_bcmp)
+.Case("bcopy", ::checkCall_bcopy)
+.Case("bzero", ::checkCall_bzero)
 .Case("gets", ::checkCall_gets)
 .Case("getpw", ::checkCall_getpw)
 .Case("mktemp", ::checkCall_mktemp)
@@ -296,6 +308,132 @@ void WalkAST::checkLoopConditionForFloat
 }
 
 
//===--===//
+// Check: Any use of bcmp.
+// CWE-477: Use of Obsolete Functions
+// bcmp was deprecated in POSIX.1-2008
+//===--===//
+
+void WalkAST::checkCall_bcmp(const CallExpr *CE, const FunctionDecl *FD) {
+  if (!filter.check_bcmp)
+return;
+
+  const FunctionProtoType *FPT = FD->getType()->getAs();
+  if (!FPT)
+return;
+
+  // Verify that the function takes three arguments.
+  if (FPT->getNumParams() != 3)
+return;
+
+  for (int i = 0; i < 2; i++) {
+// Verify the first and second argument type is void*.
+const PointerType *PT = FPT->getParamType(i)->getAs();
+if (!PT)
+  return;
+
+if (PT->getPointeeType().getUnqualifiedType() != BR.getContext().VoidTy)
+  return;
+  }
+
+  // Verify the third argument type is integer.
+  if (!FPT->getParamType(2)->isIntegralOrUnscopedEnumerationType())
+return;
+
+  // Issue a warning.
+  PathDiagnosticLocation CELoc =
+PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
+  

[PATCH] D47303: [analyzer] NFC: Merge object construction related state traits into one.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:377
+  if (!State->contains(Key)) {
+return State->set(Key, V);
   }

george.karpenkov wrote:
> nitpick: most C++ containers eliminate the need for two lookups by allowing 
> the `get` method to return a reference. I'm not sure whether this can be done 
> here though.
It's likely to be harder than usual because one doesn't simply obtain a 
non-const reference to an object from an immutable map.

That's said, it's quite unimportant what do we do if the object is already 
there.


https://reviews.llvm.org/D47303



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


[PATCH] D47303: [analyzer] NFC: Merge object construction related state traits into one.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 148692.
NoQ marked 3 inline comments as done.
NoQ added a comment.

Fix review comments.


https://reviews.llvm.org/D47303

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -288,8 +288,8 @@
   AllocV, CNE->getType(),
   getContext().getPointerType(getContext().VoidTy));
 
-  state =
-  setCXXNewAllocatorValue(state, CNE, calleeCtx->getParent(), AllocV);
+  state = addObjectUnderConstruction(state, CNE, calleeCtx->getParent(),
+ AllocV);
 }
   }
 
@@ -354,8 +354,9 @@
  /*WasInlined=*/true);
   for (auto I : DstPostPostCallCallback) {
 getCheckerManager().runCheckersForNewAllocator(
-CNE, getCXXNewAllocatorValue(I->getState(), CNE,
- calleeCtx->getParent()),
+CNE,
+*getObjectUnderConstruction(I->getState(), CNE,
+calleeCtx->getParent()),
 DstPostCall, I, *this,
 /*WasInlined=*/true);
   }
@@ -588,8 +589,8 @@
 // Conjure a temporary if the function returns an object by value.
 MemRegionManager  = svalBuilder.getRegionManager();
 const CXXTempObjectRegion *TR = MRMgr.getCXXTempObjectRegion(E, LCtx);
-State = addAllNecessaryTemporaryInfo(State, RTC->getConstructionContext(),
- LCtx, TR);
+State = markStatementsCorrespondingToConstructedObject(
+State, RTC->getConstructionContext(), LCtx, loc::MemRegionVal(TR));
 
 // Invalidate the region so that it didn't look uninitialized. Don't notify
 // the checkers.
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -111,11 +111,10 @@
 }
 
 
-const MemRegion *
-ExprEngine::getRegionForConstructedObject(const CXXConstructExpr *CE,
-  ExplodedNode *Pred,
-  const ConstructionContext *CC,
-  EvalCallOptions ) {
+SVal ExprEngine::getLocationForConstructedObject(const CXXConstructExpr *CE,
+ ExplodedNode *Pred,
+ const ConstructionContext *CC,
+ EvalCallOptions ) {
   const LocationContext *LCtx = Pred->getLocationContext();
   ProgramStateRef State = Pred->getState();
   MemRegionManager  = getSValBuilder().getRegionManager();
@@ -130,9 +129,8 @@
   const auto *Var = cast(DS->getSingleDecl());
   SVal LValue = State->getLValue(Var, LCtx);
   QualType Ty = Var->getType();
-  LValue =
-  makeZeroElementRegion(State, LValue, Ty, CallOpts.IsArrayCtorOrDtor);
-  return LValue.getAsRegion();
+  return makeZeroElementRegion(State, LValue, Ty,
+   CallOpts.IsArrayCtorOrDtor);
 }
 case ConstructionContext::SimpleConstructorInitializerKind: {
   const auto *ICC = cast(CC);
@@ -156,25 +154,26 @@
   QualType Ty = Field->getType();
   FieldVal = makeZeroElementRegion(State, FieldVal, Ty,
CallOpts.IsArrayCtorOrDtor);
-  return FieldVal.getAsRegion();
+  return FieldVal;
 }
 case ConstructionContext::NewAllocatedObjectKind: {
   if (AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
 const auto *NECC = cast(CC);
 const auto *NE = NECC->getCXXNewExpr();
-// TODO: Detect when the allocator returns a null pointer.
-// Constructor shall not be called in this case.
-if (const SubRegion *MR = dyn_cast_or_null(
-getCXXNewAllocatorValue(State, NE, LCtx).getAsRegion())) {
+SVal V = *getObjectUnderConstruction(State, NE, LCtx);
+if (const SubRegion *MR =
+dyn_cast_or_null(V.getAsRegion())) {
   if (NE->isArray()) {
 // TODO: In fact, we need to call the constructor for every
 // allocated element, not just the first one!
 CallOpts.IsArrayCtorOrDtor = true;
-return getStoreManager().GetElementZeroRegion(
-MR, NE->getType()->getPointeeType());
+return loc::MemRegionVal(getStoreManager().GetElementZeroRegion(
+MR, NE->getType()->getPointeeType()));
   }
-  return 

[PATCH] D47400: [libcxx] [test] Allow a standard library that implements LWG 1203 in istream.rvalue/rvalue.pass.cpp

2018-05-25 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal created this revision.
BillyONeal added reviewers: EricWF, mclow.lists.

If a standard library implements LWG 1203 (which I am implementing in MSVC++ 
right now) the return value of (istringstream() << A{}) is an rvalue, so it 
can't have an lvalue reference bound to it. Change this test to bind a 
forwarding reference instead which allows both standard behavior and LWG 1203 
proposed behavior.

Note that LWG 1203 is presently not accepted.


https://reviews.llvm.org/D47400

Files:
  
test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp


Index: 
test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
===
--- 
test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
+++ 
test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
@@ -65,7 +65,7 @@
 { // test perfect forwarding
 assert(called == false);
 std::istringstream ss;
-auto& out = (std::move(ss) >> A{});
+auto&& out = (std::move(ss) >> A{});
 assert( == );
 assert(called);
 }


Index: test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
===
--- test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
+++ test/std/input.output/iostream.format/input.streams/istream.rvalue/rvalue.pass.cpp
@@ -65,7 +65,7 @@
 { // test perfect forwarding
 assert(called == false);
 std::istringstream ss;
-auto& out = (std::move(ss) >> A{});
+auto&& out = (std::move(ss) >> A{});
 assert( == );
 assert(called);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r333325 - Add nonnull; use it for atomics

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 16:43:53 2018
New Revision: 25

URL: http://llvm.org/viewvc/llvm-project?rev=25=rev
Log:
Add nonnull; use it for atomics

Summary:
The atomic non-member functions accept pointers to std::atomic / 
std::atomic_flag as well as to the non-atomic value. These are all dereferenced 
unconditionally when lowered, and therefore will fault if null. It's a tiny 
gotcha for new users, especially when they pass in NULL as expected value 
(instead of passing a pointer to a NULL value). We can therefore use the 
nonnull attribute to denote that:

  - A warning should be generated if the argument is null
  - It is undefined behavior if the argument is null (because a dereference 
will segfault)

This patch adds support for this attribute for clang and GCC, and sticks to the 
subset of the syntax both supports. In particular, work around this GCC oddity:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60625

The attributes are documented:

  - https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html
  - https://clang.llvm.org/docs/AttributeReference.html#nullability-attributes

I'm authoring a companion clang patch for the __c11_* and __atomic_* builtins, 
which currently only warn on a subset of the pointer parameters.

In all cases the check needs to be explicit and not use the empty nonnull list, 
because some of the overloads are for atomic and the values themselves are 
allowed to be null.



Reviewers: arphaman, EricWF

Subscribers: aheejin, christof, cfe-commits

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

Added:
libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=25=24=25=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri May 25 16:43:53 2018
@@ -1218,6 +1218,17 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #  endif
 #endif
 
+#if __has_attribute(nonnull) || _GNUC_VER >= 400
+// Function pointer parameter must be non-null: warns on null parameter,
+// undefined behavior if the parameter is null. Omitting parameter indices
+// indicates that all parameters of pointer type cannot be null.
+//
+// Note: parameter indexing starts at 1.
+#  define _LIBCPP_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
+#else
+#  define _LIBCPP_NONNULL(...)
+#endif
+
 // Define availability macros.
 #if defined(_LIBCPP_USE_AVAILABILITY_APPLE)
 #  define _LIBCPP_AVAILABILITY_SHARED_MUTEX
\

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=25=24=25=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Fri May 25 16:43:53 2018
@@ -646,19 +646,23 @@ static inline _LIBCPP_CONSTEXPR int __to
 } // namespace __gcc_atomic
 
 template 
+_LIBCPP_NONNULL(1)
 static inline
 typename enable_if<
 __gcc_atomic::__can_assign::value>::type
-__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val)
+{
   __a->__a_value = __val;
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline
 typename enable_if<
 !__gcc_atomic::__can_assign::value &&
  __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
-__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val)
+{
   // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
   // the default operator= in an object is not volatile, a byte-by-byte copy
   // is required.
@@ -671,7 +675,9 @@ __c11_atomic_init(volatile _Atomic(_Tp)*
 }
 
 template 
-static inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val) {
+_LIBCPP_NONNULL(1)
+static inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val)
+{
   __a->__a_value = __val;
 }
 
@@ -684,22 +690,28 @@ static inline void __c11_atomic_signal_f
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a,  _Tp __val,
-  memory_order __order) {
+  memory_order __order)
+{
   return __atomic_store(&__a->__a_value, &__val,
 __gcc_atomic::__to_gcc_order(__order));
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline void __c11_atomic_store(_Atomic(_Tp)* __a,  _Tp __val,
-  memory_order __order) {
+  memory_order __order)
+{
   __atomic_store(&__a->__a_value, &__val,
  __gcc_atomic::__to_gcc_order(__order));
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline _Tp 

[PATCH] D47225: Add nonnull; use it for atomics

2018-05-25 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL25: Add nonnull; use it for atomics (authored by jfb, 
committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47225

Files:
  libcxx/trunk/include/__config
  libcxx/trunk/include/atomic
  libcxx/trunk/test/libcxx/atomics/diagnose_nonnull.fail.cpp

Index: libcxx/trunk/include/atomic
===
--- libcxx/trunk/include/atomic
+++ libcxx/trunk/include/atomic
@@ -646,19 +646,23 @@
 } // namespace __gcc_atomic
 
 template 
+_LIBCPP_NONNULL(1)
 static inline
 typename enable_if<
 __gcc_atomic::__can_assign::value>::type
-__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val)
+{
   __a->__a_value = __val;
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline
 typename enable_if<
 !__gcc_atomic::__can_assign::value &&
  __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
-__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val)
+{
   // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
   // the default operator= in an object is not volatile, a byte-by-byte copy
   // is required.
@@ -671,7 +675,9 @@
 }
 
 template 
-static inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val) {
+_LIBCPP_NONNULL(1)
+static inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val)
+{
   __a->__a_value = __val;
 }
 
@@ -684,88 +690,108 @@
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a,  _Tp __val,
-  memory_order __order) {
+  memory_order __order)
+{
   return __atomic_store(&__a->__a_value, &__val,
 __gcc_atomic::__to_gcc_order(__order));
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline void __c11_atomic_store(_Atomic(_Tp)* __a,  _Tp __val,
-  memory_order __order) {
+  memory_order __order)
+{
   __atomic_store(&__a->__a_value, &__val,
  __gcc_atomic::__to_gcc_order(__order));
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
-memory_order __order) {
+memory_order __order)
+{
   _Tp __ret;
   __atomic_load(&__a->__a_value, &__ret,
 __gcc_atomic::__to_gcc_order(__order));
   return __ret;
 }
 
 template 
-static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
+_LIBCPP_NONNULL(1)
+static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order)
+{
   _Tp __ret;
   __atomic_load(&__a->__a_value, &__ret,
 __gcc_atomic::__to_gcc_order(__order));
   return __ret;
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
-_Tp __value, memory_order __order) {
+_Tp __value, memory_order __order)
+{
   _Tp __ret;
   __atomic_exchange(&__a->__a_value, &__value, &__ret,
 __gcc_atomic::__to_gcc_order(__order));
   return __ret;
 }
 
 template 
+_LIBCPP_NONNULL(1)
 static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
-memory_order __order) {
+memory_order __order)
+{
   _Tp __ret;
   __atomic_exchange(&__a->__a_value, &__value, &__ret,
 __gcc_atomic::__to_gcc_order(__order));
   return __ret;
 }
 
 template 
+_LIBCPP_NONNULL(1, 2)
 static inline bool __c11_atomic_compare_exchange_strong(
 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
-memory_order __success, memory_order __failure) {
+memory_order __success, memory_order __failure)
+{
   return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
false,
__gcc_atomic::__to_gcc_order(__success),
__gcc_atomic::__to_gcc_failure_order(__failure));
 }
 
 template 
+_LIBCPP_NONNULL(1, 2)
 static inline bool __c11_atomic_compare_exchange_strong(
 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
-memory_order __failure) {
+memory_order __failure)
+{
   return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
false,
__gcc_atomic::__to_gcc_order(__success),
__gcc_atomic::__to_gcc_failure_order(__failure));
 }
 
 template 
+_LIBCPP_NONNULL(1, 2)
 static inline bool __c11_atomic_compare_exchange_weak(
 volatile _Atomic(_Tp)* __a, _Tp* 

r333324 - Fix typo + reflow comment; NFC

2018-05-25 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Fri May 25 16:40:59 2018
New Revision: 24

URL: http://llvm.org/viewvc/llvm-project?rev=24=rev
Log:
Fix typo + reflow comment; NFC

Reflow brings said comment below 80 cols

Modified:
cfe/trunk/include/clang/AST/ASTContext.h

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=24=23=24=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri May 25 16:40:59 2018
@@ -1123,7 +1123,7 @@ public:
   /// Return the uniqued reference to the type for an Objective-C
   /// gc-qualified type.
   ///
-  /// The retulting type has a union of the qualifiers from T and the gc
+  /// The resulting type has a union of the qualifiers from T and the gc
   /// attribute.
   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
 
@@ -1250,9 +1250,9 @@ public:
   /// Returns true iff we need copy/dispose helpers for the given type.
   bool BlockRequiresCopying(QualType Ty, const VarDecl *D);
 
-  /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout 
is set
-  /// to false in this case. If HasByrefExtendedLayout returns true, byref 
variable
-  /// has extended lifetime.
+  /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout
+  /// is set to false in this case. If HasByrefExtendedLayout returns true,
+  /// byref variable has extended lifetime.
   bool getByrefLifetime(QualType Ty,
 Qualifiers::ObjCLifetime ,
 bool ) const;


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


[PATCH] D46895: add AR to acronyms of clang-tidy property check

2018-05-25 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:37-38
 
 /// The acronyms are from
 /// 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
 ///

This comment does not seem to be accurate anymore. The acronyms in this list 
are not all from the linked Apple documentation.

Sent out https://reviews.llvm.org/D46922.



Comment at: clang-tidy/objc/PropertyDeclarationCheck.cpp:45
 "API",
+"AR",
 "ARGB",

Are we sure it's sustainable to keep growing this list of acronyms? I suspect 
there may be enough domain-specific acronyms that it might be better to accept 
any sequence of capitalized alphanumeric characters as an acronym.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46895



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


[PATCH] D47155: [analyzer] Reduce simplifySVal complexity threshold further.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 148684.
NoQ added a comment.

Add an explicit brute-force protection against re-entering `simplifySVal()`. 
Remove the threshold completely.


https://reviews.llvm.org/D47155

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/hangs.c

Index: test/Analysis/hangs.c
===
--- /dev/null
+++ test/Analysis/hangs.c
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker core -verify %s
+
+// expected-no-diagnostics
+
+// Stuff that used to hang.
+
+int g();
+
+int f(int y) {
+  return y + g();
+}
+
+int produce_a_very_large_symbol(int x) {
+  return f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(
+ f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(x;
+}
+
+void produce_an_exponentially_exploding_symbol(int x, int y) {
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1222,6 +1222,10 @@
 ProgramStateRef State;
 SValBuilder 
 
+static bool isUnchanged(SymbolRef Sym, SVal Val) {
+  return Sym == Val.getAsSymbol();
+}
+
   public:
 Simplifier(ProgramStateRef State)
 : State(State), SVB(State->getStateManager().getSValBuilder()) {}
@@ -1231,15 +1235,16 @@
   SVB.getKnownValue(State, nonloc::SymbolVal(S)))
 return Loc::isLocType(S->getType()) ? (SVal)SVB.makeIntLocVal(*I)
 : (SVal)SVB.makeIntVal(*I);
-  return Loc::isLocType(S->getType()) ? (SVal)SVB.makeLoc(S) 
-  : nonloc::SymbolVal(S);
+  return SVB.makeSymbolVal(S);
 }
 
 // TODO: Support SymbolCast. Support IntSymExpr when/if we actually
 // start producing them.
 
 SVal VisitSymIntExpr(const SymIntExpr *S) {
   SVal LHS = Visit(S->getLHS());
+  if (isUnchanged(S->getLHS(), LHS))
+return SVB.makeSymbolVal(S);
   SVal RHS;
   // By looking at the APSInt in the right-hand side of S, we cannot
   // figure out if it should be treated as a Loc or as a NonLoc.
@@ -1264,6 +1269,8 @@
 SVal VisitSymSymExpr(const SymSymExpr *S) {
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
+  if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
+return SVB.makeSymbolVal(S);
   return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
 }
 
@@ -1274,13 +1281,20 @@
 SVal VisitNonLocSymbolVal(nonloc::SymbolVal V) {
   // Simplification is much more costly than computing complexity.
   // For high complexity, it may be not worth it.
-  if (V.getSymbol()->computeComplexity() > 100)
-return V;
   return Visit(V.getSymbol());
 }
 
 SVal VisitSVal(SVal V) { return V; }
   };
 
-  return Simplifier(State).Visit(V);
+  // A crude way of preventing this function from calling itself from evalBinOp.
+  static bool isReentering = false;
+  if (isReentering)
+return V;
+
+  isReentering = true;
+  SVal SimplifiedV = Simplifier(State).Visit(V);
+  isReentering = false;
+
+  return SimplifiedV;
 }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -367,6 +367,15 @@
 return loc::ConcreteInt(BasicVals.getValue(integer));
   }
 
+  /// Make an SVal that represents the given symbol. This follows the convention
+  /// of representing Loc-type symbols (symbolic pointers and references)
+  /// as Loc values wrapping the symbol rather than as plain symbol values.
+  SVal makeSymbolVal(SymbolRef Sym) {
+if (Loc::isLocType(Sym->getType()))
+  return makeLoc(Sym);
+return nonloc::SymbolVal(Sym);
+  }
+
   /// Return a memory region for the 'this' object reference.
   loc::MemRegionVal getCXXThis(const CXXMethodDecl *D,
const StackFrameContext *SFC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47155: [analyzer] Reduce simplifySVal complexity threshold further.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I only essentially did one optimization - introduce a short path that returns 
the original value if visiting its sub-values changed nothing, which is a 
relatively common case. The reason it works though is that `evalBinOp()` will 
be called later to combine the sub-values, which may in turn call 
`simplifySVal()` again, which is clearly unwanted.




Comment at: test/Analysis/hangs.c:18-30
+void produce_an_exponentially_exploding_symbol(int x, int y) {
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();

This currently finishes in 1 second on my machine. This test, unlike the 
original test, is easy to experiment with.


https://reviews.llvm.org/D47155



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


r333321 - [X86] Add const to another builtin that was missed from r331814.

2018-05-25 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri May 25 15:52:29 2018
New Revision: 21

URL: http://llvm.org/viewvc/llvm-project?rev=21=rev
Log:
[X86] Add const to another builtin that was missed from r331814.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=21=20=21=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri May 25 15:52:29 2018
@@ -1689,7 +1689,7 @@ TARGET_BUILTIN(__builtin_ia32_pmovusdw12
 TARGET_BUILTIN(__builtin_ia32_pmovusdw128mem_mask, "vV8s*V4iUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusdw256_mask, "V8sV8iV8sUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusdw256mem_mask, "vV8s*V8iUc", "n", 
"avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pmovusqb128_mask, "V16cV2LLiV16cUc", "n", 
"avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pmovusqb128_mask, "V16cV2LLiV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqb128mem_mask, "vV16c*V2LLiUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqb256_mask, "V16cV4LLiV16cUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmovusqb256mem_mask, "vV16c*V4LLiUc", "n", 
"avx512vl")


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


[PATCH] D47155: [analyzer] Reduce simplifySVal complexity threshold further.

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 148681.
NoQ added a comment.

Optimize `simplifySVal()` instead of reducing the threshold.

I'll address the memoization separately.


https://reviews.llvm.org/D47155

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/hangs.c


Index: test/Analysis/hangs.c
===
--- /dev/null
+++ test/Analysis/hangs.c
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker core -verify %s
+
+// expected-no-diagnostics
+
+// Stuff that used to hang.
+
+int g();
+
+int f(int y) {
+  return y + g();
+}
+
+int produce_a_very_large_symbol(int x) {
+  return f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(
+ f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(x;
+}
+
+void produce_an_exponentially_exploding_symbol(int x, int y) {
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1222,6 +1222,10 @@
 ProgramStateRef State;
 SValBuilder 
 
+static bool isUnchanged(SymbolRef Sym, SVal Val) {
+  return Sym == Val.getAsSymbol();
+}
+
   public:
 Simplifier(ProgramStateRef State)
 : State(State), SVB(State->getStateManager().getSValBuilder()) {}
@@ -1231,15 +1235,16 @@
   SVB.getKnownValue(State, nonloc::SymbolVal(S)))
 return Loc::isLocType(S->getType()) ? (SVal)SVB.makeIntLocVal(*I)
 : (SVal)SVB.makeIntVal(*I);
-  return Loc::isLocType(S->getType()) ? (SVal)SVB.makeLoc(S) 
-  : nonloc::SymbolVal(S);
+  return SVB.makeSymbolVal(S);
 }
 
 // TODO: Support SymbolCast. Support IntSymExpr when/if we actually
 // start producing them.
 
 SVal VisitSymIntExpr(const SymIntExpr *S) {
   SVal LHS = Visit(S->getLHS());
+  if (isUnchanged(S->getLHS(), LHS))
+return SVB.makeSymbolVal(S);
   SVal RHS;
   // By looking at the APSInt in the right-hand side of S, we cannot
   // figure out if it should be treated as a Loc or as a NonLoc.
@@ -1264,6 +1269,8 @@
 SVal VisitSymSymExpr(const SymSymExpr *S) {
   SVal LHS = Visit(S->getLHS());
   SVal RHS = Visit(S->getRHS());
+  if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
+return SVB.makeSymbolVal(S);
   return SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -367,6 +367,15 @@
 return loc::ConcreteInt(BasicVals.getValue(integer));
   }
 
+  /// Make an SVal that represents the given symbol. This follows the 
convention
+  /// of representing Loc-type symbols (symbolic pointers and references)
+  /// as Loc values wrapping the symbol rather than as plain symbol values.
+  SVal makeSymbolVal(SymbolRef Sym) {
+if (Loc::isLocType(Sym->getType()))
+  return makeLoc(Sym);
+return nonloc::SymbolVal(Sym);
+  }
+
   /// Return a memory region for the 'this' object reference.
   loc::MemRegionVal getCXXThis(const CXXMethodDecl *D,
const StackFrameContext *SFC);


Index: test/Analysis/hangs.c
===
--- /dev/null
+++ test/Analysis/hangs.c
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker core -verify %s
+
+// expected-no-diagnostics
+
+// Stuff that used to hang.
+
+int g();
+
+int f(int y) {
+  return y + g();
+}
+
+int produce_a_very_large_symbol(int x) {
+  return f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(
+ f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(x;
+}
+
+void produce_an_exponentially_exploding_symbol(int x, int y) {
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+  x += y; y += x + g();
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1222,6 +1222,10 @@
 ProgramStateRef State;
 SValBuilder 
 
+static bool 

r333320 - [X86] Correct the target features on two avx512bw builtins that were incorrectly labeled as avx512f.

2018-05-25 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri May 25 15:43:20 2018
New Revision: 20

URL: http://llvm.org/viewvc/llvm-project?rev=20=rev
Log:
[X86] Correct the target features on two avx512bw builtins that were 
incorrectly labeled as avx512f.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=20=19=20=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri May 25 15:43:20 2018
@@ -1486,8 +1486,8 @@ TARGET_BUILTIN(__builtin_ia32_vcomisd, "
 TARGET_BUILTIN(__builtin_ia32_vcomiss, "iV4fV4fIiIi", "nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_kunpckdi, "ULLiULLiULLi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_kunpcksi, "UiUiUi", "nc", "avx512bw")
-TARGET_BUILTIN(__builtin_ia32_loaddquhi512_mask, "V32sV32s*V32sUi", "n", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_loaddquqi512_mask, "V64cV64c*V64cULLi", "n", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_loaddquhi512_mask, "V32sV32s*V32sUi", "n", 
"avx512bw")
+TARGET_BUILTIN(__builtin_ia32_loaddquqi512_mask, "V64cV64c*V64cULLi", "n", 
"avx512bw")
 TARGET_BUILTIN(__builtin_ia32_fixupimmpd512_mask, "V8dV8dV8dV8LLiIiUcIi", 
"nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_fixupimmpd512_maskz, "V8dV8dV8dV8LLiIiUcIi", 
"nc", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_fixupimmps512_mask, "V16fV16fV16fV16iIiUsIi", 
"nc", "avx512f")


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


RE: r333311 - [DebugInfo] Don't bother with MD5 checksums of preprocessed files.

2018-05-25 Thread via cfe-commits
Reverted in r19 because I got failure notices from
http://lab.llvm.org:8011/builders/clang-ppc64le-linux/builds/17262
and (for stage 1, but not stage 2, which is pretty weird)
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10824

The Bots Know when I'm about to go out of town... I'll have to
revisit this later.
--paulr

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of
> Paul Robinson via cfe-commits
> Sent: Friday, May 25, 2018 4:59 PM
> To: cfe-commits@lists.llvm.org
> Subject: r11 - [DebugInfo] Don't bother with MD5 checksums of
> preprocessed files.
> 
> Author: probinson
> Date: Fri May 25 13:59:29 2018
> New Revision: 11
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=11=rev
> Log:
> [DebugInfo] Don't bother with MD5 checksums of preprocessed files.
> 
> The checksum will not reflect the real source, so there's no clear
> reason to include them in the debug info.  Also this was causing a
> crash on the DWARF side.
> 
> Differential Revision: https://reviews.llvm.org/D47260
> 
> Added:
> cfe/trunk/test/CodeGen/md5-checksum-crash.c
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/lib/CodeGen/CGDebugInfo.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=11=10=
> 11=diff
> ==
> 
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri May 25 13:59:29 2018
> @@ -67,6 +67,8 @@ CGDebugInfo::CGDebugInfo(CodeGenModule &
>DBuilder(CGM.getModule()) {
>for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
>  DebugPrefixMap[KV.first] = KV.second;
> +  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
> +  CGM.getCodeGenOpts().DwarfVersion >= 5;
>CreateCompileUnit();
>  }
> 
> @@ -365,15 +367,21 @@ Optional
>  CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const
> {
>Checksum.clear();
> 
> -  if (!CGM.getCodeGenOpts().EmitCodeView &&
> -  CGM.getCodeGenOpts().DwarfVersion < 5)
> +  if (!EmitFileChecksums)
>  return None;
> 
>SourceManager  = CGM.getContext().getSourceManager();
>bool Invalid;
> -  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
> -  if (Invalid)
> +  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
> +  if (Invalid || !Entry.isFile())
>  return None;
> +  if (Entry.getFile().hasLineDirectives()) {
> +// This must be a preprocessed file; its content won't match the
> original
> +// source; therefore checksumming the text we have is pointless or
> wrong.
> +EmitFileChecksums = false;
> +return None;
> +  }
> +  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
> 
>llvm::MD5 Hash;
>llvm::MD5::MD5Result Result;
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=11=10=11
> =diff
> ==
> 
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri May 25 13:59:29 2018
> @@ -57,6 +57,7 @@ class CGDebugInfo {
>CodeGenModule 
>const codegenoptions::DebugInfoKind DebugKind;
>bool DebugTypeExtRefs;
> +  mutable bool EmitFileChecksums;
>llvm::DIBuilder DBuilder;
>llvm::DICompileUnit *TheCU = nullptr;
>ModuleMap *ClangModuleMap = nullptr;
> 
> Added: cfe/trunk/test/CodeGen/md5-checksum-crash.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/md5-
> checksum-crash.c?rev=11=auto
> ==
> 
> --- cfe/trunk/test/CodeGen/md5-checksum-crash.c (added)
> +++ cfe/trunk/test/CodeGen/md5-checksum-crash.c Fri May 25 13:59:29 2018
> @@ -0,0 +1,13 @@
> +// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -
> dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
> +// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-
> kind=limited %s -emit-llvm -o- | FileCheck %s
> +
> +// This had been crashing, no MD5 checksum for string.h.
> +// Now if there are #line directives, don't bother with checksums
> +// as a preprocessed file won't properly reflect the original source.
> +#define __NTH fct
> +void fn1() {}
> +# 7 "/usr/include/string.h"
> +void __NTH() {}
> +// Verify no checksum attributes on these files.
> +// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
> +// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

r333319 - Revert "[DebugInfo] Don't bother with MD5 checksums of preprocessed files."

2018-05-25 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Fri May 25 15:35:59 2018
New Revision: 19

URL: http://llvm.org/viewvc/llvm-project?rev=19=rev
Log:
Revert "[DebugInfo] Don't bother with MD5 checksums of preprocessed files."

This reverts commit d734f2aa3f76fbf355ecd2bbe081d0c1f49867ab.
Also known as r11.  A very small but nonzero number of bots fail.

Removed:
cfe/trunk/test/CodeGen/md5-checksum-crash.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=19=18=19=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri May 25 15:35:59 2018
@@ -67,8 +67,6 @@ CGDebugInfo::CGDebugInfo(CodeGenModule &
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
-  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
-  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -367,21 +365,15 @@ Optional
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!EmitFileChecksums)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
-  if (Invalid || !Entry.isFile())
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
+  if (Invalid)
 return None;
-  if (Entry.getFile().hasLineDirectives()) {
-// This must be a preprocessed file; its content won't match the original
-// source; therefore checksumming the text we have is pointless or wrong.
-EmitFileChecksums = false;
-return None;
-  }
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=19=18=19=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri May 25 15:35:59 2018
@@ -57,7 +57,6 @@ class CGDebugInfo {
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
-  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;

Removed: cfe/trunk/test/CodeGen/md5-checksum-crash.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/md5-checksum-crash.c?rev=18=auto
==
--- cfe/trunk/test/CodeGen/md5-checksum-crash.c (original)
+++ cfe/trunk/test/CodeGen/md5-checksum-crash.c (removed)
@@ -1,13 +0,0 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited 
-dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
-// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited 
%s -emit-llvm -o- | FileCheck %s
-
-// This had been crashing, no MD5 checksum for string.h.
-// Now if there are #line directives, don't bother with checksums
-// as a preprocessed file won't properly reflect the original source.
-#define __NTH fct
-void fn1() {}
-# 7 "/usr/include/string.h"
-void __NTH() {}
-// Verify no checksum attributes on these files.
-// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
-// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")


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


r333302 - Convert clang-interpreter to ORC JIT API

2018-05-25 Thread Stephane Sezer via cfe-commits
Author: sas
Date: Fri May 25 13:23:42 2018
New Revision: 02

URL: http://llvm.org/viewvc/llvm-project?rev=02=rev
Log:
Convert clang-interpreter to ORC JIT API

Summary: This mostly re-uses code from the KaleidoscopeJIT example.

Reviewers: ddunbar, lhames

Reviewed By: lhames

Subscribers: mgrang, alexshap, mgorny, xiaobai, cfe-commits

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

Removed:
cfe/trunk/examples/clang-interpreter/Invoke.cpp
cfe/trunk/examples/clang-interpreter/Invoke.h
cfe/trunk/examples/clang-interpreter/Manager.cpp
cfe/trunk/examples/clang-interpreter/Manager.h
Modified:
cfe/trunk/examples/clang-interpreter/CMakeLists.txt
cfe/trunk/examples/clang-interpreter/main.cpp

Modified: cfe/trunk/examples/clang-interpreter/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/clang-interpreter/CMakeLists.txt?rev=02=01=02=diff
==
--- cfe/trunk/examples/clang-interpreter/CMakeLists.txt (original)
+++ cfe/trunk/examples/clang-interpreter/CMakeLists.txt Fri May 25 13:23:42 2018
@@ -12,8 +12,6 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_executable(clang-interpreter
   main.cpp
-  Invoke.cpp
-  Manager.cpp
   )
 
 add_dependencies(clang-interpreter

Removed: cfe/trunk/examples/clang-interpreter/Invoke.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/clang-interpreter/Invoke.cpp?rev=01=auto
==
--- cfe/trunk/examples/clang-interpreter/Invoke.cpp (original)
+++ cfe/trunk/examples/clang-interpreter/Invoke.cpp (removed)
@@ -1,31 +0,0 @@
-//==-- examples/clang-interpreter/Invoke.cpp - Clang C Interpreter Example 
-==//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "Invoke.h"
-
-#include 
-#include 
-
-namespace interpreter {
-
-int TryIt(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
-  const std::vector , char *const *EnvP,
-  Invoker Invoke) {
-  int Res = -1;
-  try {
-Res = Invoke(EE, EntryFn, Args, EnvP);
-  } catch (const std::exception ) {
-std::cout << "Caught '" << E.what() << "'\n";
-  } catch (...) {
-std::cout << "Unknown exception\n";
-  }
-  return Res;
-}
-
-}

Removed: cfe/trunk/examples/clang-interpreter/Invoke.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/clang-interpreter/Invoke.h?rev=01=auto
==
--- cfe/trunk/examples/clang-interpreter/Invoke.h (original)
+++ cfe/trunk/examples/clang-interpreter/Invoke.h (removed)
@@ -1,34 +0,0 @@
-//===-- examples/clang-interpreter/Invoke.h - Clang C Interpreter Example 
-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#ifndef CLANG_EXAMPLE_INTERPRETER_INVOKE_H
-#define CLANG_EXAMPLE_INTERPRETER_INVOKE_H
-
-namespace llvm {
-  class ExecutionEngine;
-  class Function;
-}
-
-#include 
-#include 
-
-namespace interpreter {
-
-typedef std::vector InvokeArgs;
-
-typedef int (*Invoker)(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
-   const InvokeArgs , char *const *EnvP);
-
-int TryIt(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
-  const InvokeArgs , char *const *EnvP,
-  Invoker Invoke);
-
-} // interpreter
-
-#endif // CLANG_EXAMPLE_INTERPRETER_INVOKE_H

Removed: cfe/trunk/examples/clang-interpreter/Manager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/clang-interpreter/Manager.cpp?rev=01=auto
==
--- cfe/trunk/examples/clang-interpreter/Manager.cpp (original)
+++ cfe/trunk/examples/clang-interpreter/Manager.cpp (removed)
@@ -1,328 +0,0 @@
-//==-- examples/clang-interpreter/Manager.cpp - Clang C Interpreter Example 
-=//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "Manager.h"
-
-#ifdef CLANG_INTERPRETER_WIN_EXCEPTIONS
-#include "llvm/Support/DynamicLibrary.h"
-
-#define WIN32_LEAN_AND_MEAN
-#define NOGDI
-#define NOMINMAX
-#include 
-#endif
-
-namespace interpreter {
-
-using namespace llvm;
-
-void SingleSectionMemoryManager::Block::Reset(uint8_t *Ptr, uintptr_t Size) {
-  assert(Ptr != nullptr && "Bad allocation");
-  Addr = Ptr;
-  End = Ptr ? Ptr + Size : 

[PATCH] D41881: [analyzer] Flag bcmp, bcopy and bzero as obsolete

2018-05-25 Thread Tom Rix via Phabricator via cfe-commits
trixirt added a comment.
Herald added a reviewer: george.karpenkov.

I need someone to commit this..


Repository:
  rC Clang

https://reviews.llvm.org/D41881



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 148678.
juliehockett marked 11 inline comments as done.
juliehockett added a comment.

Reworking the reducer interface a bit to address comments.


https://reviews.llvm.org/D43341

Files:
  clang-doc/BitcodeReader.cpp
  clang-doc/BitcodeReader.h
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/Reducer.cpp
  clang-doc/Reducer.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/tool/ClangDocMain.cpp
  docs/ReleaseNotes.rst
  test/clang-doc/bc-comment.cpp
  test/clang-doc/bc-namespace.cpp
  test/clang-doc/bc-record.cpp

Index: test/clang-doc/bc-record.cpp
===
--- /dev/null
+++ test/clang-doc/bc-record.cpp
@@ -0,0 +1,254 @@
+// This test requires Linux due to the system-dependent USR for the
+// inner class in function H.
+// REQUIRES: system-linux
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-intermediate -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/ACE81AFA6627B4CEF2B456FB6E1252925674AF7E.bc --dump | FileCheck %s --check-prefix CHECK-A
+// RUN: llvm-bcanalyzer %t/docs/bc/FC07BD34D5E77782C263FA97929EA8753740.bc --dump | FileCheck %s --check-prefix CHECK-B
+// RUN: llvm-bcanalyzer %t/docs/bc/1E3438A08BA22025C0B46289FF0686F92C8924C5.bc --dump | FileCheck %s --check-prefix CHECK-BC
+// RUN: llvm-bcanalyzer %t/docs/bc/06B5F6A19BA9F6A832E127C9968282B94619B210.bc --dump | FileCheck %s --check-prefix CHECK-C
+// RUN: llvm-bcanalyzer %t/docs/bc/0921737541208B8FA9BB42B60F78AC1D779AA054.bc --dump | FileCheck %s --check-prefix CHECK-D
+// RUN: llvm-bcanalyzer %t/docs/bc/289584A8E0FF4178A794622A547AA622503967A1.bc --dump | FileCheck %s --check-prefix CHECK-E
+// RUN: llvm-bcanalyzer %t/docs/bc/DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4.bc --dump | FileCheck %s --check-prefix CHECK-ECON
+// RUN: llvm-bcanalyzer %t/docs/bc/BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17.bc --dump | FileCheck %s --check-prefix CHECK-EDES
+// RUN: llvm-bcanalyzer %t/docs/bc/E3B54702FABFF4037025BA194FC27C47006330B5.bc --dump | FileCheck %s --check-prefix CHECK-F
+// RUN: llvm-bcanalyzer %t/docs/bc/B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E.bc --dump | FileCheck %s --check-prefix CHECK-H
+// RUN: llvm-bcanalyzer %t/docs/bc/6BA1EE2B3DAEACF6E4306F10AF44908F4807927C.bc --dump | FileCheck %s --check-prefix CHECK-I
+// RUN: llvm-bcanalyzer %t/docs/bc/5093D428CDC62096A67547BA52566E4FB9404EEE.bc --dump | FileCheck %s --check-prefix CHECK-PM
+// RUN: llvm-bcanalyzer %t/docs/bc/CA7C7935730B5EACD25F080E9C83FA087CCDC75E.bc --dump | FileCheck %s --check-prefix CHECK-X
+// RUN: llvm-bcanalyzer %t/docs/bc/641AB4A3D36399954ACDE29C7A8833032BF40472.bc --dump | FileCheck %s --check-prefix CHECK-Y
+
+void H() {
+  class I {};
+}
+// CHECK-H: 
+  // CHECK-H-NEXT: 
+  // CHECK-H-NEXT:  blob data = 'H'
+  // CHECK-H-NEXT:  blob data = '{{.*}}'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT:  blob data = 'void'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+
+
+// CHECK-I: 
+  // CHECK-I-NEXT: 
+  // CHECK-I-NEXT:  blob data = 'I'
+  // CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+// CHECK-I-NEXT:  blob data = 'H'
+// CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+  // CHECK-I-NEXT: 
+  // CHECK-I-NEXT:  blob data = '{{.*}}'
+  // CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+
+union A { int X; int Y; };
+// CHECK-A: 
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'A'
+  // CHECK-A-NEXT:  blob data = '{{.*}}'
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'int'
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+// CHECK-A-NEXT:  blob data = 'X'
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'int'
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+// CHECK-A-NEXT:  blob data = 'Y'
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+
+enum B { X, Y };
+// CHECK-B: 
+  // CHECK-B-NEXT: 
+  // CHECK-B-NEXT:  blob data = 'B'
+  // CHECK-B-NEXT:  blob data = '{{.*}}'
+  // CHECK-B-NEXT:  blob data = 'X'
+  // CHECK-B-NEXT:  blob data = 'Y'
+// CHECK-B-NEXT: 
+
+enum class Bc { A, B };
+// CHECK-BC: 
+  // CHECK-BC-NEXT: 
+  // CHECK-BC-NEXT:  blob data = 'Bc'
+  // CHECK-BC-NEXT:  blob data = '{{.*}}'
+  // CHECK-BC-NEXT: 
+  // CHECK-BC-NEXT:  blob data = 'A'
+  // CHECK-BC-NEXT:  blob data = 'B'
+// CHECK-BC-NEXT: 
+
+struct C { int i; };
+// CHECK-C: 
+  // CHECK-C-NEXT: 
+  // CHECK-C-NEXT:  blob data = 'C'
+  // CHECK-C-NEXT:  blob data = '{{.*}}'
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+  // CHECK-C-NEXT:  blob data = 'int'
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+// CHECK-C-NEXT:  blob data = 'i'
+// CHECK-C-NEXT: 
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+

r333318 - [X86] Mark a few more builtins const that were missed in r331814.

2018-05-25 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Fri May 25 15:07:43 2018
New Revision: 18

URL: http://llvm.org/viewvc/llvm-project?rev=18=rev
Log:
[X86] Mark a few more builtins const that were missed in r331814.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=18=17=18=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri May 25 15:07:43 2018
@@ -1237,9 +1237,9 @@ TARGET_BUILTIN(__builtin_ia32_pmaxsq256,
 TARGET_BUILTIN(__builtin_ia32_pmaxuq128, "V2LLiV2LLiV2LLi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pmaxuq256, "V4LLiV4LLiV4LLi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_pminsq128, "V2LLiV2LLiV2LLi", "nc", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pminsq256, "V4LLiV4LLiV4LLi", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pminuq128, "V2LLiV2LLiV2LLi", "n", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_pminuq256, "V4LLiV4LLiV4LLi", "n", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pminsq256, "V4LLiV4LLiV4LLi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pminuq128, "V2LLiV2LLiV2LLi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_pminuq256, "V4LLiV4LLiV4LLi", "nc", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_rndscalepd_128_mask, "V2dV2dIiV2dUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_rndscalepd_256_mask, "V4dV4dIiV4dUc", "nc", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_rndscaleps_128_mask, "V4fV4fIiV4fUc", "nc", 
"avx512vl")


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


[PATCH] D47394: [OpenMP][Clang][NVPTX] Replace bundling with partial linking for the OpenMP NVPTX device offloading toolchain

2018-05-25 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 148677.

Repository:
  rC Clang

https://reviews.llvm.org/D47394

Files:
  include/clang/Driver/Action.h
  include/clang/Driver/Compilation.h
  include/clang/Driver/Driver.h
  include/clang/Driver/ToolChain.h
  lib/Driver/Action.cpp
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Clang.h
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c
  test/Driver/openmp-offload.c

Index: test/Driver/openmp-offload.c
===
--- test/Driver/openmp-offload.c
+++ test/Driver/openmp-offload.c
@@ -480,13 +480,13 @@
 // Create host object and bundle.
 // CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-BUJOBS-SAME: [[HOSTOBJ:[^\\/]+\.o]]" "-x" "ir" "{{.*}}[[HOSTBC]]"
-// CHK-BUJOBS: clang-offload-bundler{{.*}}" "-type=o" "-targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu,host-powerpc64le--linux" "-outputs=
+// CHK-BUJOBS: clang-offload-bundler{{.*}}" "-type=o"{{.*}}"-targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu,host-powerpc64le--linux" "-outputs=
 // CHK-BUJOBS-SAME: [[RES:[^\\/]+\.o]]" "-inputs={{.*}}[[T1OBJ]],{{.*}}[[T2OBJ]],{{.*}}[[HOSTOBJ]]"
 // CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-BUJOBS-ST-SAME: [[HOSTASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[HOSTBC]]"
 // CHK-BUJOBS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le--linux" "-filetype" "obj" {{.*}}"-o" "
 // CHK-BUJOBS-ST-SAME: [[HOSTOBJ:[^\\/]+\.o]]" "{{.*}}[[HOSTASM]]"
-// CHK-BUJOBS-ST: clang-offload-bundler{{.*}}" "-type=o" "-targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu,host-powerpc64le--linux" "-outputs=
+// CHK-BUJOBS-ST: clang-offload-bundler{{.*}}" "-type=o"{{.*}}"-targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu,host-powerpc64le--linux" "-outputs=
 // CHK-BUJOBS-ST-SAME: [[RES:[^\\/]+\.o]]" "-inputs={{.*}}[[T1OBJ]],{{.*}}[[T2OBJ]],{{.*}}[[HOSTOBJ]]"
 
 /// ###
Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -66,24 +66,29 @@
 
 // CHK-PTXAS-CUBIN-BUNDLING: clang{{.*}}" "-o" "[[PTX:.*\.s]]"
 // CHK-PTXAS-CUBIN-BUNDLING-NEXT: ptxas{{.*}}" "--output-file" "[[CUBIN:.*\.cubin]]" {{.*}}"[[PTX]]"
-// CHK-PTXAS-CUBIN-BUNDLING: clang-offload-bundler{{.*}}" "-type=o" {{.*}}"-inputs={{.*}}[[CUBIN]]
+// CHK-PTXAS-CUBIN-BUNDLING: fatbinary{{.*}}" "--create=[[FATBIN:.*\.fatbin]]" "
+// CHK-PTXAS-CUBIN-BUNDLING-SAME: --embedded-fatbin=[[FATBINC:.*\.fatbin.c]]" "
+// CHK-PTXAS-CUBIN-BUNDLING-SAME: --cmdline=--compile-only" "--image=profile={{.*}}[[PTX]]" "
+// CHK-PTXAS-CUBIN-BUNDLING-SAME: --image=profile={{.*}}file=[[CUBIN]]" "--cuda" "--device-c"
+// CHK-PTXAS-CUBIN-BUNDLING: clang++{{.*}}" "-c" "-o" "[[HOSTDEV:.*\.o]]"{{.*}}" "[[FATBINC]]" "-D__NV_MODULE_ID=
+// CHK-PTXAS-CUBIN-BUNDLING-NOT: clang-offload-bundler{{.*}}" "-type=o" {{.*}}"-inputs={{.*}}[[CUBIN]]
+// CHK-PTXAS-CUBIN-BUNDLING: ld" "-r" "[[HOSTDEV]]" "{{.*}}.o" "-o" "{{.*}}.o"
 
 /// ###
 
-/// Check cubin file unbundling and usage by nvlink
+/// Check object file unbundling is not happening when skipping bundler
 // RUN:   touch %t.o
 // RUN:   %clang -### -target powerpc64le-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
 // RUN:  -no-canonical-prefixes -save-temps %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-CUBIN-UNBUNDLING-NVLINK %s
 
-/// Use DAG to ensure that cubin file has been unbundled.
-// CHK-CUBIN-UNBUNDLING-NVLINK-DAG: nvlink{{.*}}" {{.*}}"[[CUBIN:.*\.cubin]]"
-// CHK-CUBIN-UNBUNDLING-NVLINK-DAG: clang-offload-bundler{{.*}}" "-type=o" {{.*}}"-outputs={{.*}}[[CUBIN]]
-// CHK-CUBIN-UNBUNDLING-NVLINK-DAG-SAME: "-unbundle"
+/// Use DAG to ensure that object file has not been unbundled.
+// CHK-CUBIN-UNBUNDLING-NVLINK-DAG: nvlink{{.*}}" {{.*}}"[[OBJ:.*\.o]]"
+// CHK-CUBIN-UNBUNDLING-NVLINK-DAG: ld{{.*}}" {{.*}}"[[OBJ]]"
 
 /// ###
 
-/// Check cubin file generation and usage by nvlink
+/// Check object file generation is not happening when skipping bundler
 // RUN:   touch %t1.o
 // RUN:   touch %t2.o
 // RUN:   %clang -### -no-canonical-prefixes -target powerpc64le-unknown-linux-gnu -fopenmp=libomp \
@@ -94,7 +99,7 @@
 // RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %t1.o %t2.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-TWOCUBIN %s
 
-// CHK-TWOCUBIN: nvlink{{.*}}openmp-offload-{{.*}}.cubin" "{{.*}}openmp-offload-{{.*}}.cubin"
+// CHK-TWOCUBIN: nvlink{{.*}}openmp-offload-{{.*}}.o" 

[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:265-276
+  const llvm::APSInt  = i->From(),  = i->To();
+  const llvm::APSInt  = (to.isMinSignedValue() ?
+ BV.getMaxValue(to) :
+ (to.isMaxSignedValue() ?
+  BV.getMinValue(to) :
+  BV.getValue(- to)));
+  const llvm::APSInt  = (from.isMinSignedValue() ?

baloghadamsoftware wrote:
> NoQ wrote:
> > baloghadamsoftware wrote:
> > > NoQ wrote:
> > > > Hmm, wait a minute, is this actually correct?
> > > > 
> > > > For the range [-2³¹, -2³¹ + 1] over a 32-bit integer, the negated range 
> > > > will be [-2³¹, -2³¹] U [2³¹ - 1, 2³¹ - 1].
> > > > 
> > > > So there must be a place in the code where we take one range and add 
> > > > two ranges.
> > > The two ends of the range of the type usually stands for +/- infinity. If 
> > > we add the minimum of the type when negating a negative range, then we 
> > > lose the whole point of this transformation.
> > > 
> > > Example: If `A - B < 0`, then the range of `A - B` is `[-2³¹, -1]`, If we 
> > > negate this, and keep the `-2³¹` range end, then we get `[-2³¹, -2³¹]U[1, 
> > > 2³¹-1]`. However, this does not mean `B - A > 0`. If we make assumption 
> > > about this, we get two states instead of one, in the true state `A - B`'s 
> > > range is `[1, 2³¹-1]` and in the false state it is `[-2³¹, -2³¹]`. This 
> > > is surely not what we want.
> > Well, we can't turn math into something we want, it is what it is.
> > 
> > Iterator-related symbols are all planned to be within range [-2²⁹, -2²⁹], 
> > right? So if we subtract one such symbol from another, it's going to be in 
> > range [-2³⁰, 2³⁰]. Can we currently infer that? Or maybe we should make the 
> > iterator checker to enforce that separately? Because this range doesn't 
> > include -2³¹, so we won't have any problems with doing negation correctly.
> > 
> > So as usual i propose to get this code mathematically correct and then see 
> > if we can ensure correct behavior by enforcing reasonable constraints on 
> > our symbols.
> I agree that the code should do mathematically correct things, but what I 
> argue here is what math here means. Computer science is based on math, but it 
> is somewhat different because of finite ranges and overflows. So I initially 
> regarded the minimal and maximal values as infinity. Maybe that is not 
> correct. However, I am sure that negating `-2³¹` should never be `-2³¹`. This 
> is mathematically incorrect, and renders the whole calculation useless, since 
> the union of a positive range and a negative range is unsuitable for any 
> reasoning. I see two options here:
> 
> 1. Remove the extension when negating a range which ends at the maximal value 
> of the type. So the negated range begins at the minimal value plus one. 
> However, cut the range which begins at the minimal value of the type by one. 
> So the negated range ends at the maximal value, as in the current version in 
> the patch.
> 
> 2. Remove the extension as in 1. and disable the whole negation if we have 
> the range begins at the minimal value.
> 
> Iterator checkers are of course not affected because of the max/4 constraints.
> However, I am sure that negating `-2³¹` should never be `-2³¹`. This is 
> mathematically incorrect, and renders the whole calculation useless, since 
> the union of a positive range and a negative range is unsuitable for any 
> reasoning.

Well, that's how computers already work. And that's how all sorts of abstract 
algebra work as well, so this is totally mathematically correct. We promise to 
support the [[ https://en.wikipedia.org/wiki/Two's_complement | two's 
complement ]] semantics in the analyzer when it comes to signed integer 
overflows. Even though it's technically UB, most implementations follow this 
semantics and a lot of real-world applications explicitly rely on that. Also we 
cannot simply drop values from our constraint ranges in the general case 
because the values we drop might be the only valid values, and the assumption 
that at least one non-dropped value can definitely be taken is generally 
incorrect. Finding cornercases like this one is one of the strong sides of any 
static analysis: it is in fact our job to make the user aware of it if he 
doesn't understand overflow rules. If it cannot be said that the variable on a 
certain path is non-negative because it might as well be -2³¹, we should 
totally explore this possibility. If for a certain checker it brings no benefit 
because such value would be unlikely in certain circumstances, that checker is 
free to cut off the respective paths, but the core should perform operations 
precisely. I don't think we have much room for personal preferences here.


https://reviews.llvm.org/D35110



___

[PATCH] D47395: [libcxx] [test] Remove nonportable locale assumption in basic.ios.members/narrow.pass.cpp

2018-05-25 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal created this revision.
BillyONeal added reviewers: EricWF, mclow.lists.

I'm not sure if libcxx is asserting UTF-8 here; but on Windows the full char 
value is always passed through in its entirety, since the default codepage is 
something like Windows-1252. The replacement character is only used for 
non-chars there; and that should be a more portable test everywhere.


https://reviews.llvm.org/D47395

Files:
  test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp


Index: 
test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
===
--- test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
+++ test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
@@ -18,7 +18,7 @@
 
 int main()
 {
-const std::ios ios(0);
-assert(ios.narrow('c', '*') == 'c');
-assert(ios.narrow('\xFE', '*') == '*');
+const std::wios ios(0);
+assert(ios.narrow(L'c', '*') == 'c');
+assert(ios.narrow(L'\u203C', '*') == '*');
 }


Index: test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
===
--- test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
+++ test/std/input.output/iostreams.base/ios/basic.ios.members/narrow.pass.cpp
@@ -18,7 +18,7 @@
 
 int main()
 {
-const std::ios ios(0);
-assert(ios.narrow('c', '*') == 'c');
-assert(ios.narrow('\xFE', '*') == '*');
+const std::wios ios(0);
+assert(ios.narrow(L'c', '*') == 'c');
+assert(ios.narrow(L'\u203C', '*') == '*');
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r333317 - Fix optional test breakage

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 14:32:27 2018
New Revision: 17

URL: http://llvm.org/viewvc/llvm-project?rev=17=rev
Log:
Fix optional test breakage

It seems GCC and clang disagree. Talked to mclow on IRC, disabling for now.

Modified:

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp?rev=17=16=17=diff
==
--- 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
 Fri May 25 14:32:27 2018
@@ -43,11 +43,15 @@ int main()
 
 {
 //  optional(const optional &);
+  // FIXME clang and GCC disagree about this!
+  // clang thinks opt is optional, GCC thinks it's 
optional.
+#if 0
 std::optional source('A');
 std::optional opt(source);
 static_assert(std::is_same_v>, "");
 assert(static_cast(opt) == static_cast(source));
 assert(*opt == *source);
+#endif
 }
 
 }


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


[PATCH] D47394: [OpenMP][Clang][NVPTX] Replace bundling with partial linking for the OpenMP NVPTX device offloading toolchain

2018-05-25 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: Hahnfeld, hfinkel, caomhin, carlo.bertolli, tra.
Herald added subscribers: cfe-commits, guansong.

So far, the clang-offload-bundler has been the default tool for bundling 
together various files types produced by the different OpenMP offloading 
toolchains supported by Clang. It does a great job for file types such as .bc, 
.ll, .ii, .ast. It is also used for bundling object files. Object files are 
special, in this case object files which contain sections meant to be executed 
on devices other than the host (such is the case of the OpenMP NVPTX 
toolchain). The bundling of object files prevents:

- STATIC LINKING: These bundled object files can be part of static libraries 
which means that the object file requires an unbundling step. If an object file 
in a static library requires "unbundling" then we need to know the whereabouts 
of that library and of the files before the actual link step which makes it 
impossible to do static linking using the "-L/path/to/lib/folder -labc" flag.
- INTEROPERABILITY WITH OTHER COMPILERS: These bundled object files can end up 
being passed between Clang and other compilers which may lead to 
incompatibilities: passing a bundled file from Clang to another compiler would 
lead to that compiler not being able to unbundle it. Passing an unbundled 
object file to Clang and therefore Clang not knowing that it doesn't need to 
unbundle it.

**Goal:**
Disable the use of the clang-offload-bundler for bundling/unbundling object 
files which contain OpenMP NVPTX device offloaded code. This applies to the 
case where the following set of flags are passed to Clang:
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda
When the above condition is not met the compiler works as it does today by 
invoking the clang-offload-bundler for bundling/unbundling object files (at the 
cost of static linking and interoperability).
The clang-offload-bundler usage on files other than object files is not 
affected by this patch.

**Extensibility**
Although this patch disables bundling/unbundling of object files via the 
clang-offload-bundler for the OpenMP NVPTX device offloading toolchain ONLY, 
this functionality can be extended to other platforms/system where:

- the device toolchain can produce a host-compatible object AND
- partial linking of host objects is supported.

**The solution:**
The solution enables the OpenMP NVPTX toolchain to produce an object file which 
is host-compatible (when compiling with -c). The host-compatible file is 
produced using several steps:
Step 1 (already exists): invoke PTXAS on the .s file to obtain a .cubin.
Step 2 (new step): invoke the FATBIN tool (this tool comes with every standard 
CUDA installation) which creates a CUDA fatbinary that contains both the PTX 
code (the .s file) and the .cubin file. This same tool can wrap the resulting 
.fatbin file in a C/C++ wrapper thus creating a .fatbin.c file.
Step 3 (new step): call clang++ on the .fatbin.c file to create a .o file which 
is host-compatible.

Once this device side host-compatible file is produced for the NVPTX toolchain 
then one further step is needed:
Step 4 (new step): invoke a linker supporting partial linking (currently using 
"ld -r") to link host-compatible object file against the original host file and 
end up with one single object file which I can now safely pass to another 
compiler or include in a static library (new step).

**Passing final object file to clang:**
This file doesn't require unbundling so call to "clang-offload-bundler 
--unbundle" is NOT required.
The compiler needs to be notified that the object file contains an "offloaded 
device part" by using: "-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda". This 
will invoke the OpenMP NVPTX toolchain and it will call only NVLINK on this 
file.

**Passing final object file to clang inside a static lib "libabc.a" passed to 
clang via: "-L/path/to/lib/folder -labc":**
Call clang with "-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda" to trigger 
NVPTX toolchain.
The -L path along with the -labc will be passed to NVLINK which will perform 
the "static linking".


Repository:
  rC Clang

https://reviews.llvm.org/D47394

Files:
  include/clang/Driver/Action.h
  include/clang/Driver/Compilation.h
  include/clang/Driver/Driver.h
  include/clang/Driver/ToolChain.h
  lib/Driver/Action.cpp
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Clang.h
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c
  test/Driver/openmp-offload.c

Index: test/Driver/openmp-offload.c
===
--- test/Driver/openmp-offload.c
+++ test/Driver/openmp-offload.c
@@ -480,13 +480,13 @@
 // Create host object and bundle.
 // CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-BUJOBS-SAME: 

[PATCH] D47225: Add nonnull; use it for atomics

2018-05-25 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM

(FYI, Please use a weekly frequency for Pings).


Repository:
  rCXX libc++

https://reviews.llvm.org/D47225



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


[PATCH] D47393: [clang-format] Disable AlwaysBreakBeforeMultilineStrings in Google style for Objective-C 

2018-05-25 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 148672.

Repository:
  rC Clang

https://reviews.llvm.org/D47393

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1193,6 +1193,18 @@
"}");
 }
 
+TEST_F(FormatTestObjC, AlwaysBreakBeforeMultilineStrings) {
+  Style = getGoogleStyle();
+  verifyFormat(" = @\"\"\n"
+   "   @\"\";");
+  verifyFormat("(@\"\"\n"
+   " @\"\");");
+  verifyFormat("(qqq, @\"\"\n"
+   "  @\"\");");
+  verifyFormat("NSString *const kString = @\"\"\n"
+   "  @\"\");");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -799,6 +799,7 @@
 // has been implemented.
 GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
   }
 


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1193,6 +1193,18 @@
"}");
 }
 
+TEST_F(FormatTestObjC, AlwaysBreakBeforeMultilineStrings) {
+  Style = getGoogleStyle();
+  verifyFormat(" = @\"\"\n"
+   "   @\"\";");
+  verifyFormat("(@\"\"\n"
+   " @\"\");");
+  verifyFormat("(qqq, @\"\"\n"
+   "  @\"\");");
+  verifyFormat("NSString *const kString = @\"\"\n"
+   "  @\"\");");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -799,6 +799,7 @@
 // has been implemented.
 GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46550: Support Swift calling convention for PPC64 targets

2018-05-25 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson closed this revision.
bob.wilson added a comment.

Committed in Clang r16


Repository:
  rC Clang

https://reviews.llvm.org/D46550



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


r333316 - Support Swift calling convention for PPC64 targets

2018-05-25 Thread Bob Wilson via cfe-commits
Author: bwilson
Date: Fri May 25 14:26:03 2018
New Revision: 16

URL: http://llvm.org/viewvc/llvm-project?rev=16=rev
Log:
Support Swift calling convention for PPC64 targets

This adds basic support for the Swift calling convention with PPC64 targets.
Patch provided by Atul Sowani in bug report #37223

Modified:
cfe/trunk/lib/Basic/Targets/PPC.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/Basic/Targets/PPC.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.h?rev=16=15=16=diff
==
--- cfe/trunk/lib/Basic/Targets/PPC.h (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.h Fri May 25 14:26:03 2018
@@ -335,6 +335,15 @@ public:
 }
 return false;
   }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_Swift:
+  return CCCR_OK;
+default:
+  return CCCR_Warning;
+}
+  }
 };
 
 class LLVM_LIBRARY_VISIBILITY DarwinPPC32TargetInfo

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=16=15=16=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Fri May 25 14:26:03 2018
@@ -4287,7 +4287,7 @@ PPC32TargetCodeGenInfo::initDwarfEHRegSi
 
 namespace {
 /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
-class PPC64_SVR4_ABIInfo : public ABIInfo {
+class PPC64_SVR4_ABIInfo : public SwiftABIInfo {
 public:
   enum ABIKind {
 ELFv1 = 0,
@@ -4331,7 +4331,7 @@ private:
 public:
   PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes , ABIKind Kind, bool HasQPX,
  bool SoftFloatABI)
-  : ABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
+  : SwiftABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
 IsSoftFloatABI(SoftFloatABI) {}
 
   bool isPromotableTypeForABI(QualType Ty) const;
@@ -4374,6 +4374,15 @@ public:
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
 QualType Ty) const override;
+
+  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
+bool asReturnValue) const override {
+return occupiesMoreThan(CGT, scalars, /*total*/ 4);
+  }
+
+  bool isSwiftErrorInRegister() const override {
+return false;
+  }
 };
 
 class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {


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


[PATCH] D47393: [clang-format] Disable AlwaysBreakBeforeMultilineStrings in Google style for Objective-C 

2018-05-25 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore created this revision.
Herald added subscribers: cfe-commits, klimek.

Repository:
  rC Clang

https://reviews.llvm.org/D47393

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1193,6 +1193,22 @@
"}");
 }
 
+TEST_F(FormatTestObjC, AlwaysBreakBeforeMultilineStrings) {
+  FormatStyle Style = getGoogleStyle();
+  verifyFormat(" = @\"\"\n"
+   "   @\"\";",
+   Style);
+  verifyFormat("(@\"\"\n"
+   " @\"\");",
+   Style);
+  verifyFormat("(qqq, @\"\"\n"
+   "  @\"\");",
+   Style);
+  verifyFormat("NSString *const kString = @\"\"\n"
+   "  @\"\");",
+   Style);
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -799,6 +799,7 @@
 // has been implemented.
 GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
   }
 


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1193,6 +1193,22 @@
"}");
 }
 
+TEST_F(FormatTestObjC, AlwaysBreakBeforeMultilineStrings) {
+  FormatStyle Style = getGoogleStyle();
+  verifyFormat(" = @\"\"\n"
+   "   @\"\";",
+   Style);
+  verifyFormat("(@\"\"\n"
+   " @\"\");",
+   Style);
+  verifyFormat("(qqq, @\"\"\n"
+   "  @\"\");",
+   Style);
+  verifyFormat("NSString *const kString = @\"\"\n"
+   "  @\"\");",
+   Style);
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -799,6 +799,7 @@
 // has been implemented.
 GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-25 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D46918



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


[libcxx] r333315 - Fix array deduction guide test breakage

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 14:17:43 2018
New Revision: 15

URL: http://llvm.org/viewvc/llvm-project?rev=15=rev
Log:
Fix array deduction guide test breakage

No matching constructor

Modified:
libcxx/trunk/test/std/containers/sequences/array/array.cons/deduct.pass.cpp

Modified: 
libcxx/trunk/test/std/containers/sequences/array/array.cons/deduct.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/array.cons/deduct.pass.cpp?rev=15=14=15=diff
==
--- libcxx/trunk/test/std/containers/sequences/array/array.cons/deduct.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/sequences/array/array.cons/deduct.pass.cpp 
Fri May 25 14:17:43 2018
@@ -51,6 +51,8 @@ int main()
 }
 
 //  Test the implicit deduction guides
+// FIXME broken: no matching constructor
+#if 0
   {
   std::array source = {4.0, 5.0};
   std::array arr(source);   // array(array)
@@ -59,4 +61,5 @@ int main()
 assert(arr[0] == 4.0);
 assert(arr[1] == 5.0);
   }
+#endif
 }


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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Ok! Putting any remaining work into follow-up patches would be great indeed. 
Let's land this into `alpha.cplusplus` for now because i still haven't made up 
my mind for how to organize the proposed `bugprone` category (sorry!).




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:223-225
+  ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
+  if (!Node)
+return;

Szelethus wrote:
> NoQ wrote:
> > I suspect that a fatal error is better here. We don't want the user to 
> > receive duplicate report from other checkers that catch uninitialized 
> > values; just one report is enough.
> I think that would be a bad idea. For example, this checker shouts so loudly 
> while checking the LLVM project, it would practically halt the analysis of 
> the code, reducing the coverage, which means that checkers other then uninit 
> value checkers would "suffer" from it.
> 
> However, I also think that having multiple uninit reports for the same object 
> might be good, especially with this checker, as it would be very easy to see 
> where the problem originated from.
> 
> What do you think?
Well, i guess that's the reason to not use the checker on LLVM. Regardless of 
fatal/nonfatal warnings, enabling this checker on LLVM regularly would be a bad 
idea because it's unlikely that anybody will be able to fix all the false 
positives to make it usable. And for other projects that don't demonstrate many 
false positives, this shouldn't be a problem.

In order to indicate where the problem originates from, we have our bug 
reporter visitors that try their best to add such info directly to the report. 
In particular, @george.karpenkov's recent `NoStoreFuncVisitor` highlights 
functions in which a variable was //not// initialized but was probably expected 
to be. Not sure if it highlights constructors in its current shape, but that's 
definitely a better way to give this piece of information to the user because 
it doesn't make the user look for a different report to understand the current 
report.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:258-260
+Report->addNote(NoteBuf,
+PathDiagnosticLocation::create(FieldChain.getEndOfChain(),
+   
Context.getSourceManager()));

Szelethus wrote:
> NoQ wrote:
> > NoQ wrote:
> > > Szelethus wrote:
> > > > NoQ wrote:
> > > > > Aha, ok, got it, so you're putting the warning at the end of the 
> > > > > constructor and squeezing all uninitialized fields into a single 
> > > > > warning by presenting them as notes.
> > > > > 
> > > > > Because for now notes aren't supported everywhere (and aren't always 
> > > > > supported really well), i guess it'd be necessary to at least provide 
> > > > > an option to make note-less reports before the checker is enabled by 
> > > > > default everywhere. In this case notes contain critical pieces of 
> > > > > information and as such cannot be really discarded.
> > > > > 
> > > > > I'm not sure that notes are providing a better user experience here 
> > > > > than simply saying that "field x.y->z is never initialized". With 
> > > > > notes, the user will have to scroll around (at least in scan-build) 
> > > > > to find which field is uninitialized.
> > > > > 
> > > > > Notes will probably also not decrease the number of reports too much 
> > > > > because in most cases there will be just one uninitialized field. 
> > > > > Though i agree that when there is more than one report, the user will 
> > > > > be likely to deal with all fields at once rather than separately.
> > > > > 
> > > > > So it's a bit wonky.
> > > > > 
> > > > > We might want to enable one mode or another in the checker depending 
> > > > > on the analyzer output flag. Probably in the driver 
> > > > > (`RenderAnalyzerOptions()`).
> > > > > 
> > > > > It'd be a good idea to land the checker into alpha first and fix this 
> > > > > in a follow-up patch because this review is already overweight.
> > > > > [...]i guess it'd be necessary to at least provide an option to make 
> > > > > note-less reports before the checker is enabled by default 
> > > > > everywhere. In this case notes contain critical pieces of information 
> > > > > and as such cannot be really discarded.
> > > > This can already be achieved with `-analyzer-config 
> > > > notes-as-events=true`. There no good reason however not to make an 
> > > > additional flag that would emit warnings instead of notes.
> > > > > I'm not sure that notes are providing a better user experience here 
> > > > > than simply saying that "field x.y->z is never initialized". With 
> > > > > notes, the user will have to scroll around (at least in scan-build) 
> > > > > to find which field is uninitialized.
> > > > This checker had a previous implementation that emitted a warning for 
> > > > each uninitialized 

[PATCH] D47340: [ClangDiagnostics] Silence warning about fallthrough after PrintFatalError

2018-05-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Ok?


https://reviews.llvm.org/D47340



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


[PATCH] D47260: [DebugInfo] Skip MD5 checksums of preprocessed files

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
probinson marked an inline comment as done.
Closed by commit rL11: [DebugInfo] Dont bother with MD5 checksums of 
preprocessed files. (authored by probinson, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47260?vs=148663=148668#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47260

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/test/CodeGen/md5-checksum-crash.c


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
+  if (Invalid || !Entry.isFile())
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+// This must be a preprocessed file; its content won't match the original
+// source; therefore checksumming the text we have is pointless or wrong.
+EmitFileChecksums = false;
+return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -57,6 +57,7 @@
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;
Index: cfe/trunk/test/CodeGen/md5-checksum-crash.c
===
--- cfe/trunk/test/CodeGen/md5-checksum-crash.c
+++ cfe/trunk/test/CodeGen/md5-checksum-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited 
-dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited 
%s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
+  if (Invalid || !Entry.isFile())
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+// This must be a preprocessed file; its content won't match the original
+// source; therefore checksumming the text we have is pointless or wrong.
+EmitFileChecksums = false;
+return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -57,6 +57,7 @@
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool 

[PATCH] D47260: [DebugInfo] Skip MD5 checksums of preprocessed files

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
probinson marked an inline comment as done.
Closed by commit rC11: [DebugInfo] Dont bother with MD5 checksums of 
preprocessed files. (authored by probinson, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47260?vs=148663=148667#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47260

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGen/md5-checksum-crash.c


Index: test/CodeGen/md5-checksum-crash.c
===
--- test/CodeGen/md5-checksum-crash.c
+++ test/CodeGen/md5-checksum-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited 
-dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited 
%s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
+  if (Invalid || !Entry.isFile())
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+// This must be a preprocessed file; its content won't match the original
+// source; therefore checksumming the text we have is pointless or wrong.
+EmitFileChecksums = false;
+return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -57,6 +57,7 @@
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;


Index: test/CodeGen/md5-checksum-crash.c
===
--- test/CodeGen/md5-checksum-crash.c
+++ test/CodeGen/md5-checksum-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited %s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );

r333311 - [DebugInfo] Don't bother with MD5 checksums of preprocessed files.

2018-05-25 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Fri May 25 13:59:29 2018
New Revision: 11

URL: http://llvm.org/viewvc/llvm-project?rev=11=rev
Log:
[DebugInfo] Don't bother with MD5 checksums of preprocessed files.

The checksum will not reflect the real source, so there's no clear
reason to include them in the debug info.  Also this was causing a
crash on the DWARF side.

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

Added:
cfe/trunk/test/CodeGen/md5-checksum-crash.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=11=10=11=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri May 25 13:59:29 2018
@@ -67,6 +67,8 @@ CGDebugInfo::CGDebugInfo(CodeGenModule &
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@ Optional
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
+  if (Invalid || !Entry.isFile())
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+// This must be a preprocessed file; its content won't match the original
+// source; therefore checksumming the text we have is pointless or wrong.
+EmitFileChecksums = false;
+return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=11=10=11=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri May 25 13:59:29 2018
@@ -57,6 +57,7 @@ class CGDebugInfo {
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;

Added: cfe/trunk/test/CodeGen/md5-checksum-crash.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/md5-checksum-crash.c?rev=11=auto
==
--- cfe/trunk/test/CodeGen/md5-checksum-crash.c (added)
+++ cfe/trunk/test/CodeGen/md5-checksum-crash.c Fri May 25 13:59:29 2018
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited 
-dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited 
%s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")


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


[PATCH] D47260: [DebugInfo] Skip MD5 checksums of preprocessed files

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson marked an inline comment as done.
probinson added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:378
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+EmitFileChecksums = false;

aprantl wrote:
> Can you add a comment explaining why we are doing this here?
Of course.


https://reviews.llvm.org/D47260



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


[PATCH] D47260: [DebugInfo] Skip MD5 checksums of preprocessed files

2018-05-25 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Minor comment inline.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:378
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+EmitFileChecksums = false;

Can you add a comment explaining why we are doing this here?


https://reviews.llvm.org/D47260



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


[libcxx] r333308 - Fix optional deduction guide test breakage

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 13:43:57 2018
New Revision: 08

URL: http://llvm.org/viewvc/llvm-project?rev=08=rev
Log:
Fix optional deduction guide test breakage

Modified:

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp?rev=08=07=08=diff
==
--- 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp
 Fri May 25 13:43:57 2018
@@ -28,7 +28,7 @@ int main()
 //  Test the implicit deduction guides
 {
 //  optional()
-std::optional opt;   // expected-error {{no viable constructor or 
deduction guide for deduction of template arguments of 'optional'}}
+std::optional opt;   // expected-error {{declaration of variable 'opt' 
with deduced type 'std::optional' requires an initializer}}
 }
 
 {

Modified: 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp?rev=08=07=08=diff
==
--- 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp
 Fri May 25 13:43:57 2018
@@ -45,7 +45,7 @@ int main()
 //  optional(const optional &);
 std::optional source('A');
 std::optional opt(source);
-static_assert(std::is_same_v, "");
+static_assert(std::is_same_v>, "");
 assert(static_cast(opt) == static_cast(source));
 assert(*opt == *source);
 }


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


[PATCH] D47260: [DebugInfo] Skip MD5 checksums of preprocessed files

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson updated this revision to Diff 148663.
probinson added a comment.

Upload patch to suppress checksums when we see a preprocessed file.


https://reviews.llvm.org/D47260

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/md5-checksum-crash.c


Index: clang/test/CodeGen/md5-checksum-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/md5-checksum-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited 
-dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited 
%s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -57,6 +57,7 @@
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,19 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, );
-  if (Invalid)
+  const SrcMgr::SLocEntry  = SM.getSLocEntry(FID, );
+  if (Invalid || !Entry.isFile())
 return None;
+  if (Entry.getFile().hasLineDirectives()) {
+EmitFileChecksums = false;
+return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;


Index: clang/test/CodeGen/md5-checksum-crash.c
===
--- /dev/null
+++ clang/test/CodeGen/md5-checksum-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited %s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -57,6 +57,7 @@
   CodeGenModule 
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -67,6 +67,8 @@
   DBuilder(CGM.getModule()) {
   for (const auto  : CGM.getCodeGenOpts().DebugPrefixMap)
 DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+  CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,19 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-  CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
 return None;
 
   SourceManager  = CGM.getContext().getSourceManager();
   bool Invalid;
-  

r333307 - [Support] Avoid normalization in sys::getDefaultTargetTriple

2018-05-25 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri May 25 13:39:37 2018
New Revision: 07

URL: http://llvm.org/viewvc/llvm-project?rev=07=rev
Log:
[Support] Avoid normalization in sys::getDefaultTargetTriple

The return value of sys::getDefaultTargetTriple, which is derived from
-DLLVM_DEFAULT_TRIPLE, is used to construct tool names, default target,
and in the future also to control the search path directly; as such it
should be used textually, without interpretation by LLVM.

Normalization of this value may lead to unexpected results, for example
if we configure LLVM with -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-linux-gnu,
normalization will transform that value to x86_64--linux-gnu. Driver will
use that value to search for tools prefixed with x86_64--linux-gnu- which
may be confusing. This is also inconsistent with the behavior of the
--target flag which is taken as-is without any normalization and overrides
the value of LLVM_DEFAULT_TARGET_TRIPLE.

Users of sys::getDefaultTargetTriple already perform their own
normalization as needed, so this change shouldn't impact existing logic.

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

Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=07=06=07=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri May 25 13:39:37 2018
@@ -2930,10 +2930,11 @@ static void ParseTargetArgs(TargetOption
   Opts.FPMath = Args.getLastArgValue(OPT_mfpmath);
   Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
   Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
-  Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
+  Opts.Triple = Args.getLastArgValue(OPT_triple);
   // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
 Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  Opts.Triple = llvm::Triple::normalize(Opts.Triple);
   Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
   Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
   Opts.NVPTXUseShortPointers = Args.hasFlag(


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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-05-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D41039#984009, @ahatanak wrote:

> Yes, please document this in itanium-cxx-abi. Thanks!


Looks like this hasn't happened yet.


Repository:
  rL LLVM

https://reviews.llvm.org/D41039



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


[PATCH] D45897: Convert clang-interpreter to ORC JIT API

2018-05-25 Thread Stephane Sezer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL02: Convert clang-interpreter to ORC JIT API (authored 
by sas, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45897?vs=143376=148656#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45897

Files:
  cfe/trunk/examples/clang-interpreter/CMakeLists.txt
  cfe/trunk/examples/clang-interpreter/Invoke.cpp
  cfe/trunk/examples/clang-interpreter/Invoke.h
  cfe/trunk/examples/clang-interpreter/Manager.cpp
  cfe/trunk/examples/clang-interpreter/Manager.h
  cfe/trunk/examples/clang-interpreter/main.cpp

Index: cfe/trunk/examples/clang-interpreter/CMakeLists.txt
===
--- cfe/trunk/examples/clang-interpreter/CMakeLists.txt
+++ cfe/trunk/examples/clang-interpreter/CMakeLists.txt
@@ -12,8 +12,6 @@
 
 add_clang_executable(clang-interpreter
   main.cpp
-  Invoke.cpp
-  Manager.cpp
   )
 
 add_dependencies(clang-interpreter
Index: cfe/trunk/examples/clang-interpreter/main.cpp
===
--- cfe/trunk/examples/clang-interpreter/main.cpp
+++ cfe/trunk/examples/clang-interpreter/main.cpp
@@ -7,11 +7,8 @@
 //
 //===--===//
 
-#include "Invoke.h"
-#include "Manager.h"
-
-#include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Tool.h"
@@ -21,37 +18,24 @@
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
+#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Mangler.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetMachine.h"
 
 using namespace clang;
 using namespace clang::driver;
 
-namespace interpreter {
-
-static llvm::ExecutionEngine *
-createExecutionEngine(std::unique_ptr M, std::string *ErrorStr) {
-  llvm::EngineBuilder EB(std::move(M));
-  EB.setErrorStr(ErrorStr);
-  EB.setMemoryManager(llvm::make_unique());
-  llvm::ExecutionEngine *EE = EB.create();
-  EE->finalizeObject();
-  return EE;
-}
-
-// Invoked from a try/catch block in invoke.cpp.
-//
-static int Invoke(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
-  const std::vector , char *const *EnvP) {
-  return EE->runFunctionAsMain(EntryFn, Args, EnvP);
-}
-
 // This function isn't referenced outside its translation unit, but it
 // can't use the "static" keyword because its address is used for
 // GetMainExecutable (since some platforms don't support taking the
@@ -61,13 +45,76 @@
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-} // namespace interpreter
+namespace llvm {
+namespace orc {
+
+class SimpleJIT {
+private:
+  ExecutionSession ES;
+  std::shared_ptr Resolver;
+  std::unique_ptr TM;
+  const DataLayout DL;
+  RTDyldObjectLinkingLayer ObjectLayer;
+  IRCompileLayer CompileLayer;
+
+public:
+  SimpleJIT()
+  : Resolver(createLegacyLookupResolver(
+ES,
+[this](const std::string ) -> JITSymbol {
+  if (auto Sym = CompileLayer.findSymbol(Name, false))
+return Sym;
+  else if (auto Err = Sym.takeError())
+return std::move(Err);
+  if (auto SymAddr =
+  RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+  return nullptr;
+},
+[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
+TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ObjectLayer(ES,
+[this](VModuleKey) {
+  return RTDyldObjectLinkingLayer::Resources{
+  std::make_shared(), Resolver};
+}),
+CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
+llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
+  }
+
+  const TargetMachine () const { return *TM; }
 
-int main(int argc, const char **argv, char * const *envp) {
+  VModuleKey addModule(std::unique_ptr M) {
+// Add the module to the JIT with a new VModuleKey.
+auto K = ES.allocateVModule();
+

r333301 - [OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

2018-05-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri May 25 13:16:03 2018
New Revision: 01

URL: http://llvm.org/viewvc/llvm-project?rev=01=rev
Log:
[OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

If orphaned parallel region is found, the next code must be emitted:
```
if(__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid))
  Serialized execution.
else if (IsMasterThread())
  Prepare and signal worker.
else
  Outined function call.
```

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=01=00=01=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri May 25 13:16:03 2018
@@ -1845,35 +1845,21 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   RCG(CGF);
 } else {
   // Check for master and then parallelism:
-  // if (__kmpc_is_spmd_exec_mode()) {
+  // if (__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid)) {
   //  Serialized execution.
-  // } else if (is_master) {
+  // } else if (master) {
   //   Worker call.
-  // } else if (__kmpc_parallel_level(loc, gtid)) {
-  //   Serialized execution.
   // } else {
   //   Outlined function call.
   // }
   CGBuilderTy  = CGF.Builder;
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
-  llvm::BasicBlock *SPMDCheckBB = CGF.createBasicBlock(".spmdcheck");
+  llvm::BasicBlock *SeqBB = CGF.createBasicBlock(".sequential");
+  llvm::BasicBlock *ParallelCheckBB = CGF.createBasicBlock(".parcheck");
   llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
-  llvm::BasicBlock *ParallelCheckBB =
-  CGF.createBasicBlock(".parallelcheck");
   llvm::Value *IsSPMD = Bld.CreateIsNotNull(CGF.EmitNounwindRuntimeCall(
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_is_spmd_exec_mode)));
-  Bld.CreateCondBr(IsSPMD, SPMDCheckBB, MasterCheckBB);
-  CGF.EmitBlock(SPMDCheckBB);
-  SeqGen(CGF, Action);
-  CGF.EmitBranch(ExitBB);
-  CGF.EmitBlock(MasterCheckBB);
-  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
-  llvm::Value *IsMaster =
-  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-  Bld.CreateCondBr(IsMaster, MasterThenBB, ParallelCheckBB);
-  CGF.EmitBlock(MasterThenBB);
-  L0ParallelGen(CGF, Action);
-  CGF.EmitBranch(ExitBB);
+  Bld.CreateCondBr(IsSPMD, SeqBB, ParallelCheckBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
   CGF.EmitBlock(ParallelCheckBB);
@@ -1883,15 +1869,23 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_parallel_level),
   {RTLoc, ThreadID});
   llvm::Value *Res = Bld.CreateIsNotNull(PL);
-  llvm::BasicBlock *ThenBlock = CGF.createBasicBlock("omp_if.then");
-  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
-  Bld.CreateCondBr(Res, ThenBlock, ElseBlock);
-  // Emit the 'then' code.
-  CGF.EmitBlock(ThenBlock);
+  Bld.CreateCondBr(Res, SeqBB, MasterCheckBB);
+  CGF.EmitBlock(SeqBB);
   SeqGen(CGF, Action);
+  CGF.EmitBranch(ExitBB);
+  // There is no need to emit line number for unconditional branch.
+  (void)ApplyDebugLocation::CreateEmpty(CGF);
+  CGF.EmitBlock(MasterCheckBB);
+  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
+  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
+  llvm::Value *IsMaster =
+  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
+  Bld.CreateCondBr(IsMaster, MasterThenBB, ElseBlock);
+  CGF.EmitBlock(MasterThenBB);
+  L0ParallelGen(CGF, Action);
+  CGF.EmitBranch(ExitBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
-  // Emit the 'else' code.
   CGF.EmitBlock(ElseBlock);
   RCG(CGF);
   // There is no need to emit line number for unconditional branch.

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=01=00=01=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Fri May 25 13:16:03 2018
@@ -566,6 +566,10 @@ int baz(int f, double ) {
   // CHECK: icmp ne i8 [[RES]], 0
   // CHECK: br i1
 
+  // CHECK: [[RES:%.+]] = call i16 @__kmpc_parallel_level(%struct.ident_t* 
@{{.+}}, i32 

[PATCH] D46918: [Coverage] Discard the last uncompleted deferred region in a decl

2018-05-25 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Ping.


https://reviews.llvm.org/D46918



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


[PATCH] D47260: Testcase for dwarf 5 crash/assert when calculating a checksum for an expansion

2018-05-25 Thread Tom Rix via Phabricator via cfe-commits
trixirt added a comment.

commandeer away!
Sure that is fine.


Repository:
  rC Clang

https://reviews.llvm.org/D47260



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


[PATCH] D46845: [libcxx][c++17] P0083R5: Splicing Maps and Sets

2018-05-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D46845#1105638, @erik.pilkington wrote:

> make __map_node_handle use a const_cast on the key instead of type-punning 
> between pair and pair. Add calls to std::launder in key() 
> and before inserting a node handle.


Can you do this as a separate change, prior to adding node_handle? I would in 
particular expect this to result in the removal of the `union __value_type` 
from .


https://reviews.llvm.org/D46845



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


[PATCH] D46823: [analyzer] const init: handle non-explicit cases more accurately

2018-05-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks good!

Do you have commit access? I think you should get commit access.




Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650
+
+// If there is a list, but no init, it must be zero.
+if (i >= InitList->getNumInits())

r.stahl wrote:
> r.stahl wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > Would this work correctly if the element is not of an integral or 
> > > > enumeration type? I think this needs an explicit check.
> > > What if we have an out-of-bounds access to a variable-length array? I 
> > > don't think it'd yield zero.
> > I'm getting "variable-sized object may not be initialized", so this case 
> > should not be possible.
> I'm having a hard time reproducing this either.
> 
> 
> ```
> struct S {
>   int a = 3;
> };
> S const sarr[2] = {};
> void definit() {
>   int i = 1;
>   clang_analyzer_dump(sarr[i].a); // expected-warning{{test}}
> }
> ```
> 
> results in a symbolic value, because makeZeroVal returns an empty SVal list 
> for arrays, records, vectors and complex types. Otherwise it just returns 
> UnknownVal (for example for not-yet-implemented floats).
> 
> Can you think of a case where this would be an issue?
Yup, sounds reasonable.



Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650-1652
+// If there is a list, but no init, it must be zero.
+if (i >= InitList->getNumInits())
+  return svalBuilder.makeZeroVal(R->getElementType());

NoQ wrote:
> r.stahl wrote:
> > r.stahl wrote:
> > > NoQ wrote:
> > > > NoQ wrote:
> > > > > Would this work correctly if the element is not of an integral or 
> > > > > enumeration type? I think this needs an explicit check.
> > > > What if we have an out-of-bounds access to a variable-length array? I 
> > > > don't think it'd yield zero.
> > > I'm getting "variable-sized object may not be initialized", so this case 
> > > should not be possible.
> > I'm having a hard time reproducing this either.
> > 
> > 
> > ```
> > struct S {
> >   int a = 3;
> > };
> > S const sarr[2] = {};
> > void definit() {
> >   int i = 1;
> >   clang_analyzer_dump(sarr[i].a); // expected-warning{{test}}
> > }
> > ```
> > 
> > results in a symbolic value, because makeZeroVal returns an empty SVal list 
> > for arrays, records, vectors and complex types. Otherwise it just returns 
> > UnknownVal (for example for not-yet-implemented floats).
> > 
> > Can you think of a case where this would be an issue?
> Yup, sounds reasonable.
Had a look. This indeed looks fine, but for a completely different reason. In 
fact structs don't appear in `getBindingForElement()` because they all go 
through `getBindingForStruct()` instead. Hopefully this does take care of other 
cornercases.

So your test case doesn't even trigger your code to be executed, neither would 
`S s = sarr[i]; clang_analyzer_dump(s.a);`.

Still, as far as i understand, `sarr` here should be zero-initialized, so i 
think the symbolic value can be improved upon, so we might as well add this as 
a FIXME test.


https://reviews.llvm.org/D46823



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


[PATCH] D46084: [Fixed Point Arithmetic] Addition of the Fixed Point _Accum type

2018-05-25 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan marked 2 inline comments as done.
leonardchan added inline comments.



Comment at: include/clang/Driver/Options.td:882
 
+def enable_fixed_point : Flag<["-", "--"], "enable-fixed-point">, 
Group,
+ Flags<[CC1Option]>, HelpText<"Enable fixed point 
types">;

ebevhan wrote:
> Shouldn't this be an `-f` flag, like `-ffixed-point`? I'm not for or against 
> either, just wondering what anyone else thinks.
Makes sense since this flag is target independent.


Repository:
  rC Clang

https://reviews.llvm.org/D46084



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


[PATCH] D46084: [Fixed Point Arithmetic] Addition of the Fixed Point _Accum type

2018-05-25 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 148637.
leonardchan added a comment.

Changed flag names


Repository:
  rC Clang

https://reviews.llvm.org/D46084

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/TokenKinds.def
  include/clang/Driver/Options.td
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/Basic/TargetInfo.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Index/USRGeneration.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/Frontend/fixed_point.c
  test/Frontend/fixed_point_bit_widths.c
  test/Frontend/fixed_point_errors.c
  test/Frontend/fixed_point_errors.cpp
  test/Frontend/fixed_point_not_enabled.c
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -53,6 +53,12 @@
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
+BTCASE(ShortAccum);
+BTCASE(Accum);
+BTCASE(LongAccum);
+BTCASE(UShortAccum);
+BTCASE(UAccum);
+BTCASE(ULongAccum);
 BTCASE(Float16);
 BTCASE(Float128);
 BTCASE(NullPtr);
@@ -546,6 +552,12 @@
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);
+TKIND(ShortAccum);
+TKIND(Accum);
+TKIND(LongAccum);
+TKIND(UShortAccum);
+TKIND(UAccum);
+TKIND(ULongAccum);
 TKIND(Float16);
 TKIND(Float128);
 TKIND(NullPtr);
Index: test/Frontend/fixed_point_not_enabled.c
===
--- /dev/null
+++ test/Frontend/fixed_point_not_enabled.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x c -verify %s
+// RUN: %clang_cc1 -x c -fno-fixed-point -verify %s
+
+// Primary fixed point types
+signed short _Accum s_short_accum;// expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+signed _Accum s_accum;// expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+signed long _Accum s_long_accum;  // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+unsigned short _Accum u_short_accum;  // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+unsigned _Accum u_accum;  // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+unsigned long _Accum u_long_accum;// expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+
+// Aliased fixed point types
+short _Accum short_accum; // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+_Accum accum; // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
+  // expected-warning@-1{{type specifier missing, defaults to 'int'}}
+long _Accum long_accum;   // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
Index: test/Frontend/fixed_point_errors.cpp
===
--- /dev/null
+++ test/Frontend/fixed_point_errors.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -ffixed-point %s -verify
+
+// Name namgling is not provided for fixed point types in c++
+
+signed short _Accum s_short_accum;  // expected-error{{fixed point types are only allowed in C}}
+signed _Accum s_accum;  // expected-error{{fixed point types are only allowed in C}}
+signed long _Accum s_long_accum;// expected-error{{fixed point types are only allowed in C}}
+unsigned short _Accum u_short_accum;// expected-error{{fixed point types are only allowed in C}}
+unsigned _Accum u_accum;// expected-error{{fixed point types are only allowed in C}}
+unsigned long _Accum u_long_accum;  // expected-error{{fixed point types are only allowed in C}}
+
+short _Accum short_accum;   // expected-error{{fixed point types are only allowed in C}}
+_Accum accum;   // expected-error{{fixed point types are only allowed in C}}
+// expected-error@-1{{C++ requires a type specifier for all declarations}}
+long _Accum long_accum; // expected-error{{fixed point types are only allowed in C}}
Index: 

[PATCH] D47067: Update NRVO logic to support early return

2018-05-25 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Just commenting to say that this LGTM and I have no further nitpicks.  I have 
verified that I cannot detect any change in the behavior of 
`-Wpessimizing-move` or `-Wreturn-std-move` due to this change (and I //can// 
successfully detect the additional copy-elision due to this change, hooray).


Repository:
  rC Clang

https://reviews.llvm.org/D47067



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


[PATCH] D47291: Proposal to make rtti errors more generic.

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6729
 def err_no_dynamic_cast_with_fno_rtti : Error<
-  "cannot use dynamic_cast with -fno-rtti">;
+  "use of dynamic_cast requires enabling RTTI">;
 

filcab wrote:
> I'd prefer to have the way to enable RTTI mentioned in the message. Could we 
> have something like `ToolChain::getRTTIMode()` and have a "RTTI was on/of" or 
> "RTTI defaulted to on/off"? That way we'd be able to have a message similar 
> to the current one (mentioning "you passed -fno-rtti") on platforms that 
> default to RTTI=on, and have your updated message (possibly with a mention of 
> "use -frtti") on platforms that default to RTTI=off.
> 
> (This is a minor usability comment about this patch, I don't consider it a 
> blocker or anything)
If the options are spelled differently for clang-cl and we had a way to 
retrieve the appropriate spellings, providing the option to use in the 
diagnostic does seem like a nice touch.


Repository:
  rC Clang

https://reviews.llvm.org/D47291



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


[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

2018-05-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think the approach makes sense.




Comment at: lib/CodeGen/CGObjCMac.cpp:7457-7460
 CGObjCNonFragileABIMac::GetEHType(QualType T) {
   // There's a particular fixed type info for 'id'.
   if (T->isObjCIdType() || T->isObjCQualifiedIdType()) {
+if (CGM.getTriple().isWindowsMSVCEnvironment())

@rjmccall how should this be organized in the long run? At this point, the 
naming seems totally wrong. Is the non-fragile ABI sort of the canonical way 
forward for Obj-C, i.e. it's what a new platform would want to use to best stay 
in sync with the future of obj-c?


Repository:
  rC Clang

https://reviews.llvm.org/D47233



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


[PATCH] D47229: Make atomic non-member functions as nonnull

2018-05-25 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

Fixed by r333290.


Repository:
  rL LLVM

https://reviews.llvm.org/D47229



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


r333290 - Follow-up fix for nonnull atomic non-member functions

2018-05-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri May 25 10:36:49 2018
New Revision: 333290

URL: http://llvm.org/viewvc/llvm-project?rev=333290=rev
Log:
Follow-up fix for nonnull atomic non-member functions

Handling of the third parameter was only checking for *_n and not for the C11 
variant, which means that cmpxchg of a 'desired' 0 value was erroneously 
warning. Handle C11 properly, and add extgensive tests for this as well as NULL 
pointers in a bunch of places.

Fixes r333246 from D47229.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/atomic-ops.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=333290=333289=333290=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri May 25 10:36:49 2018
@@ -3519,8 +3519,8 @@ ExprResult Sema::SemaAtomicOpsOverloaded
 break;
   case 2:
 // The third argument to compare_exchange / GNU exchange is the desired
-// value, either by-value (for the *_n variant) or as a pointer.
-if (!IsN)
+// value, either by-value (for the C11 and *_n variant) or as a 
pointer.
+if (IsPassedByAddress)
   CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getLocStart());
 Ty = ByValType;
 break;

Modified: cfe/trunk/test/Sema/atomic-ops.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/atomic-ops.c?rev=333290=333289=333290=diff
==
--- cfe/trunk/test/Sema/atomic-ops.c (original)
+++ cfe/trunk/test/Sema/atomic-ops.c Fri May 25 10:36:49 2018
@@ -530,11 +530,15 @@ void memory_checks(_Atomic(int) *Ap, int
   (void)__atomic_compare_exchange_n(p, p, val, 0, memory_order_seq_cst, 
memory_order_relaxed);
 }
 
-void nullPointerWarning(_Atomic(int) *Ap, int *p, int val) {
+void nullPointerWarning() {
   volatile _Atomic(int) vai;
   _Atomic(int) ai;
   volatile int vi = 42;
   int i = 42;
+  volatile _Atomic(int*) vap;
+  _Atomic(int*) ap;
+  volatile int* vp = NULL;
+  int* p = NULL;
 
   __c11_atomic_init((volatile _Atomic(int)*)0, 42); // expected-warning {{null 
passed to a callee that requires a non-null argument}}
   __c11_atomic_init((_Atomic(int)*)0, 42); // expected-warning {{null passed 
to a callee that requires a non-null argument}}
@@ -607,4 +611,65 @@ void nullPointerWarning(_Atomic(int) *Ap
   (void)__atomic_fetch_min((int*)0, 42, memory_order_relaxed); // 
expected-warning {{null passed to a callee that requires a non-null argument}}
   (void)__atomic_fetch_max((volatile int*)0, 42, memory_order_relaxed); // 
expected-warning {{null passed to a callee that requires a non-null argument}}
   (void)__atomic_fetch_max((int*)0, 42, memory_order_relaxed); // 
expected-warning {{null passed to a callee that requires a non-null argument}}
+
+  // These don't warn: the "desired" parameter is passed by value. Even for
+  // atomic pointers the "desired" result can be NULL.
+  __c11_atomic_init(, 0);
+  __c11_atomic_init(, 0);
+  __c11_atomic_init(, NULL);
+  __c11_atomic_init(, NULL);
+  __c11_atomic_store(, 0, memory_order_relaxed);
+  __c11_atomic_store(, 0, memory_order_relaxed);
+  __c11_atomic_store(, NULL, memory_order_relaxed);
+  __c11_atomic_store(, NULL, memory_order_relaxed);
+  (void)__c11_atomic_exchange(, 0, memory_order_relaxed);
+  (void)__c11_atomic_exchange(, 0, memory_order_relaxed);
+  (void)__c11_atomic_exchange(, NULL, memory_order_relaxed);
+  (void)__c11_atomic_exchange(, NULL, memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_weak(, , 0, memory_order_relaxed, 
memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_weak(, , 0, memory_order_relaxed, 
memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_weak(, , NULL, 
memory_order_relaxed, memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_weak(, , NULL, 
memory_order_relaxed, memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_strong(, , 0, 
memory_order_relaxed, memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_strong(, , 0, memory_order_relaxed, 
memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_strong(, , NULL, 
memory_order_relaxed, memory_order_relaxed);
+  (void)__c11_atomic_compare_exchange_strong(, , NULL, 
memory_order_relaxed, memory_order_relaxed);
+  (void)__c11_atomic_fetch_add(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_add(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_sub(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_sub(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_and(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_and(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_or(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_or(, 0, memory_order_relaxed);
+  (void)__c11_atomic_fetch_xor(, 0, 

[PATCH] D47229: Make atomic non-member functions as nonnull

2018-05-25 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D47229#1112549, @jakehehrlich wrote:

> This is causing breaks in fuchsia,
>
> Code that looks like this
>
>   uintptr_t last_unlogged =
>atomic_load_explicit(_tail, memory_order_acquire);
>do { 
>if (last_unlogged == 0)
>return;
>} while (!atomic_compare_exchange_weak_explicit(_tail,
>_unlogged, 0,
>memory_order_acq_rel,
>memory_order_relaxed));
>   
>
> Where unlogged_tail is somewhere on the stack. And 
> 'atomic_compare_exchange_weak_explicit' is an #define alias for 
> '__c11_atomic_compare_exchange_weak'
>
> Full context here: 
> https://fuchsia.googlesource.com/zircon/+/master/third_party/ulib/musl/ldso/dynlink.c#822


Here's a repro for what seems to be happening:

  #include 
  void foo() {
atomic_int s;
int a;
atomic_compare_exchange_weak_explicit(, , 0, memory_order_acq_rel, 
memory_order_relaxed);
  }

Yields:

  ./foo.c:5:3: warning: null passed to a callee that requires a non-null 
argument [-Wnonnull]
atomic_compare_exchange_weak_explicit(, , 0, memory_order_acq_rel, 
memory_order_relaxed);
^ ~
  /s/llvm1/llvm/debug/lib/clang/7.0.0/include/stdatomic.h:144:47: note: 
expanded from macro 'atomic_compare_exchange_weak_explicit'
  #define atomic_compare_exchange_weak_explicit 
__c11_atomic_compare_exchange_weak
^

The problem is that my patch checks that the "desired" value is non-null, but 
that's incorrect because it's not a pointer. I'll do a follow-up fix. Thanks 
for catching this!


Repository:
  rL LLVM

https://reviews.llvm.org/D47229



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


[PATCH] D47357: [Driver] Rename DefaultTargetTriple to TargetTriple

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

lgtm


Repository:
  rC Clang

https://reviews.llvm.org/D47357



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


[PATCH] D47229: Make atomic non-member functions as nonnull

2018-05-25 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

This is causing breaks in fuchsia,

Code that looks like this

  uintptr_t last_unlogged =
   atomic_load_explicit(_tail, memory_order_acquire);
   do { 
   if (last_unlogged == 0)
   return;
   } while (!atomic_compare_exchange_weak_explicit(_tail,
   _unlogged, 0,
   memory_order_acq_rel,
   memory_order_relaxed));

Where unlogged_tail is somewhere on the stack. And 
'atomic_compare_exchange_weak_explicit' is an #define alias for 
'__c11_atomic_compare_exchange_weak'

Full context here: 
https://fuchsia.googlesource.com/zircon/+/master/third_party/ulib/musl/ldso/dynlink.c#822


Repository:
  rL LLVM

https://reviews.llvm.org/D47229



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


[PATCH] D47200: [Sema] Add tests for weak functions

2018-05-25 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333283: [Sema] Add tests for weak functions (authored by 
Hahnfeld, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47200?vs=148021=148616#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47200

Files:
  cfe/trunk/test/Sema/attr-weak.c


Index: cfe/trunk/test/Sema/attr-weak.c
===
--- cfe/trunk/test/Sema/attr-weak.c
+++ cfe/trunk/test/Sema/attr-weak.c
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 
+extern int f0() __attribute__((weak));
 extern int g0 __attribute__((weak));
 extern int g1 __attribute__((weak_import));
+int f2() __attribute__((weak));
 int g2 __attribute__((weak));
 int g3 __attribute__((weak_import)); // expected-warning {{'weak_import' 
attribute cannot be specified on a definition}}
 int __attribute__((weak_import)) g4(void);
@@ -11,6 +13,7 @@
 struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute 
only applies to variables, functions, and classes}}
 struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' 
attribute only applies to variables and functions}}
 
+static int f() __attribute__((weak)); // expected-error {{weak declaration 
cannot have internal linkage}}
 static int x __attribute__((weak)); // expected-error {{weak declaration 
cannot have internal linkage}}
 
 // rdar://9538608


Index: cfe/trunk/test/Sema/attr-weak.c
===
--- cfe/trunk/test/Sema/attr-weak.c
+++ cfe/trunk/test/Sema/attr-weak.c
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 
+extern int f0() __attribute__((weak));
 extern int g0 __attribute__((weak));
 extern int g1 __attribute__((weak_import));
+int f2() __attribute__((weak));
 int g2 __attribute__((weak));
 int g3 __attribute__((weak_import)); // expected-warning {{'weak_import' attribute cannot be specified on a definition}}
 int __attribute__((weak_import)) g4(void);
@@ -11,6 +13,7 @@
 struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only applies to variables, functions, and classes}}
 struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}}
 
+static int f() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
 static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
 
 // rdar://9538608
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r333283 - [Sema] Add tests for weak functions

2018-05-25 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Fri May 25 08:56:12 2018
New Revision: 333283

URL: http://llvm.org/viewvc/llvm-project?rev=333283=rev
Log:
[Sema] Add tests for weak functions

I found these checks to be missing, just add some simple cases.

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

Modified:
cfe/trunk/test/Sema/attr-weak.c

Modified: cfe/trunk/test/Sema/attr-weak.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-weak.c?rev=333283=333282=333283=diff
==
--- cfe/trunk/test/Sema/attr-weak.c (original)
+++ cfe/trunk/test/Sema/attr-weak.c Fri May 25 08:56:12 2018
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
 
+extern int f0() __attribute__((weak));
 extern int g0 __attribute__((weak));
 extern int g1 __attribute__((weak_import));
+int f2() __attribute__((weak));
 int g2 __attribute__((weak));
 int g3 __attribute__((weak_import)); // expected-warning {{'weak_import' 
attribute cannot be specified on a definition}}
 int __attribute__((weak_import)) g4(void);
@@ -11,6 +13,7 @@ void __attribute__((weak_import)) g5(voi
 struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute 
only applies to variables, functions, and classes}}
 struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' 
attribute only applies to variables and functions}}
 
+static int f() __attribute__((weak)); // expected-error {{weak declaration 
cannot have internal linkage}}
 static int x __attribute__((weak)); // expected-error {{weak declaration 
cannot have internal linkage}}
 
 // rdar://9538608


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


[PATCH] D47260: Testcase for dwarf 5 crash/assert when calculating a checksum for an expansion

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

@trixirt do you mind if I commandeer this review?  I think I have a patch.


Repository:
  rC Clang

https://reviews.llvm.org/D47260



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


[PATCH] D47375: [Driver] Add flag "--dependent-lib=..." when enabling asan or ubsan on PS4.

2018-05-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

LGTM with the indicated test tweak, but best if @filcab also takes a look.




Comment at: lib/Driver/ToolChains/PS4CPU.cpp:87
+CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
+  }
+}

Don't bother with braces for a one-line `if` body.



Comment at: test/Driver/fsanitize.c:624
+// CHECK-ASAN-PS4: --dependent-lib=libSceDbgAddressSanitizer_stub_weak.a
 // CHECK-ASAN-PS4-NOT: {{(\.(o|bc)"? |-l).*-lSceDbgAddressSanitizer_stub_weak}}
 // CHECK-ASAN-PS4: -lSceDbgAddressSanitizer_stub_weak

Repeat this NOT line before the new check? to preserve the property described 
in the comment.


Repository:
  rC Clang

https://reviews.llvm.org/D47375



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


[PATCH] D47376: [CUDA][HIP] Do not offload for -M

2018-05-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.

CUDA and HIP action builder currently tries to do offloading for -M, which 
causes dependency file
not generated.

This patch changes action builder so that only host compilation is performed to 
generate dependency
file.

This assumes that the header files do not depend on whether it is device 
compilation or host
compilation. This is not ideal, but at least let projects using -M compile.

Ideally, we should create an offloading action for host dependency file and 
device dependency file
and merge them to be on dependency file, which will be done in a separate patch.


https://reviews.llvm.org/D47376

Files:
  lib/Driver/Driver.cpp
  test/Driver/cuda-phases.cu


Index: test/Driver/cuda-phases.cu
===
--- test/Driver/cuda-phases.cu
+++ test/Driver/cuda-phases.cu
@@ -246,3 +246,14 @@
 // DASM2-DAG: [[P7:[0-9]+]]: compiler, {[[P6]]}, ir, (device-[[T]], [[ARCH2]])
 // DASM2_NV-DAG: [[P8:[0-9]+]]: backend, {[[P7]]}, assembler, (device-[[T]], 
[[ARCH2]])
 // DASM2_NV-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] ([[TRIPLE]]:[[ARCH2]])" 
{[[P8]]}, assembler
+
+//
+// Test -M does not cause device input.
+//
+// RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases 
--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_35 %s -M 2>&1 \
+// RUN: | FileCheck -check-prefixes=DEP %s
+// RUN: %clang -x hip -target powerpc64le-ibm-linux-gnu -ccc-print-phases 
--cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s -M 2>&1 \
+// RUN: | FileCheck -check-prefixes=DEP %s
+// DEP-DAG: [[P0:[0-9]+]]: input, "{{.*}}cuda-phases.cu", [[T:.*]], 
(host-[[T]])
+// DEP-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, dependencies, (host-[[T]])
+
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2210,7 +2210,10 @@
 // Set the flag to true, so that the builder acts on the current input.
 IsActive = true;
 
-if (CompileHostOnly)
+// ToDo: Handle situations where device compilation and host
+// compilation have different dependencies. Currently we assume they
+// are the same therefore device compilation is not performed for -M.
+if (CompileHostOnly || Args.getLastArg(options::OPT_M))
   return ABRT_Success;
 
 // Replicate inputs for each GPU architecture.


Index: test/Driver/cuda-phases.cu
===
--- test/Driver/cuda-phases.cu
+++ test/Driver/cuda-phases.cu
@@ -246,3 +246,14 @@
 // DASM2-DAG: [[P7:[0-9]+]]: compiler, {[[P6]]}, ir, (device-[[T]], [[ARCH2]])
 // DASM2_NV-DAG: [[P8:[0-9]+]]: backend, {[[P7]]}, assembler, (device-[[T]], [[ARCH2]])
 // DASM2_NV-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] ([[TRIPLE]]:[[ARCH2]])" {[[P8]]}, assembler
+
+//
+// Test -M does not cause device input.
+//
+// RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_35 %s -M 2>&1 \
+// RUN: | FileCheck -check-prefixes=DEP %s
+// RUN: %clang -x hip -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s -M 2>&1 \
+// RUN: | FileCheck -check-prefixes=DEP %s
+// DEP-DAG: [[P0:[0-9]+]]: input, "{{.*}}cuda-phases.cu", [[T:.*]], (host-[[T]])
+// DEP-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, dependencies, (host-[[T]])
+
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2210,7 +2210,10 @@
 // Set the flag to true, so that the builder acts on the current input.
 IsActive = true;
 
-if (CompileHostOnly)
+// ToDo: Handle situations where device compilation and host
+// compilation have different dependencies. Currently we assume they
+// are the same therefore device compilation is not performed for -M.
+if (CompileHostOnly || Args.getLastArg(options::OPT_M))
   return ABRT_Success;
 
 // Replicate inputs for each GPU architecture.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47375: [Driver] Add flag "--dependent-lib=..." when enabling asan or ubsan on PS4.

2018-05-25 Thread pierre gousseau via Phabricator via cfe-commits
pgousseau created this revision.
pgousseau added reviewers: rsmith, filcab, probinson, gbedwell.
Herald added a subscriber: cfe-commits.

NFC for targets other than PS4.

Simplify users' workflow when enabling asan or ubsan and calling the linker 
separately.


Repository:
  rC Clang

https://reviews.llvm.org/D47375

Files:
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/PS4CPU.cpp
  lib/Driver/ToolChains/PS4CPU.h
  test/Driver/fsanitize.c
  test/Driver/sanitizer-ld.c


Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -646,20 +646,25 @@
 // RUN: -target x86_64-scei-ps4 -fuse-ld=ld \
 // RUN: -shared \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-PS4 %s
+// CHECK-UBSAN-PS4: --dependent-lib=libSceDbgUBSanitizer_stub_weak.a
 // CHECK-UBSAN-PS4: "{{.*}}ld{{(.gold)?(.exe)?}}"
 // CHECK-UBSAN-PS4: -lSceDbgUBSanitizer_stub_weak
 
 // RUN: %clang -fsanitize=address %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-scei-ps4 -fuse-ld=ld \
 // RUN: -shared \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-PS4 %s
+// CHECK-ASAN-PS4: --dependent-lib=libSceDbgAddressSanitizer_stub_weak.a
 // CHECK-ASAN-PS4: "{{.*}}ld{{(.gold)?(.exe)?}}"
 // CHECK-ASAN-PS4: -lSceDbgAddressSanitizer_stub_weak
 
 // RUN: %clang -fsanitize=address,undefined %s -### -o %t.o 2>&1 \
 // RUN: -target x86_64-scei-ps4 -fuse-ld=ld \
 // RUN: -shared \
 // RUN:   | FileCheck --check-prefix=CHECK-AUBSAN-PS4 %s
+// CHECK-AUBSAN-PS4-NOT: --dependent-lib=libSceDbgUBSanitizer_stub_weak.a
+// CHECK-AUBSAN-PS4: --dependent-lib=libSceDbgAddressSanitizer_stub_weak.a
+// CHECK-AUBSAN-PS4-NOT: --dependent-lib=libSceDbgUBSanitizer_stub_weak.a
 // CHECK-AUBSAN-PS4: "{{.*}}ld{{(.gold)?(.exe)?}}"
 // CHECK-AUBSAN-PS4: -lSceDbgAddressSanitizer_stub_weak
 
Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -620,6 +620,7 @@
 // CHECK-ESAN-PS4: unsupported option '-fsanitize=efficiency-{{.*}}' for 
target 'x86_64-scei-ps4'
 // RUN: %clang -target x86_64-scei-ps4 -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-PS4
 // Make sure there are no *.{o,bc} or -l passed before the ASan library.
+// CHECK-ASAN-PS4: --dependent-lib=libSceDbgAddressSanitizer_stub_weak.a
 // CHECK-ASAN-PS4-NOT: {{(\.(o|bc)"? |-l).*-lSceDbgAddressSanitizer_stub_weak}}
 // CHECK-ASAN-PS4: -lSceDbgAddressSanitizer_stub_weak
 
Index: lib/Driver/ToolChains/PS4CPU.h
===
--- lib/Driver/ToolChains/PS4CPU.h
+++ lib/Driver/ToolChains/PS4CPU.h
@@ -23,6 +23,8 @@
 void addProfileRTArgs(const ToolChain , const llvm::opt::ArgList ,
   llvm::opt::ArgStringList );
 
+void addSanitizerArgs(const ToolChain , llvm::opt::ArgStringList );
+
 class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
 public:
   Assemble(const ToolChain )
Index: lib/Driver/ToolChains/PS4CPU.cpp
===
--- lib/Driver/ToolChains/PS4CPU.cpp
+++ lib/Driver/ToolChains/PS4CPU.cpp
@@ -76,6 +76,17 @@
   }
 }
 
+void tools::PS4cpu::addSanitizerArgs(const ToolChain ,
+ ArgStringList ) {
+  const SanitizerArgs  = TC.getSanitizerArgs();
+  if (SanArgs.needsUbsanRt()) {
+CmdArgs.push_back("--dependent-lib=libSceDbgUBSanitizer_stub_weak.a");
+  }
+  if (SanArgs.needsAsanRt()) {
+CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
+  }
+}
+
 static void ConstructPS4LinkJob(const Tool , Compilation ,
 const JobAction , const InputInfo ,
 const InputInfoList ,
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3687,9 +3687,11 @@
   if (auto *ABICompatArg = Args.getLastArg(options::OPT_fclang_abi_compat_EQ))
 ABICompatArg->render(Args, CmdArgs);
 
-  // Add runtime flag for PS4 when PGO or Coverage are enabled.
-  if (RawTriple.isPS4CPU())
+  // Add runtime flag for PS4 when PGO or Coverage or sanitizers are enabled.
+  if (RawTriple.isPS4CPU()) {
 PS4cpu::addProfileRTArgs(getToolChain(), Args, CmdArgs);
+PS4cpu::addSanitizerArgs(getToolChain(), CmdArgs);
+  }
 
   // Pass options for controlling the default header search paths.
   if (Args.hasArg(options::OPT_nostdinc)) {


Index: test/Driver/sanitizer-ld.c
===
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -646,20 +646,25 @@
 // RUN: -target x86_64-scei-ps4 -fuse-ld=ld \
 // RUN: -shared \
 // RUN:   | FileCheck --check-prefix=CHECK-UBSAN-PS4 %s
+// CHECK-UBSAN-PS4: --dependent-lib=libSceDbgUBSanitizer_stub_weak.a
 // 

[clang-tools-extra] r333280 - [clangd] Temporarily disable the test that crashes under asan.

2018-05-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri May 25 07:55:18 2018
New Revision: 333280

URL: http://llvm.org/viewvc/llvm-project?rev=333280=rev
Log:
[clangd] Temporarily disable the test that crashes under asan.

It turns out that our fix did not solve the problem completely and the
crash due to stale preamble is still there under asan.
Disabling the test for now, will reenable it when landing a proper fix
for the problem.

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=333280=333279=333280=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri May 25 
07:55:18 2018
@@ -999,7 +999,8 @@ TEST(CompletionTest, NoIndexCompletionsI
   }
 }
 
-TEST(CompletionTest, DocumentationFromChangedFileCrash) {
+// FIXME: This still crashes under asan. Fix it and reenable the test.
+TEST(CompletionTest, DISABLED_DocumentationFromChangedFileCrash) {
   MockFSProvider FS;
   auto FooH = testPath("foo.h");
   auto FooCpp = testPath("foo.cpp");


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


[PATCH] D46891: [StaticAnalyzer] Added a getLValue method to ProgramState for bases

2018-05-25 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC333278: [analyzer] Added a getLValue method to ProgramState 
for bases (authored by Szelethus, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46891

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -294,6 +294,13 @@
   ProgramStateRef enterStackFrame(const CallEvent ,
   const StackFrameContext *CalleeCtx) const;
 
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXBaseSpecifier , const SubRegion *Super) 
const;
+
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXRecordDecl *BaseClass, const SubRegion *Super,
+bool IsVirtual) const;
+
   /// Get the lvalue for a variable reference.
   Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
 
@@ -724,6 +731,22 @@
   return this;
 }
 
+inline Loc ProgramState::getLValue(const CXXBaseSpecifier ,
+   const SubRegion *Super) const {
+  const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+Base, Super, 
BaseSpec.isVirtual()));
+}
+
+inline Loc ProgramState::getLValue(const CXXRecordDecl *BaseClass,
+   const SubRegion *Super,
+   bool IsVirtual) const {
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+  BaseClass, Super, 
IsVirtual));
+}
+
 inline Loc ProgramState::getLValue(const VarDecl *VD,
const LocationContext *LC) const {
   return getStateManager().StoreMgr->getLValueVar(VD, LC);


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -294,6 +294,13 @@
   ProgramStateRef enterStackFrame(const CallEvent ,
   const StackFrameContext *CalleeCtx) const;
 
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXBaseSpecifier , const SubRegion *Super) const;
+
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXRecordDecl *BaseClass, const SubRegion *Super,
+bool IsVirtual) const;
+
   /// Get the lvalue for a variable reference.
   Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
 
@@ -724,6 +731,22 @@
   return this;
 }
 
+inline Loc ProgramState::getLValue(const CXXBaseSpecifier ,
+   const SubRegion *Super) const {
+  const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+Base, Super, BaseSpec.isVirtual()));
+}
+
+inline Loc ProgramState::getLValue(const CXXRecordDecl *BaseClass,
+   const SubRegion *Super,
+   bool IsVirtual) const {
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+  BaseClass, Super, IsVirtual));
+}
+
 inline Loc ProgramState::getLValue(const VarDecl *VD,
const LocationContext *LC) const {
   return getStateManager().StoreMgr->getLValueVar(VD, LC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r333278 - [analyzer] Added a getLValue method to ProgramState for bases

2018-05-25 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri May 25 07:48:33 2018
New Revision: 333278

URL: http://llvm.org/viewvc/llvm-project?rev=333278=rev
Log:
[analyzer] Added a getLValue method to ProgramState for bases

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


Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=333278=333277=333278=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Fri May 25 07:48:33 2018
@@ -294,6 +294,13 @@ public:
   ProgramStateRef enterStackFrame(const CallEvent ,
   const StackFrameContext *CalleeCtx) const;
 
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXBaseSpecifier , const SubRegion *Super) 
const;
+
+  /// Get the lvalue for a base class object reference.
+  Loc getLValue(const CXXRecordDecl *BaseClass, const SubRegion *Super,
+bool IsVirtual) const;
+
   /// Get the lvalue for a variable reference.
   Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
 
@@ -724,6 +731,22 @@ inline ProgramStateRef ProgramState::bin
   return this;
 }
 
+inline Loc ProgramState::getLValue(const CXXBaseSpecifier ,
+   const SubRegion *Super) const {
+  const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+Base, Super, 
BaseSpec.isVirtual()));
+}
+
+inline Loc ProgramState::getLValue(const CXXRecordDecl *BaseClass,
+   const SubRegion *Super,
+   bool IsVirtual) const {
+  return loc::MemRegionVal(
+   getStateManager().getRegionManager().getCXXBaseObjectRegion(
+  BaseClass, Super, 
IsVirtual));
+}
+
 inline Loc ProgramState::getLValue(const VarDecl *VD,
const LocationContext *LC) const {
   return getStateManager().StoreMgr->getLValueVar(VD, LC);


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


[PATCH] D46944: [analyzer] Use sufficiently large types for index/size calculation.

2018-05-25 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:89
 SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
-StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy),
+StateMgr(stateMgr), ArrayIndexTy(context.getSignedSizeType()),
 ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {}

a.sidorin wrote:
> ebevhan wrote:
> > a.sidorin wrote:
> > > As you correctly pointed, ssize_t is 32-bit on 32-bit systems. Therefore, 
> > > it is too short. So, we can leave this line as-is.
> > But if it's hardcoded to LongLongTy, you have the same problem on 64-bit 
> > systems.
> Some reasons why LongLongTy is used here are listed in D16063. In brief, you 
> just cannot create an array of size greater than SIZE_MAX/2  on 64-bit 
> platforms.
I don't think that's limited to 64-bit platforms, it applies to 32-bit ones as 
well. I know that LLVM has issues with indexing arrays that are larger than 
half of the address space in general due to limitations of GEP.


https://reviews.llvm.org/D46944



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


[PATCH] D46944: [analyzer] Use sufficiently large types for index/size calculation.

2018-05-25 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:89
 SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
-StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy),
+StateMgr(stateMgr), ArrayIndexTy(context.getSignedSizeType()),
 ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {}

ebevhan wrote:
> a.sidorin wrote:
> > As you correctly pointed, ssize_t is 32-bit on 32-bit systems. Therefore, 
> > it is too short. So, we can leave this line as-is.
> But if it's hardcoded to LongLongTy, you have the same problem on 64-bit 
> systems.
Some reasons why LongLongTy is used here are listed in D16063. In brief, you 
just cannot create an array of size greater than SIZE_MAX/2  on 64-bit 
platforms.


https://reviews.llvm.org/D46944



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


[PATCH] D47331: [clangd] Remove accessors for top-level decls from preamble

2018-05-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 148605.
ilya-biryukov added a comment.

- Rewrote findDecl, it will deserialize decls if needed now


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47331

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/XRefs.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -1,5 +1,4 @@
-//===--- TestTU.cpp - Scratch source files for testing *-
-//C++-*-===//
+//===--- TestTU.cpp - Scratch source files for testing ===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -73,22 +72,24 @@
 }
 
 const NamedDecl (ParsedAST , llvm::StringRef QName) {
-  const NamedDecl *Result = nullptr;
-  for (const Decl *D : AST.getTopLevelDecls()) {
-auto *ND = dyn_cast(D);
-if (!ND || ND->getNameAsString() != QName)
-  continue;
-if (Result) {
-  ADD_FAILURE() << "Multiple Decls named " << QName;
-  assert(false && "QName is not unique");
-}
-Result = ND;
-  }
-  if (!Result) {
-ADD_FAILURE() << "No Decl named " << QName << " in AST";
-assert(false && "No Decl with QName");
+  llvm::SmallVector Components;
+  QName.split(Components, "::");
+
+  auto  = AST.getASTContext();
+  auto LookupDecl = [](const DeclContext ,
+   llvm::StringRef Name) -> const NamedDecl & {
+auto LookupRes = Scope.lookup(DeclarationName((Name)));
+assert(!LookupRes.empty() && "Lookup failed");
+assert(LookupRes.size() == 1 && "Lookup returned multiple results");
+return *LookupRes.front();
+  };
+
+  const DeclContext *Scope = Ctx.getTranslationUnitDecl();
+  for (auto NameIt = Components.begin(), End = Components.end() - 1;
+   NameIt != End; ++NameIt) {
+Scope = (LookupDecl(*Scope, *NameIt));
   }
-  return *Result;
+  return LookupDecl(*Scope, Components.back());
 }
 
 } // namespace clangd
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -168,7 +168,7 @@
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
+  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
  DeclMacrosFinder, IndexOpts);
 
   return {DeclMacrosFinder.takeDecls(), DeclMacrosFinder.takeMacroInfos()};
@@ -418,7 +418,7 @@
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
+  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
  DocHighlightsFinder, IndexOpts);
 
   return DocHighlightsFinder.takeHighlights();
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -44,12 +44,10 @@
 
 // Stores Preamble and associated data.
 struct PreambleData {
-  PreambleData(PrecompiledPreamble Preamble,
-   std::vector TopLevelDeclIDs,
-   std::vector Diags, std::vector Inclusions);
+  PreambleData(PrecompiledPreamble Preamble, std::vector Diags,
+   std::vector Inclusions);
 
   PrecompiledPreamble Preamble;
-  std::vector TopLevelDeclIDs;
   std::vector Diags;
   // Processes like code completions and go-to-definitions will need #include
   // information, and their compile action skips preamble range.
@@ -80,17 +78,19 @@
 
   ~ParsedAST();
 
+  /// Note that the returned ast will not contain decls from the preamble that
+  /// were not deserialized during parsing. Clients should expect only decls
+  /// from the main file to be in the AST.
   ASTContext ();
   const ASTContext () const;
 
   Preprocessor ();
   std::shared_ptr getPreprocessorPtr();
   const Preprocessor () const;
 
-  /// This function returns all top-level decls, including those that come
-  /// from Preamble. Decls, coming from Preamble, have to be deserialized, so
-  /// this call might be expensive.
-  ArrayRef getTopLevelDecls();
+  /// This function returns top-level decls present in the main file of the AST.
+  /// The result does not include the decls that come from the preamble.
+  ArrayRef getLocalTopLevelDecls();
 
   const std::vector () const;
 
@@ -103,11 +103,8 @@
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action,
-std::vector TopLevelDecls, std::vector Diags,
-std::vector Inclusions);
-
-private:
-  void ensurePreambleDeclsDeserialized();
+std::vector LocalTopLevelDecls,
+std::vector Diags, std::vector Inclusions);
 
   // In-memory preambles must outlive 

[PATCH] D45686: [Driver] Clean up tmp files when deleting Compilation objects

2018-05-25 Thread David Stenberg via Phabricator via cfe-commits
dstenb updated this revision to Diff 148604.
dstenb added a comment.

Query TheDriver.isSaveTempsEnabled() at uses instead of storing the value in 
the constructor.


https://reviews.llvm.org/D45686

Files:
  include/clang/Driver/Compilation.h
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1243,9 +1243,6 @@
 
   // If any of the preprocessing commands failed, clean up and exit.
   if (!FailingCommands.empty()) {
-if (!isSaveTempsEnabled())
-  C.CleanupFileList(C.getTempFiles(), true);
-
 Diag(clang::diag::note_drv_command_failed_diag_msg)
 << "Error generating preprocessed source(s).";
 return;
@@ -1362,9 +1359,6 @@
 
   C.ExecuteJobs(C.getJobs(), FailingCommands);
 
-  // Remove temp files.
-  C.CleanupFileList(C.getTempFiles());
-
   // If the command succeeded, we are done.
   if (FailingCommands.empty())
 return 0;
Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -45,6 +45,11 @@
 }
 
 Compilation::~Compilation() {
+  // Remove temporary files. This must be done before arguments are freed, as
+  // the file names might be derived from the input arguments.
+  if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
+CleanupFileList(TempFiles);
+
   delete TranslatedArgs;
   delete Args;
 
@@ -245,6 +250,10 @@
   AllActions.clear();
   Jobs.clear();
 
+  // Remove temporary files.
+  if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
+CleanupFileList(TempFiles);
+
   // Clear temporary/results file lists.
   TempFiles.clear();
   ResultFiles.clear();
@@ -262,6 +271,9 @@
 
   // Redirect stdout/stderr to /dev/null.
   Redirects = {None, {""}, {""}};
+
+  // Temporary files added by diagnostics should be kept.
+  ForceKeepTempFiles = true;
 }
 
 StringRef Compilation::getSysRoot() const {
Index: include/clang/Driver/Compilation.h
===
--- include/clang/Driver/Compilation.h
+++ include/clang/Driver/Compilation.h
@@ -122,6 +122,9 @@
   /// Whether an error during the parsing of the input args.
   bool ContainsError;
 
+  /// Whether to keep temporary files regardless of -save-temps.
+  bool ForceKeepTempFiles = false;
+
 public:
   Compilation(const Driver , const ToolChain ,
   llvm::opt::InputArgList *Args,


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1243,9 +1243,6 @@
 
   // If any of the preprocessing commands failed, clean up and exit.
   if (!FailingCommands.empty()) {
-if (!isSaveTempsEnabled())
-  C.CleanupFileList(C.getTempFiles(), true);
-
 Diag(clang::diag::note_drv_command_failed_diag_msg)
 << "Error generating preprocessed source(s).";
 return;
@@ -1362,9 +1359,6 @@
 
   C.ExecuteJobs(C.getJobs(), FailingCommands);
 
-  // Remove temp files.
-  C.CleanupFileList(C.getTempFiles());
-
   // If the command succeeded, we are done.
   if (FailingCommands.empty())
 return 0;
Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -45,6 +45,11 @@
 }
 
 Compilation::~Compilation() {
+  // Remove temporary files. This must be done before arguments are freed, as
+  // the file names might be derived from the input arguments.
+  if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
+CleanupFileList(TempFiles);
+
   delete TranslatedArgs;
   delete Args;
 
@@ -245,6 +250,10 @@
   AllActions.clear();
   Jobs.clear();
 
+  // Remove temporary files.
+  if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
+CleanupFileList(TempFiles);
+
   // Clear temporary/results file lists.
   TempFiles.clear();
   ResultFiles.clear();
@@ -262,6 +271,9 @@
 
   // Redirect stdout/stderr to /dev/null.
   Redirects = {None, {""}, {""}};
+
+  // Temporary files added by diagnostics should be kept.
+  ForceKeepTempFiles = true;
 }
 
 StringRef Compilation::getSysRoot() const {
Index: include/clang/Driver/Compilation.h
===
--- include/clang/Driver/Compilation.h
+++ include/clang/Driver/Compilation.h
@@ -122,6 +122,9 @@
   /// Whether an error during the parsing of the input args.
   bool ContainsError;
 
+  /// Whether to keep temporary files regardless of -save-temps.
+  bool ForceKeepTempFiles = false;
+
 public:
   Compilation(const Driver , const ToolChain ,
   llvm::opt::InputArgList *Args,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47067: Update NRVO logic to support early return

2018-05-25 Thread Taiju Tsuiki via Phabricator via cfe-commits
tzik added inline comments.



Comment at: lib/Sema/Scope.cpp:128
 
-  if (getEntity())
-return;
-
-  if (NRVO.getInt())
-getParent()->setNoNRVO();
-  else if (NRVO.getPointer())
-getParent()->addNRVOCandidate(NRVO.getPointer());
+  if (getParent())
+getParent()->setNRVOCandidate(Candidate);

xbolva00 wrote:
> auto * Parent = getParent();
> if (Parent)
> Parent>setNRVOCandidate(Candidate);
> 
> ?
Updated!


Repository:
  rC Clang

https://reviews.llvm.org/D47067



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


[PATCH] D47067: Update NRVO logic to support early return

2018-05-25 Thread Taiju Tsuiki via Phabricator via cfe-commits
tzik updated this revision to Diff 148603.
tzik added a comment.

reuse getParent() result


Repository:
  rC Clang

https://reviews.llvm.org/D47067

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/Scope.h
  lib/Sema/Scope.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/nrvo-noopt.cpp
  test/CodeGenCXX/nrvo.cpp
  test/SemaCXX/nrvo-ast.cpp

Index: test/SemaCXX/nrvo-ast.cpp
===
--- /dev/null
+++ test/SemaCXX/nrvo-ast.cpp
@@ -0,0 +1,139 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -ast-dump -o - %s | FileCheck %s
+
+struct X {
+  X();
+  X(const X&);
+  X(X&&);
+};
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_00
+X test_00() {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_01
+X test_01(bool b) {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  if (b)
+return x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_02
+X test_02(bool b) {
+  // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  // CHECK-NOT: VarDecl {{.*}} y {{.*}} nrvo
+  X y;
+  if (b)
+return y;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_03
+X test_03(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} y {{.*}} nrvo
+X y;
+return y;
+  }
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+extern "C" _Noreturn void exit(int) throw();
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_04
+X test_04(bool b) {
+  {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+if (b)
+  return x;
+  }
+  exit(1);
+}
+
+void may_throw();
+// CHECK-LABEL: FunctionDecl {{.*}} test_05
+X test_05() {
+  try {
+may_throw();
+return X();
+  } catch (X x) {
+// CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+return x;
+  }
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_06
+X test_06() {
+  // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+  X x __attribute__((aligned(8)));
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_07
+X test_07(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+return x;
+  }
+  return X();
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_08
+X test_08(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+return x;
+  } else {
+// CHECK: VarDecl {{.*}} y {{.*}} nrvo
+X y;
+return y;
+  }
+}
+
+template 
+struct Y {
+  Y();
+  // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y ()'
+  // CHECK: VarDecl {{.*}} y 'Y' nrvo
+
+  // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y ()'
+  // CHECK: VarDecl {{.*}} y 'Y' nrvo
+  static Y test_09() {
+Y y;
+return y;
+  }
+};
+
+struct Z {
+  Z(const X&);
+};
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'A ()'
+// CHECK: VarDecl {{.*}} b 'B' nrvo
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'X ()'
+// CHECK: VarDecl {{.*}} b {{.*}} nrvo
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'Z ()'
+// CHECK-NOT: VarDecl {{.*}} b {{.*}} nrvo
+template 
+A test_10() {
+  B b;
+  return b;
+}
+
+void instantiate() {
+  Y::test_09();
+  test_10();
+  test_10();
+}
Index: test/CodeGenCXX/nrvo.cpp
===
--- test/CodeGenCXX/nrvo.cpp
+++ test/CodeGenCXX/nrvo.cpp
@@ -130,17 +130,13 @@
 }
 
 // CHECK-LABEL: define void @_Z5test3b
-X test3(bool B) {
+X test3(bool B, X x) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
-  // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_
-  // CHECK: call {{.*}} @_ZN1XC1Ev
-  // CHECK: call {{.*}} @_ZN1XC1ERKS_
   if (B) {
 X y;
 return y;
   }
-  // FIXME: we should NRVO this variable too.
-  X x;
+  // CHECK: tail call {{.*}} @_ZN1XC1ERKS_
   return x;
 }
 
@@ -191,21 +187,29 @@
 }
 
 // CHECK-LABEL: define void @_Z5test7b
+// CHECK-EH-LABEL: define void @_Z5test7b
 X test7(bool b) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
   // CHECK-NEXT: ret
+
+  // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-EH-NEXT: ret
   if (b) {
 X x;
 return x;
   }
   return X();
 }
 
 // CHECK-LABEL: define void @_Z5test8b
+// CHECK-EH-LABEL: define void @_Z5test8b
 X test8(bool b) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
   // CHECK-NEXT: ret
-  if (b) {
+
+  // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-EH-NEXT: ret
+if (b) {
 X x;
 return x;
   } else {
@@ -221,4 +225,37 @@
 // CHECK-LABEL: define linkonce_odr void @_ZN1YIiE1fEv
 // CHECK: tail call {{.*}} @_ZN1YIiEC1Ev
 
+// CHECK-LABEL: define void @_Z6test10b
+X test10(bool B, X x) {
+  if (B) {
+// CHECK: tail call {{.*}} @_ZN1XC1ERKS_
+// CHECK-EH: tail call {{.*}} @_ZN1XC1ERKS_
+return x;
+  }
+  // CHECK: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_
+
+  // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-EH-NOT: call {{.*}} @_ZN1XC1ERKS_
+  X y;
+  return y;
+}
+
+// CHECK-LABEL: define {{.*}} void 

[PATCH] D47331: [clangd] Remove accessors for top-level decls from preamble

2018-05-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdUnit.h:81
 
   ASTContext ();
   const ASTContext () const;

ioeric wrote:
> IIUC, `ASTContext` in a `ParsedAST` may not contain information from 
> preambles and thus may give an incomplete AST. If so, I think we should make 
> this more explicit in the class level to make sure this is not misused (e.g. 
> in case the incomplete context is used to build dynamic index).
Added a small doc comment about it. Let me know if you feel we need to 
elaborate more on this.
I don't think anything changed wrt to this behavior in this patch, apart from 
the fact that we used to deserialize more stuff most of the time before so this 
wan't as visible.



Comment at: unittests/clangd/TestTU.cpp:77
   const NamedDecl *Result = nullptr;
-  for (const Decl *D : AST.getTopLevelDecls()) {
+  for (const Decl *D : AST.getLocalTopLevelDecls()) {
 auto *ND = dyn_cast(D);

sammccall wrote:
> isn't this incorrect? Or should be "findDeclInMainFile" or similar?
> 
> I'd think this would conflict with your other patch, which uses this to test 
> the boost of things that come from the header.
Thanks for spotting that, I would also expect this to fail in the new patch.
I'll look into rewriting this helper.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47331



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


[PATCH] D47331: [clangd] Remove accessors for top-level decls from preamble

2018-05-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 148602.
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added a comment.

- Rename the field in addition to the getter
- Address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47331

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/XRefs.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -74,7 +74,7 @@
 
 const NamedDecl (ParsedAST , llvm::StringRef QName) {
   const NamedDecl *Result = nullptr;
-  for (const Decl *D : AST.getTopLevelDecls()) {
+  for (const Decl *D : AST.getLocalTopLevelDecls()) {
 auto *ND = dyn_cast(D);
 if (!ND || ND->getNameAsString() != QName)
   continue;
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -168,7 +168,7 @@
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
+  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
  DeclMacrosFinder, IndexOpts);
 
   return {DeclMacrosFinder.takeDecls(), DeclMacrosFinder.takeMacroInfos()};
@@ -418,7 +418,7 @@
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
-  indexTopLevelDecls(AST.getASTContext(), AST.getTopLevelDecls(),
+  indexTopLevelDecls(AST.getASTContext(), AST.getLocalTopLevelDecls(),
  DocHighlightsFinder, IndexOpts);
 
   return DocHighlightsFinder.takeHighlights();
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -44,12 +44,10 @@
 
 // Stores Preamble and associated data.
 struct PreambleData {
-  PreambleData(PrecompiledPreamble Preamble,
-   std::vector TopLevelDeclIDs,
-   std::vector Diags, std::vector Inclusions);
+  PreambleData(PrecompiledPreamble Preamble, std::vector Diags,
+   std::vector Inclusions);
 
   PrecompiledPreamble Preamble;
-  std::vector TopLevelDeclIDs;
   std::vector Diags;
   // Processes like code completions and go-to-definitions will need #include
   // information, and their compile action skips preamble range.
@@ -80,17 +78,19 @@
 
   ~ParsedAST();
 
+  /// Note that the returned ast will not contain decls from the preamble that
+  /// were not deserialized during parsing. Clients should expect only decls
+  /// from the main file to be in the AST.
   ASTContext ();
   const ASTContext () const;
 
   Preprocessor ();
   std::shared_ptr getPreprocessorPtr();
   const Preprocessor () const;
 
-  /// This function returns all top-level decls, including those that come
-  /// from Preamble. Decls, coming from Preamble, have to be deserialized, so
-  /// this call might be expensive.
-  ArrayRef getTopLevelDecls();
+  /// This function returns top-level decls present in the main file of the AST.
+  /// The result does not include the decls that come from the preamble.
+  ArrayRef getLocalTopLevelDecls();
 
   const std::vector () const;
 
@@ -103,11 +103,8 @@
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action,
-std::vector TopLevelDecls, std::vector Diags,
-std::vector Inclusions);
-
-private:
-  void ensurePreambleDeclsDeserialized();
+std::vector LocalTopLevelDecls,
+std::vector Diags, std::vector Inclusions);
 
   // In-memory preambles must outlive the AST, it is important that this member
   // goes before Clang and Action.
@@ -122,8 +119,9 @@
 
   // Data, stored after parsing.
   std::vector Diags;
-  std::vector TopLevelDecls;
-  bool PreambleDeclsDeserialized;
+  // Top-level decls inside the current file. Not that this does not include
+  // top-level decls from the preamble.
+  std::vector LocalTopLevelDecls;
   std::vector Inclusions;
 };
 
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -90,37 +90,15 @@
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
   : File(File), ParsedCallback(ParsedCallback) {}
 
-  std::vector takeTopLevelDeclIDs() {
-return std::move(TopLevelDeclIDs);
-  }
-
   std::vector takeInclusions() { return std::move(Inclusions); }
 
-  void AfterPCHEmitted(ASTWriter ) override {
-TopLevelDeclIDs.reserve(TopLevelDecls.size());
-for (Decl *D : TopLevelDecls) {
-  // Invalid top-level decls may not have been serialized.
-  if (D->isInvalidDecl())
-continue;
-  TopLevelDeclIDs.push_back(Writer.getDeclID(D));
-}
-  }
-
   

[PATCH] D47063: [clangd] Keep only a limited number of idle ASTs in memory

2018-05-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

The cache looks way simpler now, thank you!
As discussed offline, flattening ASTBuilder right into ASTWorker still seems 
like a good idea to me, but happy with what you come up with there.




Comment at: clangd/TUScheduler.cpp:71
+
+  /// Update the function used to compute the value.
+  void update(std::function ComputeF);

ilya-biryukov wrote:
> sammccall wrote:
> > I think I understand this more as "updates the value" but the value is 
> > lazy...
> > 
> > I find this API somewhat hard to follow, maybe just because it's unfamiliar.
> > I've mostly seen cache APIs look like one of:
> > 1. `Cache(function Compute)`, `Value Cache::get(Input)`
> > 2. `void Cache::put(Key, Value)`, `Optional Cache::get(Key)`
> > 3. `Handle Cache::put(Value)`, `Optional Handle::get()`
> > 
> > This one is `Slot Cache::create()`, `void Slot::update(function 
> > LazyV)`, `Value Slot::get()`.
> > 
> > It's similar-ish to 3, but has 3 nontrivial operations instead of 2, and 
> > the slot object is externally mutable instead of immutable, so it seems 
> > more complex. What does it buy us in exchange?
> > 
> > (1 & 2 work well with a natural key or inputs that are easy to compare, 
> > which we don't particularly have)
> As discussed offline, now we have a simpler version that keeps `unique_ptr`s 
> to idle ASTs and the clients are responsible for building the ASTs.
> Note that it's not a "cache" per se, so we might want a different name for 
> that.
> @sammccall, you suggested to call it a pool, I find it reasonable.  Should we 
> name it `ASTPool` instead of `ASTCache`?
I think the name is actually fine, it's still mostly a cache.
It does have things in common with a pool, but unrelated consumers can't share 
a resource, so I think that name is at least as misleading.



Comment at: clangd/TUScheduler.cpp:66
+
+/// Provides an LRU cache of ASTs.
+class TUScheduler::ASTCache {

I'd say a little more about the interaction here. e.g. 
```
/// An LRU cache of idle ASTs.
/// Because we want to limit the overall number of these we retain, the cache
/// owns ASTs (and may evict them) while their workers are idle.
/// Workers borrow them when active, and return them when done.



Comment at: clangd/TUScheduler.cpp:84
+  /// Store the value in the pool, possibly removing the last used AST.
+  void put(Key K, std::unique_ptr V) {
+std::unique_lock Lock(Mut);

consider assert(findByKey(K) == LRU.end()) as a precondition



Comment at: clangd/TUScheduler.cpp:92
+LRU.pop_back();
+// AST destructor may need to run, make sure it happens outside the lock.
+Lock.unlock();

Just "run the expensive destructor outside the lock"?
the "may not" case seems unimportant and slightly confusing here



Comment at: clangd/TUScheduler.cpp:94
+Lock.unlock();
+ForCleanup.reset();
+  }

this line isn't actually needed right?



Comment at: clangd/TUScheduler.cpp:342
+if (!AST)
+  return Action(llvm::make_error(
+  "invalid AST", llvm::errc::invalid_argument));

This failure doesn't get cached, correct? That's bad for performance.

But if we think this is always a clangd bug, it's probably fine. (and certainly 
simplifies things)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47063



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


[PATCH] D47291: Proposal to make rtti errors more generic.

2018-05-25 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6729
 def err_no_dynamic_cast_with_fno_rtti : Error<
-  "cannot use dynamic_cast with -fno-rtti">;
+  "use of dynamic_cast requires enabling RTTI">;
 

I'd prefer to have the way to enable RTTI mentioned in the message. Could we 
have something like `ToolChain::getRTTIMode()` and have a "RTTI was on/of" or 
"RTTI defaulted to on/off"? That way we'd be able to have a message similar to 
the current one (mentioning "you passed -fno-rtti") on platforms that default 
to RTTI=on, and have your updated message (possibly with a mention of "use 
-frtti") on platforms that default to RTTI=off.

(This is a minor usability comment about this patch, I don't consider it a 
blocker or anything)


Repository:
  rC Clang

https://reviews.llvm.org/D47291



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


r333276 - Fix members initialization order in constructor (fails with -Werror)

2018-05-25 Thread Ivan Donchevskii via cfe-commits
Author: yvvan
Date: Fri May 25 06:46:07 2018
New Revision: 333276

URL: http://llvm.org/viewvc/llvm-project?rev=333276=rev
Log:
Fix members initialization order in constructor (fails with -Werror)

Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=333276=333275=333276=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Fri May 25 06:46:07 2018
@@ -840,10 +840,10 @@ public:
bool Accessible = true,
std::vector FixIts = 
std::vector())
   : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
-Hidden(false), QualifierIsInformative(QualifierIsInformative),
+FixIts(std::move(FixIts)), Hidden(false),
+QualifierIsInformative(QualifierIsInformative),
 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
-DeclaringEntity(false), Qualifier(Qualifier),
-FixIts(std::move(FixIts)) {
+DeclaringEntity(false), Qualifier(Qualifier) {
 //FIXME: Add assert to check FixIts range requirements.
 computeCursorKindAndAvailability(Accessible);
   }


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


[PATCH] D47063: [clangd] Keep only a limited number of idle ASTs in memory

2018-05-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I have addressed the comments regarding the cache implementation. ASTBuilder 
ones are still pending, but I would appreciate the feedback on how 
`TUScheduler.cpp` looks like.




Comment at: clangd/ClangdUnit.h:132
 
-/// Manages resources, required by clangd. Allows to rebuild file with new
-/// contents, and provides AST and Preamble for it.
-class CppFile {
+/// A helper class that handles building preambles and ASTs for a file. Also
+/// adds some logging.

sammccall wrote:
> ilya-biryukov wrote:
> > sammccall wrote:
> > > This may be change aversion, but I'm not sure this class does enough 
> > > after this change - it doesn't store the inputs or the outputs/cache, so 
> > > it kind of seems like it wants to be a function.
> > > 
> > > I guess the motivation here is that storing the outputs means dealing 
> > > with the cache, and the cache is local to TUScheduler.
> > > But `CppFile` is only used in TUScheduler, so we could move this there 
> > > too? It feels like expanding the scope more than I'd like.
> > > 
> > > The upside is that I think it's a more natural division of 
> > > responsibility: `CppFile` could continue to be the "main" holder of the 
> > > `shared_ptr` (which we don't limit, but share), and instead of 
> > > `Optional` it'd have a `weak_ptr` which is 
> > > controlled and can be refreshed through the cache.
> > > 
> > > As discussed offline, the cache could look something like:
> > > ```
> > > class Cache {
> > >shared_ptr put(ParsedAST);
> > >void hintUsed(ParsedAST*); // optional, bumps LRU when client reads
> > >void hintUnused(ParsedAST*); // optional, releases when client abandons
> > > }
> > > 
> > > shared_ptr CppFile::getAST() {
> > >   shared_ptr AST = WeakAST.lock();
> > >   if (AST)
> > > Cache.hintUsed(AST.get());
> > >   else
> > > WeakAST = AST = Cache.put(build...);
> > >   return AST;
> > > }
> > > ```
> > I've reimplemented the cache with weak_ptr/shared_ptr. 
> > With a slightly different interface to hide more stuff in the cache API. 
> > Please take a look and let me know what you think.
> > 
> > Nevertheless, I still find `CppFile` refactoring useful. It unties 
> > preambles from the ASTs and I believe this is a good thing, given that 
> > their lifetimes are different.
> I'm not sure how much they were tangled before, they were computed in the 
> same place, but accessed separately, and it's not sure you ever *want* to 
> compute them separately? (possibly in unit tests?)
> 
> I do think making ASTWorker maintain the old preamble and pass it in is 
> confusing. The remaining members are trivial and unrelated enough that I do 
> think if the references to the preamble/ast are removed, then moving the 
> remaining members to ASTWorker or to a dumb struct, and making these free 
> functions would make it easier to navigate the class structure.
> it's not sure you ever *want* to compute them separately?
I think that's exactly what we're doing now. The ASTs can now get built 
separately from the preamble, because they can be evicted from the cache and 
need to be rebuild while  preamble is not changed.

> The remaining members are trivial and unrelated enough that I do think if the 
> references to the preamble/ast are removed, then moving the remaining members 
> to ASTWorker or to a dumb struct, and making these free functions would make 
> it easier to navigate the class structure.
Dumb struct SG, it's essentially what ASTWorker is right now.



Comment at: clangd/TUScheduler.cpp:71
+
+  /// Update the function used to compute the value.
+  void update(std::function ComputeF);

sammccall wrote:
> I think I understand this more as "updates the value" but the value is lazy...
> 
> I find this API somewhat hard to follow, maybe just because it's unfamiliar.
> I've mostly seen cache APIs look like one of:
> 1. `Cache(function Compute)`, `Value Cache::get(Input)`
> 2. `void Cache::put(Key, Value)`, `Optional Cache::get(Key)`
> 3. `Handle Cache::put(Value)`, `Optional Handle::get()`
> 
> This one is `Slot Cache::create()`, `void Slot::update(function 
> LazyV)`, `Value Slot::get()`.
> 
> It's similar-ish to 3, but has 3 nontrivial operations instead of 2, and the 
> slot object is externally mutable instead of immutable, so it seems more 
> complex. What does it buy us in exchange?
> 
> (1 & 2 work well with a natural key or inputs that are easy to compare, which 
> we don't particularly have)
As discussed offline, now we have a simpler version that keeps `unique_ptr`s to 
idle ASTs and the clients are responsible for building the ASTs.
Note that it's not a "cache" per se, so we might want a different name for that.
@sammccall, you suggested to call it a pool, I find it reasonable.  Should we 
name it `ASTPool` instead of `ASTCache`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47063




[PATCH] D45686: [Driver] Clean up tmp files when deleting Compilation objects

2018-05-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

LGTM, but i'm quite unfamiliar with this area of the code,
so please wait for someone else to accept :)




Comment at: lib/Driver/Compilation.cpp:276-277
+
+  // Temporary files added by diagnostics should be kept.
+  SaveTempsEnabled = true;
 }

dstenb wrote:
> lebedev.ri wrote:
> > Is there a test that breaks without this?
> Yes, the following tests fail:
> 
>   - Driver/crash-report-modules.m
>   - Driver/crash-report-spaces.c
>   - Driver/crash-report-header.h
>   - Driver/crash-report.c
>   - Modules/crash-vfs-path-emptydir-entries.m
>   - Modules/crash-vfs-path-symlink-topheader.m
>   - Modules/crash-vfs-path-symlink-component.m
>   - Modules/crash-vfs-path-traversal.m
>   - Modules/crash-vfs-relative-overlay.m
>   - Modules/crash-vfs-umbrella-frameworks.m
> 
> due to the preprocessed files for the crash diagnostics having been removed.
Ok, good.


https://reviews.llvm.org/D45686



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


[PATCH] D47063: [clangd] Keep only a limited number of idle ASTs in memory

2018-05-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 148599.
ilya-biryukov added a comment.

- Rebase, fix merge conflicts
- Simpler implemenataion of the Cache
- s/IdleASTs/ASTCache


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47063

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  test/clangd/trace.test
  unittests/clangd/FileIndexTests.cpp

Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -11,6 +11,7 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "index/FileIndex.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -210,15 +211,15 @@
   auto FooH = testPath("foo.h");
   FileIndex Index;
   bool IndexUpdated = false;
-  CppFile File("foo.cpp", /*StorePreambleInMemory=*/true,
-   std::make_shared(),
-   [, ](PathRef FilePath, ASTContext ,
-   std::shared_ptr PP) {
- EXPECT_FALSE(IndexUpdated)
- << "Expected only a single index update";
- IndexUpdated = true;
- Index.update(FilePath, , std::move(PP));
-   });
+  ASTBuilder Builder("foo.cpp", /*StorePreambleInMemory=*/true,
+ std::make_shared(),
+ [, ](PathRef FilePath, ASTContext ,
+ std::shared_ptr PP) {
+   EXPECT_FALSE(IndexUpdated)
+   << "Expected only a single index update";
+   IndexUpdated = true;
+   Index.update(FilePath, , std::move(PP));
+ });
 
   // Preparse ParseInputs.
   ParseInputs PI;
@@ -243,7 +244,9 @@
   )cpp";
 
   // Rebuild the file.
-  File.rebuild(std::move(PI));
+  auto CI = Builder.buildCompilerInvocation(PI);
+  Builder.buildPreamble(*CI, /*OldPreamble=*/nullptr, tooling::CompileCommand(),
+PI);
   ASSERT_TRUE(IndexUpdated);
 
   // Check the index contains symbols from the preamble, but not from the main
Index: test/clangd/trace.test
===
--- test/clangd/trace.test
+++ test/clangd/trace.test
@@ -8,14 +8,14 @@
 # CHECK:   "args": {
 # CHECK: "File": "{{.*(/|\\)}}foo.c"
 # CHECK:   },
-# CHECK:   "name": "Preamble",
+# CHECK:   "name": "BuildPreamble",
 # CHECK:   "ph": "X",
 # CHECK: }
 # CHECK: {
 # CHECK:   "args": {
 # CHECK: "File": "{{.*(/|\\)}}foo.c"
 # CHECK:   },
-# CHECK:   "name": "Build",
+# CHECK:   "name": "BuildAST",
 # CHECK:   "ph": "X",
 # CHECK: }
 # CHECK: },
Index: clangd/TUScheduler.h
===
--- clangd/TUScheduler.h
+++ clangd/TUScheduler.h
@@ -42,6 +42,15 @@
 /// within a bounded amount of time.
 };
 
+/// Configuration of the AST retention policy. This only covers retention of
+/// *idle* ASTs. If queue has operations requiring the AST, they might be
+/// kept in memory.
+struct ASTRetentionParams {
+  /// Maximum number of ASTs to be retained in memory when there are no pending
+  /// requests for them.
+  unsigned MaxRetainedASTs = 3;
+};
+
 /// Handles running tasks for ClangdServer and managing the resources (e.g.,
 /// preambles and ASTs) for opened files.
 /// TUScheduler is not thread-safe, only one thread should be providing updates
@@ -53,7 +62,8 @@
 public:
   TUScheduler(unsigned AsyncThreadsCount, bool StorePreamblesInMemory,
   PreambleParsedCallback PreambleCallback,
-  std::chrono::steady_clock::duration UpdateDebounce);
+  std::chrono::steady_clock::duration UpdateDebounce,
+  ASTRetentionParams RetentionConfig = {});
   ~TUScheduler();
 
   /// Returns estimated memory usage for each of the currently open files.
@@ -99,11 +109,18 @@
   /// This class stores per-file data in the Files map.
   struct FileData;
 
+public:
+  /// Responsible for retaining and rebuilding idle ASTs. An implementation is
+  /// an LRU cache.
+  class ASTCache;
+
+private:
   const bool StorePreamblesInMemory;
   const std::shared_ptr PCHOps;
   const PreambleParsedCallback PreambleCallback;
   Semaphore Barrier;
   llvm::StringMap Files;
+  std::unique_ptr IdleASTs;
   // None when running tasks synchronously and non-None when running tasks
   // asynchronously.
   llvm::Optional PreambleTasks;
Index: clangd/TUScheduler.cpp
===
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -45,16 +45,82 @@
 #include "TUScheduler.h"
 #include "Logger.h"
 #include "Trace.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include 

[PATCH] D45686: [Driver] Clean up tmp files when deleting Compilation objects

2018-05-25 Thread David Stenberg via Phabricator via cfe-commits
dstenb added inline comments.



Comment at: lib/Driver/Compilation.cpp:276-277
+
+  // Temporary files added by diagnostics should be kept.
+  SaveTempsEnabled = true;
 }

lebedev.ri wrote:
> Is there a test that breaks without this?
Yes, the following tests fail:

  - Driver/crash-report-modules.m
  - Driver/crash-report-spaces.c
  - Driver/crash-report-header.h
  - Driver/crash-report.c
  - Modules/crash-vfs-path-emptydir-entries.m
  - Modules/crash-vfs-path-symlink-topheader.m
  - Modules/crash-vfs-path-symlink-component.m
  - Modules/crash-vfs-path-traversal.m
  - Modules/crash-vfs-relative-overlay.m
  - Modules/crash-vfs-umbrella-frameworks.m

due to the preprocessed files for the crash diagnostics having been removed.


https://reviews.llvm.org/D45686



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


[PATCH] D46933: [analyzer] Added template argument lists to the Pathdiagnostic output

2018-05-25 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC333275: [analyzer] Added template argument lists to the 
Pathdiagnostic output (authored by Szelethus, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D46933

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/plist-diagnostics-template-function.cpp
  test/Analysis/plist-diagnostics-template-record.cpp

Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/OperationKinds.h"
@@ -1000,11 +1001,49 @@
 CalleeCtx->getAnalysisDeclContext()->isBodyAutosynthesized());
 }
 
+static void describeTemplateParameters(raw_ostream ,
+   const ArrayRef TAList,
+   const LangOptions ,
+   StringRef Prefix = StringRef(),
+   StringRef Postfix = StringRef());
+
+static void describeTemplateParameter(raw_ostream ,
+  const TemplateArgument ,
+  const LangOptions ) {
+
+  if (TArg.getKind() == TemplateArgument::ArgKind::Pack) {
+describeTemplateParameters(Out, TArg.getPackAsArray(), LO);
+  } else {
+TArg.print(PrintingPolicy(LO), Out);
+  }
+}
+
+static void describeTemplateParameters(raw_ostream ,
+   const ArrayRef TAList,
+   const LangOptions ,
+   StringRef Prefix, StringRef Postfix) {
+  if (TAList.empty())
+return;
+
+  Out << Prefix;
+  for (int I = 0, Last = TAList.size() - 1; I != Last; ++I) {
+describeTemplateParameter(Out, TAList[I], LO);
+Out << ", ";
+  }
+  describeTemplateParameter(Out, TAList[TAList.size() - 1], LO);
+  Out << Postfix;
+}
+
 static void describeClass(raw_ostream , const CXXRecordDecl *D,
   StringRef Prefix = StringRef()) {
   if (!D->getIdentifier())
 return;
-  Out << Prefix << '\'' << *D << '\'';
+  Out << Prefix << '\'' << *D;
+  if (const auto T = dyn_cast(D))
+describeTemplateParameters(Out, T->getTemplateArgs().asArray(),
+   D->getASTContext().getLangOpts(), "<", ">");
+
+  Out << '\'';
 }
 
 static bool describeCodeDecl(raw_ostream , const Decl *D,
@@ -1062,7 +1101,16 @@
 return true;
   }
 
-  Out << Prefix << '\'' << cast(*D) << '\'';
+  Out << Prefix << '\'' << cast(*D);
+
+  // Adding template parameters.
+  if (const auto FD = dyn_cast(D))
+if (const TemplateArgumentList *TAList =
+FD->getTemplateSpecializationArgs())
+  describeTemplateParameters(Out, TAList->asArray(),
+ FD->getASTContext().getLangOpts(), "<", ">");
+
+  Out << '\'';
   return true;
 }
 
Index: test/Analysis/plist-diagnostics-template-function.cpp
===
--- test/Analysis/plist-diagnostics-template-function.cpp
+++ test/Analysis/plist-diagnostics-template-function.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_analyze_cc1 -analyzer-output=plist -o %t.plist -std=c++11 -analyzer-checker=core %s
+// RUN: FileCheck --input-file=%t.plist %s
+
+bool ret();
+
+template 
+void f(int i) {
+  if (ret())
+i = i / (i - 5);
+}
+
+template <>
+void f(int i) {
+  if (ret())
+i = i / (i - 5);
+}
+
+template 
+void defaultTemplateParameterFunction(int i) {
+  if (ret())
+int a = 10 / i;
+}
+
+template 
+void variadicTemplateFunction(int i) {
+  if (ret())
+int a = 10 / i;
+}
+
+int main() {
+  f(5);
+  f(5);
+  defaultTemplateParameterFunction<>(0);
+  variadicTemplateFunction(0);
+}
+
+// CHECK:  Calling ffloat
+// CHECK:  Calling fint
+// CHECK:  Calling defaultTemplateParameterFunction0
+// CHECK:  Calling variadicTemplateFunctionchar, float, double, int *
+
Index: test/Analysis/plist-diagnostics-template-record.cpp
===
--- test/Analysis/plist-diagnostics-template-record.cpp
+++ test/Analysis/plist-diagnostics-template-record.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_analyze_cc1 -analyzer-output=plist -o %t.plist -std=c++11 -analyzer-checker=core %s
+// RUN: FileCheck --input-file=%t.plist %s
+
+bool ret();
+
+template 
+struct DivByZero {
+  int i;
+  DivByZero(bool b) {
+if (ret())
+  i = 50 / (b - 1);
+  }
+};
+
+template 
+struct DivByZero {
+  int i;
+  DivByZero(bool b) {
+if (ret())
+  

r333275 - [analyzer] Added template argument lists to the Pathdiagnostic output

2018-05-25 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri May 25 06:18:38 2018
New Revision: 333275

URL: http://llvm.org/viewvc/llvm-project?rev=333275=rev
Log:
[analyzer] Added template argument lists to the Pathdiagnostic output

Because template parameter lists were not displayed
in the plist output, it was difficult to decide in
some cases whether a given checker found a true or a
false positive. This patch aims to correct this.

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

Added:
cfe/trunk/test/Analysis/plist-diagnostics-template-function.cpp
cfe/trunk/test/Analysis/plist-diagnostics-template-record.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=333275=333274=333275=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Fri May 25 06:18:38 
2018
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/OperationKinds.h"
@@ -1000,11 +1001,49 @@ void PathDiagnosticCallPiece::setCallee(
 CalleeCtx->getAnalysisDeclContext()->isBodyAutosynthesized());
 }
 
+static void describeTemplateParameters(raw_ostream ,
+   const ArrayRef TAList,
+   const LangOptions ,
+   StringRef Prefix = StringRef(),
+   StringRef Postfix = StringRef());
+
+static void describeTemplateParameter(raw_ostream ,
+  const TemplateArgument ,
+  const LangOptions ) {
+
+  if (TArg.getKind() == TemplateArgument::ArgKind::Pack) {
+describeTemplateParameters(Out, TArg.getPackAsArray(), LO);
+  } else {
+TArg.print(PrintingPolicy(LO), Out);
+  }
+}
+
+static void describeTemplateParameters(raw_ostream ,
+   const ArrayRef TAList,
+   const LangOptions ,
+   StringRef Prefix, StringRef Postfix) {
+  if (TAList.empty())
+return;
+
+  Out << Prefix;
+  for (int I = 0, Last = TAList.size() - 1; I != Last; ++I) {
+describeTemplateParameter(Out, TAList[I], LO);
+Out << ", ";
+  }
+  describeTemplateParameter(Out, TAList[TAList.size() - 1], LO);
+  Out << Postfix;
+}
+
 static void describeClass(raw_ostream , const CXXRecordDecl *D,
   StringRef Prefix = StringRef()) {
   if (!D->getIdentifier())
 return;
-  Out << Prefix << '\'' << *D << '\'';
+  Out << Prefix << '\'' << *D;
+  if (const auto T = dyn_cast(D))
+describeTemplateParameters(Out, T->getTemplateArgs().asArray(),
+   D->getASTContext().getLangOpts(), "<", ">");
+
+  Out << '\'';
 }
 
 static bool describeCodeDecl(raw_ostream , const Decl *D,
@@ -1062,7 +1101,16 @@ static bool describeCodeDecl(raw_ostream
 return true;
   }
 
-  Out << Prefix << '\'' << cast(*D) << '\'';
+  Out << Prefix << '\'' << cast(*D);
+
+  // Adding template parameters.
+  if (const auto FD = dyn_cast(D))
+if (const TemplateArgumentList *TAList =
+FD->getTemplateSpecializationArgs())
+  describeTemplateParameters(Out, TAList->asArray(),
+ FD->getASTContext().getLangOpts(), "<", ">");
+
+  Out << '\'';
   return true;
 }
 

Added: cfe/trunk/test/Analysis/plist-diagnostics-template-function.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plist-diagnostics-template-function.cpp?rev=333275=auto
==
--- cfe/trunk/test/Analysis/plist-diagnostics-template-function.cpp (added)
+++ cfe/trunk/test/Analysis/plist-diagnostics-template-function.cpp Fri May 25 
06:18:38 2018
@@ -0,0 +1,41 @@
+// RUN: %clang_analyze_cc1 -analyzer-output=plist -o %t.plist -std=c++11 
-analyzer-checker=core %s
+// RUN: FileCheck --input-file=%t.plist %s
+
+bool ret();
+
+template 
+void f(int i) {
+  if (ret())
+i = i / (i - 5);
+}
+
+template <>
+void f(int i) {
+  if (ret())
+i = i / (i - 5);
+}
+
+template 
+void defaultTemplateParameterFunction(int i) {
+  if (ret())
+int a = 10 / i;
+}
+
+template 
+void variadicTemplateFunction(int i) {
+  if (ret())
+int a = 10 / i;
+}
+
+int main() {
+  f(5);
+  f(5);
+  defaultTemplateParameterFunction<>(0);
+  variadicTemplateFunction(0);
+}
+
+// CHECK:  Calling ffloat
+// CHECK:  Calling fint
+// CHECK:  Calling 
defaultTemplateParameterFunction0
+// CHECK:  Calling 

  1   2   >