r295935 - [CodeGen] Don't reemit expressions for pass_object_size params.

2017-02-22 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Feb 22 23:59:56 2017
New Revision: 295935

URL: http://llvm.org/viewvc/llvm-project?rev=295935=rev
Log:
[CodeGen] Don't reemit expressions for pass_object_size params.

This fixes an assertion failure in cases where we had expression
statements that declared variables nested inside of pass_object_size
args. Since we were emitting the same ExprStmt twice (once for the arg,
once for the @llvm.objectsize call), we were getting issues with
redefining locals.

This also means that we can be more lax about when we emit
@llvm.objectsize for pass_object_size args: since we're reusing the
arg's value itself, we don't have to care so much about side-effects.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/pass-object-size.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=295935=295934=295935=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Feb 22 23:59:56 2017
@@ -420,10 +420,11 @@ getDefaultBuiltinObjectSizeResult(unsign
 
 llvm::Value *
 CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
- llvm::IntegerType *ResType) {
+ llvm::IntegerType *ResType,
+ llvm::Value *EmittedE) {
   uint64_t ObjectSize;
   if (!E->tryEvaluateObjectSize(ObjectSize, getContext(), Type))
-return emitBuiltinObjectSize(E, Type, ResType);
+return emitBuiltinObjectSize(E, Type, ResType, EmittedE);
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
@@ -432,9 +433,14 @@ CodeGenFunction::evaluateOrEmitBuiltinOb
 ///   - A llvm::Argument (if E is a param with the pass_object_size attribute 
on
 /// it)
 ///   - A call to the @llvm.objectsize intrinsic
+///
+/// EmittedE is the result of emitting `E` as a scalar expr. If it's non-null
+/// and we wouldn't otherwise try to reference a pass_object_size parameter,
+/// we'll call @llvm.objectsize on EmittedE, rather than emitting E.
 llvm::Value *
 CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type,
-   llvm::IntegerType *ResType) {
+   llvm::IntegerType *ResType,
+   llvm::Value *EmittedE) {
   // We need to reference an argument if the pointer is a parameter with the
   // pass_object_size attribute.
   if (auto *D = dyn_cast(E->IgnoreParenImpCasts())) {
@@ -457,10 +463,10 @@ CodeGenFunction::emitBuiltinObjectSize(c
   // LLVM can't handle Type=3 appropriately, and __builtin_object_size 
shouldn't
   // evaluate E for side-effects. In either case, we shouldn't lower to
   // @llvm.objectsize.
-  if (Type == 3 || E->HasSideEffects(getContext()))
+  if (Type == 3 || (!EmittedE && E->HasSideEffects(getContext(
 return getDefaultBuiltinObjectSizeResult(Type, ResType);
 
-  Value *Ptr = EmitScalarExpr(E);
+  Value *Ptr = EmittedE ? EmittedE : EmitScalarExpr(E);
   assert(Ptr->getType()->isPointerTy() &&
  "Non-pointer passed to __builtin_object_size?");
 
@@ -965,7 +971,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
 // We pass this builtin onto the optimizer so that it can figure out the
 // object size in more complex cases.
-return RValue::get(emitBuiltinObjectSize(E->getArg(0), Type, ResType));
+return RValue::get(emitBuiltinObjectSize(E->getArg(0), Type, ResType,
+ /*EmittedE=*/nullptr));
   }
   case Builtin::BI__builtin_prefetch: {
 Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=295935=295934=295935=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Feb 22 23:59:56 2017
@@ -3243,7 +3243,18 @@ void CodeGenFunction::EmitCallArgs(
 EvaluationOrder Order) {
   assert((int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
 
-  auto MaybeEmitImplicitObjectSize = [&](unsigned I, const Expr *Arg) {
+  // We *have* to evaluate arguments from right to left in the MS C++ ABI,
+  // because arguments are destroyed left to right in the callee. As a special
+  // case, there are certain language constructs that require left-to-right
+  // evaluation, and in those cases we consider the evaluation order 
requirement
+  // to trump the "destruction order is reverse construction order" guarantee.
+  bool LeftToRight =
+  CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()
+  ? 

r295934 - [c-index-test] For the 'core' invocation, avoid running it under a new thread.

2017-02-22 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Wed Feb 22 23:51:47 2017
New Revision: 295934

URL: http://llvm.org/viewvc/llvm-project?rev=295934=rev
Log:
[c-index-test] For the 'core' invocation, avoid running it under a new thread.

It's unnecessary.

Modified:
cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=295934=295933=295934=diff
==
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Feb 22 23:51:47 2017
@@ -4452,13 +4452,13 @@ int main(int argc, const char **argv) {
   LIBXML_TEST_VERSION
 #endif
 
+  if (argc > 1 && strcmp(argv[1], "core") == 0)
+return indextest_core_main(argc, argv);
+
   client_data.main_func = cindextest_main;
   client_data.argc = argc;
   client_data.argv = argv;
 
-  if (argc > 1 && strcmp(argv[1], "core") == 0)
-client_data.main_func = indextest_core_main;
-
   if (getenv("CINDEXTEST_NOTHREADS"))
 return client_data.main_func(client_data.argc, client_data.argv);
 


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


[PATCH] D28445: [Analyzer] Extend taint propagation and checking

2017-02-22 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich updated this revision to Diff 89467.
vlad.tsyrklevich added a comment.

@NoQ I've tried to address all the issues you mentioned in this change. Let me 
know if the expanded documentation doesn't address what you were looking for.


https://reviews.llvm.org/D28445

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/taint-generic.c

Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -169,6 +169,43 @@
   sock = socket(AF_LOCAL, SOCK_STREAM, 0);
   read(sock, buffer, 100);
   execl(buffer, "filename", 0); // no-warning
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  // References to both buffer and  as an argument should taint the argument
+  read(sock, , 100);
+  execl(buffer, "filename", 0); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+void testStruct() {
+  struct {
+char buf[16];
+int length;
+  } tainted;
+
+  char buffer[16];
+  int sock;
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  read(sock, , sizeof(tainted));
+  __builtin_memcpy(buffer, tainted.buf, tainted.length); // expected-warning {{Untrusted data is used to specify the buffer size}}
+}
+
+void testStructArray() {
+  struct {
+char buf[16];
+struct {
+  int length;
+} st[1];
+  } tainted;
+
+  char buffer[16];
+  int sock;
+
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+  read(sock, [0], sizeof(tainted.buf));
+  read(sock, [0], sizeof(tainted.st));
+  // FIXME: tainted.st[0].length should be marked tainted
+  __builtin_memcpy(buffer, tainted.buf, tainted.st[0].length); // no-warning
 }
 
 int testDivByZero() {
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -494,6 +494,11 @@
 return getBinding(getRegionBindings(S), L, T);
   }
 
+  Optional getDefaultBinding(Store S, const MemRegion *R) override {
+RegionBindingsRef B = getRegionBindings(S);
+return B.getDefaultBinding(R);
+  }
+
   SVal getBinding(RegionBindingsConstRef B, Loc L, QualType T = QualType());
 
   SVal getBindingForElement(RegionBindingsConstRef B, const ElementRegion *R);
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -65,6 +65,18 @@
   /// and thus, is tainted.
   static bool isStdin(const Expr *E, CheckerContext );
 
+  /// This is called from getPointedToSymbol() to resolve symbol references for
+  /// the region underlying a LazyCompoundVal. This is the default binding
+  /// for the LCV, which could be a conjured symbol from a function call that
+  /// initialized the region. It only returns the conjured symbol if the LCV
+  /// covers the entire region, e.g. we avoid false positives by not returning
+  /// a default bindingc for an entire struct if the symbol for only a single
+  /// field or element within it is requested.
+  // TODO: Return an appropriate symbol for sub-fields/elements of an LCV so
+  // that they are also appropriately tainted.
+  static SymbolRef getLCVSymbol(CheckerContext ,
+nonloc::LazyCompoundVal );
+
   /// \brief Given a pointer argument, get the symbol of the value it contains
   /// (points to).
   static SymbolRef getPointedToSymbol(CheckerContext , const Expr *Arg);
@@ -423,6 +435,27 @@
   return false;
 }
 
+SymbolRef GenericTaintChecker::getLCVSymbol(CheckerContext ,
+nonloc::LazyCompoundVal ) {
+  StoreManager  = C.getStoreManager();
+
+  // getLCVSymbol() is reached in a PostStmt so we can always expect a default
+  // binding to exist if one is present.
+  if (Optional binding = StoreMgr.getDefaultBinding(LCV)) {
+SymbolRef Sym = binding->getAsSymbol();
+if (!Sym)
+  return nullptr;
+
+// If the LCV covers an entire base region return the default conjured symbol.
+if (LCV.getRegion() == LCV.getRegion()->getBaseRegion())
+  return Sym;
+  }
+
+  // Otherwise, return a nullptr as there's not yet a functional way to taint
+  // sub-regions of LCVs.
+  return nullptr;
+}
+
 SymbolRef GenericTaintChecker::getPointedToSymbol(CheckerContext ,
   const Expr* Arg) {
   ProgramStateRef State = C.getState();
@@ -438,6 +471,10 @@
 dyn_cast(Arg->getType().getCanonicalType().getTypePtr());
   SVal Val = State->getSVal(*AddrLoc,
 ArgTy ? ArgTy->getPointeeType(): QualType());
+
+  if (auto LCV = Val.getAs())
+return getLCVSymbol(C, *LCV);
+
   return Val.getAsSymbol();
 }
 
Index: 

Re: r295473 - [OpenMP] Remove barriers at cancel and cancellation point

2017-02-22 Thread Alexey Bataev via cfe-commits
Yes, approved

Best regards,
Alexey Bataev

> 23 февр. 2017 г., в 1:00, Hans Wennborg  написал(а):
> 
> Alexey: ping?
> 
>> On Tue, Feb 21, 2017 at 11:07 AM, Hans Wennborg  wrote:
>> I'm Ok with it if Alexey approves.
>> 
>> On Fri, Feb 17, 2017 at 10:52 AM, Hahnfeld, Jonas
>>  wrote:
>>> Hi Hans, Alexey,
>>> 
>>> can we merge this commit and r295474 for the 4.0 release or is it already
>>> too late for that? I will totally understand that and can apply these
>>> commits locally prior to installing.
>>> However, I think that these changes are quite focussed and bear minimal
>>> possibility of introducing regressions.
>>> 
>>> Thanks,
>>> Jonas
>>> 
>>> Am Freitag, den 17.02.2017, 18:32 + schrieb Jonas Hahnfeld via
>>> cfe-commits:
>>> 
>>> Author: hahnfeld
>>> Date: Fri Feb 17 12:32:51 2017
>>> New Revision: 295473
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=295473=rev
>>> Log:
>>> [OpenMP] Remove barriers at cancel and cancellation point
>>> 
>>> This resolves a deadlock with the cancel directive when there is no explicit
>>> cancellation point. In that case, the implicit barrier acts as cancellation
>>> point. After removing the barrier after cancel, the now unmatched barrier
>>> for
>>> the explicit cancellation point has to go as well.
>>> 
>>> This has probably worked before rL255992: With the calls for the explicit
>>> barrier, it was sure that all threads passed a barrier before exiting.
>>> 
>>> Reported by Simon Convent and Joachim Protze!
>>> 
>>> Differential Revision: https://reviews.llvm.org/D30088
>>> 
>>> Modified:
>>>cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>>cfe/trunk/test/OpenMP/cancel_codegen.cpp
>>>cfe/trunk/test/OpenMP/cancellation_point_codegen.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21279: Fix some issues in clang-format's AlignConsecutive modes

2017-02-22 Thread Ben Harper via Phabricator via cfe-commits
bmharper updated this revision to Diff 89463.
bmharper added a comment.

Fixed two small issues raised by @daphnediane


https://reviews.llvm.org/D21279

Files:
  lib/Format/WhitespaceManager.cpp
  lib/Format/WhitespaceManager.h
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7539,12 +7539,11 @@
"};",
Alignment);
 
-  // FIXME: Should align all three assignments
   verifyFormat(
   "int i  = 1;\n"
   "SomeType a = SomeFunction(looongParameterA,\n"
   "  loongParameterB);\n"
-  "int j = 2;",
+  "int j  = 2;",
   Alignment);
 
   verifyFormat("template  2) ? 3 : 4);\n"
"float b[1][] = {{3.f}};\n",
Alignment);
+  verifyFormat("for (int i = 0; i < 1; i++)\n"
+   "  int x = 1;\n",
+   Alignment);
+  verifyFormat("for (i = 0; i < 1; i++)\n"
+   "  x = 1;\n"
+   "y = 1;\n",
+   Alignment);
 }
 
 TEST_F(FormatTest, AlignConsecutiveDeclarations) {
@@ -7626,7 +7632,57 @@
"unsigned oneTwoThree = 123;\n"
"int oneTwo = 12;",
Alignment));
+  // Function prototype alignment
+  verifyFormat("inta();\n"
+   "double b();",
+   Alignment);
+  verifyFormat("inta(int x);\n"
+   "double b();",
+   Alignment);
+  unsigned OldColumnLimit = Alignment.ColumnLimit;
+  // We need to set ColumnLimit to zero, in order to stress nested alignments,
+  // otherwise the function parameters will be re-flowed onto a single line.
+  Alignment.ColumnLimit = 0;
+  EXPECT_EQ("inta(int   x,\n"
+" float y);\n"
+"double b(intx,\n"
+" double y);",
+format("int a(int x,\n"
+   " float y);\n"
+   "double b(int x,\n"
+   " double y);",
+   Alignment));
+  // This ensures that function parameters of function declarations are
+  // correctly indented when their owning functions are indented.
+  // The failure case here is for 'double y' to not be indented enough.
+  EXPECT_EQ("double a(int x);\n"
+"intb(inty,\n"
+" double z);",
+format("double a(int x);\n"
+   "int b(int y,\n"
+   " double z);",
+   Alignment));
+  // Set ColumnLimit low so that we induce wrapping immediately after
+  // the function name and opening paren.
+  Alignment.ColumnLimit = 13;
+  verifyFormat("int function(\n"
+   "int  x,\n"
+   "bool y);",
+   Alignment);
+  Alignment.ColumnLimit = OldColumnLimit;
+  // Ensure function pointers don't screw up recursive alignment
+  verifyFormat("inta(int x, void (*fp)(int y));\n"
+   "double b();",
+   Alignment);
   Alignment.AlignConsecutiveAssignments = true;
+  // Ensure recursive alignment is broken by function braces, so that the
+  // "a = 1" does not align with subsequent assignments inside the function
+  // body.
+  verifyFormat("int func(int a = 1) {\n"
+   "  int b  = 2;\n"
+   "  int cc = 3;\n"
+   "}",
+   Alignment);
   verifyFormat("float  something = 2000;\n"
"double another   = 911;\n"
"inti = 1, j = 10;\n"
@@ -7636,6 +7692,28 @@
   verifyFormat("int  oneTwoThree = {0}; // comment\n"
"unsigned oneTwo  = 0;   // comment",
Alignment);
+  // Make sure that scope is correctly tracked, in the absence of braces
+  verifyFormat("for (int i = 0; i < n; i++)\n"
+   "  j = i;\n"
+   "double x = 1;\n",
+   Alignment);
+  verifyFormat("if (int i = 0)\n"
+   "  j = i;\n"
+   "double x = 1;\n",
+   Alignment);
+  // Ensure operator[] and operator() are comprehended
+  verifyFormat("struct test {\n"
+   "  long long int foo();\n"
+   "  int   operator[](int a);\n"
+   "  doublebar();\n"
+   "};\n",
+   Alignment);
+  verifyFormat("struct test {\n"
+   "  long long int foo();\n"
+   "  int   operator()(int a);\n"
+   "  doublebar();\n"
+   "};\n",
+   Alignment);
   EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
 "  int const i   = 1;\n"
 "  int * j   = 2;\n"
@@ -7737,17 +7815,16 @@
Alignment);
   Alignment.AlignConsecutiveAssignments = false;
 
-  // FIXME: Should align all three declarations
   verifyFormat(
   "int  i = 1;\n"
  

r295931 - [ODRHash] Handle types in ODR hashing.

2017-02-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Feb 22 21:25:57 2017
New Revision: 295931

URL: http://llvm.org/viewvc/llvm-project?rev=295931=rev
Log:
[ODRHash] Handle types in ODR hashing.

Fields will now have their types added to the hash, allowing for detection of
mismatched field types.  This detection allows the existing ODR checking to
produce the correct message.

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

Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=295931=295930=295931=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Wed Feb 22 21:25:57 2017
@@ -102,6 +102,10 @@ public:
 }
   }
 
+  void AddQualType(QualType T) {
+Hash.AddQualType(T);
+  }
+
   void Visit(const Decl *D) {
 ID.AddInteger(D->getKind());
 Inherited::Visit(D);
@@ -112,6 +116,11 @@ public:
 Inherited::VisitNamedDecl(D);
   }
 
+  void VisitValueDecl(const ValueDecl *D) {
+AddQualType(D->getType());
+Inherited::VisitValueDecl(D);
+  }
+
   void VisitAccessSpecDecl(const AccessSpecDecl *D) {
 ID.AddInteger(D->getAccess());
 Inherited::VisitAccessSpecDecl(D);
@@ -185,8 +194,59 @@ void ODRHash::AddDecl(const Decl *D) {
   ID.AddInteger(D->getKind());
 }
 
-void ODRHash::AddType(const Type *T) {}
-void ODRHash::AddQualType(QualType T) {}
+// Process a Type pointer.  Add* methods call back into ODRHash while Visit*
+// methods process the relevant parts of the Type.
+class ODRTypeVisitor : public TypeVisitor {
+  typedef TypeVisitor Inherited;
+  llvm::FoldingSetNodeID 
+  ODRHash 
+
+public:
+  ODRTypeVisitor(llvm::FoldingSetNodeID , ODRHash )
+  : ID(ID), Hash(Hash) {}
+
+  void AddStmt(Stmt *S) {
+Hash.AddBoolean(S);
+if (S) {
+  Hash.AddStmt(S);
+}
+  }
+
+  void Visit(const Type *T) {
+ID.AddInteger(T->getTypeClass());
+Inherited::Visit(T);
+  }
+
+  void VisitType(const Type *T) {}
+
+  void VisitBuiltinType(const BuiltinType *T) {
+ID.AddInteger(T->getKind());
+VisitType(T);
+  }
+};
+
+void ODRHash::AddType(const Type *T) {
+  assert(T && "Expecting non-null pointer.");
+  auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
+  ID.AddInteger(Result.first->second);
+  // On first encounter of a Type pointer, process it.  Every time afterwards,
+  // only the index value is needed.
+  if (!Result.second) {
+return;
+  }
+
+  ODRTypeVisitor(ID, *this).Visit(T);
+}
+
+void ODRHash::AddQualType(QualType T) {
+  AddBoolean(T.isNull());
+  if (T.isNull())
+return;
+  SplitQualType split = T.split();
+  ID.AddInteger(split.Quals.getAsOpaqueValue());
+  AddType(split.Ty);
+}
+
 void ODRHash::AddBoolean(bool Value) {
   Bools.push_back(Value);
 }

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=295931=295930=295931=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Wed Feb 22 21:25:57 2017
@@ -148,6 +148,20 @@ S2 s2;
 // expected-error@second.h:* {{'Field::S2' has different definitions in 
different modules; first difference is definition in module 'SecondModule' 
found field 'y'}}
 // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
 #endif
+
+#if defined(FIRST)
+struct S3 {
+  double x;
+};
+#elif defined(SECOND)
+struct S3 {
+  int x;
+};
+#else
+S3 s3;
+// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not 
present in definition of 'Field::S3' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+#endif
 }  // namespace Field
 
 // Naive parsing of AST can lead to cycles in processing.  Ensure


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


[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-02-22 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 89460.
xiangzhai added a comment.

Hi Anna,

Thanks for your suggest!

Firstly I uploaded Glib-MallocChecker-single-size-value.patch for code review, 
if submitted to UPSTREAM, then upload another one, correct?

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D28348

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/gmalloc.c

Index: test/Analysis/gmalloc.c
===
--- test/Analysis/gmalloc.c
+++ test/Analysis/gmalloc.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+typedef void* gpointer;
+typedef const void* gconstpointer;
+typedef unsigned long gsize;
+typedef unsigned int guint;
+
+gpointer g_malloc(gsize n_bytes);
+gpointer g_malloc0(gsize n_bytes);
+gpointer g_realloc(gpointer mem, gsize n_bytes);
+gpointer g_try_malloc(gsize n_bytes);
+gpointer g_try_malloc0(gsize n_bytes);
+gpointer g_try_realloc(gpointer mem, gsize n_bytes);
+void g_free(gpointer mem);
+gpointer g_memdup(gconstpointer mem, guint byte_size);
+
+static const gsize n_bytes = 1024;
+
+void f1() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g2); // expected-warning{{Attempt to free released memory}}
+}
+
+void f2() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+  g3 = g_memdup(g3, n_bytes); // expected-warning{{Use of memory after it is freed}}
+}
+
+void f3() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2); // expected-warning{{Potential leak of memory pointed to by 'g4'}}
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+}
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -174,7 +174,10 @@
 II_valloc(nullptr), II_reallocf(nullptr), II_strndup(nullptr),
 II_strdup(nullptr), II_win_strdup(nullptr), II_kmalloc(nullptr),
 II_if_nameindex(nullptr), II_if_freenameindex(nullptr),
-II_wcsdup(nullptr), II_win_wcsdup(nullptr) {}
+II_wcsdup(nullptr), II_win_wcsdup(nullptr), II_g_malloc(nullptr),
+II_g_malloc0(nullptr), II_g_realloc(nullptr), II_g_try_malloc(nullptr), 
+II_g_try_malloc0(nullptr), II_g_try_realloc(nullptr), 
+II_g_free(nullptr), II_g_memdup(nullptr) {}
 
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -236,7 +239,9 @@
  *II_realloc, *II_calloc, *II_valloc, *II_reallocf,
  *II_strndup, *II_strdup, *II_win_strdup, *II_kmalloc,
  *II_if_nameindex, *II_if_freenameindex, *II_wcsdup,
- *II_win_wcsdup;
+ *II_win_wcsdup, *II_g_malloc, *II_g_malloc0, 
+ *II_g_realloc, *II_g_try_malloc, *II_g_try_malloc0, 
+ *II_g_try_realloc, *II_g_free, *II_g_memdup;
   mutable Optional KernelZeroFlagVal;
 
   void initIdentifierInfo(ASTContext ) const;
@@ -554,6 +559,16 @@
   II_win_strdup = ("_strdup");
   II_win_wcsdup = ("_wcsdup");
   II_win_alloca = ("_alloca");
+
+  // Glib
+  II_g_malloc = ("g_malloc");
+  II_g_malloc0 = ("g_malloc0");
+  II_g_realloc = ("g_realloc");
+  II_g_try_malloc = ("g_try_malloc");
+  II_g_try_malloc0 = ("g_try_malloc0");
+  II_g_try_realloc = ("g_try_realloc");
+  II_g_free = ("g_free");
+  II_g_memdup = ("g_memdup");
 }
 
 bool MallocChecker::isMemFunction(const FunctionDecl *FD, ASTContext ) const {
@@ -589,15 +604,20 @@
 initIdentifierInfo(C);
 
 if (Family == AF_Malloc && CheckFree) {
-  if (FunI == II_free || FunI == II_realloc || FunI == II_reallocf)
+  if (FunI == II_free || FunI == II_realloc || FunI == II_reallocf || 
+  FunI == II_g_free)
 return true;
 }
 
 if (Family == AF_Malloc && CheckAlloc) {
   if (FunI == II_malloc || FunI == II_realloc || FunI == II_reallocf ||
   FunI == II_calloc || FunI == II_valloc || FunI == II_strdup ||
   FunI == II_win_strdup || FunI == II_strndup || FunI == II_wcsdup ||
-  FunI == II_win_wcsdup || FunI == II_kmalloc)
+  FunI == II_win_wcsdup || 

[PATCH] D30285: [ubsan] Don't check alignment if the alignment is 1

2017-02-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

If a pointer is 1-byte aligned, there's no use in checking its
alignment. Somewhat surprisingly, ubsan can spend a significant amount
of time doing just that!

This loosely depends on https://reviews.llvm.org/D30283.

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

I also compiled X86FastISel.cpp with -fsanitize=alignment using
patched/unpatched clangs based on r295686 with https://reviews.llvm.org/D30283 
applied. Here are
the number of alignment checks emitted:

| Setup  | # of alignment checks |
| unpatched + https://reviews.llvm.org/D30283, -O0 | 14307 |
| patched + https://reviews.llvm.org/D30283, -O0   | 12515 |


https://reviews.llvm.org/D30285

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/ubsan-suppress-checks.cpp
  test/CodeGenCXX/ubsan-type-checks.cpp


Index: test/CodeGenCXX/ubsan-type-checks.cpp
===
--- test/CodeGenCXX/ubsan-type-checks.cpp
+++ test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,16 +5,32 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN: and i64 %{{.*}}, 0, !nosanitize
+// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
 // OBJSIZE-NOT: call i64 @llvm.objectsize
   }
 };
 
+struct B {
+  int x;
+
+  // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+  void do_nothing() {
+// ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+// NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+// OBJSIZE-NOT: call i64 @llvm.objectsize
+  }
+};
+
 void force_irgen() {
   A a;
   a.do_nothing();
+
+  B b;
+  b.do_nothing();
 }
Index: test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -124,7 +124,7 @@
 // CHECK: call void @__ubsan_handle_type_mismatch
 //
 // Check the result of the conversion before using it.
-// CHECK: call void @__ubsan_handle_type_mismatch
+// NULL: call void @__ubsan_handle_type_mismatch
 //
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 B b;
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -597,7 +597,7 @@
   AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
 
 // The glvalue must be suitably aligned.
-if (AlignVal) {
+if (AlignVal > 1) {
   llvm::Value *Align =
   Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));


Index: test/CodeGenCXX/ubsan-type-checks.cpp
===
--- test/CodeGenCXX/ubsan-type-checks.cpp
+++ test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,16 +5,32 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN: and i64 %{{.*}}, 0, !nosanitize
+// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
 // OBJSIZE-NOT: call i64 @llvm.objectsize
   }
 };
 
+struct B {
+  int x;
+
+  // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+  void do_nothing() {
+// ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+// NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+// OBJSIZE-NOT: call i64 @llvm.objectsize
+  }
+};
+
 void force_irgen() {
   A a;
   a.do_nothing();
+
+  B b;
+  b.do_nothing();
 }
Index: test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -124,7 +124,7 @@
 // CHECK: call void @__ubsan_handle_type_mismatch
 //
 // Check the result of the conversion before using it.
-// CHECK: call void @__ubsan_handle_type_mismatch
+// NULL: call void @__ubsan_handle_type_mismatch
 //
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 B b;
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -597,7 +597,7 @@
   AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
 
 // The glvalue must be suitably aligned.
-if (AlignVal) {
+if (AlignVal > 1) {
   llvm::Value *Align =
   Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),

r295921 - Fix tracking of whether the previous template instantiation stack matches the current one.

2017-02-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb 22 20:09:03 2017
New Revision: 295921

URL: http://llvm.org/viewvc/llvm-project?rev=295921=rev
Log:
Fix tracking of whether the previous template instantiation stack matches the 
current one.

Rather than attempting to compare whether the previous and current top of
context stack are "equal" (which fails for a number of reasons, such as the
context stack entries containing pointers to objects on the stack, or reaching
the same "top of stack" entry through two different paths), track the depth of
context stack at which we last emitted a note and invalidate it when we pop the
context stack to less than that depth.

This causes us to emit some missing "in instantiation of" notes and to stop
emitting redundant "in instantiation of" stacks matching the previous stack in
rare cases.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/CXX/drs/dr4xx.cpp
cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp
cfe/trunk/test/SemaCXX/libstdcxx_pair_swap_hack.cpp
cfe/trunk/test/SemaCXX/make_integer_seq.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=295921=295920=295921=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Feb 22 20:09:03 2017
@@ -6922,39 +6922,6 @@ public:
 /// \brief Determines whether this template is an actual instantiation
 /// that should be counted toward the maximum instantiation depth.
 bool isInstantiationRecord() const;
-
-friend bool operator==(const CodeSynthesisContext ,
-   const CodeSynthesisContext ) {
-  if (X.Kind != Y.Kind)
-return false;
-
-  if (X.Entity != Y.Entity)
-return false;
-
-  switch (X.Kind) {
-  case TemplateInstantiation:
-  case ExceptionSpecInstantiation:
-return true;
-
-  case PriorTemplateArgumentSubstitution:
-  case DefaultTemplateArgumentChecking:
-return X.Template == Y.Template && X.TemplateArgs == Y.TemplateArgs;
-
-  case DefaultTemplateArgumentInstantiation:
-  case ExplicitTemplateArgumentSubstitution:
-  case DeducedTemplateArgumentSubstitution:
-  case DefaultFunctionArgumentInstantiation:
-return X.TemplateArgs == Y.TemplateArgs;
-
-  }
-
-  llvm_unreachable("Invalid InstantiationKind!");
-}
-
-friend bool operator!=(const CodeSynthesisContext ,
-   const CodeSynthesisContext ) {
-  return !(X == Y);
-}
   };
 
   /// \brief List of active code synthesis contexts.
@@ -7004,14 +6971,13 @@ public:
   // FIXME: Should we have a similar limit for other forms of synthesis?
   unsigned NonInstantiationEntries;
 
-  /// \brief The last template from which a template instantiation
+  /// \brief The depth of the context stack at the point when the most recent
   /// error or warning was produced.
   ///
-  /// This value is used to suppress printing of redundant template
-  /// instantiation backtraces when there are multiple errors in the
-  /// same instantiation. FIXME: Does this belong in Sema? It's tough
-  /// to implement it anywhere else.
-  CodeSynthesisContext LastTemplateInstantiationErrorContext;
+  /// This value is used to suppress printing of redundant context stacks
+  /// when there are multiple errors or warnings in the same instantiation.
+  // FIXME: Does this belong in Sema? It's tough to implement it anywhere else.
+  unsigned LastEmittedCodeSynthesisContextDepth = 0;
 
   /// \brief The current index into pack expansion arguments that will be
   /// used for substitution of parameter packs.
@@ -7192,11 +7158,9 @@ public:
 
   void PrintContextStack() {
 if (!CodeSynthesisContexts.empty() &&
-CodeSynthesisContexts.back() !=
-LastTemplateInstantiationErrorContext) {
+CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) {
   PrintInstantiationStack();
-  LastTemplateInstantiationErrorContext =
-  CodeSynthesisContexts.back();
+  LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size();
 }
   }
   void PrintInstantiationStack();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=295921=295920=295921=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 22 20:09:03 2017
@@ -11774,9 +11774,6 @@ static void RebuildLambdaScopeInfo(CXXMe
 
 Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
 SkipBodyInfo *SkipBody) {
-  // Clear the last template instantiation error context.
-  LastTemplateInstantiationErrorContext 

[PATCH] D30131: [profiling] PR31992: Don't skip interesting non-base constructors

2017-02-22 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.

One point to note, when we are displaying coverage for constructors that have 
both the base and complete versions instrumented, e.g.:

  class Foo {
  public:
  Foo() { }
  };
  
  class Bar : virtual public Foo {
  public:
 Bar() { }; // llvm-cov will show 2 instantiations for Bar()
  };
  
  class BarBar: public Bar {
  public:
BarBar() { }
  };
  
  int main (int argc, char* argv[])
  {
  BarBar b;
  Bar bb;
  }

llvm-cov will treat each constructor as an instantiation (like a template 
instantiation). Should they be treated as instantiations though?


https://reviews.llvm.org/D30131



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


[libclc] r295920 - math: Add native_tan as wrapper to tan

2017-02-22 Thread Aaron Watry via cfe-commits
Author: awatry
Date: Wed Feb 22 19:46:57 2017
New Revision: 295920

URL: http://llvm.org/viewvc/llvm-project?rev=295920=rev
Log:
math: Add native_tan as wrapper to tan

Trivially define native_tan as a redirect to tan.

If there are any targets with a native implementation, we can deal with it 
later.

Signed-off-by: Aaron Watry 
Reviewed-by: Matt Arsenault 

Added:
libclc/trunk/generic/include/clc/math/native_tan.h
Modified:
libclc/trunk/generic/include/clc/clc.h

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=295920=295919=295920=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Feb 22 19:46:57 2017
@@ -103,6 +103,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* 6.11.2.1 Floating-point macros */

Added: libclc/trunk/generic/include/clc/math/native_tan.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/native_tan.h?rev=295920=auto
==
--- libclc/trunk/generic/include/clc/math/native_tan.h (added)
+++ libclc/trunk/generic/include/clc/math/native_tan.h Wed Feb 22 19:46:57 2017
@@ -0,0 +1,10 @@
+//===-- generic/include/clc/math/native_tan.h 
-===//
+
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under both the University of Illinois Open Source
+// License and the MIT license. See LICENSE.TXT for details.
+//
+//===--===//
+#define native_tan tan


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


r295919 - Rename ActiveTemplateInstantiation to CodeSynthesisContext in preparation for

2017-02-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb 22 19:43:54 2017
New Revision: 295919

URL: http://llvm.org/viewvc/llvm-project?rev=295919=rev
Log:
Rename ActiveTemplateInstantiation to CodeSynthesisContext in preparation for
using it for other kinds of context (where we currently produce context notes
in a highly ad-hoc manner).

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=295919=295918=295919=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Feb 22 19:43:54 2017
@@ -6837,10 +6837,12 @@ public:
bool RelativeToPrimary = false,
const FunctionDecl *Pattern = nullptr);
 
-  /// \brief A template instantiation that is currently in progress.
-  struct ActiveTemplateInstantiation {
+  /// A context in which code is being synthesized (where a source location
+  /// alone is not sufficient to identify the context). This covers template
+  /// instantiation and various forms of implicitly-generated functions.
+  struct CodeSynthesisContext {
 /// \brief The kind of template instantiation we are performing
-enum InstantiationKind {
+enum SynthesisKind {
   /// We are instantiating a template declaration. The entity is
   /// the declaration we're instantiating (e.g., a CXXRecordDecl).
   TemplateInstantiation,
@@ -6913,7 +6915,7 @@ public:
 /// template instantiation.
 SourceRange InstantiationRange;
 
-ActiveTemplateInstantiation()
+CodeSynthesisContext()
   : Kind(TemplateInstantiation), Template(nullptr), Entity(nullptr),
 TemplateArgs(nullptr), NumTemplateArgs(0), DeductionInfo(nullptr) {}
 
@@ -6921,8 +6923,8 @@ public:
 /// that should be counted toward the maximum instantiation depth.
 bool isInstantiationRecord() const;
 
-friend bool operator==(const ActiveTemplateInstantiation ,
-   const ActiveTemplateInstantiation ) {
+friend bool operator==(const CodeSynthesisContext ,
+   const CodeSynthesisContext ) {
   if (X.Kind != Y.Kind)
 return false;
 
@@ -6949,20 +6951,17 @@ public:
   llvm_unreachable("Invalid InstantiationKind!");
 }
 
-friend bool operator!=(const ActiveTemplateInstantiation ,
-   const ActiveTemplateInstantiation ) {
+friend bool operator!=(const CodeSynthesisContext ,
+   const CodeSynthesisContext ) {
   return !(X == Y);
 }
   };
 
-  /// \brief List of active template instantiations.
+  /// \brief List of active code synthesis contexts.
   ///
-  /// This vector is treated as a stack. As one template instantiation
-  /// requires another template instantiation, additional
-  /// instantiations are pushed onto the stack up to a
-  /// user-configurable limit LangOptions::InstantiationDepth.
-  SmallVector
-ActiveTemplateInstantiations;
+  /// This vector is treated as a stack. As synthesis of one entity requires
+  /// synthesis of another, additional contexts are pushed onto the stack.
+  SmallVector CodeSynthesisContexts;
 
   /// Specializations whose definitions are currently being instantiated.
   llvm::DenseSet InstantiatingSpecializations;
@@ -6973,7 +6972,7 @@ public:
 
   /// \brief Extra modules inspected when performing a lookup during a template
   /// instantiation. Computed lazily.
-  SmallVector ActiveTemplateInstantiationLookupModules;
+  SmallVector CodeSynthesisContextLookupModules;
 
   /// \brief Cache of additional modules that should be used for name lookup
   /// within the current template instantiation. Computed lazily; use
@@ -6996,9 +6995,13 @@ public:
   /// of a template instantiation or template argument deduction.
   bool InNonInstantiationSFINAEContext;
 
-  /// \brief The number of ActiveTemplateInstantiation entries in
-  /// \c ActiveTemplateInstantiations that are not actual instantiations and,
-  /// therefore, should not be counted as part of the instantiation depth.
+  /// \brief The number of \p CodeSynthesisContexts that are not template
+  /// instantiations and, therefore, should not be counted as part of the
+  /// instantiation depth.
+  ///
+  /// When the instantiation depth reaches the user-configurable limit
+  /// \p LangOptions::InstantiationDepth we will abort 

[PATCH] D30283: [ubsan] Reduce alignment checking of C++ object pointers

2017-02-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

This patch teaches ubsan to insert an alignment check for the 'this'
pointer at the start of each method/lambda. This allows clang to emit
significantly fewer alignment checks overall, because if 'this' is
aligned, so are its fields.

This is essentially the same thing r295515 does, but for the alignment
check instead of the null check.

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

I also compiled X86FastISel.cpp with -fsanitize=alignment using
patched/unpatched clangs based on r295686. Here are the number of
alignment checks emitted:

| Setup  | # of alignment checks |
| unpatched, -O0 | 24918 |
| patched, -O0   | 14307 |

There are a few possible follow-ups:

- Don't add the per method/lambda check in delegating constructors.
- Don't instrument accesses to fields with alignment = 1.


https://reviews.llvm.org/D30283

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/catch-undef-behavior.c
  test/CodeGen/sanitize-recover.c
  test/CodeGenCXX/ubsan-suppress-checks.cpp
  test/CodeGenCXX/ubsan-suppress-null-checks.cpp
  test/CodeGenCXX/ubsan-type-checks.cpp

Index: test/CodeGenCXX/ubsan-type-checks.cpp
===
--- test/CodeGenCXX/ubsan-type-checks.cpp
+++ test/CodeGenCXX/ubsan-type-checks.cpp
@@ -5,8 +5,8 @@
 struct A {
   // COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
-// ALIGN-NOT: and i64 %{{.*}}, 7, !nosanitize
+// ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %{{.*}}, 0, !nosanitize
  
 // NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
  
Index: test/CodeGenCXX/ubsan-suppress-checks.cpp
===
--- test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -1,24 +1,28 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=null | FileCheck %s
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=null -DCHECK_LAMBDA | FileCheck %s --check-prefix=LAMBDA
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment | FileCheck %s --check-prefixes=CHECK,ALIGN
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=null | FileCheck %s --check-prefixes=CHECK,NULL
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=alignment,null -DCHECK_LAMBDA | FileCheck %s --check-prefixes=LAMBDA
 
 struct A {
   int foo;
 
   // CHECK-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
   void do_nothing() {
-// CHECK: icmp ne %struct.A* %[[THIS1:[a-z0-9]+]], null, !nosanitize
-// CHECK: ptrtoint %struct.A* %[[THIS1]] to i64, !nosanitize
-// CHECK-NEXT: call void @__ubsan_handle_type_mismatch
+// ALIGN: %[[THISINT1:[0-9]+]] = ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %[[THISINT1]], 3, !nosanitize
+// NULL: icmp ne %struct.A* %[[THIS1:[a-z0-9]+]], null, !nosanitize
+// NULL: ptrtoint %struct.A* %[[THIS1]] to i64, !nosanitize
+// CHECK: call void @__ubsan_handle_type_mismatch
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 // CHECK: ret void
   }
 
 #ifdef CHECK_LAMBDA
   // LAMBDA-LABEL: define linkonce_odr void @_ZN1A22do_nothing_with_lambdaEv
   void do_nothing_with_lambda() {
 // LAMBDA: icmp ne %struct.A* %[[THIS2:[a-z0-9]+]], null, !nosanitize
-// LAMBDA: ptrtoint %struct.A* %[[THIS2]] to i64, !nosanitize
-// LAMBDA-NEXT: call void @__ubsan_handle_type_mismatch
+// LAMBDA: %[[THISINT2:[0-9]+]] = ptrtoint %struct.A* %[[THIS2]] to i64, !nosanitize
+// LAMBDA: and i64 %[[THISINT2]], 3, !nosanitize
+// LAMBDA: call void @__ubsan_handle_type_mismatch
 
 auto f = [&] {
   foo = 0;
@@ -38,49 +42,59 @@
 
   // CHECK-LABEL: define linkonce_odr i32 @_ZN1A11load_memberEv
   int load_member() {
-// CHECK: icmp ne %struct.A* %[[THIS3:[a-z0-9]+]], null, !nosanitize
-// CHECK: ptrtoint %struct.A* %[[THIS3]] to i64, !nosanitize
-// CHECK-NEXT: call void @__ubsan_handle_type_mismatch
+// ALIGN: %[[THISINT3:[0-9]+]] = ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
+// ALIGN: and i64 %[[THISINT3]], 3, !nosanitize
+// NULL: icmp ne %struct.A* %[[THIS3:[a-z0-9]+]], null, !nosanitize
+// NULL: ptrtoint %struct.A* %[[THIS3]] to i64, !nosanitize
+// CHECK: call void @__ubsan_handle_type_mismatch
 // CHECK-NOT: call void @__ubsan_handle_type_mismatch
 return foo;
 // CHECK: ret i32
   }
 
   // CHECK-LABEL: define linkonce_odr i32 @_ZN1A11call_methodEv
   int call_method() {
-// CHECK: icmp ne %struct.A* %[[THIS4:[a-z0-9]+]], null, !nosanitize
-// CHECK: 

r295918 - Rename a helper function, NFC.

2017-02-22 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Wed Feb 22 19:22:38 2017
New Revision: 295918

URL: http://llvm.org/viewvc/llvm-project?rev=295918=rev
Log:
Rename a helper function, NFC.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=295918=295917=295918=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Feb 22 19:22:38 2017
@@ -952,7 +952,7 @@ LValue CodeGenFunction::EmitUnsupportedL
 E->getType());
 }
 
-bool CodeGenFunction::CanElideObjectPointerNullCheck(const Expr *Obj) {
+bool CodeGenFunction::IsDeclRefOrWrappedCXXThis(const Expr *Obj) {
   if (isa(Obj))
 return true;
 
@@ -987,7 +987,7 @@ LValue CodeGenFunction::EmitCheckedLValu
   if (!isa(E) && !LV.isBitField() && LV.isSimple()) {
 SanitizerSet SkippedChecks;
 if (const auto *ME = dyn_cast(E))
-  if (CanElideObjectPointerNullCheck(ME->getBase()))
+  if (IsDeclRefOrWrappedCXXThis(ME->getBase()))
 SkippedChecks.set(SanitizerKind::Null, true);
 EmitTypeCheck(TCK, E->getExprLoc(), LV.getPointer(),
   E->getType(), LV.getAlignment(), SkippedChecks);
@@ -3372,7 +3372,7 @@ LValue CodeGenFunction::EmitMemberExpr(c
 Address Addr = EmitPointerWithAlignment(BaseExpr, );
 QualType PtrTy = BaseExpr->getType()->getPointeeType();
 SanitizerSet SkippedChecks;
-if (CanElideObjectPointerNullCheck(BaseExpr))
+if (IsDeclRefOrWrappedCXXThis(BaseExpr))
   SkippedChecks.set(SanitizerKind::Null, true);
 EmitTypeCheck(TCK_MemberAccess, E->getExprLoc(), Addr.getPointer(), PtrTy,
   /*Alignment=*/CharUnits::Zero(), SkippedChecks);

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=295918=295917=295918=diff
==
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Feb 22 19:22:38 2017
@@ -292,7 +292,7 @@ RValue CodeGenFunction::EmitCXXMemberOrO
 
   SanitizerSet SkippedChecks;
   if (const auto *CMCE = dyn_cast(CE))
-if (CanElideObjectPointerNullCheck(CMCE->getImplicitObjectArgument()))
+if (IsDeclRefOrWrappedCXXThis(CMCE->getImplicitObjectArgument()))
   SkippedChecks.set(SanitizerKind::Null, true);
   EmitTypeCheck(
   isa(CalleeDecl) ? 
CodeGenFunction::TCK_ConstructorCall

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=295918=295917=295918=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Feb 22 19:22:38 2017
@@ -2030,8 +2030,9 @@ public:
   llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
   llvm::BasicBlock *GetIndirectGotoBlock();
 
-  /// Check if the null check for \p ObjectPointer can be skipped.
-  static bool CanElideObjectPointerNullCheck(const Expr *ObjectPointer);
+  /// Check if \p E is a reference, or a C++ "this" pointer wrapped in value-
+  /// preserving casts.
+  static bool IsDeclRefOrWrappedCXXThis(const Expr *E);
 
   /// EmitNullInitialization - Generate code to set a value of the given type 
to
   /// null, If the type contains data member pointers, they will be initialized


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


r295911 - [ODRHash] Add IdentiferInfo and FieldDecl support.

2017-02-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Feb 22 18:23:01 2017
New Revision: 295911

URL: http://llvm.org/viewvc/llvm-project?rev=295911=rev
Log:
[ODRHash] Add IdentiferInfo and FieldDecl support.

IdentifierInfo is hashed based on the stored string.  FieldDecl versus other
Decl is now detected, as well as differently named fields.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=295911=295910=295911=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed Feb 22 
18:23:01 2017
@@ -121,10 +121,10 @@ def err_module_odr_violation_mismatch_de
   "%q0 has different definitions in different modules; first difference is "
   "%select{definition in module '%2'|defined here}1 found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier|static assert}3">;
+  "protected access specifier|static assert|field}3">;
 def note_module_odr_violation_mismatch_decl : Note<"but in '%0' found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier|static assert}1">;
+  "protected access specifier|static assert|field}1">;
 
 def err_module_odr_violation_mismatch_decl_diff : Error<
   "%q0 has different definitions in different modules; first difference is "
@@ -132,13 +132,15 @@ def err_module_odr_violation_mismatch_de
   "%select{"
   "static assert with condition|"
   "static assert with message|"
-  "static assert with %select{|no }4message}3">;
+  "static assert with %select{|no }4message|"
+  "field %4}3">;
 
 def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
   "%select{"
   "static assert with different condition|"
   "static assert with different message|"
-  "static assert with %select{|no }2message}1">;
+  "static assert with %select{|no }2message|"
+  "field %2}1">;
 
 def warn_module_uses_date_time : Warning<
   "%select{precompiled header|module}0 uses __DATE__ or __TIME__">,

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=295911=295910=295911=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Wed Feb 22 18:23:01 2017
@@ -26,7 +26,12 @@ void ODRHash::AddStmt(const Stmt *S) {
   assert(S && "Expecting non-null pointer.");
   S->ProcessODRHash(ID, *this);
 }
-void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {}
+
+void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
+  assert(II && "Expecting non-null pointer.");
+  ID.AddString(II->getName());
+}
+
 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {}
 void ODRHash::AddTemplateName(TemplateName Name) {}
 void ODRHash::AddDeclarationName(DeclarationName Name) {}
@@ -90,11 +95,23 @@ public:
 }
   }
 
+  void AddIdentifierInfo(const IdentifierInfo *II) {
+Hash.AddBoolean(II);
+if (II) {
+  Hash.AddIdentifierInfo(II);
+}
+  }
+
   void Visit(const Decl *D) {
 ID.AddInteger(D->getKind());
 Inherited::Visit(D);
   }
 
+  void VisitNamedDecl(const NamedDecl *D) {
+AddIdentifierInfo(D->getIdentifier());
+Inherited::VisitNamedDecl(D);
+  }
+
   void VisitAccessSpecDecl(const AccessSpecDecl *D) {
 ID.AddInteger(D->getAccess());
 Inherited::VisitAccessSpecDecl(D);
@@ -106,6 +123,10 @@ public:
 
 Inherited::VisitStaticAssertDecl(D);
   }
+
+  void VisitFieldDecl(const FieldDecl *D) {
+Inherited::VisitFieldDecl(D);
+  }
 };
 
 // Only allow a small portion of Decl's to be processed.  Remove this once
@@ -118,6 +139,7 @@ bool ODRHash::isWhitelistedDecl(const De
 default:
   return false;
 case Decl::AccessSpec:
+case Decl::Field:
 case Decl::StaticAssert:
   return true;
   }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=295911=295910=295911=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Feb 22 18:23:01 2017
@@ -8956,6 +8956,7 @@ void ASTReader::diagnoseOdrViolations()
 PrivateSpecifer,
 ProtectedSpecifer,
 StaticAssert,
+Field,
 Other
   } FirstDiffType = Other,
 SecondDiffType = Other;
@@ -8979,6 +8980,8 @@ void 

[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Ping, is the argument in favor of making the change in my last comment 
satisfactory?


https://reviews.llvm.org/D29369



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


r295903 - [ObjC][Modules] Don't perform property lookup in hidden class extensions

2017-02-22 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Feb 22 17:18:49 2017
New Revision: 295903

URL: http://llvm.org/viewvc/llvm-project?rev=295903=rev
Log:
[ObjC][Modules] Don't perform property lookup in hidden class extensions

rdar://30603803

Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/test/Modules/Inputs/category_right_sub.h
cfe/trunk/test/Modules/objc-categories.m

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=295903=295902=295903=diff
==
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Feb 22 17:18:49 2017
@@ -162,10 +162,10 @@ ObjCPropertyDecl::findPropertyDecl(const
 return nullptr;
   }
 
-  // If context is class, then lookup property in its extensions.
+  // If context is class, then lookup property in its visible extensions.
   // This comes before property is looked up in primary class.
   if (auto *IDecl = dyn_cast(DC)) {
-for (const auto *Ext : IDecl->known_extensions())
+for (const auto *Ext : IDecl->visible_extensions())
   if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext,
propertyID,
queryKind))

Modified: cfe/trunk/test/Modules/Inputs/category_right_sub.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/category_right_sub.h?rev=295903=295902=295903=diff
==
--- cfe/trunk/test/Modules/Inputs/category_right_sub.h (original)
+++ cfe/trunk/test/Modules/Inputs/category_right_sub.h Wed Feb 22 17:18:49 2017
@@ -15,3 +15,8 @@
 
 @interface Foo(LeftP4) 
 @end
+
+// A hidden extension
+@interface Foo ()
+@property (assign) int hiddenPropertyFromExtension;
+@end

Modified: cfe/trunk/test/Modules/objc-categories.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/objc-categories.m?rev=295903=295902=295903=diff
==
--- cfe/trunk/test/Modules/objc-categories.m (original)
+++ cfe/trunk/test/Modules/objc-categories.m Wed Feb 22 17:18:49 2017
@@ -53,6 +53,9 @@ void test_hidden_all_errors(Foo *foo) {
   p3p = foo.p3_prop; // expected-error{{property 'p3_prop' not found on object 
of type 'Foo *'}}
   id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on 
object of type 'id'}}
   p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object 
of type 'Foo *'}}
+
+  if (foo.hiddenPropertyFromExtension) { // expected-error {{property 
'hiddenPropertyFromExtension' not found on object of type 'Foo *'}}
+  }
 }
 
 @import category_left.sub;
@@ -74,6 +77,7 @@ void test_hidden_right_errors(Foo *foo)
   id p4p = p4.p4_prop; // expected-error{{property 'p4_prop' not found on 
object of type 'id'}}
   p4p = foo.p4_prop; // expected-error{{property 'p4_prop' not found on object 
of type 'Foo *'; did you mean 'p3_prop'?}}
   // expected-note@Inputs/category_left_sub.h:7{{'p3_prop' declared here}}
+  int hiddenFromExtension = foo.hiddenPropertyFromExtension; // expected-error 
{{property 'hiddenPropertyFromExtension' not found on object of type 'Foo *'}}
 }
 
 @import category_right.sub;
@@ -92,4 +96,6 @@ void test_hidden_okay(Foo *foo) {
   p3p = foo.p3_prop;
   id p4p = p4.p4_prop;
   p4p = foo.p4_prop;
+  if (foo.hiddenPropertyFromExtension) {
+  }
 }


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


r295894 - [CodeGen] Add param info for ctors with ABI args.

2017-02-22 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Feb 22 16:38:25 2017
New Revision: 295894

URL: http://llvm.org/viewvc/llvm-project?rev=295894=rev
Log:
[CodeGen] Add param info for ctors with ABI args.

This fixes a few assertion failures. Please see the added test case.

Added:
cfe/trunk/test/CodeGenObjCXX/arc-attrs-abi.mm
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=295894=295893=295894=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Feb 22 16:38:25 2017
@@ -288,7 +288,17 @@ CodeGenTypes::arrangeCXXStructorDeclarat
   if (PassParams)
 appendParameterTypes(*this, argTypes, paramInfos, FTP, MD);
 
-  TheCXXABI.buildStructorSignature(MD, Type, argTypes);
+  CGCXXABI::AddedStructorArgs AddedArgs =
+  TheCXXABI.buildStructorSignature(MD, Type, argTypes);
+  if (!paramInfos.empty()) {
+// Note: prefix implies after the first param.
+if (AddedArgs.Prefix)
+  paramInfos.insert(paramInfos.begin() + 1, AddedArgs.Prefix,
+FunctionProtoType::ExtParameterInfo{});
+if (AddedArgs.Suffix)
+  paramInfos.append(AddedArgs.Suffix,
+FunctionProtoType::ExtParameterInfo{});
+  }
 
   RequiredArgs required =
   (PassParams && MD->isVariadic() ? RequiredArgs(argTypes.size())

Added: cfe/trunk/test/CodeGenObjCXX/arc-attrs-abi.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-attrs-abi.mm?rev=295894=auto
==
--- cfe/trunk/test/CodeGenObjCXX/arc-attrs-abi.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/arc-attrs-abi.mm Wed Feb 22 16:38:25 2017
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-apple -emit-llvm -fobjc-arc -o - %s
+// RUN: %clang_cc1 -triple x86_64-windows -emit-llvm -fobjc-arc -o - %s
+//
+// Test caess where we weren't properly adding parameter infos declarations,
+// which caused assertions to fire. Hence, no CHECKs.
+
+struct VirtualBase {
+  VirtualBase(__attribute__((ns_consumed)) id x);
+};
+struct WithVirtualBase : virtual VirtualBase {
+  WithVirtualBase(__attribute__((ns_consumed)) id x);
+};
+
+WithVirtualBase::WithVirtualBase(__attribute__((ns_consumed)) id x)
+: VirtualBase(x) {}


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


[PATCH] D29621: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks

2017-02-22 Thread Samuel Benzaquen via Phabricator via cfe-commits
sbenza added inline comments.



Comment at: lib/Tooling/RefactoringCallbacks.cpp:213
+llvm::errs() << "Node " << Element.Value
+ << " used in replacement template not bound in Matcher 
\n";
+llvm_unreachable("Unbound node in replacement template.");

I don't know if stderr is the best place for this error output.
Maybe we should take a sink of some sort in the constructor.



Comment at: lib/Tooling/RefactoringCallbacks.cpp:214
+ << " used in replacement template not bound in Matcher 
\n";
+llvm_unreachable("Unbound node in replacement template.");
+  }

I don't think this is ok.
afaik, llvm_unreachable leads to undefined behavior if it is reached in opt 
mode.
This error can be triggered from user input. We should not fail that way.



Comment at: lib/Tooling/RefactoringCallbacks.cpp:227
+  if (NodeMap.count(FromId) == 0) {
+llvm::errs() << "Node to be replaced " << FromId
+ << " not bound in query.\n";

Same as above. This error can be triggered from user input.


https://reviews.llvm.org/D29621



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


[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-02-22 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Could you please split the patch into two - one with the previously reviewed 
support for functions that take a single size value and another patch that 
models the two size arguments (num and size). It's easier to review patches if 
they do not grow new functionality. Splitting the patch would also play nicely 
with the incremental development policy of LLVM.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D28348



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


r295890 - [ODRHash] static_cast and Stmt hashing.

2017-02-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Feb 22 16:22:42 2017
New Revision: 295890

URL: http://llvm.org/viewvc/llvm-project?rev=295890=rev
Log:
[ODRHash] static_cast and Stmt hashing.

Add support for static_cast in classes.  Add pointer-independent profiling for
Stmt's, sharing most of the logic with Stmt::Profile.  This is the first of the
deep sub-Decl diffing for error messages.

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

Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=295890=295889=295890=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Feb 22 16:22:42 2017
@@ -39,6 +39,7 @@ namespace clang {
   class Expr;
   class IdentifierInfo;
   class LabelDecl;
+  class ODRHash;
   class ParmVarDecl;
   class PrinterHelper;
   struct PrintingPolicy;
@@ -436,6 +437,15 @@ public:
   /// written in the source.
   void Profile(llvm::FoldingSetNodeID , const ASTContext ,
bool Canonical) const;
+
+  /// \brief Calculate a unique representation for a statement that is
+  /// stable across compiler invocations.
+  ///
+  /// \param ID profile information will be stored in ID.
+  ///
+  /// \param Hash an ODRHash object which will be called where pointers would
+  /// have been used in the Profile function.
+  void ProcessODRHash(llvm::FoldingSetNodeID , ODRHash& Hash) const;
 };
 
 /// DeclStmt - Adaptor class for mixing declarations with statements and

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=295890=295889=295890=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed Feb 22 
16:22:42 2017
@@ -121,10 +121,24 @@ def err_module_odr_violation_mismatch_de
   "%q0 has different definitions in different modules; first difference is "
   "%select{definition in module '%2'|defined here}1 found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier}3">;
+  "protected access specifier|static assert}3">;
 def note_module_odr_violation_mismatch_decl : Note<"but in '%0' found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier}1">;
+  "protected access specifier|static assert}1">;
+
+def err_module_odr_violation_mismatch_decl_diff : Error<
+  "%q0 has different definitions in different modules; first difference is "
+  "%select{definition in module '%2'|defined here}1 found "
+  "%select{"
+  "static assert with condition|"
+  "static assert with message|"
+  "static assert with %select{|no }4message}3">;
+
+def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
+  "%select{"
+  "static assert with different condition|"
+  "static assert with different message|"
+  "static assert with %select{|no }2message}1">;
 
 def warn_module_uses_date_time : Warning<
   "%select{precompiled header|module}0 uses __DATE__ or __TIME__">,

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=295890=295889=295890=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Wed Feb 22 16:22:42 2017
@@ -22,7 +22,10 @@
 
 using namespace clang;
 
-void ODRHash::AddStmt(const Stmt *S) {}
+void ODRHash::AddStmt(const Stmt *S) {
+  assert(S && "Expecting non-null pointer.");
+  S->ProcessODRHash(ID, *this);
+}
 void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {}
 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {}
 void ODRHash::AddTemplateName(TemplateName Name) {}
@@ -74,10 +77,18 @@ unsigned ODRHash::CalculateHash() {
 class ODRDeclVisitor : public ConstDeclVisitor {
   typedef ConstDeclVisitor Inherited;
   llvm::FoldingSetNodeID 
+  ODRHash 
 
 public:
-  ODRDeclVisitor(llvm::FoldingSetNodeID )
-  : ID(ID) {}
+  ODRDeclVisitor(llvm::FoldingSetNodeID , ODRHash )
+  : ID(ID), Hash(Hash) {}
+
+  void AddStmt(const Stmt *S) {
+Hash.AddBoolean(S);
+if (S) {
+  Hash.AddStmt(S);
+}
+  }
 
   void Visit(const Decl *D) {
 ID.AddInteger(D->getKind());
@@ -88,6 +99,13 @@ public:
 ID.AddInteger(D->getAccess());
 Inherited::VisitAccessSpecDecl(D);
   }
+
+  void VisitStaticAssertDecl(const StaticAssertDecl *D) 

[PATCH] D29621: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks

2017-02-22 Thread Julian Bangert via Phabricator via cfe-commits
jbangert accepted this revision.
jbangert added a comment.

Thanks, added tests for parser failures.


https://reviews.llvm.org/D29621



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


[PATCH] D29621: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks

2017-02-22 Thread Julian Bangert via Phabricator via cfe-commits
jbangert updated this revision to Diff 89420.
jbangert marked an inline comment as done.
jbangert added a comment.

- additional tests


https://reviews.llvm.org/D29621

Files:
  include/clang/Tooling/RefactoringCallbacks.h
  lib/Tooling/RefactoringCallbacks.cpp
  unittests/Tooling/RefactoringCallbacksTest.cpp

Index: unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- unittests/Tooling/RefactoringCallbacksTest.cpp
+++ unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -7,31 +7,30 @@
 //
 //===--===//
 
-#include "clang/Tooling/RefactoringCallbacks.h"
 #include "RewriterTestContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/RefactoringCallbacks.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace tooling {
 
 using namespace ast_matchers;
 
 template 
-void expectRewritten(const std::string ,
- const std::string ,
- const T ,
- RefactoringCallback ) {
-  MatchFinder Finder;
+void expectRewritten(const std::string , const std::string ,
+ const T , RefactoringCallback ) {
+  std::map FileToReplace;
+  ASTMatchRefactorer Finder(FileToReplace);
   Finder.addMatcher(AMatcher, );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
   << "Parsing error in \"" << Code << "\"";
   RewriterTestContext Context;
   FileID ID = Context.createInMemoryFile("input.cc", Code);
-  EXPECT_TRUE(tooling::applyAllReplacements(Callback.getReplacements(),
+  EXPECT_TRUE(tooling::applyAllReplacements(FileToReplace["input.cc"],
 Context.Rewrite));
   EXPECT_EQ(Expected, Context.getRewrittenText(ID));
 }
@@ -61,40 +60,94 @@
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { int i = 2; }";
   ReplaceStmtWithText Callback("id", "2");
-  expectRewritten(Code, Expected, id("id", expr(integerLiteral())),
-  Callback);
+  expectRewritten(Code, Expected, id("id", expr(integerLiteral())), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) {
   std::string Code = "void f() { int i = false ? 1 : i * 2; }";
   std::string Expected = "void f() { int i = i * 2; }";
   ReplaceStmtWithStmt Callback("always-false", "should-be");
-  expectRewritten(Code, Expected,
-  id("always-false", conditionalOperator(
-  hasCondition(cxxBoolLiteral(equals(false))),
-  hasFalseExpression(id("should-be", expr(),
+  expectRewritten(
+  Code, Expected,
+  id("always-false",
+ conditionalOperator(hasCondition(cxxBoolLiteral(equals(false))),
+ hasFalseExpression(id("should-be", expr(),
   Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesIfStmt) {
   std::string Code = "bool a; void f() { if (a) f(); else a = true; }";
   std::string Expected = "bool a; void f() { f(); }";
   ReplaceIfStmtWithItsBody Callback("id", true);
-  expectRewritten(Code, Expected,
-  id("id", ifStmt(
-  hasCondition(implicitCastExpr(hasSourceExpression(
-  declRefExpr(to(varDecl(hasName("a"),
+  expectRewritten(
+  Code, Expected,
+  id("id", ifStmt(hasCondition(implicitCastExpr(hasSourceExpression(
+   declRefExpr(to(varDecl(hasName("a"),
   Callback);
 }
 
 TEST(RefactoringCallbacksTest, RemovesEntireIfOnEmptyElse) {
   std::string Code = "void f() { if (false) int i = 0; }";
   std::string Expected = "void f() {  }";
   ReplaceIfStmtWithItsBody Callback("id", false);
   expectRewritten(Code, Expected,
-  id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false),
-  Callback);
+  id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false),
+  Callback);
 }
 
+TEST(RefactoringCallbacksTest, TemplateJustText) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { FOO }";
+  auto Callback = ReplaceNodeWithTemplate::create("id", "FOO");
+  EXPECT_FALSE(Callback.takeError());
+  expectRewritten(Code, Expected, id("id", declStmt()), **Callback);
+}
+
+TEST(RefactoringCallbacksTest, TemplateSimpleSubst) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { long x = 1; }";
+  auto Callback = ReplaceNodeWithTemplate::create("decl", "long x = ${init}");
+  EXPECT_FALSE(Callback.takeError());
+  expectRewritten(Code, Expected,
+  id("decl", varDecl(hasInitializer(id("init", expr(),
+  **Callback);
+}
+
+TEST(RefactoringCallbacksTest, TemplateLiteral) {
+  std::string Code = "void f() { int i = 1; }";
+  std::string Expected = "void f() { string x = \"$-1\"; }";
+  auto Callback = 

r295886 - PR32034: Evaluate _Atomic(T) in-place when T is a class or array type.

2017-02-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb 22 16:09:50 2017
New Revision: 295886

URL: http://llvm.org/viewvc/llvm-project?rev=295886=rev
Log:
PR32034: Evaluate _Atomic(T) in-place when T is a class or array type.

This is necessary in order for the evaluation of an _Atomic initializer for
those types to have an associated object, which an initializer for class or
array type needs.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=295886=295885=295886=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Feb 22 16:09:50 2017
@@ -1437,7 +1437,8 @@ static bool EvaluateIntegerOrLValue(cons
 EvalInfo );
 static bool EvaluateFloat(const Expr *E, APFloat , EvalInfo );
 static bool EvaluateComplex(const Expr *E, ComplexValue , EvalInfo );
-static bool EvaluateAtomic(const Expr *E, APValue , EvalInfo );
+static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue ,
+   EvalInfo );
 static bool EvaluateAsRValue(EvalInfo , const Expr *E, APValue );
 
 
//===--===//
@@ -4743,7 +4744,10 @@ public:
 
 case CK_AtomicToNonAtomic: {
   APValue AtomicVal;
-  if (!EvaluateAtomic(E->getSubExpr(), AtomicVal, Info))
+  // This does not need to be done in place even for class/array types:
+  // atomic-to-non-atomic conversion implies copying the object
+  // representation.
+  if (!Evaluate(AtomicVal, Info, E->getSubExpr()))
 return false;
   return DerivedSuccess(AtomicVal, E);
 }
@@ -9689,10 +9693,11 @@ bool ComplexExprEvaluator::VisitInitList
 namespace {
 class AtomicExprEvaluator :
 public ExprEvaluatorBase {
+  const LValue *This;
   APValue 
 public:
-  AtomicExprEvaluator(EvalInfo , APValue )
-  : ExprEvaluatorBaseTy(Info), Result(Result) {}
+  AtomicExprEvaluator(EvalInfo , const LValue *This, APValue )
+  : ExprEvaluatorBaseTy(Info), This(This), Result(Result) {}
 
   bool Success(const APValue , const Expr *E) {
 Result = V;
@@ -9702,7 +9707,10 @@ public:
   bool ZeroInitialization(const Expr *E) {
 ImplicitValueInitExpr VIE(
 E->getType()->castAs()->getValueType());
-return Evaluate(Result, Info, );
+// For atomic-qualified class (and array) types in C++, initialize the
+// _Atomic-wrapped subobject directly, in-place.
+return This ? EvaluateInPlace(Result, Info, *This, )
+: Evaluate(Result, Info, );
   }
 
   bool VisitCastExpr(const CastExpr *E) {
@@ -9710,15 +9718,17 @@ public:
 default:
   return ExprEvaluatorBaseTy::VisitCastExpr(E);
 case CK_NonAtomicToAtomic:
-  return Evaluate(Result, Info, E->getSubExpr());
+  return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr())
+  : Evaluate(Result, Info, E->getSubExpr());
 }
   }
 };
 } // end anonymous namespace
 
-static bool EvaluateAtomic(const Expr *E, APValue , EvalInfo ) {
+static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue ,
+   EvalInfo ) {
   assert(E->isRValue() && E->getType()->isAtomicType());
-  return AtomicExprEvaluator(Info, Result).Visit(E);
+  return AtomicExprEvaluator(Info, This, Result).Visit(E);
 }
 
 
//===--===//
@@ -9823,8 +9833,17 @@ static bool Evaluate(APValue , Ev
 if (!EvaluateVoid(E, Info))
   return false;
   } else if (T->isAtomicType()) {
-if (!EvaluateAtomic(E, Result, Info))
-  return false;
+QualType Unqual = T.getAtomicUnqualifiedType();
+if (Unqual->isArrayType() || Unqual->isRecordType()) {
+  LValue LV;
+  LV.set(E, Info.CurrentCall->Index);
+  APValue  = Info.CurrentCall->createTemporary(E, false);
+  if (!EvaluateAtomic(E, , Value, Info))
+return false;
+} else {
+  if (!EvaluateAtomic(E, nullptr, Result, Info))
+return false;
+}
   } else if (Info.getLangOpts().CPlusPlus11) {
 Info.FFDiag(E, diag::note_constexpr_nonliteral) << E->getType();
 return false;
@@ -9849,10 +9868,16 @@ static bool EvaluateInPlace(APValue 
   if (E->isRValue()) {
 // Evaluate arrays and record types in-place, so that later initializers 
can
 // refer to earlier-initialized members of the object.
-if (E->getType()->isArrayType())
+QualType T = E->getType();
+if (T->isArrayType())
   return EvaluateArray(E, This, Result, Info);
-else if (E->getType()->isRecordType())
+else if (T->isRecordType())
   return EvaluateRecord(E, This, Result, Info);
+else if (T->isAtomicType()) {
+  QualType Unqual = T.getAtomicUnqualifiedType();
+  if 

Re: r295473 - [OpenMP] Remove barriers at cancel and cancellation point

2017-02-22 Thread Hans Wennborg via cfe-commits
Alexey: ping?

On Tue, Feb 21, 2017 at 11:07 AM, Hans Wennborg  wrote:
> I'm Ok with it if Alexey approves.
>
> On Fri, Feb 17, 2017 at 10:52 AM, Hahnfeld, Jonas
>  wrote:
>> Hi Hans, Alexey,
>>
>> can we merge this commit and r295474 for the 4.0 release or is it already
>> too late for that? I will totally understand that and can apply these
>> commits locally prior to installing.
>> However, I think that these changes are quite focussed and bear minimal
>> possibility of introducing regressions.
>>
>> Thanks,
>> Jonas
>>
>> Am Freitag, den 17.02.2017, 18:32 + schrieb Jonas Hahnfeld via
>> cfe-commits:
>>
>> Author: hahnfeld
>> Date: Fri Feb 17 12:32:51 2017
>> New Revision: 295473
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=295473=rev
>> Log:
>> [OpenMP] Remove barriers at cancel and cancellation point
>>
>> This resolves a deadlock with the cancel directive when there is no explicit
>> cancellation point. In that case, the implicit barrier acts as cancellation
>> point. After removing the barrier after cancel, the now unmatched barrier
>> for
>> the explicit cancellation point has to go as well.
>>
>> This has probably worked before rL255992: With the calls for the explicit
>> barrier, it was sure that all threads passed a barrier before exiting.
>>
>> Reported by Simon Convent and Joachim Protze!
>>
>> Differential Revision: https://reviews.llvm.org/D30088
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> cfe/trunk/test/OpenMP/cancel_codegen.cpp
>> cfe/trunk/test/OpenMP/cancellation_point_codegen.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r295874 - AMDGPU: Add fmed3 half builtin

2017-02-22 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Wed Feb 22 14:55:59 2017
New Revision: 295874

URL: http://llvm.org/viewvc/llvm-project?rev=295874=rev
Log:
AMDGPU: Add fmed3 half builtin

Added:
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx9.cl
cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-gfx9.cl
Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-f16.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=295874=295873=295874=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Wed Feb 22 14:55:59 2017
@@ -100,6 +100,12 @@ TARGET_BUILTIN(__builtin_amdgcn_classh,
 TARGET_BUILTIN(__builtin_amdgcn_s_memrealtime, "LUi", "n", "s-memrealtime")
 
 
//===--===//
+// GFX9+ only builtins.
+//===--===//
+
+TARGET_BUILTIN(__builtin_amdgcn_fmed3h, "", "nc", "gfx9-insts")
+
+//===--===//
 // Special builtins.
 
//===--===//
 BUILTIN(__builtin_amdgcn_read_exec, "LUi", "nc")

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=295874=295873=295874=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Feb 22 14:55:59 2017
@@ -2355,6 +2355,9 @@ bool AMDGPUTargetInfo::initFeatureMap(
 case GK_GFX7:
   break;
 
+case GK_GFX9:
+  Features["gfx9-insts"] = true;
+  LLVM_FALLTHROUGH;
 case GK_GFX8:
   Features["s-memrealtime"] = true;
   Features["16-bit-insts"] = true;

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=295874=295873=295874=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Feb 22 14:55:59 2017
@@ -8445,6 +8445,7 @@ Value *CodeGenFunction::EmitAMDGPUBuilti
   case AMDGPU::BI__builtin_amdgcn_classh:
 return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class);
   case AMDGPU::BI__builtin_amdgcn_fmed3f:
+  case AMDGPU::BI__builtin_amdgcn_fmed3h:
 return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_fmed3);
   case AMDGPU::BI__builtin_amdgcn_read_exec: {
 CallInst *CI = cast(

Added: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx9.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx9.cl?rev=295874=auto
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx9.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx9.cl Wed Feb 22 14:55:59 
2017
@@ -0,0 +1,11 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx900 -S 
-emit-llvm -o - %s | FileCheck %s
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// CHECK-LABEL: @test_fmed3_f16
+// CHECK: call half @llvm.amdgcn.fmed3.f16(half %a, half %b, half %c)
+void test_fmed3_f16(global half* out, half a, half b, half c)
+{
+  *out = __builtin_amdgcn_fmed3h(a, b, c);
+}

Modified: cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-f16.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-f16.cl?rev=295874=295873=295874=diff
==
--- cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-f16.cl (original)
+++ cfe/trunk/test/SemaOpenCL/builtins-amdgcn-error-f16.cl Wed Feb 22 14:55:59 
2017
@@ -1,9 +1,10 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -triple amdgcn-- -target-cpu tahiti -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -verify -S -o - %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
-void test_f16(global half *out, half a, half b, half c)
+__attribute__((target("arch=tahiti")))
+void test_f16_tahiti(global half *out, half a, half b, half c)
 {
   *out = __builtin_amdgcn_div_fixuph(a, b, c); // expected-error 
{{'__builtin_amdgcn_div_fixuph' needs target feature 16-bit-insts}}
   *out = __builtin_amdgcn_rcph(a); // expected-error {{'__builtin_amdgcn_rcph' 
needs target feature 16-bit-insts}}
@@ -15,4 +16,5 @@ void test_f16(global half *out, half a,
   *out = __builtin_amdgcn_frexp_exph(a); // expected-error 
{{'__builtin_amdgcn_frexp_exph' needs target feature 16-bit-insts}}
   *out = 

[PATCH] D30241: AMDGPU: Add fmed3 half builtin

2017-02-22 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r295874


https://reviews.llvm.org/D30241



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


[PATCH] D30035: Add const to function parameters

2017-02-22 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

Thank you for the feedback. This was supposed to be first out of two patches. I 
have posted the next patch here: https://reviews.llvm.org/D30268 which aims to 
remove copy of __src array each time a number is parsed. I can abandon this 
patch if we don't need to separate this from the other.


https://reviews.llvm.org/D30035



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


[PATCH] D30268: Avoid copy of __atoms when char_type is char

2017-02-22 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya created this revision.

The function __num_get<_CharT>::__stage2_int_prep makes unnecessary copy of 
__src into __atoms when char_type is char. This can be avoided by creating
a switch on type and just returning __src when char_type is char. Running a 
synthetic benchmark shows the impact of this change:

The test case can be found here: 
https://github.com/hiraditya/std-benchmark/blob/master/cxx/stringstream.bench.cpp

Without the change with llvm-project/trunk
$ export LD_LIBRARY_PATH=/work/llvm-project/install/lib; 
./cxx/stringstream.bench.cpp.out
Run on (24 X 1200 MHz CPU s)
2017-02-22 14:37:34

BenchmarkTime   CPU Iterations
--

BM_Istream_numbers/32 8328 ns   8336 ns  83121
BM_Istream_numbers/64 8312 ns   8320 ns  83754
BM_Istream_numbers/1288301 ns   8309 ns  83975
BM_Istream_numbers/2568298 ns   8306 ns  84349
BM_Istream_numbers/5128303 ns   8311 ns  84308
BM_Istream_numbers/1024   8301 ns   8309 ns  84316

With the change on llvm-project/trunk
$ export LD_LIBRARY_PATH=/work/llvm-project/install-sstream/lib; 
./cxx/stringstream.bench.cpp.out
Run on (24 X 1200 MHz CPU s)
2017-02-22 14:37:55

BenchmarkTime   CPU Iterations
--

BM_Istream_numbers/32 7465 ns   7472 ns  91957
BM_Istream_numbers/64 7460 ns   7467 ns  93824
BM_Istream_numbers/1287457 ns   7464 ns  93875
BM_Istream_numbers/2567456 ns   7463 ns  93781
BM_Istream_numbers/5127455 ns   7462 ns  93793
BM_Istream_numbers/1024   7457 ns   7464 ns  93757


https://reviews.llvm.org/D30268

Files:
  libcxx/include/locale


Index: libcxx/include/locale
===
--- libcxx/include/locale
+++ libcxx/include/locale
@@ -380,25 +380,45 @@
 struct __num_get
 : protected __num_get_base
 {
-static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& 
__thousands_sep);
+static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep);
 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, 
_CharT& __decimal_point,
   _CharT& __thousands_sep);
+const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
+{
+  return __do_widen_p(__iob, __atoms);
+}
+
+
 static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& 
__a_end,
   unsigned& __dc, _CharT __thousands_sep, const string& 
__grouping,
-  unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
+  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
 static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
char* __a, char*& __a_end,
_CharT __decimal_point, _CharT 
__thousands_sep,
const string& __grouping, unsigned* __g,
unsigned*& __g_end, unsigned& __dc, _CharT* 
__atoms);
+private:
+template
+const T* __do_widen_p(ios_base& __iob, T* __atoms) const
+{
+  locale __loc = __iob.getloc();
+  use_facet(__loc).widen(__src, __src + 26, __atoms);
+  return __atoms;
+}
+
+const char* __do_widen_p(ios_base& __iob, char* __atoms) const
+{
+  (void)__iob;
+  (void)__atoms;
+  return __src;
+}
 };
 
 template 
 string
-__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& 
__thousands_sep)
+__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
 {
 locale __loc = __iob.getloc();
-use_facet >(__loc).widen(__src, __src + 26, __atoms);
 const numpunct<_CharT>& __np = use_facet >(__loc);
 __thousands_sep = __np.thousands_sep();
 return __np.grouping();
@@ -421,7 +441,7 @@
 int
 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, 
char*& __a_end,
   unsigned& __dc, _CharT __thousands_sep, const string& 
__grouping,
-  unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
+  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
 {
 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
 {
@@ -854,9 +874,10 @@
 // Stage 1
 int __base = this->__get_base(__iob);
 // Stage 2
-char_type __atoms[26];
+char_type __atoms1[26];
 char_type __thousands_sep;
-string __grouping = this->__stage2_int_prep(__iob, __atoms, 
__thousands_sep);
+const char_type *__atoms = this->__do_widen(__iob, __atoms1);
+string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
 string 

r295872 - stop using associative comdats for SEH filter functions

2017-02-22 Thread Bob Haarman via cfe-commits
Author: inglorion
Date: Wed Feb 22 14:29:39 2017
New Revision: 295872

URL: http://llvm.org/viewvc/llvm-project?rev=295872=rev
Log:
stop using associative comdats for SEH filter functions

Summary: We implement structured exception handling (SEH) by generating filter 
functions for functions that use exceptions. Currently, we use associative 
comdats to ensure that the filter functions are preserved if and only if the 
functions we generated them for are preserved. This can lead to problems when 
generating COFF objects - LLVM may decide to inline a function that uses SEH 
and remove its body, at which point we will end up with a comdat that COFF 
cannot represent. To avoid running into that situation, this change makes us 
not use associative comdats for SEH filter functions. We can still get the 
benefits we used the associative comdats for: we will always preserve filter 
functions we use, and dead stripping can eliminate the ones we don't use.

Reviewers: rnk, pcc, ruiu

Reviewed By: rnk

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

Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=295872=295871=295872=diff
==
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Feb 22 14:29:39 2017
@@ -1666,23 +1666,12 @@ void CodeGenFunction::startOutlinedSEHHe
 
   QualType RetTy = IsFilter ? getContext().LongTy : getContext().VoidTy;
 
-  llvm::Function *ParentFn = ParentCGF.CurFn;
   const CGFunctionInfo  =
 CGM.getTypes().arrangeBuiltinFunctionDeclaration(RetTy, Args);
 
   llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FnInfo);
   llvm::Function *Fn = llvm::Function::Create(
   FnTy, llvm::GlobalValue::InternalLinkage, Name.str(), ());
-  // The filter is either in the same comdat as the function, or it's internal.
-  if (llvm::Comdat *C = ParentFn->getComdat()) {
-Fn->setComdat(C);
-  } else if (ParentFn->hasWeakLinkage() || ParentFn->hasLinkOnceLinkage()) {
-llvm::Comdat *C = CGM.getModule().getOrInsertComdat(ParentFn->getName());
-ParentFn->setComdat(C);
-Fn->setComdat(C);
-  } else {
-Fn->setLinkage(llvm::GlobalValue::InternalLinkage);
-  }
 
   IsOutlinedSEHHelper = true;
 

Modified: cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp?rev=295872=295871=295872=diff
==
--- cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/exceptions-seh.cpp Wed Feb 22 14:29:39 2017
@@ -118,7 +118,7 @@ void use_inline() {
   use_seh_in_inline_func();
 }
 
-// CHECK-LABEL: define linkonce_odr void @use_seh_in_inline_func() #{{[0-9]+}} 
comdat
+// CHECK-LABEL: define linkonce_odr void @use_seh_in_inline_func() #{{[0-9]+}}
 // CHECK-SAME:  personality i8* bitcast (i32 (...)* @__C_specific_handler to 
i8*)
 // CHECK: invoke void @might_throw()
 //
@@ -134,12 +134,12 @@ void use_inline() {
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress()
 // CHECK: call void @"\01?fin$0@0@use_seh_in_inline_func@@"(i8 1, i8* %[[fp]])
 
-// CHECK-LABEL: define internal i32 
@"\01?filt$0@0@use_seh_in_inline_func@@"(i8* %exception_pointers, i8* 
%frame_pointer) #{{[0-9]+}} comdat($use_seh_in_inline_func)
+// CHECK-LABEL: define internal i32 
@"\01?filt$0@0@use_seh_in_inline_func@@"(i8* %exception_pointers, i8* 
%frame_pointer) #{{[0-9]+}}
 // CHECK: icmp eq i32 %{{.*}}, 424242
 // CHECK: zext i1 %{{.*}} to i32
 // CHECK: ret i32
 
-// CHECK-LABEL: define internal void 
@"\01?fin$0@0@use_seh_in_inline_func@@"(i8 %abnormal_termination, i8* 
%frame_pointer) #{{[0-9]+}} comdat($use_seh_in_inline_func)
+// CHECK-LABEL: define internal void 
@"\01?fin$0@0@use_seh_in_inline_func@@"(i8 %abnormal_termination, i8* 
%frame_pointer) #{{[0-9]+}}
 // CHECK: store i32 1234, i32* @my_unique_global
 
 // CHECK: attributes #[[NOINLINE]] = { {{.*noinline.*}} }


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


r295870 - [CodeGen] Note where we add ABI-specific args in ctors. NFC.

2017-02-22 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Wed Feb 22 14:28:02 2017
New Revision: 295870

URL: http://llvm.org/viewvc/llvm-project?rev=295870=rev
Log:
[CodeGen] Note where we add ABI-specific args in ctors. NFC.

Meta: The ultimate goal is to teach ExtParameterInfo about
pass_object_size attributes. This is necessary for that, since our
ExtParameterInfo is a bit buggy in C++. I plan to actually make use of
this Prefix/Suffix info in the near future, but I like small
single-purpose changes. Especially when those changes are hard to
actually test...

At the moment, some of our C++-specific CodeGen pretends that ABIs can
only add arguments to the beginning of a function call. This isn't quite
correct: args can be appended to the end, as well. It hasn't mattered
much until now, since we seem to only use this "number of arguments
added" data when calculating the ExtParameterInfo to use when making a
CGFunctionInfo. Said ExtParameterInfo is currently only used for
ParameterABIs (Swift) and ns_consumed (ObjC).

So, this patch allows ABIs to indicate whether args they added were at
the beginning or end of an argument list. We can use this information to
emit ExtParameterInfos more correctly, though like said, that bit is
coming soon.

No tests since this is theoretically a nop.

Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=295870=295869=295870=diff
==
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Wed Feb 22 14:28:02 2017
@@ -291,11 +291,26 @@ public:
   /// Emit constructor variants required by this ABI.
   virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
 
+  /// Notes how many arguments were added to the beginning (Prefix) and ending
+  /// (Suffix) of an arg list.
+  ///
+  /// Note that Prefix actually refers to the number of args *after* the first
+  /// one: `this` arguments always come first.
+  struct AddedStructorArgs {
+unsigned Prefix = 0;
+unsigned Suffix = 0;
+AddedStructorArgs() = default;
+AddedStructorArgs(unsigned P, unsigned S) : Prefix(P), Suffix(S) {}
+static AddedStructorArgs prefix(unsigned N) { return {N, 0}; }
+static AddedStructorArgs suffix(unsigned N) { return {0, N}; }
+  };
+
   /// Build the signature of the given constructor or destructor variant by
   /// adding any required parameters.  For convenience, ArgTys has been
   /// initialized with the type of 'this'.
-  virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
-  SmallVectorImpl ) = 
0;
+  virtual AddedStructorArgs
+  buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
+ SmallVectorImpl ) = 0;
 
   /// Returns true if the given destructor type should be emitted as a linkonce
   /// delegating thunk, regardless of whether the dtor is defined in this TU or
@@ -355,9 +370,9 @@ public:
 
   /// Add any ABI-specific implicit arguments needed to call a constructor.
   ///
-  /// \return The number of args added to the call, which is typically zero or
-  /// one.
-  virtual unsigned
+  /// \return The number of arguments added at the beginning and end of the
+  /// call, which is typically zero or one.
+  virtual AddedStructorArgs
   addImplicitConstructorArgs(CodeGenFunction , const CXXConstructorDecl *D,
  CXXCtorType Type, bool ForVirtualBase,
  bool Delegating, CallArgList ) = 0;

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=295870=295869=295870=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Feb 22 14:28:02 2017
@@ -2032,14 +2032,15 @@ void CodeGenFunction::EmitCXXConstructor
   }
 
   // Insert any ABI-specific implicit constructor arguments.
-  unsigned ExtraArgs = CGM.getCXXABI().addImplicitConstructorArgs(
-  *this, D, Type, ForVirtualBase, Delegating, Args);
+  CGCXXABI::AddedStructorArgs ExtraArgs =
+  CGM.getCXXABI().addImplicitConstructorArgs(*this, D, Type, 
ForVirtualBase,
+ Delegating, Args);
 
   // Emit the call.
   llvm::Constant *CalleePtr =
 CGM.getAddrOfCXXStructor(D, getFromCtorType(Type));
-  const CGFunctionInfo  =
-CGM.getTypes().arrangeCXXConstructorCall(Args, D, Type, ExtraArgs);
+  const CGFunctionInfo  = CGM.getTypes().arrangeCXXConstructorCall(
+  Args, D, Type, ExtraArgs.Prefix + ExtraArgs.Suffix);
   CGCallee Callee = CGCallee::forDirect(CalleePtr, D);
   EmitCall(Info, Callee, ReturnValueSlot(), 

[PATCH] D27827: [ObjC] CodeGen support for @available on macOS

2017-02-22 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: test/CodeGenObjC/availability-check.m:16
+  // CHECK: br i1 true
+  if (__builtin_available(ios 10, *))
+;

arphaman wrote:
> Shouldn't this be `br i1 false`, since we are building for macOS so we have 
> no iOS support at all?
No, this is intentional. If the platform we're targeting isn't mentioned, we 
take the `*` case, and emit -Wunguarded-availability diagnostics in the body of 
the `if` using the minimum deployment target. The idea is that if a new OS is 
released it will be forked from an existing one and use existing APIs, and it 
would be unfortunate for everyone to have to add the new platform to their 
existing `@available` calls. This is probably the most counterintuative part of 
this feature, and is the reason for the somewhat bizarre `*` syntax, to call 
out this control flow.


https://reviews.llvm.org/D27827



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


r295866 - Improve support for 'decltype(auto)' in template template parameter matching.

2017-02-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb 22 14:01:55 2017
New Revision: 295866

URL: http://llvm.org/viewvc/llvm-project?rev=295866=rev
Log:
Improve support for 'decltype(auto)' in template template parameter matching.

A 'decltype(auto)' parameter can match any other kind of non-type template
parameter, so should be usable in place of any other parameter in a template
template argument. The standard is sadly extremely unclear on how this is
supposed to work, but this seems like the obviously-correct result.

It's less clear whether an 'auto' parameter should be able to match
'decltype(auto)', since the former cannot be used if the latter turns out to be
used for a reference type, but if we disallow that then consistency suggests we
should also disallow 'auto' matching 'T' for the same reason, defeating
intended use cases of the feature.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaTemplate/temp_arg_template_cxx1z.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=295866=295865=295866=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Feb 22 14:01:55 2017
@@ -5666,6 +5666,19 @@ ExprResult Sema::CheckTemplateArgument(N
 
   // If the parameter type somehow involves auto, deduce the type now.
   if (getLangOpts().CPlusPlus1z && ParamType->isUndeducedType()) {
+// During template argument deduction, we allow 'decltype(auto)' to
+// match an arbitrary dependent argument.
+// FIXME: The language rules don't say what happens in this case.
+// FIXME: We get an opaque dependent type out of decltype(auto) if the
+// expression is merely instantiation-dependent; is this enough?
+if (CTAK == CTAK_Deduced && Arg->isTypeDependent()) {
+  auto *AT = dyn_cast(ParamType);
+  if (AT && AT->isDecltypeAuto()) {
+Converted = TemplateArgument(Arg);
+return Arg;
+  }
+}
+
 // When checking a deduced template argument, deduce from its type even if
 // the type is dependent, in order to check the types of non-type template
 // arguments line up properly in partial ordering.

Modified: cfe/trunk/test/SemaTemplate/temp_arg_template_cxx1z.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_template_cxx1z.cpp?rev=295866=295865=295866=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_template_cxx1z.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_template_cxx1z.cpp Wed Feb 22 14:01:55 
2017
@@ -103,12 +103,13 @@ namespace Auto {
   TDecltypeAuto dai; // expected-error {{different template parameters}}
   TDecltypeAuto daip; // expected-error {{different template 
parameters}}
 
-  // FIXME: It's completely unclear what should happen here. A case can be made
-  // that 'auto' is more specialized, because it's always a prvalue, whereas
-  // 'decltype(auto)' could have any value category. Under that interpretation,
-  // we get the following results entirely backwards:
-  TAuto ada; // expected-error {{different template parameters}}
-  TAutoPtr apda; // expected-error {{different template 
parameters}}
+  // FIXME: It's completely unclear what should happen here, but these results
+  // seem at least plausible:
+  TAuto ada;
+  TAutoPtr apda;
+  // Perhaps this case should be invalid, as there are valid 'decltype(auto)'
+  // parameters (such as 'user-defined-type &') that are not valid 'auto'
+  // parameters.
   TDecltypeAuto daa;
   TDecltypeAuto daa; // expected-error {{different template 
parameters}}
 


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


[PATCH] D30238: [Driver] Enable SafeStack for Fuchsia targets

2017-02-22 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D30238



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


[PATCH] D30238: [Driver] Enable SafeStack for Fuchsia targets

2017-02-22 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 89393.
mcgrathr added a comment.

Added test case.


Repository:
  rL LLVM

https://reviews.llvm.org/D30238

Files:
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  test/Driver/fuchsia.c


Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -38,3 +38,8 @@
 // CHECK-RELOCATABLE-NOT: "-pie"
 // CHECK-RELOCATABLE-NOT: "--build-id"
 // CHECK-RELOCATABLE: "-r"
+
+// RUN: %clang %s -### --target=x86_64-unknown-fuchsia \
+// RUN: -fsanitize=safe-stack 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK
+// CHECK-SAFESTACK: "-fsanitize=safe-stack"
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -1095,6 +1095,8 @@
 return llvm::DebuggerKind::GDB;
   }
 
+  SanitizerMask getSupportedSanitizers() const override;
+
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList ) const override;
   CXXStdlibType
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4860,6 +4860,12 @@
   CmdArgs.push_back("-lunwind");
 }
 
+SanitizerMask Fuchsia::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  Res |= SanitizerKind::SafeStack;
+  return Res;
+}
+
 /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
 
 DragonFly::DragonFly(const Driver , const llvm::Triple ,


Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -38,3 +38,8 @@
 // CHECK-RELOCATABLE-NOT: "-pie"
 // CHECK-RELOCATABLE-NOT: "--build-id"
 // CHECK-RELOCATABLE: "-r"
+
+// RUN: %clang %s -### --target=x86_64-unknown-fuchsia \
+// RUN: -fsanitize=safe-stack 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK
+// CHECK-SAFESTACK: "-fsanitize=safe-stack"
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -1095,6 +1095,8 @@
 return llvm::DebuggerKind::GDB;
   }
 
+  SanitizerMask getSupportedSanitizers() const override;
+
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList ) const override;
   CXXStdlibType
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4860,6 +4860,12 @@
   CmdArgs.push_back("-lunwind");
 }
 
+SanitizerMask Fuchsia::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  Res |= SanitizerKind::SafeStack;
+  return Res;
+}
+
 /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
 
 DragonFly::DragonFly(const Driver , const llvm::Triple ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30239: enable -flto=thin, -flto-jobs=, and -fthinlto-index= in clang-cl

2017-02-22 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D30239#683697, @inglorion wrote:

> @mehdi_amini:
>
> > Is clang-cl using lld as default? How is the switch done? Ideally we should 
> > have a nice error message from the driver if -flto is used without lld.
>
> I believe we use link.exe by default. You can use lld by passing -fuse-ld=lld 
> to the compiler.
>
> I can add an error message when -flto is used without -fuse-ld=lld at least 
> for the case when linking is actually performed. Of course, it's possible to 
> invoke clang-cl without it doing any linking. If you're only compiling, it's 
> perfectly valid to use -flto without -fuse-ld=lld.


That sounds like a good idea.




Comment at: test/Driver/cl-lto.c:2
+// -flto causes a switch to llvm-bc object files.
+// RUN: %clang_cl -ccc-print-phases -c -flto -- %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-COMPILE-ACTIONS < %t %s

This test and the other file look like they're doing the same as 
test/Driver/(thin)lto.c.

I don't think we need to test these separately for clang-cl; it should be 
enough with a simple test in test/Driver/cl-options.c to check that they're 
exposed and that -### looks right for them.


https://reviews.llvm.org/D30239



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


Re: [PATCH] D13330: Implement __attribute__((unique_instantiation))

2017-02-22 Thread David Blaikie via cfe-commits
On Tue, Feb 14, 2017 at 4:21 PM Mehdi AMINI via Phabricator via cfe-commits
 wrote:

> mehdi_amini added a comment.
>
> In https://reviews.llvm.org/D13330#582607, @rsmith wrote:
>
> > I think this attribute is poorly named. Explicit instantiation
> definitions are *already* required to be globally unique; see
> [temp.spec]/5.1:
> >
> > "For a given template and a given set of template-arguments, an explicit
> instantiation definition shall appear at most once in a program"
>
>
> So what prevents from emitting these as "strong" symbols without any
> attribute? We should have the guarantee that we have only one such copy in
> the program.
>

If I recall correctly - the requirement is that if there's an explicit
instantiation declaration there must be an explicit instantiation
definition, but it's not required that all sites required an instantiation
should see/have an explicit instantiation declaration. So you might have
some implicit instantiations scattered around, then one explicit
instantiation. If the explicit instantiation were strong, you'd get
duplicate symbol problems in your link.

(that's my naive/vague understanding anyway)


>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D13330
>
>
>
> ___
> 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


[PATCH] D30248: [libclang] Fix crash in member access code completion with implicit base

2017-02-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

It seems that unresolved member expressions have other lookup issues. For 
example, this will crash when code-completing as well:

  struct Foo {
void foo() const;
static void foo(bool);
  };
  
  struct Bar: Foo {
void foo(bool param) {
  this->Foo::foo(/*CC CRASH*/  );// unresolved member expression with an 
explicit base
}
  };

Are we sure that a call to `AddFunctionCandidates` is the right way to gather 
the method overloads in this particular instance?


https://reviews.llvm.org/D30248



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


Re: [PATCH] D30035: Add const to function parameters

2017-02-22 Thread David Blaikie via cfe-commits
Adding const to pointed/referenced types doesn't usually help the compiler,
since they don't guarantee that the underlying object is const (nor that
any use can't involve const_casting away the constness and mutating the
value anyway).

On Fri, Feb 17, 2017 at 2:34 PM Aditya Kumar via Phabricator via
cfe-commits  wrote:

> hiraditya added a comment.
>
> Adding const could help compiler, I do not have any specific performance
> numbers yet. So if this is too much trouble then we don't have to merge
> this.
>
>
> https://reviews.llvm.org/D30035
>
>
>
> ___
> 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


[PATCH] D30239: enable -flto=thin, -flto-jobs=, and -fthinlto-index= in clang-cl

2017-02-22 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

@mehdi_amini:

> Is clang-cl using lld as default? How is the switch done? Ideally we should 
> have a nice error message from the driver if -flto is used without lld.

I believe we use link.exe by default. You can use lld by passing -fuse-ld=lld 
to the compiler.

I can add an error message when -flto is used without -fuse-ld=lld at least for 
the case when linking is actually performed. Of course, it's possible to invoke 
clang-cl without it doing any linking. If you're only compiling, it's perfectly 
valid to use -flto without -fuse-ld=lld.


https://reviews.llvm.org/D30239



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


[PATCH] D27827: [ObjC] CodeGen support for @available on macOS

2017-02-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: test/CodeGenObjC/availability-check.m:16
+  // CHECK: br i1 true
+  if (__builtin_available(ios 10, *))
+;

Shouldn't this be `br i1 false`, since we are building for macOS so we have no 
iOS support at all?


https://reviews.llvm.org/D27827



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


Re: r295843 - [OpenCL] r600 needs OpenCL kernel calling convention

2017-02-22 Thread Hans Wennborg via cfe-commits
I'm OK with it if either Matt or Anastasia agrees.

Thanks,
Hans

On Wed, Feb 22, 2017 at 7:20 AM, Jan Vesely  wrote:
> Hi Hans,
>
> I'd like this commit to make it to 4.0. I'm not sure if it falls under
> OpenCL or AMDGPU so I've added both Matt and Anastasia to cc.
>
> thank you,
> Jan
>
> On Wed, 2017-02-22 at 15:01 +, Jan Vesely via cfe-commits wrote:
>> Author: jvesely
>> Date: Wed Feb 22 09:01:42 2017
>> New Revision: 295843
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=295843=rev
>> Log:
>> [OpenCL] r600 needs OpenCL kernel calling convention
>>
>> Differential Revision: https://reviews.llvm.org/D30236
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaType.cpp
>> cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
>>
>> Modified: cfe/trunk/lib/Sema/SemaType.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=295843=295842=295843=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 22 09:01:42 2017
>> @@ -3175,7 +3175,7 @@ getCCForDeclaratorChunk(Sema , Declara
>>if (Attr->getKind() == AttributeList::AT_OpenCLKernel) {
>>  llvm::Triple::ArchType arch = 
>> S.Context.getTargetInfo().getTriple().getArch();
>>  if (arch == llvm::Triple::spir || arch == llvm::Triple::spir64 ||
>> -arch == llvm::Triple::amdgcn) {
>> +arch == llvm::Triple::amdgcn || arch == llvm::Triple::r600) {
>>CC = CC_OpenCLKernel;
>>  }
>>  break;
>>
>> Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl?rev=295843=295842=295843=diff
>> ==
>> --- cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (original)
>> +++ cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl Wed Feb 22 
>> 09:01:42 2017
>> @@ -1,5 +1,6 @@
>>  // REQUIRES: amdgpu-registered-target
>>  // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
>> FileCheck %s
>> +// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | 
>> FileCheck %s
>>
>>  // CHECK-NOT: %struct.single_element_struct_arg = type { i32 }
>>  typedef struct single_element_struct_arg
>>
>>
>> ___
>> 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


[PATCH] D25604: Add support for Mageia Linux

2017-02-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev abandoned this revision.
v.g.vassilev added a comment.

Thanks for following this up. I will close it.


https://reviews.llvm.org/D25604



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


[PATCH] D30241: AMDGPU: Add fmed3 half builtin

2017-02-22 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl accepted this revision.
kzhuravl added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D30241



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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 89366.
sammccall added a comment.

git-clang-format


https://reviews.llvm.org/D30210

Files:
  include-fixer/InMemorySymbolIndex.cpp
  include-fixer/InMemorySymbolIndex.h
  include-fixer/IncludeFixer.cpp
  include-fixer/SymbolIndex.h
  include-fixer/SymbolIndexManager.cpp
  include-fixer/YamlSymbolIndex.cpp
  include-fixer/YamlSymbolIndex.h
  include-fixer/find-all-symbols/FindAllMacros.cpp
  include-fixer/find-all-symbols/FindAllMacros.h
  include-fixer/find-all-symbols/FindAllSymbols.cpp
  include-fixer/find-all-symbols/FindAllSymbols.h
  include-fixer/find-all-symbols/SymbolInfo.cpp
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/find-all-symbols/SymbolReporter.h
  include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
  include-fixer/tool/ClangIncludeFixer.cpp
  test/include-fixer/Inputs/fake_yaml_db.yaml
  test/include-fixer/Inputs/merge/a.yaml
  test/include-fixer/Inputs/merge/b.yaml
  test/include-fixer/merge.test
  unittests/include-fixer/IncludeFixerTest.cpp
  unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -19,6 +19,7 @@
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
@@ -35,30 +36,35 @@
 public:
   ~TestSymbolReporter() override {}
 
-  void reportSymbol(llvm::StringRef FileName,
-const SymbolInfo ) override {
-Symbols.push_back(Symbol);
+  void reportSymbols(llvm::StringRef FileName,
+ SymbolInfo::SignalMap NewSymbols) override {
+for (const auto  : NewSymbols)
+  Symbols[Entry.first] += Entry.second;
   }
 
   bool hasSymbol(const SymbolInfo ) const {
-for (const auto  : Symbols) {
-  if (S == Symbol)
-return true;
-}
-return false;
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Seen > 0;
+  }
+
+  bool hasUse(const SymbolInfo ) const {
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Used > 0;
   }
 
 private:
-  std::vector Symbols;
+  SymbolInfo::SignalMap Symbols;
 };
 
 class FindAllSymbolsTest : public ::testing::Test {
 public:
   bool hasSymbol(const SymbolInfo ) {
 return Reporter.hasSymbol(Symbol);
   }
 
-  bool runFindAllSymbols(StringRef Code) {
+  bool hasUse(const SymbolInfo ) { return Reporter.hasUse(Symbol); }
+
+  bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
 llvm::IntrusiveRefCntPtr InMemoryFileSystem(
 new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
@@ -98,7 +104,7 @@
 std::make_shared());
 
 InMemoryFileSystem->addFile(HeaderName, 0,
-llvm::MemoryBuffer::getMemBuffer(Code));
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
 
 std::string Content = "#include\"" + std::string(HeaderName) +
   "\"\n"
@@ -118,6 +124,7 @@
 SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
CleanHeader, 2, {});
 #endif // _MSC_VER && __MINGW32__
+Content += "\n" + MainCode.str();
 InMemoryFileSystem->addFile(FileName, 0,
 llvm::MemoryBuffer::getMemBuffer(Content));
 Invocation.run();
@@ -135,49 +142,64 @@
 };
 
 TEST_F(FindAllSymbolsTest, VariableSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern int xargc;
   namespace na {
   static bool  = false;
   namespace nb { const long long *; }
   })";
-  runFindAllSymbols(Code);
+  static const char Main[] = R"(
+  auto y = ::nb::;
+  int main() { if (na::) return xargc; }
+  )";
+  runFindAllSymbols(Header, Main);
 
   SymbolInfo Symbol =
   SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
   {{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 5,
   {{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 }
 
 TEST_F(FindAllSymbolsTest, ExternCSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern 

[PATCH] D25604: Add support for Mageia Linux

2017-02-22 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I just tested this on Mageia and this patch is superseded by now (it was 
originally written in 2013). The latest clang release is already able to 
correctly handle Mageia.

(Also there is anyway comma missing at the end of each line)


https://reviews.llvm.org/D25604



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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 89365.
sammccall added a comment.

Switch from SymbolInfo::WithSignals as a typedef for std::pair, to a struct
SymbolAndSignals, to have clearer semantics.


https://reviews.llvm.org/D30210

Files:
  include-fixer/InMemorySymbolIndex.cpp
  include-fixer/InMemorySymbolIndex.h
  include-fixer/IncludeFixer.cpp
  include-fixer/SymbolIndex.h
  include-fixer/SymbolIndexManager.cpp
  include-fixer/YamlSymbolIndex.cpp
  include-fixer/YamlSymbolIndex.h
  include-fixer/find-all-symbols/FindAllMacros.cpp
  include-fixer/find-all-symbols/FindAllMacros.h
  include-fixer/find-all-symbols/FindAllSymbols.cpp
  include-fixer/find-all-symbols/FindAllSymbols.h
  include-fixer/find-all-symbols/SymbolInfo.cpp
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/find-all-symbols/SymbolReporter.h
  include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
  include-fixer/tool/ClangIncludeFixer.cpp
  test/include-fixer/Inputs/fake_yaml_db.yaml
  test/include-fixer/Inputs/merge/a.yaml
  test/include-fixer/Inputs/merge/b.yaml
  test/include-fixer/merge.test
  unittests/include-fixer/IncludeFixerTest.cpp
  unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -19,6 +19,7 @@
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
@@ -35,30 +36,36 @@
 public:
   ~TestSymbolReporter() override {}
 
-  void reportSymbol(llvm::StringRef FileName,
-const SymbolInfo ) override {
-Symbols.push_back(Symbol);
+  void reportSymbols(llvm::StringRef FileName,
+ SymbolInfo::SignalMap NewSymbols) override {
+for (const auto  : NewSymbols) Symbols[Entry.first] += Entry.second;
   }
 
   bool hasSymbol(const SymbolInfo ) const {
-for (const auto  : Symbols) {
-  if (S == Symbol)
-return true;
-}
-return false;
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Seen > 0;
+  }
+
+  bool hasUse(const SymbolInfo ) const {
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Used > 0;
   }
 
 private:
-  std::vector Symbols;
+  SymbolInfo::SignalMap Symbols;
 };
 
 class FindAllSymbolsTest : public ::testing::Test {
 public:
   bool hasSymbol(const SymbolInfo ) {
 return Reporter.hasSymbol(Symbol);
   }
 
-  bool runFindAllSymbols(StringRef Code) {
+  bool hasUse(const SymbolInfo ) {
+return Reporter.hasUse(Symbol);
+  }
+
+  bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
 llvm::IntrusiveRefCntPtr InMemoryFileSystem(
 new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
@@ -98,7 +105,7 @@
 std::make_shared());
 
 InMemoryFileSystem->addFile(HeaderName, 0,
-llvm::MemoryBuffer::getMemBuffer(Code));
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
 
 std::string Content = "#include\"" + std::string(HeaderName) +
   "\"\n"
@@ -118,6 +125,7 @@
 SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
CleanHeader, 2, {});
 #endif // _MSC_VER && __MINGW32__
+Content += "\n" + MainCode.str();
 InMemoryFileSystem->addFile(FileName, 0,
 llvm::MemoryBuffer::getMemBuffer(Content));
 Invocation.run();
@@ -135,49 +143,64 @@
 };
 
 TEST_F(FindAllSymbolsTest, VariableSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern int xargc;
   namespace na {
   static bool  = false;
   namespace nb { const long long *; }
   })";
-  runFindAllSymbols(Code);
+  static const char Main[] = R"(
+  auto y = ::nb::;
+  int main() { if (na::) return xargc; }
+  )";
+  runFindAllSymbols(Header, Main);
 
   SymbolInfo Symbol =
   SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
   {{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 5,
   {{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 }
 
 

[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 89360.
sammccall added a comment.

Changes based on offline discussion:

- mutable SignalInfo data split into SignalInfo::Signals
- yaml serialized data is SignalInfo::WithSignals, which is currently a 
pair
- FindAllSymbols/FindAllMacros now report in batches, with symbols already 
deduplicated. This makes it easy to count each (file,symbol) only once.
- implemented macro usages because I had to touch that anyway


https://reviews.llvm.org/D30210

Files:
  include-fixer/InMemorySymbolIndex.cpp
  include-fixer/InMemorySymbolIndex.h
  include-fixer/IncludeFixer.cpp
  include-fixer/SymbolIndex.h
  include-fixer/SymbolIndexManager.cpp
  include-fixer/YamlSymbolIndex.cpp
  include-fixer/YamlSymbolIndex.h
  include-fixer/find-all-symbols/FindAllMacros.cpp
  include-fixer/find-all-symbols/FindAllMacros.h
  include-fixer/find-all-symbols/FindAllSymbols.cpp
  include-fixer/find-all-symbols/FindAllSymbols.h
  include-fixer/find-all-symbols/SymbolInfo.cpp
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/find-all-symbols/SymbolReporter.h
  include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
  include-fixer/tool/ClangIncludeFixer.cpp
  test/include-fixer/Inputs/fake_yaml_db.yaml
  test/include-fixer/Inputs/merge/a.yaml
  test/include-fixer/Inputs/merge/b.yaml
  test/include-fixer/merge.test
  unittests/include-fixer/IncludeFixerTest.cpp
  unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -19,6 +19,7 @@
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
@@ -35,30 +36,36 @@
 public:
   ~TestSymbolReporter() override {}
 
-  void reportSymbol(llvm::StringRef FileName,
-const SymbolInfo ) override {
-Symbols.push_back(Symbol);
+  void reportSymbols(llvm::StringRef FileName,
+ SymbolInfo::SignalMap NewSymbols) override {
+for (const auto  : NewSymbols) Symbols[Entry.first] += Entry.second;
   }
 
   bool hasSymbol(const SymbolInfo ) const {
-for (const auto  : Symbols) {
-  if (S == Symbol)
-return true;
-}
-return false;
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Seen > 0;
+  }
+
+  bool hasUse(const SymbolInfo ) const {
+auto it = Symbols.find(Symbol);
+return it != Symbols.end() && it->second.Used > 0;
   }
 
 private:
-  std::vector Symbols;
+  SymbolInfo::SignalMap Symbols;
 };
 
 class FindAllSymbolsTest : public ::testing::Test {
 public:
   bool hasSymbol(const SymbolInfo ) {
 return Reporter.hasSymbol(Symbol);
   }
 
-  bool runFindAllSymbols(StringRef Code) {
+  bool hasUse(const SymbolInfo ) {
+return Reporter.hasUse(Symbol);
+  }
+
+  bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
 llvm::IntrusiveRefCntPtr InMemoryFileSystem(
 new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
@@ -98,7 +105,7 @@
 std::make_shared());
 
 InMemoryFileSystem->addFile(HeaderName, 0,
-llvm::MemoryBuffer::getMemBuffer(Code));
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
 
 std::string Content = "#include\"" + std::string(HeaderName) +
   "\"\n"
@@ -118,6 +125,7 @@
 SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
CleanHeader, 2, {});
 #endif // _MSC_VER && __MINGW32__
+Content += "\n" + MainCode.str();
 InMemoryFileSystem->addFile(FileName, 0,
 llvm::MemoryBuffer::getMemBuffer(Content));
 Invocation.run();
@@ -135,49 +143,64 @@
 };
 
 TEST_F(FindAllSymbolsTest, VariableSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern int xargc;
   namespace na {
   static bool  = false;
   namespace nb { const long long *; }
   })";
-  runFindAllSymbols(Code);
+  static const char Main[] = R"(
+  auto y = ::nb::;
+  int main() { if (na::) return xargc; }
+  )";
+  runFindAllSymbols(Header, Main);
 
   SymbolInfo Symbol =
   SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
   {{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", 

Re: r295843 - [OpenCL] r600 needs OpenCL kernel calling convention

2017-02-22 Thread Jan Vesely via cfe-commits
Hi Hans,

I'd like this commit to make it to 4.0. I'm not sure if it falls under
OpenCL or AMDGPU so I've added both Matt and Anastasia to cc.

thank you,
Jan

On Wed, 2017-02-22 at 15:01 +, Jan Vesely via cfe-commits wrote:
> Author: jvesely
> Date: Wed Feb 22 09:01:42 2017
> New Revision: 295843
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=295843=rev
> Log:
> [OpenCL] r600 needs OpenCL kernel calling convention
> 
> Differential Revision: https://reviews.llvm.org/D30236
> 
> Modified:
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
> 
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=295843=295842=295843=diff
> ==
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 22 09:01:42 2017
> @@ -3175,7 +3175,7 @@ getCCForDeclaratorChunk(Sema , Declara
>if (Attr->getKind() == AttributeList::AT_OpenCLKernel) {
>  llvm::Triple::ArchType arch = 
> S.Context.getTargetInfo().getTriple().getArch();
>  if (arch == llvm::Triple::spir || arch == llvm::Triple::spir64 ||
> -arch == llvm::Triple::amdgcn) {
> +arch == llvm::Triple::amdgcn || arch == llvm::Triple::r600) {
>CC = CC_OpenCLKernel;
>  }
>  break;
> 
> Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl?rev=295843=295842=295843=diff
> ==
> --- cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (original)
> +++ cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl Wed Feb 22 
> 09:01:42 2017
> @@ -1,5 +1,6 @@
>  // REQUIRES: amdgpu-registered-target
>  // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
> FileCheck %s
> +// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | 
> FileCheck %s
>  
>  // CHECK-NOT: %struct.single_element_struct_arg = type { i32 }
>  typedef struct single_element_struct_arg
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


signature.asc
Description: This is a digitally signed message part
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r295843 - [OpenCL] r600 needs OpenCL kernel calling convention

2017-02-22 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Feb 22 09:01:42 2017
New Revision: 295843

URL: http://llvm.org/viewvc/llvm-project?rev=295843=rev
Log:
[OpenCL] r600 needs OpenCL kernel calling convention

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

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=295843=295842=295843=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 22 09:01:42 2017
@@ -3175,7 +3175,7 @@ getCCForDeclaratorChunk(Sema , Declara
   if (Attr->getKind() == AttributeList::AT_OpenCLKernel) {
 llvm::Triple::ArchType arch = 
S.Context.getTargetInfo().getTriple().getArch();
 if (arch == llvm::Triple::spir || arch == llvm::Triple::spir64 ||
-arch == llvm::Triple::amdgcn) {
+arch == llvm::Triple::amdgcn || arch == llvm::Triple::r600) {
   CC = CC_OpenCLKernel;
 }
 break;

Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl?rev=295843=295842=295843=diff
==
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl Wed Feb 22 
09:01:42 2017
@@ -1,5 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
 
 // CHECK-NOT: %struct.single_element_struct_arg = type { i32 }
 typedef struct single_element_struct_arg


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


r295839 - Remove superfluous initializer.

2017-02-22 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Wed Feb 22 08:32:39 2017
New Revision: 295839

URL: http://llvm.org/viewvc/llvm-project?rev=295839=rev
Log:
Remove superfluous initializer. 
The following fully-covered switch either sets value to External or exits the 
function.


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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=295839=295838=295839=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb 22 08:32:39 2017
@@ -8810,7 +8810,7 @@ static GVALinkage basicGVALinkageForFunc
   if (!FD->isExternallyVisible())
 return GVA_Internal;
 
-  GVALinkage External = GVA_StrongExternal;
+  GVALinkage External;
   switch (FD->getTemplateSpecializationKind()) {
   case TSK_Undeclared:
   case TSK_ExplicitSpecialization:


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


r295829 - Fix 'control reaches end of non-void function' warning

2017-02-22 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Feb 22 07:21:24 2017
New Revision: 295829

URL: http://llvm.org/viewvc/llvm-project?rev=295829=rev
Log:
Fix 'control reaches end of non-void function' warning

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=295829=295828=295829=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Feb 22 07:21:24 2017
@@ -8973,8 +8973,9 @@ void ASTReader::diagnoseOdrViolations()
   case AS_protected:
 return ProtectedSpecifer;
   case AS_none:
-llvm_unreachable("Invalid access specifier");
+break;
   }
+  llvm_unreachable("Invalid access specifier");
 }
   };
 


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


r295828 - Fix -Wunused-private-field warning by removing unused ODRHash reference field from ODRDeclVisitor

2017-02-22 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Feb 22 07:19:24 2017
New Revision: 295828

URL: http://llvm.org/viewvc/llvm-project?rev=295828=rev
Log:
Fix -Wunused-private-field warning by removing unused ODRHash reference field 
from ODRDeclVisitor

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

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=295828=295827=295828=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Wed Feb 22 07:19:24 2017
@@ -74,11 +74,10 @@ unsigned ODRHash::CalculateHash() {
 class ODRDeclVisitor : public ConstDeclVisitor {
   typedef ConstDeclVisitor Inherited;
   llvm::FoldingSetNodeID 
-  ODRHash 
 
 public:
-  ODRDeclVisitor(llvm::FoldingSetNodeID , ODRHash )
-  : ID(ID), Hash(Hash) {}
+  ODRDeclVisitor(llvm::FoldingSetNodeID )
+  : ID(ID) {}
 
   void Visit(const Decl *D) {
 ID.AddInteger(D->getKind());
@@ -109,7 +108,7 @@ void ODRHash::AddSubDecl(const Decl *D)
   assert(D && "Expecting non-null pointer.");
   AddDecl(D);
 
-  ODRDeclVisitor(ID, *this).Visit(D);
+  ODRDeclVisitor(ID).Visit(D);
 }
 
 void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {


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


[PATCH][scan-build]Add -target option when clang is invoked to check syntax

2017-02-22 Thread Kazuhiro Yabe via cfe-commits
Dear all,

This patch adds the '-target' option to the clang option to invoke to
check the syntax when scan-build is called with the --analyzer-target
option.


I'm using scan-build in cross compile project. (target: armv7-a)
Even when cross compiling, scan-build invokes clang with -triple (HOST
ARCH) to check syntax.
Therefore, if my code has some errors, clang reports error in syntax
checking:

error: unknown target CPU 'armv7-a'

This patch fixes that issue.

Thanks.


Index: tools/scan-build/libexec/ccc-analyzer
===
--- tools/scan-build/libexec/ccc-analyzer (revision 295806)
+++ tools/scan-build/libexec/ccc-analyzer (working copy)
@@ -224,6 +224,10 @@
   else {
 $Cmd = $Clang;

+if (defined $AnalyzerTarget) {
+  push @Args, "-target", $AnalyzerTarget;
+}
+
 # Create arguments for doing regular parsing.
 my $SyntaxArgs = GetCCArgs($HtmlDir, "-fsyntax-only", \@Args);
 @CmdArgsSansAnalyses = @$SyntaxArgs;
@@ -248,10 +252,6 @@
   push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
 }

-if (defined $AnalyzerTarget) {
-  push @Args, "-target", $AnalyzerTarget;
-}
-
 my $AnalysisArgs = GetCCArgs($HtmlDir, "--analyze", \@Args);
 @CmdArgs = @$AnalysisArgs;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30248: [libclang] Fix crash in member access code completion with implicit base

2017-02-22 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv created this revision.

If there is an unresolved member access AST node, and the base is
implicit, do not access/use it for generating candidate overloads for
code completion results (because the base is a nullptr).

Fixes PR31093.


https://reviews.llvm.org/D30248

Files:
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeCompletion/member-access.cpp

Index: test/CodeCompletion/member-access.cpp
===
--- test/CodeCompletion/member-access.cpp
+++ test/CodeCompletion/member-access.cpp
@@ -37,6 +37,17 @@
   }
 };
 
+struct Foo {
+  void foo() const;
+  static void foo(bool);
+};
+
+struct Bar {
+  void foo(bool param) {
+Foo::foo(  );// unresolved member expression with an implicit base
+  }
+};
+
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:29:6 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
   // CHECK-CC1: Base1 : Base1::
   // CHECK-CC1: member1 : [#int#][#Base1::#]member1
@@ -52,3 +63,6 @@
 
 // Make sure this doesn't crash
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:7 %s -verify
+
+// Make sure this also doesn't crash
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:47:14 %s
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -6307,30 +6307,43 @@
   for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) {
 NamedDecl *D = F.getDecl()->getUnderlyingDecl();
 if (FunctionDecl *FD = dyn_cast(D)) {
-  if (isa(FD) && !cast(FD)->isStatic())
+  if (isa(FD) && !cast(FD)->isStatic()) {
+QualType ObjectType;
+Expr::Classification ObjectClassification;
+if (Expr *E = Args[0]) {
+  ObjectType = E->getType();
+  ObjectClassification = E->Classify(Context);
+}
 AddMethodCandidate(cast(FD), F.getPair(),
-   cast(FD)->getParent(),
-   Args[0]->getType(), Args[0]->Classify(Context),
-   Args.slice(1), CandidateSet, SuppressUserConversions,
-   PartialOverloading);
-  else
+   cast(FD)->getParent(), ObjectType,
+   ObjectClassification, Args.slice(1), CandidateSet,
+   SuppressUserConversions, PartialOverloading);
+  } else {
 AddOverloadCandidate(FD, F.getPair(), Args, CandidateSet,
  SuppressUserConversions, PartialOverloading);
+  }
 } else {
   FunctionTemplateDecl *FunTmpl = cast(D);
   if (isa(FunTmpl->getTemplatedDecl()) &&
-  !cast(FunTmpl->getTemplatedDecl())->isStatic())
+  !cast(FunTmpl->getTemplatedDecl())->isStatic()) {
+QualType ObjectType;
+Expr::Classification ObjectClassification;
+if (Expr *E = Args[0]) {
+  ObjectType = E->getType();
+  ObjectClassification = E->Classify(Context);
+}
 AddMethodTemplateCandidate(
 FunTmpl, F.getPair(),
 cast(FunTmpl->getDeclContext()),
-ExplicitTemplateArgs, Args[0]->getType(),
-Args[0]->Classify(Context), Args.slice(1), CandidateSet,
-SuppressUserConversions, PartialOverloading);
-  else
+ExplicitTemplateArgs, ObjectType, ObjectClassification,
+Args.slice(1), CandidateSet, SuppressUserConversions,
+PartialOverloading);
+  } else {
 AddTemplateOverloadCandidate(FunTmpl, F.getPair(),
  ExplicitTemplateArgs, Args,
  CandidateSet, SuppressUserConversions,
  PartialOverloading);
+  }
 }
   }
 }
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4309,7 +4309,8 @@
   UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
   TemplateArgs = 
 }
-SmallVector ArgExprs(1, UME->getBase());
+SmallVector ArgExprs(
+1, UME->isImplicitAccess() ? nullptr : UME->getBase());
 ArgExprs.append(Args.begin(), Args.end());
 UnresolvedSet<8> Decls;
 Decls.append(UME->decls_begin(), UME->decls_end());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r295820 - [ODRHash] Avoid dereferencing end() of a SmallVector.

2017-02-22 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Feb 22 04:19:45 2017
New Revision: 295820

URL: http://llvm.org/viewvc/llvm-project?rev=295820=rev
Log:
[ODRHash] Avoid dereferencing end() of a SmallVector.

Found by MSAN.

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=295820=295819=295820=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Feb 22 04:19:45 2017
@@ -8987,7 +8987,8 @@ void ASTReader::diagnoseOdrViolations()
   // SecondDiffType will not be Other and FirstDecl and SecondDecl will be
   // filled in if not EndOfClass.
   while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) {
-if (FirstIt->second == SecondIt->second) {
+if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() &&
+FirstIt->second == SecondIt->second) {
   ++FirstIt;
   ++SecondIt;
   continue;


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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall planned changes to this revision.
sammccall added a comment.

OK, some changes to come here:

- klimek thinks using a set as a pseudo-map with `mutable` is evil, which is a 
fair point
- the current `SymbolReporter` interface doesn't provide enough information to 
deduplicate efficiently, so we'll move the dedup to `FindAllSymbols` instead.




Comment at: include-fixer/find-all-symbols/SymbolInfo.h:79-80
 
-  /// \brief The number of times this symbol was found during an indexing run.
-  unsigned getNumOccurrences() const { return NumOccurrences; }
+  // Ranking signals are mutable to allow updating when the SymbolInfo is a map
+  // key. They do not affect ordering or equality.
+  /// \brief The number of times this symbol was found during an indexing

klimek wrote:
> So we map from Symbol to NumOccurences in SymbolInfoMain, but duplicate the 
> info in the key? That seems somewhat weird.
We no longer do that mapping.


https://reviews.llvm.org/D30210



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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include-fixer/find-all-symbols/FindAllSymbols.cpp:251
+  } else {
+assert(false && "Must match a NamedDecl!");
+  }

You can use llvm_unreachable  instead. Or do you actually want to fall through 
in release mode?



Comment at: include-fixer/find-all-symbols/SymbolInfo.h:79-80
 
-  /// \brief The number of times this symbol was found during an indexing run.
-  unsigned getNumOccurrences() const { return NumOccurrences; }
+  // Ranking signals are mutable to allow updating when the SymbolInfo is a map
+  // key. They do not affect ordering or equality.
+  /// \brief The number of times this symbol was found during an indexing

So we map from Symbol to NumOccurences in SymbolInfoMain, but duplicate the 
info in the key? That seems somewhat weird.


https://reviews.llvm.org/D30210



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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks for the review, still learning the style :)




Comment at: include-fixer/find-all-symbols/FindAllSymbols.cpp:250
+  } else {
+assert(!"Must match a NamedDecl!");
+  }

hokein wrote:
> Is the preceding `!` intended?
This does the right thing (!"string" is always false) but generates a warning.
Changed to assert(false && ...)


https://reviews.llvm.org/D30210



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


[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 89337.
sammccall marked 7 inline comments as done.
sammccall added a comment.

Address review comments.


https://reviews.llvm.org/D30210

Files:
  include-fixer/IncludeFixer.cpp
  include-fixer/SymbolIndexManager.cpp
  include-fixer/find-all-symbols/FindAllSymbols.cpp
  include-fixer/find-all-symbols/SymbolInfo.cpp
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/find-all-symbols/SymbolReporter.h
  include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
  test/include-fixer/Inputs/fake_yaml_db.yaml
  test/include-fixer/Inputs/merge/a.yaml
  test/include-fixer/Inputs/merge/b.yaml
  test/include-fixer/merge.test
  unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp

Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -19,6 +19,7 @@
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
@@ -40,25 +41,34 @@
 Symbols.push_back(Symbol);
   }
 
+  void reportUse(llvm::StringRef FileName, const SymbolInfo ) override {
+Used.push_back(Symbol);
+  }
+
   bool hasSymbol(const SymbolInfo ) const {
-for (const auto  : Symbols) {
-  if (S == Symbol)
-return true;
-}
-return false;
+return llvm::is_contained(Symbols, Symbol);
+  }
+
+  bool hasUse(const SymbolInfo ) const {
+return llvm::is_contained(Used, Symbol);
   }
 
 private:
   std::vector Symbols;
+  std::vector Used;
 };
 
 class FindAllSymbolsTest : public ::testing::Test {
 public:
   bool hasSymbol(const SymbolInfo ) {
 return Reporter.hasSymbol(Symbol);
   }
 
-  bool runFindAllSymbols(StringRef Code) {
+  bool hasUse(const SymbolInfo ) {
+return Reporter.hasUse(Symbol);
+  }
+
+  bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
 llvm::IntrusiveRefCntPtr InMemoryFileSystem(
 new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
@@ -98,7 +108,7 @@
 std::make_shared());
 
 InMemoryFileSystem->addFile(HeaderName, 0,
-llvm::MemoryBuffer::getMemBuffer(Code));
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
 
 std::string Content = "#include\"" + std::string(HeaderName) +
   "\"\n"
@@ -118,6 +128,7 @@
 SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
CleanHeader, 2, {});
 #endif // _MSC_VER && __MINGW32__
+Content += "\n" + MainCode.str();
 InMemoryFileSystem->addFile(FileName, 0,
 llvm::MemoryBuffer::getMemBuffer(Content));
 Invocation.run();
@@ -135,49 +146,64 @@
 };
 
 TEST_F(FindAllSymbolsTest, VariableSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern int xargc;
   namespace na {
   static bool  = false;
   namespace nb { const long long *; }
   })";
-  runFindAllSymbols(Code);
+  static const char Main[] = R"(
+  auto y = ::nb::;
+  int main() { if (na::) return xargc; }
+  )";
+  runFindAllSymbols(Header, Main);
 
   SymbolInfo Symbol =
   SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
   {{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol = SymbolInfo("", SymbolInfo::SymbolKind::Variable, HeaderName, 5,
   {{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, "na"}});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 }
 
 TEST_F(FindAllSymbolsTest, ExternCSymbols) {
-  static const char Code[] = R"(
+  static const char Header[] = R"(
   extern "C" {
   int C_Func() { return 0; }
   struct C_struct {
 int Member;
   };
   })";
-  runFindAllSymbols(Code);
+  static const char Main[] = R"(
+  C_struct q() {
+int(*ptr)() = C_Func;
+return {0};
+  }
+  )";
+  runFindAllSymbols(Header, Main);
 
   SymbolInfo Symbol =
   SymbolInfo("C_Func", SymbolInfo::SymbolKind::Function, HeaderName, 3, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 
   Symbol =
   SymbolInfo("C_struct", SymbolInfo::SymbolKind::Class, HeaderName, 4, {});
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_TRUE(hasUse(Symbol));
 }
 
 TEST_F(FindAllSymbolsTest, CXXRecordSymbols) {
-  

[clang-tools-extra] r295818 - Completion related fixes for clang-include-fixer.el.

2017-02-22 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Feb 22 03:21:22 2017
New Revision: 295818

URL: http://llvm.org/viewvc/llvm-project?rev=295818=rev
Log:
Completion related fixes for clang-include-fixer.el.

1. Quitting inside a process sentinel is not allowed, but the sentinel invokes
completion, where the user is free to hit C-g. By wrapping the call in
with-local-quit, the process sentinel invocation can finish without triggering
an error
2. Invoke completing-read instead of ido-completing-read, since this may
interfere with user customizations to completing-read-function. The user should
use something like ido-ubiquitous if ido completion is wanted
3. Compare the string returned from completion with string=, since it may be a
copy of the original string in the collection

Patch by Torsten Marek.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=295818=295817=295818=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Wed Feb 
22 03:21:22 2017
@@ -251,25 +251,28 @@ clang-include-fixer to insert the select
 (message "Couldn't find header for '%s'"
  (let-alist (car .QuerySymbolInfos) .RawIdentifier)))
(t
-;; Replace the HeaderInfos list by a single header selected by
-;; the user.
-(clang-include-fixer--select-header context)
-;; Call clang-include-fixer again to insert the selected header.
-(clang-include-fixer--start
- (let ((old-tick (buffer-chars-modified-tick)))
-   (lambda (stdout)
- (when (/= old-tick (buffer-chars-modified-tick))
-   ;; Replacing the buffer now would undo the user’s changes.
-   (user-error (concat "The buffer has been changed "
-   "before the header could be inserted")))
- (clang-include-fixer--replace-buffer stdout)
- (let-alist context
-   (let-alist (car .HeaderInfos)
- (run-hook-with-args 'clang-include-fixer-add-include-hook
- (substring .Header 1 -1)
- (string= (substring .Header 0 1) "<"))
- (format "-insert-header=%s"
- (clang-include-fixer--encode-json context)))
+;; Users may C-g in prompts, make sure the process sentinel
+;; behaves correctly.
+(with-local-quit
+  ;; Replace the HeaderInfos list by a single header selected by
+  ;; the user.
+  (clang-include-fixer--select-header context)
+  ;; Call clang-include-fixer again to insert the selected header.
+  (clang-include-fixer--start
+   (let ((old-tick (buffer-chars-modified-tick)))
+ (lambda (stdout)
+   (when (/= old-tick (buffer-chars-modified-tick))
+ ;; Replacing the buffer now would undo the user’s changes.
+ (user-error (concat "The buffer has been changed "
+ "before the header could be inserted")))
+   (clang-include-fixer--replace-buffer stdout)
+   (let-alist context
+ (let-alist (car .HeaderInfos)
+   (run-hook-with-args 'clang-include-fixer-add-include-hook
+   (substring .Header 1 -1)
+   (string= (substring .Header 0 1) 
"<"))
+   (format "-insert-header=%s"
+   (clang-include-fixer--encode-json context
   nil)
 
 (defun clang-include-fixer--select-header (context)
@@ -305,13 +308,13 @@ They are replaced by the single element
 (goto-char (clang-include-fixer--closest-overlay overlays))
 (cl-flet ((header (info) (let-alist info .Header)))
   ;; The header-infos is already sorted by include-fixer.
-  (let* ((header (ido-completing-read
+  (let* ((header (completing-read
   (clang-include-fixer--format-message
"Select include for '%s': " symbol)
   (mapcar #'header .HeaderInfos)
   nil :require-match nil
   'clang-include-fixer--history))
- (info (cl-find header .HeaderInfos :key #'header)))
+ (info (cl-find header .HeaderInfos :key #'header :test 
#'string=)))
 (cl-assert info)
 (setcar .HeaderInfos info)
 (setcdr .HeaderInfos nil


___
cfe-commits mailing list

[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-02-22 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 89333.
xiangzhai added a comment.

Fixed the confused

  State->getSVal(CE->getArg(1), C.getLocationContext());

with

  CE->getArg(1)

issue.


Repository:
  rL LLVM

https://reviews.llvm.org/D28348

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/gmalloc.c

Index: test/Analysis/gmalloc.c
===
--- test/Analysis/gmalloc.c
+++ test/Analysis/gmalloc.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+typedef void* gpointer;
+typedef const void* gconstpointer;
+typedef unsigned long gsize;
+typedef unsigned int guint;
+
+gpointer g_malloc(gsize n_bytes);
+gpointer g_malloc0(gsize n_bytes);
+gpointer g_realloc(gpointer mem, gsize n_bytes);
+gpointer g_try_malloc(gsize n_bytes);
+gpointer g_try_malloc0(gsize n_bytes);
+gpointer g_try_realloc(gpointer mem, gsize n_bytes);
+gpointer g_malloc_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_malloc0_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_malloc_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_malloc0_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
+void g_free(gpointer mem);
+gpointer g_memdup(gconstpointer mem, guint byte_size);
+
+static const gsize n_bytes = 1024;
+
+void f1() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char));
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char));
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char));
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g2); // expected-warning{{Attempt to free released memory}}
+}
+
+void f2() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char));
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char));
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char));
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+  g3 = g_memdup(g3, n_bytes); // expected-warning{{Use of memory after it is freed}}
+}
+
+void f3() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2); // expected-warning{{Potential leak of memory pointed to by 'g4'}}
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g6'}}
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g5'}}
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g8'}}
+
+  g_free(g1); // expected-warning{{Potential leak of memory pointed to by 'g7'}}
+  g_free(g2);
+  g_free(g3);
+}
+
+void f4() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g6'}}
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g5'}}
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g8'}}
+
+  g_free(g1); // expected-warning{{Potential leak of memory pointed to by 'g7'}}
+  g_free(g2);
+  g_free(g3);
+  g_free(g4);
+}
+
+void f5() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = 

[PATCH] D30210: [include-fixer] Add usage count to find-all-symbols.

2017-02-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for the contributions!




Comment at: include-fixer/find-all-symbols/FindAllSymbols.cpp:244
 
-  const auto *ND = Result.Nodes.getNodeAs("decl");
-  assert(ND && "Matched declaration must be a NamedDecl!");
+  auto report = ::reportSymbol;
+  const NamedDecl *ND;

The way seems too tricky to me. I'd use a flag variable like `isUsedDecl` to 
distinguish and handle `use` and `decl` cases.



Comment at: include-fixer/find-all-symbols/FindAllSymbols.cpp:250
+  } else {
+assert(!"Must match a NamedDecl!");
+  }

Is the preceding `!` intended?



Comment at: include-fixer/find-all-symbols/SymbolInfo.h:83
+  /// run. Populated by the reducer and used to rank results.
+  mutable unsigned NumOccurrences;
+  /// \brief The number of times this symbol was used during an indexing run.

A blank between class members.



Comment at: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:551
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_FALSE(hasUse(Symbol));  // Not yet implemented.
 

The same.



Comment at: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:48
   bool hasSymbol(const SymbolInfo ) const {
-for (const auto  : Symbols) {
-  if (S == Symbol)
-return true;
-}
-return false;
+return std::find(Symbols.begin(), Symbols.end(), Symbol) != Symbols.end();
+  }

nit: You can use `llvm::is_contained` here.



Comment at: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:52
+  bool hasUse(const SymbolInfo ) const {
+return std::find(Used.begin(), Used.end(), Symbol) != Used.end();
   }

The same.



Comment at: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:65
   }
+  bool hasUse(const SymbolInfo ) {
+return Reporter.hasUse(Symbol);

nit: a blank line between methods.



Comment at: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp:526
   EXPECT_TRUE(hasSymbol(Symbol));
+  EXPECT_FALSE(hasUse(Symbol));  // Not yet implemented.
 

I'd put a `FIXME` comment here.


https://reviews.llvm.org/D30210



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


[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-02-22 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 89331.
xiangzhai added a comment.

Hi Anna,

I added **svalBinMulOp**  to take BO_Mul evalBinOp for g_malloc_n's two 
arguments: CE->getArg(0) and CE->getArg(1), so it does **NOT** need to change 
**MallocMemAux** any more, but just use it in this way:

  State = MallocMemAux(C, CE,   
   svalBinMulOp(C, CE->getArg(0), 
CE->getArg(1), State),
   UndefinedVal(), State);

And I also added **ReallocMemN** for g_realloc_n, it also use svalBinMulOp for 
**!StateSizeIsZero** check.

Please indicate my mistake, thanks a lot!

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D28348

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/gmalloc.c

Index: test/Analysis/gmalloc.c
===
--- test/Analysis/gmalloc.c
+++ test/Analysis/gmalloc.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+typedef void* gpointer;
+typedef const void* gconstpointer;
+typedef unsigned long gsize;
+typedef unsigned int guint;
+
+gpointer g_malloc(gsize n_bytes);
+gpointer g_malloc0(gsize n_bytes);
+gpointer g_realloc(gpointer mem, gsize n_bytes);
+gpointer g_try_malloc(gsize n_bytes);
+gpointer g_try_malloc0(gsize n_bytes);
+gpointer g_try_realloc(gpointer mem, gsize n_bytes);
+gpointer g_malloc_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_malloc0_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_malloc_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_malloc0_n(gsize n_blocks, gsize n_block_bytes);
+gpointer g_try_realloc_n(gpointer mem, gsize n_blocks, gsize n_block_bytes);
+void g_free(gpointer mem);
+gpointer g_memdup(gconstpointer mem, guint byte_size);
+
+static const gsize n_bytes = 1024;
+
+void f1() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char));
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char));
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char));
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g2); // expected-warning{{Attempt to free released memory}}
+}
+
+void f2() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char));
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char));
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char));
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+  g3 = g_memdup(g3, n_bytes); // expected-warning{{Use of memory after it is freed}}
+}
+
+void f3() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2); // expected-warning{{Potential leak of memory pointed to by 'g4'}}
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g6'}}
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g5'}}
+  gpointer g8 = g_try_malloc0_n(n_bytes, sizeof(char));
+  g7 = g_try_realloc_n(g7, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g8'}}
+
+  g_free(g1); // expected-warning{{Potential leak of memory pointed to by 'g7'}}
+  g_free(g2);
+  g_free(g3);
+}
+
+void f4() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+  gpointer g5 = g_malloc_n(n_bytes, sizeof(char));
+  gpointer g6 = g_malloc0_n(n_bytes, sizeof(char));
+  g5 = g_realloc_n(g5, n_bytes * 2, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g6'}}
+  gpointer g7 = g_try_malloc_n(n_bytes, sizeof(char)); // expected-warning{{Potential leak of memory pointed to by 'g5'}}
+ 

[clang-tools-extra] r295814 - Adds a hook clang-include-fixer-add-include-hook that is invoked with the path and type of the added include.

2017-02-22 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Wed Feb 22 02:26:04 2017
New Revision: 295814

URL: http://llvm.org/viewvc/llvm-project?rev=295814=rev
Log:
Adds a hook clang-include-fixer-add-include-hook that is invoked with the path 
and type of the added include.

This patch also adds a new function clang-include-fixer-from-symbol, which 
prompts the user for a symbol to resolve and include.

Patch by Torsten Marek.

Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=295814=295813=295814=diff
==
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Wed Feb 
22 02:26:04 2017
@@ -20,6 +20,11 @@
   "Clang-based include fixer."
   :group 'tools)
 
+(defvar clang-include-fixer-add-include-hook nil
+  "A hook that will be called for every added include.
+The first argument is the filename of the include, the second argument is
+non-nil if the include is a system-header.")
+
 (defcustom clang-include-fixer-executable
   "clang-include-fixer"
   "Location of the clang-include-fixer executable.
@@ -67,8 +72,15 @@ This string is passed as -input argument
   (let ((symbol (clang-include-fixer--symbol-at-point)))
 (unless symbol
   (user-error "No symbol at current location"))
-(clang-include-fixer--start #'clang-include-fixer--add-header
-(format "-query-symbol=%s" symbol
+(clang-include-fixer-from-symbol symbol)))
+
+(defun clang-include-fixer-from-symbol (symbol)
+  "Invoke the Clang include fixer for the SYMBOL.
+When called interactively, prompts the user for a symbol."
+  (interactive
+   (list (read-string "Symbol: " (clang-include-fixer--symbol-at-point
+  (clang-include-fixer--start #'clang-include-fixer--add-header
+  (format "-query-symbol=%s" symbol)))
 
 (defun clang-include-fixer--start (callback  args)
   "Asynchronously start clang-include-fixer with parameters ARGS.
@@ -250,7 +262,12 @@ clang-include-fixer to insert the select
;; Replacing the buffer now would undo the user’s changes.
(user-error (concat "The buffer has been changed "
"before the header could be inserted")))
- (clang-include-fixer--replace-buffer stdout)))
+ (clang-include-fixer--replace-buffer stdout)
+ (let-alist context
+   (let-alist (car .HeaderInfos)
+ (run-hook-with-args 'clang-include-fixer-add-include-hook
+ (substring .Header 1 -1)
+ (string= (substring .Header 0 1) "<"))
  (format "-insert-header=%s"
  (clang-include-fixer--encode-json context)))
   nil)


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