[PATCH] D43737: Improve -Winfinite-recursion

2018-03-12 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu added a comment.

>   I believe you were around this code last, so can you remember why it was 
> there?

Yes, that's an early exit to speed up the check.  You can remove that check and 
add a test case for it.

This was a little confusing for me, so let's refactor it a little.  These 
changes will make it so that any CFGBlock in the WorkList has already been 
checked, so it can go straight to checking the successors.




Comment at: lib/Sema/AnalysisBasedWarnings.cpp:203-204
 
-// All blocks are in one of three states.  States are ordered so that blocks
-// can only move to higher states.
-enum RecursiveState {
-  FoundNoPath,
-  FoundPath,
-  FoundPathWithNoRecursiveCall
-};
-
 // Returns true if there exists a path to the exit block and every path
 // to the exit block passes through a call to FD.
 static bool checkForRecursiveFunctionCall(const FunctionDecl *FD, CFG *cfg) {

Update comment to reflect your changes.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:224-225
 
-  // Mark all nodes as FoundNoPath, then set the status of the entry block.
-  SmallVector States(cfg->getNumBlockIDs(), FoundNoPath);
-  States[cfg->getEntry().getBlockID()] = FoundPathWithNoRecursiveCall;
-
-  // Make the processing stack and seed it with the entry block.
-  SmallVector Stack;
-  Stack.push_back(&cfg->getEntry());
-
-  while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
+  // Seed the work list with the entry block.
+  foundRecursion |= analyzeSuccessor(&cfg->getEntry());
 

The entry CFGBlock is special.  It will never trigger on any of the conditions 
we are checking for.  Just push it into WorkList and Visited.  It has no 
statements, so it can't have a recursive call.

http://clang.llvm.org/docs/InternalsManual.html#entry-and-exit-blocks

Technically, it has no incoming edges, so you don't even need to insert it into 
Visited.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:232-233
+// Found a path to the exit node without a recursive call.
+if (ExitID == ID)
+  return false;
 

ID is not longer needed as an index so it is only needed here, so it should be 
inlined.

Also, move this check in the loop over the successors, so there are no checks 
on the current CFG block.  This way, all checks happen at the same place.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:237
+  if (*I)
+foundRecursion |= analyzeSuccessor(*I);
   }

Since the lambda isn't needed for seeding the WorkList, this is the only use 
and it should be inlined here.

Also, use:
```
   if (cond)
 foundRecursion = true;
```
instead of:

```
  foundRecursion |= true;
```


https://reviews.llvm.org/D43737



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


[PATCH] D44411: [libc++] Fix Container::insert(value_type const&) tests

2018-03-12 Thread Joe Loser via Phabricator via cfe-commits
jloser created this revision.
jloser added reviewers: EricWF, matthew.
Herald added subscribers: cfe-commits, christof.

[libc++] Fix Container::insert(value_type const&) tests

Several unit tests meaning to test the behavior of lvalue insertion incorrectly 
pass rvalues.  Fixes bug 27394.


Repository:
  rCXX libc++

https://reviews.llvm.org/D44411

Files:
  libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp
  libcxx/test/std/containers/associative/set/insert_cv.pass.cpp
  
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp
  
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp
  
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp
  
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp
  
libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp
  libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
  libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp

Index: libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
@@ -24,53 +24,42 @@
 
 #include "min_allocator.h"
 
+template
+void do_insert_hint_const_lvalue_test()
+{
+typedef Container C;
+typedef typename C::iterator R;
+typedef typename C::value_type VT;
+C c;
+typename C::const_iterator e = c.end();
+const VT v1(3.5);
+R r = c.insert(e, v1);
+assert(c.size() == 1);
+assert(*r == 3.5);
+
+r = c.insert(e, v1);
+assert(c.size() == 1);
+assert(*r == 3.5);
+
+const VT v2(4.5);
+r = c.insert(e, v2);
+assert(c.size() == 2);
+assert(*r == 4.5);
+
+const VT v3(5.5);
+r = c.insert(e, v3);
+assert(c.size() == 3);
+assert(*r == 5.5);
+}
+
 int main()
 {
-{
-typedef std::unordered_set C;
-typedef C::iterator R;
-typedef C::value_type P;
-C c;
-C::const_iterator e = c.end();
-R r = c.insert(e, P(3.5));
-assert(c.size() == 1);
-assert(*r == 3.5);
-
-r = c.insert(e, P(3.5));
-assert(c.size() == 1);
-assert(*r == 3.5);
-
-r = c.insert(e, P(4.5));
-assert(c.size() == 2);
-assert(*r == 4.5);
-
-r = c.insert(e, P(5.5));
-assert(c.size() == 3);
-assert(*r == 5.5);
-}
+do_insert_hint_const_lvalue_test >();
 #if TEST_STD_VER >= 11
 {
 typedef std::unordered_set,
 std::equal_to, min_allocator> C;
-typedef C::iterator R;
-typedef C::value_type P;
-C c;
-C::const_iterator e = c.end();
-R r = c.insert(e, P(3.5));
-assert(c.size() == 1);
-assert(*r == 3.5);
-
-r = c.insert(e, P(3.5));
-assert(c.size() == 1);
-assert(*r == 3.5);
-
-r = c.insert(e, P(4.5));
-assert(c.size() == 2);
-assert(*r == 4.5);
-
-r = c.insert(e, P(5.5));
-assert(c.size() == 3);
-assert(*r == 5.5);
+do_insert_hint_const_lvalue_test();
 }
 #endif
 #if _LIBCPP_DEBUG >= 1
Index: libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
@@ -20,59 +20,45 @@
 
 #include "min_allocator.h"
 
+template
+void do_insert_const_lvalue_test()
+{
+typedef Container C;
+typedef std::pair R;
+typedef typename C::value_type VT;
+C c;
+const VT v1(3.5);
+R r = c.insert(v1);
+assert(c.size() == 1);
+assert(*r.first == 3.5);
+assert(r.second);
+
+r = c.insert(v1);
+assert(c.size() == 1);
+assert(*r.first == 3.5);
+assert(!r.second);
+
+const VT v2(4.5);
+r = c.insert(v2);
+assert(c.size() == 2);
+assert(*r.first == 4.5);
+assert(r.second);
+
+const VT v3(5.5);
+r = c.insert(v3);
+assert(c.size() == 3);
+assert(*r.first == 5.5);
+assert(r.second);
+}
+
 int main()
 {
-{
-typedef std::unordered_set C;
-typedef std::pair R;
-typedef C::value_type P;
-C c;
-R r = c.insert(P(3.5));
-assert(c.size() == 1);
-assert(*r.first == 3.5);
-assert(r.second);
-
-r = c.insert(P(3.5));
-assert(c.size() == 1);
-assert(*r.first == 3.5);
-assert(!r.second);
-
-r = c.insert(P(4.5));
-assert(c.size() == 2);
-as

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1035509, @aaron.ballman wrote:

> LGTM with the test comments fixed up.


Thanks!  I'll commit tomorrow.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with the test comments fixed up.




Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:5
+// RUN: %clang -emit-ast -o %t.ast %S/../Sema/attr-print.cpp
+// RUN: %clang_cc1 %t.ast -ast-print | FileCheck %S/../Sema/attr-print.cpp

jdenny wrote:
> aaron.ballman wrote:
> > Just to verify my understanding, this test is checking the serialization 
> > and deserialization?
> That's right, and it failed without the other changes in this revision 
> because alloc_size's second argument serialized/deserialized as 0 when it was 
> actually invalid (that is, unspecified).  Of course, this test is more 
> thorough than just exercising alloc_size.
Perfect, thank you!


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:5
+// RUN: %clang -emit-ast -o %t.ast %S/../Sema/attr-print.cpp
+// RUN: %clang_cc1 %t.ast -ast-print | FileCheck %S/../Sema/attr-print.cpp

aaron.ballman wrote:
> Just to verify my understanding, this test is checking the serialization and 
> deserialization?
That's right, and it failed without the other changes in this revision because 
alloc_size's second argument serialized/deserialized as 0 when it was actually 
invalid (that is, unspecified).  Of course, this test is more thorough than 
just exercising alloc_size.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:5
+// RUN: %clang -emit-ast -o %t.ast %S/../Sema/attr-print.cpp
+// RUN: %clang_cc1 %t.ast -ast-print | FileCheck %S/../Sema/attr-print.cpp

Just to verify my understanding, this test is checking the serialization and 
deserialization?


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > Can you move this below the RUN line?
> > Sure.  I'm still trying to learn the LLVM coding standards.  Is this 
> > specified there?
> Nope! I'm just used to looking at the very first line of the test to know 
> what it's running, and that seems consistent with other tests.
OK, that makes sense.  I'll be sure to change both of those.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D43248#1035477, @jdenny wrote:

> In https://reviews.llvm.org/D43248#1035466, @aaron.ballman wrote:
>
> > It seems like there are some other changes than just the serialize and 
> > deserialize that I'm not opposed to, but am wondering why they're needed. 
> > It seems some functions are now `getFoo()` calls
>
>
> These were originally named getFoo, and my previous patch changed them to 
> foo.  I believe I did that to make ParamIdxArgument accessors more like 
> VariadicParamIdxArgument accessors (which inherits accessors from 
> VariadicArgument), but I probably shouldn't have done that.  In any case, 
> this new revision implements ParamIdxArgument using SimpleArgument, and that 
> names accessors like getFoo.


Ahhh, thank you for the explanation, that makes sense.

>> and it seems like some declarations moved around. Are those intended as part 
>> of this patch?
> 
> Are you referring to the changes in SemaDeclAttr.cpp?  Those changes are 
> needed because the ParamIdx constructor now asserts that Idx is one-origin, 
> but that requires validating that it's actually one-origin beforehand.  
> Sorry, I should've mentioned the new asserts.

Ah, okay, thank you!




Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

jdenny wrote:
> aaron.ballman wrote:
> > Can you move this below the RUN line?
> Sure.  I'm still trying to learn the LLVM coding standards.  Is this 
> specified there?
Nope! I'm just used to looking at the very first line of the test to know what 
it's running, and that seems consistent with other tests.


https://reviews.llvm.org/D43248



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


[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-12 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

I uploaded a new patch that moves the draft store to ClangdLSPServer, that 
implements what you suggested.

https://reviews.llvm.org/D44408

I will update the incremental sync patch once that patch is in.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272



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


[PATCH] D44408: Move DraftMgr from ClangdServer to ClangdLSPServer

2018-03-12 Thread Simon Marchi via Phabricator via cfe-commits
simark created this revision.
Herald added subscribers: cfe-commits, ioeric, jkorous-apple, ilya-biryukov, 
mgorny, klimek.

This patch moves the draft manager closer to the edge of Clangd, from
ClangdServer to ClangdLSPServer.  This will make it easier to implement
incremental document sync, by making ClangdServer only deal with
complete documents.

As a result, DraftStore doesn't have to deal with versioning, and thus
its API can be simplified.  It is replaced by a StringMap in
ClangdServer holding a current version number for each file.

The current implementation of reparseOpenedFiles is racy.  It calls
getActiveDrafts and calls forceReparse for each of them.  forceReparse
gets the draft fromt he DraftStore.  In theory, it's possible for a file
to have been closed in the mean time.  I replaced getActiveDrafts by
forEachActiveDraft.  It has the advantage that the DraftStore lock is
held while we iterate on the drafts.

Signed-off-by: Simon Marchi 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44408

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/DraftStoreTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -22,11 +22,13 @@
 void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents);
 
 Tagged runCodeComplete(ClangdServer &Server, PathRef File,
-   Position Pos,
+   StringRef Contents, Position Pos,
clangd::CodeCompleteOptions Opts);
 
-llvm::Expected>
-runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos);
+llvm::Expected> runSignatureHelp(ClangdServer &Server,
+   PathRef File,
+   StringRef Contents,
+   Position Pos);
 
 llvm::Expected>>
 runFindDefinitions(ClangdServer &Server, PathRef File, Position Pos);
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -68,17 +68,19 @@
 } // namespace
 
 Tagged runCodeComplete(ClangdServer &Server, PathRef File,
-   Position Pos,
+   StringRef Contents, Position Pos,
clangd::CodeCompleteOptions Opts) {
   llvm::Optional> Result;
-  Server.codeComplete(File, Pos, Opts, capture(Result));
+  Server.codeComplete(File, Contents, Pos, Opts, capture(Result));
   return std::move(*Result);
 }
 
-llvm::Expected>
-runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos) {
+llvm::Expected> runSignatureHelp(ClangdServer &Server,
+   PathRef File,
+   StringRef Contents,
+   Position Pos) {
   llvm::Optional>> Result;
-  Server.signatureHelp(File, Pos, capture(Result));
+  Server.signatureHelp(File, Contents, Pos, capture(Result));
   return std::move(*Result);
 }
 
Index: unittests/clangd/DraftStoreTests.cpp
===
--- /dev/null
+++ unittests/clangd/DraftStoreTests.cpp
@@ -0,0 +1,56 @@
+//===-- DraftStoreTests.cpp - Clangd unit tests -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DraftStore.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using namespace llvm;
+
+using ::testing::UnorderedElementsAre;
+
+/// Get the active drafts from \p DS as a vector.
+static std::vector getActiveDrafts(const DraftStore &DS) {
+  std::vector ActiveDrafts;
+
+  DS.forEachActiveDraft([&ActiveDrafts](PathRef File, StringRef Contents) {
+ActiveDrafts.push_back(File);
+  });
+
+  return ActiveDrafts;
+}
+
+TEST(DraftStoreTest, forEachActiveDraft) {
+  DraftStore DS;
+
+  DS.updateDraft("/foo.cpp", "Foo");
+  DS.updateDraft("/bar.cpp", "Bar");
+  DS.updateDraft("/baz.cpp", "Baz");
+
+  std::vector Drafts = getActiveDrafts(DS);
+  EXPECT_THAT(Drafts, UnorderedElementsAre("/foo.cpp", "/bar.cpp", "/baz.cpp"));
+
+  DS.removeDraft("/bar.cpp");
+
+  Drafts = getActiveDrafts(DS);
+  EXPECT_T

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

aaron.ballman wrote:
> Can you move this below the RUN line?
Sure.  I'm still trying to learn the LLVM coding standards.  Is this specified 
there?


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1035466, @aaron.ballman wrote:

> It seems like there are some other changes than just the serialize and 
> deserialize that I'm not opposed to, but am wondering why they're needed. It 
> seems some functions are now `getFoo()` calls


These were originally named getFoo, and my previous patch changed them to foo.  
I believe I did that to make ParamIdxArgument accessors more like 
VariadicParamIdxArgument accessors (which inherits accessors from 
VariadicArgument), but I probably shouldn't have done that.  In any case, this 
new revision implements ParamIdxArgument using SimpleArgument, and that names 
accessors like getFoo.

> and it seems like some declarations moved around. Are those intended as part 
> of this patch?

Are you referring to the changes in SemaDeclAttr.cpp?  Those changes are needed 
because the ParamIdx constructor now asserts that Idx is one-origin, but that 
requires validating that it's actually one-origin beforehand.  Sorry, I 
should've mentioned the new asserts.


https://reviews.llvm.org/D43248



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


r327354 - Add missing "env" so that test added in r327322 passes on Windows bots.

2018-03-12 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Mon Mar 12 17:41:44 2018
New Revision: 327354

URL: http://llvm.org/viewvc/llvm-project?rev=327354&view=rev
Log:
Add missing "env" so that test added in r327322 passes on Windows bots.

Modified:
cfe/trunk/test/Index/reparsed-live-issue.cpp

Modified: cfe/trunk/test/Index/reparsed-live-issue.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/reparsed-live-issue.cpp?rev=327354&r1=327353&r2=327354&view=diff
==
--- cfe/trunk/test/Index/reparsed-live-issue.cpp (original)
+++ cfe/trunk/test/Index/reparsed-live-issue.cpp Mon Mar 12 17:41:44 2018
@@ -1,4 +1,4 @@
-// RUN: CINDEXTEST_EDITING=1 LIBCLANG_DISABLE_CRASH_RECOVERY=1 c-index-test 
-test-load-source-reparse 2 none 
-remap-file-0=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-0 
-remap-file-1=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-1 -- %s 2>&1 
| FileCheck %s
+// RUN: env CINDEXTEST_EDITING=1 LIBCLANG_DISABLE_CRASH_RECOVERY=1 
c-index-test -test-load-source-reparse 2 none 
-remap-file-0=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-0 
-remap-file-1=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-1 -- %s 2>&1 
| FileCheck %s
 #include "Inputs/reparse-issue.h"
 
 // CHECK: reparse-issue.h:4:1:{1:1-1:1}: error: C++ requires a type specifier 
for all declarations


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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

It seems like there are some other changes than just the serialize and 
deserialize that I'm not opposed to, but am wondering why they're needed. It 
seems some functions are now `getFoo()` calls and it seems like some 
declarations moved around. Are those intended as part of this patch?




Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

Can you move this below the RUN line?



Comment at: cfe/trunk/test/Sema/attr-print.cpp:1
+// This file is also used as input for %S/../Frontend/ast-attr.cpp.
+

Can you move this comment below the RUN line?


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 138113.
jdenny added a comment.

Well, that didn't work.  Here's another attempt at getting the paths right.


https://reviews.llvm.org/D43248

Files:
  cfe/trunk/include/clang/AST/Attr.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  cfe/trunk/test/CodeGenCXX/alloc-size.cpp
  cfe/trunk/test/Frontend/ast-attr.cpp
  cfe/trunk/test/Misc/ast-dump-attr.cpp
  cfe/trunk/test/Sema/attr-ownership.cpp
  cfe/trunk/test/Sema/attr-print.cpp
  cfe/trunk/test/Sema/error-type-safety.cpp
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -104,6 +104,7 @@
 .Case("Expr *", "Record.readExpr()")
 .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
 .Case("StringRef", "Record.readString()")
+.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
 .Default("Record.readInt()");
 }
 
@@ -122,6 +123,7 @@
 .Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
 .Case("IdentifierInfo *", "AddIdentifierRef(" + std::string(name) + ");\n")
 .Case("StringRef", "AddString(" + std::string(name) + ");\n")
+.Case("ParamIdx", "push_back(" + std::string(name) + ".serialize());\n")
 .Default("push_back(" + std::string(name) + ");\n");
 }
 
@@ -302,9 +304,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
+  if (type == "ParamIdx")
+return "!get" + getUpperName().str() + "().isValid()";
   return "false";
 }
 
@@ -319,6 +320,8 @@
<< "()->getName() : \"\") << \"";
   else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
+  else if (type == "ParamIdx")
+OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
   else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
@@ -341,6 +344,11 @@
<< getUpperName() << "\";\n";
   } else if (type == "int" || type == "unsigned") {
 OS << "OS << \" \" << SA->get" << getUpperName() << "();\n";
+  } else if (type == "ParamIdx") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "().isValid())\n  ";
+OS << "OS << \" \" << SA->get" << getUpperName()
+   << "().getSourceIndex();\n";
   } else {
 llvm_unreachable("Unknown SimpleArgument type!");
   }
@@ -618,6 +626,10 @@
 virtual void writeValueImpl(raw_ostream &OS) const {
   OS << "OS << Val;\n";
 }
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeDumpImpl(raw_ostream &OS) const {
+  OS << "  OS << \" \" << Val;\n";
+}
 
   public:
 VariadicArgument(const Record &Arg, StringRef Attr, std::string T)
@@ -744,7 +756,22 @@
 
 void writeDump(raw_ostream &OS) const override {
   OS << "for (const auto &Val : SA->" << RangeName << "())\n";
-  OS << "  OS << \" \" << Val;\n";
+  writeDumpImpl(OS);
+}
+  };
+
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDumpImpl(raw_ostream &OS) const override {
+  OS << "  OS << \" \" << Val.getSourceIndex();\n";
 }
   };
 
@@ -1247,6 +1274,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: cfe/trunk/test/Sema/error-type-safety.cpp
===
--- cfe/trunk/test/Sema/error-type-safety.cpp
+++ cfe/trunk/test/Sema/error-type-safety.cpp
@@ -3,21 +3,50 @@
 #define INT_TAG 42
 
 static const int test_in
-  __attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
+__attribute__((type_tag_for_datatype(test, int))

[PATCH] D44143: [clang-tidy] Create properly seeded random generator check

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/cert/CERTTidyModule.cpp:40
 // DCL
-CheckFactories.registerCheck(
-"cert-dcl21-cpp");
+CheckFactories.registerCheck("cert-dcl21-cpp");
 CheckFactories.registerCheck("cert-dcl50-cpp");

This change looks unrelated to the patch.



Comment at: clang-tidy/cert/CERTTidyModule.cpp:44
 "cert-dcl54-cpp");
-CheckFactories.registerCheck(
-"cert-dcl58-cpp");
+
CheckFactories.registerCheck("cert-dcl58-cpp");
 CheckFactories.registerCheck(

This change looks unrelated to the patch.



Comment at: clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp:35-37
+  hasAnyName("linear_congruential_engine", "mersenne_twister_engine",
+ "subtract_with_carry_engine", "discard_block_engine",
+ "independent_bits_engine", "shuffle_order_engine"));

These should be full-qualified names.



Comment at: clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp:74
+  callExpr(has(implicitCastExpr(has(
+   declRefExpr(hasDeclaration(namedDecl(hasName("srand"
+  .bind("srand"),

I think that in C mode, this is fine, but in C++ mode it should register 
`::std::srand`.



Comment at: clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp:114
+  Func->getArg(0)->IgnoreCasts()->getType().getAsString());
+  if (std::find(DisallowedSeedTypes.begin(), DisallowedSeedTypes.end(),
+SeedType) != DisallowedSeedTypes.end()) {

You can use `llvm::find()` instead.



Comment at: docs/clang-tidy/checks/cert-msc51-cpp.rst:7
+This check flags all pseudo-random number engines, engine adaptor
+instantiations and srand when initialized or seeded with default argument,
+constant expression or any user-configurable type. Pseudo-random number

Backticks around `srand`



Comment at: docs/clang-tidy/checks/cert-msc51-cpp.rst:11
+security protocols.
+This is a CERT security rule, see MSC51-CPP.
+

Should link to the CERT rule, and also link to the C CERT rule.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44143



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 138111.
jdenny added a comment.

OK, this diff has the svn paths, and I've rebased to a more recent master.


https://reviews.llvm.org/D43248

Files:
  trunk/include/clang/AST/Attr.h
  trunk/include/clang/Basic/Attr.td
  trunk/lib/AST/ExprConstant.cpp
  trunk/lib/CodeGen/CGCall.cpp
  trunk/lib/Sema/SemaChecking.cpp
  trunk/lib/Sema/SemaDecl.cpp
  trunk/lib/Sema/SemaDeclAttr.cpp
  trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  trunk/test/CodeGenCXX/alloc-size.cpp
  trunk/test/Frontend/ast-attr.cpp
  trunk/test/Misc/ast-dump-attr.cpp
  trunk/test/Sema/attr-ownership.cpp
  trunk/test/Sema/attr-print.cpp
  trunk/test/Sema/error-type-safety.cpp
  trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -104,6 +104,7 @@
 .Case("Expr *", "Record.readExpr()")
 .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
 .Case("StringRef", "Record.readString()")
+.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
 .Default("Record.readInt()");
 }
 
@@ -122,6 +123,7 @@
 .Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
 .Case("IdentifierInfo *", "AddIdentifierRef(" + std::string(name) + ");\n")
 .Case("StringRef", "AddString(" + std::string(name) + ");\n")
+.Case("ParamIdx", "push_back(" + std::string(name) + ".serialize());\n")
 .Default("push_back(" + std::string(name) + ");\n");
 }
 
@@ -302,9 +304,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
+  if (type == "ParamIdx")
+return "!get" + getUpperName().str() + "().isValid()";
   return "false";
 }
 
@@ -319,6 +320,8 @@
<< "()->getName() : \"\") << \"";
   else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
+  else if (type == "ParamIdx")
+OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
   else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
@@ -341,6 +344,11 @@
<< getUpperName() << "\";\n";
   } else if (type == "int" || type == "unsigned") {
 OS << "OS << \" \" << SA->get" << getUpperName() << "();\n";
+  } else if (type == "ParamIdx") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "().isValid())\n  ";
+OS << "OS << \" \" << SA->get" << getUpperName()
+   << "().getSourceIndex();\n";
   } else {
 llvm_unreachable("Unknown SimpleArgument type!");
   }
@@ -618,6 +626,10 @@
 virtual void writeValueImpl(raw_ostream &OS) const {
   OS << "OS << Val;\n";
 }
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeDumpImpl(raw_ostream &OS) const {
+  OS << "  OS << \" \" << Val;\n";
+}
 
   public:
 VariadicArgument(const Record &Arg, StringRef Attr, std::string T)
@@ -744,7 +756,22 @@
 
 void writeDump(raw_ostream &OS) const override {
   OS << "for (const auto &Val : SA->" << RangeName << "())\n";
-  OS << "  OS << \" \" << Val;\n";
+  writeDumpImpl(OS);
+}
+  };
+
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDumpImpl(raw_ostream &OS) const override {
+  OS << "  OS << \" \" << Val.getSourceIndex();\n";
 }
   };
 
@@ -1247,6 +1274,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: trunk/test/Sema/error-type-safety.cpp
===
--- trunk/test/Sema/error-type-safety.cpp
+++ trunk/test/Sema/error-type-safety.cpp
@@ -3,21 +3,50 @@
 #define INT_TAG 42
 
 static const int test_in
-  __attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
+__attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
 
 // Argument index: 1, Type tag index: 2
 void test_bounds_index(...)
-  __att

[PATCH] D44327: ObjCARC: teach the cloner about funclets

2018-03-12 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r327336.  Addressed comments in SVN r327351, because I forgot to 
incorporate them in the first try.


Repository:
  rL LLVM

https://reviews.llvm.org/D44327



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


[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue/xvalue call expression.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327352: [CFG] [analyzer] Don't add construction context 
to a return-by-reference call. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44273

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp
  test/Analysis/temporaries.cpp

Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -183,14 +183,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext &ACtx) {
+return CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+ const TemporaryObjectConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
-assert(isCXXRecordTypedCall(CE));
+// FIXME: This is not protected against squeezing a non-record-typed-call
+// into the constructor. An assertion would require passing an ASTContext
+// which would mean paying for something we don't use.
 assert(C);
 Data2.setPointer(const_cast(C));
   }
Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C &foo1();
+C &&foo2();
 
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C &bar1() { return foo1(); } // no-crash
+C &&bar2() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -205,6 +205,21 @@
   return 0;
 }
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C &foo1();
+C &&foo2();
+
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C &bar1() { return foo1(); } // no-crash
+C &&bar2() { return foo2(); } // no-crash
+} // end namespace pass_references_through
+
 // CHECK:   [B1 (ENTRY)]
 // CHECK: Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -1402,3 +1417,29 @@
 // CHECK: Succs (2): B8 B1
 // CHECK:   [B0 (EXIT)]
 // CHECK: Preds (3): B1 B2 B4
+// CHECK:   [B1 (ENTRY)]
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B1]
+// CHECK: 1: foo1
+// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, const class pass_references_through::C &(*)(void))
+// CHECK: 3: [B1.2]()
+// CHECK: 4: return [B1.3];
+// CHECK: Preds (1): B2
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B1]
+// CHECK: 1: foo2
+// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class pass_references_through::C &&(*)(void))
+// CHECK: 3: [B1.2]()
+// CHECK: 4: return [B1.3];
+// CHECK: Preds (1): B2
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -751,7 +751,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1265,7 +1265,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
___
cfe-commits mailing l

r327352 - [CFG] [analyzer] Don't add construction context to a return-by-reference call.

2018-03-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Mar 12 16:52:36 2018
New Revision: 327352

URL: http://llvm.org/viewvc/llvm-project?rev=327352&view=rev
Log:
[CFG] [analyzer] Don't add construction context to a return-by-reference call.

Call expressions that return objects by an lvalue reference or an rvalue
reference have a value type in the AST but wear an auxiliary flag of being an
lvalue or an xvalue respectively.

Use the helper method for obtaining the actual return type of the function.

Fixes a crash.

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

Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=327352&r1=327351&r2=327352&view=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Mon Mar 12 16:52:36 2018
@@ -183,14 +183,16 @@ class CFGCXXRecordTypedCall : public CFG
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext &ACtx) {
+return 
CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+ const TemporaryObjectConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
-assert(isCXXRecordTypedCall(CE));
+// FIXME: This is not protected against squeezing a non-record-typed-call
+// into the constructor. An assertion would require passing an ASTContext
+// which would mean paying for something we don't use.
 assert(C);
 Data2.setPointer(const_cast(C));
   }

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=327352&r1=327351&r2=327352&view=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Mar 12 16:52:36 2018
@@ -751,7 +751,7 @@ private:
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1265,7 +1265,7 @@ void CFGBuilder::findConstructionContext
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }

Modified: cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp?rev=327352&r1=327351&r2=327352&view=diff
==
--- cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp Mon Mar 12 16:52:36 
2018
@@ -205,6 +205,21 @@ int testConsistencyNestedNormalReturn(bo
   return 0;
 }
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C &foo1();
+C &&foo2();
+
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C &bar1() { return foo1(); } // no-crash
+C &&bar2() { return foo2(); } // no-crash
+} // end namespace pass_references_through
+
 // CHECK:   [B1 (ENTRY)]
 // CHECK: Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -1402,3 +1417,29 @@ int testConsistencyNestedNormalReturn(bo
 // CHECK: Succs (2): B8 B1
 // CHECK:   [B0 (EXIT)]
 // CHECK: Preds (3): B1 B2 B4
+// CHECK:   [B1 (ENTRY)]
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B1]
+// CHECK: 1: foo1
+// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, const class 
pass_references_through::C &(*)(void))
+// CHECK: 3: [B1.2]()
+// CHECK: 4: return [B1.3];
+// CHECK: Preds (1): B2
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Can you regenerate the patch using the same paths as 
https://reviews.llvm.org/D43248?id=136811? When I try to do a diff between what 
was accepted & committed and the current patch, Phabricator gets confused 
because the paths are too different from one another.


https://reviews.llvm.org/D43248



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


[PATCH] D44131: [analyzer] Support temporaries conjured by conservatively evaluated functions.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327348: [analyzer] Support temporaries conjured by 
conservatively evaluated functions. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44131

Files:
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/explain-svals.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/explain-svals.cpp
===
--- test/Analysis/explain-svals.cpp
+++ test/Analysis/explain-svals.cpp
@@ -94,5 +94,5 @@
 
 void test_6() {
   clang_analyzer_explain(conjure_S()); // expected-warning-re^lazily frozen compound value of temporary object constructed at statement 'conjure_S\(\)'$
-  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value derived from \(symbol of type 'struct S' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$
+  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$
 }
Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -895,6 +895,45 @@
 }
 } // namespace test_match_constructors_and_destructors
 
+namespace destructors_for_return_values {
+
+class C {
+public:
+  ~C() {
+1 / 0; // expected-warning{{Division by zero}}
+  }
+};
+
+C make();
+
+void testFloatingCall() {
+  make();
+  // Should have divided by zero in the destructor.
+  clang_analyzer_warnIfReached();
+#ifndef TEMPORARY_DTORS
+// expected-warning@-2{{REACHABLE}}
+#endif
+}
+
+void testLifetimeExtendedCall() {
+  {
+const C &c = make();
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+  // Should have divided by zero in the destructor.
+  clang_analyzer_warnIfReached(); // no-warning
+}
+
+void testCopiedCall() {
+  C c = make();
+  // Should have divided by zero in the temporary destructor.
+  clang_analyzer_warnIfReached();
+#ifndef TEMPORARY_DTORS
+// expected-warning@-2{{REACHABLE}}
+#endif
+}
+} // namespace destructors_for_return_values
+
 namespace dont_forget_destructor_around_logical_op {
 int glob;
 
@@ -922,8 +961,17 @@
   // return value of get() was initialized. However, we didn't track
   // temporaries returned from functions, so we took the wrong branch.
   coin && is(get()); // no-crash
-  // FIXME: Should be true once we inline all destructors.
-  clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}}
+  if (coin) {
+clang_analyzer_eval(glob);
+#ifdef TEMPORARY_DTORS
+// expected-warning@-2{{TRUE}}
+#else
+// expected-warning@-4{{UNKNOWN}}
+#endif
+  } else {
+// The destructor is not called on this branch.
+clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}}
+  }
 }
 } // namespace dont_forget_destructor_around_logical_op
 
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -581,23 +581,39 @@
 return State->BindExpr(E, LCtx, ThisV);
   }
 
-  // Conjure a symbol if the return value is unknown.
+  SVal R;
   QualType ResultTy = Call.getResultType();
-  SValBuilder &SVB = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
+  if (auto RTC = getCurrentCFGElement().getAs()) {
+// Conjure a temporary if the function returns an object by value.
+MemRegionManager &MRMgr = svalBuilder.getRegionManager();
+const CXXTempObjectRegion *TR = MRMgr.getCXXTempObjectRegion(E, LCtx);
+State = addAllNecessaryTemporaryInfo(State, RTC->getConstructionContext(),
+ LCtx, TR);
+
+// Invalidate the region so that it didn't look uninitialized. Don't notify
+// the checkers.
+State = State->invalidateRegions(TR, E, Count, LCtx,
+ /* CausedByPointerEscape=*/false, nullptr,
+ &Call, nullptr);
 
-  // See if we need to conjure a heap pointer instead of
-  // a regular unknown pointer.
-  bool IsHeapPointer = false;
-  if (const auto *CNE = dyn_cast(E))
-if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
-  // FIXME: Delegate this to evalCall in MallocChecker?
-  IsHeapPointer = true;
-}
+R = State->getSVal(TR, E->getType());
+  } else {
+// Conjure a symbol if the return value is unknown.
 
-  SVal R = IsHeapPointer
-   ? SVB.getConjuredHeapSymbolVal(E, LCtx, Count)
-   : SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+// See if we need to conjure a heap pointer instead of
+

r327348 - [analyzer] Support temporaries conjured by conservatively evaluated functions.

2018-03-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Mar 12 16:36:12 2018
New Revision: 327348

URL: http://llvm.org/viewvc/llvm-project?rev=327348&view=rev
Log:
[analyzer] Support temporaries conjured by conservatively evaluated functions.

Properly perform destruction and lifetime extension of such temporaries.

C++ object-type return values of conservatively evaluated functions are now
represented as compound values of well-defined temporary object regions. The
function creates a region that represents the temporary object and will later
be used for destruction or materialization, invalidates it, and returns the
invalidated compound value of the object.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/explain-svals.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=327348&r1=327347&r2=327348&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Mon Mar 12 
16:36:12 2018
@@ -581,23 +581,39 @@ ProgramStateRef ExprEngine::bindReturnVa
 return State->BindExpr(E, LCtx, ThisV);
   }
 
-  // Conjure a symbol if the return value is unknown.
+  SVal R;
   QualType ResultTy = Call.getResultType();
-  SValBuilder &SVB = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
+  if (auto RTC = getCurrentCFGElement().getAs()) {
+// Conjure a temporary if the function returns an object by value.
+MemRegionManager &MRMgr = svalBuilder.getRegionManager();
+const CXXTempObjectRegion *TR = MRMgr.getCXXTempObjectRegion(E, LCtx);
+State = addAllNecessaryTemporaryInfo(State, RTC->getConstructionContext(),
+ LCtx, TR);
 
-  // See if we need to conjure a heap pointer instead of
-  // a regular unknown pointer.
-  bool IsHeapPointer = false;
-  if (const auto *CNE = dyn_cast(E))
-if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
-  // FIXME: Delegate this to evalCall in MallocChecker?
-  IsHeapPointer = true;
-}
-
-  SVal R = IsHeapPointer
-   ? SVB.getConjuredHeapSymbolVal(E, LCtx, Count)
-   : SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+// Invalidate the region so that it didn't look uninitialized. Don't notify
+// the checkers.
+State = State->invalidateRegions(TR, E, Count, LCtx,
+ /* CausedByPointerEscape=*/false, nullptr,
+ &Call, nullptr);
+
+R = State->getSVal(TR, E->getType());
+  } else {
+// Conjure a symbol if the return value is unknown.
+
+// See if we need to conjure a heap pointer instead of
+// a regular unknown pointer.
+bool IsHeapPointer = false;
+if (const auto *CNE = dyn_cast(E))
+  if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
+// FIXME: Delegate this to evalCall in MallocChecker?
+IsHeapPointer = true;
+  }
+
+R = IsHeapPointer ? svalBuilder.getConjuredHeapSymbolVal(E, LCtx, Count)
+  : svalBuilder.conjureSymbolVal(nullptr, E, LCtx, 
ResultTy,
+ Count);
+  }
   return State->BindExpr(E, LCtx, R);
 }
 

Modified: cfe/trunk/test/Analysis/explain-svals.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/explain-svals.cpp?rev=327348&r1=327347&r2=327348&view=diff
==
--- cfe/trunk/test/Analysis/explain-svals.cpp (original)
+++ cfe/trunk/test/Analysis/explain-svals.cpp Mon Mar 12 16:36:12 2018
@@ -94,5 +94,5 @@ public:
 
 void test_6() {
   clang_analyzer_explain(conjure_S()); // expected-warning-re^lazily 
frozen compound value of temporary object constructed at statement 
'conjure_S\(\)'$
-  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value 
derived from \(symbol of type 'struct S' conjured at statement 
'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 
'conjure_S\(\)'$
+  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value 
derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for 
field 'z' of temporary object constructed at statement 'conjure_S\(\)'$
 }

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=327348&r1=327347&r2=327348&view=diff
==
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Mon M

[PATCH] D44129: [analyzer] NFC: Refactor the code for obtaining temporary lifetime info into a method.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327347: [analyzer] NFC: Move the code for setting temp 
object lifetime into method. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44129

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

Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -774,6 +774,14 @@
 const LocationContext *FromLC,
 const LocationContext *ToLC);
 
+  /// Adds an initialized temporary and/or a materialization, whichever is
+  /// necessary, by looking at the whole construction context. Handles
+  /// function return values, which need the construction context of the parent
+  /// stack frame, automagically.
+  ProgramStateRef addAllNecessaryTemporaryInfo(
+  ProgramStateRef State, const ConstructionContext *CC,
+  const LocationContext *LC, const MemRegion *R);
+
   /// Store the region returned by operator new() so that the constructor
   /// that follows it knew what location to initialize. The value should be
   /// cleared once the respective CXXNewExpr CFGStmt element is processed.
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -31,6 +31,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Analysis/ConstructionContext.h"
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
@@ -449,6 +450,65 @@
   return true;
 }
 
+ProgramStateRef ExprEngine::addAllNecessaryTemporaryInfo(
+ProgramStateRef State, const ConstructionContext *CC,
+const LocationContext *LC, const MemRegion *R) {
+  const CXXBindTemporaryExpr *BTE = nullptr;
+  const MaterializeTemporaryExpr *MTE = nullptr;
+  const LocationContext *TempLC = LC;
+
+  if (CC) {
+// In case of temporary object construction, extract data necessary for
+// destruction and lifetime extension.
+const auto *TCC = dyn_cast(CC);
+
+// If the temporary is being returned from the function, it will be
+// destroyed or lifetime-extended in the caller stack frame.
+if (const auto *RCC = dyn_cast(CC)) {
+  const StackFrameContext *SFC = LC->getCurrentStackFrame();
+  assert(SFC);
+  if (SFC->getParent()) {
+TempLC = SFC->getParent();
+const CFGElement &CallElem =
+(*SFC->getCallSiteBlock())[SFC->getIndex()];
+if (auto RTCElem = CallElem.getAs()) {
+  TCC = cast(
+  RTCElem->getConstructionContext());
+}
+  }
+}
+if (TCC) {
+  if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
+BTE = TCC->getCXXBindTemporaryExpr();
+MTE = TCC->getMaterializedTemporaryExpr();
+if (!BTE) {
+  // FIXME: Lifetime extension for temporaries without destructors
+  // is not implemented yet.
+  MTE = nullptr;
+}
+if (MTE && MTE->getStorageDuration() != SD_FullExpression) {
+  // If the temporary is lifetime-extended, don't save the BTE,
+  // because we don't need a temporary destructor, but an automatic
+  // destructor.
+  BTE = nullptr;
+}
+  }
+}
+
+if (BTE) {
+  State = addInitializedTemporary(State, BTE, TempLC,
+  cast(R));
+}
+
+if (MTE) {
+  State = addTemporaryMaterialization(State, MTE, TempLC,
+  cast(R));
+}
+  }
+
+  return State;
+}
+
 ProgramStateRef
 ExprEngine::setCXXNewAllocatorValue(ProgramStateRef State,
 const CXXNewExpr *CNE,
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -265,55 +265,9 @@
   assert(C || getCurrentCFGElement().getAs());
   const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr;
 
-  bool IsReturnedIntoParentStackFrame = false;
-  const CXXBindTemporaryExpr *BTE = nullptr;
-  const MaterializeTemporaryExpr *MTE = nullptr;
-
   switch (CE->getConstructionKind()) {
   case CXXConstructExpr::CK_Complete: {
 Target = getRegionForConstructedObject(CE, Pred, CC, CallOpts);
-
-if (CC) {
-  // In c

r327347 - [analyzer] NFC: Move the code for setting temp object lifetime into method.

2018-03-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Mar 12 16:27:52 2018
New Revision: 327347

URL: http://llvm.org/viewvc/llvm-project?rev=327347&view=rev
Log:
[analyzer] NFC: Move the code for setting temp object lifetime into method.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=327347&r1=327346&r2=327347&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Mon 
Mar 12 16:27:52 2018
@@ -774,6 +774,14 @@ private:
 const LocationContext *FromLC,
 const LocationContext *ToLC);
 
+  /// Adds an initialized temporary and/or a materialization, whichever is
+  /// necessary, by looking at the whole construction context. Handles
+  /// function return values, which need the construction context of the parent
+  /// stack frame, automagically.
+  ProgramStateRef addAllNecessaryTemporaryInfo(
+  ProgramStateRef State, const ConstructionContext *CC,
+  const LocationContext *LC, const MemRegion *R);
+
   /// Store the region returned by operator new() so that the constructor
   /// that follows it knew what location to initialize. The value should be
   /// cleared once the respective CXXNewExpr CFGStmt element is processed.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=327347&r1=327346&r2=327347&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Mar 12 16:27:52 2018
@@ -31,6 +31,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Analysis/ConstructionContext.h"
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
@@ -449,6 +450,65 @@ bool ExprEngine::areTemporaryMaterializa
   return true;
 }
 
+ProgramStateRef ExprEngine::addAllNecessaryTemporaryInfo(
+ProgramStateRef State, const ConstructionContext *CC,
+const LocationContext *LC, const MemRegion *R) {
+  const CXXBindTemporaryExpr *BTE = nullptr;
+  const MaterializeTemporaryExpr *MTE = nullptr;
+  const LocationContext *TempLC = LC;
+
+  if (CC) {
+// In case of temporary object construction, extract data necessary for
+// destruction and lifetime extension.
+const auto *TCC = dyn_cast(CC);
+
+// If the temporary is being returned from the function, it will be
+// destroyed or lifetime-extended in the caller stack frame.
+if (const auto *RCC = dyn_cast(CC)) {
+  const StackFrameContext *SFC = LC->getCurrentStackFrame();
+  assert(SFC);
+  if (SFC->getParent()) {
+TempLC = SFC->getParent();
+const CFGElement &CallElem =
+(*SFC->getCallSiteBlock())[SFC->getIndex()];
+if (auto RTCElem = CallElem.getAs()) {
+  TCC = cast(
+  RTCElem->getConstructionContext());
+}
+  }
+}
+if (TCC) {
+  if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
+BTE = TCC->getCXXBindTemporaryExpr();
+MTE = TCC->getMaterializedTemporaryExpr();
+if (!BTE) {
+  // FIXME: Lifetime extension for temporaries without destructors
+  // is not implemented yet.
+  MTE = nullptr;
+}
+if (MTE && MTE->getStorageDuration() != SD_FullExpression) {
+  // If the temporary is lifetime-extended, don't save the BTE,
+  // because we don't need a temporary destructor, but an automatic
+  // destructor.
+  BTE = nullptr;
+}
+  }
+}
+
+if (BTE) {
+  State = addInitializedTemporary(State, BTE, TempLC,
+  cast(R));
+}
+
+if (MTE) {
+  State = addTemporaryMaterialization(State, MTE, TempLC,
+  cast(R));
+}
+  }
+
+  return State;
+}
+
 ProgramStateRef
 ExprEngine::setCXXNewAllocatorValue(ProgramStateRef State,
 const CXXNewExpr *CNE,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=327347&r1=327346&r2=327347&view=diff
==

[clang-tools-extra] r327346 - Revert "Reland "[clang-doc] Setup clang-doc frontend framework""

2018-03-12 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Mar 12 16:23:24 2018
New Revision: 327346

URL: http://llvm.org/viewvc/llvm-project?rev=327346&view=rev
Log:
Revert "Reland "[clang-doc] Setup clang-doc frontend framework""

This reverts commit r327295 since it was causing the Windows bots to
fail.

Removed:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=327346&r1=327345&r2=327346&view=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Mon Mar 12 16:23:24 2018
@@ -7,7 +7,6 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
-add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Removed: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=327345&view=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (removed)
@@ -1,515 +0,0 @@
-//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "BitcodeWriter.h"
-#include "llvm/ADT/IndexedMap.h"
-
-namespace clang {
-namespace doc {
-
-// Since id enums are not zero-indexed, we need to transform the given id into
-// its associated index.
-struct BlockIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
-};
-
-struct RecordIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
-};
-
-using AbbrevDsc = void (*)(std::shared_ptr &Abbrev);
-
-static void AbbrevGen(std::shared_ptr &Abbrev,
-  const std::initializer_list Ops) {
-  for (const auto &Op : Ops)
-Abbrev->Add(Op);
-}
-
-static void BoolAbbrev(std::shared_ptr &Abbrev) {
-  AbbrevGen(Abbrev,
-{// 0. Boolean
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::BoolSize)});
-}
-
-static void IntAbbrev(std::shared_ptr &Abbrev) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::IntSize)});
-}
-
-static void SymbolIDAbbrev(std::shared_ptr &Abbrev) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the sha1'd USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRLengthSize),
- // 1. Fixed-size array of Char6 (USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRBitLengthSize)});
-}
-
-static void StringAbbrev(std::shared_ptr &Abbrev) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the following string)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConst

[PATCH] D44124: [analyzer] Support destruction and lifetime-extension of inlined function return values.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327345: [analyzer] Destroy and lifetime-extend inlined 
function return values properly. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44124

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/lifetime-extension.cpp

Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -197,16 +197,19 @@
   return MRMgr.getCXXTempObjectRegion(CE, LCtx);
 }
 case ConstructionContext::ReturnedValueKind: {
-  // TODO: We should construct into a CXXBindTemporaryExpr or a
-  // MaterializeTemporaryExpr around the call-expression on the previous
-  // stack frame. Currently we re-bind the temporary to the correct region
-  // later, but that's not semantically correct. This of course does not
-  // apply when we're in the top frame. But if we are in an inlined
-  // function, we should be able to take the call-site CFG element,
-  // and it should contain (but right now it wouldn't) some sort of
-  // construction context that'd give us the right temporary expression.
+  // The temporary is to be managed by the parent stack frame.
+  // So build it in the parent stack frame if we're not in the
+  // top frame of the analysis.
+  // TODO: What exactly happens when we are? Does the temporary object live
+  // long enough in the region store in this case? Would checkers think
+  // that this object immediately goes out of scope?
+  const LocationContext *TempLCtx = LCtx;
+  if (const LocationContext *CallerLCtx =
+  LCtx->getCurrentStackFrame()->getParent()) {
+TempLCtx = CallerLCtx;
+  }
   CallOpts.IsTemporaryCtorOrDtor = true;
-  return MRMgr.getCXXTempObjectRegion(CE, LCtx);
+  return MRMgr.getCXXTempObjectRegion(CE, TempLCtx);
 }
 }
   }
@@ -262,32 +265,52 @@
   assert(C || getCurrentCFGElement().getAs());
   const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr;
 
+  bool IsReturnedIntoParentStackFrame = false;
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
 
   switch (CE->getConstructionKind()) {
   case CXXConstructExpr::CK_Complete: {
 Target = getRegionForConstructedObject(CE, Pred, CC, CallOpts);
 
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-if (const auto *TCC =
-dyn_cast_or_null(CC)) {
-  assert(CallOpts.IsTemporaryCtorOrDtor);
-  assert(!CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion);
-  if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
-BTE = TCC->getCXXBindTemporaryExpr();
-MTE = TCC->getMaterializedTemporaryExpr();
-if (!BTE) {
-  // FIXME: lifetime extension for temporaries without destructors
-  // is not implemented yet.
-  MTE = nullptr;
+if (CC) {
+  // In case of temporary object construction, extract data necessary for
+  // destruction and lifetime extension.
+  const auto *TCC = dyn_cast(CC);
+
+  // If the temporary is being returned from the function, it will be
+  // destroyed or lifetime-extended in the caller stack frame.
+  if (const auto *RCC = dyn_cast(CC)) {
+const StackFrameContext *SFC = LCtx->getCurrentStackFrame();
+assert(SFC);
+if (SFC->getParent()) {
+  IsReturnedIntoParentStackFrame = true;
+  const CFGElement &CallElem =
+  (*SFC->getCallSiteBlock())[SFC->getIndex()];
+  if (auto RTCElem = CallElem.getAs()) {
+TCC = cast(
+RTCElem->getConstructionContext());
+  }
 }
-if (MTE && MTE->getStorageDuration() != SD_FullExpression) {
-  // If the temporary is lifetime-extended, don't save the BTE,
-  // because we don't need a temporary destructor, but an automatic
-  // destructor.
-  BTE = nullptr;
+  }
+
+  if (TCC) {
+assert(CallOpts.IsTemporaryCtorOrDtor);
+assert(!CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion);
+if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
+  BTE = TCC->getCXXBindTemporaryExpr();
+  MTE = TCC->getMaterializedTemporaryExpr();
+  if (!BTE) {
+// FIXME: lifetime extension for temporaries without destructors
+// is not implemented yet.
+MTE = nullptr;
+  }
+  if (MTE && MTE->getStorageDuration() != SD_FullExpression) {
+// If the temporary is lifetime-extended, don't save the BTE,
+// because we don't need a temporary destructor, but an automatic
+// destructor.
+ 

[clang-tools-extra] r327344 - [clangd] Remove Tagged and some related APIs from ClangdServer.

2018-03-12 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Mar 12 16:22:35 2018
New Revision: 327344

URL: http://llvm.org/viewvc/llvm-project?rev=327344&view=rev
Log:
[clangd] Remove Tagged and some related APIs from ClangdServer.

Context can do what Tagged was intended to support (snapshot filesystems),
and less intrusively.
getTaggedFileSystem() no longer needs a filename.

Cleanups while here:
 - code-complete now returns errors as Expected, like other functions
 - added an alias Callback for the usual callback function type

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/Function.h
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
clang-tools-extra/trunk/unittests/clangd/TestFS.h
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=327344&r1=327343&r2=327344&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Mar 12 16:22:35 2018
@@ -330,28 +330,33 @@ void ClangdLSPServer::onCodeAction(CodeA
 
 void ClangdLSPServer::onCompletion(TextDocumentPositionParams &Params) {
   Server.codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
-  [](Tagged List) { reply(List.Value); });
+  [](llvm::Expected List) {
+if (!List)
+  return replyError(ErrorCode::InvalidParams,
+llvm::toString(List.takeError()));
+reply(*List);
+  });
 }
 
 void ClangdLSPServer::onSignatureHelp(TextDocumentPositionParams &Params) {
   Server.signatureHelp(Params.textDocument.uri.file(), Params.position,
-   [](llvm::Expected> SignatureHelp) 
{
+   [](llvm::Expected SignatureHelp) {
  if (!SignatureHelp)
return replyError(
ErrorCode::InvalidParams,
llvm::toString(SignatureHelp.takeError()));
- reply(SignatureHelp->Value);
+ reply(*SignatureHelp);
});
 }
 
 void ClangdLSPServer::onGoToDefinition(TextDocumentPositionParams &Params) {
   Server.findDefinitions(
   Params.textDocument.uri.file(), Params.position,
-  [](llvm::Expected>> Items) {
+  [](llvm::Expected> Items) {
 if (!Items)
   return replyError(ErrorCode::InvalidParams,
 llvm::toString(Items.takeError()));
-reply(json::ary(Items->Value));
+reply(json::ary(*Items));
   });
 }
 
@@ -363,24 +368,24 @@ void ClangdLSPServer::onSwitchSourceHead
 void ClangdLSPServer::onDocumentHighlight(TextDocumentPositionParams &Params) {
   Server.findDocumentHighlights(
   Params.textDocument.uri.file(), Params.position,
-  [](llvm::Expected>> Highlights) {
+  [](llvm::Expected> Highlights) {
 if (!Highlights)
   return replyError(ErrorCode::InternalError,
 llvm::toString(Highlights.takeError()));
-reply(json::ary(Highlights->Value));
+reply(json::ary(*Highlights));
   });
 }
 
 void ClangdLSPServer::onHover(TextDocumentPositionParams &Params) {
   Server.findHover(Params.textDocument.uri.file(), Params.position,
-   [](llvm::Expected> H) {
+   [](llvm::Expected H) {
  if (!H) {
replyError(ErrorCode::InternalError,
   llvm::toString(H.takeError()));
return;
  }
 
- reply(H->Value);
+ reply(*H);
});
 }
 
@@ -437,12 +442,12 @@ std::vector ClangdLSPServer::getFix
   return FixItsIter->second;
 }
 
-void ClangdLSPServer::onDiagnosticsReady(
-PathRef File, Tagged> Diagnostics) {
+void ClangdLSPServer::onDiagnosticsReady(PathRef File,
+ std::vector Diagnostics) {
   json::ary DiagnosticsJSON;
 
   DiagnosticToReplacementMap LocalFixIts; // Temporary storage
-  for (auto &Diag : Diagnostics.Value) {
+  for (auto &Diag : Diagnostics) {
 to

r327345 - [analyzer] Destroy and lifetime-extend inlined function return values properly.

2018-03-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Mar 12 16:22:35 2018
New Revision: 327345

URL: http://llvm.org/viewvc/llvm-project?rev=327345&view=rev
Log:
[analyzer] Destroy and lifetime-extend inlined function return values properly.

This patch uses the newly added CFGCXXRecordTypedCall element at the call site
of the caller to construct the return value within the callee directly into the
caller's stack frame. This way it is also capable of populating the temporary
destructor and lifetime extension maps for the temporary, which allows
temporary destructors and lifetime extension to work correctly.

This patch does not affect temporaries that were returned from conservatively
evaluated functions.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/test/Analysis/lifetime-extension.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=327345&r1=327344&r2=327345&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Mon Mar 12 16:22:35 2018
@@ -197,16 +197,19 @@ ExprEngine::getRegionForConstructedObjec
   return MRMgr.getCXXTempObjectRegion(CE, LCtx);
 }
 case ConstructionContext::ReturnedValueKind: {
-  // TODO: We should construct into a CXXBindTemporaryExpr or a
-  // MaterializeTemporaryExpr around the call-expression on the previous
-  // stack frame. Currently we re-bind the temporary to the correct region
-  // later, but that's not semantically correct. This of course does not
-  // apply when we're in the top frame. But if we are in an inlined
-  // function, we should be able to take the call-site CFG element,
-  // and it should contain (but right now it wouldn't) some sort of
-  // construction context that'd give us the right temporary expression.
+  // The temporary is to be managed by the parent stack frame.
+  // So build it in the parent stack frame if we're not in the
+  // top frame of the analysis.
+  // TODO: What exactly happens when we are? Does the temporary object live
+  // long enough in the region store in this case? Would checkers think
+  // that this object immediately goes out of scope?
+  const LocationContext *TempLCtx = LCtx;
+  if (const LocationContext *CallerLCtx =
+  LCtx->getCurrentStackFrame()->getParent()) {
+TempLCtx = CallerLCtx;
+  }
   CallOpts.IsTemporaryCtorOrDtor = true;
-  return MRMgr.getCXXTempObjectRegion(CE, LCtx);
+  return MRMgr.getCXXTempObjectRegion(CE, TempLCtx);
 }
 }
   }
@@ -262,6 +265,7 @@ void ExprEngine::VisitCXXConstructExpr(c
   assert(C || getCurrentCFGElement().getAs());
   const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr;
 
+  bool IsReturnedIntoParentStackFrame = false;
   const CXXBindTemporaryExpr *BTE = nullptr;
   const MaterializeTemporaryExpr *MTE = nullptr;
 
@@ -269,25 +273,44 @@ void ExprEngine::VisitCXXConstructExpr(c
   case CXXConstructExpr::CK_Complete: {
 Target = getRegionForConstructedObject(CE, Pred, CC, CallOpts);
 
-// In case of temporary object construction, extract data necessary for
-// destruction and lifetime extension.
-if (const auto *TCC =
-dyn_cast_or_null(CC)) {
-  assert(CallOpts.IsTemporaryCtorOrDtor);
-  assert(!CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion);
-  if (AMgr.getAnalyzerOptions().includeTemporaryDtorsInCFG()) {
-BTE = TCC->getCXXBindTemporaryExpr();
-MTE = TCC->getMaterializedTemporaryExpr();
-if (!BTE) {
-  // FIXME: lifetime extension for temporaries without destructors
-  // is not implemented yet.
-  MTE = nullptr;
+if (CC) {
+  // In case of temporary object construction, extract data necessary for
+  // destruction and lifetime extension.
+  const auto *TCC = dyn_cast(CC);
+
+  // If the temporary is being returned from the function, it will be
+  // destroyed or lifetime-extended in the caller stack frame.
+  if (const auto *RCC = dyn_cast(CC)) {
+const StackFrameContext *SFC = LCtx->getCurrentStackFrame();
+assert(SFC);
+if (SFC->getParent()) {
+  IsReturnedIntoParentStackFrame = true;
+  const CFGElement &CallElem =
+  (*SFC->getCallSiteBlock())[SFC->getIndex()];
+  if (auto RTCElem = CallElem.getAs()) {
+TCC = cast(
+RTCElem->getConstructionContext());
+  }
 }
-if (MTE && MTE->getStorageDuration() != SD_FullExpression) {
-  // If the temporary is lifetime-extended, don't save the BTE,
-  // because we don't need a temporary destructor, but an automatic
-  /

[PATCH] D44120: [CFG] [analyzer] Heavier CFGCXXRecordTypedCall elements.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327343: [CFG] [analyzer] Add construction context to C++ 
return-by-value call elements. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44120?vs=137116&id=138103#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44120

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -39,6 +39,7 @@
 class BinaryOperator;
 class CFG;
 class ConstructionContext;
+class TemporaryObjectConstructionContext;
 class CXXBaseSpecifier;
 class CXXBindTemporaryExpr;
 class CXXCtorInitializer;
@@ -65,8 +66,9 @@
 // stmt kind
 Statement,
 Constructor,
+CXXRecordTypedCall,
 STMT_BEGIN = Statement,
-STMT_END = Constructor,
+STMT_END = CXXRecordTypedCall,
 // dtor kind
 AutomaticObjectDtor,
 DeleteDtor,
@@ -158,10 +160,6 @@
 return static_cast(Data2.getPointer());
   }
 
-  QualType getType() const {
-return cast(getStmt())->getType();
-  }
-
 private:
   friend class CFGElement;
 
@@ -172,6 +170,46 @@
   }
 };
 
+/// CFGCXXRecordTypedCall - Represents a function call that returns a C++ object
+/// by value. This, like constructor, requires a construction context, which
+/// will always be that of a temporary object - usually consumed by an elidable
+/// constructor. For such value-typed calls the ReturnedValueConstructionContext
+/// of their return value is naturally complemented by the
+/// TemporaryObjectConstructionContext at the call site (here). In C such
+/// tracking is not necessary because no additional effort is required for
+/// destroying the object or modeling copy elision. Like CFGConstructor, this is
+/// for now only used by the analyzer's CFG.
+class CFGCXXRecordTypedCall : public CFGStmt {
+public:
+  /// Returns true when call expression \p CE needs to be represented
+  /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
+  static bool isCXXRecordTypedCall(CallExpr *CE) {
+return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  }
+
+  explicit CFGCXXRecordTypedCall(CallExpr *CE,
+ const TemporaryObjectConstructionContext *C)
+  : CFGStmt(CE, CXXRecordTypedCall) {
+assert(isCXXRecordTypedCall(CE));
+assert(C);
+Data2.setPointer(const_cast(C));
+  }
+
+  const TemporaryObjectConstructionContext *getConstructionContext() const {
+return static_cast(
+Data2.getPointer());
+  }
+
+private:
+  friend class CFGElement;
+
+  CFGCXXRecordTypedCall() = default;
+
+  static bool isKind(const CFGElement &E) {
+return E.getKind() == CXXRecordTypedCall;
+  }
+};
+
 /// CFGInitializer - Represents C++ base or member initializer from
 /// constructor's initialization list.
 class CFGInitializer : public CFGElement {
@@ -840,6 +878,12 @@
 Elements.push_back(CFGConstructor(CE, CC), C);
   }
 
+  void appendCXXRecordTypedCall(CallExpr *CE,
+const TemporaryObjectConstructionContext *CC,
+BumpVectorContext &C) {
+Elements.push_back(CFGCXXRecordTypedCall(CE, CC), C);
+  }
+
   void appendInitializer(CXXCtorInitializer *initializer,
 BumpVectorContext &C) {
 Elements.push_back(CFGInitializer(initializer), C);
Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -,7 +,8 @@
 // CHECK:   [B1]
 // CHECK: 1: A::make
 // CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class A (*)(void))
-// CHECK: 3: [B1.2]()
+// WARNINGS: 3: [B1.2]()
+// ANALYZER: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
 // CHECK: 4: [B1.3] (BindTemporary)
 // CHECK: 5: [B1.4] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 6: [B1.5]
@@ -1130,16 +1131,18 @@
 // CHECK:   [B1]
 // CHECK: 1: A::make
 // CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class A (*)(void))
-// CHECK: 3: [B1.2]()
+// WARNINGS: 3: [B1.2]()
+// ANALYZER: 3: [B1.2]() (CXXRecordTypedCall, [B1.4], [B1.6])
 // CHECK: 4: [B1.3] (BindTemporary)
 // CHECK: 5: [B1.4] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 6: [B1.5]
 // CHECK: 7: const A &a = A::make();
 // CHECK: 8: foo
 // CHECK: 9: [B1.8] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class A &))
 // CHECK:10: A::make
 // CHECK:11: [B1.10] (ImplicitCastExpr, FunctionToPointerDecay, class A (*)(void))
-// CHECK:12: [B1.11]()

r327343 - [CFG] [analyzer] Add construction context to C++ return-by-value call elements.

2018-03-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Mar 12 16:12:40 2018
New Revision: 327343

URL: http://llvm.org/viewvc/llvm-project?rev=327343&view=rev
Log:
[CFG] [analyzer] Add construction context to C++ return-by-value call elements.

This patch adds a new CFGStmt sub-class, CFGCXXRecordTypedCall, which replaces
the regular CFGStmt for the respective CallExpr whenever the CFG has additional
information to provide regarding the lifetime of the returned value.

This additional call site information is represented by a ConstructionContext
(which was previously used for CFGConstructor elements) that provides references
to CXXBindTemporaryExpr and MaterializeTemporaryExpr that surround the call.

This corresponds to the common C++ calling convention solution of providing
the target address for constructing the return value as an auxiliary implicit
argument during function call.

One of the use cases for such extra context at the call site would be to perform
any sort of inter-procedural analysis over the CFG that involves functions
returning objects by value. In this case the elidable constructor at the return
site would construct the object explained by the context at the call site, and
its lifetime would also be managed by the caller, not the callee.

The extra context would also be useful for properly handling the return-value
temporary at the call site, even if the callee is not being analyzed
inter-procedurally.

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

Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=327343&r1=327342&r2=327343&view=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Mon Mar 12 16:12:40 2018
@@ -39,6 +39,7 @@ class ASTContext;
 class BinaryOperator;
 class CFG;
 class ConstructionContext;
+class TemporaryObjectConstructionContext;
 class CXXBaseSpecifier;
 class CXXBindTemporaryExpr;
 class CXXCtorInitializer;
@@ -65,8 +66,9 @@ public:
 // stmt kind
 Statement,
 Constructor,
+CXXRecordTypedCall,
 STMT_BEGIN = Statement,
-STMT_END = Constructor,
+STMT_END = CXXRecordTypedCall,
 // dtor kind
 AutomaticObjectDtor,
 DeleteDtor,
@@ -158,10 +160,6 @@ public:
 return static_cast(Data2.getPointer());
   }
 
-  QualType getType() const {
-return cast(getStmt())->getType();
-  }
-
 private:
   friend class CFGElement;
 
@@ -172,6 +170,46 @@ private:
   }
 };
 
+/// CFGCXXRecordTypedCall - Represents a function call that returns a C++ 
object
+/// by value. This, like constructor, requires a construction context, which
+/// will always be that of a temporary object - usually consumed by an elidable
+/// constructor. For such value-typed calls the 
ReturnedValueConstructionContext
+/// of their return value is naturally complemented by the
+/// TemporaryObjectConstructionContext at the call site (here). In C such
+/// tracking is not necessary because no additional effort is required for
+/// destroying the object or modeling copy elision. Like CFGConstructor, this 
is
+/// for now only used by the analyzer's CFG.
+class CFGCXXRecordTypedCall : public CFGStmt {
+public:
+  /// Returns true when call expression \p CE needs to be represented
+  /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
+  static bool isCXXRecordTypedCall(CallExpr *CE) {
+return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  }
+
+  explicit CFGCXXRecordTypedCall(CallExpr *CE,
+ const TemporaryObjectConstructionContext *C)
+  : CFGStmt(CE, CXXRecordTypedCall) {
+assert(isCXXRecordTypedCall(CE));
+assert(C);
+Data2.setPointer(const_cast(C));
+  }
+
+  const TemporaryObjectConstructionContext *getConstructionContext() const {
+return static_cast(
+Data2.getPointer());
+  }
+
+private:
+  friend class CFGElement;
+
+  CFGCXXRecordTypedCall() = default;
+
+  static bool isKind(const CFGElement &E) {
+return E.getKind() == CXXRecordTypedCall;
+  }
+};
+
 /// CFGInitializer - Represents C++ base or member initializer from
 /// constructor's initialization list.
 class CFGInitializer : public CFGElement {
@@ -840,6 +878,12 @@ public:
 Elements.push_back(CFGConstructor(CE, CC), C);
   }
 
+  void appendCXXRecordTypedCall(CallExpr *CE,
+const TemporaryObjectConstructionContext *CC,
+BumpVectorContext &C) {
+Elements.push_back(CFGCXXRecordTypedCall(CE, CC), C);
+  }
+
   void appendInitializer(CXXCtorInitializer *initializ

RE: r327322 - [Tooling] Clear the PreambleSrcLocCache when preamble is discarded during reparsing

2018-03-12 Thread via cfe-commits
Hi Alex,

The test you added in this commit seems to be failing on the Windows bot 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/15855:

FAIL: Clang :: Index/reparsed-live-issue.cpp (7841 of 38815)
 TEST 'Clang :: Index/reparsed-live-issue.cpp' FAILED 

Script:
--
CINDEXTEST_EDITING=1 LIBCLANG_DISABLE_CRASH_RECOVERY=1 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.obj\bin\c-index-test.EXE
 -test-load-source-reparse 2 none 
-remap-file-0=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h,C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h-0
 
-remap-file-1=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h,C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h-1
 -- 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index\reparsed-live-issue.cpp
 2>&1 | 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.obj\bin\FileCheck.EXE
 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index\reparsed-live-issue.cpp
--
Exit Code: 127

Command Output (stdout):
--
$ "CINDEXTEST_EDITING=1" "LIBCLANG_DISABLE_CRASH_RECOVERY=1" 
"C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.obj\bin\c-index-test.EXE"
 "-test-load-source-reparse" "2" "none" 
"-remap-file-0=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h,C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h-0"
 
"-remap-file-1=C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h,C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index/Inputs/reparse-issue.h-1"
 "--" 
"C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Index\reparsed-live-issue.cpp"
# command stderr:
'CINDEXTEST_EDITING=1': command not found
error: command failed with exit status: 127

--



It seems perhaps you forgot to prefix the test line with "env"?

Douglas Yung

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of
> Alex Lorenz via cfe-commits
> Sent: Monday, March 12, 2018 12:36
> To: cfe-commits@lists.llvm.org
> Subject: r327322 - [Tooling] Clear the PreambleSrcLocCache when preamble is
> discarded during reparsing
> 
> Author: arphaman
> Date: Mon Mar 12 12:36:29 2018
> New Revision: 327322
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=327322&view=rev
> Log:
> [Tooling] Clear the PreambleSrcLocCache when preamble is discarded during
> reparsing
> 
> This ensures that diagnostics are not remapped to incorrect preamble locations
> after the second reparse with a remapped header file occurs.
> 
> rdar://37502480
> 
> Added:
> cfe/trunk/test/Index/Inputs/reparse-issue.h
> cfe/trunk/test/Index/Inputs/reparse-issue.h-0
> cfe/trunk/test/Index/Inputs/reparse-issue.h-1
> cfe/trunk/test/Index/reparsed-live-issue.cpp
> Modified:
> cfe/trunk/lib/Frontend/ASTUnit.cpp
> 
> Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=327322&r1=327321&r2=327322&view
> =diff
> ==
> --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
> +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Mar 12 12:36:29 2018
> @@ -1259,6 +1259,7 @@ ASTUnit::getMainBufferWithPrecompiledPre
>Preamble.reset();
>PreambleDiagnostics.clear();
>TopLevelDeclsInPreamble.clear();
> +  PreambleSrcLocCache.clear();
>PreambleRebuildCounter = 1;
>  }
>}
> 
> Added: cfe/trunk/test/Index/Inputs/reparse-issue.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/reparse-
> issue.h?rev=327322&view=auto
> ==
> --- cfe/trunk/test/Index/Inputs/reparse-issue.h (added)
> +++ cfe/trunk/test/Index/Inputs/reparse-issue.h Mon Mar 12 12:36:29 2018
> @@ -0,0 +1,3 @@
> +
> +asdf;
> +
> 
> Added: cfe/trunk/test/Index/Inputs/reparse-issue.h-0
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/reparse-
> issue.h-0?rev=327322&view=auto
> ==
> --- cfe/trunk/test/Index/Inputs/reparse-issue.h-0 (added)
> +++ cfe/trunk/test/Index/Inputs/reparse-issue.h-0 Mon Mar 12 12:36:29
> +++ 2018
> @@ -0,0 +1,4

r327334 - Re-land "[Sema] Make getCurFunction() return null outside function parsing"

2018-03-12 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Mar 12 14:43:02 2018
New Revision: 327334

URL: http://llvm.org/viewvc/llvm-project?rev=327334&view=rev
Log:
Re-land "[Sema] Make getCurFunction() return null outside function parsing"

This relands r326965.

There was a null dereference in typo correction that was triggered in
Sema/diagnose_if.c. We are not always in a function scope when doing
typo correction. The fix is to add a null check.

LLVM's optimizer made it hard to find this bug. I wrote it up in a
not-very-well-editted blog post here:
http://qinsb.blogspot.com/2018/03/ub-will-delete-your-null-checks.html

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=327334&r1=327333&r2=327334&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Mar 12 14:43:02 2018
@@ -528,12 +528,10 @@ public:
   ///  full expression.
   llvm::SmallPtrSet MaybeODRUseExprs;
 
+  std::unique_ptr PreallocatedFunctionScope;
+
   /// \brief Stack containing information about each of the nested
   /// function, block, and method scopes that are currently active.
-  ///
-  /// This array is never empty.  Clients should ignore the first
-  /// element, which is used to cache a single FunctionScopeInfo
-  /// that's used to parse every top-level function.
   SmallVector FunctionScopes;
 
   typedef LazyVectorhttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=327334&r1=327333&r2=327334&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Mar 12 14:43:02 2018
@@ -632,18 +632,19 @@ struct CheckFallThroughDiagnostics {
 
 } // anonymous namespace
 
-/// CheckFallThroughForFunctionDef - Check that we don't fall off the end of a
+/// CheckFallThroughForBody - Check that we don't fall off the end of a
 /// function that should return a value.  Check that we don't fall off the end
 /// of a noreturn function.  We assume that functions and blocks not marked
 /// noreturn will return.
 static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
 const BlockExpr *blkExpr,
-const CheckFallThroughDiagnostics& CD,
-AnalysisDeclContext &AC) {
+const CheckFallThroughDiagnostics &CD,
+AnalysisDeclContext &AC,
+sema::FunctionScopeInfo *FSI) {
 
   bool ReturnsVoid = false;
   bool HasNoReturn = false;
-  bool IsCoroutine = S.getCurFunction() && S.getCurFunction()->isCoroutine();
+  bool IsCoroutine = FSI->isCoroutine();
 
   if (const auto *FD = dyn_cast(D)) {
 if (const auto *CBody = dyn_cast(Body))
@@ -675,7 +676,7 @@ static void CheckFallThroughForBody(Sema
   SourceLocation LBrace = Body->getLocStart(), RBrace = Body->getLocEnd();
   auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) {
 if (IsCoroutine)
-  S.Diag(Loc, DiagID) << S.getCurFunction()->CoroutinePromise->getType();
+  S.Diag(Loc, DiagID) << FSI->CoroutinePromise->getType();
 else
   S.Diag(Loc, DiagID);
   };
@@ -2143,7 +2144,7 @@ AnalysisBasedWarnings::IssueWarnings(sem
: (fscope->isCoroutine()
   ? CheckFallThroughDiagnostics::MakeForCoroutine(D)
   : CheckFallThroughDiagnostics::MakeForFunction(D)));
-CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC);
+CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC, fscope);
   }
 
   // Warning: check for unreachable code

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=327334&r1=327333&r2=327334&view=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Mon Mar 12 14:43:02 2018
@@ -162,7 +162,7 @@ Sema::Sema(Preprocessor &pp, ASTContext
   ExpressionEvaluationContext::PotentiallyEvaluated, 0, CleanupInfo{},
   nullptr, false);
 
-  FunctionScopes.push_back(new FunctionScopeInfo(Diags));
+  PreallocatedFunctionScope.reset(new FunctionScopeInfo(Diags));
 
   // Initilization of data sharing attributes stack for OpenMP
   InitDataSharingAttributesStack();
@@ -332,11 +332,11 @@ void Sema::I

[clang-tools-extra] r327333 - [docs] Adding clang-doc to CTE toctree to fix docs build error

2018-03-12 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Mar 12 14:39:01 2018
New Revision: 327333

URL: http://llvm.org/viewvc/llvm-project?rev=327333&view=rev
Log:
[docs] Adding clang-doc to CTE toctree to fix docs build error

Modified:
clang-tools-extra/trunk/docs/clang-doc.rst
clang-tools-extra/trunk/docs/index.rst

Modified: clang-tools-extra/trunk/docs/clang-doc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-doc.rst?rev=327333&r1=327332&r2=327333&view=diff
==
--- clang-tools-extra/trunk/docs/clang-doc.rst (original)
+++ clang-tools-extra/trunk/docs/clang-doc.rst Mon Mar 12 14:39:01 2018
@@ -4,6 +4,9 @@ Clang-Doc
 
 .. contents::
 
+.. toctree::
+   :maxdepth: 1
+
 :program:`clang-doc` is a tool for generating C and C++ documenation from 
 source code and comments. 
 

Modified: clang-tools-extra/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/index.rst?rev=327333&r1=327332&r2=327333&view=diff
==
--- clang-tools-extra/trunk/docs/index.rst (original)
+++ clang-tools-extra/trunk/docs/index.rst Mon Mar 12 14:39:01 2018
@@ -26,6 +26,7 @@ Contents
pp-trace
clang-rename
clangd
+   clang-doc
 
 
 Doxygen Documentation


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


LLVM buildmaster will be updated and restarted tonight

2018-03-12 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be updated and restarted after 6PM Pacific time today.

Thanks

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


[PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2018-03-12 Thread Marcus Johnson via Phabricator via cfe-commits
bumblebritches57 added a comment.
Herald added a subscriber: christof.

This is the wrong approach.

C and C++ compatibility is far more important than taking the easy way out.

By doing this, you're potentially breaking the ABI for all software that relies 
on atomic operations...


https://reviews.llvm.org/D26376



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


[PATCH] D40988: Clang-format: add finer-grained options for putting all arguments on one line

2018-03-12 Thread Russell McClellan via Phabricator via cfe-commits
russellmcc added a comment.

Bump!


https://reviews.llvm.org/D40988



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


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

I think this check LGTM.


https://reviews.llvm.org/D41655



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


[PATCH] D44346: [clang-tidy] Add Fuchsia checker for temporary objects

2018-03-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/FuchsiaTidyModule.cpp:44
+CheckFactories.registerCheck(
+"fuchsia-zx-temporary-objects");
   }

Do we want a zircon module instead? I'm wondering about people who enable 
modules by doing `fuchsia-*` and whether or not they would expect this check 
(and others for zircon) to be enabled.



Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp:46
+void ZxTemporaryObjectsCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs("temps")) {
+diag(D->getLocation(), "misuse of temporary object");

Elide braces.



Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp:47
+  if (const auto *D = Result.Nodes.getNodeAs("temps")) {
+diag(D->getLocation(), "misuse of temporary object");
+  }

I think this could be stated more clearly as "creating a temporary object of 
type %0 is prohibited" and pass in the temporary type. That will also help the 
user to identify what type is problematic in something like: `f(good_temp{}, 
bad_temp{}, good_temp{});`. I'm not tied to printing the type, but "misuse" 
suggests there's a better way to use the temporary object, which I don't think 
is a correct interpretation.



Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.h:20
+
+/// Constructing of specific temporary objects in the Zircon kernel is
+/// discouraged. Takes the list of such discouraged temporary objects as a

Construction instead of constructing?


https://reviews.llvm.org/D44346



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


RE: [clang-tools-extra] r327295 - Reland "[clang-doc] Setup clang-doc frontend framework"

2018-03-12 Thread via cfe-commits
Hi Julie,

It looks like this commit is causing Clang tests in Windows bots to crash. 
Could you take a look?

http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/9413

Thanks,
Matthew

-Original Message-
From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
Julie Hockett via cfe-commits
Sent: Monday, March 12, 2018 10:05 AM
To: cfe-commits@lists.llvm.org
Subject: [clang-tools-extra] r327295 - Reland "[clang-doc] Setup clang-doc 
frontend framework"

Author: juliehockett
Date: Mon Mar 12 10:05:14 2018
New Revision: 327295

URL: http://llvm.org/viewvc/llvm-project?rev=327295&view=rev
Log:
Reland "[clang-doc] Setup clang-doc frontend framework"

There was a missing newline in the docs, and a static_assert that needed
to be a normal assert.

Added:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/docs/clang-doc.rst
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=327295&r1=327294&r2=327295&view=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Mon Mar 12 10:05:14 2018
@@ -7,6 +7,7 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
+add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Added: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=327295&view=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Mar 12 10:05:14 2018
@@ -0,0 +1,515 @@
+//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "BitcodeWriter.h"
+#include "llvm/ADT/IndexedMap.h"
+
+namespace clang {
+namespace doc {
+
+// Since id enums are not zero-indexed, we need to transform the given id into
+// its associated index.
+struct BlockIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
+};
+
+struct RecordIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
+};
+
+using AbbrevDsc = void (*)(std::shared_ptr &Abbrev);
+
+static void AbbrevGen(std::shared_ptr &Abbrev,
+  const std::initializer_list Ops) {
+  for (const auto &Op : Ops)
+Abbrev->Add(Op);
+}
+
+static void BoolAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Boolean
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::BoolSize)});
+}
+
+static void IntAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::IntSize)});
+}
+
+static void SymbolIDAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the sha1'd USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+

[libclc] r327324 - nan: Implement

2018-03-12 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Mon Mar 12 12:46:52 2018
New Revision: 327324

URL: http://llvm.org/viewvc/llvm-project?rev=327324&view=rev
Log:
nan: Implement

Passes CTS on carrizo and turks

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/nan.h
libclc/trunk/generic/include/clc/math/nan.inc
libclc/trunk/generic/lib/math/nan.cl
libclc/trunk/generic/lib/math/nan.inc
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=327324&r1=327323&r2=327324&view=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Mon Mar 12 12:46:52 2018
@@ -98,6 +98,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/nan.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/nan.h?rev=327324&view=auto
==
--- libclc/trunk/generic/include/clc/math/nan.h (added)
+++ libclc/trunk/generic/include/clc/math/nan.h Mon Mar 12 12:46:52 2018
@@ -0,0 +1,8 @@
+#define __CLC_CONCAT(x, y) x ## y
+#define __CLC_XCONCAT(x, y) __CLC_CONCAT(x, y)
+
+#define __CLC_BODY 
+#include 
+
+#undef __CLC_XCONCAT
+#undef __CLC_CONCAT

Added: libclc/trunk/generic/include/clc/math/nan.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/nan.inc?rev=327324&view=auto
==
--- libclc/trunk/generic/include/clc/math/nan.inc (added)
+++ libclc/trunk/generic/include/clc/math/nan.inc Mon Mar 12 12:46:52 2018
@@ -0,0 +1,16 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+#define __CLC_NATN __CLC_XCONCAT(ulong, __CLC_VECSIZE)
+#else
+#define __CLC_NATN __CLC_XCONCAT(uint, __CLC_VECSIZE)
+#endif
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE nan(__CLC_NATN code);
+
+#undef __CLC_NATN
+#ifdef __CLC_SCALAR
+#undef __CLC_VECSIZE
+#endif

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=327324&r1=327323&r2=327324&view=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Mon Mar 12 12:46:52 2018
@@ -134,6 +134,7 @@ math/mad.cl
 math/maxmag.cl
 math/minmag.cl
 math/modf.cl
+math/nan.cl
 math/native_cos.cl
 math/native_divide.cl
 math/native_exp.cl

Added: libclc/trunk/generic/lib/math/nan.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/nan.cl?rev=327324&view=auto
==
--- libclc/trunk/generic/lib/math/nan.cl (added)
+++ libclc/trunk/generic/lib/math/nan.cl Mon Mar 12 12:46:52 2018
@@ -0,0 +1,6 @@
+#include 
+#include "utils.h"
+
+#define __CLC_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
+#define __CLC_BODY 
+#include 

Added: libclc/trunk/generic/lib/math/nan.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/nan.inc?rev=327324&view=auto
==
--- libclc/trunk/generic/lib/math/nan.inc (added)
+++ libclc/trunk/generic/lib/math/nan.inc Mon Mar 12 12:46:52 2018
@@ -0,0 +1,20 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_XCONCAT(ulong, __CLC_VECSIZE) 
code)
+{
+   return __CLC_AS_GENTYPE(code | 0x7ff0ul);
+}
+#else
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_XCONCAT(uint, __CLC_VECSIZE) 
code)
+{
+   return __CLC_AS_GENTYPE(code | 0x7fc0);
+}
+#endif
+
+
+#ifdef __CLC_SCALAR
+#undef __CLC_VECSIZE
+#endif


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


[libclc] r327323 - travis: Add build using llvm-6

2018-03-12 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Mon Mar 12 12:46:48 2018
New Revision: 327323

URL: http://llvm.org/viewvc/llvm-project?rev=327323&view=rev
Log:
travis: Add build using llvm-6

Acked-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/.travis.yml

Modified: libclc/trunk/.travis.yml
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/.travis.yml?rev=327323&r1=327322&r2=327323&view=diff
==
--- libclc/trunk/.travis.yml (original)
+++ libclc/trunk/.travis.yml Mon Mar 12 12:46:48 2018
@@ -54,6 +54,28 @@ matrix:
 # From sources above
 - llvm-5.0-dev
 - clang-5.0
+- env:
+- LABEL="make gcc LLVM-6.0"
+- LLVM_VERSION=6.0
+- LLVM_CONFIG="llvm-config-${LLVM_VERSION}"
+- CHECK_FILES="barts-r600--.bc cayman-r600--.bc cedar-r600--.bc 
cypress-r600--.bc tahiti-amdgcn--.bc amdgcn--amdhsa.bc nvptx--nvidiacl.bc 
nvptx64--nvidiacl.bc"
+# llvm passes -Werror=date-time which is only supported in gcc-4.9+
+- MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
+  addons:
+apt:
+  sources:
+- sourceline: 'deb http://apt.llvm.org/trusty/ 
llvm-toolchain-trusty-6.0 main'
+- ubuntu-toolchain-r-test
+  packages:
+- libedit-dev
+# LLVM-6 needs libstdc++4.9
+- g++-4.9
+# From sources above
+- llvm-6.0-dev
+- clang-6.0
+
+before_install:
+- eval "${MATRIX_EVAL}"
 
 script:
   - $PYTHON ./configure.py --with-llvm-config=$LLVM_CONFIG 
--with-cxx-compiler=$CXX && make -j4


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


[PATCH] D44143: [clang-tidy] Create properly seeded random generator check

2018-03-12 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 added a subscriber: szepet.
boga95 marked 4 inline comments as done.
boga95 added inline comments.



Comment at: test/clang-tidy/cert-properly-seeded-random-generator.cpp:76
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator must be 
seeded with a random_device instead of a constant 
[cert-properly-seeded-random-generator]
+  engine1.seed(seed);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator must be 
seeded with a random_device instead of a constant 
[cert-properly-seeded-random-generator]

Quuxplusone wrote:
> Is the diagnostic suppressed if `seed` is a template parameter? (Not that I'd 
> do this. It's just a corner case I thought of.)
Hopefully, it is not suppressed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44143



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


r327322 - [Tooling] Clear the PreambleSrcLocCache when preamble is discarded during reparsing

2018-03-12 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Mar 12 12:36:29 2018
New Revision: 327322

URL: http://llvm.org/viewvc/llvm-project?rev=327322&view=rev
Log:
[Tooling] Clear the PreambleSrcLocCache when preamble is discarded during 
reparsing

This ensures that diagnostics are not remapped to incorrect preamble locations 
after
the second reparse with a remapped header file occurs.

rdar://37502480

Added:
cfe/trunk/test/Index/Inputs/reparse-issue.h
cfe/trunk/test/Index/Inputs/reparse-issue.h-0
cfe/trunk/test/Index/Inputs/reparse-issue.h-1
cfe/trunk/test/Index/reparsed-live-issue.cpp
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=327322&r1=327321&r2=327322&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Mar 12 12:36:29 2018
@@ -1259,6 +1259,7 @@ ASTUnit::getMainBufferWithPrecompiledPre
   Preamble.reset();
   PreambleDiagnostics.clear();
   TopLevelDeclsInPreamble.clear();
+  PreambleSrcLocCache.clear();
   PreambleRebuildCounter = 1;
 }
   }

Added: cfe/trunk/test/Index/Inputs/reparse-issue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/reparse-issue.h?rev=327322&view=auto
==
--- cfe/trunk/test/Index/Inputs/reparse-issue.h (added)
+++ cfe/trunk/test/Index/Inputs/reparse-issue.h Mon Mar 12 12:36:29 2018
@@ -0,0 +1,3 @@
+
+asdf;
+

Added: cfe/trunk/test/Index/Inputs/reparse-issue.h-0
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/reparse-issue.h-0?rev=327322&view=auto
==
--- cfe/trunk/test/Index/Inputs/reparse-issue.h-0 (added)
+++ cfe/trunk/test/Index/Inputs/reparse-issue.h-0 Mon Mar 12 12:36:29 2018
@@ -0,0 +1,4 @@
+//
+//
+asdf;
+

Added: cfe/trunk/test/Index/Inputs/reparse-issue.h-1
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/reparse-issue.h-1?rev=327322&view=auto
==
--- cfe/trunk/test/Index/Inputs/reparse-issue.h-1 (added)
+++ cfe/trunk/test/Index/Inputs/reparse-issue.h-1 Mon Mar 12 12:36:29 2018
@@ -0,0 +1,5 @@
+//
+//
+//
+asdf;
+

Added: cfe/trunk/test/Index/reparsed-live-issue.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/reparsed-live-issue.cpp?rev=327322&view=auto
==
--- cfe/trunk/test/Index/reparsed-live-issue.cpp (added)
+++ cfe/trunk/test/Index/reparsed-live-issue.cpp Mon Mar 12 12:36:29 2018
@@ -0,0 +1,4 @@
+// RUN: CINDEXTEST_EDITING=1 LIBCLANG_DISABLE_CRASH_RECOVERY=1 c-index-test 
-test-load-source-reparse 2 none 
-remap-file-0=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-0 
-remap-file-1=%S/Inputs/reparse-issue.h,%S/Inputs/reparse-issue.h-1 -- %s 2>&1 
| FileCheck %s
+#include "Inputs/reparse-issue.h"
+
+// CHECK: reparse-issue.h:4:1:{1:1-1:1}: error: C++ requires a type specifier 
for all declarations


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


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327317: Check that ubsan is the only supported sanitizer on 
OpenBSD (authored by vedantk, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44069

Files:
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -388,6 +388,25 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 
-fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-OPENBSD
+// CHECK-LSAN-OPENBSD: unsupported option '-fsanitize=leak' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-OPENBSD
+// CHECK-TSAN-OPENBSD: unsupported option '-fsanitize=thread' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-OPENBSD
+// CHECK-MSAN-OPENBSD: unsupported option '-fsanitize=memory' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-cache-frag %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-working-set %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// CHECK-ESAN-OPENBSD: error: unsupported option 
'-fsanitize=efficiency-{{.*}}' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -388,6 +388,25 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LSAN-OPENBSD
+// CHECK-LSAN-OPENBSD: unsupported option '-fsanitize=leak' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-OPENBSD
+// CHECK-TSAN-OPENBSD: unsupported option '-fsanitize=thread' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-OPENBSD
+// CHECK-MSAN-OPENBSD: unsupported option '-fsanitize=memory' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-cache-frag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-working-set %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// CHECK-ESAN-OPENBSD: error: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327317: Check that ubsan is the only supported sanitizer on 
OpenBSD (authored by vedantk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44069?vs=137448&id=138071#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44069

Files:
  cfe/trunk/test/Driver/fsanitize.c


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -388,6 +388,25 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 
-fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-OPENBSD
+// CHECK-LSAN-OPENBSD: unsupported option '-fsanitize=leak' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-OPENBSD
+// CHECK-TSAN-OPENBSD: unsupported option '-fsanitize=thread' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-OPENBSD
+// CHECK-MSAN-OPENBSD: unsupported option '-fsanitize=memory' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-cache-frag %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-working-set %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// CHECK-ESAN-OPENBSD: error: unsupported option 
'-fsanitize=efficiency-{{.*}}' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -388,6 +388,25 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LSAN-OPENBSD
+// CHECK-LSAN-OPENBSD: unsupported option '-fsanitize=leak' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-OPENBSD
+// CHECK-TSAN-OPENBSD: unsupported option '-fsanitize=thread' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-OPENBSD
+// CHECK-MSAN-OPENBSD: unsupported option '-fsanitize=memory' for target 'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-cache-frag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-working-set %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// CHECK-ESAN-OPENBSD: error: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r327317 - Check that ubsan is the only supported sanitizer on OpenBSD

2018-03-12 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Mar 12 12:18:51 2018
New Revision: 327317

URL: http://llvm.org/viewvc/llvm-project?rev=327317&view=rev
Log:
Check that ubsan is the only supported sanitizer on OpenBSD

Patch by David Carlier!

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

Modified:
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=327317&r1=327316&r2=327317&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Mon Mar 12 12:18:51 2018
@@ -388,6 +388,25 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 
-fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-OPENBSD
+// CHECK-LSAN-OPENBSD: unsupported option '-fsanitize=leak' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=thread %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-TSAN-OPENBSD
+// CHECK-TSAN-OPENBSD: unsupported option '-fsanitize=thread' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-OPENBSD
+// CHECK-MSAN-OPENBSD: unsupported option '-fsanitize=memory' for target 
'i386-pc-openbsd'
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-cache-frag %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// RUN: %clang -target i386-pc-openbsd -fsanitize=efficiency-working-set %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-OPENBSD
+// CHECK-ESAN-OPENBSD: error: unsupported option 
'-fsanitize=efficiency-{{.*}}' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 


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


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 138066.
ahatanak added a comment.

The new patch passes the calling context to CheckNonDependent so that 
Sema::CheckAddressOfMemberAccess uses the correct context to check 
accessibility of explicit template arguments. I initially tried moving the 
declaration of SavedContext in Sema::FinishTemplateArgumentDeduction to after 
the call to CheckNonDependent, but that caused 
test/SemaCXX/cxx1z-class-template-argument-deduction.cpp to fail. It seems like 
it changes the way lookup of default template arguments is done when the 
context (which is a CXXDeductionGuideDecl in the failing test case) is not set 
before ConvertDeducedTemplateArguments is called.


https://reviews.llvm.org/D36918

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplateDeduction.cpp
  test/SemaCXX/access.cpp

Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2(&func0);
+  func2(&func1);
+}
+  };
+
+  void friendFunc() {
+func2(&func0);
+func2(&func1);
+  }
+
+  void nonFriendFunc() {
+func2(&func0); // expected-error {{no matching function for call to 'func2'}}
+func2(&func1); // expected-error {{no matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3170,7 +3170,8 @@
 unsigned NumExplicitlySpecified, FunctionDecl *&Specialization,
 TemplateDeductionInfo &Info,
 SmallVectorImpl const *OriginalCallArgs,
-bool PartialOverloading, llvm::function_ref CheckNonDependent) {
+bool PartialOverloading,
+llvm::function_ref CheckNonDependent) {
   // Unevaluated SFINAE context.
   EnterExpressionEvaluationContext Unevaluated(
   *this, Sema::ExpressionEvaluationContext::Unevaluated);
@@ -3185,6 +3186,7 @@
   if (Inst.isInvalid())
 return TDK_InstantiationDepth;
 
+  DeclContext *CallingCtx = CurContext;
   ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl());
 
   // C++ [temp.deduct.type]p2:
@@ -3206,7 +3208,7 @@
   //   P with a type that was non-dependent before substitution of any
   //   explicitly-specified template arguments, if the corresponding argument
   //   A cannot be implicitly converted to P, deduction fails.
-  if (CheckNonDependent())
+  if (CheckNonDependent(CallingCtx))
 return TDK_NonDependentConversionFailure;
 
   // Form the template argument list from the deduced template arguments.
@@ -3799,8 +3801,10 @@
 
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  &OriginalCallArgs, PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  &OriginalCallArgs, PartialOverloading, [&](DeclContext *CallingCtx) {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -6927,7 +6927,8 @@
   sema::TemplateDeductionInfo &Info,
   SmallVectorImpl const *OriginalCallArgs = nullptr,
   bool PartialOverloading = false,
-  llvm::function_ref CheckNonDependent = []{ return false; });
+  llvm::function_ref CheckNonDependent =
+  [](DeclContext *){ return false; });
 
   TemplateDeductionResult DeduceTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.

2018-03-12 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added inline comments.



Comment at: clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:213-221
   // Use the file manager to deduplicate paths. FileEntries are
   // automatically canonicalized.
-  if (const FileEntry *Entry = 
SM.getFileManager().getFile(R.getFilePath())) {
+  if (const FileEntry *Entry =
+  SM.getFileManager().getFile(R.getFilePath())) {
 GroupedReplacements[Entry].push_back(R);
   } else if (Warned.insert(R.getFilePath()).second) {
+errs() << "Described file '" << R.getFilePath()

ioeric wrote:
> This code block is the same as the one in the above loop. Consider pulling it 
> into a lambda.
Yes, for sure. I was not confident about this part.



Comment at: clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:290
+std::vector Changes;
+for (const auto &R : AllChanges.getReplacements()) {
+  tooling::AtomicChange Change(Entry->getName(), Entry->getName());

ioeric wrote:
> I might be missing something, but why do we need to pull replacements from 
> the result change into a set of changes? 
I interpret you suggestion of set of `AtomicChange` a little bit too much.



Comment at: clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:353
+const FileEntry *Entry = FileAndReplacements.first;
+ReplacementsToAtomicChanges DeduplicatedChanges(SM, Entry);
+for (const auto &R : FileAndReplacements.second)

ioeric wrote:
> Sorry that I didn't make myself clear... what you had in the previous 
> revision was correct (for the current use case of apply-all-replacements) 
> i.e. store all replacements in one `AtomicChange`, which allows you to detect 
> conflicts on the fly. So the code here can be simplified as:
> 
> ```
> ...
> Entry = ...;
> AtomicChange FileChange;
> for (const auto &R : FileAndReplacements.second) {
>   auto Err = FileChange.replace(  );
>   if (Err)
> reportConflict(Entry, std::move(Err));  // reportConflict as we go
> }
> FileChanges.emplace(Entry, {FileChange});
> ...
> ```
> 
> I think with this set up, you wouldn't need `ReplacementsToAtomicChanges`, 
> `ConflictError` and `reportConflicts`.
I think I have over-interpreting your previous comment :-)
However, I am still confused about error reporting.
Currently, clang-apply-replacements reports conflicting replacement per file 
and per conflict.
For example:
```
There are conflicting changes to XXX:
The following changes conflict:
  Replace 8:8-8:33 with "AAA"
  Replace 8:8-8:33 with "BBB"
  Remove 8:10-8:15
  Insert at 8:14 CCC
```

With this patch, conflict are reported by pair (first replacement/conflicted 
one) and I am able to print the corresponding file only once (thanks to the 
defered reporting).
```
There are conflicting changes to XXX:
The following changes conflict:
  Replace 8:8-8:33 with "AAA"
  Replace 8:8-8:33 with "BBB"
The following changes conflict:
  Replace 8:8-8:33 with "AAA"
  Remove 8:10-8:15
The following changes conflict:
  Replace 8:8-8:33 with "AAA"
  Insert at 8:14 CCC
```

I prefer the way you suggest to report conflict but we will loose or print 
conflicting file at each conflict detected.
I even more prefer to use `llvm::toString(std::move(Err))` but this will fully 
change the reporting and will also be reported by pair.
```
The new replacement overlaps with an existing replacement.
New replacement: XXX: 106:+26:"AAA"
Existing replacement: XXX: 106:+26:"BBB"
The new replacement overlaps with an existing replacement.
New replacement: XXX: 106:+26:"AAA"
Existing replacement: XXX: 112:+0:"CCC"
The new replacement overlaps with an existing replacement.
New replacement: XXX: 106:+26:"AAA"
Existing replacement: XXX: 108:+12:""
```



Comment at: test/clang-apply-replacements/Inputs/basic/file2.yaml:1
 ---
 MainSourceFile: source2.cpp

ioeric wrote:
> Could you please add two test cases for insertions: 1) identical insertions 
> (e.g. "AB" and "AB") at the same location are applied sucessfully and 2) 
> order-dependent insertions (e.g. "AB" and "BA") are detected.
> 
> (It might make sense to do this in a different file)
I will.



Comment at: test/clang-apply-replacements/Inputs/conflict/expected.txt:8
+  Replace 9:5-9:11 with "elem"
 The following changes conflict:
   Remove 12:3-12:14

ioeric wrote:
> How could one replacement (`Remove 12:3-12:14`) conflict with itself?
It is not the case, they are reported by pair now.


https://reviews.llvm.org/D43764



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


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak reopened this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

The patch got reverted in r325335 as it broke the Chromium build. I'm reopening 
this review.


Repository:
  rC Clang

https://reviews.llvm.org/D36918



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


r327313 - [Driver] Add text description of --help-hidden so it is shown in help

2018-03-12 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Mar 12 11:33:55 2018
New Revision: 327313

URL: http://llvm.org/viewvc/llvm-project?rev=327313&view=rev
Log:
[Driver] Add text description of --help-hidden so it is shown in help

Modified:
cfe/trunk/include/clang/Driver/Options.td

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=327313&r1=327312&r2=327313&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Mar 12 11:33:55 2018
@@ -2401,7 +2401,8 @@ def _for_linker_EQ : Joined<["--"], "for
 def _for_linker : Separate<["--"], "for-linker">, Alias;
 def _force_link_EQ : Joined<["--"], "force-link=">, Alias;
 def _force_link : Separate<["--"], "force-link">, Alias;
-def _help_hidden : Flag<["--"], "help-hidden">;
+def _help_hidden : Flag<["--"], "help-hidden">,
+  HelpText<"Display help for hidden options">;
 def _imacros_EQ : Joined<["--"], "imacros=">, Alias;
 def _include_barrier : Flag<["--"], "include-barrier">, Alias;
 def _include_directory_after_EQ : Joined<["--"], "include-directory-after=">, 
Alias;


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


[PATCH] D44228: [analyzer] Move the GCDAsyncSemaphoreChecker to optin.performance

2018-03-12 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327309: [analyzer] Move the GCDAsyncSemaphoreChecker to 
optin.performance (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44228?vs=137823&id=138063#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44228

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
  lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
  test/Analysis/gcdantipatternchecker_test.m
  test/Analysis/gcdasyncsemaphorechecker_test.m

Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -610,12 +610,12 @@
 
 } // end "osx.cocoa"
 
-let ParentPackage = OSXAlpha in {
+let ParentPackage = Performance in {
 
-def GCDAsyncSemaphoreChecker : Checker<"GCDAsyncSemaphore">,
-  HelpText<"Checker for performance anti-pattern when using semaphors from async API">,
-  DescFile<"GCDAsyncSemaphoreChecker.cpp">;
-} // end "alpha.osx"
+def GCDAntipattern : Checker<"GCDAntipattern">,
+  HelpText<"Check for performance anti-patterns when using Grand Central Dispatch">,
+  DescFile<"GCDAntipatternChecker.cpp">;
+} // end "optin.performance"
 
 let ParentPackage = CocoaAlpha in {
 
Index: test/Analysis/gcdantipatternchecker_test.m
===
--- test/Analysis/gcdantipatternchecker_test.m
+++ test/Analysis/gcdantipatternchecker_test.m
@@ -0,0 +1,266 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.performance.GCDAntipattern %s -fblocks -verify
+typedef signed char BOOL;
+@protocol NSObject  - (BOOL)isEqual:(id)object; @end
+@interface NSObject  {}
++(id)alloc;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+-(id)retain;
+@end
+
+typedef int dispatch_semaphore_t;
+typedef void (^block_t)();
+
+dispatch_semaphore_t dispatch_semaphore_create(int);
+void dispatch_semaphore_wait(dispatch_semaphore_t, int);
+void dispatch_semaphore_signal(dispatch_semaphore_t);
+
+void func(void (^)(void));
+void func_w_typedef(block_t);
+
+int coin();
+
+void use_semaphor_antipattern() {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+}
+
+// It's OK to use pattern in tests.
+// We simply match the containing function name against ^test.
+void test_no_warning() {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100);
+}
+
+void use_semaphor_antipattern_multiple_times() {
+  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema1);
+  });
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+
+  dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema2);
+  });
+  dispatch_semaphore_wait(sema2, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+}
+
+void use_semaphor_antipattern_multiple_wait() {
+  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema1);
+  });
+  // FIXME: multiple waits on same semaphor should not raise a warning.
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+}
+
+void warn_incorrect_order() {
+  // FIXME: ASTMatchers do not allow ordered matching, so would match even
+  // if out of order.
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+}
+
+void warn_w_typedef() {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func_w_typedef(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}}

r327309 - [analyzer] Move the GCDAsyncSemaphoreChecker to optin.performance

2018-03-12 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Mar 12 11:27:36 2018
New Revision: 327309

URL: http://llvm.org/viewvc/llvm-project?rev=327309&view=rev
Log:
[analyzer] Move the GCDAsyncSemaphoreChecker to optin.performance

rdar://38383753

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
  - copied, changed from r327294, 
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
cfe/trunk/test/Analysis/gcdantipatternchecker_test.m
  - copied, changed from r327294, 
cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m
Removed:
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

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=327309&r1=327308&r2=327309&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Mar 12 
11:27:36 2018
@@ -610,12 +610,12 @@ def ObjCSuperDeallocChecker : Checker<"S
 
 } // end "osx.cocoa"
 
-let ParentPackage = OSXAlpha in {
+let ParentPackage = Performance in {
 
-def GCDAsyncSemaphoreChecker : Checker<"GCDAsyncSemaphore">,
-  HelpText<"Checker for performance anti-pattern when using semaphors from 
async API">,
-  DescFile<"GCDAsyncSemaphoreChecker.cpp">;
-} // end "alpha.osx"
+def GCDAntipattern : Checker<"GCDAntipattern">,
+  HelpText<"Check for performance anti-patterns when using Grand Central 
Dispatch">,
+  DescFile<"GCDAntipatternChecker.cpp">;
+} // end "optin.performance"
 
 let ParentPackage = CocoaAlpha in {
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=327309&r1=327308&r2=327309&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Mon Mar 12 11:27:36 
2018
@@ -37,7 +37,7 @@ add_clang_library(clangStaticAnalyzerChe
   DynamicTypeChecker.cpp
   ExprInspectionChecker.cpp
   FixedAddressChecker.cpp
-  GCDAsyncSemaphoreChecker.cpp
+  GCDAntipatternChecker.cpp
   GenericTaintChecker.cpp
   GTestChecker.cpp
   IdenticalExprChecker.cpp

Copied: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp (from 
r327294, cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp?p2=cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp&p1=cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp&r1=327294&r2=327309&rev=327309&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp Mon Mar 12 
11:27:36 2018
@@ -1,4 +1,4 @@
-//===- GCDAsyncSemaphoreChecker.cpp -*- C++ -*-==//
+//===- GCDAntipatternChecker.cpp -*- C++ 
-*-==//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -7,20 +7,20 @@
 //
 
//===--===//
 //
-// This file defines GCDAsyncSemaphoreChecker which checks against a common
+// This file defines GCDAntipatternChecker which checks against a common
 // antipattern when synchronous API is emulated from asynchronous callbacks
-// using a semaphor:
+// using a semaphore:
+//
+//   dispatch_semaphore_t sema = dispatch_semaphore_create(0);
 //
-//   dispatch_semapshore_t sema = dispatch_semaphore_create(0);
-
 //   AnyCFunctionCall(^{
 // // code…
-// dispatch_semapshore_signal(sema);
+// dispatch_semaphore_signal(sema);
 //   })
-//   dispatch_semapshore_wait(sema, *)
+//   dispatch_semaphore_wait(sema, *)
 //
 // Such code is a common performance problem, due to inability of GCD to
-// properly handle QoS when a combination of queues and semaphors is used.
+// properly handle QoS when a combination of queues and semaphores is used.
 // Good code would either use asynchronous API (when available), or perform
 // the necessary action in asynchronous callback.
 //
@@ -37,8 +37,6 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "llvm/Support/Debug.h"
 
-#define DEBUG_TYPE "gcdasyncsemaphorechecker"
-
 using namespace clang;
 using namespace ento;
 using namespace ast_matchers;
@@ -47,7 +45,7 @@ name

[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-12 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai marked 6 inline comments as done.
vsapsai added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:1798
+  // already done some merging. Either way, just merge into it.
+  if (Canon->DefinitionData && Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));

rsmith wrote:
> `Canon->DefinitionData` can't be null here, so the first half of this check 
> is redundant. If you're concerned about that, you can add an assert that it's 
> equal to `D->DefinitionData` (and that both are non-null).
`MergeDefinitionData` already has assertion `Canon->DefinitionData` is not null 
so adding assertion here doesn't add safety. And I don't think it would improve 
readability or make it easier to understand the code.


https://reviews.llvm.org/D43494



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


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-12 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

Yes I do ☺ thanks.


https://reviews.llvm.org/D44069



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-12 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 138059.
vsapsai added a comment.

- Some more cleanup. NFC.


https://reviews.llvm.org/D43494

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/self-referencing-lambda/a.h
  clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
  clang/test/Modules/self-referencing-lambda.cpp


Index: clang/test/Modules/self-referencing-lambda.cpp
===
--- /dev/null
+++ clang/test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I 
%S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: clang/test/Modules/Inputs/self-referencing-lambda/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1782,29 +1782,31 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  if (!Canon->DefinitionData)
+Canon->DefinitionData = DD;
+  D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D);
 
-  // We might already have a definition for this record. This can happen either
-  // because we're reading an update record, or because we've already done some
-  // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  // We might already have a different definition for this record. This can
+  // happen either because we're reading an update record, or because we've
+  // already done some merging. Either way, just merge into it.
+  if (Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));
-D->DefinitionData = Canon->DefinitionData;
 return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
   // DefinitionData pointer onto them.
-  if (Update || Canon != D) {
-Canon->DefinitionData = D->DefinitionData;
+  if (Update || Canon != D)
 Reader.PendingDefinitions.insert(D);
-  }
 }
 
 ASTDeclReader::RedeclarableResult


Index: clang/test/Modules/self-referencing-lambda.cpp
===
--- /dev/null
+++ clang/test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: clang/test/Modules/Inputs/self-referencing-lambda/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1782,29 +1782,31 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  if (!Canon->DefinitionData)
+Canon->DefinitionData = DD;
+  D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D);
 
-  // We might already have a definition for this record. This can happen either
-  // because we're reading an update record, or because we've already done some
-  // m

[libcxx] r327304 - [libcxx][test] Adding apple-clang-9 to UNSUPPORTED in iter_alloc_deduction.fail.cpp.

2018-03-12 Thread Mike Edwards via cfe-commits
Author: sqlbyme
Date: Mon Mar 12 11:06:37 2018
New Revision: 327304

URL: http://llvm.org/viewvc/llvm-project?rev=327304&view=rev
Log:
[libcxx][test] Adding apple-clang-9 to UNSUPPORTED in 
iter_alloc_deduction.fail.cpp.


After two failed attempts last week to make this work I am
going back to a known good method of making this test pass on
macOS...adding the current apple-clang version to the
UNSUPPORTED list.

During a previous patch review (https://reviews.llvm.org/D44103)
it was suggested to just XFAIL libcpp-no-deduction-guides
as was done to iter_alloc_deduction.pass.cpp. However
this caused a an unexpected pass on:
http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-gcc-tot-latest-std/builds/214

I then attempted to just mark libcpp-no-deduction-guides
as UNSUPPORTED, however this caused an additional bot
failure.  So I reverted everything (https://reviews.llvm.org/rCXX327191).

To solve this and get work unblocked I am adding
apple-clang-9 to the original UNSUPPORTED list.


Modified:

libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp?rev=327304&r1=327303&r2=327304&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc_deduction.fail.cpp
 Mon Mar 12 11:06:37 2018
@@ -10,7 +10,7 @@
 // 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8, clang-3.9, clang-4.0
-// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
+// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0, apple-clang-9
 
 // template::value_type>>


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


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

The new changes look fine. Do you need someone to commit this for you?


https://reviews.llvm.org/D44069



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


RE: r326946 - CodeGen: Fix address space of indirect function argument

2018-03-12 Thread Liu, Yaxun (Sam) via cfe-commits
I will try implementing John's suggestions. Thanks.

Sam

From: rjmcc...@apple.com [mailto:rjmcc...@apple.com]
Sent: Saturday, March 10, 2018 12:14 PM
To: Richard Smith 
Cc: Liu, Yaxun (Sam) ; cfe-commits 

Subject: Re: r326946 - CodeGen: Fix address space of indirect function argument

On Mar 9, 2018, at 8:51 PM, Richard Smith 
mailto:rich...@metafoo.co.uk>> wrote:

Hi,

This change increases the size of a CallArg, and thus that of a CallArgList, 
dramatically (an LValue is *much* larger than an RValue, and unlike an RValue, 
does not appear to be at all optimized for size). This results in CallArgList 
(which contains inline storage for 16 CallArgs) ballooning in size from ~500 
bytes to 2KB, resulting in stack overflows on programs with deep ASTs.

Given that this introduces a regression (due to stack overflow), I've reverted 
in r327195. Sorry about that.

Seems reasonable.

The right short-term fix is probably a combination of the following:
  - put a little bit of effort into packing LValue (using fewer than 64 bits 
for the alignment and packing the bit-fields, I think)
  - drop the inline argument count to something like 8, which should still 
capture the vast majority of calls.

There are quite a few other space optimizations we could do the LValue 
afterwards.   I think we could eliminate BaseIVarExp completely by storing some 
sort of ObjC GC classification and then just evaluating the base expression 
normally.


The program it broke looked something like this:

struct VectorBuilder {
  VectorBuilder &operator,(int);
};
void f() {
  VectorBuilder(),
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,
  
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0;
}

using Eigen's somewhat-ridiculous comma initializer technique 
(https://eigen.tuxfamily.org/dox/group__TutorialAdvancedInitialization.html) to 
build an approx 40 x 40 array.

An AST 1600 levels deep is somewhat extreme, but it still seems like something 
we should be able to handle within our default 8MB stack limit.

I mean, at some point this really is not supportable, even if it happens to 
build on current compilers.  If we actually documented and enforced our 
implementation limits like we're supposed to, I do not think we would allow 
this much call nesting.

John.



On 7 March 2018 at 13:45, Yaxun Liu via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: yaxunl
Date: Wed Mar  7 13:45:40 2

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
Thanks a lot Akira!

FWIW, it seems that the FIXME here might be related
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/DeclCXX.h#L1484

On Mon, Mar 12, 2018 at 6:03 PM Akira Hatanaka  wrote:

> I’m not sure if this a bug r327206 introduced or an existing bug in
> ASTImporter as there are other bits in RecordDecl that are not copied, but
> I think I should revert the patch for now.
>
> On Mar 12, 2018, at 9:57 AM, Eric Liu  wrote:
>
> I think it's likely as our tests only fail with module enabled (without
> module, ASTImporter isn't really used).
>
> On Mon, Mar 12, 2018 at 5:51 PM Akira Hatanaka 
> wrote:
>
>> The patch I committed moved CXXRecordDecl::CanPassInRegisters to
>> RecordDecl. It looks like ASTImporter::ImportDefinition no longer copies
>> the bit for CanPassInRegisters after that change. I’m not sure that is
>> what’s causing tests to fail.
>>
>> On Mar 12, 2018, at 9:29 AM, Eric Liu  wrote:
>>
>> I have been trying to reduce a reproducer for this but haven't gotten any
>> luck yet. The error happens in conversion between different version of STL
>> containers and is a bit hard to reduce. I'll keep trying to create a
>> reproducer.
>>
>> Could you please also take a quick look to see if
>> ASTImporter/Reader/Writer is actually missing something?
>>
>> Thanks,
>> Eric
>>
>> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka 
>> wrote:
>>
>>> Do you have a reproducer?
>>>
>>>
>>> On Mar 12, 2018, at 9:07 AM, Eric Liu  wrote:
>>>
>>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not
>>> sure what's the right way to fix it. I'll revert this commit for now to
>>> unblock integration. Let me know if you need more information from us.
>>>
>>> Regards,
>>> Eric
>>>
>>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  wrote:
>>>
 The tests only failed with module enabled. FWIW, I think the change in
 ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk)
 needs additional changes to make imports work for RecordDecl.

 On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  wrote:

> Hi Akira,
>
> It seems that this commit also changes behavior for compiling C++ code
> as we are seeing test failures caused by this change in our internal 
> tests.
>
> I'm still trying to reduce a reproducer for the failure. In the
> meantime, could you please double check if this affects C++?
>
> Thanks,
> Eric
>
> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ahatanak
>> Date: Fri Mar  9 22:36:08 2018
>> New Revision: 327206
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
>> Log:
>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>>
>> This patch uses the infrastructure added in r326307 for enabling
>> non-trivial fields to be declared in C structs to allow __weak fields
>> in
>> C structs in ARC.
>>
>> rdar://problem/33599681
>>
>> Differential Revision: https://reviews.llvm.org/D44095
>>
>> Added:
>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/include/clang/AST/DeclCXX.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/ASTImporter.cpp
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/DeclCXX.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>>
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>bool NonTrivialToPrimitiveCopy : 1;
>>bool NonTrivialToPrimitiveDestroy : 1;
>>
>> +  /// True if this class can be passed in a non-address-preserving
>> fashion
>> +  /// (such as in registers).
>> +  /// This does not imply anything about how the ABI in use will
>> actually
>> +  /// pass an object of this class.
>> +  bool CanPassInRegisters : 1;
>> +
>>  protected:
>>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, 

[PATCH] D41102: Setup clang-doc frontend framework

2018-03-12 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D41102#1034919, @lebedev.ri wrote:

> Since the commit was reverted, did you mean to either recommit it, or reopen 
> this (with updated diff), so it does not get lost?


Relanded in r327295.




Comment at: clang-doc/BitcodeWriter.h:154
+  ClangDocBitcodeWriter(llvm::BitstreamWriter &Stream,
+bool OmitFilenames = false)
+  : Stream(Stream), OmitFilenames(OmitFilenames) {

sammccall wrote:
> Hmm, you spend a lot of effort plumbing this variable around! Why is it so 
> important?
> Filesize? (I'm not that familiar with LLVM bitcode, but surely we'll end up 
> with a string table anyway?)
> 
> If it really is an important option people will want, the command-line arg 
> should probably say why.
It was for testing purposes (so that the tests aren't flaky on filenames), but 
I replaced it with regex.



Comment at: clang-doc/BitcodeWriter.h:241
+/// \param I The info to emit to bitcode.
+template  void ClangDocBitcodeWriter::emitBlock(const T &I) {
+  StreamSubBlockGuard Block(Stream, MapFromInfoToBlockId::ID);

lebedev.ri wrote:
> sammccall wrote:
> > OK, I don't get this at all.
> > 
> > We have to declare emitBlockContent(NamespaceInfo) *and* the specialization 
> > of MapFromInfoToBlockId, and deal with the public interface 
> > emitBlock being a template function where you can't tell what's legal to 
> > pass, instead of writing:
> > 
> > ```void emitBlock(const NamespaceInfo &I) {
> >   SubStreamBlockGuard Block(Stream, BI_NAMESPACE_BLOCK_ID); // <-- this one 
> > line
> >   ...
> > }```
> > 
> > This really seems like templates for the sake of templates :(
> If you want to add a new block, in one case you just need to add one
> ```
> template <> struct MapFromInfoToBlockId {
>   static const BlockId ID = BI_???_BLOCK_ID;
> };
> ```
> In the other case you need to add whole
> ```
> void ClangDocBitcodeWriter::emitBlock(const ???Info &I) {
>   StreamSubBlockGuard Block(Stream, BI_???_BLOCK_ID);
>   emitBlockContent(I);
> }
> ```
> (and it was even longer initially)
> It seems just templating one static variable is shorter than duplicating 
> `emitBlock()` each time, no?
> 
> Do compare the current diff with the original diff state.
> I *think* these templates helped move much of the duplication to simplify the 
> code overall.
You'd still have to add the appropriate `emitBlock()` function for any new 
block, since it would have different attributes. 



Comment at: clang-doc/Mapper.cpp:33
+  ECtx->reportResult(llvm::toHex(llvm::toStringRef(serialize::hashUSR(USR))),
+ serialize::emitInfo(D, getComment(D, D->getASTContext()),
+ getLine(D, D->getASTContext()),

sammccall wrote:
> It seems a bit of a poor fit to use a complete bitcode file (header, version, 
> block info) as your value format when you know the format, and know there'll 
> be no version skew.
> Is it easy just to emit the block we care about?
Ideally, yes, but right now in the clang BitstreamWriter there's no way to tell 
the instance what all the abbreviations are without also emitting the blockinfo 
to the output stream, though I'm thinking about taking a stab at separating the 
two. 

Also, this relies on the llvm-bcanalyzer for testing, which requires both the 
header and the blockinfo in order to read the data :/


Repository:
  rL LLVM

https://reviews.llvm.org/D41102



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


[clang-tools-extra] r327295 - Reland "[clang-doc] Setup clang-doc frontend framework"

2018-03-12 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Mar 12 10:05:14 2018
New Revision: 327295

URL: http://llvm.org/viewvc/llvm-project?rev=327295&view=rev
Log:
Reland "[clang-doc] Setup clang-doc frontend framework"

There was a missing newline in the docs, and a static_assert that needed
to be a normal assert.

Added:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/docs/clang-doc.rst
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=327295&r1=327294&r2=327295&view=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Mon Mar 12 10:05:14 2018
@@ -7,6 +7,7 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
+add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Added: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=327295&view=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Mar 12 10:05:14 2018
@@ -0,0 +1,515 @@
+//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "BitcodeWriter.h"
+#include "llvm/ADT/IndexedMap.h"
+
+namespace clang {
+namespace doc {
+
+// Since id enums are not zero-indexed, we need to transform the given id into
+// its associated index.
+struct BlockIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
+};
+
+struct RecordIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
+};
+
+using AbbrevDsc = void (*)(std::shared_ptr &Abbrev);
+
+static void AbbrevGen(std::shared_ptr &Abbrev,
+  const std::initializer_list Ops) {
+  for (const auto &Op : Ops)
+Abbrev->Add(Op);
+}
+
+static void BoolAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Boolean
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::BoolSize)});
+}
+
+static void IntAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::IntSize)});
+}
+
+static void SymbolIDAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the sha1'd USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRLengthSize),
+ // 1. Fixed-size array of Char6 (USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::USRBitLengthSize)});
+}
+
+static void StringAbbrev(std::shared_ptr &Abbrev) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the following string)
+ llvm::BitCodeAbbrevOp(llvm::BitCo

r327294 - Revert "[ObjC] Allow declaring __weak pointer fields in C structs in

2018-03-12 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Mar 12 10:05:06 2018
New Revision: 327294

URL: http://llvm.org/viewvc/llvm-project?rev=327294&view=rev
Log:
Revert "[ObjC] Allow declaring __weak pointer fields in C structs in
ARC."

This reverts commit r327206 as there were test failures caused by this
patch.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180312/221427.html

Removed:
cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Mar 12 10:05:06 2018
@@ -3553,12 +3553,6 @@ class RecordDecl : public TagDecl {
   bool NonTrivialToPrimitiveCopy : 1;
   bool NonTrivialToPrimitiveDestroy : 1;
 
-  /// True if this class can be passed in a non-address-preserving fashion
-  /// (such as in registers).
-  /// This does not imply anything about how the ABI in use will actually
-  /// pass an object of this class.
-  bool CanPassInRegisters : 1;
-
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3642,18 +3636,6 @@ public:
 NonTrivialToPrimitiveDestroy = true;
   }
 
-  /// Determine whether this class can be passed in registers. In C++ mode,
-  /// it must have at least one trivial, non-deleted copy or move constructor.
-  /// FIXME: This should be set as part of completeDefinition.
-  bool canPassInRegisters() const {
-return CanPassInRegisters;
-  }
-
-  /// Set that we can pass this RecordDecl in registers.
-  void setCanPassInRegisters(bool CanPass) {
-CanPassInRegisters = CanPass;
-  }
-
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Mar 12 10:05:06 2018
@@ -467,6 +467,12 @@ class CXXRecordDecl : public RecordDecl
 /// constructor.
 unsigned HasDefaultedDefaultConstructor : 1;
 
+/// \brief True if this class can be passed in a non-address-preserving
+/// fashion (such as in registers) according to the C++ language rules.
+/// This does not imply anything about how the ABI in use will actually
+/// pass an object of this class.
+unsigned CanPassInRegisters : 1;
+
 /// \brief True if a defaulted default constructor for this class would
 /// be constexpr.
 unsigned DefaultedDefaultConstructorIsConstexpr : 1;
@@ -1468,6 +1474,18 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
+  /// \brief Determine whether this class has at least one trivial, non-deleted
+  /// copy or move constructor.
+  bool canPassInRegisters() const {
+return data().CanPassInRegisters;
+  }
+
+  /// \brief Set that we can pass this RecordDecl in registers.
+  // FIXME: This should be set as part of completeDefinition.
+  void setCanPassInRegisters(bool CanPass) {
+data().CanPassInRegisters = CanPass;
+  }
+
   /// Determine whether the triviality for the purpose of calls for this class
   /// is overridden to be trivial because this class or the type of one of its
   /// subobjects has attribute "trivial_abi".

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Mar 12 10:05:06 2018
@@ -1097,10 +1097,6 @@ public:
 /// with the ARC __strong qualifier.
 PDIK_ARCStrong,
 
-/// The type is an Objective-C retainable pointer type that is qualified
-/// with the ARC __weak qualifier.
-PDIK_A

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
I’m not sure if this a bug r327206 introduced or an existing bug in ASTImporter 
as there are other bits in RecordDecl that are not copied, but I think I should 
revert the patch for now.

> On Mar 12, 2018, at 9:57 AM, Eric Liu  wrote:
> 
> I think it's likely as our tests only fail with module enabled (without 
> module, ASTImporter isn't really used).
> 
> On Mon, Mar 12, 2018 at 5:51 PM Akira Hatanaka  > wrote:
> The patch I committed moved CXXRecordDecl::CanPassInRegisters to RecordDecl. 
> It looks like ASTImporter::ImportDefinition no longer copies the bit for 
> CanPassInRegisters after that change. I’m not sure that is what’s causing 
> tests to fail.
> 
>> On Mar 12, 2018, at 9:29 AM, Eric Liu > > wrote:
>> 
>> I have been trying to reduce a reproducer for this but haven't gotten any 
>> luck yet. The error happens in conversion between different version of STL 
>> containers and is a bit hard to reduce. I'll keep trying to create a 
>> reproducer.
>> 
>> Could you please also take a quick look to see if ASTImporter/Reader/Writer 
>> is actually missing something?
>> 
>> Thanks,
>> Eric
>> 
>> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka > > wrote:
>> Do you have a reproducer?
>> 
>> 
>>> On Mar 12, 2018, at 9:07 AM, Eric Liu >> > wrote:
>>> 
>>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
>>> what's the right way to fix it. I'll revert this commit for now to unblock 
>>> integration. Let me know if you need more information from us.
>>> 
>>> Regards,
>>> Eric
>>> 
>>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu >> > wrote:
>>> The tests only failed with module enabled. FWIW, I think the change in 
>>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
>>> ) needs additional 
>>> changes to make imports work for RecordDecl. 
>>> 
>>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu >> > wrote:
>>> Hi Akira,
>>> 
>>> It seems that this commit also changes behavior for compiling C++ code as 
>>> we are seeing test failures caused by this change in our internal tests.
>>> 
>>> I'm still trying to reduce a reproducer for the failure. In the meantime, 
>>> could you please double check if this affects C++?
>>> 
>>> Thanks,
>>> Eric
>>> 
>>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> Author: ahatanak
>>> Date: Fri Mar  9 22:36:08 2018
>>> New Revision: 327206
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
>>> 
>>> Log:
>>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>>> 
>>> This patch uses the infrastructure added in r326307 for enabling
>>> non-trivial fields to be declared in C structs to allow __weak fields in
>>> C structs in ARC.
>>> 
>>> rdar://problem/33599681 <>
>>> 
>>> Differential Revision: https://reviews.llvm.org/D44095 
>>> 
>>> 
>>> Added:
>>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>>> Modified:
>>> cfe/trunk/include/clang/AST/Decl.h
>>> cfe/trunk/include/clang/AST/DeclCXX.h
>>> cfe/trunk/include/clang/AST/Type.h
>>> cfe/trunk/lib/AST/ASTImporter.cpp
>>> cfe/trunk/lib/AST/Decl.cpp
>>> cfe/trunk/lib/AST/DeclCXX.cpp
>>> cfe/trunk/lib/AST/Type.cpp
>>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>>> cfe/trunk/lib/Sema/SemaDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>>> 
>>> Modified: cfe/trunk/include/clang/AST/Decl.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>>  
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>>bool NonTrivialToPrimitiveCopy : 1;
>>>bool NonTrivialToPrimitiveDestroy : 1;
>>> 
>>> +  /// True if this class can be passed in a non-address-preserving fashion
>>> +  /// (such as in registers).
>>> +  /// This does not imply anything about how the ABI in use will actually
>>> +  /// pass an object of this class.
>>> +  bool CanPassInRegisters : 1;
>>> +
>>>  protected:
>>>RecordDecl(Kind DK

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
I think it's likely as our tests only fail with module enabled (without
module, ASTImporter isn't really used).

On Mon, Mar 12, 2018 at 5:51 PM Akira Hatanaka  wrote:

> The patch I committed moved CXXRecordDecl::CanPassInRegisters to
> RecordDecl. It looks like ASTImporter::ImportDefinition no longer copies
> the bit for CanPassInRegisters after that change. I’m not sure that is
> what’s causing tests to fail.
>
> On Mar 12, 2018, at 9:29 AM, Eric Liu  wrote:
>
> I have been trying to reduce a reproducer for this but haven't gotten any
> luck yet. The error happens in conversion between different version of STL
> containers and is a bit hard to reduce. I'll keep trying to create a
> reproducer.
>
> Could you please also take a quick look to see if
> ASTImporter/Reader/Writer is actually missing something?
>
> Thanks,
> Eric
>
> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka 
> wrote:
>
>> Do you have a reproducer?
>>
>>
>> On Mar 12, 2018, at 9:07 AM, Eric Liu  wrote:
>>
>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure
>> what's the right way to fix it. I'll revert this commit for now to unblock
>> integration. Let me know if you need more information from us.
>>
>> Regards,
>> Eric
>>
>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  wrote:
>>
>>> The tests only failed with module enabled. FWIW, I think the change in
>>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk)
>>> needs additional changes to make imports work for RecordDecl.
>>>
>>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  wrote:
>>>
 Hi Akira,

 It seems that this commit also changes behavior for compiling C++ code
 as we are seeing test failures caused by this change in our internal tests.

 I'm still trying to reduce a reproducer for the failure. In the
 meantime, could you please double check if this affects C++?

 Thanks,
 Eric

 On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Author: ahatanak
> Date: Fri Mar  9 22:36:08 2018
> New Revision: 327206
>
> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
> Log:
> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>
> This patch uses the infrastructure added in r326307 for enabling
> non-trivial fields to be declared in C structs to allow __weak fields
> in
> C structs in ARC.
>
> rdar://problem/33599681
>
> Differential Revision: https://reviews.llvm.org/D44095
>
> Added:
> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/DeclCXX.h
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/DeclCXX.cpp
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CGBlocks.cpp
> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
> cfe/trunk/lib/CodeGen/CGObjC.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>bool NonTrivialToPrimitiveCopy : 1;
>bool NonTrivialToPrimitiveDestroy : 1;
>
> +  /// True if this class can be passed in a non-address-preserving
> fashion
> +  /// (such as in registers).
> +  /// This does not imply anything about how the ABI in use will
> actually
> +  /// pass an object of this class.
> +  bool CanPassInRegisters : 1;
> +
>  protected:
>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext
> *DC,
>   SourceLocation StartLoc, SourceLocation IdLoc,
> @@ -3636,6 +3642,18 @@ public:
>  NonTrivialToPrimitiveDestroy = true;
>}
>
> +  /// Determine whether this class can be passed in registers. In C++
> mode,
> +  /// it must have at least one trivial, non-deleted copy or move
> constructor.
> +  /// FIXME: This should be set as part of completeDefinition.
> +  bool canPassInRegisters() const {
> +return CanPassInRegisters;
> +  }
> +
> +  /// Set that we can pass this Record

[clang-tools-extra] r327293 - [clangd] Fix diagnostic errors in the test code, NFC.

2018-03-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Mar 12 09:49:24 2018
New Revision: 327293

URL: http://llvm.org/viewvc/llvm-project?rev=327293&view=rev
Log:
[clangd] Fix diagnostic errors in the test code, NFC.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, ioeric

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

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

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=327293&r1=327292&r2=327293&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Mon Mar 12 09:49:24 
2018
@@ -596,7 +596,9 @@ TEST(GoToInclude, All) {
   auto FooH = testPath("foo.h");
   auto FooHUri = URIForFile{FooH};
 
-  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  const char *HeaderContents = R"cpp([[]]#pragma once
+ int a;
+ )cpp";
   Annotations HeaderAnnotations(HeaderContents);
   FS.Files[FooH] = HeaderAnnotations.code();
 


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


[PATCH] D44294: [clangd] Fix diagnostic errors in the test code, NFC.

2018-03-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE327293: [clangd] Fix diagnostic errors in the test code, 
NFC. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44294?vs=137712&id=138039#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44294

Files:
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -596,7 +596,9 @@
   auto FooH = testPath("foo.h");
   auto FooHUri = URIForFile{FooH};
 
-  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  const char *HeaderContents = R"cpp([[]]#pragma once
+ int a;
+ )cpp";
   Annotations HeaderAnnotations(HeaderContents);
   FS.Files[FooH] = HeaderAnnotations.code();
 


Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -596,7 +596,9 @@
   auto FooH = testPath("foo.h");
   auto FooHUri = URIForFile{FooH};
 
-  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  const char *HeaderContents = R"cpp([[]]#pragma once
+ int a;
+ )cpp";
   Annotations HeaderAnnotations(HeaderContents);
   FS.Files[FooH] = HeaderAnnotations.code();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
The patch I committed moved CXXRecordDecl::CanPassInRegisters to RecordDecl. It 
looks like ASTImporter::ImportDefinition no longer copies the bit for 
CanPassInRegisters after that change. I’m not sure that is what’s causing tests 
to fail.

> On Mar 12, 2018, at 9:29 AM, Eric Liu  wrote:
> 
> I have been trying to reduce a reproducer for this but haven't gotten any 
> luck yet. The error happens in conversion between different version of STL 
> containers and is a bit hard to reduce. I'll keep trying to create a 
> reproducer.
> 
> Could you please also take a quick look to see if ASTImporter/Reader/Writer 
> is actually missing something?
> 
> Thanks,
> Eric
> 
> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka  > wrote:
> Do you have a reproducer?
> 
> 
>> On Mar 12, 2018, at 9:07 AM, Eric Liu > > wrote:
>> 
>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
>> what's the right way to fix it. I'll revert this commit for now to unblock 
>> integration. Let me know if you need more information from us.
>> 
>> Regards,
>> Eric
>> 
>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu > > wrote:
>> The tests only failed with module enabled. FWIW, I think the change in 
>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
>> ) needs additional 
>> changes to make imports work for RecordDecl. 
>> 
>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu > > wrote:
>> Hi Akira,
>> 
>> It seems that this commit also changes behavior for compiling C++ code as we 
>> are seeing test failures caused by this change in our internal tests.
>> 
>> I'm still trying to reduce a reproducer for the failure. In the meantime, 
>> could you please double check if this affects C++?
>> 
>> Thanks,
>> Eric
>> 
>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: ahatanak
>> Date: Fri Mar  9 22:36:08 2018
>> New Revision: 327206
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
>> 
>> Log:
>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>> 
>> This patch uses the infrastructure added in r326307 for enabling
>> non-trivial fields to be declared in C structs to allow __weak fields in
>> C structs in ARC.
>> 
>> rdar://problem/33599681 <>
>> 
>> Differential Revision: https://reviews.llvm.org/D44095 
>> 
>> 
>> Added:
>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/include/clang/AST/DeclCXX.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/ASTImporter.cpp
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/DeclCXX.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>> 
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>  
>> 
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>bool NonTrivialToPrimitiveCopy : 1;
>>bool NonTrivialToPrimitiveDestroy : 1;
>> 
>> +  /// True if this class can be passed in a non-address-preserving fashion
>> +  /// (such as in registers).
>> +  /// This does not imply anything about how the ABI in use will actually
>> +  /// pass an object of this class.
>> +  bool CanPassInRegisters : 1;
>> +
>>  protected:
>>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>>   SourceLocation StartLoc, SourceLocation IdLoc,
>> @@ -3636,6 +3642,18 @@ public:
>>  NonTrivialToPrimitiveDestroy = true;
>>}
>> 
>> +  /// Determine whether this class can be passed in registers. In C++ mode,
>> +  /// it must have at least one trivial, non-deleted copy or move 
>> constructor.
>> +  /// FIXME: This should be set as part of completeDefinition.
>> +  bool canPassInRegisters() const {
>> +return CanPassInRegisters;
>> +  }
>> +
>> +  /// Set that we can pass this RecordDecl in registers.
>> + 

[PATCH] D44293: [clangd] Fix irrelevant declaratations in goto definition (on macros).

2018-03-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/XRefs.cpp:201
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
+  if (!MacroInfos.empty()) {
+for (auto Item : MacroInfos) {

ilya-biryukov wrote:
> I wonder whether we should fix the `DeclrationAndMacrosFinder` to not return 
> declarations coming from macro instantiations instead.
> There are other clients (e.g. document highlights) that will probably break 
> in the same way.
> 
> Do you think it would be possible and it would make sense for 
> `DeclrationAndMacrosFinder` to only return a macro in this case and not 
> return Decls coming from macro expansions?
I thought about it initially, but the information provided 
`handleDeclOccurrence` is limited...the occurrence location (`FID` and 
`Offset`) is expansion location (which is not always we want). That being said, 
when GoToDefinition on a macro, all declarations inside the macro body will be 
picked up.

In document hover implementation, we also use the same mechanism to avoid this 
problem :(



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44293



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-03-12 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Since the commit was reverted, did you mean to either recommit it, or reopen 
this (with updated diff), so it does not get lost?


Repository:
  rL LLVM

https://reviews.llvm.org/D41102



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


Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
I have been trying to reduce a reproducer for this but haven't gotten any
luck yet. The error happens in conversion between different version of STL
containers and is a bit hard to reduce. I'll keep trying to create a
reproducer.

Could you please also take a quick look to see if ASTImporter/Reader/Writer
is actually missing something?

Thanks,
Eric

On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka  wrote:

> Do you have a reproducer?
>
>
> On Mar 12, 2018, at 9:07 AM, Eric Liu  wrote:
>
> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure
> what's the right way to fix it. I'll revert this commit for now to unblock
> integration. Let me know if you need more information from us.
>
> Regards,
> Eric
>
> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  wrote:
>
>> The tests only failed with module enabled. FWIW, I think the change in
>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk)
>> needs additional changes to make imports work for RecordDecl.
>>
>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  wrote:
>>
>>> Hi Akira,
>>>
>>> It seems that this commit also changes behavior for compiling C++ code
>>> as we are seeing test failures caused by this change in our internal tests.
>>>
>>> I'm still trying to reduce a reproducer for the failure. In the
>>> meantime, could you please double check if this affects C++?
>>>
>>> Thanks,
>>> Eric
>>>
>>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: ahatanak
 Date: Fri Mar  9 22:36:08 2018
 New Revision: 327206

 URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
 Log:
 [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

 This patch uses the infrastructure added in r326307 for enabling
 non-trivial fields to be declared in C structs to allow __weak fields in
 C structs in ARC.

 rdar://problem/33599681

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

 Added:
 cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
 Modified:
 cfe/trunk/include/clang/AST/Decl.h
 cfe/trunk/include/clang/AST/DeclCXX.h
 cfe/trunk/include/clang/AST/Type.h
 cfe/trunk/lib/AST/ASTImporter.cpp
 cfe/trunk/lib/AST/Decl.cpp
 cfe/trunk/lib/AST/DeclCXX.cpp
 cfe/trunk/lib/AST/Type.cpp
 cfe/trunk/lib/CodeGen/CGBlocks.cpp
 cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
 cfe/trunk/lib/CodeGen/CGObjC.cpp
 cfe/trunk/lib/CodeGen/CodeGenFunction.h
 cfe/trunk/lib/CodeGen/TargetInfo.cpp
 cfe/trunk/lib/Sema/SemaDecl.cpp
 cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
 cfe/trunk/lib/Serialization/ASTWriter.cpp
 cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
 cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m

 Modified: cfe/trunk/include/clang/AST/Decl.h
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff

 ==
 --- cfe/trunk/include/clang/AST/Decl.h (original)
 +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
 @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
bool NonTrivialToPrimitiveCopy : 1;
bool NonTrivialToPrimitiveDestroy : 1;

 +  /// True if this class can be passed in a non-address-preserving
 fashion
 +  /// (such as in registers).
 +  /// This does not imply anything about how the ABI in use will
 actually
 +  /// pass an object of this class.
 +  bool CanPassInRegisters : 1;
 +
  protected:
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
   SourceLocation StartLoc, SourceLocation IdLoc,
 @@ -3636,6 +3642,18 @@ public:
  NonTrivialToPrimitiveDestroy = true;
}

 +  /// Determine whether this class can be passed in registers. In C++
 mode,
 +  /// it must have at least one trivial, non-deleted copy or move
 constructor.
 +  /// FIXME: This should be set as part of completeDefinition.
 +  bool canPassInRegisters() const {
 +return CanPassInRegisters;
 +  }
 +
 +  /// Set that we can pass this RecordDecl in registers.
 +  void setCanPassInRegisters(bool CanPass) {
 +CanPassInRegisters = CanPass;
 +  }
 +
/// \brief Determines whether this declaration represents the
/// injected class name.
///

 Modified: cfe/trunk/include/clang/AST/DeclCXX.h
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff

 ==
 --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
 +++ cfe/trunk/include/clang/A

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
Do you have a reproducer?

> On Mar 12, 2018, at 9:07 AM, Eric Liu  wrote:
> 
> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
> what's the right way to fix it. I'll revert this commit for now to unblock 
> integration. Let me know if you need more information from us.
> 
> Regards,
> Eric
> 
> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  > wrote:
> The tests only failed with module enabled. FWIW, I think the change in 
> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
> ) needs additional 
> changes to make imports work for RecordDecl. 
> 
> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  > wrote:
> Hi Akira,
> 
> It seems that this commit also changes behavior for compiling C++ code as we 
> are seeing test failures caused by this change in our internal tests.
> 
> I'm still trying to reduce a reproducer for the failure. In the meantime, 
> could you please double check if this affects C++?
> 
> Thanks,
> Eric
> 
> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: ahatanak
> Date: Fri Mar  9 22:36:08 2018
> New Revision: 327206
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
> 
> Log:
> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
> 
> This patch uses the infrastructure added in r326307 for enabling
> non-trivial fields to be declared in C structs to allow __weak fields in
> C structs in ARC.
> 
> rdar://problem/33599681
> 
> Differential Revision: https://reviews.llvm.org/D44095 
> 
> 
> Added:
> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/DeclCXX.h
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/DeclCXX.cpp
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CGBlocks.cpp
> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
> cfe/trunk/lib/CodeGen/CGObjC.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
> 
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>bool NonTrivialToPrimitiveCopy : 1;
>bool NonTrivialToPrimitiveDestroy : 1;
> 
> +  /// True if this class can be passed in a non-address-preserving fashion
> +  /// (such as in registers).
> +  /// This does not imply anything about how the ABI in use will actually
> +  /// pass an object of this class.
> +  bool CanPassInRegisters : 1;
> +
>  protected:
>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>   SourceLocation StartLoc, SourceLocation IdLoc,
> @@ -3636,6 +3642,18 @@ public:
>  NonTrivialToPrimitiveDestroy = true;
>}
> 
> +  /// Determine whether this class can be passed in registers. In C++ mode,
> +  /// it must have at least one trivial, non-deleted copy or move 
> constructor.
> +  /// FIXME: This should be set as part of completeDefinition.
> +  bool canPassInRegisters() const {
> +return CanPassInRegisters;
> +  }
> +
> +  /// Set that we can pass this RecordDecl in registers.
> +  void setCanPassInRegisters(bool CanPass) {
> +CanPassInRegisters = CanPass;
> +  }
> +
>/// \brief Determines whether this declaration represents the
>/// injected class name.
>///
> 
> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018
> @@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
>  /// constructor.
>  unsigned HasDefaultedDefaultConstructor : 1;
> 
> -/// \brief True if this class can be passed in a no

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure
what's the right way to fix it. I'll revert this commit for now to unblock
integration. Let me know if you need more information from us.

Regards,
Eric

On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  wrote:

> The tests only failed with module enabled. FWIW, I think the change in
> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk) needs
> additional changes to make imports work for RecordDecl.
>
> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  wrote:
>
>> Hi Akira,
>>
>> It seems that this commit also changes behavior for compiling C++ code as
>> we are seeing test failures caused by this change in our internal tests.
>>
>> I'm still trying to reduce a reproducer for the failure. In the meantime,
>> could you please double check if this affects C++?
>>
>> Thanks,
>> Eric
>>
>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ahatanak
>>> Date: Fri Mar  9 22:36:08 2018
>>> New Revision: 327206
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
>>> Log:
>>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>>>
>>> This patch uses the infrastructure added in r326307 for enabling
>>> non-trivial fields to be declared in C structs to allow __weak fields in
>>> C structs in ARC.
>>>
>>> rdar://problem/33599681
>>>
>>> Differential Revision: https://reviews.llvm.org/D44095
>>>
>>> Added:
>>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>>> Modified:
>>> cfe/trunk/include/clang/AST/Decl.h
>>> cfe/trunk/include/clang/AST/DeclCXX.h
>>> cfe/trunk/include/clang/AST/Type.h
>>> cfe/trunk/lib/AST/ASTImporter.cpp
>>> cfe/trunk/lib/AST/Decl.cpp
>>> cfe/trunk/lib/AST/DeclCXX.cpp
>>> cfe/trunk/lib/AST/Type.cpp
>>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>>> cfe/trunk/lib/Sema/SemaDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>>>
>>> Modified: cfe/trunk/include/clang/AST/Decl.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>>bool NonTrivialToPrimitiveCopy : 1;
>>>bool NonTrivialToPrimitiveDestroy : 1;
>>>
>>> +  /// True if this class can be passed in a non-address-preserving
>>> fashion
>>> +  /// (such as in registers).
>>> +  /// This does not imply anything about how the ABI in use will
>>> actually
>>> +  /// pass an object of this class.
>>> +  bool CanPassInRegisters : 1;
>>> +
>>>  protected:
>>>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>>>   SourceLocation StartLoc, SourceLocation IdLoc,
>>> @@ -3636,6 +3642,18 @@ public:
>>>  NonTrivialToPrimitiveDestroy = true;
>>>}
>>>
>>> +  /// Determine whether this class can be passed in registers. In C++
>>> mode,
>>> +  /// it must have at least one trivial, non-deleted copy or move
>>> constructor.
>>> +  /// FIXME: This should be set as part of completeDefinition.
>>> +  bool canPassInRegisters() const {
>>> +return CanPassInRegisters;
>>> +  }
>>> +
>>> +  /// Set that we can pass this RecordDecl in registers.
>>> +  void setCanPassInRegisters(bool CanPass) {
>>> +CanPassInRegisters = CanPass;
>>> +  }
>>> +
>>>/// \brief Determines whether this declaration represents the
>>>/// injected class name.
>>>///
>>>
>>> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
>>> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018
>>> @@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
>>>  /// constructor.
>>>  unsigned HasDefaultedDefaultConstructor : 1;
>>>
>>> -/// \brief True if this class can be passed in a
>>> non-address-preserving
>>> -/// fashion (such as in registers) according to the C++ language
>>> rules.
>>> -/// This does not imply anything about how the ABI in use will
>>> actually
>>> -/// pass an object of this class.
>>> -unsigned CanPassInRegisters : 1;
>>> -
>>>  /// \brief True if a defaulted default constructor for this class
>>> wo

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
The tests only failed with module enabled. FWIW, I think the change in
ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk) needs
additional changes to make imports work for RecordDecl.

On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  wrote:

> Hi Akira,
>
> It seems that this commit also changes behavior for compiling C++ code as
> we are seeing test failures caused by this change in our internal tests.
>
> I'm still trying to reduce a reproducer for the failure. In the meantime,
> could you please double check if this affects C++?
>
> Thanks,
> Eric
>
> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ahatanak
>> Date: Fri Mar  9 22:36:08 2018
>> New Revision: 327206
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
>> Log:
>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>>
>> This patch uses the infrastructure added in r326307 for enabling
>> non-trivial fields to be declared in C structs to allow __weak fields in
>> C structs in ARC.
>>
>> rdar://problem/33599681
>>
>> Differential Revision: https://reviews.llvm.org/D44095
>>
>> Added:
>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/include/clang/AST/DeclCXX.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/ASTImporter.cpp
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/DeclCXX.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>>
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>bool NonTrivialToPrimitiveCopy : 1;
>>bool NonTrivialToPrimitiveDestroy : 1;
>>
>> +  /// True if this class can be passed in a non-address-preserving
>> fashion
>> +  /// (such as in registers).
>> +  /// This does not imply anything about how the ABI in use will actually
>> +  /// pass an object of this class.
>> +  bool CanPassInRegisters : 1;
>> +
>>  protected:
>>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>>   SourceLocation StartLoc, SourceLocation IdLoc,
>> @@ -3636,6 +3642,18 @@ public:
>>  NonTrivialToPrimitiveDestroy = true;
>>}
>>
>> +  /// Determine whether this class can be passed in registers. In C++
>> mode,
>> +  /// it must have at least one trivial, non-deleted copy or move
>> constructor.
>> +  /// FIXME: This should be set as part of completeDefinition.
>> +  bool canPassInRegisters() const {
>> +return CanPassInRegisters;
>> +  }
>> +
>> +  /// Set that we can pass this RecordDecl in registers.
>> +  void setCanPassInRegisters(bool CanPass) {
>> +CanPassInRegisters = CanPass;
>> +  }
>> +
>>/// \brief Determines whether this declaration represents the
>>/// injected class name.
>>///
>>
>> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
>> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018
>> @@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
>>  /// constructor.
>>  unsigned HasDefaultedDefaultConstructor : 1;
>>
>> -/// \brief True if this class can be passed in a
>> non-address-preserving
>> -/// fashion (such as in registers) according to the C++ language
>> rules.
>> -/// This does not imply anything about how the ABI in use will
>> actually
>> -/// pass an object of this class.
>> -unsigned CanPassInRegisters : 1;
>> -
>>  /// \brief True if a defaulted default constructor for this class
>> would
>>  /// be constexpr.
>>  unsigned DefaultedDefaultConstructorIsConstexpr : 1;
>> @@ -1474,18 +1468,6 @@ public:
>>  return data().HasIrrelevantDestructor;
>>}
>>
>> -  /// \brief Determine whether this class has at least one trivial,
>> non-deleted
>> -  /// copy or move constructor.
>> -  bool canPassInRegisters() const {
>> -return data().CanPassInRegisters;
>> -  }
>> -
>> -  /

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-12 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
benhamilton marked an inline comment as done.
Closed by commit rC327285: [clang-format] Improve detection of Objective-C 
block types (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43906?vs=138024&id=138026#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43906

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


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -141,10 +141,7 @@
 Contexts.size() == 2 && Contexts[0].ColonIsForRangeExpr;
 
 bool StartsObjCMethodExpr = false;
-if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
-} else if (FormatToken *MaybeSel = Left->Previous) {
+if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&
   MaybeSel->Previous->is(tok::at)) {
@@ -210,8 +207,16 @@
   Left->Type = TT_ObjCMethodExpr;
 }
 
+// MightBeFunctionType and ProbablyFunctionType are used for
+// function pointer and reference types as well as Objective-C
+// block types:
+//
+// void (*FunctionPointer)(void);
+// void (&FunctionReference)(void);
+// void (^ObjCBlock)(void);
 bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
+bool ProbablyFunctionType =
+CurrentToken->isOneOf(tok::star, tok::amp, tok::caret);
 bool HasMultipleLines = false;
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
@@ -248,7 +253,8 @@
 if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next 
&&
 (CurrentToken->Next->is(tok::l_paren) ||
  (CurrentToken->Next->is(tok::l_square) && 
Line.MustBeDeclaration)))
-  Left->Type = TT_FunctionTypeLParen;
+  Left->Type = Left->Next->is(tok::caret) ? TT_ObjCBlockLParen
+  : TT_FunctionTypeLParen;
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
 
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[10])(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[kNumEntries])(char, float);"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -141,10 +141,7 @@
 Contexts.size() == 2 && Contexts[0].ColonIsForRangeExpr;
 
 bool StartsObjCMethodExpr = false;
-if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
-} else if (FormatToken *MaybeSel = Left->Previous) {
+if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous &&
   MaybeSel->Previous->is(tok::

[PATCH] D43902: [clang-format] Don't detect C++11 attribute specifiers as ObjC

2018-03-12 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327284: [clang-format] Don't detect C++11 attribute 
specifiers as ObjC (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43902?vs=137696&id=138025#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43902

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -29,7 +29,9 @@
 #define LIST_TOKEN_TYPES   \
   TYPE(ArrayInitializerLSquare)\
   TYPE(ArraySubscriptLSquare)  \
+  TYPE(AttributeColon) \
   TYPE(AttributeParen) \
+  TYPE(AttributeSquare)\
   TYPE(BinaryOperator) \
   TYPE(BitFieldColon)  \
   TYPE(BlockComment)   \
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -328,13 +328,40 @@
 return false;
   }
 
+  bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
+if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
+  return false;
+const FormatToken *AttrTok = Tok.Next->Next;
+if (!AttrTok)
+  return false;
+// C++17 '[[using ns: foo, bar(baz, blech)]]'
+// We assume nobody will name an ObjC variable 'using'.
+if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+  return true;
+if (AttrTok->isNot(tok::identifier))
+  return false;
+while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+  // ObjC message send. We assume nobody will use : in a C++11 attribute
+  // specifier parameter, although this is technically valid:
+  // [[foo(:)]]
+  if (AttrTok->is(tok::colon) ||
+  AttrTok->startsSequence(tok::identifier, tok::identifier))
+return false;
+  if (AttrTok->is(tok::ellipsis))
+return true;
+  AttrTok = AttrTok->Next;
+}
+return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+  }
+
   bool parseSquare() {
 if (!CurrentToken)
   return false;
 
 // A '[' could be an index subscript (after an identifier or after
 // ')' or ']'), it could be the start of an Objective-C method
-// expression, or it could the start of an Objective-C array literal.
+// expression, it could the start of an Objective-C array literal,
+// or it could be a C++ attribute specifier [[foo::bar]].
 FormatToken *Left = CurrentToken->Previous;
 Left->ParentBracket = Contexts.back().ContextKind;
 FormatToken *Parent = Left->getPreviousNonComment();
@@ -347,8 +374,11 @@
 (Contexts.back().CanBeExpression || Contexts.back().IsExpression ||
  Contexts.back().InTemplateArgument);
 
+bool IsCpp11AttributeSpecifier = isCpp11AttributeSpecifier(*Left) ||
+ Contexts.back().InCpp11AttributeSpecifier;
+
 bool StartsObjCMethodExpr =
-!CppArrayTemplates && Style.isCpp() &&
+!CppArrayTemplates && Style.isCpp() && !IsCpp11AttributeSpecifier &&
 Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
 CurrentToken->isNot(tok::l_brace) &&
 (!Parent ||
@@ -365,6 +395,8 @@
 } else if (Left->is(TT_Unknown)) {
   if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
+  } else if (IsCpp11AttributeSpecifier) {
+Left->Type = TT_AttributeSquare;
   } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
  Contexts.back().ContextKind == tok::l_brace &&
  Parent->isOneOf(tok::l_brace, tok::comma)) {
@@ -432,11 +464,14 @@
   Contexts.back().IsExpression = false;
 
 Contexts.back().ColonIsObjCMethodExpr = StartsObjCMethodExpr;
+Contexts.back().InCpp11AttributeSpecifier = IsCpp11AttributeSpecifier;
 
 while (CurrentToken) {
   if (CurrentToken->is(tok::r_square)) {
-if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) &&
-Left->is(TT_ObjCMethodExpr)) {
+if (IsCpp11AttributeSpecifier)
+  CurrentToken->Type = TT_AttributeSquare;
+else if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) &&
+

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-12 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 138024.
benhamilton added a comment.

- Restore short functionn type variable names and add clarifying comment.


Repository:
  rC Clang

https://reviews.llvm.org/D43906

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[10])(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[kNumEntries])(char, float);"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -141,10 +141,7 @@
 Contexts.size() == 2 && Contexts[0].ColonIsForRangeExpr;
 
 bool StartsObjCMethodExpr = false;
-if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
-} else if (FormatToken *MaybeSel = Left->Previous) {
+if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&
   MaybeSel->Previous->is(tok::at)) {
@@ -210,8 +207,16 @@
   Left->Type = TT_ObjCMethodExpr;
 }
 
+// MightBeFunctionType and ProbablyFunctionType are used for
+// function pointer and reference types as well as Objective-C
+// block types:
+//
+// void (*FunctionPointer)(void);
+// void (&FunctionReference)(void);
+// void (^ObjCBlock)(void);
 bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
+bool ProbablyFunctionType =
+CurrentToken->isOneOf(tok::star, tok::amp, tok::caret);
 bool HasMultipleLines = false;
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
@@ -248,7 +253,8 @@
 if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next 
&&
 (CurrentToken->Next->is(tok::l_paren) ||
  (CurrentToken->Next->is(tok::l_square) && 
Line.MustBeDeclaration)))
-  Left->Type = TT_FunctionTypeLParen;
+  Left->Type = Left->Next->is(tok::caret) ? TT_ObjCBlockLParen
+  : TT_FunctionTypeLParen;
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
 


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp

r327284 - [clang-format] Don't detect C++11 attribute specifiers as ObjC

2018-03-12 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Mon Mar 12 08:42:38 2018
New Revision: 327284

URL: http://llvm.org/viewvc/llvm-project?rev=327284&view=rev
Log:
[clang-format] Don't detect C++11 attribute specifiers as ObjC

Summary:
Previously, clang-format would detect C++11 and C++17 attribute
specifiers like the following as Objective-C method invocations:

  [[noreturn]];
  [[clang::fallthrough]];
  [[noreturn, deprecated("so sorry")]];
  [[using gsl: suppress("type")]];

To fix this, I ported part of the logic from
tools/clang/lib/Parse/ParseTentative.cpp into TokenAnnotator.cpp so we
can explicitly parse and identify C++11 attribute specifiers.

This allows the guessLanguage() and getStyle() APIs to correctly
guess files containing the C++11 attribute specifiers as C++,
not Objective-C.

Test Plan: New tests added. Ran tests with:
  make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: krasimir, jolesiak, djasper

Reviewed By: djasper

Subscribers: aaron.ballman, cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=327284&r1=327283&r2=327284&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Mar 12 08:42:38 2018
@@ -889,8 +889,8 @@ unsigned ContinuationIndenter::getNewLin
   if ((PreviousNonComment &&
(PreviousNonComment->ClosesTemplateDeclaration ||
 PreviousNonComment->isOneOf(
-TT_AttributeParen, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
-TT_LeadingJavaAnnotation))) ||
+TT_AttributeParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
+TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
   (!Style.IndentWrappedFunctionNames &&
NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName)))
 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=327284&r1=327283&r2=327284&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Mon Mar 12 08:42:38 2018
@@ -29,7 +29,9 @@ namespace format {
 #define LIST_TOKEN_TYPES   
\
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\
+  TYPE(AttributeColon) 
\
   TYPE(AttributeParen) 
\
+  TYPE(AttributeSquare)
\
   TYPE(BinaryOperator) 
\
   TYPE(BitFieldColon)  
\
   TYPE(BlockComment)   
\

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=327284&r1=327283&r2=327284&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Mar 12 08:42:38 2018
@@ -328,13 +328,40 @@ private:
 return false;
   }
 
+  bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
+if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
+  return false;
+const FormatToken *AttrTok = Tok.Next->Next;
+if (!AttrTok)
+  return false;
+// C++17 '[[using ns: foo, bar(baz, blech)]]'
+// We assume nobody will name an ObjC variable 'using'.
+if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+  return true;
+if (AttrTok->isNot(tok::identifier))
+  return false;
+while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+  // ObjC message send. We assume nobody will use : in a C++11 attribute
+  // specifier parameter, although this is technically valid:
+  // [[foo(:)]]
+  if (AttrTok->is(tok::colon) ||
+  AttrTok->startsSequence(tok::identifier, tok::identifier))
+return false;
+  if (AttrTok->is(tok::ellipsis))
+return true;
+  AttrTok = AttrTok->Next;
+}
+return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+  }
+
   bool parseSquare() {

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-12 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton marked an inline comment as done.
benhamilton added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:210
 
-bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
+bool MightBeFunctionOrObjCBlockType =
+!Contexts[Contexts.size() - 2].IsExpression;

djasper wrote:
> I'd suggest to put a comment here saying that this is for both ObjC blocks 
> and Function types, because they look very similar in nature (maybe giving 
> examples) and then not actually rename the variables. To me, the long names 
> make the code harder to read.
> 
> But if you feel strongly the other way, I'd be ok with it.
Restored old names and added comment.



Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


r327285 - [clang-format] Improve detection of Objective-C block types

2018-03-12 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Mon Mar 12 08:42:40 2018
New Revision: 327285

URL: http://llvm.org/viewvc/llvm-project?rev=327285&view=rev
Log:
[clang-format] Improve detection of Objective-C block types

Summary:
Previously, clang-format would detect the following as an
Objective-C block type:

  FOO(^);

when it actually must be a C or C++ macro dealing with an XOR
statement or an XOR operator overload.

According to the Clang Block Language Spec:

https://clang.llvm.org/docs/BlockLanguageSpec.html

block types are of the form:

  int (^)(char, float)

and block variables of block type are of the form:

  void (^blockReturningVoidWithVoidArgument)(void);
  int (^blockReturningIntWithIntAndCharArguments)(int, char);
  void (^arrayOfTenBlocksReturningVoidWithIntArgument[10])(int);

This tightens up the detection so we don't unnecessarily detect
C macros which pass in the XOR operator.

Depends On D43904

Test Plan: New tests added. Ran tests with:
  make -j12 FormatTests &&
  ./tools/clang/unittests/Format/FormatTests

Reviewers: krasimir, jolesiak, djasper

Reviewed By: djasper

Subscribers: djasper, cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=327285&r1=327284&r2=327285&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Mar 12 08:42:40 2018
@@ -141,10 +141,7 @@ private:
 Contexts.size() == 2 && Contexts[0].ColonIsForRangeExpr;
 
 bool StartsObjCMethodExpr = false;
-if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
-} else if (FormatToken *MaybeSel = Left->Previous) {
+if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&
   MaybeSel->Previous->is(tok::at)) {
@@ -210,8 +207,16 @@ private:
   Left->Type = TT_ObjCMethodExpr;
 }
 
+// MightBeFunctionType and ProbablyFunctionType are used for
+// function pointer and reference types as well as Objective-C
+// block types:
+//
+// void (*FunctionPointer)(void);
+// void (&FunctionReference)(void);
+// void (^ObjCBlock)(void);
 bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
+bool ProbablyFunctionType =
+CurrentToken->isOneOf(tok::star, tok::amp, tok::caret);
 bool HasMultipleLines = false;
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
@@ -248,7 +253,8 @@ private:
 if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next 
&&
 (CurrentToken->Next->is(tok::l_paren) ||
  (CurrentToken->Next->is(tok::l_square) && 
Line.MustBeDeclaration)))
-  Left->Type = TT_FunctionTypeLParen;
+  Left->Type = Left->Next->is(tok::caret) ? TT_ObjCBlockLParen
+  : TT_FunctionTypeLParen;
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=327285&r1=327284&r2=327285&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Mar 12 08:42:40 2018
@@ -12128,6 +12128,22 @@ TEST_F(FormatTest, GuessLanguageWithCpp1
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[10])(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[kNumEntries])(char, float);"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp

[PATCH] D40731: Integrate CHash into CLang

2018-03-12 Thread Christian Dietrich via Phabricator via cfe-commits
stettberger added inline comments.



Comment at: include/clang/AST/CHashVisitor.h:72-79
+  template
+  void addData(const llvm::iterator_range &x) {
+addData(std::distance(x.begin(), x.end()));
+  }
+  template
+  void addData(const llvm::ArrayRef &x) {
+addData(x.size());

rtrieu wrote:
> Should these also be storing the hashes of the elements in addition to 
> storing the size?
Ok. So this is called from 

- FunctionProtoTypes { addData(S->exceptions()); }
- DecompositionDecl { addData(S->bindings()); }
- ObjCObjectType  { addData(S->getTypeArgsAsWritten()); }

All of these occurrences are vistied by the RecursiveASTVisitor. However, we 
have no Idea how many children are visited by these for loops. Therefore, we 
additionally call addData(ArrayRef<...> x)  to indicate give the actual user of 
StmtCollector* the possibility to add these lengths to the hash. This is also 
the reason, why we add only the std::distance to the length. I will add a 
comment to this.



Comment at: include/clang/AST/CHashVisitor.h:211
+
+  bool VisitTypeDecl(TypeDecl *D) {
+// If we would hash the resulting type for a typedef, we

rtrieu wrote:
> I thought the idea was to have all the code in the *Collectors.td but here 
> you have a bunch of Visit* functions for AST nodes.  This seems counter to 
> your point of having them generated.
See Mail.



Comment at: include/clang/AST/CHashVisitor.h:212-213
+  bool VisitTypeDecl(TypeDecl *D) {
+// If we would hash the resulting type for a typedef, we
+// would get into an endless recursion.
+if (!isa(D) && !isa(D) && !isa(D)) {

rtrieu wrote:
> I don't see this example in the test.
It is now reflected in the tests.



Comment at: include/clang/AST/CHashVisitor.h:226
+}
+if (isa(ValDecl)) {
+  /* We emulate TraverseDecl here for VarDecl, because we

rtrieu wrote:
> Can't you query the hash for the Decl instead of doing work here?
How would I do it. As the example shows, there is no hash for a, when we try to 
calculate the hash for a. However, I included a  unittest to cover this.



Comment at: include/clang/AST/CHashVisitor.h:253
+  bool VisitValueDecl(ValueDecl *D) {
+/* Field Declarations can induce recursions */
+if (isa(D)) {

rtrieu wrote:
> Is this possible recursion included in your test?
It  now is.



Comment at: include/clang/AST/CHashVisitor.h:255
+if (isa(D)) {
+  addData(std::string(D->getType().getAsString()));
+} else {

rtrieu wrote:
> Shouldn't this be handled in the VisitFieldDecl function?
I must avoid to call addData(D->getType()) in VisitValueDecl for 
FieldDeclarations. So there would also be a conditional.



Comment at: include/clang/AST/DeclDataCollectors.td:5-7
+  // Every Declaration gets a tag field in the hash stream. It is
+  // hashed to add additional randomness to the hash
+  addData(llvm::hash_value(S->getKind()));

rtrieu wrote:
> Why is this randomness needed?
It is there for my personal feeling of less hash collisions. In former versions 
of this patch there was a large random constant for every type of AST node to 
decrease the likelyness of collisions when we left out some information. Small 
numbers (like enum values) often occur in source code. A 32 Bit Pseudo-Random 
value is unlikely to be seen in real source code. However, if you dislike its, 
I can remove the llvm::hash_value here.



Comment at: include/clang/AST/DeclDataCollectors.td:9
+
+  // CrossRef
+  addData(S->hasAttrs());

rtrieu wrote:
> What do you mean by "CrossRef"?
CrossRef indicates that the following fields are not local to the node. 
However, we give them to the user of the DataCollector to give it a chance to 
include the number of children into its hash. This directly relates to the 
addData(ArrayRef<...>) question above.


Repository:
  rC Clang

https://reviews.llvm.org/D40731



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


[PATCH] D40731: Integrate CHash into CLang

2018-03-12 Thread Christian Dietrich via Phabricator via cfe-commits
stettberger updated this revision to Diff 138019.
stettberger marked an inline comment as done.
stettberger added a comment.

Addressed comments, for more details, please see the mail on cfe-devel


Repository:
  rC Clang

https://reviews.llvm.org/D40731

Files:
  include/clang/AST/AttrDataCollectors.td
  include/clang/AST/CHashVisitor.h
  include/clang/AST/CMakeLists.txt
  include/clang/AST/DataCollection.h
  include/clang/AST/DeclDataCollectors.td
  include/clang/AST/StmtDataCollectors.td
  include/clang/AST/TypeDataCollectors.td
  unittests/AST/CHashTest.cpp
  unittests/AST/CMakeLists.txt

Index: unittests/AST/CMakeLists.txt
===
--- unittests/AST/CMakeLists.txt
+++ unittests/AST/CMakeLists.txt
@@ -17,6 +17,7 @@
   NamedDeclPrinterTest.cpp
   SourceLocationTest.cpp
   StmtPrinterTest.cpp
+  CHashTest.cpp
   )
 
 target_link_libraries(ASTTests
Index: unittests/AST/CHashTest.cpp
===
--- /dev/null
+++ unittests/AST/CHashTest.cpp
@@ -0,0 +1,116 @@
+//===- unittests/AST/DataCollectionTest.cpp ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file contains tests for the DataCollection module.
+//
+// They work by hashing the collected data of two nodes and asserting that the
+// hash values are equal iff the nodes are considered equal.
+//
+//===--===//
+
+#include "clang/AST/CHashVisitor.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+using namespace tooling;
+
+
+class CHashConsumer : public ASTConsumer {
+CompilerInstance &CI;
+llvm::MD5::MD5Result *ASTHash;
+
+public:
+
+CHashConsumer(CompilerInstance &CI, llvm::MD5::MD5Result *ASTHash)
+: CI(CI), ASTHash(ASTHash){}
+
+virtual void HandleTranslationUnit(clang::ASTContext &Context) override {
+TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
+
+// Traversing the translation unit decl via a RecursiveASTVisitor
+// will visit all nodes in the AST.
+CHashVisitor<> Visitor(Context);
+Visitor.TraverseDecl(TU);
+// Copy Away the resulting hash
+*ASTHash = *Visitor.getHash(TU);
+
+}
+
+~CHashConsumer() override {}
+};
+
+struct CHashAction : public ASTFrontendAction {
+llvm::MD5::MD5Result *Hash;
+
+CHashAction(llvm::MD5::MD5Result *Hash) : Hash(Hash) {}
+
+std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+   StringRef) override {
+return std::unique_ptr(new CHashConsumer(CI, Hash));
+}
+};
+
+static testing::AssertionResult
+isASTHashEqual(StringRef Code1, StringRef Code2) {
+llvm::MD5::MD5Result Hash1, Hash2;
+if (!runToolOnCode(new CHashAction(&Hash1), Code1)) {
+return testing::AssertionFailure()
+<< "Parsing error in (A)\"" << Code1.str() << "\"";
+}
+if (!runToolOnCode(new CHashAction(&Hash2), Code2)) {
+return testing::AssertionFailure()
+<< "Parsing error in (B) \"" << Code2.str() << "\"";
+}
+return testing::AssertionResult(Hash1 == Hash2);
+}
+
+TEST(CHashVisitor, TestRecordTypes) {
+ASSERT_TRUE(isASTHashEqual( // Unused record definition
+ "struct foobar { int a0; char a1; unsigned long a2; };",
+ "struct foobar { int a0; char a1;};"
+ ));
+
+// Recursive Record Types
+ASSERT_FALSE(isASTHashEqual( // Names still matter
+"struct ll { struct ll* foo; }; struct ll a;",
+"struct ll { struct ll* bar; }; struct ll a;"
+));
+
+ASSERT_TRUE(isASTHashEqual( // Order does not matter
+ "struct b; struct a { struct b* o; }; struct b { struct a* o; }; struct a X;",
+ "struct a; struct b { struct a* o; }; struct a { struct b* o; }; struct a X;"
+ ));
+
+// The initialization of a struct with a reference to itself should not crash
+ASSERT_FALSE(isASTHashEqual(
+"struct foo { int N; }; struct foo a = { sizeof(a) };",
+"struct foo { int N; }; struct foo a = { sizeof(struct foo) };"
+));
+}
+
+TEST(CHashVisitor, TypedefTest) {
+ASSERT_FALSE(isASTHashEqual(
+"typedef int bar_t;  bar_t x;",
+"typedef char bar_t; bar_t x;"
+));
+}
+
+
+TEST(CHashVisitor, TestSourceStructure) {
+ASSERT_FALSE(isASTHashEqual(
+ "void foo() { int c; if (0) { c = 1; } }",
+ "void foo() 

[PATCH] D43902: [clang-format] Don't detect C++11 attribute specifiers as ObjC

2018-03-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.

Ok, looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D43902



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


[PATCH] D44142: [clangd] Revamp handling of diagnostics.

2018-03-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE327282: [clangd] Revamp handling of diagnostics. (authored 
by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44142?vs=138004&id=138018#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44142

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Diagnostics.cpp
  clangd/Diagnostics.h
  clangd/Protocol.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  test/clangd/diagnostics.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/XRefsTests.cpp

Index: clangd/ClangdLSPServer.h
===
--- clangd/ClangdLSPServer.h
+++ clangd/ClangdLSPServer.h
@@ -46,9 +46,8 @@
 
 private:
   // Implement DiagnosticsConsumer.
-  virtual void
-  onDiagnosticsReady(PathRef File,
- Tagged> Diagnostics) override;
+  void onDiagnosticsReady(PathRef File,
+  Tagged> Diagnostics) override;
 
   // Implement ProtocolCallbacks.
   void onInitialize(InitializeParams &Params) override;
@@ -74,7 +73,7 @@
   void onHover(TextDocumentPositionParams &Params) override;
   void onChangeConfiguration(DidChangeConfigurationParams &Params) override;
 
-  std::vector getFixIts(StringRef File, const clangd::Diagnostic &D);
+  std::vector getFixes(StringRef File, const clangd::Diagnostic &D);
 
   JSONOutput &Out;
   /// Used to indicate that the 'shutdown' request was received from the
@@ -87,8 +86,7 @@
   bool IsDone = false;
 
   std::mutex FixItsMutex;
-  typedef std::map,
-   LSPDiagnosticCompare>
+  typedef std::map, LSPDiagnosticCompare>
   DiagnosticToReplacementMap;
   /// Caches FixIts per file and diagnostics
   llvm::StringMap FixItsMap;
Index: clangd/SourceCode.h
===
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -30,6 +30,10 @@
 /// Turn a SourceLocation into a [line, column] pair.
 Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc);
 
+// Converts a half-open clang source range to an LSP range.
+// Note that clang also uses closed source ranges, which this can't handle!
+Range halfOpenToRange(const SourceManager &SM, CharSourceRange R);
+
 } // namespace clangd
 } // namespace clang
 #endif
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -9,7 +9,9 @@
 
 #include "ClangdUnit.h"
 #include "Compiler.h"
+#include "Diagnostics.h"
 #include "Logger.h"
+#include "SourceCode.h"
 #include "Trace.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -81,22 +83,6 @@
   std::vector TopLevelDecls;
 };
 
-// Converts a half-open clang source range to an LSP range.
-// Note that clang also uses closed source ranges, which this can't handle!
-Range toRange(CharSourceRange R, const SourceManager &M) {
-  // Clang is 1-based, LSP uses 0-based indexes.
-  Position Begin;
-  Begin.line = static_cast(M.getSpellingLineNumber(R.getBegin())) - 1;
-  Begin.character =
-  static_cast(M.getSpellingColumnNumber(R.getBegin())) - 1;
-
-  Position End;
-  End.line = static_cast(M.getSpellingLineNumber(R.getEnd())) - 1;
-  End.character = static_cast(M.getSpellingColumnNumber(R.getEnd())) - 1;
-
-  return {Begin, End};
-}
-
 class InclusionLocationsCollector : public PPCallbacks {
 public:
   InclusionLocationsCollector(SourceManager &SourceMgr,
@@ -115,7 +101,7 @@
 if (SourceMgr.isInMainFile(SR.getBegin())) {
   // Only inclusion directives in the main file make sense. The user cannot
   // select directives not in the main file.
-  IncLocations.emplace_back(toRange(FilenameRange, SourceMgr),
+  IncLocations.emplace_back(halfOpenToRange(SourceMgr, FilenameRange),
 File->tryGetRealPathName());
 }
   }
@@ -170,113 +156,6 @@
   SourceManager *SourceMgr = nullptr;
 };
 
-/// Convert from clang diagnostic level to LSP severity.
-static int getSeverity(DiagnosticsEngine::Level L) {
-  switch (L) {
-  case DiagnosticsEngine::Remark:
-return 4;
-  case DiagnosticsEngine::Note:
-return 3;
-  case DiagnosticsEngine::Warning:
-return 2;
-  case DiagnosticsEngine::Fatal:
-  case DiagnosticsEngine::Error:
-return 1;
-  case DiagnosticsEngine::Ignored:
-return 0;
-  }
-  llvm_unreachable("Unknown diagnostic level!");
-}
-
-// Checks whether a location is within a half-open range.
-// Note that clang al

[clang-tools-extra] r327282 - [clangd] Revamp handling of diagnostics.

2018-03-12 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Mar 12 08:28:22 2018
New Revision: 327282

URL: http://llvm.org/viewvc/llvm-project?rev=327282&view=rev
Log:
[clangd] Revamp handling of diagnostics.

Summary:
The new implementation attaches notes to diagnostic message and shows
the original diagnostics in the message of the note.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, mgorny, cfe-commits, jkorous-apple

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

Added:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Diagnostics.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/test/clangd/diagnostics.test
clang-tools-extra/trunk/test/clangd/execute-command.test
clang-tools-extra/trunk/test/clangd/extra-flags.test
clang-tools-extra/trunk/test/clangd/fixits.test
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=327282&r1=327281&r2=327282&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Mar 12 08:28:22 2018
@@ -12,6 +12,7 @@ add_clang_library(clangDaemon
   CompileArgsCache.cpp
   Compiler.cpp
   Context.cpp
+  Diagnostics.cpp
   DraftStore.cpp
   FuzzyMatch.cpp
   GlobalCompilationDatabase.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=327282&r1=327281&r2=327282&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Mar 12 08:28:22 2018
@@ -8,6 +8,7 @@
 //===-===//
 
 #include "ClangdLSPServer.h"
+#include "Diagnostics.h"
 #include "JSONRPCDispatcher.h"
 #include "SourceCode.h"
 #include "URI.h"
@@ -313,12 +314,12 @@ void ClangdLSPServer::onCodeAction(CodeA
 
   json::ary Commands;
   for (Diagnostic &D : Params.context.diagnostics) {
-auto Edits = getFixIts(Params.textDocument.uri.file(), D);
-if (!Edits.empty()) {
+for (auto &F : getFixes(Params.textDocument.uri.file(), D)) {
   WorkspaceEdit WE;
+  std::vector Edits(F.Edits.begin(), F.Edits.end());
   WE.changes = {{Params.textDocument.uri.uri(), std::move(Edits)}};
   Commands.push_back(json::obj{
-  {"title", llvm::formatv("Apply FixIt {0}", D.message)},
+  {"title", llvm::formatv("Apply fix: {0}", F.Message)},
   {"command", ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND},
   {"arguments", {WE}},
   });
@@ -421,8 +422,8 @@ bool ClangdLSPServer::run(std::istream &
   return ShutdownRequestReceived;
 }
 
-std::vector ClangdLSPServer::getFixIts(StringRef File,
- const clangd::Diagnostic &D) {
+std::vector ClangdLSPServer::getFixes(StringRef File,
+   const clangd::Diagnostic &D) {
   std::lock_guard Lock(FixItsMutex);
   auto DiagToFixItsIter = FixItsMap.find(File);
   if (DiagToFixItsIter == FixItsMap.end())
@@ -437,21 +438,22 @@ std::vector ClangdLSPServer::g
 }
 
 void ClangdLSPServer::onDiagnosticsReady(
-PathRef File, Tagged> Diagnostics) {
+PathRef File, Tagged> Diagnostics) {
   json::ary DiagnosticsJSON;
 
   DiagnosticToReplacementMap LocalFixIts; // Temporary storage
-  for (auto &DiagWithFixes : Diagnostics.Value) {
-auto Diag = DiagWithFixes.Diag;
-DiagnosticsJSON.push_back(json::obj{
-{"range", Diag.range},
-{"severity", Diag.severity},
-{"message", Diag.message},
+  for (auto &Diag : Diagnostics.Value) {
+toLSPDiags(Diag, [&](clangd::Diagnostic Diag, llvm::ArrayRef Fixes) {
+  DiagnosticsJSON.push_back(json::obj{
+  {"range", Diag.range},
+  {"severity", Diag.severity},
+  {

[PATCH] D44387: [x86] Introduce the pconfig/encl[u|s|v] intrinsics

2018-03-12 Thread Gabor Buella via Phabricator via cfe-commits
GBuella created this revision.
GBuella added reviewers: craig.topper, zvi.
Herald added subscribers: cfe-commits, mgorny.

Introduce pconfig and SGX related intrinsics.


Repository:
  rC Clang

https://reviews.llvm.org/D44387

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/cpuid.h
  lib/Headers/module.modulemap
  lib/Headers/pconfigintrin.h
  lib/Headers/sgxintrin.h
  lib/Headers/x86intrin.h
  test/CodeGen/builtins-x86.c
  test/CodeGen/pconfig.c
  test/CodeGen/sgx.c
  test/Driver/x86-target-features.c

Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -139,3 +139,8 @@
 // RUN: %clang -target i386-linux-gnu -mretpoline -mno-retpoline-external-thunk %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-RETPOLINE-EXTERNAL-THUNK %s
 // RETPOLINE-EXTERNAL-THUNK: "-target-feature" "+retpoline-external-thunk"
 // NO-RETPOLINE-EXTERNAL-THUNK: "-target-feature" "-retpoline-external-thunk"
+
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mpconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PCONFIG %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-pconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-PCONFIG %s
+// PCONFIG: "-target-feature" "+pconfig"
+// NO-PCONFIG: "-target-feature" "-pconfig"
Index: test/CodeGen/sgx.c
===
--- /dev/null
+++ test/CodeGen/sgx.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_encls(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_encls
+  //CHECK-64: @llvm.x86.encls.64
+  //CHECK-32: @llvm.x86.encls.32
+  return _encls_u32(leaf, arguments);
+}
+
+unsigned int test_enclu(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclu
+  //CHECK-64: @llvm.x86.enclu.64
+  //CHECK-32: @llvm.x86.enclu.32
+  return _enclu_u32(leaf, arguments);
+}
+
+unsigned int test_enclv(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclv
+  //CHECK-64: @llvm.x86.enclv.64
+  //CHECK-32: @llvm.x86.enclv.32
+  return _enclv_u32(leaf, arguments);
+}
Index: test/CodeGen/pconfig.c
===
--- /dev/null
+++ test/CodeGen/pconfig.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-darwin -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386 -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_pconfig(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_pconfig
+  //CHECK-64: @llvm.x86.pconfig.64
+  //CHECK-32: @llvm.x86.pconfig.32
+  return _pconfig_u32(leaf, arguments);
+}
+
Index: test/CodeGen/builtins-x86.c
===
--- test/CodeGen/builtins-x86.c
+++ test/CodeGen/builtins-x86.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -emit-llvm -o %t %s
-// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -fsyntax-only -o %t %s
+// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -target-feature +pconfig -emit-llvm -o %t %s
+// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -target-feature +pconfig -fsyntax-only -o %t %s
 
 #ifdef USE_ALL
 #define USE_3DNOW
@@ -295,6 +295,9 @@
   (void) __builtin_ia32_monitorx(tmp_vp, tmp_Ui, tmp_Ui);
   (void) __builtin_ia32_mwaitx(tmp_Ui, tmp_Ui, tmp_Ui);
   (void) __builtin_ia32_clzero(tmp_vp);
+  (v

[PATCH] D44093: [BUILTINS] structure pretty printer

2018-03-12 Thread Paul Semel via Phabricator via cfe-commits
paulsemel added a comment.

Hi,

In https://reviews.llvm.org/D44093#1034610, @lebedev.ri wrote:

> BTW, as far as i can tell this still has zero test coverage (no new tests are 
> being added).
>  I'd expect to see the tests for the actual output
>
> - one struct per each type it is able to print
> - probably some tests showing error handling, and possibly the availability 
> of the builtin is somehow tested, too?


Sure, I am going to work on it, now that the patch seems to be kind of "Okay" 
for its first version !

Thanks !


Repository:
  rC Clang

https://reviews.llvm.org/D44093



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


Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Eric Liu via cfe-commits
Hi Akira,

It seems that this commit also changes behavior for compiling C++ code as
we are seeing test failures caused by this change in our internal tests.

I'm still trying to reduce a reproducer for the failure. In the meantime,
could you please double check if this affects C++?

Thanks,
Eric

On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ahatanak
> Date: Fri Mar  9 22:36:08 2018
> New Revision: 327206
>
> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
> Log:
> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>
> This patch uses the infrastructure added in r326307 for enabling
> non-trivial fields to be declared in C structs to allow __weak fields in
> C structs in ARC.
>
> rdar://problem/33599681
>
> Differential Revision: https://reviews.llvm.org/D44095
>
> Added:
> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/DeclCXX.h
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/DeclCXX.cpp
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CGBlocks.cpp
> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
> cfe/trunk/lib/CodeGen/CGObjC.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>bool NonTrivialToPrimitiveCopy : 1;
>bool NonTrivialToPrimitiveDestroy : 1;
>
> +  /// True if this class can be passed in a non-address-preserving fashion
> +  /// (such as in registers).
> +  /// This does not imply anything about how the ABI in use will actually
> +  /// pass an object of this class.
> +  bool CanPassInRegisters : 1;
> +
>  protected:
>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>   SourceLocation StartLoc, SourceLocation IdLoc,
> @@ -3636,6 +3642,18 @@ public:
>  NonTrivialToPrimitiveDestroy = true;
>}
>
> +  /// Determine whether this class can be passed in registers. In C++
> mode,
> +  /// it must have at least one trivial, non-deleted copy or move
> constructor.
> +  /// FIXME: This should be set as part of completeDefinition.
> +  bool canPassInRegisters() const {
> +return CanPassInRegisters;
> +  }
> +
> +  /// Set that we can pass this RecordDecl in registers.
> +  void setCanPassInRegisters(bool CanPass) {
> +CanPassInRegisters = CanPass;
> +  }
> +
>/// \brief Determines whether this declaration represents the
>/// injected class name.
>///
>
> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018
> @@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
>  /// constructor.
>  unsigned HasDefaultedDefaultConstructor : 1;
>
> -/// \brief True if this class can be passed in a
> non-address-preserving
> -/// fashion (such as in registers) according to the C++ language
> rules.
> -/// This does not imply anything about how the ABI in use will
> actually
> -/// pass an object of this class.
> -unsigned CanPassInRegisters : 1;
> -
>  /// \brief True if a defaulted default constructor for this class
> would
>  /// be constexpr.
>  unsigned DefaultedDefaultConstructorIsConstexpr : 1;
> @@ -1474,18 +1468,6 @@ public:
>  return data().HasIrrelevantDestructor;
>}
>
> -  /// \brief Determine whether this class has at least one trivial,
> non-deleted
> -  /// copy or move constructor.
> -  bool canPassInRegisters() const {
> -return data().CanPassInRegisters;
> -  }
> -
> -  /// \brief Set that we can pass this RecordDecl in registers.
> -  // FIXME: This should be set as part of completeDefinition.
> -  void setCanPassInRegisters(bool CanPass) {
> -data().CanPassInRegisters = CanPass;
> -  }
> -
>/// Determine whether the triviality for the purpose of calls for this
> class
>/// is overridden to be trivial because this class or the type of one
> of 

[PATCH] D44315: [clangd] Collect the number of files referencing a symbol in the static index.

2018-03-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE327275: [clangd] Collect the number of files referencing a 
symbol in the static index. (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44315?vs=137790&id=138006#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44315

Files:
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clangd/index/FileIndex.cpp
  clangd/index/Index.h
  clangd/index/Merge.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolYAML.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: clangd/index/SymbolCollector.h
===
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -45,6 +45,8 @@
 /// If set, this is used to map symbol #include path to a potentially
 /// different #include path.
 const CanonicalIncludes *Includes = nullptr;
+// Populate the Symbol.References field.
+bool CountReferences = false;
   };
 
   SymbolCollector(Options Opts);
@@ -63,6 +65,8 @@
 
   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
 
+  void finish() override;
+
 private:
   const Symbol *addDeclaration(const NamedDecl &, SymbolID);
   void addDefinition(const NamedDecl &, const Symbol &DeclSymbol);
@@ -74,6 +78,8 @@
   std::shared_ptr CompletionAllocator;
   std::unique_ptr CompletionTUInfo;
   Options Opts;
+  // Decls referenced from the current TU, flushed on finish().
+  llvm::DenseSet ReferencedDecls;
 };
 
 } // namespace clangd
Index: clangd/index/Merge.cpp
===
--- clangd/index/Merge.cpp
+++ clangd/index/Merge.cpp
@@ -73,6 +73,7 @@
 S.Definition = O.Definition;
   if (!S.CanonicalDeclaration)
 S.CanonicalDeclaration = O.CanonicalDeclaration;
+  S.References += O.References;
   if (S.CompletionLabel == "")
 S.CompletionLabel = O.CompletionLabel;
   if (S.CompletionFilterText == "")
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -228,37 +228,58 @@
 ArrayRef Relations, FileID FID, unsigned Offset,
 index::IndexDataConsumer::ASTNodeInfo ASTNode) {
   assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set.");
+  assert(CompletionAllocator && CompletionTUInfo);
+  const NamedDecl *ND = llvm::dyn_cast(D);
+  if (!ND)
+return true;
+
+  // Mark D as referenced if this is a reference coming from the main file.
+  // D may not be an interesting symbol, but it's cheaper to check at the end.
+  if (Opts.CountReferences &&
+  (Roles & static_cast(index::SymbolRole::Reference)) &&
+  ASTCtx->getSourceManager().getMainFileID() == FID)
+ReferencedDecls.insert(ND);
 
-  // FIXME: collect all symbol references.
+  // Don't continue indexing if this is a mere reference.
   if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
 Roles & static_cast(index::SymbolRole::Definition)))
 return true;
+  if (shouldFilterDecl(ND, ASTCtx, Opts))
+return true;
 
-  assert(CompletionAllocator && CompletionTUInfo);
+  llvm::SmallString<128> USR;
+  if (index::generateUSRForDecl(ND, USR))
+return true;
+  SymbolID ID(USR);
 
-  if (const NamedDecl *ND = llvm::dyn_cast(D)) {
-if (shouldFilterDecl(ND, ASTCtx, Opts))
-  return true;
-llvm::SmallString<128> USR;
-if (index::generateUSRForDecl(ND, USR))
-  return true;
+  const NamedDecl &OriginalDecl = *cast(ASTNode.OrigD);
+  const Symbol *BasicSymbol = Symbols.find(ID);
+  if (!BasicSymbol) // Regardless of role, ND is the canonical declaration.
+BasicSymbol = addDeclaration(*ND, std::move(ID));
+  else if (isPreferredDeclaration(OriginalDecl, Roles))
+// If OriginalDecl is preferred, replace the existing canonical
+// declaration (e.g. a class forward declaration). There should be at most
+// one duplicate as we expect to see only one preferred declaration per
+// TU, because in practice they are definitions.
+BasicSymbol = addDeclaration(OriginalDecl, std::move(ID));
 
-const NamedDecl &OriginalDecl = *cast(ASTNode.OrigD);
-auto ID = SymbolID(USR);
-const Symbol *BasicSymbol = Symbols.find(ID);
-if (!BasicSymbol) // Regardless of role, ND is the canonical declaration.
-  BasicSymbol = addDeclaration(*ND, std::move(ID));
-else if (isPreferredDeclaration(OriginalDecl, Roles))
-  // If OriginalDecl is preferred, replace the existing canonical
-  // declaration (e.g. a class forward declaration). There should be at most
-  // one duplicate as we expect to see only one preferred declaration per
-  // TU, because in practice they are definitions.
-  BasicSymbol = addDeclaration(OriginalDecl, std::move(ID));
+  if (Ro

[clang-tools-extra] r327275 - [clangd] Collect the number of files referencing a symbol in the static index.

2018-03-12 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Mar 12 07:49:09 2018
New Revision: 327275

URL: http://llvm.org/viewvc/llvm-project?rev=327275&view=rev
Log:
[clangd] Collect the number of files referencing a symbol in the static index.

Summary:
This is an important ranking signal.
It's off for the dynamic index for now. Correspondingly, tell the index
infrastructure only to report declarations for the dynamic index.

Reviewers: ioeric, hokein

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

Modified:

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=327275&r1=327274&r2=327275&view=diff
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Mon Mar 12 07:49:09 2018
@@ -99,6 +99,7 @@ public:
 auto CollectorOpts = SymbolCollector::Options();
 CollectorOpts.FallbackDir = AssumedHeaderDir;
 CollectorOpts.CollectIncludePath = true;
+CollectorOpts.CountReferences = true;
 auto Includes = llvm::make_unique();
 addSystemHeadersMapping(Includes.get());
 CollectorOpts.Includes = Includes.get();

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=327275&r1=327274&r2=327275&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Mon Mar 12 07:49:09 2018
@@ -26,12 +26,14 @@ std::unique_ptr indexAST(AST
   // AST at this point, but we also need preprocessor callbacks (e.g.
   // CommentHandler for IWYU pragma) to canonicalize includes.
   CollectorOpts.CollectIncludePath = false;
+  CollectorOpts.CountReferences = false;
 
   auto Collector = std::make_shared(std::move(CollectorOpts));
   Collector->setPreprocessor(std::move(PP));
   index::IndexingOptions IndexOpts;
+  // We only need declarations, because we don't count references.
   IndexOpts.SystemSymbolFilter =
-  index::IndexingOptions::SystemSymbolFilterKind::All;
+  index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly;
   IndexOpts.IndexFunctionLocals = false;
 
   index::indexTopLevelDecls(Ctx, Decls, Collector, IndexOpts);

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=327275&r1=327274&r2=327275&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Mar 12 07:49:09 2018
@@ -131,6 +131,9 @@ struct Symbol {
   //   * For non-inline functions, the canonical declaration typically appears
   // in the ".h" file corresponding to the definition.
   SymbolLocation CanonicalDeclaration;
+  // The number of translation units that reference this symbol from their main
+  // file. This number is only meaningful if aggregated in an index.
+  unsigned References = 0;
 
   /// A brief description of the symbol that can be displayed in the completion
   /// candidate list. For example, "Foo(X x, Y y) const" is a labal for a

Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=327275&r1=327274&r2=327275&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Merge.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp Mon Mar 12 07:49:09 2018
@@ -73,6 +73,7 @@ mergeSymbol(const Symbol &L, const Symbo
 S.Definition = O.Definition;
   if (!S.CanonicalDeclaration)
 S.CanonicalDeclaration = O.CanonicalDeclaration;
+  S.References += O.References;
   if (S.CompletionLabel == "")
 S.CompletionLabel = O.CompletionLabel;
   if (S.CompletionFilterText == "")

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/t

[PATCH] D44294: [clangd] Fix diagnostic errors in the test code, NFC.

2018-03-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/clangd/XRefsTests.cpp:587
 
-  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  const char *HeaderContents = R"cpp([[]]#ifndef TEST_H_
+ #define TEST_H_

hokein wrote:
> ilya-biryukov wrote:
> > I would go with `#pragma once` in the test code, it adds less noise. WDYT?
> I thought `#pragma once` is non-standard, but the diagnostic message also 
> suggest this fix. Changed to it.
Thanks! It's non-standard, but supported on every modern compiler, so we should 
be fine :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44294



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


[PATCH] D44142: [clangd] Revamp handling of diagnostics.

2018-03-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 138004.
ilya-biryukov added a comment.

- Replace equality comparison ops with matchers, they were only used in tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44142

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Diagnostics.cpp
  clangd/Diagnostics.h
  clangd/Protocol.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  test/clangd/diagnostics.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -41,8 +41,8 @@
 using testing::UnorderedElementsAreArray;
 
 class IgnoreDiagnostics : public DiagnosticsConsumer {
-  void onDiagnosticsReady(
-  PathRef File, Tagged> Diagnostics) override {}
+  void onDiagnosticsReady(PathRef File,
+  Tagged> Diagnostics) override {}
 };
 
 // FIXME: this is duplicated with FileIndexTests. Share it.
Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -21,7 +21,7 @@
 using ::testing::Pair;
 using ::testing::Pointee;
 
-void ignoreUpdate(llvm::Optional>) {}
+void ignoreUpdate(llvm::Optional>) {}
 void ignoreError(llvm::Error Err) {
   handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {});
 }
@@ -102,20 +102,20 @@
 /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero());
 auto Path = testPath("foo.cpp");
 S.update(Path, getInputs(Path, ""), WantDiagnostics::Yes,
- [&](std::vector) { Ready.wait(); });
+ [&](std::vector) { Ready.wait(); });
 
 S.update(Path, getInputs(Path, "request diags"), WantDiagnostics::Yes,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 S.update(Path, getInputs(Path, "auto (clobbered)"), WantDiagnostics::Auto,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "auto should have been cancelled by auto";
  });
 S.update(Path, getInputs(Path, "request no diags"), WantDiagnostics::No,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "no diags should not be called back";
  });
 S.update(Path, getInputs(Path, "auto (produces)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 Ready.notify();
   }
   EXPECT_EQ(2, CallbackCount);
@@ -131,15 +131,15 @@
 // FIXME: we could probably use timeouts lower than 1 second here.
 auto Path = testPath("foo.cpp");
 S.update(Path, getInputs(Path, "auto (debounced)"), WantDiagnostics::Auto,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "auto should have been debounced and canceled";
  });
 std::this_thread::sleep_for(std::chrono::milliseconds(200));
 S.update(Path, getInputs(Path, "auto (timed out)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 std::this_thread::sleep_for(std::chrono::seconds(2));
 S.update(Path, getInputs(Path, "auto (shut down)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
   }
   EXPECT_EQ(2, CallbackCount);
 }
@@ -190,8 +190,8 @@
 {
   WithContextValue WithNonce(NonceKey, ++Nonce);
   S.update(File, Inputs, WantDiagnostics::Auto,
-   [Nonce, &Mut, &TotalUpdates](
-   llvm::Optional> Diags) {
+   [Nonce, &Mut,
+&TotalUpdates](llvm::Optional> Diags) {
  EXPECT_THAT(Context::current().get(NonceKey),
  Pointee(Nonce));
 
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -56,13 +56,13 @@
 using ::testing::Contains;
 using ::testing::Each;
 using ::testing::ElementsAre;
+using ::testing::Field;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
-using ::testing::Field;
 
 class IgnoreDi

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-12 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 138002.
gtbercea added a comment.

Add input file.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/Inputs/libomptarget/libomptarget-nvptx-sm_20.bc
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,23 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the 
default clang lib directory or in LIBRARY_PATH. Expect degraded performance due 
to no inlining of runtime functions on target devices.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def warn_drv_omp_offload_target_missingbcruntime : Warning<
+  "No library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Expect degraded performance due to no inlining of runtime 
functions on target devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-12 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 138001.
gtbercea added a comment.

Fixes.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,23 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the 
default clang lib directory or in LIBRARY_PATH. Expect degraded performance due 
to no inlining of runtime functions on target devices.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def warn_drv_omp_offload_target_missingbcruntime : Warning<
+  "No library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Expect degraded performance due to no inlining of runtime 
functions on target devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,23 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 /

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-12 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 138000.
gtbercea added a comment.

Rename folder. Fix test.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,23 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   env LIBRARY_PATH=%S/Inputs/libomptarget %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the 
default clang lib directory or in LIBRARY_PATH. Expect degraded performance due 
to no inlining of runtime functions on target devices.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def warn_drv_omp_offload_target_missingbcruntime : Warning<
+  "No library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Expect degraded performance due to no inlining of runtime 
functions on target devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,23 @@
 // RUN:   | FileCheck -check-prefix=CHK-N

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-12 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137999.
gtbercea added a comment.
Herald added a subscriber: jholewinski.

Change name of folder.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/Inputs/libomptarget/libomptarget-nvptx-sm_20.bc
  test/Driver/openmp-offload-gpu.c
  test/OpenMP/nvptx_data_sharing.cpp
  test/OpenMP/nvptx_parallel_codegen.cpp

Index: test/OpenMP/nvptx_parallel_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_codegen.cpp
+++ test/OpenMP/nvptx_parallel_codegen.cpp
@@ -64,254 +64,243 @@
 
   // CHECK-NOT: define {{.*}}void {{@__omp_offloading_.+template.+l17}}_worker()
 
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l26}}_worker()
+// CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
+// CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
+// CHECK: store i8* null, i8** [[OMP_WORK_FN]],
+// CHECK: store i8 0, i8* [[OMP_EXEC_STATUS]],
+// CHECK: br label {{%?}}[[AWAIT_WORK:.+]]
+//
+// CHECK: [[AWAIT_WORK]]
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: [[KPR:%.+]] = call i1 @__kmpc_kernel_parallel(i8** [[OMP_WORK_FN]]
+// CHECK: [[KPRB:%.+]] = zext i1 [[KPR]] to i8
+// store i8 [[KPRB]], i8* [[OMP_EXEC_STATUS]], align 1
+// CHECK: [[WORK:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[SHOULD_EXIT:%.+]] = icmp eq i8* [[WORK]], null
+// CHECK: br i1 [[SHOULD_EXIT]], label {{%?}}[[EXIT:.+]], label {{%?}}[[SEL_WORKERS:.+]]
+//
+// CHECK: [[SEL_WORKERS]]
+// CHECK: [[ST:%.+]] = load i8, i8* [[OMP_EXEC_STATUS]]
+// CHECK: [[IS_ACTIVE:%.+]] = icmp ne i8 [[ST]], 0
+// CHECK: br i1 [[IS_ACTIVE]], label {{%?}}[[EXEC_PARALLEL:.+]], label {{%?}}[[BAR_PARALLEL:.+]]
+//
+// CHECK: [[EXEC_PARALLEL]]
+// CHECK: [[WF1:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[WM1:%.+]] = icmp eq i8* [[WF1]], bitcast (void (i16, i32)* [[PARALLEL_FN1:@.+]]_wrapper to i8*)
+// CHECK: br i1 [[WM1]], label {{%?}}[[EXEC_PFN1:.+]], label {{%?}}[[CHECK_NEXT1:.+]]
+//
+// CHECK: [[EXEC_PFN1]]
+// CHECK: call void [[PARALLEL_FN1]]_wrapper(
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[CHECK_NEXT1]]
+// CHECK: [[WF2:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[WM2:%.+]] = icmp eq i8* [[WF2]], bitcast (void (i16, i32)* [[PARALLEL_FN2:@.+]]_wrapper to i8*)
+// CHECK: br i1 [[WM2]], label {{%?}}[[EXEC_PFN2:.+]], label {{%?}}[[CHECK_NEXT2:.+]]
+//
+// CHECK: [[EXEC_PFN2]]
+// CHECK: call void [[PARALLEL_FN2]]_wrapper(
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[CHECK_NEXT2]]
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[TERM_PARALLEL]]
+// CHECK: call void @__kmpc_kernel_end_parallel()
+// CHECK: br label {{%?}}[[BAR_PARALLEL]]
+//
+// CHECK: [[BAR_PARALLEL]]
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: br label {{%?}}[[AWAIT_WORK]]
+//
+// CHECK: [[EXIT]]
+// CHECK: ret void
 
+// CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l26]](i[[SZ:32|64]]
+// Create local storage for each capture.
+// CHECK:  [[LOCAL_A:%.+]] = alloca i[[SZ]],
+// CHECK-DAG:  store i[[SZ]] [[ARG_A:%.+]], i[[SZ]]* [[LOCAL_A]]
+// Store captures in the context.
+// CHECK-64-DAG:[[REF_A:%.+]] = bitcast i[[SZ]]* [[LOCAL_A]] to i32*
+//
+// CHECK-DAG: [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[NTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[WS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK-DAG: [[TH_LIMIT:%.+]] = sub i32 [[NTH]], [[WS]]
+// CHECK: [[IS_WORKER:%.+]] = icmp ult i32 [[TID]], [[TH_LIMIT]]
+// CHECK: br i1 [[IS_WORKER]], label {{%?}}[[WORKER:.+]], label {{%?}}[[CHECK_MASTER:.+]]
+//
+// CHECK: [[WORKER]]
+// CHECK: {{call|invoke}} void [[T6]]_worker()
+// CHECK: br label {{%?}}[[EXIT:.+]]
+//
+// CHECK: [[CHECK_MASTER]]
+// CHECK-DAG: [[CMTID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[CMNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[CMWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[IS_MASTER:%.+]] = icmp eq i32 [[CMTID]],
+// CHECK: br i1 [[IS_MASTER]], label {{%?}}[[MASTER:.+]], label {{%?}}[[EXIT]]
+//
+// CHECK: [[MASTER]]
+// CHECK-DAG: [[MNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[MWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[MTMP1:%.+]] = sub i32 [[MNTH]], [[MWS]]
+// CHECK: call void @__kmpc_kernel_init(i32 [[MTMP1]]
+// CHECK: call void @__kmpc_kernel_prepare_parallel(i8* bitcast (void (i16, i32)* [[PARALLEL_FN1]]_wrapper to i8*),
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_

[PATCH] D44093: [BUILTINS] structure pretty printer

2018-03-12 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

BTW, as far as i can tell this still has zero test coverage (no new tests are 
being added).
I'd expect to see the tests for the actual output

- one struct per each type it is able to print
- probably some tests showing error handling,

and possibly the availability of the builtin is somehow tested, too?


Repository:
  rC Clang

https://reviews.llvm.org/D44093



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


[PATCH] D44093: [BUILTINS] structure pretty printer

2018-03-12 Thread Paul Semel via Phabricator via cfe-commits
paulsemel updated this revision to Diff 137998.
paulsemel added a comment.

Applied Francis' suggestions


Repository:
  rC Clang

https://reviews.llvm.org/D44093

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1110,6 +1110,65 @@
 // so ensure that they are declared.
 DeclareGlobalNewDelete();
 break;
+  case Builtin::BI__builtin_dump_struct: {
+// We first want to ensure we are called with 2 arguments
+if (checkArgCount(*this, TheCall, 2))
+  return ExprError();
+// Ensure that the first argument is of type 'struct XX *'
+const Expr *PtrArg = TheCall->getArg(0)->IgnoreParenImpCasts();
+const QualType PtrArgType = PtrArg->getType();
+if (!PtrArgType->isPointerType()) {
+  this->Diag(PtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< PtrArgType << "\'structure pointer type\'"
+<< 1 << 0 << 3 << 1
+<< PtrArgType << "\'structure pointer type\'";
+  return ExprError();
+}
+
+const RecordType *RT = PtrArgType->getPointeeType()->getAs();
+if (!RT) {
+  this->Diag(PtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< PtrArgType << "\'structure pointer type\'"
+<< 1 << 0 << 3 << 1
+<< PtrArgType << "\'structure pointer type\'";
+  return ExprError();
+}
+// Ensure that the second argument is of type 'FunctionType'
+const Expr *FnPtrArg = TheCall->getArg(1)->IgnoreImpCasts();
+const QualType FnPtrArgType = FnPtrArg->getType();
+if (!FnPtrArgType->isPointerType()) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+  return ExprError();
+}
+
+const FunctionType *FuncType =
+  FnPtrArgType->getPointeeType()->getAs();
+
+if (!FuncType) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+  return ExprError();
+}
+
+if (const FunctionProtoType *FT = dyn_cast(FuncType)) {
+  if (!FT->isVariadic() ||
+  FT->getReturnType() != Context.IntTy) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType<< "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+return ExprError();
+  }
+}
+
+TheCall->setType(Context.IntTy);
+break;
+  }
 
   // check secure string manipulation functions where overflows
   // are detectable at compile time
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -14,6 +14,7 @@
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
+#include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
@@ -930,6 +931,90 @@
   return RValue::get(Overflow);
 }
 
+static llvm::Value *dumpRecord(CodeGenFunction &CGF, QualType RType,
+ Value*& RecordPtr, CharUnits Align,
+ Value *Func, int Lvl)
+{
+  const RecordType *RT = RType->getAs();
+  ASTContext& Context = CGF.getContext();
+  RecordDecl *RD = RT->getDecl()->getDefinition();
+  ASTContext& Ctx = RD->getASTContext();
+  const ASTRecordLayout &RL = Ctx.getASTRecordLayout(RD);
+  std::string Pad = std::string(Lvl * 4, ' ');
+
+  Value *GString = CGF.Builder.CreateGlobalStringPtr(RType.getAsString()
+ + " {\n");
+  Value *Res = CGF.Builder.CreateCall(Func, {GString});
+
+  static llvm::DenseMap Types;
+  if (Types.empty()) {
+Types[Context.CharTy] = "%c";
+Types[Context.BoolTy] = "%d";
+Types[Context.IntTy] = "%d";
+Types[Context.UnsignedIntTy] = "%u";
+Types[Context.LongTy] = "%ld";
+Types[Context.UnsignedLongTy] = "%lu";
+Types[Context.LongLongTy] = "%lld";
+Types[Context.UnsignedLongLongTy] = "%llu";
+Types[Context.ShortTy] = "%hd";
+Types[Context.UnsignedShortTy] = "%hu";
+Types[Context.VoidPtrTy] = "%p";
+Types[Context.FloatTy] = "%f";
+Types[Context.DoubleTy] = "%f";
+Types[Context.LongDoubleTy] = "%Lf";
+Types[Context.getPointerType(Context.CharTy)] = "%s";
+  }
+
+  for (const auto *FD : RD->fields()) {
+uint64_t Off = RL.getFieldOffset(FD->getFieldIndex());
+Off = Ctx.toCharUnitsFromBits(Off).getQuantity();
+
+Value *FieldPtr = RecordPtr;
+FieldPtr = CGF.Builder.

[PATCH] D35200: Don't use mmap on Windows

2018-03-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan abandoned this revision.
yvvan added a comment.

It was the wrong direction


https://reviews.llvm.org/D35200



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


r327270 - [analyzer] Trying to fix Windows buildbots after r327258

2018-03-12 Thread Maxim Ostapenko via cfe-commits
Author: chefmax
Date: Mon Mar 12 06:44:19 2018
New Revision: 327270

URL: http://llvm.org/viewvc/llvm-project?rev=327270&view=rev
Log:
[analyzer] Trying to fix Windows buildbots after r327258

Modified:
cfe/trunk/test/Analysis/scopes-cfg-output.cpp

Modified: cfe/trunk/test/Analysis/scopes-cfg-output.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/scopes-cfg-output.cpp?rev=327270&r1=327269&r2=327270&view=diff
==
--- cfe/trunk/test/Analysis/scopes-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/scopes-cfg-output.cpp Mon Mar 12 06:44:19 2018
@@ -837,7 +837,7 @@ void test_for_compound_and_break() {
 // CHECK-NEXT:   4: *[B4.3]
 // CHECK-NEXT:   5: auto &i = *__begin1;
 // CHECK-NEXT:   6: operator=
-// CHECK-NEXT:   7: [B4.6] (ImplicitCastExpr, FunctionToPointerDecay, class A 
&(*)(const class A &) noexcept)
+// CHECK-NEXT:   7: [B4.6] (ImplicitCastExpr, FunctionToPointerDecay, class A 
&(*)(const class A &)
 // CHECK-NEXT:   8: i
 // CHECK-NEXT:   9: b
 // CHECK-NEXT:  10: [B4.9] (ImplicitCastExpr, NoOp, const class A)


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


  1   2   >