[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-30 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

In D58675#1449053 , @thakis wrote:

> ps: Hooray for landing this, and thanks for the cool feature!


Thanks! It's @aras_p accomplishment.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58675



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


[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-30 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

In D58675#1449051 , @thakis wrote:

> Looks like this landed without tests. Please add tests in a follow-up.
>
> Also, it looks like the flag is currently a cc1 flag. This should probably be 
> a CoreOption instead so that both the gcc-style and the cl-style drivers 
> expose it. Right now, users can't really use this if I read the patch right 
> (without using -Xclang, which is discouraged.)


Ok, thanks, I'm to add tests in a follow-up.

It works like `clang -ftime-trace main.cpp` now. Not sure I know where 
CoreOption is, but I'm to figure out it, thanks.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58675



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


[PATCH] D60040: [clangd] Use capacity() instead of size() in RefSlab::bytes()

2019-03-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

This was suggested in this comment 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60040



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


[PATCH] D60040: [clangd] Use capacity() instead of size() in RefSlab::bytes()

2019-03-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: gribozavr.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60040

Files:
  clang-tools-extra/clangd/index/Ref.h


Index: clang-tools-extra/clangd/index/Ref.h
===
--- clang-tools-extra/clangd/index/Ref.h
+++ clang-tools-extra/clangd/index/Ref.h
@@ -86,7 +86,7 @@
 
   size_t bytes() const {
 return sizeof(*this) + Arena.getTotalMemory() +
-   sizeof(value_type) * Refs.size();
+   sizeof(value_type) * Refs.capacity();
   }
 
   /// RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.


Index: clang-tools-extra/clangd/index/Ref.h
===
--- clang-tools-extra/clangd/index/Ref.h
+++ clang-tools-extra/clangd/index/Ref.h
@@ -86,7 +86,7 @@
 
   size_t bytes() const {
 return sizeof(*this) + Arena.getTotalMemory() +
-   sizeof(value_type) * Refs.size();
+   sizeof(value_type) * Refs.capacity();
   }
 
   /// RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57560: [clangd] Link libclangAST into clangd tool

2019-03-30 Thread Nathan Ridge via Phabricator via cfe-commits
nridge abandoned this revision.
nridge added a comment.
Herald added a subscriber: cfe-commits.

Abandoning as this has been fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57560



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


[PATCH] D60038: gn build: Add build files for most clang-tools-extra unit tests

2019-03-30 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: mbonadei.
Herald added subscribers: jdoerfert, kadircet, arphaman, jkorous, ioeric, 
mgorny, srhines.
Herald added a project: LLVM.

https://reviews.llvm.org/D60038

Files:
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  llvm/utils/gn/build/sync_source_lists_from_cmake.py
  llvm/utils/gn/secondary/clang-tools-extra/clangd/indexer/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
  
llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-apply-replacements/BUILD.gn
  
llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-change-namespace/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-doc/BUILD.gn
  
llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-include-fixer/BUILD.gn
  
llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-include-fixer/find-all-symbols/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-move/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-query/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-tidy/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/BUILD.gn
@@ -0,0 +1,67 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("ClangdTests") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clang-tidy",
+"//clang-tools-extra/clangd",
+"//clang-tools-extra/clangd/refactor/tweaks",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Format",
+"//clang/lib/Frontend",
+"//clang/lib/Index",
+"//clang/lib/Lex",
+"//clang/lib/Sema",
+"//clang/lib/Serialization",
+"//clang/lib/Tooling",
+"//clang/lib/Tooling/Core",
+"//clang/lib/Tooling/Inclusions",
+"//llvm/lib/Support",
+"//llvm/lib/Testing/Support",
+  ]
+  include_dirs = [ "//clang-tools-extra/clangd" ]
+  sources = [
+"Annotations.cpp",
+"BackgroundIndexTests.cpp",
+"CancellationTests.cpp",
+"ClangdTests.cpp",
+"ClangdUnitTests.cpp",
+"CodeCompleteTests.cpp",
+"CodeCompletionStringsTests.cpp",
+"ContextTests.cpp",
+"DexTests.cpp",
+"DiagnosticsTests.cpp",
+"DraftStoreTests.cpp",
+"ExpectedTypeTest.cpp",
+"FSTests.cpp",
+"FileDistanceTests.cpp",
+"FileIndexTests.cpp",
+"FindSymbolsTests.cpp",
+"FunctionTests.cpp",
+"FuzzyMatchTests.cpp",
+"GlobalCompilationDatabaseTests.cpp",
+"HeadersTests.cpp",
+"IndexActionTests.cpp",
+"IndexTests.cpp",
+"JSONTransportTests.cpp",
+"QualityTests.cpp",
+"RIFFTests.cpp",
+"SelectionTests.cpp",
+"SerializationTests.cpp",
+"SourceCodeTests.cpp",
+"SymbolCollectorTests.cpp",
+"SymbolInfoTests.cpp",
+"SyncAPI.cpp",
+"TUSchedulerTests.cpp",
+"TestFS.cpp",
+"TestIndex.cpp",
+"TestTU.cpp",
+"ThreadingTests.cpp",
+"TraceTests.cpp",
+"TweakTests.cpp",
+"TypeHierarchyTests.cpp",
+"URITests.cpp",
+"XRefsTests.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-tidy/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-tidy/BUILD.gn
@@ -0,0 +1,36 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("ClangTidyTests") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clang-tidy",
+"//clang-tools-extra/clang-tidy/android",
+"//clang-tools-extra/clang-tidy/google",
+"//clang-tools-extra/clang-tidy/llvm",
+"//clang-tools-extra/clang-tidy/objc",
+"//clang-tools-extra/clang-tidy/readability",
+"//clang-tools-extra/clang-tidy/utils",
+"//clang/lib/AST",
+"//clang/lib/ASTMatchers",
+"//clang/lib/Basic",
+"//clang/lib/Frontend",
+"//clang/lib/Lex",
+"//clang/lib/Serialization",
+"//clang/lib/Tooling",
+"//clang/lib/Tooling/Core",
+"//llvm/lib/Support",
+  ]
+  include_dirs = [ "//clang-tools-extra/clang-tidy" ]
+  sources = [
+"ClangTidyDiagnosticConsumerTest.cpp",
+"ClangTidyOptionsTest.cpp",
+"GoogleModuleTest.cpp",
+"IncludeInserterTest.cpp",
+"LLVMModuleTest.cpp",
+"NamespaceAliaserTest.cpp",
+"ObjCModuleTest.cpp",
+"OverlappingReplacementsTest.cpp",
+"ReadabilityModuleTest.cpp",
+"UsingInserterTest.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-query/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/unittests/clang-query/BUILD.gn
@@ -0,0 +1,21 @@
+import("//llvm/utils/unittest/unitte

[PATCH] D59934: Compare SourceLocations from different TUs by FileID

2019-03-30 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

In D59934#1446059 , @lebedev.ri wrote:

> Test?


Thanks for the remark :) I agree, that there should be at least a unit test 
asserting the right behaviour. I am working on it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59934



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


[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-30 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

ps: Hooray for landing this, and thanks for the cool feature!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58675



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


[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-30 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this landed without tests. Please add tests in a follow-up.

Also, it looks like the flag is currently a cc1 flag. This should probably be a 
CoreOption instead so that both the gcc-style and the cl-style drivers expose 
it. Right now, users can't really use this if I read the patch right (without 
using -Xclang, which is discouraged.)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58675



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


[clang-tools-extra] r357356 - Rename IncludeFixerTests to ClangIncludeFixerTests and ChangeNamespaceTests to ClangChangeNamespaceTests

2019-03-30 Thread Nico Weber via cfe-commits
Author: nico
Date: Sat Mar 30 16:09:10 2019
New Revision: 357356

URL: http://llvm.org/viewvc/llvm-project?rev=357356&view=rev
Log:
Rename IncludeFixerTests to ClangIncludeFixerTests and ChangeNamespaceTests to 
ClangChangeNamespaceTests

Follow-up to r356897 and r356254.

Modified:
clang-tools-extra/trunk/unittests/clang-change-namespace/CMakeLists.txt
clang-tools-extra/trunk/unittests/clang-include-fixer/CMakeLists.txt

Modified: 
clang-tools-extra/trunk/unittests/clang-change-namespace/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-change-namespace/CMakeLists.txt?rev=357356&r1=357355&r2=357356&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-change-namespace/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/unittests/clang-change-namespace/CMakeLists.txt Sat 
Mar 30 16:09:10 2019
@@ -11,11 +11,11 @@ include_directories(
 # We'd like clang/unittests/Tooling/RewriterTestContext.h in the test.
 include_directories(${CLANG_SOURCE_DIR})
 
-add_extra_unittest(ChangeNamespaceTests
+add_extra_unittest(ClangChangeNamespaceTests
   ChangeNamespaceTests.cpp
   )
 
-target_link_libraries(ChangeNamespaceTests
+target_link_libraries(ClangChangeNamespaceTests
   PRIVATE
   clangAST
   clangASTMatchers

Modified: clang-tools-extra/trunk/unittests/clang-include-fixer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-include-fixer/CMakeLists.txt?rev=357356&r1=357355&r2=357356&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-include-fixer/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/unittests/clang-include-fixer/CMakeLists.txt Sat 
Mar 30 16:09:10 2019
@@ -11,12 +11,12 @@ include_directories(
 # We'd like to clang/unittests/Tooling/RewriterTestContext.h in the test.
 include_directories(${CLANG_SOURCE_DIR})
 
-add_extra_unittest(IncludeFixerTests
+add_extra_unittest(ClangIncludeFixerTests
   IncludeFixerTest.cpp
   FuzzySymbolIndexTests.cpp
   )
 
-target_link_libraries(IncludeFixerTests
+target_link_libraries(ClangIncludeFixerTests
   PRIVATE
   clangBasic
   clangFormat


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


[PATCH] D59934: Compare SourceLocations from different TUs by FileID

2019-03-30 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

Just have a bit more context, I have the following information from a debug 
session at the execution point of the unreachable:

  (rr) p LHS.dump(*this)
  ./tmux-2.8/compat/tree.h:721:9
  
  (rr) p RHS.dump(*this)
  ./tmux-2.8/arguments.c:56:10
  
  (rr) p LOffs.first
  {ID = 1}
  (rr) p ROffs.first
  {ID = 2826}
  
  (rr) p LB
  {static npos = 18446744073709551615, Data = 0xe4f378 
"./tmux-2.8/cmd-capture-pane.c", Length = 49}
  (rr) p RB
  {static npos = 18446744073709551615, Data = 0x5ff7a78 
"./tmux-2.8/arguments.c", Length = 42}


Repository:
  rC Clang

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

https://reviews.llvm.org/D59934



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


[PATCH] D59934: Compare SourceLocations from different TUs by FileID

2019-03-30 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

In D59934#1446736 , @Szelethus wrote:

> In D59934#1446051 , @gamesh411 wrote:
>
> > Hi!
> >
> > This issue came up during the generation BugReports of BugPaths containing 
> > macro-expansions, where the spelling location and expansion locations were 
> > in different files.
> >  With this change, we make such SourceLocations comparable by their FileIDs.
>
>
> Do you mean regular macro expansions or the one we're generating in the plist 
> output via `-analyzer-config expand-macros=true`?


I have confirmed, that this happens when -analyzer-config expand-macros=true is 
passed, and no unreachable line is triggered without this analyzer config.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59934



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


[PATCH] D59919: [Attributor] Deduce "returned" argument attribute

2019-03-30 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:394
+
+indicateFixpoint(/* Optimistic */ true);
+return;

Maybe enum here ?
So you could call indicateFixpoint(Fixpoint::optimistic) ?

Or maybe even better, indicateOptimisticFixpoint()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59919



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


[PATCH] D59467: [clang] Adding the Likelihood Attribute from C++2a

2019-03-30 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a subscriber: NoQ.
riccibruno added a comment.

It seems that the tests are not present in this diff ? Also, again, could you 
please:

1. Use `clang-format`, and
2. Make sure that the comments are full sentences with appropriate punctuation, 
and
3. Follow the style guide regarding for the names of variables and functions.




Comment at: clang/include/clang/AST/Stmt.h:63
+  NotTaken = 2
+};
+

Can you make this a scoped enumeration to avoid injecting these names 
everywhere ? (+ add a comment describing what it is used for)



Comment at: clang/include/clang/Sema/Scope.h:168
+  /// BranchAttr - This is the Likelihood attribute associated with this 
Branch or a nullptr.
+  LikelihoodAttr *BranchAttr;
+

Perhaps `BranchAttr` -> `BranchLikelihoodAttr` ?



Comment at: clang/lib/AST/Stmt.cpp:832
   IfStmtBits.HasInit = HasInit;
+  IfStmtBits.Hint = NoHint;
 }

A small remark: there is no need to initialize it here since this will be done 
during deserialization. Not initializing it here has the advantage that 
forgetting the initialization during deserialization will (hopefully) cause an 
msan failure. The above bits are special since they are needed to correctly 
access the trailing objects.



Comment at: clang/lib/Analysis/CFG.cpp:2208
+}
+
 CFGBlock *CFGBuilder::VisitStmt(Stmt *S, AddStmtChoice asc) {

I don't understand why this is needed. Can you explain it ? Also I think that 
someone familiar with this code should comment on this (maybe @NoQ ?)



Comment at: clang/lib/CodeGen/CGStmt.cpp:705
+}
+
 void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,

I believe that the lowering is incorrect. I applied your patch and here 
({F8571803}) is the IR that clang generates (obtained with `-O1 -S -emit-llvm 
-Xclang -disable-llvm-passes -g0`) for this code:

```
bool f(bool i);
bool g(bool i);

bool h1(bool i) {
  if (i) [[likely]]
return f(i);
  return g(i);
}

bool h2(bool i) {
  if (__builtin_expect(i, true))
return f(i);
  return g(i);
}
```

In particular for the branch in `h1` we have:
```
  %tobool = trunc i8 %0 to i1
  %expval = call i1 @llvm.expect.i1(i1 %tobool, i1 true)
  br i1 %tobool, label %if.then, label %if.end
```
Note that `%expval` is not used. Compare this to the branch in `h2`:
```
  %tobool = trunc i8 %0 to i1
  %conv = zext i1 %tobool to i64
  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  %tobool1 = icmp ne i64 %expval, 0
  br i1 %tobool1, label %if.then, label %if.end
```
where the extra conversions are because of the signature of `__builtin_expect`.



Comment at: clang/lib/Parse/ParseStmt.cpp:1262
 
+  LikelihoodAttr *ThenAttr = getCurScope()->getBranchAttr();
+  getCurScope()->setBranchAttr(nullptr);

Perhaps `ThenAttr` -> `ThenLikelihoodAttr` ?



Comment at: clang/lib/Parse/ParseStmt.cpp:1304
   }
+  LikelihoodAttr *ElseAttr = getCurScope()->getBranchAttr();
 

Perhaps `ElseAttr` -> `ElseLikelihoodAttr` ?



Comment at: clang/lib/Sema/SemaStmt.cpp:524
 
-StmtResult
-Sema::ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt,
-  ConditionResult Cond,
-  Stmt *thenStmt, SourceLocation ElseLoc,
-  Stmt *elseStmt) {
+BranchHint Sema::HandleIfStmtHint(Stmt *ThenStmt, Stmt *elseStmt,
+  LikelihoodAttr *ThenAttr, LikelihoodAttr 
*ElseAttr) {

I would appreciate some documentation above `HandleIfStmtHint`.



Comment at: clang/lib/Sema/SemaStmt.cpp:529
+  if (ThenAttr) {
+if (ElseAttr && ThenAttr->getSpelling()[0] == ElseAttr->getSpelling()[0]) {
+  Diag(ElseAttr->getLocation(), diag::warn_conflicting_likelihood_attrs)

Do you have to use `getSpelling()` here ? Why not use `isLikely()` and 
`isUnlikely()` as below ?



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:63
+  if (isa(St) || isa(St)) {
+auto *FnScope = S.getCurFunction();
+if (FnScope->SwitchStack.empty()) {

Type not obvious -> no auto please.


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

https://reviews.llvm.org/D59467



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


[PATCH] D60029: Add const children() accessors to Stmts

2019-03-30 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In D60029#1448944 , @nicolas wrote:

> In D60029#1448938 , @riccibruno 
> wrote:
>
> > Did you go over all the statements on `Stmt.h` systematically ?
>
>
> Yes.
>
> > You could also do the same thing for all of the statements/expressions in 
> > `StmtCXX.h`, `Expr.h`, `ExprCXX.h`, and so on.
>
> I will go over those soon. I believe that `Expr.h` is mostly done.
>
> > Apart from this did you run `clang-format` on the patch ?
>
> I tried to stick to the style of the non-const functions, even when it was 
> wrong. I will `clang-format` the next patch!


Ah I see. Yeah I know that a fair amount of code is not formatted unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60029



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


[PATCH] D60029: Add const children() accessors to Stmts

2019-03-30 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas added a comment.

In D60029#1448938 , @riccibruno wrote:

> Did you go over all the statements on `Stmt.h` systematically ?


Yes.

> You could also do the same thing for all of the statements/expressions in 
> `StmtCXX.h`, `Expr.h`, `ExprCXX.h`, and so on.

I will go over those soon. I believe that `Expr.h` is mostly done.

> Apart from this did you run `clang-format` on the patch ?

I tried to stick to the style of the non-const functions, even when it was 
wrong. I will `clang-format` the next patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60029



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


[PATCH] D59806: [clang-tidy] Add a check for [super self] in initializers 🔍

2019-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D59806#1447929 , @jordan_rose wrote:

> I don't think there's ever a reason to call `[super self]`, and doing so 
> through a macro could easily indicate a bug.


Thank you for the verification! And agreed about the macro thing -- I am only 
worried about trying to issue a fix-it in that case, not the diagnostic itself.




Comment at: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp:112
+  << Message->getMethodDecl()
+  << FixItHint::CreateReplacement(Message->getSourceRange(),
+  StringRef("[super init]"));

stephanemoore wrote:
> stephanemoore wrote:
> > aaron.ballman wrote:
> > > This could be dangerous if the `[super self]` construct is in a macro, 
> > > couldn't it? e.g.,
> > > ```
> > > #define DERP self
> > > 
> > > [super DERP];
> > > ```
> > Good point. Let me add some test cases and make sure this is handled 
> > properly.
> Added some test cases where `[super self]` is expanded from macros.
You missed the test case I was worried about -- where the macro is mixed into 
the expression. I don't think we want to try to add a fix-it in that case.



Comment at: clang-tools-extra/test/clang-tidy/objc-super-self.m:41
+  INITIALIZER_IMPL();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in 
initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+}

Are you missing a `CHECK-FIXES` here?

Personally, I don't think we should try to generate a fixit for this case, so I 
would expect a CHECK-FIXES that ensures this doesn't get modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59806



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


[PATCH] D60029: Add const children() accessors to Stmts

2019-03-30 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

+1. I wanted to do this but never bothered. Did you go over all the statements 
on `Stmt.h` systematically ? You could also do the same thing for all of the 
statements/expressions in `StmtCXX.h`, `Expr.h`, `ExprCXX.h`, and so on. Apart 
from this did you run `clang-format` on the patch ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60029



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


[PATCH] D59467: [clang] Adding the Likelihood Attribute from C++2a

2019-03-30 Thread Gauthier via Phabricator via cfe-commits
Tyker updated this revision to Diff 192979.

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

https://reviews.llvm.org/D59467

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -140,6 +140,7 @@
   Record.push_back(HasElse);
   Record.push_back(HasVar);
   Record.push_back(HasInit);
+  Record.push_back(S->getBranchHint());
 
   Record.AddStmt(S->getCond());
   Record.AddStmt(S->getThen());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -223,6 +223,7 @@
   bool HasElse = Record.readInt();
   bool HasVar = Record.readInt();
   bool HasInit = Record.readInt();
+  S->setBranchHint(static_cast(Record.readInt()));
 
   S->setCond(Record.readSubExpr());
   S->setThen(Record.readSubStmt());
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -51,6 +51,55 @@
   return ::new (S.Context) auto(Attr);
 }
 
+static Attr *handleLikelihoodAttr(Sema &S, Stmt *St, const ParsedAttr &A,
+  SourceRange Range) {
+  LikelihoodAttr *Attr = ::new (S.Context) LikelihoodAttr(
+  A.getRange(), S.Context, A.getAttributeSpellingListIndex());
+
+  if (!S.getLangOpts().CPlusPlus2a && A.isCXX11Attribute())
+S.Diag(A.getLoc(), diag::ext_cxx2a_attr) << A.getName();
+
+  if (isa(St) || isa(St)) {
+auto *FnScope = S.getCurFunction();
+if (FnScope->SwitchStack.empty()) {
+  S.Diag(A.getLoc(), diag::warn_likelihood_on_case_outside_switch) << Attr->getSpelling()
+<< (isa(St) ? "case" : "default");
+}
+return Attr;
+  }
+
+  Scope *CurScope = S.getCurScope();
+  if (CurScope) {
+Scope *ControlScope = CurScope->getParent();
+if (!ControlScope ||
+ !(ControlScope->getFlags() & Scope::ControlScope ||
+   ControlScope->getFlags() & Scope::BreakScope) ||
+ ControlScope->getFlags() & Scope::SEHExceptScope ||
+ ControlScope->getFlags() & Scope::SEHTryScope ||
+ ControlScope->getFlags() & Scope::TryScope ||
+ ControlScope->getFlags() & Scope::FnTryCatchScope) {
+  S.Diag(A.getLoc(), diag::warn_no_likelihood_attr_associated_branch)
+  << A.getName();
+  return Attr;
+}
+
+if (ControlScope->getBranchAttr()) {
+  if (ControlScope->getBranchAttr()->getSpelling()[0] ==
+  Attr->getSpelling()[0])
+S.Diag(Attr->getLocation(), diag::err_repeat_attribute)
+<< Attr->getSpelling();
+  else
+S.Diag(Attr->getLocation(), diag::err_attributes_are_not_compatible)
+<< Attr->getSpelling()
+<< ControlScope->getBranchAttr()->getSpelling();
+  S.Diag(ControlScope->getBranchAttr()->getLocation(),
+ diag::note_previous_attribute);
+} else
+  ControlScope->setBranchAttr(Attr);
+  }
+  return Attr;
+}
+
 static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
 SourceRange Range) {
   if (A.getNumArgs() < 1) {
@@ -336,6 +385,8 @@
 return nullptr;
   case ParsedAttr::AT_FallThrough:
 return handleFallThroughAttr(S, St, A, Range);
+  case ParsedAttr::AT_Likelihood:
+return handleLikelihoodAttr(S, St, A, Range);
   case ParsedAttr::AT_LoopHint:
 return handleLoopHintAttr(S, St, A, Range);
   case ParsedAttr::AT_OpenCLUnrollHint:
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -521,11 +521,27 @@
 };
 }
 
-StmtResult
-Sema::ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt,
-  ConditionResult Cond,
-  Stmt *thenStmt, SourceLocation ElseLoc,
-  Stmt *elseStmt) {
+BranchHint Sema::HandleIfStmtHint(Stmt *ThenStmt, Stmt *elseStmt,
+  LikelihoodAttr *ThenAttr, LikelihoodAttr *ElseAttr) {
+  BranchHint Hint = NoHint;
+  // diagnose conflicting attribute and

r357348 - [cmake] Change deprecated $ to $. NFC

2019-03-30 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Mar 30 07:38:51 2019
New Revision: 357348

URL: http://llvm.org/viewvc/llvm-project?rev=357348&view=rev
Log:
[cmake] Change deprecated $ to $. NFC

See rL357338 for a similar change. The informational expression
$ has been deprecated since CMake 3.0

Modified:
cfe/trunk/runtime/CMakeLists.txt

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=357348&r1=357347&r2=357348&view=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Sat Mar 30 07:38:51 2019
@@ -18,7 +18,7 @@ function(get_ext_project_build_command o
 set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)
   else()
 set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}
---config $ PARENT_SCOPE)
+--config $ PARENT_SCOPE)
   endif()
 endfunction()
 


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


r357344 - [clang-format]: Add NonEmptyParentheses spacing option

2019-03-30 Thread Reuben Thomas via cfe-commits
Author: reuk
Date: Sat Mar 30 05:32:35 2019
New Revision: 357344

URL: http://llvm.org/viewvc/llvm-project?rev=357344&view=rev
Log:
[clang-format]: Add NonEmptyParentheses spacing option

This patch aims to add support for the following rules from the JUCE coding 
standards:

- Always put a space before an open parenthesis that contains text - e.g. foo 
(123);
- Never put a space before an empty pair of open/close parenthesis - e.g. foo();

Patch by Reuben Thomas

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

Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/TokenAnnotator.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=357344&r1=357343&r2=357344&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sat Mar 30 05:32:35 2019
@@ -1690,6 +1690,17 @@ struct FormatStyle {
 ///}
 /// \endcode
 SBPO_ControlStatements,
+/// Put a space before opening parentheses only if the parentheses are not
+/// empty i.e. '()'
+/// \code
+///   void() {
+/// if (true) {
+///   f();
+///   g (x, y, z);
+/// }
+///   }
+/// \endcode
+SBPO_NonEmptyParentheses,
 /// Always put a space before opening parentheses, except when it's
 /// prohibited by the syntax rules (in function-like macro definitions) or
 /// when determined by other style rules (after unary operators, opening

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357344&r1=357343&r2=357344&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sat Mar 30 05:32:35 2019
@@ -285,6 +285,8 @@ struct ScalarEnumerationTraitshttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=357344&r1=357343&r2=357344&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Mar 30 05:32:35 2019
@@ -2453,6 +2453,12 @@ unsigned TokenAnnotator::splitPenalty(co
   return 3;
 }
 
+bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const 
{
+  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
+ (Style.SpaceBeforeParens == FormatStyle::SBPO_NonEmptyParentheses &&
+  Right.ParameterCount > 0);
+}
+
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   const FormatToken &Left,
   const FormatToken &Right) {
@@ -2599,9 +2605,9 @@ bool TokenAnnotator::spaceRequiredBetwee
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||
-   (Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
+   (spaceRequiredBeforeParens(Right) &&
 (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() ||
- Left.is(tok::r_paren) ||
+ Left.is(tok::r_paren) || Left.isSimpleTypeSpecifier() ||
  (Left.is(tok::r_square) && Left.MatchingParen &&
   Left.MatchingParen->is(TT_LambdaLSquare))) &&
 Line.Type != LT_PreprocessorDirective);
@@ -2795,7 +2801,7 @@ bool TokenAnnotator::spaceRequiredBefore
   Left.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow))
 return true;
   if (Right.is(TT_OverloadedOperatorLParen))
-return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+return spaceRequiredBeforeParens(Right);
   if (Left.is(tok::comma))
 return true;
   if (Right.is(tok::comma))
@@ -2879,7 +2885,7 @@ bool TokenAnnotator::spaceRequiredBefore
 return true;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren) &&
   Right.isNot(TT_FunctionTypeLParen))
-return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+return spaceRequiredBeforeParens(Right);
   if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) &&
   Left.MatchingParen && 
Left.MatchingParen->is(TT_OverloadedOperatorLParen))
 return false;

Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=357344&r1=357343&r2=357344&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Sat Mar 30 05:32:35 2019
@@ -164,6 +16

r357340 - Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps.

2019-03-30 Thread Anton Afanasyev via cfe-commits
Author: anton-afanasyev
Date: Sat Mar 30 01:42:48 2019
New Revision: 357340

URL: http://llvm.org/viewvc/llvm-project?rev=357340&view=rev
Log:
Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` 
compatible JSON profiling output dumps.

This change adds hierarchical "time trace" profiling blocks that can be 
visualized in Chrome, in a "flame chart" style. Each profiling block can have a 
"detail" string that for example indicates the file being processed, template 
name being instantiated, function being optimized etc.

This is taken from GitHub PR: 
https://github.com/aras-p/llvm-project-20170507/pull/2

Patch by Aras Pranckevičius.

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

Modified:
cfe/trunk/include/clang/Basic/CodeGenOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Parse/ParseAST.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.def?rev=357340&r1=357339&r2=357340&view=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.def Sat Mar 30 01:42:48 2019
@@ -224,6 +224,7 @@ CODEGENOPT(FineGrainedBitfieldAccesses,
 CODEGENOPT(StrictEnums   , 1, 0) ///< Optimize based on strict enum 
definition.
 CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict 
vtable pointers
 CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report is enabled.
+CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
 CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
 CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled.

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=357340&r1=357339&r2=357340&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Sat Mar 30 01:42:48 2019
@@ -1745,6 +1745,7 @@ def Wframe_larger_than_EQ : Joined<["-"]
 def : Flag<["-"], "fterminated-vtables">, Alias;
 def fthreadsafe_statics : Flag<["-"], "fthreadsafe-statics">, Group;
 def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>;
+def ftime_trace : Flag<["-"], "ftime-trace">, Group, 
Flags<[CC1Option]>;
 def ftlsmodel_EQ : Joined<["-"], "ftls-model=">, Group, 
Flags<[CC1Option]>;
 def ftrapv : Flag<["-"], "ftrapv">, Group, Flags<[CC1Option]>,
   HelpText<"Trap on integer overflow">;

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=357340&r1=357339&r2=357340&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Sat Mar 30 01:42:48 2019
@@ -256,6 +256,9 @@ public:
   /// Show timers for individual actions.
   unsigned ShowTimers : 1;
 
+  /// Output time trace profile.
+  unsigned TimeTrace : 1;
+
   /// Show the -version text.
   unsigned ShowVersion : 1;
 
@@ -437,13 +440,14 @@ public:
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
-ShowStats(false), ShowTimers(false), ShowVersion(false),
-FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
-FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
-SkipFunctionBodies(false), UseGlobalModuleIndex(true),
-GenerateGlobalModuleIndex(true), ASTDumpDecls(false),
-ASTDumpLookups(false), BuildingImplicitModule(false),
-ModulesEmbedAllFiles(false), IncludeTimestamps(true) {}
+ShowStats(false), ShowTimers(false), TimeTrace(false),
+ShowVersion(false), FixWhatYouCan(false), FixOnlyWarnings(false),
+FixAndRecompile(false), FixToTemporaries(false),
+ARCMTMigrateEmitARCErrors(false), SkipFunctionBodies(false),
+UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true),
+ 

[PATCH] D60029: Add const children() accessors to Stmts

2019-03-30 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas created this revision.
nicolas added reviewers: bkramer, rsmith.
nicolas added a project: clang.
Herald added a subscriber: cfe-commits.

Exprs already have children() const but not Stmts.
All the changes are very simple, except for `DeclStmt` where I used a 
`const_cast`.


Repository:
  rC Clang

https://reviews.llvm.org/D60029

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/Stmt.cpp

Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -1254,6 +1254,10 @@
   return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
 }
 
+Stmt::const_child_range CapturedStmt::children() const {
+  return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
+}
+
 CapturedDecl *CapturedStmt::getCapturedDecl() {
   return CapDeclAndKind.getPointer();
 }
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -1188,6 +1188,11 @@
child_iterator(DG.end(), DG.end()));
   }
 
+  const_child_range children() const {
+auto Children = const_cast(this)->children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
   using decl_iterator = DeclGroupRef::iterator;
   using const_decl_iterator = DeclGroupRef::const_iterator;
   using decl_range = llvm::iterator_range;
@@ -1245,6 +1250,10 @@
   child_range children() {
 return child_range(child_iterator(), child_iterator());
   }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
 };
 
 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
@@ -1549,6 +1558,12 @@
getTrailingObjects() +
numTrailingObjects(OverloadToken()));
   }
+
+  const_child_range children() const {
+return const_child_range(getTrailingObjects(),
+ getTrailingObjects() +
+ numTrailingObjects(OverloadToken()));
+  }
 };
 
 class DefaultStmt : public SwitchCase {
@@ -1580,6 +1595,10 @@
 
   // Iterators
   child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
+
+  const_child_range children() const {
+return const_child_range(&SubStmt, &SubStmt + 1);
+  }
 };
 
 SourceLocation SwitchCase::getEndLoc() const {
@@ -1654,6 +1673,10 @@
 
   child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
 
+  const_child_range children() const {
+return const_child_range(&SubStmt, &SubStmt + 1);
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == LabelStmtClass;
   }
@@ -1711,6 +1734,10 @@
 
   child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
 
+  const_child_range children() const {
+return const_child_range(&SubStmt, &SubStmt + 1);
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == AttributedStmtClass;
   }
@@ -1910,6 +1937,12 @@
numTrailingObjects(OverloadToken()));
   }
 
+  const_child_range children() const {
+return const_child_range(getTrailingObjects(),
+ getTrailingObjects() +
+ numTrailingObjects(OverloadToken()));
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == IfStmtClass;
   }
@@ -2087,6 +2120,12 @@
numTrailingObjects(OverloadToken()));
   }
 
+  const_child_range children() const {
+return const_child_range(getTrailingObjects(),
+   getTrailingObjects() +
+   numTrailingObjects(OverloadToken()));
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == SwitchStmtClass;
   }
@@ -2212,6 +2251,12 @@
getTrailingObjects() +
numTrailingObjects(OverloadToken()));
   }
+
+  const_child_range children() const {
+return const_child_range(getTrailingObjects(),
+ getTrailingObjects() +
+ numTrailingObjects(OverloadToken()));
+  }
 };
 
 /// DoStmt - This represents a 'do/while' stmt.
@@ -2262,6 +2307,10 @@
   child_range children() {
 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
+  }
 };
 
 /// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
@@ -2331,6 +2380,10 @@
   child_range children() {
 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
+  }
 };
 
 /// GotoStmt - This represents a direct goto.
@@ -2366,6 +2419,10 @@
   child_range children() {
 return child_ra

[PATCH] D59684: [clang-format] [PR41187] moves Java import statements to the wrong location if code contains statements that start with the word import

2019-03-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357345: [clang-format] [PR41187] moves Java import 
statements to the wrong location if… (authored by paulhoad, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D59684?vs=191833&id=192973#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D59684

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


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1983,7 +1983,7 @@
 namespace {
 
 const char JavaImportRegexPattern[] =
-"^[\t ]*import[\t ]*(static[\t ]*)?([^\t ]*)[\t ]*;";
+"^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
 
 } // anonymous namespace
 
Index: unittests/Format/SortImportsTestJava.cpp
===
--- unittests/Format/SortImportsTestJava.cpp
+++ unittests/Format/SortImportsTestJava.cpp
@@ -262,6 +262,21 @@
  "import org.a;"));
 }
 
+TEST_F(SortImportsTestJava, ImportNamedFunction) {
+  EXPECT_EQ("import X;\n"
+"class C {\n"
+"  void m() {\n"
+"importFile();\n"
+"  }\n"
+"}\n",
+sort("import X;\n"
+ "class C {\n"
+ "  void m() {\n"
+ "importFile();\n"
+ "  }\n"
+ "}\n"));
+}
+
 TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "import org.a;\n"


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1983,7 +1983,7 @@
 namespace {
 
 const char JavaImportRegexPattern[] =
-"^[\t ]*import[\t ]*(static[\t ]*)?([^\t ]*)[\t ]*;";
+"^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
 
 } // anonymous namespace
 
Index: unittests/Format/SortImportsTestJava.cpp
===
--- unittests/Format/SortImportsTestJava.cpp
+++ unittests/Format/SortImportsTestJava.cpp
@@ -262,6 +262,21 @@
  "import org.a;"));
 }
 
+TEST_F(SortImportsTestJava, ImportNamedFunction) {
+  EXPECT_EQ("import X;\n"
+"class C {\n"
+"  void m() {\n"
+"importFile();\n"
+"  }\n"
+"}\n",
+sort("import X;\n"
+ "class C {\n"
+ "  void m() {\n"
+ "importFile();\n"
+ "  }\n"
+ "}\n"));
+}
+
 TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "import org.a;\n"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357345 - [clang-format] [PR41187] moves Java import statements to the wrong location if code contains statements that start with the word import

2019-03-30 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Sat Mar 30 06:05:40 2019
New Revision: 357345

URL: http://llvm.org/viewvc/llvm-project?rev=357345&view=rev
Log:
[clang-format] [PR41187] moves Java import statements to the wrong location if 
code contains statements that start with the word import

Summary:
Import sorting of java file, incorrectly move import statement to after a 
function beginning with the word import.

Make 1 character change to regular expression to ensure there is always at 
least one space/tab after the word import

Previously clang-format --style="LLVM" would format

```
import X;

class C {
  void m() {
importFile();
  }
}
```
as

```
class C {
  void m() {
importFile();
import X;
  }
}
```

Reviewers: djasper, klimek, reuk, JonasToth

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/SortImportsTestJava.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357345&r1=357344&r2=357345&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sat Mar 30 06:05:40 2019
@@ -1983,7 +1983,7 @@ static void sortJavaImports(const Format
 namespace {
 
 const char JavaImportRegexPattern[] =
-"^[\t ]*import[\t ]*(static[\t ]*)?([^\t ]*)[\t ]*;";
+"^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
 
 } // anonymous namespace
 

Modified: cfe/trunk/unittests/Format/SortImportsTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJava.cpp?rev=357345&r1=357344&r2=357345&view=diff
==
--- cfe/trunk/unittests/Format/SortImportsTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/SortImportsTestJava.cpp Sat Mar 30 06:05:40 2019
@@ -262,6 +262,21 @@ TEST_F(SortImportsTestJava, NoNewlineAtE
  "import org.a;"));
 }
 
+TEST_F(SortImportsTestJava, ImportNamedFunction) {
+  EXPECT_EQ("import X;\n"
+"class C {\n"
+"  void m() {\n"
+"importFile();\n"
+"  }\n"
+"}\n",
+sort("import X;\n"
+ "class C {\n"
+ "  void m() {\n"
+ "importFile();\n"
+ "  }\n"
+ "}\n"));
+}
+
 TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "import org.a;\n"


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


[PATCH] D55170: [clang-format]: Add NonEmptyParentheses spacing option

2019-03-30 Thread Reuben Thomas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357344: [clang-format]: Add NonEmptyParentheses spacing 
option (authored by reuk, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55170?vs=191560&id=192969#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55170

Files:
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/TokenAnnotator.h
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1690,6 +1690,17 @@
 ///}
 /// \endcode
 SBPO_ControlStatements,
+/// Put a space before opening parentheses only if the parentheses are not
+/// empty i.e. '()'
+/// \code
+///   void() {
+/// if (true) {
+///   f();
+///   g (x, y, z);
+/// }
+///   }
+/// \endcode
+SBPO_NonEmptyParentheses,
 /// Always put a space before opening parentheses, except when it's
 /// prohibited by the syntax rules (in function-like macro definitions) or
 /// when determined by other style rules (after unary operators, opening
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -285,6 +285,8 @@
 IO.enumCase(Value, "Never", FormatStyle::SBPO_Never);
 IO.enumCase(Value, "ControlStatements",
 FormatStyle::SBPO_ControlStatements);
+IO.enumCase(Value, "NonEmptyParentheses",
+FormatStyle::SBPO_NonEmptyParentheses);
 IO.enumCase(Value, "Always", FormatStyle::SBPO_Always);
 
 // For backward compatibility.
Index: cfe/trunk/lib/Format/TokenAnnotator.h
===
--- cfe/trunk/lib/Format/TokenAnnotator.h
+++ cfe/trunk/lib/Format/TokenAnnotator.h
@@ -164,6 +164,8 @@
   unsigned splitPenalty(const AnnotatedLine &Line, const FormatToken &Tok,
 bool InFunctionDecl);
 
+  bool spaceRequiredBeforeParens(const FormatToken &Right) const;
+
   bool spaceRequiredBetween(const AnnotatedLine &Line, const FormatToken &Left,
 const FormatToken &Right);
 
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2453,6 +2453,12 @@
   return 3;
 }
 
+bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
+  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
+ (Style.SpaceBeforeParens == FormatStyle::SBPO_NonEmptyParentheses &&
+  Right.ParameterCount > 0);
+}
+
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
   const FormatToken &Left,
   const FormatToken &Right) {
@@ -2599,9 +2605,9 @@
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||
-   (Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
+   (spaceRequiredBeforeParens(Right) &&
 (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() ||
- Left.is(tok::r_paren) ||
+ Left.is(tok::r_paren) || Left.isSimpleTypeSpecifier() ||
  (Left.is(tok::r_square) && Left.MatchingParen &&
   Left.MatchingParen->is(TT_LambdaLSquare))) &&
 Line.Type != LT_PreprocessorDirective);
@@ -2795,7 +2801,7 @@
   Left.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow))
 return true;
   if (Right.is(TT_OverloadedOperatorLParen))
-return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+return spaceRequiredBeforeParens(Right);
   if (Left.is(tok::comma))
 return true;
   if (Right.is(tok::comma))
@@ -2879,7 +2885,7 @@
 return true;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren) &&
   Right.isNot(TT_FunctionTypeLParen))
-return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+return spaceRequiredBeforeParens(Right);
   if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) &&
   Left.MatchingParen && Left.MatchingParen->is(TT_OverloadedOperatorLParen))
 return false;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@

[PATCH] D60023: [libcxx] [test] Fix inability to rebind poca_alloc in string.cons/copy_alloc.pass.cpp.

2019-03-30 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal marked an inline comment as done.
BillyONeal added inline comments.



Comment at: test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp:125
 test_assign(s1, s2);
 assert(s1 == p1);
 assert(s2 == p2);

This particular assert tests that the copy assignment operator provides the 
strong exception safety guarantee, but the standard requires only the basic 
guarantee. Should this be _LIBCXX_ASSERT?


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

https://reviews.llvm.org/D60023



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


[PATCH] D60023: [libcxx] [test] Fix inability to rebind poca_alloc in string.cons/copy_alloc.pass.cpp.

2019-03-30 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal marked 2 inline comments as done.
BillyONeal added inline comments.



Comment at: test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp:123
 
 imp2.deactivate();
 test_assign(s1, s2);

BillyONeal wrote:
> We still fail this test in debug mode because we need to allocate a new 
> _Container_proxy from imp2 in this assignment. Should this be libcxx_assert?
Hmmm this is copy assignment, not move assignment, so we still have a bug. I 
should not try writing CR comments at 2 in the morning.


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

https://reviews.llvm.org/D60023



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


[PATCH] D60023: [libcxx] [test] Fix inability to rebind poca_alloc in string.cons/copy_alloc.pass.cpp.

2019-03-30 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal added inline comments.



Comment at: test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp:123
 
 imp2.deactivate();
 test_assign(s1, s2);

We still fail this test in debug mode because we need to allocate a new 
_Container_proxy from imp2 in this assignment. Should this be libcxx_assert?


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

https://reviews.llvm.org/D60023



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


[PATCH] D58675: [clang] Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` compatible JSON profiling output dumps

2019-03-30 Thread Anton Afanasyev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357340: Adds `-ftime-trace` option to clang that produces 
Chrome `chrome://tracing`… (authored by anton-afanasyev, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D58675?vs=192525&id=192963#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58675

Files:
  cfe/trunk/include/clang/Basic/CodeGenOptions.def
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Parse/ParseAST.cpp
  cfe/trunk/lib/Parse/ParseDeclCXX.cpp
  cfe/trunk/lib/Parse/ParseTemplate.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
  cfe/trunk/tools/driver/cc1_main.cpp
  llvm/trunk/include/llvm/Support/TimeProfiler.h
  llvm/trunk/lib/IR/LegacyPassManager.cpp
  llvm/trunk/lib/Support/CMakeLists.txt
  llvm/trunk/lib/Support/TimeProfiler.cpp

Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
@@ -1382,6 +1383,9 @@
   const llvm::DataLayout &TDesc, Module *M,
   BackendAction Action,
   std::unique_ptr OS) {
+
+  llvm::TimeTraceScope TimeScope("Backend", StringRef(""));
+
   std::unique_ptr EmptyModule;
   if (!CGOpts.ThinLTOIndexFile.empty()) {
 // If we are performing a ThinLTO importing compile, load the function index
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -58,6 +58,7 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MD5.h"
+#include "llvm/Support/TimeProfiler.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -2482,6 +2483,9 @@
 if (!shouldEmitFunction(GD))
   return;
 
+llvm::TimeTraceScope TimeScope(
+"CodeGen Function", [&]() { return FD->getQualifiedNameAsString(); });
+
 if (const auto *Method = dyn_cast(D)) {
   // Make sure to emit the definition(s) before we emit the thunks.
   // This is necessary for the generation of certain thunks.
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4548,6 +4548,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
 
Index: cfe/trunk/lib/Sema/Sema.cpp
===
--- cfe/trunk/lib/Sema/Sema.cpp
+++ cfe/trunk/lib/Sema/Sema.cpp
@@ -39,6 +39,8 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/TimeProfiler.h"
+
 using namespace clang;
 using namespace sema;
 
@@ -92,6 +94,12 @@
   SourceManager &SM = S->getSourceManager();
   SourceLocation IncludeLoc = SM.getIncludeLoc(SM.getFileID(Loc));
   if (IncludeLoc.isValid()) {
+if (llvm::timeTraceProfilerEnabled()) {
+  const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
+  llvm::timeTraceProfilerBegin(
+  "Source", FE != nullptr ? FE->getName() : StringRef(""));
+}
+
 IncludeStack.push_back(IncludeLoc);
 S->DiagnoseNonDefaultPragmaPack(
 Sema::PragmaPackDiagnoseKind::NonDefaultStateAtInclude, IncludeLoc);
@@ -99,10 +107,14 @@
   break;
 }
 case ExitFile:
-  if (!IncludeStack.empty())
+  if (!IncludeStack.empty()) {
+if (llvm::timeTraceProfilerEnabled())
+  llvm::timeTraceProfilerEnd();
+
 S->DiagnoseNonDefaultPragmaPack(
 Sema::PragmaPackDiagnoseKind::ChangedStateAtExit,
 Inclu