[PATCH] D34740: [X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the two collides

2017-07-24 Thread coby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308867: [X86][InlineAsm][Ms Compatibility]Prefer variable 
name over a register when the… (authored by coby).

Changed prior to commit:
  https://reviews.llvm.org/D34740?vs=104352&id=107851#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34740

Files:
  cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c


Index: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - 
| FileCheck %s
+
+void t() {
+  int eax;
+  int Ecx;
+  __asm mov eax, ebx
+  // CHECK: mov $0, ebx
+  __asm add ecx, Ecx
+  // CHECK: add ecx, $1
+}
+


Index: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - | FileCheck %s
+
+void t() {
+  int eax;
+  int Ecx;
+  __asm mov eax, ebx
+  // CHECK: mov $0, ebx
+  __asm add ecx, Ecx
+  // CHECK: add ecx, $1
+}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH v3] [PPC64]: Add support for Swift calling convention

2017-07-24 Thread Ulrich Weigand via cfe-commits

Andrew Jeffery  wrote on 24.07.2017 03:54:05:

> > > > +  bool shouldPassIndirectlyForSwift(CharUnits totalSize,
> > > > +ArrayRef scalars,
> > > > +bool asReturnValue)
constoverride {
> > > > +return occupiesMoreThan(CGT, scalars, /*total*/ 4);
> >
> > I don't know much about Swift; the code changes seem reasonable. One
> > question I have is: from where does this number 4 come? Is there some
> > corresponding patch to Swift that this matches?
>
> As far as I'm aware a patch to Swift is not necessary, rather 4 comes
> from Ulrich's '[PowerPC] Support multiple return values with fast isel'
> patch[1] which allows up to 4 values to be returned in registers.
>
> To give some confidence, with this patch Swift builds and the tests
> pass for PPC64 on PPC64. Looking at the other implementations of
> shouldPassIndirectlyForSwift() none of them seem to have behaviour
> dependent on asReturnValue, however must say I'm not certain about the
> false (argument) case. Maybe Ulrich can provide some insight?

That LLVM back-end patch simply *allows* front-ends to return integers
in up to 4 registers.  (I did this because Anton Blanchard pointed out
in PR 26190 that Swift at that time wanted to return three values in
registers.)  The choice of 4 here is somewhat arbitrary, and the back-
end could as well be changed to allow using up to 8 registers; in fact,
this would even be more logical since it would allow using any of the
argument registers also as return register.

But this has really nothing to do with how Swift choses to *use* this.
Which and how many values Swift wants to return in registers is in
the end a choice to be made by the front-end.  Ideally, there should
be an ABI document specifying the Swift ABI for each platform.  I
don't really know what Swift is trying to do here; in particular, I
do not know whether Swift is attempting to be compatible with some
other ABI to allow interoperability, or whether this is a completely
private choice.  So I cannot really say whether 4 is "correct" here.

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


[PATCH] D35783: Ignore shadowing for declarations coming from within macros.

2017-07-24 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Your patch description sounds like you're only switching the warning off when 
the scope ends in a macro, but the patch looks different. For example:

  #define M int x
  
  int x;
  void f() {
M;
x = 42; // the user probably meant ::x here
  }

would also be suppressed now, right? It seems like we already have the 
DeclContext (which is the scope afaik), so NewDC->getEndLoc().isMacroID() might 
solve that?


https://reviews.llvm.org/D35783



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


[PATCH] D35787: [clang-tidy] Ignore vector in inefficient-vector-operation.

2017-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

https://reviews.llvm.org/D35787

Files:
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  test/clang-tidy/performance-inefficient-vector-operation.cpp


Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -274,4 +274,12 @@
   z12.push_back(e);
 }
   }
+  {
+std::vector z14;
+// std::vector will be ignored as STL provides a possibly
+// space-efficient specilaization of std::vector for the type "bool".
+for (int i = 0; i < 10; ++i) {
+  z14.push_back(true);
+}
+  }
 }
Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp
===
--- clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -73,8 +73,13 @@
 }
 
 void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector(
-  VectorLikeClasses.begin(), VectorLikeClasses.end(;
+  const auto VectorDecl = classTemplateSpecializationDecl(
+  hasAnyName(SmallVector(VectorLikeClasses.begin(),
+   VectorLikeClasses.end())),
+  // Exclude std::vector: STL provides a specilaization of 
std::vector
+  // for the type "bool", which may be optimized for space efficiency (e.g.
+  // each element occupies a single bit instead of sizeof(bool) bytes).
+  unless(hasTemplateArgument(0, refersToType(booleanType();
   const auto VectorDefaultConstructorCall = cxxConstructExpr(
   hasType(VectorDecl),
   hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;


Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -274,4 +274,12 @@
   z12.push_back(e);
 }
   }
+  {
+std::vector z14;
+// std::vector will be ignored as STL provides a possibly
+// space-efficient specilaization of std::vector for the type "bool".
+for (int i = 0; i < 10; ++i) {
+  z14.push_back(true);
+}
+  }
 }
Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp
===
--- clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -73,8 +73,13 @@
 }
 
 void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector(
-  VectorLikeClasses.begin(), VectorLikeClasses.end(;
+  const auto VectorDecl = classTemplateSpecializationDecl(
+  hasAnyName(SmallVector(VectorLikeClasses.begin(),
+   VectorLikeClasses.end())),
+  // Exclude std::vector: STL provides a specilaization of std::vector
+  // for the type "bool", which may be optimized for space efficiency (e.g.
+  // each element occupies a single bit instead of sizeof(bool) bytes).
+  unless(hasTemplateArgument(0, refersToType(booleanType();
   const auto VectorDefaultConstructorCall = cxxConstructExpr(
   hasType(VectorDecl),
   hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35790: [clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation check.

2017-07-24 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs created this revision.
rnkovacs added a project: clang-tools-extra.
Herald added subscribers: whisperity, JDevlieghere.

`bugprone-undefined-memory-manipulation` check crashes on incomplete types. 
This diff fixes that by assuming they are `TriviallyCopyable` by default.


https://reviews.llvm.org/D35790

Files:
  clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
  test/clang-tidy/bugprone-undefined-memory-manipulation.cpp


Index: test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
===
--- test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
+++ test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
@@ -52,6 +52,13 @@
   int vb;
 };
 
+// Incomplete type, assume it is TriviallyCopyable.
+struct NoDef;
+
+void f(NoDef *s) {
+  memset(s, 0, 5);
+}
+
 template 
 void memset_temp(T *b) {
   memset(b, 0, sizeof(T));
Index: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===
--- clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -19,7 +19,8 @@
 
 namespace {
 AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
-  return !Node.isTriviallyCopyable();
+  // For incomplete types, assume they are TriviallyCopyable.
+  return Node.hasDefinition() ? !Node.isTriviallyCopyable() : false;
 }
 } // namespace
 


Index: test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
===
--- test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
+++ test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
@@ -52,6 +52,13 @@
   int vb;
 };
 
+// Incomplete type, assume it is TriviallyCopyable.
+struct NoDef;
+
+void f(NoDef *s) {
+  memset(s, 0, 5);
+}
+
 template 
 void memset_temp(T *b) {
   memset(b, 0, sizeof(T));
Index: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===
--- clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -19,7 +19,8 @@
 
 namespace {
 AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
-  return !Node.isTriviallyCopyable();
+  // For incomplete types, assume they are TriviallyCopyable.
+  return Node.hasDefinition() ? !Node.isTriviallyCopyable() : false;
 }
 } // namespace
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-24 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

Dependent types seem to work, but we did manage to produce a crash on 
incomplete types. I created https://reviews.llvm.org/D35790 for that. I hope 
it's the same problem you encountered.


Repository:
  rL LLVM

https://reviews.llvm.org/D35051



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


[libunwind] r308871 - [libunwind] Handle .ARM.exidx tables without sentinel last entry

2017-07-24 Thread Momchil Velikov via cfe-commits
Author: chill
Date: Mon Jul 24 02:19:32 2017
New Revision: 308871

URL: http://llvm.org/viewvc/llvm-project?rev=308871&view=rev
Log:
[libunwind] Handle .ARM.exidx tables without sentinel last entry

UnwindCursor::getInfoFromEHABISection assumes the last
entry in the index table never corresponds to a real function.
Indeed, GNU ld always inserts an EXIDX_CANTUNWIND entry,
containing the end of the .text section. However, the EHABI specification
(http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf)
does not seem to contain text that requires the presence of a sentinel entry.
In that sense the libunwind implementation isn't compliant with the 
specification.

This patch makes getInfoFromEHABISection examine the last entry in the index
table if upper_bound returns the end iterator.

Fixes https://bugs.llvm.org/show_bug.cgi?id=31091

Differential revision: https://reviews.llvm.org/D35265

Modified:
libunwind/trunk/src/UnwindCursor.hpp

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=308871&r1=308870&r2=308871&view=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Mon Jul 24 02:19:32 2017
@@ -744,14 +744,21 @@ bool UnwindCursor::getInfoFromEHAB
   EHABISectionIterator::begin(_addressSpace, sects);
   EHABISectionIterator end =
   EHABISectionIterator::end(_addressSpace, sects);
+  if (begin == end)
+return false;
 
   EHABISectionIterator itNextPC = std::upper_bound(begin, end, pc);
-  if (itNextPC == begin || itNextPC == end)
+  if (itNextPC == begin)
 return false;
   EHABISectionIterator itThisPC = itNextPC - 1;
 
   pint_t thisPC = itThisPC.functionAddress();
-  pint_t nextPC = itNextPC.functionAddress();
+  // If an exception is thrown from a function, corresponding to the last entry
+  // in the table, we don't really know the function extent and have to choose 
a
+  // value for nextPC. Choosing max() will allow the range check during trace 
to
+  // succeed.
+  pint_t nextPC = (itNextPC == end) ? std::numeric_limits::max()
+: itNextPC.functionAddress();
   pint_t indexDataAddr = itThisPC.dataAddress();
 
   if (indexDataAddr == 0)


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


[PATCH] D35673: [analyzer] A better CFG-based suppress-on-sink.

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 107871.
NoQ added a comment.

Reduce stack operations as Alexey suggested.


https://reviews.llvm.org/D35673

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp
  test/Analysis/max-nodes-suppress-on-sink.c

Index: test/Analysis/max-nodes-suppress-on-sink.c
===
--- test/Analysis/max-nodes-suppress-on-sink.c
+++ test/Analysis/max-nodes-suppress-on-sink.c
@@ -15,6 +15,8 @@
 
 void clang_analyzer_warnIfReached(void);
 
+int coin();
+
 void test_single_cfg_block_sink() {
   void *p = malloc(1); // no-warning (wherever the leak warning may occur here)
 
@@ -29,3 +31,53 @@
   // the leak report.
   exit(0);
 }
+
+// A similar test with more complicated control flow before the no-return thing,
+// so that the no-return thing wasn't in the same CFG block.
+void test_more_complex_control_flow_before_sink() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  if (coin())
+exit(0);
+  else
+exit(1);
+}
+
+// A loop before the no-return function, to make sure that
+// the dominated-by-sink analysis doesn't hang.
+void test_loop_before_sink(int n) {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  for (int i = 0; i < n; ++i) {
+  }
+  exit(1);
+}
+
+// We're not sure if this is no-return.
+void test_loop_with_sink(int n) {
+  void *p = malloc(1); // expected-warning@+2{{Potential leak of memory}}
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  for (int i = 0; i < n; ++i)
+if (i == 0)
+  exit(1);
+}
+
+// Handle unreachable blocks correctly.
+void test_unreachable_successor_blocks() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  if (1) // no-crash
+exit(1);
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,6 +3304,45 @@
   return nullptr;
 }
 
+static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
+  const CFG &Cfg = N->getCFG();
+
+  const CFGBlock *StartBlk = findBlockForNode(N);
+  if (!StartBlk)
+return false;
+  if (StartBlk->hasNoReturnElement())
+return true;
+
+  llvm::SmallVector DFSWorkList;
+  llvm::SmallPtrSet Visited;
+
+  DFSWorkList.push_back(StartBlk);
+  while (!DFSWorkList.empty()) {
+const CFGBlock *Blk = DFSWorkList.back();
+DFSWorkList.pop_back();
+Visited.insert(Blk);
+
+for (const auto &Succ : Blk->succs()) {
+  if (const CFGBlock *SuccBlk = Succ.getReachableBlock()) {
+if (SuccBlk == &Cfg.getExit()) {
+  // We seem to be leaving the current CFG.
+  // We're no longer sure what happens next.
+  return false;
+}
+
+if (!SuccBlk->hasNoReturnElement() && !Visited.count(SuccBlk)) {
+  // If the block has reachable child blocks that aren't no-return,
+  // add them to the worklist.
+  DFSWorkList.push_back(SuccBlk);
+}
+  }
+}
+  }
+
+  // Nothing reached the exit. It can only mean one thing: there's no return.
+  return true;
+}
+
 static BugReport *
 FindReportInEquivalenceClass(BugReportEquivClass& EQ,
  SmallVectorImpl &bugReports) {
@@ -3360,9 +3399,8 @@
 // We may be post-dominated in subsequent blocks, or even
 // inter-procedurally. However, it is not clear if more complicated
 // cases are generally worth suppressing.
-if (const CFGBlock *B = findBlockForNode(errorNode))
-  if (B->hasNoReturnElement())
-continue;
+if (isDominatedByNoReturnBlocks(errorNode))
+  continue;
 
 // At this point we know that 'N' is not a sink and it has at least one
 // successor.  Use a DFS worklist to find a non-sink end-of-path node.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35674: [analyzer] Treat C++ throw as sink during CFG-based suppress-on-sink.

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 107872.
NoQ added a comment.

Rebase. Turn the comment into a FIXME.


https://reviews.llvm.org/D35674

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp
  test/Analysis/max-nodes-suppress-on-sink.cpp


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,13 +3304,34 @@
   return nullptr;
 }
 
+static bool isNoReturnBlock(const CFGBlock *Blk) {
+  if (Blk->hasNoReturnElement())
+return true;
+
+  // FIXME: Throw-expressions are currently generating sinks during analysis:
+  // they're not supported yet, and also often used for actually terminating
+  // the program. So we should treat them as sinks in this analysis as well,
+  // at least for now, but once we have better support for exceptions,
+  // we'd need to carefully handle the case when the throw is being
+  // immediately caught.
+  if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+if (Optional StmtElm = Elm.getAs())
+  if (isa(StmtElm->getStmt()))
+return true;
+return false;
+  }))
+return true;
+
+  return false;
+}
+
 static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
   const CFG &Cfg = N->getCFG();
 
   const CFGBlock *StartBlk = findBlockForNode(N);
   if (!StartBlk)
 return false;
-  if (StartBlk->hasNoReturnElement())
+  if (isNoReturnBlock(StartBlk))
 return true;
 
   llvm::SmallVector DFSWorkList;
@@ -3330,7 +3351,7 @@
   return false;
 }
 
-if (!SuccBlk->hasNoReturnElement() && !Visited.count(SuccBlk)) {
+if (!isNoReturnBlock(SuccBlk) && !Visited.count(SuccBlk)) {
   // If the block has reachable child blocks that aren't no-return,
   // add them to the worklist.
   DFSWorkList.push_back(SuccBlk);


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,13 +3304,34 @@
   return nullptr;
 }
 
+static bool isNoReturnBlock(const CFGBlock *Blk) {
+  if (Blk->hasNoReturnElement())
+return true;
+
+  // FIXME: Throw-expressions are currently generating sinks during analysis:
+  // they're not supported yet, and also often used for actually terminating
+  // the program. So we should treat them as sinks in this analysis as well,
+  // at least for now, but once we have better support for exceptions,
+  // we'd need to carefully handle the case when the throw is being
+  // immediately caught.
+  if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+if (Optional StmtElm = Elm.getAs())
+  if (isa(StmtElm->getStmt()))
+return true;
+return false;
+  }))
+return true;
+
+  return false;
+}
+
 static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
   const CFG &Cfg = N->getCFG();
 
   const CFGBlock *StartBlk = findBlockForNode(N)

[PATCH] D35674: [analyzer] Treat C++ throw as sink during CFG-based suppress-on-sink.

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 107873.
NoQ added a comment.

Bring back the test that was accidentally lost.


https://reviews.llvm.org/D35674

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp
  test/Analysis/max-nodes-suppress-on-sink.cpp


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
+
+// FIXME: Handled throws shouldn't be suppressing us!
+void test_handled_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  try {
+throw 0;
+  } catch (int i) {
+  }
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,13 +3304,34 @@
   return nullptr;
 }
 
+static bool isNoReturnBlock(const CFGBlock *Blk) {
+  if (Blk->hasNoReturnElement())
+return true;
+
+  // FIXME: Throw-expressions are currently generating sinks during analysis:
+  // they're not supported yet, and also often used for actually terminating
+  // the program. So we should treat them as sinks in this analysis as well,
+  // at least for now, but once we have better support for exceptions,
+  // we'd need to carefully handle the case when the throw is being
+  // immediately caught.
+  if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+if (Optional StmtElm = Elm.getAs())
+  if (isa(StmtElm->getStmt()))
+return true;
+return false;
+  }))
+return true;
+
+  return false;
+}
+
 static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
   const CFG &Cfg = N->getCFG();
 
   const CFGBlock *StartBlk = findBlockForNode(N);
   if (!StartBlk)
 return false;
-  if (StartBlk->hasNoReturnElement())
+  if (isNoReturnBlock(StartBlk))
 return true;
 
   llvm::SmallVector DFSWorkList;
@@ -3330,7 +3351,7 @@
   return false;
 }
 
-if (!SuccBlk->hasNoReturnElement() && !Visited.count(SuccBlk)) {
+if (!isNoReturnBlock(SuccBlk) && !Visited.count(SuccBlk)) {
   // If the block has reachable child blocks that aren't no-return,
   // add them to the worklist.
   DFSWorkList.push_back(SuccBlk);


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
+
+// FIXME: Handled throws shouldn't be suppressing us!
+void test_handled_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  try {
+throw 0;
+  } catch (int i) {
+  }
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,13 +3304,34 @@
   return nullptr;
 }
 
+static bool isNoReturnBlock(const CFGBlock *Blk) {
+  if (Blk->hasNoReturnElement())
+return true;
+
+  // FIXME: Throw-expressions are currently generating sinks during analysis:
+  // they're not supported yet, and also often used for actually terminating
+  // the pr

[PATCH] D35783: Ignore shadowing for declarations coming from within macros.

2017-07-24 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I don't understand how my patch description says that. I am trying to be very 
explicit about that fact that it doesn't, see last paragraph.

I have thought about what you are suggesting, but

- A DeclContext doesn't have getEndLoc().
- The DeclContext NewDC here is usually the FunctionDecl, which doesn't help. I 
think you are thinking about the parent CompoundStmt in terms of AST matching. 
Not sure there is something like that in the AST itself.


https://reviews.llvm.org/D35783



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


[PATCH] D34748: [clang-diff] improve mapping accuracy, HTML side-by-side diff.

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Some comments:

- I had to make a couple of post-commit fixes to appease the buildbots when I 
committed your first patch, so it looks like this one doesn't apply cleanly 
anymore. Can you please rebase it?
- Let's separate the addition of HTML output and the improvements to the 
algorithm in two patches. I would recommend that you leave the algorithm 
improvements in this one and post a follow-up patch that has HTML output (with 
a HTML output test).
- I won't be able to accept a change like this without tests. Did you monitor 
the changes in the HTML output while your worked on improvements to the 
algorithm? Please try and base the tests on those changes and improvements.




Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:814
+  return 0.001//
+ + 0.5 * Options.MinSimilarity * haveSameParents(M, Id1, Id2) //
+ + 0.5 * Options.MinSimilarity * SameValue//

What are these magic constants? Please describe them in comments and factor out 
to appropriately named const variables if needed.


https://reviews.llvm.org/D34748



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


[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This fixes a regression exposed by r307795 and 
https://reviews.llvm.org/rL308725 in which the level of a
comment line between '} else {' and a preprocessor directive is incorrectly set
as the level of the '} else {' line. For example, this :

  int f(int i) {
if (i) {
  ++i;
} else {
  // comment
  #ifdef A
  --i;
  #endif
}
  }

was formatted as:

  int f(int i) {
if (i) {
  ++i;
} else {
// comment
  #ifdef A
  --i;
  #endif
}
  }


https://reviews.llvm.org/D35794

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // comment in else\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  /* comment in else */\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Keep the current level if there is an empty line between the comment and
   // the preprocessor directive.
   EXPECT_EQ("void f() {\n"
@@ -912,8 +954,55 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "// comment in else\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "/* comment in else */\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Align with the preprocessor directive if the comment was originally aligned
-  // with the preprocessor directive.
+  // with the preprocessor directive and there is no newline between the comment
+  // and the preprocessor directive.
   EXPECT_EQ("void f() {\n"
 "  int i;\n"
 "/* comment */\n"
@@ -945,6 +1034,48 @@
"  int j;\n"
"#endif\n"
"}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " // comment in else\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comme

[PATCH] D35783: Ignore shadowing for declarations coming from within macros.

2017-07-24 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Could we perhaps only suppress the warning when we shadow a variable within the 
same declcontext? Generally, with macros, shadowing local variables is more 
surprising.


https://reviews.llvm.org/D35783



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


[PATCH] D35783: Ignore shadowing for declarations coming from within macros.

2017-07-24 Thread Daniel Jasper via Phabricator via cfe-commits
djasper updated this revision to Diff 107885.
djasper added a comment.

Updated to be a bit more strict (warn if declarations from the same context get
shadowed).


https://reviews.llvm.org/D35783

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/warn-shadow.cpp


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -168,6 +168,13 @@
   using bob2=int; // expected-warning {{declaration shadows a type alias in 
the global namespace}}
 }
 
+void macro() {
+  int x; // expected-note 1 {{previous declaration is here}}
+#define A(a) { int a = 0; }
+  A(x); // expected-warning {{declaration shadows a local variable}}
+  A(i);
+}
+
 namespace rdar29067894 {
 
 void avoidWarningWhenRedefining(int b) { // expected-note {{previous 
definition is here}}
@@ -199,13 +206,13 @@
   using l=char; // no warning or error.
   using l=char; // no warning or error.
   typedef char l; // no warning or error.
- 
-  typedef char n; // no warning or error. 
+
+  typedef char n; // no warning or error.
   typedef char n; // no warning or error.
   using n=char; // no warning or error.
 }
 
-}
+} // namespace rdar29067894
 
 extern "C" {
 typedef int externC; // expected-note {{previous declaration is here}}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6946,6 +6946,10 @@
 void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
const LookupResult &R) {
   DeclContext *NewDC = D->getDeclContext();
+  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
+
+  if (D->getLocation().isMacroID() && NewDC != OldDC)
+return;
 
   if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
 // Fields are not shadowed by variables in C++ static methods.
@@ -6975,8 +6979,6 @@
 }
 }
 
-  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
-
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
   if (isa(D) && isa(ShadowedDecl) && NewDC &&


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -168,6 +168,13 @@
   using bob2=int; // expected-warning {{declaration shadows a type alias in the global namespace}}
 }
 
+void macro() {
+  int x; // expected-note 1 {{previous declaration is here}}
+#define A(a) { int a = 0; }
+  A(x); // expected-warning {{declaration shadows a local variable}}
+  A(i);
+}
+
 namespace rdar29067894 {
 
 void avoidWarningWhenRedefining(int b) { // expected-note {{previous definition is here}}
@@ -199,13 +206,13 @@
   using l=char; // no warning or error.
   using l=char; // no warning or error.
   typedef char l; // no warning or error.
- 
-  typedef char n; // no warning or error. 
+
+  typedef char n; // no warning or error.
   typedef char n; // no warning or error.
   using n=char; // no warning or error.
 }
 
-}
+} // namespace rdar29067894
 
 extern "C" {
 typedef int externC; // expected-note {{previous declaration is here}}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6946,6 +6946,10 @@
 void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
const LookupResult &R) {
   DeclContext *NewDC = D->getDeclContext();
+  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
+
+  if (D->getLocation().isMacroID() && NewDC != OldDC)
+return;
 
   if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
 // Fields are not shadowed by variables in C++ static methods.
@@ -6975,8 +6979,6 @@
 }
 }
 
-  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
-
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
   if (isa(D) && isa(ShadowedDecl) && NewDC &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35783: Ignore shadowing for declarations coming from within macros.

2017-07-24 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Like this?


https://reviews.llvm.org/D35783



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 107886.
gamesh411 added a comment.

Fixed the naming convention issues. Also applied the suggested modifications 
inside the overridden checker method.


https://reviews.llvm.org/D33672

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
  test/Analysis/enum-cast-out-of-range.cpp

Index: test/Analysis/enum-cast-out-of-range.cpp
===
--- /dev/null
+++ test/Analysis/enum-cast-out-of-range.cpp
@@ -0,0 +1,181 @@
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=alpha.cplusplus.EnumCastOutOfRange -verify %s
+
+enum unscoped_unspecified_t {
+  unscoped_unspecified_0 = -4,
+  unscoped_unspecified_1,
+  unscoped_unspecified_2 = 1,
+  unscoped_unspecified_3,
+  unscoped_unspecified_4 = 4
+};
+
+enum unscoped_specified_t : int {
+  unscoped_specified_0 = -4,
+  unscoped_specified_1,
+  unscoped_specified_2 = 1,
+  unscoped_specified_3,
+  unscoped_specified_4 = 4
+};
+
+enum class scoped_unspecified_t {
+  scoped_unspecified_0 = -4,
+  scoped_unspecified_1,
+  scoped_unspecified_2 = 1,
+  scoped_unspecified_3,
+  scoped_unspecified_4 = 4
+};
+
+enum class scoped_specified_t : int {
+  scoped_specified_0 = -4,
+  scoped_specified_1,
+  scoped_specified_2 = 1,
+  scoped_specified_3,
+  scoped_specified_4 = 4
+};
+
+void unscopedUnspecified() {
+  unscoped_unspecified_t InvalidBeforeRangeBegin = static_cast(-5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_unspecified_t ValidNegativeValue1 = static_cast(-4); // OK.
+  unscoped_unspecified_t ValidNegativeValue2 = static_cast(-3); // OK.
+  unscoped_unspecified_t InvalidInsideRange1 = static_cast(-2); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_unspecified_t InvalidInsideRange2 = static_cast(-1); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_unspecified_t InvalidInsideRange3 = static_cast(0); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_unspecified_t ValidPositiveValue1 = static_cast(1); // OK.
+  unscoped_unspecified_t ValidPositiveValue2 = static_cast(2); // OK.
+  unscoped_unspecified_t InvalidInsideRange4 = static_cast(3); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_unspecified_t ValidPositiveValue3 = static_cast(4); // OK.
+  unscoped_unspecified_t InvalidAfterRangeEnd = static_cast(5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+}
+
+void unscopedSpecified() {
+  unscoped_specified_t InvalidBeforeRangeBegin = static_cast(-5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_specified_t ValidNegativeValue1 = static_cast(-4); // OK.
+  unscoped_specified_t ValidNegativeValue2 = static_cast(-3); // OK.
+  unscoped_specified_t InvalidInsideRange1 = static_cast(-2); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_specified_t InvalidInsideRange2 = static_cast(-1); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_specified_t InvalidInsideRange3 = static_cast(0); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_specified_t ValidPositiveValue1 = static_cast(1); // OK.
+  unscoped_specified_t ValidPositiveValue2 = static_cast(2); // OK.
+  unscoped_specified_t InvalidInsideRange4 = static_cast(3); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  unscoped_specified_t ValidPositiveValue3 = static_cast(4); // OK.
+  unscoped_specified_t InvalidAfterRangeEnd = static_cast(5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+}
+
+void scopedUnspecified() {
+  scoped_unspecified_t InvalidBeforeRangeBegin = static_cast(-5); // expected-warning{{The value provided to the cast expression is not in the valid range of values for the enum}}
+  scoped_unspecified_t ValidNegativeValue1 = static_cast(-4); // OK.
+  scoped_unspecified_t ValidNegativeValue2 = static_cast(-3); // OK.
+  scoped_unspecified_t InvalidInsideRange1 = static_cast(-2); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+  scoped_unspecified_t InvalidInsideRange2 = static_cast(-1); // expected-warning {{The value provide

[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-07-24 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added a comment.

ping


https://reviews.llvm.org/D34878



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


r308867 - [X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the two collides

2017-07-24 Thread Coby Tayree via cfe-commits
Author: coby
Date: Mon Jul 24 00:06:37 2017
New Revision: 308867

URL: http://llvm.org/viewvc/llvm-project?rev=308867&view=rev
Log:
[X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the 
two collides

On MS-style, the following snippet:

int eax;
__asm mov eax, ebx

should yield loading of ebx, into the location pointed by the variable eax

This patch sees to it.

Currently, a reg-to-reg move would have been invoked.

llvm: D34739

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

Added:
cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c   (with props)

Added: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c?rev=308867&view=auto
==
--- cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c (added)
+++ cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c Mon Jul 24 00:06:37 2017
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - 
| FileCheck %s
+
+void t() {
+  int eax;
+  int Ecx;
+  __asm mov eax, ebx
+  // CHECK: mov $0, ebx
+  __asm add ecx, Ecx
+  // CHECK: add ecx, $1
+}
+

Propchange: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
--
svn:eol-style = native

Propchange: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
--
svn:mime-type = text/plain


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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 2 inline comments as done.
gamesh411 added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:104
+  // Check whether the cast type is an enum.
+  const auto ED = dyn_cast_or_null(T->getAsTagDecl());
+  // If it is not an enum, we skip.

xazax.hun wrote:
> You could do something like T->getAs() directly without repeated 
> cast. 
Cannot get it with something like T->getAs() because T is a QualType, 
and it has an EnumDecl if it is an EnumeralType (note that it potentially has 
the Decl, not is the Decl). However the suggestion helped me refactor the 
method to make it more readable (see in the new diff).


https://reviews.llvm.org/D33672



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added reviewers: dcoughlin, NoQ, a.sidorin.
xazax.hun added a comment.
This revision is now accepted and ready to land.

Looks good to me. Did you run it on a codebase to check the results?


https://reviews.llvm.org/D33672



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


[PATCH] D35483: clang-format: fix block OpeningLineIndex around preprocessor

2017-07-24 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added inline comments.



Comment at: lib/Format/UnwrappedLineParser.cpp:464
+  for (const auto &i : PPStack) {
+hash_combine(h, i.Kind);
+hash_combine(h, i.Line);

krasimir wrote:
> When I patch this, I get an `UnwrappedLineParser.cpp:457:16 error: implicit 
> instantiation of undefined template 
> 'std::hash'`. 
Seems to work fine with latest Ubuntu, but not on macos.


https://reviews.llvm.org/D35483



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


[PATCH] D35796: [analyzer] Misused polymorphic object checker

2017-07-24 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs created this revision.
Herald added subscribers: baloghadamsoftware, xazax.hun, whisperity, mgorny.

This check warns if a derived type object is deleted through a base pointer 
with a non-virtual destructor in its base class. It also places a note at the 
last point where the derived-to-base conversion happened.

Corresponding CERT rule: OOP52-CPP: Do not delete a polymorphic object without 
a virtual destructor. 



https://reviews.llvm.org/D35796

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/MisusedPolymorphicObjectChecker.cpp
  test/Analysis/MisusedPolymorphicObject.cpp

Index: test/Analysis/MisusedPolymorphicObject.cpp
===
--- /dev/null
+++ test/Analysis/MisusedPolymorphicObject.cpp
@@ -0,0 +1,168 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.PolymorphicDtorNotCalled -std=c++11 -verify -analyzer-output=text %s
+
+struct Virtual {
+  virtual ~Virtual() {}
+};
+
+struct VDerived : public Virtual {};
+
+struct NonVirtual {
+  ~NonVirtual() {}
+};
+
+struct NVDerived : public NonVirtual {};
+struct NVDoubleDerived : public NVDerived {};
+
+struct ImplicitNV {
+  virtual void f();
+};
+
+struct ImplicitNVDerived : public ImplicitNV {};
+
+NVDerived *get();
+
+NonVirtual *create() {
+  NonVirtual *x = new NVDerived(); // expected-note{{Derived-to-base conversion happened here}}
+  return x;
+}
+
+void sink(NonVirtual *x) {
+  delete x; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void sinkCast(NonVirtual *y) {
+  delete reinterpret_cast(y);
+}
+
+void sinkParamCast(NVDerived *z) {
+  delete z;
+}
+
+void singleDerived() {
+  NonVirtual *sd;
+  sd = new NVDerived(); // expected-note{{Derived-to-base conversion happened here}}
+  delete sd; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void singleDerivedArr() {
+  NonVirtual *sda = new NVDerived[5]; // expected-note{{Derived-to-base conversion happened here}}
+  delete[] sda; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void doubleDerived() {
+  NonVirtual *dd = new NVDoubleDerived(); // expected-note{{Derived-to-base conversion happened here}}
+  delete (dd); // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void assignThroughFunction() {
+  NonVirtual *atf = get(); // expected-note{{Derived-to-base conversion happened here}}
+  delete atf; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void assignThroughFunction2() {
+  NonVirtual *atf2;
+  atf2 = get(); // expected-note{{Derived-to-base conversion happened here}}
+  delete atf2; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void createThroughFunction() {
+  NonVirtual *ctf = create(); // expected-note{{Calling 'create'}}
+  // expected-note@-1{{Returning from 'create'}}
+  delete ctf; // expected-warning {{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void deleteThroughFunction() {
+  NonVirtual *dtf = new NVDerived(); // expected-note{{Derived-to-base conversion happened here}}
+  sink(dtf); // expected-note{{Calling 'sink'}}
+}
+
+void singleCastCStyle() {
+  NVDerived *sccs = new NVDerived();
+  NonVirtual *sccs2 = (NonVirtual*)sccs; // expected-note{{Derived-to-base conversion happened here}}
+  delete sccs2; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  // expected-note@-1{{Polymorphic object without virtual destructor deleted through base pointer}}
+}
+
+void doubleCastCStyle() {
+  NonVirtual *dccs = new NVDerived();
+  NVDerived *dccs2 = (NVDerived*)dccs;
+  dccs = (NonVirtual*)dccs2; // expected-note{{Derived-to-base conversion happened here}}
+  delete dccs; // expected-warning{{Polymorphic object without virtual destructor deleted through base pointer}}
+  //

[PATCH] D35735: [ubsan] Null-check pointers in -fsanitize=vptr (PR33881)

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: test/CodeGenCXX/ubsan-devirtualized-calls.cpp:67
   static_cast(badp)->f1(); //< No devirt, test 'badp isa Base1'.
+  // We were able to skip the null check on the first type check becuase 'p'
+  // is backed by an alloca. We can't skip the second null check because 'badp'

NIT: because



Comment at: test/CodeGenCXX/ubsan-type-checks.cpp:5
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s 
-fsanitize=null,vptr | FileCheck %s -check-prefixes=VPTR
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s 
-fsanitize=vptr | FileCheck %s -check-prefixes=NOVPTR
 

You might want to check that the vptr type check is still emitted without 
-fsanitize=null when `PtrToAlloca` is true, because it doesn't look that 
scenario is tested.


https://reviews.llvm.org/D35735



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


[PATCH] D16403: Add scope information to CFG for If/While/For/Do/Compound/CXXRangeFor statements

2017-07-24 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 107894.
m.ostapenko added a comment.

Rebased and removed a bunch of stale changes. Also added a check for goto's: if 
we see GotoStmt and have cfg-scopes == true, make badCFG = true and retry 
without scopes enabled. This check will be removed once GotoStmt will become 
supported.


Repository:
  rL LLVM

https://reviews.llvm.org/D16403

Files:
  include/clang/Analysis/AnalysisContext.h
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/scopes-cfg-output.cpp

Index: test/Analysis/scopes-cfg-output.cpp
===
--- /dev/null
+++ test/Analysis/scopes-cfg-output.cpp
@@ -0,0 +1,1099 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-scopes=true %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+class A {
+public:
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  A() {}
+
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  ~A() {}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2: 1
+// CHECK-NEXT:   3: return [B1.2];
+// CHECK-NEXT:   4: CFGScopeEnd(ReturnStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  operator int() const { return 1; }
+};
+
+int getX();
+extern const bool UV;
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: a
+// CHECK-NEXT:   5: [B1.4] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   6: const A &b = a;
+// CHECK-NEXT:   7: A() (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: [B1.7] (BindTemporary)
+// CHECK-NEXT:   9: [B1.8] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:  10: [B1.9]
+// CHECK-NEXT:  11: const A &c = A();
+// CHECK-NEXT:  12: [B1.11].~A() (Implicit destructor)
+// CHECK-NEXT:  13: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  14: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+void test_const_ref() {
+  A a;
+  const A& b = a;
+  const A& c = A();
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A [2])
+// CHECK-NEXT:   3: A a[2];
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A [0])
+// CHECK-NEXT:   5: A b[0];
+// CHECK-NEXT:   6: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   5:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   6: A c;
+// CHECK-NEXT:   7:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: A d;
+// CHECK-NEXT:   9: [B1.8].~A() (Implicit destructor)
+// CHECK-NEXT:  10: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:  11:  (CXXConstructExpr, class A)
+// CHECK-NEXT:  12: A b;
+// CHECK-NEXT:  13: [B1.12].~A() (Implicit destructor)
+// CHECK-NEXT:  14: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  15: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:  16: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+void test_scope() {
+  A a;
+  { A c;
+A d;
+  }
+  A b;
+}
+
+// CHECK:  [B4 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:  [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(IfStmt)
+// CHECK-NEXT:   2: return;
+// CHECK-NEXT:   3: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(ReturnStmt)
+// CHECK-NEXT:   Preds

[PATCH] D35736: [ubsan] -fsanitize=vptr now requires -fsanitize=null, update tests

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D35736



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


[PATCH] D35735: [ubsan] Null-check pointers in -fsanitize=vptr (PR33881)

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

You might also want to mention the fact that `-fsanitizer=vptr` requires `null` 
in the release notes.


https://reviews.llvm.org/D35735



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


[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107896.
krasimir added a comment.

- Make the closing brace use the same thing


https://reviews.llvm.org/D35794

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // comment in else\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  /* comment in else */\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Keep the current level if there is an empty line between the comment and
   // the preprocessor directive.
   EXPECT_EQ("void f() {\n"
@@ -912,8 +954,55 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "// comment in else\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "/* comment in else */\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Align with the preprocessor directive if the comment was originally aligned
-  // with the preprocessor directive.
+  // with the preprocessor directive and there is no newline between the comment
+  // and the preprocessor directive.
   EXPECT_EQ("void f() {\n"
 "  int i;\n"
 "/* comment */\n"
@@ -945,6 +1034,48 @@
"  int j;\n"
"#endif\n"
"}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " // comment in else\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " /* comment in else */\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+ 

r308879 - [mips] Add support for -m(no-)extern-data.

2017-07-24 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Mon Jul 24 07:02:09 2017
New Revision: 308879

URL: http://llvm.org/viewvc/llvm-project?rev=308879&view=rev
Log:
[mips] Add support for -m(no-)extern-data.

Add support for -m(no-)extern-data when using -mgpopt in the driver. It is
enabled by default in the backend.

Reviewers: atanasyan, slthakur

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/mips-features.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=308879&r1=308878&r2=308879&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Jul 24 07:02:09 2017
@@ -2045,6 +2045,12 @@ def mlocal_sdata : Flag<["-"], "mlocal-s
   HelpText<"Extend the -G behaviour to object local data (MIPS)">;
 def mno_local_sdata : Flag<["-"], "mno-local-sdata">, Group,
   HelpText<"Do not extend the -G behaviour to object local data (MIPS)">;
+def mextern_sdata : Flag<["-"], "mextern-sdata">, Group,
+  HelpText<"Assume that externally defined data is in the small data if it"
+   " meets the -G  threshold (MIPS)">;
+def mno_extern_sdata : Flag<["-"], "mno-extern-sdata">, Group,
+  HelpText<"Do not assume that externally defined data is in the small data if"
+   " it meets the -G  threshold (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group;
 def mabicalls : Flag<["-"], "mabicalls">, Group,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=308879&r1=308878&r2=308879&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jul 24 07:02:09 2017
@@ -1483,6 +1483,8 @@ void Clang::AddMIPSTargetArgs(const ArgL
 
 Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
   options::OPT_mno_local_sdata);
+Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata,
+  options::OPT_mno_extern_sdata);
 if (LocalSData) {
   CmdArgs.push_back("-mllvm");
   if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
@@ -1493,6 +1495,15 @@ void Clang::AddMIPSTargetArgs(const ArgL
   LocalSData->claim();
 }
 
+if (ExternSData) {
+  CmdArgs.push_back("-mllvm");
+  if (ExternSData->getOption().matches(options::OPT_mextern_sdata)) {
+CmdArgs.push_back("-mextern-sdata=1");
+  } else {
+CmdArgs.push_back("-mextern-sdata=0");
+  }
+  ExternSData->claim();
+}
   } else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
 

Modified: cfe/trunk/test/Driver/mips-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-features.c?rev=308879&r1=308878&r2=308879&view=diff
==
--- cfe/trunk/test/Driver/mips-features.c (original)
+++ cfe/trunk/test/Driver/mips-features.c Mon Jul 24 07:02:09 2017
@@ -50,6 +50,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
 // CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
 //
+// -mno-abicalls -mgpopt -mextern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 
-mno-extern-sdata -mextern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATA %s
+// CHECK-MEXTERNSDATA: "-mllvm" "-mextern-sdata=1"
+//
+// -mno-abicalls -mgpopt -mno-extern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 
-mextern-sdata -mno-extern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOEXTERNSDATA %s
+// CHECK-MNOEXTERNSDATA: "-mllvm" "-mextern-sdata=0"
+//
+// -mno-abicalls -mgpopt
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATADEF %s
+// CHECK-MEXTERNSDATADEF-NOT: "-mllvm" "-mextern-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \


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


[PATCH] D35550: [mips] Add support for -m(no-)extern-data.

2017-07-24 Thread Simon Dardis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308879: [mips] Add support for -m(no-)extern-data. (authored 
by sdardis).

Changed prior to commit:
  https://reviews.llvm.org/D35550?vs=107073&id=107897#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35550

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/mips-features.c


Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -50,6 +50,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
 // CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
 //
+// -mno-abicalls -mgpopt -mextern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 
-mno-extern-sdata -mextern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATA %s
+// CHECK-MEXTERNSDATA: "-mllvm" "-mextern-sdata=1"
+//
+// -mno-abicalls -mgpopt -mno-extern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 
-mextern-sdata -mno-extern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOEXTERNSDATA %s
+// CHECK-MNOEXTERNSDATA: "-mllvm" "-mextern-sdata=0"
+//
+// -mno-abicalls -mgpopt
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATADEF %s
+// CHECK-MEXTERNSDATADEF-NOT: "-mllvm" "-mextern-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -1483,6 +1483,8 @@
 
 Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
   options::OPT_mno_local_sdata);
+Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata,
+  options::OPT_mno_extern_sdata);
 if (LocalSData) {
   CmdArgs.push_back("-mllvm");
   if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
@@ -1493,6 +1495,15 @@
   LocalSData->claim();
 }
 
+if (ExternSData) {
+  CmdArgs.push_back("-mllvm");
+  if (ExternSData->getOption().matches(options::OPT_mextern_sdata)) {
+CmdArgs.push_back("-mextern-sdata=1");
+  } else {
+CmdArgs.push_back("-mextern-sdata=0");
+  }
+  ExternSData->claim();
+}
   } else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
 
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2045,6 +2045,12 @@
   HelpText<"Extend the -G behaviour to object local data (MIPS)">;
 def mno_local_sdata : Flag<["-"], "mno-local-sdata">, Group,
   HelpText<"Do not extend the -G behaviour to object local data (MIPS)">;
+def mextern_sdata : Flag<["-"], "mextern-sdata">, Group,
+  HelpText<"Assume that externally defined data is in the small data if it"
+   " meets the -G  threshold (MIPS)">;
+def mno_extern_sdata : Flag<["-"], "mno-extern-sdata">, Group,
+  HelpText<"Do not assume that externally defined data is in the small data if"
+   " it meets the -G  threshold (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group;
 def mabicalls : Flag<["-"], "mabicalls">, Group,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;


Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -50,6 +50,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
 // CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
 //
+// -mno-abicalls -mgpopt -mextern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt -mno-extern-sdata -mextern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATA %s
+// CHECK-MEXTERNSDATA: "-mllvm" "-mextern-sdata=1"
+//
+// -mno-abicalls -mgpopt -mno-extern-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt -mextern-sdata -mno-extern-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOEXTERNSDATA %s
+// CHECK-MNOEXTERNSDATA: "-mllvm" "-mextern-sdata=0"
+//
+// -mno-abicalls -mgpopt
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEXTERNSDATADEF %s
+// CHECK-MEXTERNSDATADEF-NOT: "-mllvm" "-mextern-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \
Ind

[libcxx] r308880 - make sure that we don't call basic_streambuf::gbump with a value bigger than INT_MAX, since it only takes an int. Related to, but not quite the same as PR33725

2017-07-24 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jul 24 07:05:10 2017
New Revision: 308880

URL: http://llvm.org/viewvc/llvm-project?rev=308880&view=rev
Log:
make sure that we don't call basic_streambuf::gbump with a value bigger than 
INT_MAX, since it only takes an int. Related to, but not quite the same as 
PR33725

Modified:
libcxx/trunk/include/streambuf

Modified: libcxx/trunk/include/streambuf
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/streambuf?rev=308880&r1=308879&r2=308880&view=diff
==
--- libcxx/trunk/include/streambuf (original)
+++ libcxx/trunk/include/streambuf Mon Jul 24 07:05:10 2017
@@ -404,7 +404,8 @@ basic_streambuf<_CharT, _Traits>::xsgetn
 {
 if (__ninp_ < __einp_)
 {
-const streamsize __len = _VSTD::min(__einp_ - __ninp_, __n - __i);
+const streamsize __len = 
_VSTD::min(static_cast(INT_MAX),
+_VSTD::min(__einp_ - __ninp_, __n - __i));
 traits_type::copy(__s, __ninp_, __len);
 __s +=  __len;
 __i +=  __len;


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


[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-24 Thread Sumanth Gundapaneni via Phabricator via cfe-commits
sgundapa added a comment.

> "Should this just be part of the tuning for the hexagon backend and not 
> options at all"

This will be useful to all the backends/archs that support a tightly coupled 
memory.
AFAIK, hexagon is not the only target that has a TCM.


https://reviews.llvm.org/D35577



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


[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107900.
krasimir added a comment.

- Switch to relative levels


https://reviews.llvm.org/D35794

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // comment in else\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  /* comment in else */\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Keep the current level if there is an empty line between the comment and
   // the preprocessor directive.
   EXPECT_EQ("void f() {\n"
@@ -912,8 +954,55 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "// comment in else\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "/* comment in else */\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Align with the preprocessor directive if the comment was originally aligned
-  // with the preprocessor directive.
+  // with the preprocessor directive and there is no newline between the comment
+  // and the preprocessor directive.
   EXPECT_EQ("void f() {\n"
 "  int i;\n"
 "/* comment */\n"
@@ -945,6 +1034,48 @@
"  int j;\n"
"#endif\n"
"}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " // comment in else\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " /* comment in else */\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+ 

[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107901.
krasimir added a comment.

- Remove unused import


https://reviews.llvm.org/D35794

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // comment in else\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  /* comment in else */\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Keep the current level if there is an empty line between the comment and
   // the preprocessor directive.
   EXPECT_EQ("void f() {\n"
@@ -912,8 +954,55 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "// comment in else\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "/* comment in else */\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Align with the preprocessor directive if the comment was originally aligned
-  // with the preprocessor directive.
+  // with the preprocessor directive and there is no newline between the comment
+  // and the preprocessor directive.
   EXPECT_EQ("void f() {\n"
 "  int i;\n"
 "/* comment */\n"
@@ -945,6 +1034,48 @@
"  int j;\n"
"#endif\n"
"}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " // comment in else\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " /* comment in else */\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+  

[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg




Comment at: lib/Format/UnwrappedLineParser.h:126
   bool eof() const;
-  void nextToken();
+  // LevelDifference is the difference of levels after and before this token.
+  // For example:

s/this token/the current token/
"This token" can be interpreted as the one nextToken reads otherwise.


https://reviews.llvm.org/D35794



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


[PATCH] D35726: unguarded availability: add a fixit for the "annotate '...' with an availability attribute to silence" note

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 3 inline comments as done.
arphaman added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:7230
+return;
+  for (const auto &M : S.getPreprocessor().macros()) {
+if (M.first->getName() != "API_AVAILABLE")

erik.pilkington wrote:
> Its unfortunate to loop over every macro. Can we use 
> Preprocessor::getMacroDefinition()?
Good call.



Comment at: lib/Sema/SemaDeclAttr.cpp:7231
+  for (const auto &M : S.getPreprocessor().macros()) {
+if (M.first->getName() != "API_AVAILABLE")
+  continue;

erik.pilkington wrote:
> It would be nice if we could recommend using this macro even if it isn't 
> defined, as users might not have included the  header. 
> Maybe we can do that on apple platforms, noting that the the macro is 
> declared in os/availability.h if it isn't already defined?
I think we either have to go the full way (i.e. have an `#include 
` fixit inserted as well) or just avoid any fixits. Note 
that these fixits will be used pretty much only in Xcode which doesn't show any 
notes that don't have fixits, so an additional note wouldn't make sense. We 
could potentially change the message of `note_partial_availability_silence` but 
I doubt it's that useful.



Comment at: lib/Sema/SemaDeclAttr.cpp:7240
+FixitNoteDiag << FixItHint::CreateInsertion(
+Enclosing->getLocStart(), (llvm::Twine("API_AVAILABLE(") +
+   PlatformName + "(" + Introduced + 
"))\n")

erik.pilkington wrote:
> I was somewhat uncertain about adding a fixit for this because its difficult 
> to determine where exactly the availability attribute should go, it looks 
> like this doesn't emit an attribute at the right place for this, for example. 
> (It should go after the meth)
> ```
> @interface X
> -(new_int)meth;
> @end
> ```
> Maybe we can do better if we look at what Enclosing actually declares? It's 
> not worth it to emit an incorrect fixit.
Yeah, Good point.


Repository:
  rL LLVM

https://reviews.llvm.org/D35726



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


[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-07-24 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi added a comment.

Ping.


https://reviews.llvm.org/D34030



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


[PATCH] D35726: unguarded availability: add a fixit for the "annotate '...' with an availability attribute to silence" note

2017-07-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 107903.
arphaman marked 2 inline comments as done.
arphaman added a comment.

Addressed Erik's comments


Repository:
  rL LLVM

https://reviews.llvm.org/D35726

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/FixIt/fixit-availability.c
  test/FixIt/fixit-availability.mm

Index: test/FixIt/fixit-availability.mm
===
--- test/FixIt/fixit-availability.mm
+++ test/FixIt/fixit-availability.mm
@@ -109,3 +109,28 @@
   anotherFunction(y);
   anotherFunction(x);
 }
+
+#define API_AVAILABLE(X) __attribute__((availability(macos, introduced=10.12))) // dummy macro
+
+API_AVAILABLE(macos(10.12))
+@interface NewClass
+@end
+
+@interface OldButOfferFixit
+@property(copy) NewClass *prop;
+// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:1-[[@LINE-2]]:1}:"API_AVAILABLE(macos(10.12))\n"
+
+- (NewClass *)fixitMe;
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:22-[[@LINE-1]]:22}:" API_AVAILABLE(macos(10.12))"
+@end
+
+void oldButOfferFixitFn(NewClass *) {
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"API_AVAILABLE(macos(10.12))\n"
+}
+
+// Avoid a fixit for declarations that already have an attribute:
+__attribute__((availability(macos, introduced=10.11)))
+@interface WithoutFixit
+@property(copy) NewClass *prop;
+// CHECK-NOT: API_AVAILABLE
+@end
Index: test/FixIt/fixit-availability.c
===
--- test/FixIt/fixit-availability.c
+++ test/FixIt/fixit-availability.c
@@ -8,3 +8,11 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (__builtin_available(macOS 10.12, *)) {\n  "
 // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n  } else {\n  // Fallback on earlier versions\n  }"
 }
+
+__attribute__((availability(macos, introduced=10.12)))
+struct New { };
+
+struct NoFixit {
+  struct New field;
+};
+// CHECK-NOT: API_AVAILABLE
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7032,6 +7032,37 @@
   return dyn_cast(OrigCtx);
 }
 
+namespace {
+
+struct AttributeInsertion {
+  StringRef Prefix;
+  SourceLocation Loc;
+  StringRef Suffix;
+
+  static AttributeInsertion createInsertionAfter(const NamedDecl *D) {
+return {" ", D->getLocEnd(), ""};
+  }
+  static AttributeInsertion createInsertionBefore(const NamedDecl *D) {
+return {"", D->getLocStart(), "\n"};
+  }
+};
+
+} // end anonymous namespace
+
+/// Returns a source location in which it's appropriate to insert a new
+/// attribute for the given declaration \D.
+static Optional
+createAttributeInsertion(const NamedDecl *D) {
+  if (isa(D))
+return AttributeInsertion::createInsertionAfter(D);
+  if (const auto *MD = dyn_cast(D)) {
+if (MD->hasBody())
+  return None;
+return AttributeInsertion::createInsertionAfter(D);
+  }
+  return AttributeInsertion::createInsertionBefore(D);
+}
+
 /// Actually emit an availability diagnostic for a reference to an unavailable
 /// decl.
 ///
@@ -7221,8 +7252,30 @@
   << /*Anonymous*/1 << TD->getKindName();
   return;
 }
-  S.Diag(Enclosing->getLocation(), diag::note_partial_availability_silence)
-  << /*Named*/0 << Enclosing;
+  auto FixitNoteDiag = S.Diag(Enclosing->getLocation(),
+  diag::note_partial_availability_silence)
+   << /*Named*/ 0 << Enclosing;
+  // Don't offer a fixit for declarations with availability attributes.
+  if (Enclosing->hasAttr())
+return;
+  if (!S.getPreprocessor().getMacroDefinition(
+  &S.getASTContext().Idents.get("API_AVAILABLE")))
+return;
+  Optional Insertion =
+  createAttributeInsertion(Enclosing);
+  if (!Insertion)
+return;
+  std::string PlatformName =
+  AvailabilityAttr::getPlatformNameSourceSpelling(
+  S.getASTContext().getTargetInfo().getPlatformName())
+  .lower();
+  std::string Introduced =
+  OffendingDecl->getVersionIntroduced().getAsString();
+  FixitNoteDiag << FixItHint::CreateInsertion(
+  Insertion->Loc,
+  (llvm::Twine(Insertion->Prefix) + "API_AVAILABLE(" + PlatformName +
+   "(" + Introduced + "))" + Insertion->Suffix)
+  .str());
 }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107904.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D35794

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // comment in else\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  /* comment in else */\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Keep the current level if there is an empty line between the comment and
   // the preprocessor directive.
   EXPECT_EQ("void f() {\n"
@@ -912,8 +954,55 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "// comment in else\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "/* comment in else */\n"
+   "\n"
+   "#ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
   // Align with the preprocessor directive if the comment was originally aligned
-  // with the preprocessor directive.
+  // with the preprocessor directive and there is no newline between the comment
+  // and the preprocessor directive.
   EXPECT_EQ("void f() {\n"
 "  int i;\n"
 "/* comment */\n"
@@ -945,6 +1034,48 @@
"  int j;\n"
"#endif\n"
"}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " // comment in else\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   "}"));
+
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"/* comment in else */\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   " /* comment in else */\n"
+   " #ifdef A\n"
+   "j++;\n"
+   "#endif\n"
+   "  }\n"
+   

r308882 - [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Jul 24 07:51:59 2017
New Revision: 308882

URL: http://llvm.org/viewvc/llvm-project?rev=308882&view=rev
Log:
[clang-format] Fix comment levels between '} else {' and PPDirective.

Summary:
This fixes a regression exposed by r307795 and rL308725 in which the level of a
comment line between '} else {' and a preprocessor directive is incorrectly set
as the level of the '} else {' line. For example, this :
```
int f(int i) {
  if (i) {
++i;
  } else {
// comment
#ifdef A
--i;
#endif
  }
}
```
was formatted as:
```
int f(int i) {
  if (i) {
++i;
  } else {
  // comment
#ifdef A
--i;
#endif
  }
}
```

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=308882&r1=308881&r2=308882&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jul 24 07:51:59 2017
@@ -2820,7 +2820,7 @@ bool TokenAnnotator::canBreakBefore(cons
 }
 
 void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
-  llvm::errs() << "AnnotatedTokens:\n";
+  llvm::errs() << "AnnotatedTokens(L=" << Line.Level << "):\n";
   const FormatToken *Tok = Line.First;
   while (Tok) {
 llvm::errs() << " M=" << Tok->MustBreakBefore

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=308882&r1=308881&r2=308882&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jul 24 07:51:59 2017
@@ -460,7 +460,7 @@ void UnwrappedLineParser::parseBlock(boo
   FormatTok->BlockKind = BK_Block;
 
   unsigned InitialLevel = Line->Level;
-  nextToken();
+  nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -486,9 +486,8 @@ void UnwrappedLineParser::parseBlock(boo
 return;
   }
 
-  flushComments(isOnNewLine(*FormatTok));
-  Line->Level = InitialLevel;
-  nextToken(); // Munch the closing brace.
+  // Munch the closing brace.
+  nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -496,6 +495,7 @@ void UnwrappedLineParser::parseBlock(boo
   if (MunchSemi && FormatTok->Tok.is(tok::semi))
 nextToken();
   Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
+  Line->Level = InitialLevel;
   if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
 // Update the opening line to add the forward reference as well
 (*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
@@ -2288,13 +2288,13 @@ void UnwrappedLineParser::flushComments(
   CommentsBeforeNextToken.clear();
 }
 
-void UnwrappedLineParser::nextToken() {
+void UnwrappedLineParser::nextToken(int LevelDifference) {
   if (eof())
 return;
   flushComments(isOnNewLine(*FormatTok));
   pushToken(FormatTok);
   if (Style.Language != FormatStyle::LK_JavaScript)
-readToken();
+readToken(LevelDifference);
   else
 readTokenWithJavaScriptASI();
 }
@@ -2363,7 +2363,7 @@ void UnwrappedLineParser::distributeComm
   }
 }
 
-void UnwrappedLineParser::readToken() {
+void UnwrappedLineParser::readToken(int LevelDifference) {
   SmallVector Comments;
   do {
 FormatTok = Tokens->getNextToken();
@@ -2376,6 +2376,10 @@ void UnwrappedLineParser::readToken() {
   // directives only after that unwrapped line was finished later.
   bool SwitchToPreprocessorLines = !Line->Tokens.empty();
   ScopedLineState BlockState(*this, SwitchToPreprocessorLines);
+  assert((LevelDifference >= 0 ||
+  static_cast(-LevelDifference) <= Line->Level) &&
+ "LevelDifference makes Line->Level negative");
+  Line->Level += LevelDifference;
   // Comments stored before the preprocessor directive need to be output
   // before the preprocessor directive, at the same level as the
   // preprocessor directive, as we consider them to apply to the directive.

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=308882&r1=308881&r2=308882&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Mon Jul 24 07:51:59 2017
@@ -123,9 +123,13 @@ private:
   void tryToP

r308883 - [OPENMP] Fix the restrictions for in_reduction clause.

2017-07-24 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jul 24 07:52:13 2017
New Revision: 308883

URL: http://llvm.org/viewvc/llvm-project?rev=308883&view=rev
Log:
[OPENMP] Fix the restrictions for in_reduction clause.

This patch allows to use in_reduction clause even if the innermost
directive is not taskgroup.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/task_ast_print.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=308883&r1=308882&r2=308883&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Jul 24 07:52:13 2017
@@ -57,6 +57,10 @@ public:
 DeclRefExpr *PrivateCopy = nullptr;
 SourceLocation ImplicitDSALoc;
 DSAVarData() = default;
+DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, Expr 
*RefExpr,
+   DeclRefExpr *PrivateCopy, SourceLocation ImplicitDSALoc)
+: DKind(DKind), CKind(CKind), RefExpr(RefExpr),
+  PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {}
   };
   typedef llvm::SmallVector, 4>
   OperatorOffsetTy;
@@ -246,12 +250,12 @@ public:
   void addReductionData(ValueDecl *D, SourceRange SR, const Expr 
*ReductionRef);
   /// Returns the location and reduction operation from the innermost parent
   /// region for the given \p D.
-  bool getTopMostReductionData(ValueDecl *D, SourceRange &SR,
-   BinaryOperatorKind &BOK);
+  DSAVarData getTopMostTaskgroupReductionData(ValueDecl *D, SourceRange &SR,
+  BinaryOperatorKind &BOK);
   /// Returns the location and reduction operation from the innermost parent
   /// region for the given \p D.
-  bool getTopMostReductionData(ValueDecl *D, SourceRange &SR,
-   const Expr *&ReductionRef);
+  DSAVarData getTopMostTaskgroupReductionData(ValueDecl *D, SourceRange &SR,
+  const Expr *&ReductionRef);
 
   /// \brief Returns data sharing attributes from top of the stack for the
   /// specified declaration.
@@ -769,48 +773,54 @@ void DSAStackTy::addReductionData(ValueD
   ReductionData.set(ReductionRef, SR);
 }
 
-bool DSAStackTy::getTopMostReductionData(ValueDecl *D, SourceRange &SR,
- BinaryOperatorKind &BOK) {
+DSAStackTy::DSAVarData
+DSAStackTy::getTopMostTaskgroupReductionData(ValueDecl *D, SourceRange &SR,
+ BinaryOperatorKind &BOK) {
   D = getCanonicalDecl(D);
-  assert(!isStackEmpty() && Stack.back().first.size() > 1 &&
- "Data-sharing attributes stack is empty or has only 1 region.");
-  for (auto I = std::next(Stack.back().first.rbegin(), 0),
+  assert(!isStackEmpty() && "Data-sharing attributes stack is empty.");
+  if (Stack.back().first.empty())
+  return DSAVarData();
+  for (auto I = std::next(Stack.back().first.rbegin(), 1),
 E = Stack.back().first.rend();
I != E; std::advance(I, 1)) {
 auto &Data = I->SharingMap[D];
-if (Data.Attributes != OMPC_reduction)
+if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup)
   continue;
 auto &ReductionData = I->ReductionMap[D];
 if (!ReductionData.ReductionOp ||
 ReductionData.ReductionOp.is())
-  return false;
+  return DSAVarData();
 SR = ReductionData.ReductionRange;
 BOK = ReductionData.ReductionOp.get();
-return true;
+return DSAVarData(OMPD_taskgroup, OMPC_reduction, 
Data.RefExpr.getPointer(),
+  Data.PrivateCopy, I->DefaultAttrLoc);
   }
-  return false;
+  return DSAVarData();
 }
 
-bool DSAStackTy::getTopMostReductionData(ValueDecl *D, SourceRange &SR,
- const Expr *&ReductionRef) {
+DSAStackTy::DSAVarData
+DSAStackTy::getTopMostTaskgroupReductionData(ValueDecl *D, SourceRange &SR,
+ const Expr *&ReductionRef) {
   D = getCanonicalDecl(D);
-  assert(!isStackEmpty() && Stack.back().first.size() > 1 &&
- "Data-sharing attributes stack is empty or has only 1 region.");
-  for (auto I = std::next(Stack.back().first.rbegin(), 0),
+  assert(!isStackEmpty() && "Data-sharing attributes stack is empty.");
+  if (Stack.back().first.empty())
+  return DSAVarData();
+  for (auto I = std::next(Stack.back().first.rbegin(), 1),
 E = Stack.back().first.rend();
I != E; std::advance(I, 1)) {
 auto &Data = I->SharingMap[D];
-if (Data.Attributes != OMPC_reduction)
+if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup)
   continue;
 auto &ReductionData = I->ReductionMap[D];
 if (!ReductionData.ReductionOp ||
 !ReductionData.ReductionOp.is())
-  return false;
+  return DSAVarData();
 SR = ReductionData.ReductionRange;
  

[PATCH] D35794: [clang-format] Fix comment levels between '} else {' and PPDirective.

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308882: [clang-format] Fix comment levels between '} else {' 
and PPDirective. (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D35794

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.h
  cfe/trunk/unittests/Format/FormatTestComments.cpp

Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -460,7 +460,7 @@
   FormatTok->BlockKind = BK_Block;
 
   unsigned InitialLevel = Line->Level;
-  nextToken();
+  nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -486,16 +486,16 @@
 return;
   }
 
-  flushComments(isOnNewLine(*FormatTok));
-  Line->Level = InitialLevel;
-  nextToken(); // Munch the closing brace.
+  // Munch the closing brace.
+  nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
   if (MunchSemi && FormatTok->Tok.is(tok::semi))
 nextToken();
   Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
+  Line->Level = InitialLevel;
   if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
 // Update the opening line to add the forward reference as well
 (*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
@@ -2288,13 +2288,13 @@
   CommentsBeforeNextToken.clear();
 }
 
-void UnwrappedLineParser::nextToken() {
+void UnwrappedLineParser::nextToken(int LevelDifference) {
   if (eof())
 return;
   flushComments(isOnNewLine(*FormatTok));
   pushToken(FormatTok);
   if (Style.Language != FormatStyle::LK_JavaScript)
-readToken();
+readToken(LevelDifference);
   else
 readTokenWithJavaScriptASI();
 }
@@ -2363,7 +2363,7 @@
   }
 }
 
-void UnwrappedLineParser::readToken() {
+void UnwrappedLineParser::readToken(int LevelDifference) {
   SmallVector Comments;
   do {
 FormatTok = Tokens->getNextToken();
@@ -2376,6 +2376,10 @@
   // directives only after that unwrapped line was finished later.
   bool SwitchToPreprocessorLines = !Line->Tokens.empty();
   ScopedLineState BlockState(*this, SwitchToPreprocessorLines);
+  assert((LevelDifference >= 0 ||
+  static_cast(-LevelDifference) <= Line->Level) &&
+ "LevelDifference makes Line->Level negative");
+  Line->Level += LevelDifference;
   // Comments stored before the preprocessor directive need to be output
   // before the preprocessor directive, at the same level as the
   // preprocessor directive, as we consider them to apply to the directive.
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2820,7 +2820,7 @@
 }
 
 void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
-  llvm::errs() << "AnnotatedTokens:\n";
+  llvm::errs() << "AnnotatedTokens(L=" << Line.Level << "):\n";
   const FormatToken *Tok = Line.First;
   while (Tok) {
 llvm::errs() << " M=" << Tok->MustBreakBefore
Index: cfe/trunk/lib/Format/UnwrappedLineParser.h
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.h
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h
@@ -123,9 +123,13 @@
   void tryToParseJSFunction();
   void addUnwrappedLine();
   bool eof() const;
-  void nextToken();
+  // LevelDifference is the difference of levels after and before the current
+  // token. For example:
+  // - if the token is '{' and opens a block, LevelDifference is 1.
+  // - if the token is '}' and closes a block, LevelDifference is -1.
+  void nextToken(int LevelDifference = 0);
+  void readToken(int LevelDifference = 0);
   const FormatToken *getPreviousToken();
-  void readToken();
 
   // Decides which comment tokens should be added to the current line and which
   // should be added as comments before the next token.
Index: cfe/trunk/unittests/Format/FormatTestComments.cpp
===
--- cfe/trunk/unittests/Format/FormatTestComments.cpp
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp
@@ -855,6 +855,48 @@
"#endif\n"
"}"));
 
+  EXPECT_EQ("int f(int i) {\n"
+"  if (true) {\n"
+"i++;\n"
+"  } else {\n"
+"// comment in else\n"
+"#ifdef A\n"
+"j++;\n"
+"#endif\n"
+"  }\n"
+"}",
+format("int f(int i) {\n"
+   "  if (true) {\n"
+   "i++;\n"
+   "  } else {\n"
+   "  // commen

[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-24 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D35577#817944, @echristo wrote:

> "Should this just be part of the tuning for the hexagon backend and not 
> options at all"


The ultimate decision as to what kind of code to generate out of a switch 
statement belongs to the customer.  The reasons to choose one way over another 
may involve factors that the compiler has no knowledge of (such as details of 
the target hardware).  I don't think we need separate options to control jump 
tables and lookup tables: one option to enable/disable the use of memory tables 
would be sufficient.


https://reviews.llvm.org/D35577



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


Re: [PATCH] D24933: Enable configuration files in clang

2017-07-24 Thread Serge Pavlov via cfe-commits
I am thinking about reducing the patch further to leave only the ability to
include config file when clang is called as `target-clang-drivermode`. It
is still useful for cross compilation tasks because:
- It is a convenient way to switch between supported targets,
- SDK producer can ship compiler with a set of appropriate options or
prepare them during installation.
In this case if clang is called as `target-clang-drivermode`, it first
tries to find file `target-drivermode.cfg` or `target.cfg` in a set of
well-known directories, which in minimal case includes the directory where
clang executable resides. If such file is found, options are  read from it,
otherwise only option --target is added as clang does it now.

This solution has obvious drawbacks:
- User cannot specify config file in command line in the same way as he can
choose a target: `clang --target `,
- On Windows symlinks are implemented as file copy, the solution looks
awkward.
So more or less complete solution needs to allow specifying config file in
command line.

Using `@file` has some problems. Config file is merely a set of options,
just as file included by `@file`. Different include file search is only a
convenience and could be sacrificed. Comments and unused option warning
suppression could be extended for all files included with `@file`. The real
problem is the search path. To be useful, config files must be searched for
in well-known directories, so that meaning of `clang @config_fille` does
not depend on the current directory. So clang must have some rule to
distinguish between config file and traditional use of `@file`. For
instance, if file name ends with `.cfg` and there is a file with this name
in config search directories, this is a config file and it is interpreted a
bit differently. Of course, the file may be specified with full path, but
this way is inconvenient.

Another possible solution is to extend meaning of `--target` so that it
fully matches with the use of `target-clang-drivermode`, that is the option
`--target=hexagon` causes clang first to look for the file `hexagon.cfg` in
well-known directories and use it if found. In this case treatment of
`--target` is different if the option is specified in command line or in
the content of config file (in the latter case it is processed as target
name only), it may be confusing. Besides, use of config files is not
restricted to the choice of target.

Using special option for config files does not bring risk of compatibility
breakage and does not change meaning of existing options.


Thanks,
--Serge

2017-05-10 11:25 GMT+07:00 Serge Pavlov :

> 2017-05-10 3:46 GMT+07:00 Richard Smith :
>
>> On 1 March 2017 at 02:50, Serge Pavlov via Phabricator <
>> revi...@reviews.llvm.org> wrote:
>>
>>>
>>> Format of configuration file is similar to file used in the construct
>>> `@file`, it is a set of options. Configuration file have advantage over
>>> this construct:
>>>
>>> - it is searched for in well-known places rather than in current
>>> directory,
>>>
>>
>> This (and suppressing unused-argument warnings) might well be sufficient
>> to justify a different command-line syntax rather than @file...
>>
>
> Construct `@file` in this implementation is used only to read parts of
> config file inside containing file. Driver knows that it processes config
> file and can adjust treatment of `@file`. On the other hand, driver might
> parse config files in a more complicated way, for instance, it could treat
> line `# include(file_name)` as a command to include another file.
>
>
>>
>>> - it may contain comments, long options may be split between lines using
>>> trailing backslashes,
>>> - other files may be included by `@file` and they will be resolved
>>> relative to the including file,
>>>
>>
>> ... but I think we should just add these extensions to our @file
>> handling, and then use the exact same syntax and code to handle config
>> files and @file files. That is, the difference between @ and --config would
>> be that the latter looks in a different directory and suppresses "unused
>> argument" warnings, but they would otherwise be identical.
>>
>
> Changing treatment of `@file` can cause compatibility issues, in
> particular, both libiberty and cl resolves file name relative to current
> directory. So driver must deduce that `@file` is used to load config file
> rather than merely to organize arguments. Another difference is that
> `@file` inserts its content in the place where it occurs, while `--config`
> always puts arguments before user specified options. The following
> invocations:
>
> clang --config a.cfg -opt1 -opt2 file1.cpp
> clang -opt1 -opt2 file1.cpp --config a.cfg
>
> are equivalent, but variants with `@file` can have different effect.
>
>
>> - the file may be encoded in executable name,
>>> - unused options from configuration file do not produce warnings.
>>>
>>>
>>> https://reviews.llvm.org/D24933
>>>
>>>
>>>
>>>
>>
>
___
cf

[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-24 Thread Sumanth Gundapaneni via Phabricator via cfe-commits
sgundapa added a comment.

If it is okay for the reviewers, I have no problem using -fno-jump-tables to 
this effect.
I need to update https://reviews.llvm.org/D35578 and 
https://reviews.llvm.org/D35579


https://reviews.llvm.org/D35577



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


[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-24 Thread Chad Rosier via Phabricator via cfe-commits
mcrosier added a comment.

In https://reviews.llvm.org/D35577#818936, @kparzysz wrote:

> In https://reviews.llvm.org/D35577#817944, @echristo wrote:
>
> > "Should this just be part of the tuning for the hexagon backend and not 
> > options at all"
>
>
>
>
>   I don't think we need separate options to control jump tables and lookup 
> tables: one option to enable/disable the use of memory tables would be 
> sufficient.


I don't have an objection to this direction (i.e., disable the lookup-table 
optimization when -fno-jump-tables is specified), so long as other are in 
agreement.


https://reviews.llvm.org/D35577



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-24 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Sorry, I just noticed this weeks later. Why are we adding this to `--version` 
instead of adding some new flag for printing this? When I pass `--version`, I'm 
usually interested in clang's version and don't need a screenful of other 
information below it (which makes the output I do care about scroll off the 
screen).


https://reviews.llvm.org/D33900



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


[PATCH] D35790: [clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation check.

2017-07-24 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Thank you for the fix!


https://reviews.llvm.org/D35790



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-24 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

Here is the current output:

  clang version 5.0.0 
  Target: x86_64-apple-darwin16.6.0
  Thread model: posix
  InstalledDir: /Users/mamini/projects/llvm/./clangDebug/bin
  
Registered Targets:
  aarch64- AArch64 (little endian)
  aarch64_be - AArch64 (big endian)
  amdgcn - AMD GCN GPUs
  arm- ARM
  arm64  - ARM64 (little endian)
  armeb  - ARM (big endian)
  bpf- BPF (host endian)
  bpfeb  - BPF (big endian)
  bpfel  - BPF (little endian)
  hexagon- Hexagon
  lanai  - Lanai
  mips   - Mips
  mips64 - Mips64 [experimental]
  mips64el   - Mips64el [experimental]
  mipsel - Mipsel
  msp430 - MSP430 [experimental]
  nvptx  - NVIDIA PTX 32-bit
  nvptx64- NVIDIA PTX 64-bit
  ppc32  - PowerPC 32
  ppc64  - PowerPC 64
  ppc64le- PowerPC 64 LE
  r600   - AMD GPUs HD2XXX-HD6XXX
  riscv32- 32-bit RISC-V
  riscv64- 64-bit RISC-V
  sparc  - Sparc
  sparcel- Sparc LE
  sparcv9- Sparc V9
  systemz- SystemZ
  thumb  - Thumb
  thumbeb- Thumb (big endian)
  x86- 32-bit X86: Pentium-Pro and above
  x86-64 - 64-bit X86: EM64T and AMD64
  xcore  - XCore

I think @thakis is right: this too verbose to be the default --version.
We likely shouldn't ship this in clang-5.0 (@hans).


https://reviews.llvm.org/D33900



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


[PATCH] D34972: [CodeGen] Propagate dllexport to thunks

2017-07-24 Thread David Majnemer via Phabricator via cfe-commits
majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D34972



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


[PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init

2017-07-24 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

A few more nits.




Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h:68
   bool IgnoreArrays;
+  // Whether fix-its for initializers of fundamental type use literals. Only
+  // effective in C++11 mode. Default is false.

nit: Please add an empty line before the comment.



Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h:68
   bool IgnoreArrays;
+  // Whether fix-its for initializers of fundamental type use literals. Only
+  // effective in C++11 mode. Default is false.

alexfh wrote:
> nit: Please add an empty line before the comment.
"use literals" and "UseAssignment" should be consistent, I guess.



Comment at: 
test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp:38
+  // CHECK-FIXES: T t{};
+  S() {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these fields:

No need for a semicolon here.


https://reviews.llvm.org/D24892



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


[PATCH] D35787: [clang-tidy] Ignore vector in inefficient-vector-operation.

2017-07-24 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Should we look at whether the size is statically known?


https://reviews.llvm.org/D35787



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


[PATCH] D35787: [clang-tidy] Ignore vector in inefficient-vector-operation.

2017-07-24 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D35787#819007, @alexfh wrote:

> Should we look at whether the size is statically known?


(and small enough)


https://reviews.llvm.org/D35787



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


[PATCH] D35726: unguarded availability: add a fixit for the "annotate '...' with an availability attribute to silence" note

2017-07-24 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for working on this!




Comment at: lib/Sema/SemaDeclAttr.cpp:7230
+return;
+  for (const auto &M : S.getPreprocessor().macros()) {
+if (M.first->getName() != "API_AVAILABLE")

arphaman wrote:
> erik.pilkington wrote:
> > Its unfortunate to loop over every macro. Can we use 
> > Preprocessor::getMacroDefinition()?
> Good call.
Looks like there is a convenience function: isMacroDefined(StringRef)



Comment at: lib/Sema/SemaDeclAttr.cpp:7231
+  for (const auto &M : S.getPreprocessor().macros()) {
+if (M.first->getName() != "API_AVAILABLE")
+  continue;

arphaman wrote:
> erik.pilkington wrote:
> > It would be nice if we could recommend using this macro even if it isn't 
> > defined, as users might not have included the  header. 
> > Maybe we can do that on apple platforms, noting that the the macro is 
> > declared in os/availability.h if it isn't already defined?
> I think we either have to go the full way (i.e. have an `#include 
> ` fixit inserted as well) or just avoid any fixits. Note 
> that these fixits will be used pretty much only in Xcode which doesn't show 
> any notes that don't have fixits, so an additional note wouldn't make sense. 
> We could potentially change the message of 
> `note_partial_availability_silence` but I doubt it's that useful.
Ok, I think this is fine.



Comment at: lib/Sema/SemaDeclAttr.cpp:7063
+  }
+  return AttributeInsertion::createInsertionBefore(D);
+}

TagDecls also have a special rule: `struct __attribute__(...) X;`.


Repository:
  rL LLVM

https://reviews.llvm.org/D35726



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


[PATCH] D35757: Work around an MSVC2017 update 3 codegen bug.

2017-07-24 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D35757



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


[PATCH] D35372: [clang-tidy] Add a close-on-exec check on memfd_create() in Android module.

2017-07-24 Thread Yan Wang via Phabricator via cfe-commits
yawanng added a comment.

Ping


https://reviews.llvm.org/D35372



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


r308897 - Work around an MSVC2017 update 3 codegen bug.

2017-07-24 Thread Nico Weber via cfe-commits
Author: nico
Date: Mon Jul 24 09:54:11 2017
New Revision: 308897

URL: http://llvm.org/viewvc/llvm-project?rev=308897&view=rev
Log:
Work around an MSVC2017 update 3 codegen bug.

C2017 update 3 produces a clang that crashes when compiling clang. Disabling
optimizations for StmtProfiler::VisitCXXOperatorCallExpr() makes the crash go
away.

Patch from Bruce Dawson !
https://reviews.llvm.org/D35757

Modified:
cfe/trunk/lib/AST/StmtProfile.cpp

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=308897&r1=308896&r2=308897&view=diff
==
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Mon Jul 24 09:54:11 2017
@@ -1412,6 +1412,15 @@ static Stmt::StmtClass DecodeOperatorCal
   llvm_unreachable("Invalid overloaded operator expression");
 }
 
+#if defined(_MSC_VER)
+#if _MSC_VER == 1911
+// Work around 
https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
+// MSVC 2017 update 3 miscompiles this function, and a clang built with it
+// will crash in stage 2 of a bootstrap build.
+#pragma optimize("", off)
+#endif
+#endif
+
 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
   if (S->isTypeDependent()) {
 // Type-dependent operator calls are profiled like their underlying
@@ -1444,6 +1453,12 @@ void StmtProfiler::VisitCXXOperatorCallE
   ID.AddInteger(S->getOperator());
 }
 
+#if defined(_MSC_VER)
+#if _MSC_VER == 1911
+#pragma optimize("", on)
+#endif
+#endif
+
 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
   VisitCallExpr(S);
 }


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


[PATCH] D35757: Work around an MSVC2017 update 3 codegen bug.

2017-07-24 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

r308897.


https://reviews.llvm.org/D35757



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


[PATCH] D27918: [analyzer] OStreamChecker

2017-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

Hello,

After experimentation the following AST difference between the mock and the 
standard library implementation still stands (which necessitates the special 
handling of the complex manipulators). Example:

  // The different behaviour of the AST is illustrated on the test4 function of 
the test suite:
  //
  // void test4(float f) {
  //   std::cout << std::setprecision(2)
  // << f; // The stream state is chaged, but not restored.
  // } // expected-warning{{Possibly forgotten ostream format modification in 
scope}}
  //
  // The AST of the function with the standard library include
  // (note the wrapping CXXConstructorExpr):
  // |-FunctionDecl 0x5642e3f80b70  line:33:6 test4 'void 
(float)'
  // | |-ParmVarDecl 0x5642e3f80ab0  col:18 used f 'float'
  // | `-CompoundStmt 0x5642e3f818b0 
  // |   `-ExprWithCleanups 0x5642e3f81898  
'std::basic_ostream 
>::__ostream_type':'class std::basic_ostream' lvalue
  // | `-CXXOperatorCallExpr 0x5642e3f81850  
'std::basic_ostream 
>::__ostream_type':'class std::basic_ostream' lvalue
  // |   |-ImplicitCastExpr 0x5642e3f81838  
'std::basic_ostream >::__ostream_type 
&(*)(float)' 
  // |   | `-DeclRefExpr 0x5642e3f817b8  'std::basic_ostream >::__ostream_type &(float)' lvalue CXXMethod 
0x5642e3edf120 'operator<<' 'std::basic_ostream >::__ostream_type &(float)'
  // |   |-CXXOperatorCallExpr 0x5642e3f81270  
'basic_ostream >':'class 
std::basic_ostream' lvalue
  // |   | |-ImplicitCastExpr 0x5642e3f81258  'basic_ostream > &(*)(basic_ostream > &, struct std::_Setprecision)' 
  // |   | | `-DeclRefExpr 0x5642e3f811d0  'basic_ostream > &(basic_ostream > &, struct std::_Setprecision)' lvalue Function 
0x5642e3f6a6e0 'operator<<' 'basic_ostream 
> &(basic_ostream > &, struct 
std::_Setprecision)'
  // |   | |-DeclRefExpr 0x5642e3f80c30  
'std::ostream':'class std::basic_ostream' lvalue Var 0x5642e3f56578 
'cout' 'std::ostream':'class std::basic_ostream'
  // |   | `-CXXConstructExpr 0x5642e3f81198  'struct 
std::_Setprecision' 'void (const struct std::_Setprecision &) throw()' elidable
  // |   |   `-MaterializeTemporaryExpr 0x5642e3f81088  
'const struct std::_Setprecision' lvalue
  // |   | `-ImplicitCastExpr 0x5642e3f81070  'const 
struct std::_Setprecision' 
  // |   |   `-CallExpr 0x5642e3f80d20  'struct 
std::_Setprecision'
  // |   | |-ImplicitCastExpr 0x5642e3f80d08  
'struct std::_Setprecision (*)(int)' 
  // |   | | `-DeclRefExpr 0x5642e3f80c88  'struct 
std::_Setprecision (int)' lvalue Function 0x5642e3f63f70 'setprecision' 'struct 
std::_Setprecision (int)'
  // |   | `-IntegerLiteral 0x5642e3f80cc0  'int' 2
  // |   `-ImplicitCastExpr 0x5642e3f817a0  'float' 

  // | `-DeclRefExpr 0x5642e3f812b8  'float' lvalue ParmVar 
0x5642e3f80ab0 'f' 'float'
  //













   |   | `-IntegerLiteral 
0x5642e3f80cc0  'int' 2
  // The AST of the function with the mock library include
  // |-FunctionDecl 0x55c053dfaa70  line:32:6 test4 'void 
(float)'
  // | |-ParmVarDecl 0x55c053dfa9b0  col:18 used f 'float'
  // | `-CompoundStmt 0x55c053dfb7c0 
  // |   `-ExprWithCleanups 0x55c053dfb7a8  'class 
std::basic_ostream' lvalue
  // | `-CXXOperatorCallExpr 0x55c053dfb760  'class 
std::basic_ostream' lvalue
  // |   |-ImplicitCastExpr 0x55c053dfb748  'class 
std::basic_ostream &(*)(float)' 
  // |   | `-DeclRefExpr 0x55c053dfb6f8  'class 
std::basic_ostream &(float)' lvalue CXXMethod 0x55c053df8120 'operator<<' 
'class std::basic_ostream &(float)'
  // |   |-CXXOperatorCallExpr 0x55c053dfb670  
'basic_ostream':'class std::basic_ostream' lvalue
  // |   | |-ImplicitCastExpr 0x55c053dfb658  'basic_ostream 
&(*)(basic_ostream &, const class std::setprecision_manip &)' 

  // |   |

Re: r308897 - Work around an MSVC2017 update 3 codegen bug.

2017-07-24 Thread Nico Weber via cfe-commits
We probably want this in 5.0.

On Mon, Jul 24, 2017 at 12:54 PM, Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: nico
> Date: Mon Jul 24 09:54:11 2017
> New Revision: 308897
>
> URL: http://llvm.org/viewvc/llvm-project?rev=308897&view=rev
> Log:
> Work around an MSVC2017 update 3 codegen bug.
>
> C2017 update 3 produces a clang that crashes when compiling clang.
> Disabling
> optimizations for StmtProfiler::VisitCXXOperatorCallExpr() makes the
> crash go
> away.
>
> Patch from Bruce Dawson !
> https://reviews.llvm.org/D35757
>
> Modified:
> cfe/trunk/lib/AST/StmtProfile.cpp
>
> Modified: cfe/trunk/lib/AST/StmtProfile.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> StmtProfile.cpp?rev=308897&r1=308896&r2=308897&view=diff
> 
> ==
> --- cfe/trunk/lib/AST/StmtProfile.cpp (original)
> +++ cfe/trunk/lib/AST/StmtProfile.cpp Mon Jul 24 09:54:11 2017
> @@ -1412,6 +1412,15 @@ static Stmt::StmtClass DecodeOperatorCal
>llvm_unreachable("Invalid overloaded operator expression");
>  }
>
> +#if defined(_MSC_VER)
> +#if _MSC_VER == 1911
> +// Work around https://developercommunity.visualstudio.com/content/
> problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
> +// MSVC 2017 update 3 miscompiles this function, and a clang built with it
> +// will crash in stage 2 of a bootstrap build.
> +#pragma optimize("", off)
> +#endif
> +#endif
> +
>  void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
> *S) {
>if (S->isTypeDependent()) {
>  // Type-dependent operator calls are profiled like their underlying
> @@ -1444,6 +1453,12 @@ void StmtProfiler::VisitCXXOperatorCallE
>ID.AddInteger(S->getOperator());
>  }
>
> +#if defined(_MSC_VER)
> +#if _MSC_VER == 1911
> +#pragma optimize("", on)
> +#endif
> +#endif
> +
>  void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
>VisitCallExpr(S);
>  }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-24 Thread Blower, Melanie via cfe-commits
@jyknight I've removed the check on nostdinc.  AFAIK, I've addressed all the 
feedback which I've received on the patch, is it OK to commit?  --Melanie

-Original Message-
From: James Y Knight via Phabricator [mailto:revi...@reviews.llvm.org] 
Sent: Monday, July 10, 2017 11:57 AM
To: Blower, Melanie ; zhangsheng...@huawei.com; 
olivier...@gmail.com; kalinichev.s...@gmail.com; kf...@kde.org; 
m...@milianw.de; Keane, Erich ; 
hahnf...@itc.rwth-aachen.de; mgo...@gentoo.org; fedor.serg...@oracle.com; 
rich...@metafoo.co.uk; renato.go...@linaro.org
Cc: jykni...@google.com; ibiryu...@google.com; cfe-commits@lists.llvm.org; 
kli...@google.com; simon.dar...@imgtec.com; anastasia.stul...@arm.com; 
arichardson@gmail.com
Subject: [PATCH] D34158: For standards compatibility, preinclude 
 if the file is available

jyknight added a comment.

This version is still disabling upon -nostdinc, which doesn't make sense to me.

You didn't remove that, nor respond explaining why you think it does make sense?


https://reviews.llvm.org/D34158



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


r308898 - AArch64 & ARM: move TargetInfo functions from .h to .cpp file. NFC.

2017-07-24 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Mon Jul 24 10:06:23 2017
New Revision: 308898

URL: http://llvm.org/viewvc/llvm-project?rev=308898&view=rev
Log:
AArch64 & ARM: move TargetInfo functions from .h to .cpp file. NFC.

Most of them are virtual anyway, and the few remaining ones can move to the
.cpp for consistency.

Modified:
cfe/trunk/lib/Basic/Targets/AArch64.cpp
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/Basic/Targets/ARM.cpp
cfe/trunk/lib/Basic/Targets/ARM.h

Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=308898&r1=308897&r2=308898&view=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp Mon Jul 24 10:06:23 2017
@@ -19,6 +19,245 @@
 using namespace clang;
 using namespace clang::targets;
 
+const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#include "clang/Basic/BuiltinsNEON.def"
+
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+   {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#include "clang/Basic/BuiltinsAArch64.def"
+};
+
+AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
+ const TargetOptions &Opts)
+: TargetInfo(Triple), ABI("aapcs") {
+  if (getTriple().getOS() == llvm::Triple::NetBSD ||
+  getTriple().getOS() == llvm::Triple::OpenBSD) {
+WCharType = SignedInt;
+
+// NetBSD apparently prefers consistency across ARM targets to
+// consistency across 64-bit targets.
+Int64Type = SignedLongLong;
+IntMaxType = SignedLongLong;
+  } else {
+WCharType = UnsignedInt;
+Int64Type = SignedLong;
+IntMaxType = SignedLong;
+  }
+
+  LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
+  MaxVectorAlign = 128;
+  MaxAtomicInlineWidth = 128;
+  MaxAtomicPromoteWidth = 128;
+
+  LongDoubleWidth = LongDoubleAlign = SuitableAlign = 128;
+  LongDoubleFormat = &llvm::APFloat::IEEEquad();
+
+  // Make __builtin_ms_va_list available.
+  HasBuiltinMSVaList = true;
+
+  // {} in inline assembly are neon specifiers, not assembly variant
+  // specifiers.
+  NoAsmVariants = true;
+
+  // AAPCS gives rules for bitfields. 7.1.7 says: "The container type
+  // contributes to the alignment of the containing aggregate in the same way
+  // a plain (non bit-field) member of that type would, without exception for
+  // zero-sized or anonymous bit-fields."
+  assert(UseBitFieldTypeAlignment && "bitfields affect type alignment");
+  UseZeroLengthBitfieldAlignment = true;
+
+  // AArch64 targets default to using the ARM C++ ABI.
+  TheCXXABI.set(TargetCXXABI::GenericAArch64);
+
+  if (Triple.getOS() == llvm::Triple::Linux)
+this->MCountName = "\01_mcount";
+  else if (Triple.getOS() == llvm::Triple::UnknownOS)
+this->MCountName =
+Opts.EABIVersion == llvm::EABI::GNU ? "\01_mcount" : "mcount";
+}
+
+StringRef AArch64TargetInfo::getABI() const { return ABI; }
+
+bool AArch64TargetInfo::setABI(const std::string &Name) {
+  if (Name != "aapcs" && Name != "darwinpcs")
+return false;
+
+  ABI = Name;
+  return true;
+}
+
+bool AArch64TargetInfo::isValidCPUName(StringRef Name) const {
+  return Name == "generic" ||
+ llvm::AArch64::parseCPUArch(Name) !=
+ static_cast(llvm::AArch64::ArchKind::AK_INVALID);
+}
+
+bool AArch64TargetInfo::setCPU(const std::string &Name) {
+  return isValidCPUName(Name);
+}
+
+void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
+}
+
+void AArch64TargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  // Also include the ARMv8.1 defines
+  getTargetDefinesARMV81A(Opts, Builder);
+}
+
+void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+  // Target identification.
+  Builder.defineMacro("__aarch64__");
+  // For bare-metal none-eabi.
+  if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+  (getTriple().getEnvironment() == llvm::Triple::EABI ||
+   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+Builder.defineMacro("__ELF__");
+
+  // Target properties.
+  Builder.defineMacro("_LP64");
+  Builder.defineMacro("__LP64__");
+
+  // ACLE predefines. Many can only have one possible value on v8 AArch64.
+  Builder.defineMacro("__ARM_ACLE", "200");
+  Builder.defineMacro("__ARM_ARCH", "8");
+  Builder.defineMacro("__ARM_ARCH_PROFILE", "'A'");
+
+  Builder.defineMacro("__ARM_64BIT_STATE", "1");
+  Builder.defineMacro("__ARM_PCS_

[PATCH] D27918: [analyzer] OStreamChecker

2017-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 107921.

https://reviews.llvm.org/D27918

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/OStreamFormatChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
  test/Analysis/ostream-format.cpp

Index: test/Analysis/ostream-format.cpp
===
--- /dev/null
+++ test/Analysis/ostream-format.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.OStreamFormat -verify -std=c++11 %s
+
+#include "Inputs/system-header-simulator-cxx-iostream.h"
+
+
+class StreamState {
+public:
+  StreamState(std::ostream &out)
+  : m_out(out), m_fmt(out.flags()), m_prec(out.precision()) {}
+
+  ~StreamState() {
+m_out.precision(m_prec);
+m_out.flags(m_fmt);
+  }
+
+private:
+  std::ostream &m_out;
+  std::ios_base::fmtflags m_fmt;
+  std::streamsize m_prec;
+};
+
+void test1(int i) {
+  std::cout << std::hex << i;
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test2(int i) { std::cout << std::hex << i << std::dec; } // OK.
+
+void test3(int i) {
+  std::cout << std::hex << i;
+  std::cout << std::dec;
+} // ok
+
+void test4(float f) {
+  std::cout << std::setprecision(2)
+<< f; // The stream state is chaged, but not restored.
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+int test5() {
+  std::cout.setf(std::ios::hex,
+ std::ios::basefield); // Set hex as the basefield.
+  std::cout.setf(std::ios::showbase);  // Activating showbase.
+  std::cout << 100 << '\n';
+  std::cout.unsetf(std::ios::showbase); // Deactivating showbase.
+  std::cout << 100 << '\n';
+  return 0; // The stream state is chaged, but not restored.
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test6(const char *results) {
+  StreamState ss(std::cout);
+  std::cout << std::setiosflags(std::ios::fixed)
+<< std::setprecision(6); // The stream state is set here.
+  std::cout << results << std::endl;
+} // OK, stream state is recovered here.
+
+void test7(int i) {
+  std::cout << std::hex << i;
+  std::cout.setf(std::ios::dec);
+} // OK.
+
+void test8(float i) {
+  std::cout << std::setprecision(12) << i;
+  std::cout.precision(6);
+} // OK.
+
+void test9(float i) {
+  std::cout.precision(6);
+  std::cout << std::setprecision(12) << i;
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test10(float i) {
+  std::cout.precision(12);
+  std::cout << std::setprecision(6) << i;
+} // OK.
+
Index: test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
===
--- /dev/null
+++ test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
@@ -0,0 +1,195 @@
+// Like the compiler, the static analyzer treats some functions differently if
+// they come from a system header -- for example, it is assumed that system
+// functions do not arbitrarily free() their parameters, and that some bugs
+// found in system headers cannot be fixed by the user and should be
+// suppressed.
+#pragma clang system_header
+
+namespace std {
+typedef unsigned streamsize;
+
+namespace ios {
+int boolalpha;
+int dec;
+int fixed;
+int hex;
+int internal;
+int left;
+int oct;
+int right;
+int scientific;
+int showbase;
+int showpoint;
+int showpos;
+int skipws;
+int unitbuf;
+int uppercase;
+int adjustfield;
+int basefield;
+int floatfield;
+}
+
+class ios_base {
+public:
+  typedef int fmtflags;
+  fmtflags m_fmt;
+  fmtflags flags() const;
+  fmtflags flags(fmtflags);
+  fmtflags setf(fmtflags);
+  fmtflags setf(fmtflags, fmtflags);
+  void unsetf(fmtflags);
+  streamsize precision() const;
+  streamsize precision(streamsize);
+  streamsize width() const;
+  streamsize width(streamsize);
+};
+
+template  class basic_ios : public ios_base {};
+
+// Simple manipulators.
+
+ios_base &boolalpha(ios_base &);
+ios_base &noboolalpha(ios_base &);
+ios_base &showbase(ios_base &);
+ios_base &noshowbase(ios_base &);
+ios_base &showpoint(ios_base &);
+ios_base &noshowpoint(ios_base &);
+ios_base &showpos(ios_base &);
+ios_base &noshowpos(ios_base &);
+ios_base &skipws(ios_base &);
+ios_base &noskipws(ios_base &);
+ios_base &uppercase(ios_base &);
+ios_base &nouppercase(ios_base &);
+ios_base &unitbuf(ios_base &);
+ios_base &nounitbuf(ios_base &);
+ios_base &internal(ios_base &);
+ios_base &left(ios_base &);
+ios_base &right(ios_base &);
+ios_base &dec(ios_base &);
+ios_base &hex(ios_base &);
+ios_base &oct(ios_base &);
+ios_base &fixed(ios_base &);
+ios_base &scientific(ios_base &);
+ios_base &hexfloat(ios_base &);
+ios_base &defaultfloat(ios_base &);
+
+
+template  class basic_ostream : public basic_ios {
+public:
+  basic_ostream &operator<<(int);
+  basic_ostream &operator<<(float);
+  basic_ostream &operat

[PATCH] D34972: [CodeGen] Propagate dllexport to thunks

2017-07-24 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308899: [CodeGen] Propagate dllexport to thunks (authored by 
smeenai).

Repository:
  rL LLVM

https://reviews.llvm.org/D34972

Files:
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp


Index: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -284,6 +284,14 @@
 // linkage together with vtables when needed.
 if (ForVTable && !Thunk->hasLocalLinkage())
   Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+
+// Propagate dllexport storage, to enable the linker to generate import
+// thunks as necessary (e.g. when a parent class has a key function and a
+// child class doesn't, and the construction vtable for the parent in the
+// child needs to reference the parent's thunks).
+const CXXMethodDecl *MD = cast(GD.getDecl());
+if (MD->hasAttr())
+  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
   }
 
   llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,
Index: cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
===
--- cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
+++ cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm -o - 
%s | FileCheck %s
+
+struct __declspec(dllexport) A {
+  virtual void m();
+};
+struct __declspec(dllexport) B {
+  virtual void m();
+};
+struct __declspec(dllexport) C : A, B {
+  virtual void m();
+};
+void C::m() {}
+// CHECK: define dllexport void @_ZThn8_N1C1mEv
+
+struct Base {
+  virtual void m();
+};
+struct __declspec(dllexport) Derived : virtual Base {
+  virtual void m();
+};
+void Derived::m() {}
+// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv


Index: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -284,6 +284,14 @@
 // linkage together with vtables when needed.
 if (ForVTable && !Thunk->hasLocalLinkage())
   Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+
+// Propagate dllexport storage, to enable the linker to generate import
+// thunks as necessary (e.g. when a parent class has a key function and a
+// child class doesn't, and the construction vtable for the parent in the
+// child needs to reference the parent's thunks).
+const CXXMethodDecl *MD = cast(GD.getDecl());
+if (MD->hasAttr())
+  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
   }
 
   llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,
Index: cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
===
--- cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
+++ cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm -o - %s | FileCheck %s
+
+struct __declspec(dllexport) A {
+  virtual void m();
+};
+struct __declspec(dllexport) B {
+  virtual void m();
+};
+struct __declspec(dllexport) C : A, B {
+  virtual void m();
+};
+void C::m() {}
+// CHECK: define dllexport void @_ZThn8_N1C1mEv
+
+struct Base {
+  virtual void m();
+};
+struct __declspec(dllexport) Derived : virtual Base {
+  virtual void m();
+};
+void Derived::m() {}
+// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308899 - [CodeGen] Propagate dllexport to thunks

2017-07-24 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Mon Jul 24 10:16:27 2017
New Revision: 308899

URL: http://llvm.org/viewvc/llvm-project?rev=308899&view=rev
Log:
[CodeGen] Propagate dllexport to thunks

Under Windows Itanium, we need to export virtual and non-virtual thunks
if the functions being thunked are exported. These thunks would
previously inherit their dllexport attribute from the declaration, but
r298330 changed declarations to not have dllexport attributes. We
therefore need to add the dllexport attribute to the definition
ourselves now. This is consistent with MinGW GCC's behavior.

This redoes r306770 but limits the logic to Itanium. MicrosoftCXXABI's
setThunkLinkage ensures that thunks aren't exported under that ABI, so
I'm handling this in ItaniumCXXABI's setThunkLinkage for symmetry.

We need to export these thunks because they can be referenced outside
the library they're defined in. For example, if a child class without a
key function inherits from a parent class with a key function, the
parent's thunks will only be defined in the library with the key
function, but the construction vtable for the parent in the child might
be emitted outside the library (since the child doesn't have a key
function), and it needs to reference the parent's thunks.

We don't need to mark these thunks as imported since any references to
them will occur in data, so the compiler can't generate the IAT load
sequence anyway. Instead, we rely on the linker generating import thunks
for the thunks.

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

Added:
cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=308899&r1=308898&r2=308899&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Jul 24 10:16:27 2017
@@ -284,6 +284,14 @@ public:
 // linkage together with vtables when needed.
 if (ForVTable && !Thunk->hasLocalLinkage())
   Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+
+// Propagate dllexport storage, to enable the linker to generate import
+// thunks as necessary (e.g. when a parent class has a key function and a
+// child class doesn't, and the construction vtable for the parent in the
+// child needs to reference the parent's thunks).
+const CXXMethodDecl *MD = cast(GD.getDecl());
+if (MD->hasAttr())
+  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
   }
 
   llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,

Added: cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp?rev=308899&view=auto
==
--- cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/dllexport-vtable-thunks.cpp Mon Jul 24 10:16:27 
2017
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm -o - 
%s | FileCheck %s
+
+struct __declspec(dllexport) A {
+  virtual void m();
+};
+struct __declspec(dllexport) B {
+  virtual void m();
+};
+struct __declspec(dllexport) C : A, B {
+  virtual void m();
+};
+void C::m() {}
+// CHECK: define dllexport void @_ZThn8_N1C1mEv
+
+struct Base {
+  virtual void m();
+};
+struct __declspec(dllexport) Derived : virtual Base {
+  virtual void m();
+};
+void Derived::m() {}
+// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv


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


[PATCH] D27918: [analyzer] OStreamChecker

2017-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 107923.

https://reviews.llvm.org/D27918

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/OStreamFormatChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
  test/Analysis/ostream-format.cpp

Index: test/Analysis/ostream-format.cpp
===
--- /dev/null
+++ test/Analysis/ostream-format.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.OStreamFormat -verify -std=c++11 %s
+
+#include "Inputs/system-header-simulator-cxx-iostream.h"
+
+
+class StreamState {
+public:
+  StreamState(std::ostream &out)
+  : m_out(out), m_fmt(out.flags()), m_prec(out.precision()) {}
+
+  ~StreamState() {
+m_out.precision(m_prec);
+m_out.flags(m_fmt);
+  }
+
+private:
+  std::ostream &m_out;
+  std::ios_base::fmtflags m_fmt;
+  std::streamsize m_prec;
+};
+
+void test1(int i) {
+  std::cout << std::hex << i;
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test2(int i) { std::cout << std::hex << i << std::dec; } // OK.
+
+void test3(int i) {
+  std::cout << std::hex << i;
+  std::cout << std::dec;
+} // ok
+
+void test4(float f) {
+  std::cout << std::setprecision(2)
+<< f; // The stream state is chaged, but not restored.
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+int test5() {
+  std::cout.setf(std::ios::hex,
+ std::ios::basefield); // Set hex as the basefield.
+  std::cout.setf(std::ios::showbase);  // Activating showbase.
+  std::cout << 100 << '\n';
+  std::cout.unsetf(std::ios::showbase); // Deactivating showbase.
+  std::cout << 100 << '\n';
+  return 0; // The stream state is chaged, but not restored.
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test6(const char *results) {
+  StreamState ss(std::cout);
+  std::cout << std::setiosflags(std::ios::fixed)
+<< std::setprecision(6); // The stream state is set here.
+  std::cout << results << std::endl;
+} // OK, stream state is recovered here.
+
+void test7(int i) {
+  std::cout << std::hex << i;
+  std::cout.setf(std::ios::dec);
+} // OK.
+
+void test8(float i) {
+  std::cout << std::setprecision(12) << i;
+  std::cout.precision(6);
+} // OK.
+
+void test9(float i) {
+  std::cout.precision(6);
+  std::cout << std::setprecision(12) << i;
+} // expected-warning{{Possibly forgotten ostream format modification in scope}}
+
+void test10(float i) {
+  std::cout.precision(12);
+  std::cout << std::setprecision(6) << i;
+} // OK.
+
Index: test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
===
--- /dev/null
+++ test/Analysis/Inputs/system-header-simulator-cxx-iostream.h
@@ -0,0 +1,195 @@
+// Like the compiler, the static analyzer treats some functions differently if
+// they come from a system header -- for example, it is assumed that system
+// functions do not arbitrarily free() their parameters, and that some bugs
+// found in system headers cannot be fixed by the user and should be
+// suppressed.
+#pragma clang system_header
+
+namespace std {
+typedef unsigned streamsize;
+
+namespace ios {
+int boolalpha;
+int dec;
+int fixed;
+int hex;
+int internal;
+int left;
+int oct;
+int right;
+int scientific;
+int showbase;
+int showpoint;
+int showpos;
+int skipws;
+int unitbuf;
+int uppercase;
+int adjustfield;
+int basefield;
+int floatfield;
+}
+
+class ios_base {
+public:
+  typedef int fmtflags;
+  fmtflags m_fmt;
+  fmtflags flags() const;
+  fmtflags flags(fmtflags);
+  fmtflags setf(fmtflags);
+  fmtflags setf(fmtflags, fmtflags);
+  void unsetf(fmtflags);
+  streamsize precision() const;
+  streamsize precision(streamsize);
+  streamsize width() const;
+  streamsize width(streamsize);
+};
+
+template  class basic_ios : public ios_base {};
+
+// Simple manipulators.
+
+ios_base &boolalpha(ios_base &);
+ios_base &noboolalpha(ios_base &);
+ios_base &showbase(ios_base &);
+ios_base &noshowbase(ios_base &);
+ios_base &showpoint(ios_base &);
+ios_base &noshowpoint(ios_base &);
+ios_base &showpos(ios_base &);
+ios_base &noshowpos(ios_base &);
+ios_base &skipws(ios_base &);
+ios_base &noskipws(ios_base &);
+ios_base &uppercase(ios_base &);
+ios_base &nouppercase(ios_base &);
+ios_base &unitbuf(ios_base &);
+ios_base &nounitbuf(ios_base &);
+ios_base &internal(ios_base &);
+ios_base &left(ios_base &);
+ios_base &right(ios_base &);
+ios_base &dec(ios_base &);
+ios_base &hex(ios_base &);
+ios_base &oct(ios_base &);
+ios_base &fixed(ios_base &);
+ios_base &scientific(ios_base &);
+ios_base &hexfloat(ios_base &);
+ios_base &defaultfloat(ios_base &);
+
+
+template  class basic_ostream : public basic_ios {
+public:
+  basic_ostream &operator<<(int);
+  basic_ostream &operator<<(float);
+  basic_ostream &operat

[PATCH] D35383: [coroutines] Add serialization/deserialization of coroutines

2017-07-24 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

@rsmith, ping. Would be good to get this in for clang 5.0


https://reviews.llvm.org/D35383



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yeah, this looks good. How does this compare to `alpha.core.BoolConversion`, 
should we maybe merge them?




Comment at: lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:84
+void EnumCastOutOfRangeChecker::reportWarning(CheckerContext &C) const {
+  if (auto N = C.generateNonFatalErrorNode(C.getState())) {
+if (!EnumValueCastOutOfRange)

`C.getState()` is the default value (if you see how 
`generateNonFatalErrorNode()` calls `addTransition()` which in turns 
substitutes nullptr with `getState()`), so it can be omitted.



Comment at: lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:88-89
+  new BuiltinBug(this, "Enum cast out of range",
+ "The value provided to the cast expression is not in "
+ "the valid range of values for the enum."));
+C.emitReport(llvm::make_unique(

I believe that we'd need to explain the range we're seeing for the value in 
this case. Probably by asking the constraint manager to dump the range of 
possible values through some new API call (in case of `RangeConstraintManager` 
it should be straightforward).

Because otherwise it may be unobvious from the path what values are possible, 
when the `SVal` is a symbol.

Or, even better, we could highlight, with the help of a bug reporter visitor, 
the places where constraints were added to the symbol (then, again, it'd be 
better with ranges).

Ideally:
```
enum { Zero=0, One, Two, Three, Four } y;

void foo(int x) {
  if (x > 3) {
// core note: Assuming 'x' is greater than 3
// checker note: The assigned value is assumed to be within range [4, 
2147483647]
...
  }
  z = x;
  // intermix of 'x' and 'z' is intentional:
  // checker notes should track symbol, not variable,
  // which is what makes them great.
  if (z < 7) {
// core note: Assuming 'z' is less than 7
// checker note: The assigned value is assumed to be within range [4, 6]
if (x > 4) {
  // core note: Assuming 'x' is greater than 4
  // checker note: The assigned value is assumed to be within range [5, 6]
  y = z; // warning: The value provided to the cast expression is in range 
[5, 6], which is not in the valid range of values for the enum
}
  }
}
```
(with a special case when the range consists of one element)



Comment at: lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:119-122
+  // Check if any of the enum values possibly match.
+  bool PossibleValueMatch =
+  std::any_of(DeclValues.begin(), DeclValues.end(),
+  ConstraintBasedEQEvaluator(C, *ValueToCastOptional));

I suspect that enum values often cover a whole segment, and in this case a pair 
of assumes for the sides of the segment (or, even better, a single 
`assumeInclusiveRange`) would be much faster.


https://reviews.llvm.org/D33672



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Did the checker flag any intentionally underpopulated enums, eg.

  enum {
Unset = -1
  } NumberOfChickens = 15;

(such code is bad, but it is not necessarily buggy - as far as i understand 
from the CERT rule, we're talking about "unspecified behavior" which some 
implementations may define and document, and then some people may rely)?

Are you sure this checker isn't useful for C?


https://reviews.llvm.org/D33672



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


[PATCH] D35661: [clang] Implement P0704: "Fixing const-qualified pointers to members"

2017-07-24 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added a comment.

ping..


https://reviews.llvm.org/D35661



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


[PATCH] D34878: [ARM] Option for reading thread pointer from coprocessor register

2017-07-24 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Strahinja,

Does GCC already has a similar option? If so, does this share the same name?


https://reviews.llvm.org/D34878



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-24 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In https://reviews.llvm.org/D33900#818957, @thakis wrote:

> Sorry, I just noticed this weeks later. Why are we adding this to `--version` 
> instead of adding some new flag for printing this? When I pass `--version`, 
> I'm usually interested in clang's version and don't need a screenful of other 
> information below it (which makes the output I do care about scroll off the 
> screen).


I added it there, for consistency with other LLVM tools, for example:

  $ llc -version
  LLVM (http://llvm.org/):
LLVM version 5.0.0svn-r308421
Optimized build with assertions.
Default target: x86_64-unknown-freebsd12.0
Host CPU: ivybridge
  
Registered Targets:
  aarch64- AArch64 (little endian)
  aarch64_be - AArch64 (big endian)
  arm- ARM
  arm64  - ARM64 (little endian)
  armeb  - ARM (big endian)
  mips   - Mips
  mips64 - Mips64 [experimental]
  mips64el   - Mips64el [experimental]
  mipsel - Mipsel
  ppc32  - PowerPC 32
  ppc64  - PowerPC 64
  ppc64le- PowerPC 64 LE
  sparc  - Sparc
  sparcel- Sparc LE
  sparcv9- Sparc V9
  thumb  - Thumb
  thumbeb- Thumb (big endian)
  x86- 32-bit X86: Pentium-Pro and above
  x86-64 - 64-bit X86: EM64T and AMD64
  $ llvm-mc -version
  LLVM (http://llvm.org/):
LLVM version 5.0.0svn-r308421
Optimized build with assertions.
Default target: x86_64-unknown-freebsd12.0
Host CPU: ivybridge
  
Registered Targets:
  aarch64- AArch64 (little endian)
  aarch64_be - AArch64 (big endian)
  arm- ARM
  arm64  - ARM64 (little endian)
  armeb  - ARM (big endian)
  mips   - Mips
  mips64 - Mips64 [experimental]
  mips64el   - Mips64el [experimental]
  mipsel - Mipsel
  ppc32  - PowerPC 32
  ppc64  - PowerPC 64
  ppc64le- PowerPC 64 LE
  sparc  - Sparc
  sparcel- Sparc LE
  sparcv9- Sparc V9
  thumb  - Thumb
  thumbeb- Thumb (big endian)
  x86- 32-bit X86: Pentium-Pro and above
  x86-64 - 64-bit X86: EM64T and AMD64

etc.  I'm fine with a separate flag for clang, but it would be nice if the 
other LLVM tools used the same flag.


https://reviews.llvm.org/D33900



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-24 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

Also note that it is only added to the `--version` output, not the `-v` output 
(the former is really a "verbose" version of the latter):

  $ clang -v
  clang version 5.0.0 (trunk 308421)
  Target: x86_64-unknown-freebsd12.0
  Thread model: posix
  InstalledDir: /share/dim/llvm/308421-trunk-freebsd12-amd64-ninja-rel-1/bin


https://reviews.llvm.org/D33900



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


RE: [clang-tools-extra] r308738 - [clangd] Replace ASTUnit with manual AST management.

2017-07-24 Thread Yung, Douglas via cfe-commits
Hi Ilya,

Your change seems to be causing the test 'clangd/definitions.test' to fail on 
the PS4 Windows bot. Can you take a look?

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/11222

FAIL: Clang Tools :: clangd/definitions.test (11935 of 34225)
 TEST 'Clang Tools :: clangd/definitions.test' FAILED 

Script:
--
clangd -run-synchronously < 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\tools\extra\test\clangd\definitions.test
 | FileCheck 
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\tools\extra\test\clangd\definitions.test
--
Exit Code: 1

Command Output (stdout):
--
$ "clangd" "-run-synchronously"
# command stderr:
<-- 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}

--> {"jsonrpc":"2.0","id":0,"result":{"capabilities":{

  "textDocumentSync": 1,

  "documentFormattingProvider": true,

  "documentRangeFormattingProvider": true,

  "documentOnTypeFormattingProvider": 
{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},

  "codeActionProvider": true,

  "completionProvider": {"resolveProvider": false, "triggerCharacters": 
[".",">"]},

  "definitionProvider": true

}}}

<-- 
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"int
 main() {\nint a;\na;\n}\n"}}}

--> 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[{"range":{"start":
 {"line": 2, "character": 1}, "end": {"line": 2, "character": 
1}},"severity":2,"message":"expression result unused"}]}}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":2,"character":0}}}

--> {"jsonrpc":"2.0","id":1,"result":[{"uri": "file:///main.cpp", "range": 
{"start": {"line": 1, "character": 0}, "end": {"line": 1, "character": 5}}}]}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":2,"character":1}}}

--> {"jsonrpc":"2.0","id":1,"result":[{"uri": "file:///main.cpp", "range": 
{"start": {"line": 1, "character": 0}, "end": {"line": 1, "character": 5}}}]}

<-- 
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":2},"contentChanges":[{"text":"struct
 Foo {\nint x;\n};\nint main() {\n  Foo bar = { x : 1 };\n}\n"}]}}

--> 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[{"range":{"start":
 {"line": 4, "character": 15}, "end": {"line": 4, "character": 
15}},"severity":2,"message":"use of GNU old-style field designator 
extension"}]}}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":4,"character":14}}}

--> {"jsonrpc":"2.0","id":1,"result":[{"uri": "file:///main.cpp", "range": 
{"start": {"line": 1, "character": 0}, "end": {"line": 1, "character": 5}}}]}

<-- 
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":3},"contentChanges":[{"text":"struct
 Foo {\nint x;\n};\nint main() {\n  Foo baz = { .x = 2 };\n}\n"}]}}

--> 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[]}}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":4,"character":15}}}

--> {"jsonrpc":"2.0","id":1,"result":[{"uri": "file:///main.cpp", "range": 
{"start": {"line": 1, "character": 0}, "end": {"line": 1, "character": 5}}}]}

<-- 
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":4},"contentChanges":[{"text":"int
 main() {\n   main();\n   return 0;\n}"}]}

--> 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[]}}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":1,"character":3}}}

--> {"jsonrpc":"2.0","id":1,"result":[{"uri": "file:///main.cpp", "range": 
{"start": {"line": 0, "character": 0}, "end": {"line": 3, "character": 1}}}]}

<-- 
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":5},"contentChanges":[{"text":"struct
 Foo {\n};\nint main() {\n   Foo bar;\n   return 0;\n}\n"}]}

--> 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[]}}

<-- 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///ma

[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-07-24 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Peter,

Please add a testcase for this change, it also seems that you should update the 
comment.


https://reviews.llvm.org/D34030



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-24 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In https://reviews.llvm.org/D33900#819234, @dim wrote:

> In https://reviews.llvm.org/D33900#818957, @thakis wrote:
>
> > Sorry, I just noticed this weeks later. Why are we adding this to 
> > `--version` instead of adding some new flag for printing this? When I pass 
> > `--version`, I'm usually interested in clang's version and don't need a 
> > screenful of other information below it (which makes the output I do care 
> > about scroll off the screen).
>
>
> I added it there, for consistency with other LLVM tools, for example:


I think most of the LLVM tools are kind of internal to LLVM and only used by 
people working on LLVM. clang on the other hand is used primarily by people not 
working on LLVM. We usually try to keep `--version` output for tools that are 
primarily used by non-LLVM devs concise, see e.g. 
http://llvm.org/viewvc/llvm-project?rev=198694&view=rev


https://reviews.llvm.org/D33900



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


[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

2017-07-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

These comments of mine are mostly random ideas for follow-up patches, i agree 
with Gabor this patch is good to land.


https://reviews.llvm.org/D33672



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


[PATCH] D34992: Emit static constexpr member as available_externally definition

2017-07-24 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

Weekly ping! (@rsmith)


https://reviews.llvm.org/D34992



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


[PATCH] D35383: [coroutines] Add serialization/deserialization of coroutines

2017-07-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Serialization/ASTWriterStmt.cpp:320-321
+
+static void serializeSuspendExpr(ASTStmtWriter &Writer, ASTRecordWriter 
&Record,
+ CoroutineSuspendExpr *E) {
+  Writer.VisitExpr(E);

Please call this `ASTStmtWriter::VisitCoroutineSuspendExpr`, following the 
pattern we use in the rest of this visitor.


https://reviews.llvm.org/D35383



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


r308918 - [clang-format] Reorder assignments, NFC

2017-07-24 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Jul 24 12:52:49 2017
New Revision: 308918

URL: http://llvm.org/viewvc/llvm-project?rev=308918&view=rev
Log:
[clang-format] Reorder assignments, NFC

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=308918&r1=308917&r2=308918&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jul 24 12:52:49 2017
@@ -494,8 +494,8 @@ void UnwrappedLineParser::parseBlock(boo
 
   if (MunchSemi && FormatTok->Tok.is(tok::semi))
 nextToken();
-  Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
   Line->Level = InitialLevel;
+  Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
   if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
 // Update the opening line to add the forward reference as well
 (*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =


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


[PATCH] D35426: [clang] Add abi-breaking-checks support to clang

2017-07-24 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

Ping 2 for reviews please!


https://reviews.llvm.org/D35426



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


[PATCH] D35483: clang-format: fix block OpeningLineIndex around preprocessor

2017-07-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Looks good! Thanks!
Please rebase with master before committing since we've been touching the same 
lines in `UnwrappedLineParser.cpp`.


https://reviews.llvm.org/D35483



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


[PATCH] D33561: [CMake] Add Android toolchain CMake cache files.

2017-07-24 Thread Leo Li via Phabricator via cfe-commits
aoli updated this revision to Diff 107951.
aoli added a comment.

Add `STAGE2_` prefix to pass stage2 variables. Add 
`ANDROID_RUNTIMES_BUILD_TYPE`, `ANDROID_RUNTIMES_ENABLE_ASSERTIONS`, and 
`ANDROID_BUILTINS_BUILD_TYPE`.


https://reviews.llvm.org/D33561

Files:
  cmake/caches/Android-stage2.cmake
  cmake/caches/Android.cmake

Index: cmake/caches/Android.cmake
===
--- /dev/null
+++ cmake/caches/Android.cmake
@@ -0,0 +1,43 @@
+# This file sets up a CMakeCache for an Android toolchain build.
+
+set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
+
+set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
+set(CLANG_VENDOR Android CACHE STRING "")
+
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+
+set(HAVE_LIBCXXABI ON CACHE BOOL "")
+set(LLVM_BUILD_TOOLS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_TOOL_OPENMP_BUILD OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=${LIBCXX_ENABLE_ABI_LINKER_SCRIPT})
+endif()
+
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
+endif()
+
+if (LLVM_BUILD_EXTERNAL_COMPILER_RT)
+  set(APPEND EXTRA_ARGS -DLLVM_BUILD_EXTERNAL_COMPILER_RT=${LLVM_BUILD_EXTERNAL_COMPILER_RT})
+endif()
+
+get_cmake_property(variableNames VARIABLES)
+foreach(variableName ${variableNames})
+  if(variableName MATCHES "^STAGE2_")
+string(REPLACE "STAGE2_" "" new_name ${variableName})
+list(APPEND EXTRA_ARGS "-D${new_name}=${${variableName}}")
+  endif()
+endforeach()
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  ${EXTRA_ARGS}
+  -C${CMAKE_CURRENT_LIST_DIR}/Android-stage2.cmake CACHE STRING "")
Index: cmake/caches/Android-stage2.cmake
===
--- /dev/null
+++ cmake/caches/Android-stage2.cmake
@@ -0,0 +1,55 @@
+set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
+
+set(CLANG_VENDOR Android CACHE STRING "")
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(CMAKE_BUILD_TYPE Debug CACHE STRING "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+set(ANDROID_RUNTIMES_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(ANDROID_RUNTIMES_BUILD_TYPE Release CACHE STRING "")
+set(ANDROID_BUILTINS_BUILD_TYPE Release CACHE STRING "")
+
+#set(LLVM_BUILTIN_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+set(LLVM_BUILTIN_TARGETS "armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(BUILTINS_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_BUILTINS_BUILD_TYPE} CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_MOUDLE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+endforeach()
+
+
+#set(LLVM_RUNTIME_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+set(LLVM_RUNTIME_TARGETS "armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(RUNTIMES_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_RUNTIMES_BUILD_TYPE} CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_CXX_FLAGS ${ANDROID_${target}_CXX_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_MODULE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${

[PATCH] D33561: [CMake] Add Android toolchain CMake cache files.

2017-07-24 Thread Leo Li via Phabricator via cfe-commits
aoli updated this revision to Diff 107953.
aoli added a comment.

Remove test code.


https://reviews.llvm.org/D33561

Files:
  cmake/caches/Android-stage2.cmake
  cmake/caches/Android.cmake

Index: cmake/caches/Android.cmake
===
--- /dev/null
+++ cmake/caches/Android.cmake
@@ -0,0 +1,43 @@
+# This file sets up a CMakeCache for an Android toolchain build.
+
+set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
+
+set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
+set(CLANG_VENDOR Android CACHE STRING "")
+
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+
+set(HAVE_LIBCXXABI ON CACHE BOOL "")
+set(LLVM_BUILD_TOOLS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_TOOL_OPENMP_BUILD OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=${LIBCXX_ENABLE_ABI_LINKER_SCRIPT})
+endif()
+
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
+endif()
+
+if (LLVM_BUILD_EXTERNAL_COMPILER_RT)
+  set(APPEND EXTRA_ARGS -DLLVM_BUILD_EXTERNAL_COMPILER_RT=${LLVM_BUILD_EXTERNAL_COMPILER_RT})
+endif()
+
+get_cmake_property(variableNames VARIABLES)
+foreach(variableName ${variableNames})
+  if(variableName MATCHES "^STAGE2_")
+string(REPLACE "STAGE2_" "" new_name ${variableName})
+list(APPEND EXTRA_ARGS "-D${new_name}=${${variableName}}")
+  endif()
+endforeach()
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  ${EXTRA_ARGS}
+  -C${CMAKE_CURRENT_LIST_DIR}/Android-stage2.cmake CACHE STRING "")
Index: cmake/caches/Android-stage2.cmake
===
--- /dev/null
+++ cmake/caches/Android-stage2.cmake
@@ -0,0 +1,53 @@
+set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
+
+set(CLANG_VENDOR Android CACHE STRING "")
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(CMAKE_BUILD_TYPE Debug CACHE STRING "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+set(ANDROID_RUNTIMES_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(ANDROID_RUNTIMES_BUILD_TYPE Release CACHE STRING "")
+set(ANDROID_BUILTINS_BUILD_TYPE Release CACHE STRING "")
+
+set(LLVM_BUILTIN_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(BUILTINS_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_BUILTINS_BUILD_TYPE} CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_MOUDLE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+endforeach()
+
+
+set(LLVM_RUNTIME_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(RUNTIMES_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_RUNTIMES_BUILD_TYPE} CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_CXX_FLAGS ${ANDROID_${target}_CXX_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_MODULE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_ENABLE_WERROR ON CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_TEST_COMPILER_CFLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
+  

[PATCH] D33561: [CMake] Add Android toolchain CMake cache files.

2017-07-24 Thread Leo Li via Phabricator via cfe-commits
aoli updated this revision to Diff 107954.
aoli added a comment.

Remove test code. Sorry for the noise.


https://reviews.llvm.org/D33561

Files:
  cmake/caches/Android-stage2.cmake
  cmake/caches/Android.cmake

Index: cmake/caches/Android.cmake
===
--- /dev/null
+++ cmake/caches/Android.cmake
@@ -0,0 +1,43 @@
+# This file sets up a CMakeCache for an Android toolchain build.
+
+set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
+
+set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
+set(CLANG_VENDOR Android CACHE STRING "")
+
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+
+set(HAVE_LIBCXXABI ON CACHE BOOL "")
+set(LLVM_BUILD_TOOLS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_TOOL_OPENMP_BUILD OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=${LIBCXX_ENABLE_ABI_LINKER_SCRIPT})
+endif()
+
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+  list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
+endif()
+
+if (LLVM_BUILD_EXTERNAL_COMPILER_RT)
+  set(APPEND EXTRA_ARGS -DLLVM_BUILD_EXTERNAL_COMPILER_RT=${LLVM_BUILD_EXTERNAL_COMPILER_RT})
+endif()
+
+get_cmake_property(variableNames VARIABLES)
+foreach(variableName ${variableNames})
+  if(variableName MATCHES "^STAGE2_")
+string(REPLACE "STAGE2_" "" new_name ${variableName})
+list(APPEND EXTRA_ARGS "-D${new_name}=${${variableName}}")
+  endif()
+endforeach()
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  ${EXTRA_ARGS}
+  -C${CMAKE_CURRENT_LIST_DIR}/Android-stage2.cmake CACHE STRING "")
Index: cmake/caches/Android-stage2.cmake
===
--- /dev/null
+++ cmake/caches/Android-stage2.cmake
@@ -0,0 +1,52 @@
+set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
+
+set(CLANG_VENDOR Android CACHE STRING "")
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+set(ANDROID_RUNTIMES_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(ANDROID_RUNTIMES_BUILD_TYPE Release CACHE STRING "")
+set(ANDROID_BUILTINS_BUILD_TYPE Release CACHE STRING "")
+
+set(LLVM_BUILTIN_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(BUILTINS_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_BUILTINS_BUILD_TYPE} CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_MOUDLE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+endforeach()
+
+
+set(LLVM_RUNTIME_TARGETS "i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android" CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(RUNTIMES_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_ASM_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_BUILD_TYPE ${ANDROID_RUNTIMES_BUILD_TYPE} CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_C_FLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_CXX_FLAGS ${ANDROID_${target}_CXX_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SYSROOT ${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_MODULE_LINKER_FLAGS ${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_ENABLE_WERROR ON CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_TEST_COMPILER_CFLAGS ${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}-l

r308926 - Revert "[X86][InlineAsm][Ms Compatibility]Prefer variable name over a register when the two collides"

2017-07-24 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Jul 24 13:48:15 2017
New Revision: 308926

URL: http://llvm.org/viewvc/llvm-project?rev=308926&view=rev
Log:
Revert "[X86][InlineAsm][Ms Compatibility]Prefer variable name over a register 
when the two collides"

This reverts r308867 and r308866.

It broke the sanitizer-windows buildbot on C++ code similar to the
following:

  namespace cl { }
  void f() {
__asm {
  mov al, cl
}
  }

t.cpp(4,13):  error: unexpected namespace name 'cl': expected expression
mov al, cl
^

In this case, MSVC parses 'cl' as a register, not a namespace.

Removed:
cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c

Removed: cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c?rev=308925&view=auto
==
--- cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c (original)
+++ cfe/trunk/test/CodeGen/ms-inline-asm-var-name.c (removed)
@@ -1,12 +0,0 @@
-// REQUIRES: x86-registered-target
-// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - 
| FileCheck %s
-
-void t() {
-  int eax;
-  int Ecx;
-  __asm mov eax, ebx
-  // CHECK: mov $0, ebx
-  __asm add ecx, Ecx
-  // CHECK: add ecx, $1
-}
-


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


[PATCH] D35103: Expand clang-interpreter with example of throwing in and from the JIT for Windows64.

2017-07-24 Thread Frederich Munch via Phabricator via cfe-commits
marsupial added a comment.

Ping.


https://reviews.llvm.org/D35103



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


[PATCH] D35426: [clang] Add abi-breaking-checks support to clang

2017-07-24 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs accepted this revision.
jroelofs added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D35426



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


[PATCH] D35056: GCC ABI incompatibility when passing object with trivial copy ctor, trivial dtor, and non-trivial move ctor

2017-07-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/AST/DeclCXX.cpp:1476
+
+  data().HasNonDeletedCopyOrMoveConstructor = !CopyOrMoveDeleted;
 }

This is wrong. "Has a non-deleted copy or move constructor" is not the same 
thing as "does not have a deleted copy or move constructor". And you will also 
need to check for the case where the class notionally has such a constructor, 
but where we have lazily not yet declared it -- in that case, you may need to 
do arbitrary work (including template instantiation etc) to figure out whether 
the constructor should be deleted.

Please move this check into `Sema` and pass a bool to `completeDefinition` with 
the result of the check. That way you will have the tools available to compute 
the correct value in the case where you need to trigger the declaration of a 
constructor to determine the right answer.


https://reviews.llvm.org/D35056



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


[PATCH] D35817: Ban implicit _Complex to scalar conversions in C++

2017-07-24 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
Herald added a subscriber: mcrosier.

As part of preparing Clang for a C++14 default we noticed that code like this 
was accepted and did horrible things in C++11 or earlier modes (i.e. where 
1.0if is a `_Complex float` rather than a UDL):

  std::complex var = 1.0if;

This is because 1.0if is implicitly cast to a plain `float`, discarding the 
imaginary part. Then the constructor is called with just this real part and a 
default 0.0f for the imaginary part.

To avoid this surprising behaviour (and to follow GCC's behaviour) this patch 
bans such conversions in C++ mode. We can't do it in C99 because it's blessed 
by the standard.

As part of this some OpenMP and warning tests became irrelevant (again, in line 
with GCC) so I removed them.

My biggest annoyance is the new diagnostic; I couldn't see a way to promote the 
existing warning to an error in C++ mode so I duplicated the warning and chose 
at runtime. I'd be happy to rework if there is a better alternative.

Does it look reasonable?


Repository:
  rL LLVM

https://reviews.llvm.org/D35817

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/stmtexpr.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp
  clang/test/OpenMP/atomic_update_codegen.cpp
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/complex-overload.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  clang/test/SemaCXX/warn-absolute-value.cpp

Index: clang/test/SemaCXX/warn-absolute-value.cpp
===
--- clang/test/SemaCXX/warn-absolute-value.cpp
+++ clang/test/SemaCXX/warn-absolute-value.cpp
@@ -448,126 +448,23 @@
 }
 
 void test_complex_float(_Complex float x) {
-  (void)abs(x);
-  // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabsf"
-  (void)labs(x);
-  // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)llabs(x);
-  // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
-  (void)fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-  (void)fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
   (void)cabsf(x);
   (void)cabs(x);
   (void)cabsl(x);
 
-  (void)__builtin_abs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabsf"
-  (void)__builtin_labs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_llabs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-
-  (void)__builtin_fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-  (void)__builtin_fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argum

[PATCH] D35817: Ban implicit _Complex to scalar conversions in C++

2017-07-24 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover updated this revision to Diff 107970.
t.p.northover added a comment.

Sorry, uploaded version with slightly wrong tests.


https://reviews.llvm.org/D35817

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/stmtexpr.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp
  clang/test/OpenMP/atomic_update_codegen.cpp
  clang/test/SemaCXX/complex-conversion.cpp
  clang/test/SemaCXX/complex-overload.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  clang/test/SemaCXX/warn-absolute-value.cpp

Index: clang/test/SemaCXX/warn-absolute-value.cpp
===
--- clang/test/SemaCXX/warn-absolute-value.cpp
+++ clang/test/SemaCXX/warn-absolute-value.cpp
@@ -448,126 +448,23 @@
 }
 
 void test_complex_float(_Complex float x) {
-  (void)abs(x);
-  // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabsf"
-  (void)labs(x);
-  // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)llabs(x);
-  // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
-  (void)fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-  (void)fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf"
-  (void)fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf"
-
   (void)cabsf(x);
   (void)cabs(x);
   (void)cabsl(x);
 
-  (void)__builtin_abs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabsf"
-  (void)__builtin_labs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_llabs(x);
-  // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-
-  (void)__builtin_fabsf(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-  (void)__builtin_fabs(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf"
-  (void)__builtin_fabsl(x);
-  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of complex type}}
-  // expected-note@-2 {{use function '__builtin_cabsf' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf"
-
   (void)__builtin_cabsf(x);
   (void)__builtin_cabs(x);
   (void)__builtin_cabsl(x);
 }
 
 void test_complex_double(_Complex double x) {
-  (void)abs(x);
-  // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabs' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabs"
-  (void)labs(x);
-  // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}}
-  // expected-note@-2 {{use function 'cabs' instead}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabs"
-  (void)llabs(x);
-  // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}}
- 

[libcxx] r308932 - Remove addtional parameters in function std::next() and std::prev()

2017-07-24 Thread Rachel Craik via cfe-commits
Author: rcraik
Date: Mon Jul 24 15:17:05 2017
New Revision: 308932

URL: http://llvm.org/viewvc/llvm-project?rev=308932&view=rev
Log:
Remove addtional parameters in function std::next() and std::prev()

Creating a function pointer with proper parameters pointing to std::next() or 
std::prev() should work.
This change moves the invented paramater for enable_if over to the return type 
to resolve this QoI issue.

Patch by Jason Liu.

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

Modified:
libcxx/trunk/include/iterator

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp

Modified: libcxx/trunk/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=308932&r1=308931&r2=308932&view=diff
==
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Mon Jul 24 15:17:05 2017
@@ -604,21 +604,27 @@ distance(_InputIter __first, _InputIter
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_InputIter
+typename enable_if
+<
+__is_input_iterator<_InputIter>::value, 
+_InputIter
+>::type
 next(_InputIter __x,
- typename iterator_traits<_InputIter>::difference_type __n = 1,
- typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
+ typename iterator_traits<_InputIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, __n);
 return __x;
 }
 
-template 
+template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_BidiretionalIter
-prev(_BidiretionalIter __x,
- typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
- typename 
enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
+typename enable_if
+<
+__is_bidirectional_iterator<_BidirectionalIter>::value, 
+_BidirectionalIter
+>::type
+prev(_BidirectionalIter __x,
+ typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, -__n);
 return __x;

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp?rev=308932&r1=308931&r2=308932&view=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
 Mon Jul 24 15:17:05 2017
@@ -24,6 +24,9 @@ void
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::next(i, n) == x);
+
+It (*next)(It, typename std::iterator_traits::difference_type) = 
std::next;
+assert(next(i, n) == x);
 }
 
 template 

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp?rev=308932&r1=308931&r2=308932&view=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 Mon Jul 24 15:17:05 2017
@@ -22,6 +22,9 @@ void
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::prev(i, n) == x);
+
+It (*prev)(It, typename std::iterator_traits::difference_type) = 
std::prev;
+assert(prev(i, n) == x);
 }
 
 template 


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


[PATCH] D34649: Remove addtional parameters in function std::next() and std::prev()

2017-07-24 Thread Rachel Craik via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308932: Remove addtional parameters in function std::next() 
and std::prev() (authored by rcraik).

Changed prior to commit:
  https://reviews.llvm.org/D34649?vs=104030&id=107977#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34649

Files:
  libcxx/trunk/include/iterator
  
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
  
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp


Index: libcxx/trunk/include/iterator
===
--- libcxx/trunk/include/iterator
+++ libcxx/trunk/include/iterator
@@ -604,21 +604,27 @@
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_InputIter
+typename enable_if
+<
+__is_input_iterator<_InputIter>::value, 
+_InputIter
+>::type
 next(_InputIter __x,
- typename iterator_traits<_InputIter>::difference_type __n = 1,
- typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
+ typename iterator_traits<_InputIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, __n);
 return __x;
 }
 
-template 
+template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_BidiretionalIter
-prev(_BidiretionalIter __x,
- typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
- typename 
enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
+typename enable_if
+<
+__is_bidirectional_iterator<_BidirectionalIter>::value, 
+_BidirectionalIter
+>::type
+prev(_BidirectionalIter __x,
+ typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, -__n);
 return __x;
Index: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
===
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
@@ -24,6 +24,9 @@
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::next(i, n) == x);
+
+It (*next)(It, typename std::iterator_traits::difference_type) = 
std::next;
+assert(next(i, n) == x);
 }
 
 template 
Index: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
===
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
@@ -22,6 +22,9 @@
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::prev(i, n) == x);
+
+It (*prev)(It, typename std::iterator_traits::difference_type) = 
std::prev;
+assert(prev(i, n) == x);
 }
 
 template 


Index: libcxx/trunk/include/iterator
===
--- libcxx/trunk/include/iterator
+++ libcxx/trunk/include/iterator
@@ -604,21 +604,27 @@
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_InputIter
+typename enable_if
+<
+__is_input_iterator<_InputIter>::value, 
+_InputIter
+>::type
 next(_InputIter __x,
- typename iterator_traits<_InputIter>::difference_type __n = 1,
- typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
+ typename iterator_traits<_InputIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, __n);
 return __x;
 }
 
-template 
+template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_BidiretionalIter
-prev(_BidiretionalIter __x,
- typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
- typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
+typename enable_if
+<
+__is_bidirectional_iterator<_BidirectionalIter>::value, 
+_BidirectionalIter
+>::type
+prev(_BidirectionalIter __x,
+ typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, -__n);
 return __x;
Index: libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
===
--- libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
+++ libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
@@ -24,6 +24,9 @@
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::next(i, n) == x);
+
+It (*next)(It, typename std::iterator_traits::difference_type) = std::next;
+assert(next(i, n) == x);
 }
 
 template 
Index: libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
=

[PATCH] D34260: [StaticAnalyzer] Completely unrolling specific loops with known bound option

2017-07-24 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 107976.
szepet added a subscriber: cfe-commits.
szepet added a comment.

Accidentally left typo removed.
OK so I am not sure but am I allowed to commit it again? I mean I made some 
notable changes. Not on the functionality of the feature but the stored data.
So should i wait for a quick review or could I commit it right now? (It is 
something that would be useful to know for future commits too.)


https://reviews.llvm.org/D34260

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h
  lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CMakeLists.txt
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/loop-unrolling.cpp

Index: test/Analysis/loop-unrolling.cpp
===
--- /dev/null
+++ test/Analysis/loop-unrolling.cpp
@@ -0,0 +1,176 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true -analyzer-stats -verify -std=c++11 %s
+
+void clang_analyzer_numTimesReached();
+
+int getNum();
+void foo(int &);
+// Testing for loops.
+int simple_unroll1() {
+  int a[9];
+  int k = 42;
+  for (int i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{9}}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int simple_unroll2() {
+  int a[9];
+  int k = 42;
+  int i;
+  for (i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{9}}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int simple_no_unroll1() {
+  int a[9];
+  int k = 42;
+  for (int i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+a[i] = 42;
+foo(i);
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int simple_no_unroll2() {
+  int a[9];
+  int k = 42;
+  int i;
+  for (i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+a[i] = 42;
+i += getNum();
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int simple_no_unroll3() {
+  int a[9];
+  int k = 42;
+  int i;
+  for (i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+a[i] = 42;
+(void)&i;
+  }
+  int b = 22 / (k - 42); // no-warning
+  return 0;
+}
+
+int simple_no_unroll4() {
+  int a[9];
+  int k = 42;
+  int i;
+  for (i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+a[i] = 42;
+int &j = i;
+  }
+  int b = 22 / (k - 42); // no-warning
+  return 0;
+}
+
+int simple_no_unroll5() {
+  int a[9];
+  int k = 42;
+  int i;
+  for (i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+a[i] = 42;
+int &j{i};
+  }
+  int b = 22 / (k - 42); // no-warning
+  return 0;
+}
+
+int nested_outer_unrolled() {
+  int a[9];
+  int k = 42;
+  int j = 0;
+  for (int i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{16}}
+for (j = 0; j < getNum(); ++j) {
+  clang_analyzer_numTimesReached(); // expected-warning {{15}}
+  a[j] = 22;
+}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // no-warning
+  return 0;
+}
+
+int nested_inner_unrolled() {
+  int a[9];
+  int k = 42;
+  int j = 0;
+  for (int i = 0; i < getNum(); i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{4}}
+for (j = 0; j < 8; ++j) {
+  clang_analyzer_numTimesReached(); // expected-warning {{32}}
+  a[j] = 22;
+}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int nested_both_unrolled() {
+  int a[9];
+  int k = 42;
+  int j = 0;
+  for (int i = 0; i < 7; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{7}}
+for (j = 0; j < 6; ++j) {
+  clang_analyzer_numTimesReached(); // expected-warning {{42}}
+  a[j] = 22;
+}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
+
+int simple_known_bound_loop() {
+  for (int i = 2; i < 12; i++) {
+// This function is inlined in nested_inlined_unroll1()
+clang_analyzer_numTimesReached(); // expected-warning {{90}}
+  }
+  return 0;
+}
+
+int simple_unknown_bound_loop() {
+  for (int i = 2; i < getNum(); i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{10}}
+  }
+  return 0;
+}
+
+int nested_inlined_unroll1() {
+  int k;
+  for (int i = 0; i < 9; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{9}}
+k = simple_known_bound_loop();// no reevaluation without inlining
+  }
+  int a = 22 / 

[PATCH] D35820: [Driver] Search compiler-rt paths in -print-file-name=

2017-07-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added a subscriber: dberris.

This makes it possible to print the name of compiler-rt libraries
by using simply clang -print-file-name=libclang_rt.${runtime}-${arch}.so
same as other libraries, without having to know the details of the
resource directory organization.


Repository:
  rL LLVM

https://reviews.llvm.org/D35820

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


Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -308,6 +308,13 @@
   return TC.getArchName();
 }
 
+std::string ToolChain::getCompilerRTPath() const {
+  SmallString<128> Path(getDriver().ResourceDir);
+  StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
+  llvm::sys::path::append(Path, "lib", OSLibName);
+  return Path.str();
+}
+
 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
  bool Shared) const {
   const llvm::Triple &TT = getTriple();
@@ -320,9 +327,7 @@
   const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so")
   : (IsITANMSVCWindows ? ".lib" : ".a");
 
-  SmallString<128> Path(getDriver().ResourceDir);
-  StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
-  llvm::sys::path::append(Path, "lib", OSLibName);
+  SmallString<128> Path(getCompilerRTPath());
   llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
 Arch + Env + Suffix);
   return Path.str();
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -3684,6 +3684,11 @@
   if (llvm::sys::fs::exists(Twine(P)))
 return P.str();
 
+  P = TC.getCompilerRTPath();
+  llvm::sys::path::append(P, Name);
+  if (llvm::sys::fs::exists(Twine(P)))
+return P.str();
+
   for (const std::string &Dir : TC.getFilePaths()) {
 if (Dir.empty())
   continue;
Index: include/clang/Driver/ToolChain.h
===
--- include/clang/Driver/ToolChain.h
+++ include/clang/Driver/ToolChain.h
@@ -298,6 +298,8 @@
 return ToolChain::CST_Libstdcxx;
   }
 
+  virtual std::string getCompilerRTPath() const;
+
   virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
 StringRef Component,
 bool Shared = false) const;


Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -308,6 +308,13 @@
   return TC.getArchName();
 }
 
+std::string ToolChain::getCompilerRTPath() const {
+  SmallString<128> Path(getDriver().ResourceDir);
+  StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
+  llvm::sys::path::append(Path, "lib", OSLibName);
+  return Path.str();
+}
+
 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
  bool Shared) const {
   const llvm::Triple &TT = getTriple();
@@ -320,9 +327,7 @@
   const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so")
   : (IsITANMSVCWindows ? ".lib" : ".a");
 
-  SmallString<128> Path(getDriver().ResourceDir);
-  StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
-  llvm::sys::path::append(Path, "lib", OSLibName);
+  SmallString<128> Path(getCompilerRTPath());
   llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
 Arch + Env + Suffix);
   return Path.str();
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -3684,6 +3684,11 @@
   if (llvm::sys::fs::exists(Twine(P)))
 return P.str();
 
+  P = TC.getCompilerRTPath();
+  llvm::sys::path::append(P, Name);
+  if (llvm::sys::fs::exists(Twine(P)))
+return P.str();
+
   for (const std::string &Dir : TC.getFilePaths()) {
 if (Dir.empty())
   continue;
Index: include/clang/Driver/ToolChain.h
===
--- include/clang/Driver/ToolChain.h
+++ include/clang/Driver/ToolChain.h
@@ -298,6 +298,8 @@
 return ToolChain::CST_Libstdcxx;
   }
 
+  virtual std::string getCompilerRTPath() const;
+
   virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
 StringRef Component,
 bool Shared = false) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35820: [Driver] Search compiler-rt paths in -print-file-name=

2017-07-24 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

LGTM.  Perhaps there should be a test.


Repository:
  rL LLVM

https://reviews.llvm.org/D35820



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


[PATCH] D32210: [Sema][ObjC] Add support for attribute "noescape"

2017-07-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added a comment.

In https://reviews.llvm.org/D32210#810508, @rjmccall wrote:

> In https://reviews.llvm.org/D32210#810292, @ahatanak wrote:
>
> > Address review comments.
> >
> > - Allow attaching "noescape" to pointers other than block pointers. Update 
> > the docs accordingly.
> > - Attach attribute "nocapture" to parameters that are annotated with 
> > "noescape".
> > - Call Sema::isValidPointerAttrType to determine whether "noescape" can be 
> > applied to a parameter. Also, use the existing warning 
> > "warn_attribute_pointers_only" rather than defining a new warning that will 
> > be used just for noescape.
> >
> >   I also thought about what else we can do in the front-end when a 
> > parameter has 'noescape".  One idea is to do something similar to what 
> > r301667 did and omit emitting retains and releases of block captures when 
> > the block is passed to a function taking a noescape parameter. If that is 
> > viable, I can look into it after committing this patch.
>
>
> Hmm.  Unfortunately, I'm not sure that's valid.  The retains and releases of 
> block captures don't protect against anything related to escaping the block; 
> they protect against the original variables being modified during the 
> lifetime of the block.  It is true that a block literal passed to a noescape 
> parameter has a shorter effective lifetime — we know for certain that it will 
> be unused after the call, and ARC only promises that a value in an 
> imprecise-lifetime strong variable like a block capture will be valid until 
> the last load of that value from the variable.  But that duration is still 
> long enough for someone to modify the original variable in a way that is 
> properly sequenced after the formation of the block.
>
> Now, if you could prove that the variable was not modified for the duration 
> of the call, that would be sufficient.  And that would be easy to do in the 
> common case by just proving that the address of the variable never escapes.  
> Unfortunately, we don't have that information readily available because Sema 
> doesn't collect it.


OK, so I guess the optimization isn't valid in the following case, for example:

  void foo3(id);
  
  id __strong *gp;
  
  void foo2(id a) {
gp = &a;
nonescapingFunc(^{ foo3(a); }); // this function can modify "a" before the 
block is executed.
  }



> There are some other ways you could optimize blocks that are known not to 
> escape, though.  One big caveat is that you have to make sure the block 
> behaves reasonably in response to being copied, becase being noescape doesn't 
> guarantee that the callee won't try to copy the block.  However:

I didn't understand the following optimizations. I thought clang doesn't emit 
copy and destroy helper for global blocks with or without noescape?

> - Copying a global block is always a no-op.  If you gave the non-escaping 
> stack block a global block isa, that would allow the blocks runtime to avoid 
> doing extra work when a non-escaping block is spuriously copied, and it would 
> allow the compiler to completely avoid emitting copy and destroy helpers for 
> the block.  Please clear this with Greg Parker first, though.
> - Even if that's not possible, you can still avoid emitting copy and destroy 
> helpers in the common case where none of the captures are address-sensitive, 
> i.e. __weak references or non-trivally-copyable C++ types, because the memcpy 
> from the original block will be sufficient for correctness.
> - You can just capture a reference to an outer block instead of copying 
> anything that it captures.
> - __block variables which are only captured by non-escaping blocks are 
> themselves known not to escape.  (But remember that a non-escaping block can 
> create an escaping block that captures the __block variable!)  Because 
> __block variable copies are only ever kicked off by block copy helpers, and 
> you won't be generating those (or at least won't be asking them to copy your 
> __block variables for you), you also know that such variables can't be 
> copied.  That in turn means you can completely drop all the nonsense that 
> only exists to supporting the lazy copying of __block variables, like the 
> __block header and copy/destroy helpers and forwarding.  Just generate the 
> variable like a normal local variable and capture it by reference.
> 
>   John.






Comment at: include/clang/AST/Type.h:3156
 };
 unsigned char Data;
 

rjmccall wrote:
> Oh!  I hadn't noticed that you were adding this to ExtParameterInfo.  You're 
> modifying the function type system; there's a lot of complexity to do that 
> properly which you haven't done in this patch at all.  That's especially true 
> because, unlike all these other ExtParameterInfo cases, there's a natural 
> subtyping rule for escaping parameters: a function type that takes a 
> non-escaping parameter should be implicitly convertible 

[PATCH] D32210: [Sema][ObjC] Add support for attribute "noescape"

2017-07-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 107993.
ahatanak marked an inline comment as done.
ahatanak added a comment.
Herald added a subscriber: javed.absar.

Address review comments.


https://reviews.llvm.org/D32210

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/CodeGen/CGFunctionInfo.h
  include/clang/CodeGen/CodeGenABITypes.h
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGCall.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenABITypes.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenTypes.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/SwiftCallingConv.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/noescape.cpp
  test/CodeGenObjC/noescape.m
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/noescape.mm

Index: test/SemaObjCXX/noescape.mm
===
--- /dev/null
+++ test/SemaObjCXX/noescape.mm
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s
+
+typedef void (^BlockTy)();
+
+struct S {
+  int i;
+  void m();
+};
+
+void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
+void noescapeFunc1(id, [[clang::noescape]] BlockTy);
+void noescapeFunc2(__attribute__((noescape)) int *);
+void noescapeFunc3(__attribute__((noescape)) id);
+void noescapeFunc4(__attribute__((noescape)) int &);
+
+void invalidFunc0(int __attribute__((noescape))); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+void invalidFunc1(int __attribute__((noescape(0; // expected-error {{'noescape' attribute takes no arguments}}
+void invalidFunc2(int0 *__attribute__((noescape))); // expected-error {{use of undeclared identifier 'int0'; did you mean 'int'?}}
+void invalidFunc3(__attribute__((noescape)) int (S::*Ty)); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+void invalidFunc4(__attribute__((noescape)) void (S::*Ty)()); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+int __attribute__((noescape)) g; // expected-warning {{'noescape' attribute only applies to parameters}}
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 62 attributes:
+// CHECK: #pragma clang attribute supports 63 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -33,6 +33,7 @@
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter)
 // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function)
+// CHECK-NEXT: NoEscape (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
Index: test/CodeGenObjC/noescape.m
===
--- /dev/null
+++ test/CodeGenObjC/noescape.m
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fblocks -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^BlockTy)(void);
+
+union U {
+  int *i;
+  long long *ll;
+} __attribute__((transparent_union));
+
+void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
+void noescapeFunc1(__attribute__((noescape)) int *);
+void noescapeFunc2(__attribute__((noescape)) id);
+void noescapeFunc3(__attribute__((noescape)) union U);
+
+// CHECK-LABEL: define void @test0(
+// CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
+// CHECK: declare void @noescapeFunc0(i8*, {{.*}} nocapture)
+void test0(BlockTy b) {
+  noescapeFunc0(0, b);
+}
+
+// CHECK-LABEL: define void @test1(
+// CHECK: call void @noescapeFunc1({{.*}} nocapture {{.*}})
+// CHECK: declare void @noescapeFunc1({{.*}} nocapture)
+void test1(int *i) {
+  noescapeFunc1(i);
+}
+
+// CHECK-LABEL: define void @test2(
+// CHECK: call void @noescapeFunc2({{.*}} nocapture {{.*}})
+// CHECK: declare void @noescapeFunc2({{.*}} nocapture)
+void test2(id i) {
+  noescapeFunc2(i);
+}
+
+// CHECK-LABEL: define void @test3(
+// CHECK: call void @noescapeFunc3({{.*}} nocapture {{.*}})
+// CHECK: declare void @noescapeFunc3({{.*}} nocapture)
+void test3(unio

[PATCH] D35388: [libc++] Give extern templates default visibility on gcc

2017-07-24 Thread Tom Anderson via Phabricator via cfe-commits
thomasanderson added a comment.

Hm.. is there anyone else who might be able to review?


https://reviews.llvm.org/D35388



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


r308938 - Debug Info: Avoid completing class types when a definition is in a module.

2017-07-24 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Mon Jul 24 16:48:51 2017
New Revision: 308938

URL: http://llvm.org/viewvc/llvm-project?rev=308938&view=rev
Log:
Debug Info: Avoid completing class types when a definition is in a module.

This patch adds an early exit to CGDebugInfo::completeClassData() when
compiling with -gmodules and the to-be-completed type is available in
a clang module.

rdar://problem/2350

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/Modules/ExtDebugInfo.cpp
cfe/trunk/test/Modules/Inputs/DebugCXX.h
cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=308938&r1=308937&r2=308938&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jul 24 16:48:51 2017
@@ -1766,6 +1766,29 @@ static bool isClassOrMethodDLLImport(con
   return false;
 }
 
+/// Does a type definition exist in an imported clang module?
+static bool isDefinedInClangModule(const RecordDecl *RD) {
+  // Only definitions that where imported from an AST file come from a module.
+  if (!RD || !RD->isFromASTFile())
+return false;
+  // Anonymous entities cannot be addressed. Treat them as not from module.
+  if (!RD->isExternallyVisible() && RD->getName().empty())
+return false;
+  if (auto *CXXDecl = dyn_cast(RD)) {
+if (!CXXDecl->isCompleteDefinition())
+  return false;
+auto TemplateKind = CXXDecl->getTemplateSpecializationKind();
+if (TemplateKind != TSK_Undeclared) {
+  // This is a template, check the origin of the first member.
+  if (CXXDecl->field_begin() == CXXDecl->field_end())
+return TemplateKind == TSK_ExplicitInstantiationDeclaration;
+  if (!CXXDecl->field_begin()->isFromASTFile())
+return false;
+}
+  }
+  return true;
+}
+
 void CGDebugInfo::completeClassData(const RecordDecl *RD) {
   if (auto *CXXRD = dyn_cast(RD))
 if (CXXRD->isDynamicClass() &&
@@ -1773,6 +1796,10 @@ void CGDebugInfo::completeClassData(cons
 llvm::GlobalValue::AvailableExternallyLinkage &&
 !isClassOrMethodDLLImport(CXXRD))
   return;
+
+  if (DebugTypeExtRefs && isDefinedInClangModule(RD->getDefinition()))
+return;
+
   completeClass(RD);
 }
 
@@ -1799,29 +1826,6 @@ static bool hasExplicitMemberDefinition(
   return false;
 }
 
-/// Does a type definition exist in an imported clang module?
-static bool isDefinedInClangModule(const RecordDecl *RD) {
-  // Only definitions that where imported from an AST file come from a module.
-  if (!RD || !RD->isFromASTFile())
-return false;
-  // Anonymous entities cannot be addressed. Treat them as not from module.
-  if (!RD->isExternallyVisible() && RD->getName().empty())
-return false;
-  if (auto *CXXDecl = dyn_cast(RD)) {
-if (!CXXDecl->isCompleteDefinition())
-  return false;
-auto TemplateKind = CXXDecl->getTemplateSpecializationKind();
-if (TemplateKind != TSK_Undeclared) {
-  // This is a template, check the origin of the first member.
-  if (CXXDecl->field_begin() == CXXDecl->field_end())
-return TemplateKind == TSK_ExplicitInstantiationDeclaration;
-  if (!CXXDecl->field_begin()->isFromASTFile())
-return false;
-}
-  }
-  return true;
-}
-
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
  bool DebugTypeExtRefs, const RecordDecl *RD,
  const LangOptions &LangOpts) {

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=308938&r1=308937&r2=308938&view=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Mon Jul 24 16:48:51 2017
@@ -69,6 +69,8 @@ WithSpecializedBase definedLocally4
 
 void foo() {
   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
+  A a;
+  Virtual virt;
 }
 
 // CHECK: ![[CPP:.*]] = !DIFile(filename: {{.*}}ExtDebugInfo.cpp"
@@ -210,3 +212,10 @@ void foo() {
 // CHECK-SAME:   dwoId:
 // CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
 // CHECK-PCH:dwoId: 18446744073709551614
+
+// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
+// CHECK-SAME: DIFlagFwdDecl, identifier: "_ZTS1A")
+
+// There is a full definition of the type available in the module.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
+// CHECK-SAME: DIFlagFwdDecl, identifier: "_ZTS7Virtual")

Modified: cfe/trunk/test/Modules/Inputs/DebugCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugCXX.h?rev=308938&r1=308937&r2=308938&view=diff
==

  1   2   >