[PATCH] D34496: [clang] Fix printf check for CFIndex

2017-06-22 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap planned changes to this revision.
alexshap added a comment.

ignore this diff for now, i will update it soon.


Repository:
  rL LLVM

https://reviews.llvm.org/D34496



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


[PATCH] D34496: [clang] Fix printf check for CFIndex

2017-06-22 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap updated this revision to Diff 103536.
alexshap added a comment.

update the tests


Repository:
  rL LLVM

https://reviews.llvm.org/D34496

Files:
  lib/Sema/SemaChecking.cpp
  test/FixIt/fixit-format-darwin.m
  test/FixIt/format-darwin.m

Index: test/FixIt/format-darwin.m
===
--- test/FixIt/format-darwin.m
+++ test/FixIt/format-darwin.m
@@ -7,13 +7,14 @@
 int printf(const char * restrict, ...);
 
 #if __LP64__
+typedef long CFIndex;
 typedef long NSInteger;
 typedef unsigned long NSUInteger;
 typedef int SInt32;
 typedef unsigned int UInt32;
 
 #else
-
+typedef int CFIndex;
 typedef int NSInteger;
 typedef unsigned int NSUInteger;
 typedef long SInt32;
@@ -27,6 +28,7 @@
   EnumValueB
 } NSIntegerEnum;
 
+CFIndex getCFIndex();
 NSInteger getNSInteger();
 NSUInteger getNSUInteger();
 SInt32 getSInt32();
@@ -55,6 +57,11 @@
 
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)"
+
+  printf("%s", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}}
+
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)"
 }
 
 @interface Foo {
@@ -120,6 +127,11 @@
 
   // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
   // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)"
+
+  printf("%d", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}}
+
+  // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
+  // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)"
 }
 
 void testPreserveHex() {
@@ -167,6 +179,10 @@
   printf("%ld", getNSIntegerEnum()); // expected-warning{{enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
 
   // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)"
+
+  printf("%ld", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}}
+
+  // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)"
 }
 
 void testPreserveHex() {
@@ -218,6 +234,11 @@
 
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:31}:"(long)"
+
+  printf("%s", (CFIndex)0); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}}
+  
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:25}:"(long)"
 }
 
 void testCapitals() {
Index: test/FixIt/fixit-format-darwin.m
===
--- test/FixIt/fixit-format-darwin.m
+++ test/FixIt/fixit-format-darwin.m
@@ -8,12 +8,15 @@
 int printf(const char * restrict, ...);
 
 #if __LP64__
+typedef long CFIndex;
 typedef long NSInteger;
 typedef unsigned long NSUInteger;
 #else
+typedef int CFIndex;
 typedef int NSInteger;
 typedef unsigned int NSUInteger;
 #endif
+CFIndex getCFIndex();
 NSInteger getNSInteger();
 NSUInteger getNSUInteger();
 
@@ -74,3 +77,10 @@
   Outer2("test 9: %s %s", getNSInteger(), getNSInteger());
   // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger());
 }
+
+void testCFIndex() {
+  printf("test 10: %s", getCFIndex()); 
+  // CHECK: printf("test 10: %ld", (long)getCFIndex());
+  printf("test 11: %s %s", getCFIndex(), getCFIndex());
+  // CHECK: printf("test 11: %ld %ld", (long)getCFIndex(), (long)getCFIndex());
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6000,6 +6000,7 @@
   while (const TypedefType *UserTy = TyTy->getAs()) {
 StringRef Name = UserTy->getDecl()->getName();
 QualType CastTy = llvm::StringSwitch(Name)
+  .Case("CFIndex", Context.LongTy)
   .Case("NSInteger", Context.LongTy)
   .Case("NSUInteger", Context.UnsignedLongTy)
   .Case("SInt32", Context.IntTy)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34304: Allow CompilerInvocations to generate .d files.

2017-06-22 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

I mean, arguments need to be adjusted before converting to ArgStringList and 
calling newInvocation? I'm not sure I fully understand the problem, can you 
elaborate?


https://reviews.llvm.org/D34304



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


[PATCH] D34470: [clangd] Allow to override resource dir in ClangdServer.

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

LG


https://reviews.llvm.org/D34470



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


[PATCH] D34469: Use vfs::FileSystem in ASTUnit when creating CompilerInvocation.

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

LG


https://reviews.llvm.org/D34469



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


[PATCH] D34329: [GSoC] Clang AST diffing

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



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:57
+/// Within a tree, this identifies a node by its preorder offset.
+using NodeId = int;
+

johannes wrote:
> arphaman wrote:
> > I think that it's better to make make `NodeId` a structure as well and make 
> > `InvalidNodeId` a private member. I suggest the following interface for 
> > `NodeId`:
> > 
> > ```
> > struct NodeId {
> > private:
> >   static const int InvalidNodeId; 
> > public:
> >   int Id;
> > 
> >   NodeId() : Id(InvalidNodeId) { }
> >   NodeId(int Id) : Id(Id) { }
> >   
> >   bool isValid() const { return Id != InvalidNodeId; }
> >   bool isInvalid() const { return Id == InvalidNodeId; }
> > };
> > ```
> > 
> > 
> > This way you'll get rid of a couple of variable initializations that use 
> > `InvalidNodeId`. You also won't need to call the `memset` when creating the 
> > unique pointer array of `NodeId`s.
> Ok, I did it like this. 
> 
> Can I create a header file inside lib/Tooling/ASTDiff and include it from the 
> public interface? This would help reduce the clutter.
> 
> Instead of NodeId we could also just use references / pointer types. I don't 
> see any particularly good reason for choosing either one above the other.
> I guess indices make it more obvious how to compute the number of descendants 
> and such. On the other hand, when using reference types, there is less 
> boilerplate to write for loops.
No, but you can create a header ASTDiffInternal or somesuch next to the header 
in the public dir.


https://reviews.llvm.org/D34329



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


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-06-22 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

This seems like a reasonable start, and is a step forward.
For the VAArgs, this will be self-consistent, but to be compliant with the 
system ABI, I think you'll need to account the different padding rules for 
small aggregates, as per pp14 of "Mac_OS_X_ABI_Function_Calls".  Specifically, 
1 and 2 byte aggregates are right-aligned and padded on the left, but sizes 3 
and above are left-aligned and padded on the right.

I have a more complete ABIInfo implementation, but it needs forward-porting to 
trunk.  Will let you know when that's done.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499



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


[PATCH] D34502: [analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
Herald added a subscriber: whisperity.

This is how asserts are working right now. This way the semantics of 
__builtin_assume will be identical to asserts.

I also moved the tests to another file.


Repository:
  rL LLVM

https://reviews.llvm.org/D34502

Files:
  lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  test/Analysis/builtin-assume.c
  test/Analysis/builtin-functions.cpp


Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 void testAddressof(int x) {
   clang_analyzer_eval(&x == __builtin_addressof(x)); // 
expected-warning{{TRUE}}
@@ -50,3 +51,16 @@
   q = (char*) __builtin_assume_aligned(p + 1, 16);
   clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
 }
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__builtin_assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}
Index: test/Analysis/builtin-assume.c
===
--- test/Analysis/builtin-assume.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
-
-void clang_analyzer_eval(int);
-
-void f(int i) {
-  __builtin_assume(i < 10);
-  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
-}
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -50,8 +50,10 @@
 state = state->assume(ArgSVal.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
-if (!state)
+if (!state) {
+  C.generateSink(C.getState(), C.getPredecessor());
   return true;
+}
 
 C.addTransition(state);
 return true;


Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 void testAddressof(int x) {
   clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}}
@@ -50,3 +51,16 @@
   q = (char*) __builtin_assume_aligned(p + 1, 16);
   clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
 }
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__builtin_assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}
Index: test/Analysis/builtin-assume.c
===
--- test/Analysis/builtin-assume.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
-
-void clang_analyzer_eval(int);
-
-void f(int i) {
-  __builtin_assume(i < 10);
-  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
-}
Index: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -50,8 +50,10 @@
 state = state->assume(ArgSVal.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
-if (!state)
+if (!state) {
+  C.generateSink(C.getState(), C.getPredecessor());
   return true;
+}
 
 C.addTransition(state);
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34502: [analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume

2017-06-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Hmm, yeah, right :)


Repository:
  rL LLVM

https://reviews.llvm.org/D34502



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


r305991 - [analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume

2017-06-22 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Jun 22 05:09:40 2017
New Revision: 305991

URL: http://llvm.org/viewvc/llvm-project?rev=305991&view=rev
Log:
[analyzer] Do not continue to analyze a path if the constraints contradict with 
builtin assume

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

Removed:
cfe/trunk/test/Analysis/builtin-assume.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/test/Analysis/builtin-functions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=305991&r1=305990&r2=305991&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Thu Jun 22 
05:09:40 2017
@@ -50,8 +50,10 @@ bool BuiltinFunctionChecker::evalCall(co
 state = state->assume(ArgSVal.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
-if (!state)
+if (!state) {
+  C.generateSink(C.getState(), C.getPredecessor());
   return true;
+}
 
 C.addTransition(state);
 return true;

Removed: cfe/trunk/test/Analysis/builtin-assume.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-assume.c?rev=305990&view=auto
==
--- cfe/trunk/test/Analysis/builtin-assume.c (original)
+++ cfe/trunk/test/Analysis/builtin-assume.c (removed)
@@ -1,8 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
-
-void clang_analyzer_eval(int);
-
-void f(int i) {
-  __builtin_assume(i < 10);
-  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
-}

Modified: cfe/trunk/test/Analysis/builtin-functions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=305991&r1=305990&r2=305991&view=diff
==
--- cfe/trunk/test/Analysis/builtin-functions.cpp (original)
+++ cfe/trunk/test/Analysis/builtin-functions.cpp Thu Jun 22 05:09:40 2017
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 void testAddressof(int x) {
   clang_analyzer_eval(&x == __builtin_addressof(x)); // 
expected-warning{{TRUE}}
@@ -50,3 +51,16 @@ void test_assume_aligned_4(char *p) {
   q = (char*) __builtin_assume_aligned(p + 1, 16);
   clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
 }
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__builtin_assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}


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


[PATCH] D34502: [analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume

2017-06-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305991: [analyzer] Do not continue to analyze a path if the 
constraints contradict with… (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D34502?vs=103540&id=103544#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34502

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  cfe/trunk/test/Analysis/builtin-assume.c
  cfe/trunk/test/Analysis/builtin-functions.cpp


Index: cfe/trunk/test/Analysis/builtin-functions.cpp
===
--- cfe/trunk/test/Analysis/builtin-functions.cpp
+++ cfe/trunk/test/Analysis/builtin-functions.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 void testAddressof(int x) {
   clang_analyzer_eval(&x == __builtin_addressof(x)); // 
expected-warning{{TRUE}}
@@ -50,3 +51,16 @@
   q = (char*) __builtin_assume_aligned(p + 1, 16);
   clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
 }
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__builtin_assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}
Index: cfe/trunk/test/Analysis/builtin-assume.c
===
--- cfe/trunk/test/Analysis/builtin-assume.c
+++ cfe/trunk/test/Analysis/builtin-assume.c
@@ -1,8 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
-
-void clang_analyzer_eval(int);
-
-void f(int i) {
-  __builtin_assume(i < 10);
-  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
-}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -50,8 +50,10 @@
 state = state->assume(ArgSVal.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
-if (!state)
+if (!state) {
+  C.generateSink(C.getState(), C.getPredecessor());
   return true;
+}
 
 C.addTransition(state);
 return true;


Index: cfe/trunk/test/Analysis/builtin-functions.cpp
===
--- cfe/trunk/test/Analysis/builtin-functions.cpp
+++ cfe/trunk/test/Analysis/builtin-functions.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 void testAddressof(int x) {
   clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}}
@@ -50,3 +51,16 @@
   q = (char*) __builtin_assume_aligned(p + 1, 16);
   clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
 }
+
+void f(int i) {
+  __builtin_assume(i < 10);
+  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
+}
+
+void g(int i) {
+  if (i > 5) {
+__builtin_assume(i < 5);
+clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
+// We give up the analysis on this path.
+  }
+}
Index: cfe/trunk/test/Analysis/builtin-assume.c
===
--- cfe/trunk/test/Analysis/builtin-assume.c
+++ cfe/trunk/test/Analysis/builtin-assume.c
@@ -1,8 +0,0 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
-
-void clang_analyzer_eval(int);
-
-void f(int i) {
-  __builtin_assume(i < 10);
-  clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
-}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -50,8 +50,10 @@
 state = state->assume(ArgSVal.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
-if (!state)
+if (!state) {
+  C.generateSink(C.getState(), C.getPredecessor());
   return true;
+}
 
 C.addTransition(state);
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

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

It looks like if we have a function without the `return` (like the sample 
below), we will pass in a `0` as the location pointer. This will prevent a 
report of a runtime error as your compiler-rt change ignores the location 
pointers that are `nil`. Is this a bug or is this the intended behaviour?

  int *_Nonnull nonnull_retval1(int *p) {
  }


https://reviews.llvm.org/D34299



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


[PATCH] D34506: Relax an assert in the comparison of source locations

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.

Right now source locations from different translation units can not be 
compared. 
This is a problem for an upcoming feature in the Static Analyzer, the cross 
translation unit support (https://reviews.llvm.org/D30691).

It would be great to be able to sort the source locations, even if there are no 
guarantee to have
a meaningful order between source locations from different translation units.


Repository:
  rL LLVM

https://reviews.llvm.org/D34506

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -2034,6 +2034,9 @@
 }
 
 /// \brief Determines the order of 2 source locations in the translation unit.
+///It also works when two locations are from different translation
+///units. In that case it will return *some* order, that is
+///deterministic for that invocation of the compiler.
 ///
 /// \returns true if LHS source location comes before RHS, false otherwise.
 bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
@@ -2130,7 +2133,8 @@
   return LIsScratch;
 return LOffs.second < ROffs.second;
   }
-  llvm_unreachable("Unsortable locations found");
+  // Source locations from different translation units.
+  return LOffs.first < ROffs.first;
 }
 
 void SourceManager::PrintStats() const {


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -2034,6 +2034,9 @@
 }
 
 /// \brief Determines the order of 2 source locations in the translation unit.
+///It also works when two locations are from different translation
+///units. In that case it will return *some* order, that is
+///deterministic for that invocation of the compiler.
 ///
 /// \returns true if LHS source location comes before RHS, false otherwise.
 bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
@@ -2130,7 +2133,8 @@
   return LIsScratch;
 return LOffs.second < ROffs.second;
   }
-  llvm_unreachable("Unsortable locations found");
+  // Source locations from different translation units.
+  return LOffs.first < ROffs.first;
 }
 
 void SourceManager::PrintStats() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305996 - [index] Add the "SpecializationOf" relation to the forward declarations

2017-06-22 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Jun 22 06:20:07 2017
New Revision: 305996

URL: http://llvm.org/viewvc/llvm-project?rev=305996&view=rev
Log:
[index] Add the "SpecializationOf" relation to the forward declarations
of class template specializations

This commit fixes an issue where a forward declaration of a class template
specialization was not related to the base template. We need to relate even
forward declarations because specializations don't have to be defined.

rdar://32869409

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

Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=305996&r1=305995&r2=305996&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Thu Jun 22 06:20:07 2017
@@ -611,18 +611,16 @@ public:
ClassTemplateSpecializationDecl *D) 
{
 // FIXME: Notify subsequent callbacks if info comes from implicit
 // instantiation.
-if (D->isThisDeclarationADefinition()) {
-  llvm::PointerUnion
-  Template = D->getSpecializedTemplateOrPartial();
-  const Decl *SpecializationOf =
-  Template.is()
-  ? (Decl *)Template.get()
-  : Template.get();
-  IndexCtx.indexTagDecl(
-  D, 
SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
-SpecializationOf));
-}
+llvm::PointerUnion
+Template = D->getSpecializedTemplateOrPartial();
+const Decl *SpecializationOf =
+Template.is()
+? (Decl *)Template.get()
+: Template.get();
+IndexCtx.indexTagDecl(
+D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
+  SpecializationOf));
 if (TypeSourceInfo *TSI = D->getTypeAsWritten())
   IndexCtx.indexTypeSourceInfo(TSI, /*Parent=*/nullptr,
D->getLexicalDeclContext());

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=305996&r1=305995&r2=305996&view=diff
==
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Thu Jun 22 06:20:07 2017
@@ -282,7 +282,9 @@ class SpecializationDecl { };
 
 template<>
 class SpecializationDecl;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | SpecializationDecl | 
c:@S@SpecializationDecl>#I |  | Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
 
 template<>
 class SpecializationDecl { };
@@ -292,8 +294,10 @@ class SpecializationDecl { };
 
 template
 class PartialSpecilizationClass;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
-// CHECK-NEXT: [[@LINE-2]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref 
| rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TPS)/C++ | PartialSpecilizationClass | 
c:@SP>1#T@PartialSpecilizationClass>#$@S@Cls#t0.0 |  | 
Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
+// CHECK-NEXT: [[@LINE-4]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref 
| rel: 0
 
 template<>
 class PartialSpecilizationClass : Cls { };


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


[PATCH] D34462: [index] "SpecializationOf" relation should be added even to forward declarations of class template specializations

2017-06-22 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305996: [index] Add the "SpecializationOf" relation to the 
forward declarations (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D34462?vs=103411&id=103554#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34462

Files:
  cfe/trunk/lib/Index/IndexDecl.cpp
  cfe/trunk/test/Index/Core/index-source.cpp


Index: cfe/trunk/test/Index/Core/index-source.cpp
===
--- cfe/trunk/test/Index/Core/index-source.cpp
+++ cfe/trunk/test/Index/Core/index-source.cpp
@@ -282,7 +282,9 @@
 
 template<>
 class SpecializationDecl;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | SpecializationDecl | 
c:@S@SpecializationDecl>#I |  | Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | SpecializationDecl | 
c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
 
 template<>
 class SpecializationDecl { };
@@ -292,8 +294,10 @@
 
 template
 class PartialSpecilizationClass;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
-// CHECK-NEXT: [[@LINE-2]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref 
| rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TPS)/C++ | PartialSpecilizationClass | 
c:@SP>1#T@PartialSpecilizationClass>#$@S@Cls#t0.0 |  | 
Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | PartialSpecilizationClass | 
c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
+// CHECK-NEXT: [[@LINE-4]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref 
| rel: 0
 
 template<>
 class PartialSpecilizationClass : Cls { };
Index: cfe/trunk/lib/Index/IndexDecl.cpp
===
--- cfe/trunk/lib/Index/IndexDecl.cpp
+++ cfe/trunk/lib/Index/IndexDecl.cpp
@@ -611,18 +611,16 @@
ClassTemplateSpecializationDecl *D) 
{
 // FIXME: Notify subsequent callbacks if info comes from implicit
 // instantiation.
-if (D->isThisDeclarationADefinition()) {
-  llvm::PointerUnion
-  Template = D->getSpecializedTemplateOrPartial();
-  const Decl *SpecializationOf =
-  Template.is()
-  ? (Decl *)Template.get()
-  : Template.get();
-  IndexCtx.indexTagDecl(
-  D, 
SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
-SpecializationOf));
-}
+llvm::PointerUnion
+Template = D->getSpecializedTemplateOrPartial();
+const Decl *SpecializationOf =
+Template.is()
+? (Decl *)Template.get()
+: Template.get();
+IndexCtx.indexTagDecl(
+D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
+  SpecializationOf));
 if (TypeSourceInfo *TSI = D->getTypeAsWritten())
   IndexCtx.indexTypeSourceInfo(TSI, /*Parent=*/nullptr,
D->getLexicalDeclContext());


Index: cfe/trunk/test/Index/Core/index-source.cpp
===
--- cfe/trunk/test/Index/Core/index-source.cpp
+++ cfe/trunk/test/Index/Core/index-source.cpp
@@ -282,7 +282,9 @@
 
 template<>
 class SpecializationDecl;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | SpecializationDecl | c:@S@SpecializationDecl>#I |  | Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | SpecializationDecl | c:@ST>1#T@SpecializationDecl
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | SpecializationDecl | c:@ST>1#T@SpecializationDecl |  | Ref | rel: 0
 
 template<>
 class SpecializationDecl { };
@@ -292,8 +294,10 @@
 
 template
 class PartialSpecilizationClass;
-// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
-// CHECK-NEXT: [[@LINE-2]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref | rel: 0
+// CHECK: [[@LINE-1]]:7 | class(Gen,TPS)/C++ | PartialSpecilizationClass | c:@SP>1#T@PartialSpecilizationClass>#$@S@Cls#t0.0 |  | Decl,RelSpecialization | rel: 1
+// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass
+// CHECK: [[@LINE-3]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass |  | Ref | rel: 0
+// CHECK-NEXT: [[@LINE-4]]:33 | class/C++ | Cls | c:@S@Cls |  | Ref | rel: 0
 
 template<>
 class PartialSpecilizationClass : Cls { };
Index: cfe/trunk/lib/Index/IndexDecl.cpp
==

[PATCH] D33841: [clang-tidy] redundant keyword check

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: docs/clang-tidy/checks/readability-redundant-keyword.rst:8
+
+`extern` is redundant in function declarations
+

alexfh wrote:
> Could you explain, why you think `extern` is redundant in function 
> declarations?
Just to be clear here, do you think there is a case where extern is not 
redundant or you just want the documentation to be extended? 


Repository:
  rL LLVM

https://reviews.llvm.org/D33841



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


[PATCH] D34506: Relax an assert in the comparison of source locations

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Note that, it is not easy to add a test case for this patch without the 
https://reviews.llvm.org/D30691 being accepted.


Repository:
  rL LLVM

https://reviews.llvm.org/D34506



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


[PATCH] D34444: Teach codegen to work in incremental processing mode.

2017-06-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 103560.
v.g.vassilev added a comment.
Herald added a subscriber: mgorny.

Add a test.

Patch by Axel Naumann!


https://reviews.llvm.org/D3

Files:
  lib/CodeGen/CGDeclCXX.cpp
  unittests/CodeGen/CMakeLists.txt
  unittests/CodeGen/IncrementalProcessingTest.cpp

Index: unittests/CodeGen/IncrementalProcessingTest.cpp
===
--- /dev/null
+++ unittests/CodeGen/IncrementalProcessingTest.cpp
@@ -0,0 +1,177 @@
+//===- unittests/CodeGen/BufferSourceTest.cpp - MemoryBuffer source tests -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+
+#include 
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Incremental processing produces several modules, all using the same "main
+// file". Make sure CodeGen can cope with that, e.g. for static initializers.
+const char TestProgram1[] =
+"extern \"C\" int funcForProg1() { return 17; }\n"
+"struct EmitCXXGlobalInitFunc1 {\n"
+"   EmitCXXGlobalInitFunc1() {}\n"
+"} test1;";
+
+const char TestProgram2[] =
+"extern \"C\" int funcForProg2() { return 42; }\n"
+"struct EmitCXXGlobalInitFunc2 {\n"
+"   EmitCXXGlobalInitFunc2() {}\n"
+"} test2;";
+
+
+/// An incremental version of ParseAST().
+static std::unique_ptr
+IncrementalParseAST(CompilerInstance& CI, Parser& P,
+CodeGenerator& CG, const char* code) {
+  static int counter = 0;
+  struct IncreaseCounterOnRet {
+~IncreaseCounterOnRet() {
+  ++counter;
+}
+  } ICOR;
+
+  Sema& S = CI.getSema();
+  clang::SourceManager &SM = S.getSourceManager();
+  if (!code) {
+// Main file
+SM.setMainFileID(SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(""), clang::SrcMgr::C_User));
+
+S.getPreprocessor().EnterMainSourceFile();
+P.Initialize();
+  } else {
+FileID FID = SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(code), clang::SrcMgr::C_User);
+SourceLocation MainStartLoc = SM.getLocForStartOfFile(SM.getMainFileID());
+SourceLocation InclLoc = MainStartLoc.getLocWithOffset(counter);
+S.getPreprocessor().EnterSourceFile(FID, 0, InclLoc);
+  }
+
+  ExternalASTSource *External = S.getASTContext().getExternalSource();
+  if (External)
+External->StartTranslationUnit(&CG);
+
+  Parser::DeclGroupPtrTy ADecl;
+  for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF;
+   AtEOF = P.ParseTopLevelDecl(ADecl)) {
+// If we got a null return and something *was* parsed, ignore it.  This
+// is due to a top-level semicolon, an action override, or a parse error
+// skipping something.
+if (ADecl && !CG.HandleTopLevelDecl(ADecl.get()))
+  return false;
+  }
+
+  // Process any TopLevelDecls generated by #pragma weak.
+  for (Decl *D : S.WeakTopLevelDecls())
+CG.HandleTopLevelDecl(DeclGroupRef(D));
+
+  CG.HandleTranslationUnit(S.getASTContext());
+
+  std::unique_ptr M(CG.ReleaseModule());
+  // Switch to next module.
+  CG.StartModule("incremental-module-" + std::to_string(counter),
+ M->getContext(), CI.getCodeGenOpts());
+  return M;
+}
+
+const Function* getGlobalInit(llvm::Module& M) {
+  for (const auto& Func: M)
+if (Func.hasName() && Func.getName().startswith("_GLOBAL__sub_I_"))
+  return &Func;
+
+  return nullptr;
+}
+
+TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
+LLVMContext Context;
+CompilerInstance compiler;
+
+compiler.createDiagnostics();
+compiler.getLangOpts().CPlusPlus = 1;
+compiler.getLangOpts().CPlusPlus11 = 1;
+
+compiler.getTargetOpts().Triple = llvm::Triple::normalize(
+llvm::sys::getProcessTriple());
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+  compiler.getDiagnostics(),
+  std::make_shared(
+compiler.getTargetOpts(;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+compiler.getPreprocessor().enableIncrementalProcessing();
+
+compiler.createASTContext();
+
+CodeGenerator* CG =
+CreateLLVMCodeGen(
+compiler.getDiagnostics(),
+"main-module",
+compiler.ge

[PATCH] D33333: Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier

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

Aside from a few small nits with the test cases, this LGTM! You should hold off 
on committing for a day or two in case Richard or others have comments on the 
patch.




Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:5-6
+}; // implicitly noexcept(true)
+A_ShouldDiag::~A_ShouldDiag() {  // expected-note  {{destructor or deallocator 
has a}}
+  throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+}

The first test case showing a diagnostic or a note in the test should spell out 
the full text of the diagnostics. The remainder of the diagnostic checks can be 
shortened somewhat, but this ensures the full diagnostic text is properly 
checked.



Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:8-11
+struct B_ShouldDiag {
+  int i;
+  ~B_ShouldDiag() noexcept(true) {}
+};

Why name this ShouldDiag if it doesn't diagnose?



Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:126
+struct Throws {
+  ~Throws()noexcept(false);
+};

Add a space before the `noexcept`.



Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:131
+  Throws T;
+  ~ShouldDiagnose() noexcept{ //expected-note {{destructor or deallocator has 
a}}
+throw; // expected-warning {{has a non-throwing exception specification 
but}}

Add a space before the `{`.


Repository:
  rL LLVM

https://reviews.llvm.org/D3



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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-22 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

Splitting the attrloc from the useloc might make sense since we would be able 
to emit attrloc just once. But I don't see why we need to store/load those 
pointers in runtime instead of just caching the `Constant*` in 
`CodeGenFunction`.
I'd also like to have some asserts and explicit resets to `nullptr` after use 
on the `ReturnLocation` variable, if possible.




Comment at: lib/CodeGen/CGStmt.cpp:1035
+assert(ReturnLocation.isValid() && "No valid return location");
+Builder.CreateStore(Builder.CreateBitCast(SLocPtr, Int8PtrTy),
+ReturnLocation);

Can't you just keep the `Constant*` around and use it later for the static 
data? Instead of creating a global var and have runtime store/load?



Comment at: lib/CodeGen/CodeGenFunction.h:1412
+  /// source location for diagnostics.
+  Address ReturnLocation = Address::invalid();
+

Maybe `CurrentReturnLocation`?


https://reviews.llvm.org/D34299



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


[PATCH] D34510: Teach clang how to merge typedef over anonymous structs in C mode.

2017-06-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.

empty.h makes module A available. textual.h brings the definition of __fsid_t 
and a.h imports again the definition of __fsid_t.

In C mode clang fails to merge the textually included definition with the one 
imported from a module. The C lookup rules fail to find the imported definition 
because its linkage is internal in non C++ mode.

This patch reinstates some of the ODR merging rules for typedefs of anonymous 
tags for languages other than C++.

Patch by Raphael Isemann and I.


Repository:
  rL LLVM

https://reviews.llvm.org/D34510

Files:
  lib/AST/Decl.cpp
  lib/Sema/SemaDecl.cpp
  test/Modules/Inputs/merge-typedefs-c/a.h
  test/Modules/Inputs/merge-typedefs-c/empty.h
  test/Modules/Inputs/merge-typedefs-c/module.modulemap
  test/Modules/Inputs/merge-typedefs-c/textual.h
  test/Modules/merge-typedefs-c.c


Index: test/Modules/merge-typedefs-c.c
===
--- /dev/null
+++ test/Modules/merge-typedefs-c.c
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -xc -fmodules-cache-path=%t 
-I%S/Inputs/merge-typedefs-c/ -fimplicit-module-maps -verify %s
+// RUN: %clang_cc1 -fmodules -xc++ -fmodules-cache-path=%t 
-I%S/Inputs/merge-typedefs-c/ -fimplicit-module-maps -verify %s
+
+// expected-no-diagnostics
+#include "empty.h"
+#include "textual.h"
+#include "a.h"
+
+__fsid_t use;
Index: test/Modules/Inputs/merge-typedefs-c/textual.h
===
--- /dev/null
+++ test/Modules/Inputs/merge-typedefs-c/textual.h
@@ -0,0 +1,7 @@
+#ifndef TEXTUAL_H
+#define TEXTUAL_H
+
+typedef struct { } __fsid_t;
+
+#endif
+
Index: test/Modules/Inputs/merge-typedefs-c/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/merge-typedefs-c/module.modulemap
@@ -0,0 +1,11 @@
+module "A" {
+   export *
+   module "a.h" {
+ export *
+ header "a.h"
+   }
+   module "empty.h" {
+ export *
+ header "empty.h"
+   }
+ }
Index: test/Modules/Inputs/merge-typedefs-c/empty.h
===
--- /dev/null
+++ test/Modules/Inputs/merge-typedefs-c/empty.h
@@ -0,0 +1 @@
+// This is a module trigger.
Index: test/Modules/Inputs/merge-typedefs-c/a.h
===
--- /dev/null
+++ test/Modules/Inputs/merge-typedefs-c/a.h
@@ -0,0 +1,4 @@
+#ifndef A_H
+#define A_H
+#include "textual.h"
+#endif
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1996,8 +1996,7 @@
 
   // If both declarations give a tag declaration a typedef name for linkage
   // purposes, then they declare the same entity.
-  if (S.getLangOpts().CPlusPlus &&
-  OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) &&
+  if (OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) &&
   Decl->getAnonDeclWithTypedefName())
 continue;
 }
@@ -2115,7 +2114,7 @@
 auto *OldTag = OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
 auto *NewTag = New->getAnonDeclWithTypedefName();
 NamedDecl *Hidden = nullptr;
-if (getLangOpts().CPlusPlus && OldTag && NewTag &&
+if (OldTag && NewTag &&
 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
 !hasVisibleDefinition(OldTag, &Hidden)) {
   // There is a definition of this tag, but it is not visible. Use it
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -1257,8 +1257,7 @@
 case Decl::TypeAlias:
   // A typedef declaration has linkage if it gives a type a name for
   // linkage purposes.
-  if (!D->getASTContext().getLangOpts().CPlusPlus ||
-  !cast(D)
+  if (!cast(D)
->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
 return LinkageInfo::none();
   break;


Index: test/Modules/merge-typedefs-c.c
===
--- /dev/null
+++ test/Modules/merge-typedefs-c.c
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -xc -fmodules-cache-path=%t -I%S/Inputs/merge-typedefs-c/ -fimplicit-module-maps -verify %s
+// RUN: %clang_cc1 -fmodules -xc++ -fmodules-cache-path=%t -I%S/Inputs/merge-typedefs-c/ -fimplicit-module-maps -verify %s
+
+// expected-no-diagnostics
+#include "empty.h"
+#include "textual.h"
+#include "a.h"
+
+__fsid_t use;
Index: test/Modules/Inputs/merge-typedefs-c/textual.h
===
--- /dev/null
+++ test/Modules/Inputs/merge-typedefs-c/textual.h
@@ -0,0 +1,7 @@
+#ifndef TEXTUAL_H
+#define TEXTUAL_H
+
+typedef struct { } __fsid_t;
+
+#endif
+
Index: test/Modules/Inputs/merge-typedefs-c/module.modulemap

[PATCH] D32642: [Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks

2017-06-22 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

I tried `SValBuilder::evalBinOp()` first but it did not help too much. It could 
decide only if I compared the same conjured symbols or different ones, but 
nothing more. It always gave me `UnknownVal`. Even if comparing ${conj_X} == 
${conj_X} + n where n was a concrete integer. So I have to compare the symbol 
part and the concrete integer part separately. Waiting is not an option for us 
since we are a bit delayed with this checker. I have to bring them out of alpha 
until the end of the year. If Z3 constraint solver is accepted and will be the 
default constraint manager, then I can somewhat simplify my code. That patch is 
under review for long and I am not sure whether it will be the default ever.


https://reviews.llvm.org/D32642



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


[PATCH] D34444: Teach codegen to work in incremental processing mode.

2017-06-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 103565.
v.g.vassilev added a comment.

Bring back the initial state of this patch. I accidentally uploaded a wrong 
patch here, instead of its dependee...


https://reviews.llvm.org/D3

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/ModuleBuilder.cpp


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -119,6 +119,14 @@
   return Builder->GetAddrOfGlobal(global, 
ForDefinition_t(isForDefinition));
 }
 
+llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C,
+  const CodeGenOptions& CGO) {
+  assert(!M && "Replacing existing Module?");
+  M.reset(new llvm::Module(ModuleName, C));
+  Initialize(*Ctx);
+  return M.get();
+}
+
 void Initialize(ASTContext &Context) override {
   Ctx = &Context;
 
@@ -317,6 +325,11 @@
->GetAddrOfGlobal(global, isForDefinition);
 }
 
+llvm::Module *CodeGenerator::StartModule(const std::string& ModuleName,
+ llvm::LLVMContext& C) {
+   return static_cast(this)->StartModule(ModuleName, C);
+}
+
 CodeGenerator *clang::CreateLLVMCodeGen(
 DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
 const HeaderSearchOptions &HeaderSearchOpts,
Index: include/clang/CodeGen/ModuleBuilder.h
===
--- include/clang/CodeGen/ModuleBuilder.h
+++ include/clang/CodeGen/ModuleBuilder.h
@@ -84,6 +84,11 @@
   ///   code generator will schedule the entity for emission if a
   ///   definition has been registered with this code generator.
   llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
+
+  /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
+  /// enable codegen in interactive processing environments.
+  llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C,
+const CodeGenOptions& CGO);
 };
 
 /// CreateLLVMCodeGen - Create a CodeGenerator instance.


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -119,6 +119,14 @@
   return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
 }
 
+llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C,
+  const CodeGenOptions& CGO) {
+  assert(!M && "Replacing existing Module?");
+  M.reset(new llvm::Module(ModuleName, C));
+  Initialize(*Ctx);
+  return M.get();
+}
+
 void Initialize(ASTContext &Context) override {
   Ctx = &Context;
 
@@ -317,6 +325,11 @@
->GetAddrOfGlobal(global, isForDefinition);
 }
 
+llvm::Module *CodeGenerator::StartModule(const std::string& ModuleName,
+ llvm::LLVMContext& C) {
+   return static_cast(this)->StartModule(ModuleName, C);
+}
+
 CodeGenerator *clang::CreateLLVMCodeGen(
 DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
 const HeaderSearchOptions &HeaderSearchOpts,
Index: include/clang/CodeGen/ModuleBuilder.h
===
--- include/clang/CodeGen/ModuleBuilder.h
+++ include/clang/CodeGen/ModuleBuilder.h
@@ -84,6 +84,11 @@
   ///   code generator will schedule the entity for emission if a
   ///   definition has been registered with this code generator.
   llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
+
+  /// Create a new \c llvm::Module after calling HandleTranslationUnit. This
+  /// enable codegen in interactive processing environments.
+  llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C,
+const CodeGenOptions& CGO);
 };
 
 /// CreateLLVMCodeGen - Create a CodeGenerator instance.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34059: Get the file name for the symbol from the Module, not the SourceManager.

2017-06-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 103566.
v.g.vassilev added a comment.
Herald added a subscriber: mgorny.

Add a test case.


https://reviews.llvm.org/D34059

Files:
  lib/CodeGen/CGDeclCXX.cpp
  unittests/CodeGen/CMakeLists.txt
  unittests/CodeGen/IncrementalProcessingTest.cpp

Index: unittests/CodeGen/IncrementalProcessingTest.cpp
===
--- /dev/null
+++ unittests/CodeGen/IncrementalProcessingTest.cpp
@@ -0,0 +1,174 @@
+//===- unittests/CodeGen/BufferSourceTest.cpp - MemoryBuffer source tests -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+
+#include 
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Incremental processing produces several modules, all using the same "main
+// file". Make sure CodeGen can cope with that, e.g. for static initializers.
+const char TestProgram1[] =
+"extern \"C\" int funcForProg1() { return 17; }\n"
+"struct EmitCXXGlobalInitFunc1 {\n"
+"   EmitCXXGlobalInitFunc1() {}\n"
+"} test1;";
+
+const char TestProgram2[] =
+"extern \"C\" int funcForProg2() { return 42; }\n"
+"struct EmitCXXGlobalInitFunc2 {\n"
+"   EmitCXXGlobalInitFunc2() {}\n"
+"} test2;";
+
+
+/// An incremental version of ParseAST().
+static std::unique_ptr
+IncrementalParseAST(CompilerInstance& CI, Parser& P,
+CodeGenerator& CG, const char* code) {
+  static int counter = 0;
+  struct IncreaseCounterOnRet {
+~IncreaseCounterOnRet() {
+  ++counter;
+}
+  } ICOR;
+
+  Sema& S = CI.getSema();
+  clang::SourceManager &SM = S.getSourceManager();
+  if (!code) {
+// Main file
+SM.setMainFileID(SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(""), clang::SrcMgr::C_User));
+
+S.getPreprocessor().EnterMainSourceFile();
+P.Initialize();
+  } else {
+FileID FID = SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(code), clang::SrcMgr::C_User);
+SourceLocation MainStartLoc = SM.getLocForStartOfFile(SM.getMainFileID());
+SourceLocation InclLoc = MainStartLoc.getLocWithOffset(counter);
+S.getPreprocessor().EnterSourceFile(FID, 0, InclLoc);
+  }
+
+  ExternalASTSource *External = S.getASTContext().getExternalSource();
+  if (External)
+External->StartTranslationUnit(&CG);
+
+  Parser::DeclGroupPtrTy ADecl;
+  for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF;
+   AtEOF = P.ParseTopLevelDecl(ADecl)) {
+// If we got a null return and something *was* parsed, ignore it.  This
+// is due to a top-level semicolon, an action override, or a parse error
+// skipping something.
+if (ADecl && !CG.HandleTopLevelDecl(ADecl.get()))
+  return false;
+  }
+
+  // Process any TopLevelDecls generated by #pragma weak.
+  for (Decl *D : S.WeakTopLevelDecls())
+CG.HandleTopLevelDecl(DeclGroupRef(D));
+
+  CG.HandleTranslationUnit(S.getASTContext());
+
+  std::unique_ptr M(CG.ReleaseModule());
+  // Switch to next module.
+  CG.StartModule("incremental-module-" + std::to_string(counter),
+ M->getContext(), CI.getCodeGenOpts());
+  return M;
+}
+
+const Function* getGlobalInit(llvm::Module& M) {
+  for (const auto& Func: M)
+if (Func.hasName() && Func.getName().startswith("_GLOBAL__sub_I_"))
+  return &Func;
+
+  return nullptr;
+}
+
+TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
+LLVMContext Context;
+CompilerInstance compiler;
+
+compiler.createDiagnostics();
+compiler.getLangOpts().CPlusPlus = 1;
+compiler.getLangOpts().CPlusPlus11 = 1;
+
+compiler.getTargetOpts().Triple = llvm::Triple::normalize(
+llvm::sys::getProcessTriple());
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+  compiler.getDiagnostics(),
+  std::make_shared(
+compiler.getTargetOpts(;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+compiler.getPreprocessor().enableIncrementalProcessing();
+
+compiler.createASTContext();
+
+CodeGenerator* CG =
+CreateLLVMCodeGen(
+compiler.getDiagnostics(),
+"main-module",
+compiler.getHeaderSearchOpts()

[PATCH] D32642: [Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks

2017-06-22 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 103568.
baloghadamsoftware added a comment.

Minor fixes according to the comments.


https://reviews.llvm.org/D32642

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/iterator-range.cpp

Index: test/Analysis/iterator-range.cpp
===
--- test/Analysis/iterator-range.cpp
+++ test/Analysis/iterator-range.cpp
@@ -13,7 +13,102 @@
   }
 }
 
+void simple_good_end_negated(const std::vector &v) {
+  auto i = v.end();
+  if (!(i == v.end())) {
+clang_analyzer_warnIfReached();
+*i; // no-warning
+  }
+}
+
 void simple_bad_end(const std::vector &v) {
   auto i = v.end();
   *i; // expected-warning{{Iterator accessed outside of its range}}
 }
+
+void simple_good_begin(const std::vector &v) {
+  auto i = v.begin();
+  if (i != v.begin()) {
+clang_analyzer_warnIfReached();
+*--i; // no-warning
+  }
+}
+
+void simple_good_begin_negated(const std::vector &v) {
+  auto i = v.begin();
+  if (!(i == v.begin())) {
+clang_analyzer_warnIfReached();
+*--i; // no-warning
+  }
+}
+
+void simple_bad_begin(const std::vector &v) {
+  auto i = v.begin();
+  *--i; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void copy(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  *i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void decrease(const std::vector &v) {
+  auto i = v.end();
+  --i;
+  *i; // no-warning
+}
+
+void copy_and_decrease1(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i1; // no-warning
+}
+
+void copy_and_decrease2(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void copy_and_increase1(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i1 == v.end())
+*i2; // no-warning
+}
+
+void copy_and_increase2(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i2 == v.end())
+*i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void tricky(std::vector &V, int e) {
+  const auto first = V.begin();
+  const auto comp1 = (first != V.end()), comp2 = (first == V.end());
+  if (comp1)
+*first;
+}
+
+void loop(std::vector &V, int e) {
+  auto start = V.begin();
+  while (true) {
+auto item = std::find(start, V.end(), e);
+if (item == V.end())
+  break;
+*item;  // no-warning
+start = ++item; // no-warning
+  }
+}
+
+void bad_move(std::list &L1, std::list &L2) {
+  auto i0 = --L2.cend();
+  L1 = std::move(L2);
+  *++i0; // expected-warning{{Iterator accessed outside of its range}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp
===
--- test/Analysis/diagnostics/explicit-suppression.cpp
+++ test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:490 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:514 {{Called C++ object pointer is null}}
 #endif
 }
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -252,6 +252,12 @@
   return size_t(_finish - _start);
 }
 
+void clear();
+
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
 T &operator[](size_t n) {
   return _start[n];
 }
@@ -295,6 +301,8 @@
 list& operator=(list &&other);
 list& operator=(std::initializer_list ilist);
 
+void clear();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -330,6 +338,16 @@
   return size_t(_finish - _start);
 }
 
+void clear();
+
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 T &operator[](size_t n) {
   return _start[n];
 }
@@ -369,6 +387,12 @@
 forward_list(forward_list &&other);
 ~forward_list();
 
+void clear();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
Index: lib/StaticAnalyzer/Chec

[PATCH] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
Herald added a subscriber: mgorny.

This patch introduces a class that can help to build tools that require cross 
translation unit facilities.
This class allows function definitions to be loaded from external AST files 
based on an index.
In order to use this functionality an index is required. USRs are used as names 
to look up the functions. 
This class also does caching to avoid redundant loading of AST files.

Right now only function defnitions can be loaded using this API, because this 
is what the Static Analyzer requires.
In to future this could be extended to classes, types etc.

Note that, there is no tests right now for this functionality, but this is 
temporary.
Tets will come together with the first user once it is accepted: 
https://reviews.llvm.org/D30691


Repository:
  rL LLVM

https://reviews.llvm.org/D34512

Files:
  include/clang/Tooling/CrossTranslationUnit.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CrossTranslationUnit.cpp

Index: lib/Tooling/CrossTranslationUnit.cpp
===
--- /dev/null
+++ lib/Tooling/CrossTranslationUnit.cpp
@@ -0,0 +1,162 @@
+//===--- CrossTranslationUnit.cpp - -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file provides an interface to load binary AST dumps on demand. This
+//  feature can be utilized for tools that require cross translation unit
+//  support.
+//
+//===--===//
+#include "clang/Tooling/CrossTranslationUnit.h"
+#include "clang/AST/ASTImporter.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Index/USRGeneration.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+CrossTranslationUnit::CrossTranslationUnit(CompilerInstance &CI)
+: CI(CI), Context(CI.getASTContext()) {}
+
+CrossTranslationUnit::~CrossTranslationUnit() {}
+
+std::string CrossTranslationUnit::getLookupName(const NamedDecl *ND) {
+  SmallString<128> DeclUSR;
+  bool Ret = index::generateUSRForDecl(ND, DeclUSR);
+  assert(!Ret);
+  llvm::raw_svector_ostream OS(DeclUSR);
+  // To support cross compilation.
+  llvm::Triple::ArchType T = Context.getTargetInfo().getTriple().getArch();
+  if (T == llvm::Triple::thumb)
+T = llvm::Triple::arm;
+  OS << "@" << Context.getTargetInfo().getTriple().getArchTypeName(T);
+  return OS.str();
+}
+
+/// Recursively visit the funtion decls of a DeclContext, and looks up a
+/// function based on mangled name.
+const FunctionDecl *
+CrossTranslationUnit::findFunctionInDeclContext(const DeclContext *DC,
+StringRef LookupFnName) {
+  if (!DC)
+return nullptr;
+  for (const Decl *D : DC->decls()) {
+const auto *SubDC = dyn_cast(D);
+if (const auto *FD = findFunctionInDeclContext(SubDC, LookupFnName))
+  return FD;
+
+const auto *ND = dyn_cast(D);
+const FunctionDecl *ResultDecl;
+if (!ND || !ND->hasBody(ResultDecl))
+  continue;
+// We are already sure that the triple is correct here.
+if (getLookupName(ResultDecl) != LookupFnName)
+  continue;
+return ResultDecl;
+  }
+  return nullptr;
+}
+
+const FunctionDecl *
+CrossTranslationUnit::getCTUDefinition(const FunctionDecl *FD, StringRef CTUDir,
+   StringRef IndexName) {
+  assert(!FD->hasBody() && "FD has a definition in current translation unit!");
+
+  std::string LookupFnName = getLookupName(FD);
+  if (LookupFnName.empty())
+return nullptr;
+  ASTUnit *Unit = nullptr;
+  auto FnUnitCacheEntry = FunctionAstUnitMap.find(LookupFnName);
+  if (FnUnitCacheEntry == FunctionAstUnitMap.end()) {
+if (FunctionFileMap.empty()) {
+  SmallString<256> ExternalFunctionMap = CTUDir;
+  llvm::sys::path::append(ExternalFunctionMap, IndexName);
+  std::ifstream ExternalFnMapFile(ExternalFunctionMap.c_str());
+  if (!ExternalFnMapFile) {
+llvm::errs() << "error: '" << ExternalFunctionMap
+ << "' cannot be opened: falling back to non-CTU mode\n";
+return nullptr;
+  }
+
+  std::string FunctionName, FileName;
+  std::string line;
+  while (std::getline(ExternalFnMapFile, line)) {
+size_t pos = line.find(" ");
+FunctionName = line.substr(0, pos);
+FileName = line.substr(pos + 1);
+SmallString<256> FilePath = CTUDir;
+llvm::sys::path::append(FilePath, FileName);
+   

[PATCH] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 103571.
xazax.hun added a comment.

- Add a tool to dump USRs for function definitions. It can be used to create 
index files.


https://reviews.llvm.org/D34512

Files:
  include/clang/Tooling/CrossTranslationUnit.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CrossTranslationUnit.cpp
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp

Index: tools/clang-func-mapping/ClangFnMapGen.cpp
===
--- /dev/null
+++ tools/clang-func-mapping/ClangFnMapGen.cpp
@@ -0,0 +1,127 @@
+//===- ClangFnMapGen.cpp ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//======//
+//
+// Clang tool which creates a list of defined functions and the files in which
+// they are defined.
+//
+//======//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/GlobalDecl.h"
+#include "clang/AST/Mangle.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/USRGeneration.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::tooling;
+
+static cl::OptionCategory ClangFnMapGenCategory("clang-fnmapgen options");
+
+class MapFunctionNamesConsumer : public ASTConsumer {
+public:
+  MapFunctionNamesConsumer(ASTContext &Context) : Ctx(Context) {}
+
+  ~MapFunctionNamesConsumer() {
+// Flush results to standard output.
+llvm::outs() << DefinedFuncsStr.str();
+  }
+
+  virtual void HandleTranslationUnit(ASTContext &Ctx) {
+handleDecl(Ctx.getTranslationUnitDecl());
+  }
+
+private:
+  std::string getLookupName(const FunctionDecl *FD);
+  void handleDecl(const Decl *D);
+
+  ASTContext &Ctx;
+  std::stringstream DefinedFuncsStr;
+  std::string CurrentFileName;
+};
+
+void MapFunctionNamesConsumer::handleDecl(const Decl *D) {
+  if (!D)
+return;
+
+  if (const auto *FD = dyn_cast(D)) {
+if (FD->isThisDeclarationADefinition()) {
+  if (const Stmt *Body = FD->getBody()) {
+SmallString<128> LookupName;
+bool Res = index::generateUSRForDecl(D, LookupName);
+assert(!Res);
+const SourceManager &SM = Ctx.getSourceManager();
+if (CurrentFileName.empty()) {
+  StringRef SMgrName =
+  SM.getFileEntryForID(SM.getMainFileID())->getName();
+  char *Path = realpath(SMgrName.str().c_str(), nullptr);
+  CurrentFileName = Path;
+  free(Path);
+}
+
+switch (FD->getLinkageInternal()) {
+case ExternalLinkage:
+case VisibleNoLinkage:
+case UniqueExternalLinkage:
+  if (SM.isInMainFile(Body->getLocStart()))
+DefinedFuncsStr << LookupName.str().str() << " " << CurrentFileName
+<< "\n";
+default:
+  break;
+}
+  }
+}
+  }
+
+  if (const auto *DC = dyn_cast(D))
+for (const Decl *D : DC->decls())
+  handleDecl(D);
+}
+
+class MapFunctionNamesAction : public ASTFrontendAction {
+protected:
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ llvm::StringRef) {
+std::unique_ptr PFC(
+new MapFunctionNamesConsumer(CI.getASTContext()));
+return PFC;
+  }
+};
+
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+int main(int argc, const char **argv) {
+  // Print a stack trace if we signal out.
+  sys::PrintStackTraceOnErrorSignal(argv[0], false);
+  PrettyStackTraceProgram X(argc, argv);
+
+  const char *Overview = "\nThis tool collects the USR name and location "
+ "of all functions definitions in the source files "
+ "(excluding headers).\n";
+  CommonOptionsParser OptionsParser(argc, argv, ClangFnMapGenCategory,
+cl::ZeroOrMore, Overview);
+
+  ClangTool Tool(OptionsParser.getCompilations(),
+ OptionsParser.getSourcePathList());
+  Tool.run(newFrontendActionFactory().get());
+  return 0;
+}
Index: tools/clang-func-mapping/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-func-mapping/CMakeLists.txt
@@ -0,0 +1,21 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  asmparser
+  support
+  mc

[PATCH] D34059: Get the file name for the symbol from the Module, not the SourceManager.

2017-06-22 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 103572.
v.g.vassilev added a comment.

Update test file comment.


https://reviews.llvm.org/D34059

Files:
  lib/CodeGen/CGDeclCXX.cpp
  unittests/CodeGen/CMakeLists.txt
  unittests/CodeGen/IncrementalProcessingTest.cpp

Index: unittests/CodeGen/IncrementalProcessingTest.cpp
===
--- /dev/null
+++ unittests/CodeGen/IncrementalProcessingTest.cpp
@@ -0,0 +1,174 @@
+//=== unittests/CodeGen/IncrementalProcessingTest.cpp - IncrementalCodeGen ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+
+#include 
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Incremental processing produces several modules, all using the same "main
+// file". Make sure CodeGen can cope with that, e.g. for static initializers.
+const char TestProgram1[] =
+"extern \"C\" int funcForProg1() { return 17; }\n"
+"struct EmitCXXGlobalInitFunc1 {\n"
+"   EmitCXXGlobalInitFunc1() {}\n"
+"} test1;";
+
+const char TestProgram2[] =
+"extern \"C\" int funcForProg2() { return 42; }\n"
+"struct EmitCXXGlobalInitFunc2 {\n"
+"   EmitCXXGlobalInitFunc2() {}\n"
+"} test2;";
+
+
+/// An incremental version of ParseAST().
+static std::unique_ptr
+IncrementalParseAST(CompilerInstance& CI, Parser& P,
+CodeGenerator& CG, const char* code) {
+  static int counter = 0;
+  struct IncreaseCounterOnRet {
+~IncreaseCounterOnRet() {
+  ++counter;
+}
+  } ICOR;
+
+  Sema& S = CI.getSema();
+  clang::SourceManager &SM = S.getSourceManager();
+  if (!code) {
+// Main file
+SM.setMainFileID(SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(""), clang::SrcMgr::C_User));
+
+S.getPreprocessor().EnterMainSourceFile();
+P.Initialize();
+  } else {
+FileID FID = SM.createFileID(
+llvm::MemoryBuffer::getMemBuffer(code), clang::SrcMgr::C_User);
+SourceLocation MainStartLoc = SM.getLocForStartOfFile(SM.getMainFileID());
+SourceLocation InclLoc = MainStartLoc.getLocWithOffset(counter);
+S.getPreprocessor().EnterSourceFile(FID, 0, InclLoc);
+  }
+
+  ExternalASTSource *External = S.getASTContext().getExternalSource();
+  if (External)
+External->StartTranslationUnit(&CG);
+
+  Parser::DeclGroupPtrTy ADecl;
+  for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF;
+   AtEOF = P.ParseTopLevelDecl(ADecl)) {
+// If we got a null return and something *was* parsed, ignore it.  This
+// is due to a top-level semicolon, an action override, or a parse error
+// skipping something.
+if (ADecl && !CG.HandleTopLevelDecl(ADecl.get()))
+  return false;
+  }
+
+  // Process any TopLevelDecls generated by #pragma weak.
+  for (Decl *D : S.WeakTopLevelDecls())
+CG.HandleTopLevelDecl(DeclGroupRef(D));
+
+  CG.HandleTranslationUnit(S.getASTContext());
+
+  std::unique_ptr M(CG.ReleaseModule());
+  // Switch to next module.
+  CG.StartModule("incremental-module-" + std::to_string(counter),
+ M->getContext(), CI.getCodeGenOpts());
+  return M;
+}
+
+const Function* getGlobalInit(llvm::Module& M) {
+  for (const auto& Func: M)
+if (Func.hasName() && Func.getName().startswith("_GLOBAL__sub_I_"))
+  return &Func;
+
+  return nullptr;
+}
+
+TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
+LLVMContext Context;
+CompilerInstance compiler;
+
+compiler.createDiagnostics();
+compiler.getLangOpts().CPlusPlus = 1;
+compiler.getLangOpts().CPlusPlus11 = 1;
+
+compiler.getTargetOpts().Triple = llvm::Triple::normalize(
+llvm::sys::getProcessTriple());
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+  compiler.getDiagnostics(),
+  std::make_shared(
+compiler.getTargetOpts(;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+compiler.getPreprocessor().enableIncrementalProcessing();
+
+compiler.createASTContext();
+
+CodeGenerator* CG =
+CreateLLVMCodeGen(
+compiler.getDiagnostics(),
+"main-module",
+compiler.getHeaderSearchOpts(),
+compiler.ge

[PATCH] D34513: [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-22 Thread Peter Smith via Phabricator via cfe-commits
peter.smith created this revision.

https://reviews.llvm.org/D31709 [NFC] Refactor DiagnosticRenderer to use 
FullSourceLoc was committed in r305684 and reverted in 305688 as clang-tidy and 
clang-query failed to build. This change updates the extra tools to use the new 
interface.

With this change https://reviews.llvm.org/D31709 can be recommitted


https://reviews.llvm.org/D34513

Files:
  clang-query/Query.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp

Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -36,10 +36,9 @@
   : DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {}
 
 protected:
-  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level, StringRef Message,
  ArrayRef Ranges,
- const SourceManager *SM,
  DiagOrStoredDiag Info) override {
 // Remove check name from the message.
 // FIXME: Remove this once there's a better way to pass check names than
@@ -49,35 +48,35 @@
 if (Message.endswith(CheckNameInMessage))
   Message = Message.substr(0, Message.size() - CheckNameInMessage.size());
 
-auto TidyMessage = Loc.isValid()
-   ? tooling::DiagnosticMessage(Message, *SM, Loc)
-   : tooling::DiagnosticMessage(Message);
+auto TidyMessage =
+Loc.isValid()
+? tooling::DiagnosticMessage(Message, Loc.getManager(), Loc)
+: tooling::DiagnosticMessage(Message);
 if (Level == DiagnosticsEngine::Note) {
   Error.Notes.push_back(TidyMessage);
   return;
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic message");
 Error.Message = TidyMessage;
   }
 
-  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level,
- ArrayRef Ranges,
- const SourceManager &SM) override {}
+ ArrayRef Ranges) override {}
 
-  void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level,
+  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
SmallVectorImpl &Ranges,
-   ArrayRef Hints,
-   const SourceManager &SM) override {
+   ArrayRef Hints) override {
 assert(Loc.isValid());
 for (const auto &FixIt : Hints) {
   CharSourceRange Range = FixIt.RemoveRange;
   assert(Range.getBegin().isValid() && Range.getEnd().isValid() &&
  "Invalid range in the fix-it hint.");
   assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
  "Only file locations supported in fix-it hints.");
 
-  tooling::Replacement Replacement(SM, Range, FixIt.CodeToInsert);
+  tooling::Replacement Replacement(Loc.getManager(), Range,
+   FixIt.CodeToInsert);
   llvm::Error Err = Error.Fix[Replacement.getFilePath()].add(Replacement);
   // FIXME: better error handling (at least, don't let other replacements be
   // applied).
@@ -89,16 +88,13 @@
 }
   }
 
-  void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc,
-   const SourceManager &SM) override {}
+  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override {}
 
-  void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
-  StringRef ModuleName,
-  const SourceManager &SM) override {}
+  void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override {}
 
-  void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc,
-  StringRef ModuleName,
-  const SourceManager &SM) override {}
+  void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override {}
 
   void endDiagnostic(DiagOrStoredDiag D,
  DiagnosticsEngine::Level Level) override {
@@ -419,11 +415,12 @@
   Errors.back());
   SmallString<100> Message;
   Info.FormatDiagnostic(Message);
-  SourceManager *Sources = nullptr;
-  if (Info.hasSourceManager())
-Sources = &Info.getSourceManager();
-  Converter.emitDiagnostic(Info.getLocation(), DiagLevel, Message,
-   Info.getRanges(), Info.getFixItHints(), Sources);
+  FullSourceLoc Loc =
+  (Info.getLocation().isInvalid())
+  ? FullSourceLoc()
+  : FullSourceLoc(Info.getLocation(), Info.getSourceManag

[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-06-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Some of the CTU related analyzer independent parts are being factored out.
The review is ongoing here: https://reviews.llvm.org/D34512

Another small and independent part is under review here: 
https://reviews.llvm.org/D34506


https://reviews.llvm.org/D30691



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


[PATCH] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

2017-06-22 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

General direction looks good.

I think in addition to integration tests through the static analyzer, we should 
still have unit tests.




Comment at: include/clang/Tooling/CrossTranslationUnit.h:47
+
+  const FunctionDecl *getCTUDefinition(const FunctionDecl *FD, StringRef 
CTUDir,
+   StringRef IndexName);

I'd just spell out Cross & s/CTUDIR/IndexDir/ perhaps? (if CTUDir is to contain 
the indices)
I think as this is the major API entry point, a comment that explains the 
meaning of the arguments and how to use them would be nice.




https://reviews.llvm.org/D34512



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


[PATCH] D34506: Relax an assert in the comparison of source locations

2017-06-22 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I don't think it is a good idea to make this function non-transitive.


Repository:
  rL LLVM

https://reviews.llvm.org/D34506



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-06-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Regarding serializing vs not serializing and now vs later.

1. I think we eventually need to provide a reasonable default approach 
presented to the user. This approach shouldn't be hurting the user dramatically 
in any sense. Because //serializing// hurts the user's disk space dramatically, 
and //not-serializing// may be slower and a bit more memory-intensive but isn't 
too bad in all senses, out of these two options //not-serializing// is 
definitely preferable as a default approach.

2. Later we should definitely consider the alternative approaches that 
serialize only some ASTs, with the hope that one of them would turn out to be a 
better default approach.

3. From 2. it follows that for now it's better to keep both approaches around - 
as we believe that the ideal approach may be a combination of the two. 
Therefore it doesn't really matter in what order they land.

tl;dr: I propose to land serialization-based approach first, then land 
non-serialization-based approach later and make it default, then consider 
taking the best of the two and making it a new default.


https://reviews.llvm.org/D30691



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


[PATCH] D34514: [mips] Enable IAS by default for Android 64-bit MIPS target (N64)

2017-06-22 Thread Petar Jovanovic via Phabricator via cfe-commits
petarj created this revision.
Herald added subscribers: arichardson, srhines.

IAS is already used for MIPS64 in majority of Android projects.
Android MIPS64 uses N64 ABI. Set IAS as a default now.


Repository:
  rL LLVM

https://reviews.llvm.org/D34514

Files:
  lib/Driver/ToolChains/Gnu.cpp


Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2319,9 +2319,10 @@
 return true;
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:
-// Enabled for Debian mips64/mips64el only. Other targets are unable to
-// distinguish N32 from N64.
-if (getTriple().getEnvironment() == llvm::Triple::GNUABI64)
+// Enabled for Debian mips64/mips64el and Android (uses N64 ABI).
+// Other targets are unable to distinguish N32 from N64.
+if (getTriple().getEnvironment() == llvm::Triple::GNUABI64 ||
+getTriple().isAndroid())
   return true;
 return false;
   default:


Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2319,9 +2319,10 @@
 return true;
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:
-// Enabled for Debian mips64/mips64el only. Other targets are unable to
-// distinguish N32 from N64.
-if (getTriple().getEnvironment() == llvm::Triple::GNUABI64)
+// Enabled for Debian mips64/mips64el and Android (uses N64 ABI).
+// Other targets are unable to distinguish N32 from N64.
+if (getTriple().getEnvironment() == llvm::Triple::GNUABI64 ||
+getTriple().isAndroid())
   return true;
 return false;
   default:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34264: Introduce -Wunguarded-availability-new, which is like -Wunguarded-availability, except that it's enabled by default for new deployment targets

2017-06-22 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 103577.
arphaman added a comment.

Update the logic for `-Wunguarded-availability -Wno-unguarded-availability-new` 
so that it only warns for the old APIs.


Repository:
  rL LLVM

https://reviews.llvm.org/D34264

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/SemaObjC/unguarded-availability-new.m

Index: test/SemaObjC/unguarded-availability-new.m
===
--- /dev/null
+++ test/SemaObjC/unguarded-availability-new.m
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability-new -DNO_WARNING -fblocks -fsyntax-only -verify %s
+
+// unguarded-availability implies unguarded-availability-new:
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.11 -Wunguarded-availability -Wno-unguarded-availability-new -DNO_WARNING -DWARN_PREV -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -DNO_WARNING  -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-ios11 -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.12 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios10.3 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos11 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DTVOS -triple x86_64-apple-tvos10 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos4 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DWATCHOS -triple i386-apple-watchos3 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s
+
+#ifdef MAC
+#define PLATFORM macos
+#define NEXT 10.14
+
+#define AVAILABLE_PREV __attribute__((availability(macos, introduced = 10.12)))
+#define AVAILABLE_CURRENT __attribute__((availability(macos, introduced = 10.13)))
+#define AVAILABLE_NEXT __attribute__((availability(macos, introduced = 10.14)))
+#endif
+
+#ifdef IOS
+#define PLATFORM ios
+#define NEXT 12
+
+#define AVAILABLE_PREV __attribute__((availability(ios, introduced = 10)))
+#define AVAILABLE_CURRENT __attribute__((availability(ios, introduced = 11)))
+#define AVAILABLE_NEXT __attribute__((availability(ios, introduced = 12)))
+#endif
+
+#ifdef TVOS
+#define PLATFORM tvos
+#define NEXT 13
+
+#define AVAILABLE_PREV __attribute__((availability(tvos, introduced = 10)))
+#define AVAILABLE_CURRENT __attribute__((availability(tvos, introduced = 11)))
+#define AVAILABLE_NEXT __attribute__((availability(tvos, introduced = 13)))
+#endif
+
+#ifdef WATCHOS
+#define PLATFORM watchos
+#define NEXT 5
+
+#define AVAILABLE_PREV __attribute__((availability(watchos, introduced = 3)))
+#define AVAILABLE_CURRENT __attribute__((availability(watchos, introduced = 4)))
+#define AVAILABLE_NEXT __attribute__((availability(watchos, introduced = 5)))
+#endif
+
+void previouslyAvailable() AVAILABLE_PREV;
+#ifdef WARN_PREV
+  // expected-note@-2 {{'previouslyAvailable' has been explicitly marked partial here}}
+#endif
+void currentlyAvailable() AVAILABLE_CURRENT;
+#ifdef WARN_CURRENT
+  // expected-note@-2 {{'currentlyAvailable' has been explicitly marked partial here}}
+#endif
+voi

[PATCH] D34513: [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-22 Thread Christof Douma via Phabricator via cfe-commits
christof added a comment.

This looks good to me. But since I have never touch this code, I'll wait a bit 
till accepting this for others to have a say.


https://reviews.llvm.org/D34513



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


[PATCH] D34513: [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-22 Thread Christof Douma via Phabricator via cfe-commits
christof added a reviewer: alexfh.
christof added a comment.

Added Alexander as he seems to have touched clang-tidy recently.


https://reviews.llvm.org/D34513



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


[PATCH] D34264: Introduce -Wunguarded-availability-new, which is like -Wunguarded-availability, except that it's enabled by default for new deployment targets

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

LGTM, thanks for working on this!


Repository:
  rL LLVM

https://reviews.llvm.org/D34264



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


[PATCH] D32642: [Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks

2017-06-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D32642#787913, @baloghadamsoftware wrote:

> I tried `SValBuilder::evalBinOp()` first but it did not help too much. It 
> could decide only if I compared the same conjured symbols or different ones, 
> but nothing more. It always gave me `UnknownVal`. Even if comparing ${conj_X} 
> == ${conj_X} + n where n was a concrete integer. So I have to compare the 
> symbol part and the concrete integer part separately.


In any case, it's not right to have two `SValBuilder`s. Your code simplifies 
symbolic expressions of numeric types, `SValBuilder` does the same thing, 
there's no need to duplicate. It would be much better to move the functionality 
you need (and already have implemented) directly to `SValBuilder`.

I'm sure that simplification `(($x + N) + M) ~> ($x + (M + N))` is already 
working in `SValBuilder`. I think it's totally worth it to add `(($x + M) == 
($x + N)) ~> (M == N)` and `(($x + M) - ($x + N)) ~> M - N` into `SValBuilder` 
in case it's not already there, because the whole analyzer would immediately 
benefit from that, not just your checker.

Generally, i totally encourage you to modify the analyzer's core to fit your 
purposes, even if to reduce code duplication. It's not worth it to teach the 
core constraint manager how to work with user-defined types such as iterators, 
but it's definitely worth it to teach `SValBuilder` how to handle numeric-type 
symbols better.

In https://reviews.llvm.org/D32642#787913, @baloghadamsoftware wrote:

> If Z3 constraint solver is accepted and will be the default constraint 
> manager, then I can somewhat simplify my code. That patch is under review for 
> long and I am not sure whether it will be the default ever.


I don't expect Z3 to be on by default soon, however i'm only pointing to the 
changes in the mainline `SValBuilder` in that patch. Z3 doesn't replace 
`SValBuilder`, it only replaces the constraint manager. However, `SValBuilder` 
needs to provide accurate `SVal`s to Z3, which means that a lot of 
`UnknownVal`s need to go away. We're discussing if they should go away 
completely even if Z3 isn't on.

In https://reviews.llvm.org/D32642#787913, @baloghadamsoftware wrote:

> Waiting is not an option for us since we are a bit delayed with this checker. 
> I have to bring them out of alpha until the end of the year.


While moving things out of alpha is pretty much the primary goal of any work we 
do, sacrificing quality defeats that purpose. We can only afford to enable 
things by default when we know they're ready. This checker is research-heavy 
and as such hard to plan. We need to understand the decisions and trade-offs 
that you made.


https://reviews.llvm.org/D32642



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


Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Joerg Sonnenberger via cfe-commits
On Mon, Jun 12, 2017 at 09:03:10PM +0200, Joerg Sonnenberger wrote:
> On Thu, Jun 01, 2017 at 05:58:41PM -0700, Akira Hatanaka wrote:
> > It crashes when there is an anonymous ivar of a bitfield type.
> > 
> > @interface FormatScanner {
> >   int : 1;
> > }
> > @end
> > 
> > @implementation FormatScanner
> > @end
> > 
> > I'm not sure if the code above is valid or not, but out of curiosity,
> > why would you want an anonymous bitfield variable?
> 
> It's a reduced test case. The original test case has a variable name in
> it.

Ping?

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


[PATCH] D34304: Allow CompilerInvocations to generate .d files.

2017-06-22 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

In https://reviews.llvm.org/D34304#787699, @klimek wrote:

> I mean, arguments need to be adjusted before converting to ArgStringList and 
> calling newInvocation? I'm not sure I fully understand the problem, can you 
> elaborate?


This gets back to why the original patch plumbed the boolean all the way down 
to newInvocation.

newInvocation is the function that actually discards the dependency file 
options--today unconditionally. But there is code that calls newInvocation 
directly (ClangFuzzer is one), without going through a higher-level API. So I 
can't adjust the arguments at a higher level and still preserve the old 
behavior.

Unfortunately, newInvocation's argument list type is incompatible with 
ArgumentAdjusters, so something else will need to be done. What do you 
recommend?


https://reviews.llvm.org/D34304



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-06-22 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 103585.
danielmarjamaki added a comment.

Fix review comments


Repository:
  rL LLVM

https://reviews.llvm.org/D30295

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
  lib/StaticAnalyzer/Core/CheckerContext.cpp
  test/Analysis/bitwise-ops.c

Index: test/Analysis/bitwise-ops.c
===
--- test/Analysis/bitwise-ops.c
+++ test/Analysis/bitwise-ops.c
@@ -22,11 +22,25 @@
   case 1:
 return 0ULL << 63; // no-warning
   case 2:
-return 0ULL << 64; // expected-warning{{The result of the '<<' expression is undefined}}
+return 0ULL << 64; // expected-warning{{The result of the left shift is undefined due to shifting by 64, which is larger than the width of type 'unsigned long long'}}
   case 3:
-return 0ULL << 65; // expected-warning{{The result of the '<<' expression is undefined}}
+return 0ULL << 65; // expected-warning{{The result of the left shift is undefined due to shifting by 65, which is larger than the width of type 'unsigned long long'}}
 
   default:
 return 0;
   }
-}
\ No newline at end of file
+}
+
+int testOverflowShift(int a) {
+  if (a == 323) {
+return 1 << a; // expected-warning{{The result of the left shift is undefined due to shifting by 323, which is larger than the width of type 'int'}}
+  }
+  return 0;
+}
+
+int testNegativeShift(int a) {
+  if (a == -5) {
+return 1 << a; // expected-warning{{The result of the left shift is undefined because the right operand is negative}}
+  }
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/CheckerContext.cpp
===
--- lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -99,3 +99,35 @@
   return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOpts());
 }
 
+/// Evaluate comparison and return true if it's known that condition is true
+static bool evalComparison(SVal LHSVal, BinaryOperatorKind ComparisonOp,
+   SVal RHSVal, ProgramStateRef State) {
+  if (LHSVal.isUnknownOrUndef())
+return false;
+  ProgramStateManager &Mgr = State->getStateManager();
+  if (!LHSVal.getAs()) {
+LHSVal = Mgr.getStoreManager().getBinding(State->getStore(),
+  LHSVal.castAs());
+if (LHSVal.isUnknownOrUndef() || !LHSVal.getAs())
+  return false;
+  }
+
+  SValBuilder &Bldr = Mgr.getSValBuilder();
+  SVal Eval = Bldr.evalBinOp(State, ComparisonOp, LHSVal, RHSVal,
+ Bldr.getConditionType());
+  if (Eval.isUnknownOrUndef())
+return false;
+  ProgramStateRef StTrue, StFalse;
+  std::tie(StTrue, StFalse) = State->assume(Eval.castAs());
+  return StTrue && !StFalse;
+}
+
+bool CheckerContext::isGreaterOrEqual(const Expr *E, unsigned long long Val) {
+  DefinedSVal V = getSValBuilder().makeIntVal(Val, getASTContext().LongLongTy);
+  return evalComparison(getSVal(E), BO_GE, V, getState());
+}
+
+bool CheckerContext::isNegative(const Expr *E) {
+  DefinedSVal V = getSValBuilder().makeIntVal(0, false);
+  return evalComparison(getSVal(E), BO_LT, V, getState());
+}
Index: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
@@ -59,6 +59,26 @@
   return StOutBound && !StInBound;
 }
 
+static bool isShiftOverflow(const BinaryOperator *B, CheckerContext &C) {
+  return C.isGreaterOrEqual(
+  B->getRHS(), C.getASTContext().getIntWidth(B->getLHS()->getType()));
+}
+
+static const llvm::APSInt *getConcreteValue(const Expr *E, CheckerContext &C) {
+  SVal V = C.getSVal(E);
+  if (!V.getAs()) {
+ProgramStateRef State = C.getState();
+ProgramStateManager &Mgr = State->getStateManager();
+V = Mgr.getStoreManager().getBinding(State->getStore(), V.castAs());
+  }
+  if (V.getSubKind() == nonloc::ConcreteIntKind) {
+const auto &CI = V.castAs().castAs();
+const llvm::APSInt &I = CI.getValue();
+return &I;
+  }
+  return nullptr;
+}
+
 void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
CheckerContext &C) const {
   ProgramStateRef state = C.getState();
@@ -97,18 +117,44 @@
 }
 
 if (Ex) {
-  OS << "The " << (isLeft ? "left" : "right")
- << " operand of '"
+  OS << "The " << (isLeft ? "left" : "right") << " operand of '"
  << BinaryOperator::getOpcodeStr(B->getOpcode())
  << "' is a garbage value";
   if (isArrayIndexOutOfBounds(C, Ex))
 OS << " due to array index out of bounds";
-}
-else {
+} else {
   // Neither operand was undefined, but the result is undefined.
-  OS << "The result of the '"

[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-06-22 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

Great! Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499



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


[PATCH] D30326: [MS-ABI] Allow #pragma section to choose for ZI data

2017-06-22 Thread Javed Absar via Phabricator via cfe-commits
javed.absar abandoned this revision.
javed.absar added a comment.

Abandoning as there is a separate pragma clang section implementation now.


https://reviews.llvm.org/D30326



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-06-22 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki marked 4 inline comments as done.
danielmarjamaki added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:126
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to shift count >= width of type";
+  } else {

zaks.anna wrote:
> It's best not to use ">=" in diagnostic messages.
> Suggestions: "due to shift count >= width of type" ->
> - "due to shifting by a value larger than the width of type"
> - "due to shifting by 5, which is larger than the width of type 'int'" // 
> Providing the exact value and the type would be very useful and this 
> information is readily available to us. Note that the users might not see the 
> type or the value because of macros and such.
I used "due to shifting by 5, which is larger than the width of type 'int'"

However I did not see an easy way to show the exact value. So I added 
getConcreteValue(). Maybe you have a better suggestion. If it's a ConcreteInt I 
show the exact value, but if it's some range etc then I write "due to shifting 
by a value that is larger..." instead.

The message "due to shifting by 64, which is larger than the width of type 
'unsigned long long'" is a bit weird imho. Because 64 is not larger than the 
width. Not sure how this can be rephrazed better though.


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


r306033 - [Sema] Add -Wunguarded-availability-new

2017-06-22 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Jun 22 12:02:24 2017
New Revision: 306033

URL: http://llvm.org/viewvc/llvm-project?rev=306033&view=rev
Log:
[Sema] Add -Wunguarded-availability-new

The new compiler warning -Wunguarded-availability-new is a subset of
-Wunguarded-availability. It is on by default. It only warns about uses of APIs
that have been introduced in macOS >= 10.13, iOS >= 11, watchOS >= 4 and
tvOS >= 11. We decided to use this kind of solution as we didn't want to turn
on -Wunguarded-availability by default, because we didn't want our users to get
warnings about uses of old APIs in their existing projects.

rdar://31054725

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

Added:
cfe/trunk/test/SemaObjC/unguarded-availability-new.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=306033&r1=306032&r2=306033&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jun 22 12:02:24 2017
@@ -98,7 +98,9 @@ def CXX11CompatDeprecatedWritableStr :
 def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
-def UnguardedAvailability : DiagGroup<"unguarded-availability">;
+def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
+def UnguardedAvailability : DiagGroup<"unguarded-availability",
+  [UnguardedAvailabilityNew]>;
 // partial-availability is an alias of unguarded-availability.
 def : DiagGroup<"partial-availability", [UnguardedAvailability]>;
 def DeprecatedDynamicExceptionSpec

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=306033&r1=306032&r2=306033&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun 22 12:02:24 
2017
@@ -2870,8 +2870,13 @@ def note_protocol_method : Note<
 def warn_unguarded_availability :
   Warning<"%0 is only available on %1 %2 or newer">,
   InGroup, DefaultIgnore;
+def warn_unguarded_availability_new :
+  Warning,
+  InGroup;
 def warn_partial_availability : Warning<"%0 is only available conditionally">,
 InGroup, DefaultIgnore;
+def warn_partial_availability_new : Warning,
+  InGroup;
 def note_partial_availability_silence : Note<
   "explicitly redeclare %0 to silence this warning">;
 def note_unguarded_available_silence : Note<
@@ -2879,9 +2884,14 @@ def note_unguarded_available_silence : N
   " this warning">;
 def warn_partial_message : Warning<"%0 is partial: %1">,
 InGroup, DefaultIgnore;
+def warn_partial_message_new : Warning,
+  InGroup;
 def warn_partial_fwdclass_message : Warning<
 "%0 may be partial because the receiver type is unknown">,
 InGroup, DefaultIgnore;
+def warn_partial_fwdclass_message_new :
+  Warning,
+  InGroup;
 def warn_at_available_unchecked_use : Warning<
   "%select{@available|__builtin_available}0 does not guard availability here; "
   "use if (%select{@available|__builtin_available}0) instead">,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=306033&r1=306032&r2=306033&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jun 22 12:02:24 2017
@@ -6903,6 +6903,32 @@ static bool ShouldDiagnoseAvailabilityIn
   return true;
 }
 
+static bool
+shouldDiagnoseAvailabilityByDefault(const ASTContext &Context,
+const VersionTuple &DeploymentVersion,
+const VersionTuple &DeclVersion) {
+  const auto &Triple = Context.getTargetInfo().getTriple();
+  VersionTuple ForceAvailabilityFromVersion;
+  switch (Triple.getOS()) {
+  case llvm::Triple::IOS:
+  case llvm::Triple::TvOS:
+ForceAvailabilityFromVersion = VersionTuple(/*Major=*/11);
+break;
+  case llvm::Triple::WatchOS:
+ForceAvailabilityFromVersion = VersionTuple(/*Major=*/4);
+break;
+  case llvm::Triple::Darwin:
+  case llvm::Triple::MacOSX:
+ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
+break;
+  default:
+// New targets should always warn about availability.
+return Triple.getVendor() == llvm::Triple::Apple;
+  }
+  return DeploymentVersion >= ForceAvai

[PATCH] D34264: Introduce -Wunguarded-availability-new, which is like -Wunguarded-availability, except that it's enabled by default for new deployment targets

2017-06-22 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306033: [Sema] Add -Wunguarded-availability-new (authored by 
arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D34264?vs=103577&id=103598#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34264

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/SemaObjC/unguarded-availability-new.m

Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -98,7 +98,9 @@
 def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
-def UnguardedAvailability : DiagGroup<"unguarded-availability">;
+def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
+def UnguardedAvailability : DiagGroup<"unguarded-availability",
+  [UnguardedAvailabilityNew]>;
 // partial-availability is an alias of unguarded-availability.
 def : DiagGroup<"partial-availability", [UnguardedAvailability]>;
 def DeprecatedDynamicExceptionSpec
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2870,18 +2870,28 @@
 def warn_unguarded_availability :
   Warning<"%0 is only available on %1 %2 or newer">,
   InGroup, DefaultIgnore;
+def warn_unguarded_availability_new :
+  Warning,
+  InGroup;
 def warn_partial_availability : Warning<"%0 is only available conditionally">,
 InGroup, DefaultIgnore;
+def warn_partial_availability_new : Warning,
+  InGroup;
 def note_partial_availability_silence : Note<
   "explicitly redeclare %0 to silence this warning">;
 def note_unguarded_available_silence : Note<
   "enclose %0 in %select{an @available|a __builtin_available}1 check to silence"
   " this warning">;
 def warn_partial_message : Warning<"%0 is partial: %1">,
 InGroup, DefaultIgnore;
+def warn_partial_message_new : Warning,
+  InGroup;
 def warn_partial_fwdclass_message : Warning<
 "%0 may be partial because the receiver type is unknown">,
 InGroup, DefaultIgnore;
+def warn_partial_fwdclass_message_new :
+  Warning,
+  InGroup;
 def warn_at_available_unchecked_use : Warning<
   "%select{@available|__builtin_available}0 does not guard availability here; "
   "use if (%select{@available|__builtin_available}0) instead">,
Index: cfe/trunk/test/SemaObjC/unguarded-availability-new.m
===
--- cfe/trunk/test/SemaObjC/unguarded-availability-new.m
+++ cfe/trunk/test/SemaObjC/unguarded-availability-new.m
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DMAC -triple x86_64-apple-macosx10.13 -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability-new -DNO_WARNING -fblocks -fsyntax-only -verify %s
+
+// unguarded-availability implies unguarded-availability-new:
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.11 -Wunguarded-availability -Wno-unguarded-availability-new -DNO_WARNING -DWARN_PREV -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -DNO_WARNING  -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -Wno-unguarded-availability -Wunguarded-availability-new -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.13 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-ios11 -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DMAC -triple x86_64-apple-macosx10.12 -DWARN_CURRENT -fblocks -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_CURRENT -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios11 -D TEST_FUNC_NEXT -DNO_WARNING -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DIOS -triple x86_64-apple-ios10.3 -DWARN

[PATCH] D34102: [analyzer] Add portability package for the checkers.

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

This just supports the statement that this particular check should not go under 
unix. I understand that it will be inconsistent with the name of the malloc 
checker, which we probably should not change as people might be relying on the 
package names. I think it's better to have inconsistency than having checks 
applicable to windows in a package named portability.unix. If there will be 
checks that need to be in portability and only used for unix, we could create 
that sub-package later on.


https://reviews.llvm.org/D34102



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


[PATCH] D34469: Use vfs::FileSystem in ASTUnit when creating CompilerInvocation.

2017-06-22 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a reviewer: bruno.
bruno added a comment.

Any reason why this doesn't contain a testcase?


https://reviews.llvm.org/D34469



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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

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

In https://reviews.llvm.org/D34299#787795, @arphaman wrote:

> It looks like if we have a function without the `return` (like the sample 
> below), we will pass in a `0` as the location pointer. This will prevent a 
> report of a runtime error as your compiler-rt change ignores the location 
> pointers that are `nil`. Is this a bug or is this the intended behaviour?
>
>   int *_Nonnull nonnull_retval1(int *p) {
>   }
>


This is the intended behavior (I'll add a test). Users should not see a "null 
return value" diagnostic here. There is another check, -fsanitize=return, which 
can catch this issue.

@filcab --

> Splitting the attrloc from the useloc might make sense since we would be able 
> to emit attrloc just once. But I don't see why we need to store/load those 
> pointers in runtime instead of just caching the Constant* in CodeGenFunction.

The source locations aren't constants. The ubsan runtime uses a bit inside of 
source location structures as a flag. When an issue is diagnosed at a 
particular source location, that bit is atomically set. This is how ubsan 
implements issue deduplication.

> I'd also like to have some asserts and explicit resets to nullptr after use 
> on the ReturnLocation variable, if possible.

Resetting Address fields in CodeGenFunction doesn't appear to be an established 
practice. Could you explain what this would be in aid of?


https://reviews.llvm.org/D34299



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


Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Akira Hatanaka via cfe-commits
Do you want the same encoding for the bitfield “int : 1” you saw before 
r297792, which is just “i"?

The encoding for bitfield is normally bN where N is the number of bits, but the 
comment in function EncodeBitField says GNU runtime encodes it differently.

> On Jun 22, 2017, at 8:30 AM, Joerg Sonnenberger  wrote:
> 
> On Mon, Jun 12, 2017 at 09:03:10PM +0200, Joerg Sonnenberger wrote:
>> On Thu, Jun 01, 2017 at 05:58:41PM -0700, Akira Hatanaka wrote:
>>> It crashes when there is an anonymous ivar of a bitfield type.
>>> 
>>> @interface FormatScanner {
>>>  int : 1;
>>> }
>>> @end
>>> 
>>> @implementation FormatScanner
>>> @end
>>> 
>>> I'm not sure if the code above is valid or not, but out of curiosity,
>>> why would you want an anonymous bitfield variable?
>> 
>> It's a reduced test case. The original test case has a variable name in
>> it.
> 
> Ping?
> 
> Joerg

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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

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

In https://reviews.llvm.org/D34299#788152, @vsk wrote:

> In https://reviews.llvm.org/D34299#787795, @arphaman wrote:
>
> > It looks like if we have a function without the `return` (like the sample 
> > below), we will pass in a `0` as the location pointer. This will prevent a 
> > report of a runtime error as your compiler-rt change ignores the location 
> > pointers that are `nil`. Is this a bug or is this the intended behaviour?
> >
> >   int *_Nonnull nonnull_retval1(int *p) {
> >   }
> >
>
>
> This is the intended behavior (I'll add a test). Users should not see a "null 
> return value" diagnostic here. There is another check, -fsanitize=return, 
> which can catch this issue.


Ok. However, when the source is not using C++, the check for 
`-fsanitize=return` won't be emitted. So we will end up with a call to 
`__ubsan_handle_nullability_return_abort` without a location, which won't 
report a diagnostic, but the program will crash because compiler-rt will call 
`abort`. This seems like a regression, since previously in C mode this 
diagnostic was reported.

> @filcab --
> 
>> Splitting the attrloc from the useloc might make sense since we would be 
>> able to emit attrloc just once. But I don't see why we need to store/load 
>> those pointers in runtime instead of just caching the Constant* in 
>> CodeGenFunction.
> 
> The source locations aren't constants. The ubsan runtime uses a bit inside of 
> source location structures as a flag. When an issue is diagnosed at a 
> particular source location, that bit is atomically set. This is how ubsan 
> implements issue deduplication.
> 
>> I'd also like to have some asserts and explicit resets to nullptr after use 
>> on the ReturnLocation variable, if possible.
> 
> Resetting Address fields in CodeGenFunction doesn't appear to be an 
> established practice. Could you explain what this would be in aid of?


https://reviews.llvm.org/D34299



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


[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <= p" (PR33430)

2017-06-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 103606.
vsk added a comment.

Fix a typo introduced in emitArraySubscriptGEP while refactoring 
/*isSubtraction=false*/ to CodeGenFunction::NotSubtraction, and add CHECK lines 
which catch the issue.


https://reviews.llvm.org/D34121

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-pointer-overflow.m

Index: test/CodeGen/ubsan-pointer-overflow.m
===
--- test/CodeGen/ubsan-pointer-overflow.m
+++ test/CodeGen/ubsan-pointer-overflow.m
@@ -10,16 +10,20 @@
   ++p;
 
   // CHECK: ptrtoint i8* {{.*}} to i64, !nosanitize
-  // CHECK-NEXT: add i64 {{.*}}, -1, !nosanitize
-  // CHECK: select i1 false{{.*}}, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 {{.*}}, -1, !nosanitize
+  // CHECK: [[NEGVALID:%.*]] = icmp ule i64 [[COMPGEP]], {{.*}}, !nosanitize
+  // CHECK-NOT: select
+  // CHECK: br i1 [[NEGVALID]]{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   --p;
 
+  // CHECK: icmp uge i64
   // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p++;
 
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p--;
 }
@@ -64,7 +68,8 @@
 
   // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
   // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p - i;
 }
@@ -121,8 +126,10 @@
 
 // CHECK-LABEL: define void @pointer_array_unsigned_indices
 void pointer_array_unsigned_indices(int **arr, unsigned k) {
+  // CHECK: icmp uge
   // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  // CHECK: icmp uge
   // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   arr[k][k];
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -3580,12 +3580,19 @@
   /// nonnull, if \p LHS is marked _Nonnull.
   void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc);
 
+  /// An enumeration which makes it easier to specify whether or not an
+  /// operation is a subtraction.
+  enum { NotSubtraction = false, IsSubtraction = true };
+
   /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
   /// detect undefined behavior when the pointer overflow sanitizer is enabled.
   /// \p SignedIndices indicates whether any of the GEP indices are signed.
+  /// \p IsSubtraction indicates whether the expression used to form the GEP
+  /// is a subtraction.
   llvm::Value *EmitCheckedInBoundsGEP(llvm::Value *Ptr,
   ArrayRef IdxList,
   bool SignedIndices,
+  bool IsSubtraction,
   SourceLocation Loc,
   const Twine &Name = "");
 
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1851,7 +1851,7 @@
   llvm::Value *input;
 
   int amount = (isInc ? 1 : -1);
-  bool signedIndex = !isInc;
+  bool isSubtraction = !isInc;
 
   if (const AtomicType *atomicTy = type->getAs()) {
 type = atomicTy->getValueType();
@@ -1941,8 +1941,9 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, numElts, "vla.inc");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, numElts, signedIndex,
-   E->getExprLoc(), "vla.inc");
+value = CGF.EmitCheckedInBoundsGEP(
+value, numElts, /*SignedIndices=*/false, isSubtraction,
+E->getExprLoc(), "vla.inc");
 
 // Arithmetic on function pointers (!) is just +-1.
 } else if (type->isFunctionType()) {
@@ -1952,18 +1953,20 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.funcptr");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, amt, signedIndex,
-   E->getExprLoc(), "incdec.funcptr");
+value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
+   isSubtraction, E->getExprLoc(),
+   "incdec.funcptr");
   value = Builder.CreateBitCast(value, input->getType());
 
 // For everything else, we can just do a simple increment.
 } else {
   llvm::Value *amt = Builder.getInt32(amount);
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.ptr");
   else
- 

[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added a project: clang.

When generating the decorated name for a static variable inside a BlockDecl, 
construct a scope for the block invocation function that homes the parameter.  
This allows for arbitrary nesting of the blocks even if the variables are 
shadowed.  Furthermore, using this for the name allows for undname to properly 
undecorated the name for us.  It shows up as the synthetic __block_invocation 
function that the compiler emitted in the local scope.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/msabi-blocks.cpp


Index: test/CodeGenCXX/msabi-blocks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/msabi-blocks.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++11 -fblocks -S 
-emit-llvm -o - %s | FileCheck %s
+
+auto b = ^() {
+  static int i = 0;
+  return ++i;
+};
+
+
+void f() {
+  auto l = ^() {
+static int i = 0;
+return ++i;
+  };
+  auto m = ^() {
+static int i = 0;
+return ++i;
+  };
+  auto n = ^() {
+auto o = ^() {
+  static int i = 0;
+  return ++i;
+};
+  };
+}
+
+template 
+void g() {
+  auto p = ^() {
+static int i = 0;
+return ++i;
+  };
+}
+
+template void g();
+template void g();
+
+// CHECK: @"\01?i@?1??_block_invoke@@YAXPAU__block_literal@@@Z@4HA" = internal
+// CHECK: 
@"\01?i@?1??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" = 
internal
+// CHECK: 
@"\01?i@?1??_block_invoke_2@@YAXPAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" = 
internal
+// CHECK: 
@"\01?i@?1??_block_invoke_3@@YAXPAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA"
 = internal
+// CHECK: 
@"\01?i@?2??_block_invoke_5@@YAXPAU__block_literal_5@@@Z?2???$g@D@@YAXXZ@4HA" = 
linkonce_odr
+// CHECK: 
@"\01?i@?2??_block_invoke_6@@YAXPAU__block_literal_6@@@Z?2???$g@H@@YAXXZ@4HA" = 
linkonce_odr
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -966,16 +966,14 @@
 }

 if (const BlockDecl *BD = dyn_cast(DC)) {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID =
-  Diags.getCustomDiagID(DiagnosticsEngine::Error,
-"cannot mangle a local inside this block yet");
-  Diags.Report(BD->getLocation(), DiagID);
-
-  // FIXME: This is completely, utterly, wrong; see ItaniumMangle
-  // for how this should be done.
-  Out << "__block_invoke" << Context.getBlockId(BD, false);
-  Out << '@';
+  auto Discriminator = Context.getBlockId(BD, false);
+  Out << "?_block_invoke";
+  if (Discriminator)
+Out << '_' << Discriminator;
+  Out << "@@YAXPAU__block_literal";
+  if (Discriminator)
+Out << '_' << Discriminator;
+  Out << "@@@Z";
 } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
   mangleObjCMethodName(Method);
 } else if (isa(DC)) {


Index: test/CodeGenCXX/msabi-blocks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/msabi-blocks.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++11 -fblocks -S -emit-llvm -o - %s | FileCheck %s
+
+auto b = ^() {
+  static int i = 0;
+  return ++i;
+};
+
+
+void f() {
+  auto l = ^() {
+static int i = 0;
+return ++i;
+  };
+  auto m = ^() {
+static int i = 0;
+return ++i;
+  };
+  auto n = ^() {
+auto o = ^() {
+  static int i = 0;
+  return ++i;
+};
+  };
+}
+
+template 
+void g() {
+  auto p = ^() {
+static int i = 0;
+return ++i;
+  };
+}
+
+template void g();
+template void g();
+
+// CHECK: @"\01?i@?1??_block_invoke@@YAXPAU__block_literal@@@Z@4HA" = internal
+// CHECK: @"\01?i@?1??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" = internal
+// CHECK: @"\01?i@?1??_block_invoke_2@@YAXPAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" = internal
+// CHECK: @"\01?i@?1??_block_invoke_3@@YAXPAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA" = internal
+// CHECK: @"\01?i@?2??_block_invoke_5@@YAXPAU__block_literal_5@@@Z?2???$g@D@@YAXXZ@4HA" = linkonce_odr
+// CHECK: @"\01?i@?2??_block_invoke_6@@YAXPAU__block_literal_6@@@Z?2???$g@H@@YAXXZ@4HA" = linkonce_odr
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -966,16 +966,14 @@
 }

 if (const BlockDecl *BD = dyn_cast(DC)) {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID =
-  Diags.getCustomDiagID(DiagnosticsEngine::Error,
-"cannot mangle a local inside this block yet");
-  Diags.Report(BD->getLocation(), DiagID);
-
-  // FI

[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 103613.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

Revised by John's comments.


https://reviews.llvm.org/D33842

Files:
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGen/address-space.c
  test/CodeGen/default-address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Index: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
===
--- test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
+// RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa-amdgiz -DNO_TLS -emit-llvm -o - %s | FileCheck -check-prefixes=AMD,CHECK %s
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
@@ -46,62 +47,82 @@
   wantslist1(std::initializer_list);
   ~wantslist1();
 };
-
-// CHECK: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
-// CHECK: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
+// X86: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
+// X86: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
+// AMD: @_ZGR15globalInitList1_ = internal addrspace(1) constant [3 x i32] [i32 1, i32 2, i32 3]
+// AMD: @globalInitList1 = addrspace(1) global %{{[^ ]+}} { i32* addrspacecast (i32 addrspace(1)* getelementptr inbounds ([3 x i32], [3 x i32] addrspace(1)* @_ZGR15globalInitList1_, i32 0, i32 0) to i32*), i{{32|64}} 3 }
 std::initializer_list globalInitList1 = {1, 2, 3};
 
+#ifndef NO_TLS
 namespace thread_local_global_array {
-  // FIXME: We should be able to constant-evaluate this even though the
-  // initializer is not a constant expression (pointers to thread_local
-  // objects aren't really a problem).
-  //
-  // CHECK: @_ZN25thread_local_global_array1xE = thread_local global
-  // CHECK: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
-  std::initializer_list thread_local x = { 1, 2, 3, 4 };
+// FIXME: We should be able to constant-evaluate this even though the
+// initializer is not a constant expression (pointers to thread_local
+// objects aren't really a problem).
+//
+// X86: @_ZN25thread_local_global_array1xE = thread_local global
+// X86: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
+std::initializer_list thread_local x = {1, 2, 3, 4};
 }
-
-// CHECK: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
-// CHECK: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
-
-// CHECK: @_ZN15partly_constant1kE = global i32 0, align 4
-// CHECK: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
-// CHECK: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
-// CHECK: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
-// CHECK: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
-// CHECK: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
-// CHECK: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
-
-// CHECK: @[[REFTMP1:.*]] = private constant [2 x i32] [i32 42, i32 43], align 4
-// CHECK: @[[REFTMP2:.*]] = private constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
+#endif
+
+// X86: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
+// X86: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
+// AMD: @globalInitList2 = addrspace(1) global %{{[^ ]+}} zeroinitializer
+// AMD: @_ZGR15globalInitList2_ = internal addrspace(1) global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
+
+// X86: @_ZN15partly_constant1kE = global i32 0, align 4
+// X86: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
+// X86: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
+// X86: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
+// X86: @[[PART

Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Joerg Sonnenberger via cfe-commits
On Thu, Jun 22, 2017 at 11:09:48AM -0700, Akira Hatanaka wrote:
> Do you want the same encoding for the bitfield “int : 1” you saw before 
> r297792, which is just “i"?
> 
> The encoding for bitfield is normally bN where N is the number of bits,
> but the comment in function EncodeBitField says GNU runtime encodes it 
> differently.

Sorry, can't answer that. I primarily care about a new clang crash that
didn't exist before, cut I can't answer what the correct behavior should
be.

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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-22 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

Can you please have a test where you define blocks w/ static variables in 
several default arguments of the same function? Also would be good to have this 
in NSDMIs in class definitions.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-22 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Patch is missing context.

You have to use getBlockManglingNumber() for blocks which are externally 
visible; otherwise, the numbers won't be consistent in other translation units.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34526: [clang-tidy] Fix modernize-use-nullptr only warns the first NULL argument.

2017-06-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added a subscriber: xazax.hun.

https://reviews.llvm.org/D34526

Files:
  clang-tidy/modernize/UseNullptrCheck.cpp
  test/clang-tidy/modernize-use-nullptr.cpp


Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -261,3 +261,31 @@
 void IgnoreSubstTemplateType() {
   TemplateClass a(1);
 }
+
+// Test on recognizing multiple NULLs.
+class H {
+public:
+  H(bool);
+};
+
+#define T(expression) H(expression);
+bool h(int *, int *, int * = nullptr);
+void test_multiple_nulls() {
+  T(h(NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(NULL, nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(nullptr, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(nullptr, nullptr));
+  T(h(NULL, NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-3]]:19: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr, nullptr));
+}
+#undef T
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -233,7 +233,7 @@
   allArgUsesValid(C)) {
 replaceWithNullptr(Check, SM, FileLocStart, FileLocEnd);
   }
-  return skipSubTree();
+  return true;
 }
 
 if (SM.isMacroBodyExpansion(StartLoc) && SM.isMacroBodyExpansion(EndLoc)) {


Index: test/clang-tidy/modernize-use-nullptr.cpp
===
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ test/clang-tidy/modernize-use-nullptr.cpp
@@ -261,3 +261,31 @@
 void IgnoreSubstTemplateType() {
   TemplateClass a(1);
 }
+
+// Test on recognizing multiple NULLs.
+class H {
+public:
+  H(bool);
+};
+
+#define T(expression) H(expression);
+bool h(int *, int *, int * = nullptr);
+void test_multiple_nulls() {
+  T(h(NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(NULL, nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(nullptr, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+  T(h(nullptr, nullptr));
+  T(h(NULL, NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-3]]:19: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr, nullptr));
+}
+#undef T
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tidy/modernize/UseNullptrCheck.cpp
@@ -233,7 +233,7 @@
   allArgUsesValid(C)) {
 replaceWithNullptr(Check, SM, FileLocStart, FileLocEnd);
   }
-  return skipSubTree();
+  return true;
 }
 
 if (SM.isMacroBodyExpansion(StartLoc) && SM.isMacroBodyExpansion(EndLoc)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34449: [clang-tidy] Enable constexpr definitions in headers.

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

Have thought this a bit more, I misunderstood your patch previously (sorry for 
that).

I think what you intend to do is to ignore C++17 `inline variables` in headers, 
am I correct?




Comment at: test/clang-tidy/misc-definitions-in-headers.hpp:1
-// RUN: %check_clang_tidy %s misc-definitions-in-headers %t
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
 

hokein wrote:
> The original code should work as `-std=c++11` will be added defaultly by 
> `check_clang_tidy` script.
`constexpr` variables have internal linkage, which should be detected for the 
current check (but the test case is missing this kind of case).

If you want to test `inline` variables, I'd suggest adding a new test file like 
`misc-definitions-in-headers-1z.hpp` which includes cases of inline variables.



Comment at: test/clang-tidy/misc-definitions-in-headers.hpp:180
+class CE {
+  constexpr static int i = 5; // OK: constexpr definition.
+};

hokein wrote:
> aaron.ballman wrote:
> > This is not as safe as you might think. As-is, this is fine, however, if 
> > the class is given an inline function where that variable is odr-used, you 
> > will get an ODR violation.
> > 
> > I think it's mildly better to err on the side of safety here and diagnose.
> I think the current code (Line `97` in `DefinitionsInHeadersCheck.cpp`) has 
> already guaranteed this case. Can you try to run it without your change in 
> the `DefinitionsInHeadersCheck.cpp`?
> 
> I think it still makes sense to add `constexpr` test cases.
> 
>   
In C++17, `constexpr static int i` is an inline variable, which is fine to 
define in C++ header -- because `inline` specifier provides a facility allowing 
definitions (functions/variables) in header that is included in multiple TUs. 
Additionally, one of the `inline variable` motivations is to support the 
development of header-only libraries, you can find discussions in 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4424.pdf.

Therefore, I'm +1 ignore the inline variables (the same as inline functions). 


Repository:
  rL LLVM

https://reviews.llvm.org/D34449



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


[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.

The following changes are made to the driver since 32-bit apps do not run on 
iOS 11 or later:

- If the deployment target is set explicitly, either with a command-line option 
or an environment variable, the driver should report an error if the version is 
greater than iOS 10.

- In the case where the deployment target is not set explicitly and the default 
is inferred from the target triple or SDK version, it should use a maximum 
default of iOS 10.

rdar://problem/32230613


https://reviews.llvm.org/D34529

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c

Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -10,6 +10,41 @@
 // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS3 %s
 // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0"
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err
+// RUN:   FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s
+// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0'
+
+// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s
+// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0'
+
+// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS6 %s
+// CHECK-VERSION-IOS6: invalid iOS deployment version '-mios-simulator-version-min=11.0'
+
+// RUN: %clang -target armv7-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS7 %s
+// CHECK-VERSION-IOS7: thumbv7-apple-ios10.1.0
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target arm64-apple-ios11.0 -c -### %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS8 %s
+// CHECK-VERSION-IOS8: arm64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.0 -miphoneos-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS9 %s
+// CHECK-VERSION-IOS9: arm64-apple-ios11.0.0
+
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
+// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
+// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0
+
 // RUN: %clang -target i686-apple-darwin8 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-OSX4 %s
 // RUN: %clang -target i686-apple-darwin9 -mmacosx-version-min=10.4 -c %s -### 2>&1 | \
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1150,6 +1150,17 @@
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
 
+  unsigned Major, Minor, Micro;
+  bool HadExtra;
+
+  // iOS 10 is the maximum deployment target for 32-bit targets.
+  if (iOSVersion && getTriple().isArch32Bit() &&
+  Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
+HadExtra) &&
+  Major > 10)
+getDriver().Diag(diag::err_invalid_ios_deployment_target)
+<< iOSVersion->getAsString(Args);
+
   // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
   // -m(iphone|tv|watch)simulator-version-min=X.Y.
   if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
@@ -1191,6 +1202,14 @@
 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
   WatchOSTarget = env;
 
+// iOS 10 is the maximum deployment target for 32-bit targets.
+if (!iOSTarget.empty() && getTriple().isArch32Bit() &&
+Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro,
+  HadExtra) &&
+Major > 10)
+  getDriver().Diag(diag::err_invalid_ios_deployment_target)
+  << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
+
 // If there is no command-line argument to specify the Target version and
 // no environment variable defined, see if we can set the default based
 // on -isysroot.
@@ -1308,8 +1327,6 @@
 llvm_unreachable("Unable to infer Darwin variant");
 
   // Set the tool chain target information.
-  unsigned Major, Minor, Micro;
-  bool HadExtra;
   if (Platform == MacOS) {
 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
"Unknown target platform!");

Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Akira Hatanaka via cfe-commits
According to the documentation, the starting position of the field has to be 
encoded too:

https://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html 


I’m not sure whether we need the same information for bitfield ivars though.

> On Jun 22, 2017, at 12:03 PM, Joerg Sonnenberger  wrote:
> 
> On Thu, Jun 22, 2017 at 11:09:48AM -0700, Akira Hatanaka wrote:
>> Do you want the same encoding for the bitfield “int : 1” you saw before 
>> r297792, which is just “i"?
>> 
>> The encoding for bitfield is normally bN where N is the number of bits,
>> but the comment in function EncodeBitField says GNU runtime encodes it 
>> differently.
> 
> Sorry, can't answer that. I primarily care about a new clang crash that
> didn't exist before, cut I can't answer what the correct behavior should
> be.
> 
> Joerg

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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-22 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

In https://reviews.llvm.org/D34299#788152, @vsk wrote:

> The source locations aren't constants. The ubsan runtime uses a bit inside of 
> source location structures as a flag. When an issue is diagnosed at a 
> particular source location, that bit is atomically set. This is how ubsan 
> implements issue deduplication.


It's still an `llvm::Constant`. Just like in StaticData, in line 2966.
Basically, I don't see why we need to add the store/load and an additional 
indirection, since the pointer is constant, and we can just emit the static 
data as before.
We're already doing `Data->Loc.acquire();` for the current version (and all the 
other checks).

>> I'd also like to have some asserts and explicit resets to nullptr after use 
>> on the ReturnLocation variable, if possible.
> 
> Resetting Address fields in CodeGenFunction doesn't appear to be an 
> established practice. Could you explain what this would be in aid of?

It would be a sanity check and help with code reading/keeping in mind the 
lifetime of the information. I'm ok with that happening only on `!NDEBUG` 
builds.

Reading the code, I don't know if a `ReturnLocation` might end up being used 
for more than one checks. If it's supposed to be a different one per check, etc.
If it's only supposed to be used once, I'd rather set it to `nullptr` right 
after use (at least when `!NDEBUG`), and `assert(!ReturnLocation)` before 
setting. It's not a big deal, but would help with making sense of the flow of 
information when debugging.


https://reviews.llvm.org/D34299



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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

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

In https://reviews.llvm.org/D34299#788379, @filcab wrote:

> In https://reviews.llvm.org/D34299#788152, @vsk wrote:
>
> > The source locations aren't constants. The ubsan runtime uses a bit inside 
> > of source location structures as a flag. When an issue is diagnosed at a 
> > particular source location, that bit is atomically set. This is how ubsan 
> > implements issue deduplication.
>
>
> It's still an `llvm::Constant`. Just like in StaticData, in line 2966.
>  Basically, I don't see why we need to add the store/load and an additional 
> indirection, since the pointer is constant, and we can just emit the static 
> data as before.


My earlier response made the assumption that you wanted a copy of the source 
location passed to the runtime handler, by-value. I see now that you're 
wondering why the source locations aren't part of the static data structure. 
That's because the location of the return statement isn't known at compile 
time, i.e it's not static data. The location depends on which return statement 
is executed.

> We're already doing `Data->Loc.acquire();` for the current version (and all 
> the other checks).

The other checks do not allow the source location within a static data object 
to change.

>>> I'd also like to have some asserts and explicit resets to nullptr after use 
>>> on the ReturnLocation variable, if possible.
>> 
>> Resetting Address fields in CodeGenFunction doesn't appear to be an 
>> established practice. Could you explain what this would be in aid of?
> 
> It would be a sanity check and help with code reading/keeping in mind the 
> lifetime of the information. I'm ok with that happening only on `!NDEBUG` 
> builds.
> 
> Reading the code, I don't know if a `ReturnLocation` might end up being used 
> for more than one checks. If it's supposed to be a different one per check, 
> etc.
>  If it's only supposed to be used once, I'd rather set it to `nullptr` right 
> after use (at least when `!NDEBUG`), and `assert(!ReturnLocation)` before 
> setting. It's not a big deal, but would help with making sense of the flow of 
> information when debugging.

Sure, I'll reset it to Address::invalid().


https://reviews.llvm.org/D34299



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-22 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@efriedma hmm...using `getBlockManglingNumber` causes the name to be 
duplicated.  Ill look into that.  However, wouldn't all the block invocation 
functions be defined and COMDAT'ed?

@majnemer Sure, will add more tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 103632.
vsk marked an inline comment as done.
vsk added a comment.

Handle functions without return statements correctly (fixing an issue pointed 
out by @arphaman). Now, the instrumentation always checks that we have a valid 
return location before calling the runtime. I added tests for this on the clang 
side: we can't test it on the compiler-rt side, because functions without 
return statements can cause stack corruption / crashes on Darwin.


https://reviews.llvm.org/D34299

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjC/ubsan-nonnull-and-nullability.m
  test/CodeGenObjC/ubsan-nullability.m

Index: test/CodeGenObjC/ubsan-nullability.m
===
--- test/CodeGenObjC/ubsan-nullability.m
+++ test/CodeGenObjC/ubsan-nullability.m
@@ -2,31 +2,28 @@
 // RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s
 // RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s
 
-// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 109, i32 1 {{.*}} i32 100, i32 6
+// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 100, i32 6
 // CHECK: [[NONNULL_ARG_LOC:@.*]] = private unnamed_addr global {{.*}} i32 204, i32 15 {{.*}} i32 190, i32 23
 // CHECK: [[NONNULL_ASSIGN1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 305, i32 9
 // CHECK: [[NONNULL_ASSIGN2_LOC:@.*]] = private unnamed_addr global {{.*}} i32 405, i32 10
 // CHECK: [[NONNULL_ASSIGN3_LOC:@.*]] = private unnamed_addr global {{.*}} i32 506, i32 10
 // CHECK: [[NONNULL_INIT1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 604, i32 25
 // CHECK: [[NONNULL_INIT2_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 26
 // CHECK: [[NONNULL_INIT2_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 29
-// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 817, i32 1 {{.*}} i32 800, i32 6
+// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 800, i32 6
 
 #define NULL ((void *)0)
 #define INULL ((int *)NULL)
 #define INNULL ((int *_Nonnull)NULL)
 
 // CHECK-LABEL: define i32* @{{.*}}nonnull_retval1
 #line 100
 int *_Nonnull nonnull_retval1(int *p) {
-  // CHECK: br i1 true, label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
-  // CHECK: [[NULL]]:
   // CHECK: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
-  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
+  // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_nullability_return{{.*}}[[NONNULL_RV_LOC1]]
   return p;
-  // CHECK: [[NONULL]]:
-  // CHECK-NEXT: ret i32*
+  // CHECK: ret i32*
 }
 
 #line 190
@@ -108,10 +105,13 @@
   // CHECK-NEXT: [[DO_RV_CHECK_1:%.*]] = and i1 true, [[ARG1CMP]], !nosanitize
   // CHECK: [[ARG2CMP:%.*]] = icmp ne i32* %arg2, null, !nosanitize
   // CHECK-NEXT: [[DO_RV_CHECK_2:%.*]] = and i1 [[DO_RV_CHECK_1]], [[ARG2CMP]]
-  // CHECK: br i1 [[DO_RV_CHECK_2]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
+  // CHECK: [[SLOC_PTR:%.*]] = load i8*, i8** %return.sloc.ptr
+  // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC_PTR]], null
+  // CHECK-NEXT: [[DO_RV_CHECK_3:%.*]] = and i1 [[SLOC_NONNULL]], [[DO_RV_CHECK_2]]
+  // CHECK: br i1 [[DO_RV_CHECK_3]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
   // CHECK: [[NULL]]:
   // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
-  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
+  // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_nullability_return{{.*}}[[NONNULL_RV_LOC2]]
   return arg1;
   // CHECK: [[NONULL]]:
@@ -129,10 +129,13 @@
 +(int *_Nonnull) objc_clsmethod: (int *_Nonnull) arg1 {
   // CHECK: [[ARG1CMP:%.*]] = icmp ne i32* %arg1, null, !nosanitize
   // CHECK-NEXT: [[DO_RV_CHECK:%.*]] = and i1 true, [[ARG1CMP]]
-  // CHECK: br i1 [[DO_RV_CHECK]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
+  // CHECK: [[SLOC_PTR:%.*]] = load i8*, i8** %return.sloc.ptr
+  // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC_PTR]], null
+  // CHECK-NEXT: [[DO_RV_CHECK_2:%.*]] = and i1 [[SLOC_NONNULL]], [[DO_RV_CHECK]]
+  // CHECK: br i1 [[DO_RV_CHECK_2]], label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
   // CHECK: [[NULL]]:
   // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
-  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
+  // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_nullability_return{{.*}}
   return arg1;
   // CHECK: [[NONULL]]:
@@ -143,10 +146,13 @@
 -(int *_Nonnull) objc_method: (int *_Nonnull) arg1 {
   // CHECK: [[ARG1CMP:%.*]

[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: lib/CodeGen/CGStmt.cpp:1035
+assert(ReturnLocation.isValid() && "No valid return location");
+Builder.CreateStore(Builder.CreateBitCast(SLocPtr, Int8PtrTy),
+ReturnLocation);

filcab wrote:
> Can't you just keep the `Constant*` around and use it later for the static 
> data? Instead of creating a global var and have runtime store/load?
I hope I've cleared this up, but: we need to store the source location constant 
_somewhere_, before we emit the return value check. That's because we can't 
infer which return location to use at compile time.



Comment at: lib/CodeGen/CodeGenFunction.h:1412
+  /// source location for diagnostics.
+  Address ReturnLocation = Address::invalid();
+

filcab wrote:
> Maybe `CurrentReturnLocation`?
I'd prefer to keep it the way it is, for consistency with the "ReturnValue" 
field.


https://reviews.llvm.org/D34299



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


[PATCH] D34114: [clang] A better format for unnecessary packed warning.

2017-06-22 Thread Stephen Hines via Phabricator via cfe-commits
srhines added a comment.

Richard, can you take a look at this, or suggest someone who would be a good 
reviewer for this improved diagnostic? Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D34114



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


[PATCH] D34534: [libcxx] [test] Fix MSVC warning C4242 "conversion from 'int' to 'const char', possible loss of data".

2017-06-22 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.

[libcxx] [test] Fix MSVC warning C4242 "conversion from 'int' to 'const char', 
possible loss of data".


https://reviews.llvm.org/D34534

Files:
  test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp


Index: 
test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
===
--- 
test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
+++ 
test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
@@ -46,7 +46,7 @@
 if (__c != base::traits_type::eof())
 {
 int n = str_.size();
-str_.push_back(__c);
+str_.push_back(static_cast(__c));
 str_.resize(str_.capacity());
 base::setp(const_cast(str_.data()),
const_cast(str_.data() + str_.size()));
Index: test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
===
--- test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
+++ test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
@@ -40,7 +40,7 @@
 if (__c != base::traits_type::eof())
 {
 int n = str_.size();
-str_.push_back(__c);
+str_.push_back(static_cast(__c));
 str_.resize(str_.capacity());
 base::setp(const_cast(str_.data()),
const_cast(str_.data() + str_.size()));


Index: test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
===
--- test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
+++ test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp
@@ -46,7 +46,7 @@
 if (__c != base::traits_type::eof())
 {
 int n = str_.size();
-str_.push_back(__c);
+str_.push_back(static_cast(__c));
 str_.resize(str_.capacity());
 base::setp(const_cast(str_.data()),
const_cast(str_.data() + str_.size()));
Index: test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
===
--- test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
+++ test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp
@@ -40,7 +40,7 @@
 if (__c != base::traits_type::eof())
 {
 int n = str_.size();
-str_.push_back(__c);
+str_.push_back(static_cast(__c));
 str_.resize(str_.capacity());
 base::setp(const_cast(str_.data()),
const_cast(str_.data() + str_.size()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34535: [libcxx] [test] Fix MSVC warning C4067 "unexpected tokens following preprocessor directive - expected a newline".

2017-06-22 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.

[libcxx] [test] Fix MSVC warning C4067 "unexpected tokens following 
preprocessor directive - expected a newline".

Also fixes Clang/LLVM 4.0 (for Windows) error "function-like macro 
'TEST_GLIBC_PREREQ' is not defined".


https://reviews.llvm.org/D34535

Files:
  
test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp


Index: 
test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
===
--- 
test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
+++ 
test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
@@ -117,7 +117,13 @@
 // GLIBC <= 2.23 uses currency_symbol=""
 // GLIBC >= 2.24 uses currency_symbol=""
 // See also: 
http://www.fileformat.info/info/unicode/char/20bd/index.htm
-#if defined(TEST_GLIBC_PREREQ) && TEST_GLIBC_PREREQ(2, 24)
+#if defined(TEST_GLIBC_PREREQ)
+#if TEST_GLIBC_PREREQ(2, 24)
+#define TEST_GLIBC_2_24_CURRENCY_SYMBOL
+#endif
+#endif
+
+#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
 assert(f.curr_symbol() == " \u20BD");
 #else
 assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
@@ -129,7 +135,7 @@
 }
 {
 Fwf f(LOCALE_ru_RU_UTF_8, 1);
-#if defined(TEST_GLIBC_PREREQ) && TEST_GLIBC_PREREQ(2, 24)
+#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
 assert(f.curr_symbol() == L" \u20BD");
 #else
 assert(f.curr_symbol() == L" \x440\x443\x431");


Index: test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
===
--- test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
+++ test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
@@ -117,7 +117,13 @@
 // GLIBC <= 2.23 uses currency_symbol=""
 // GLIBC >= 2.24 uses currency_symbol=""
 // See also: http://www.fileformat.info/info/unicode/char/20bd/index.htm
-#if defined(TEST_GLIBC_PREREQ) && TEST_GLIBC_PREREQ(2, 24)
+#if defined(TEST_GLIBC_PREREQ)
+#if TEST_GLIBC_PREREQ(2, 24)
+#define TEST_GLIBC_2_24_CURRENCY_SYMBOL
+#endif
+#endif
+
+#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
 assert(f.curr_symbol() == " \u20BD");
 #else
 assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
@@ -129,7 +135,7 @@
 }
 {
 Fwf f(LOCALE_ru_RU_UTF_8, 1);
-#if defined(TEST_GLIBC_PREREQ) && TEST_GLIBC_PREREQ(2, 24)
+#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
 assert(f.curr_symbol() == L" \u20BD");
 #else
 assert(f.curr_symbol() == L" \x440\x443\x431");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34536: [libcxx] [test] Fix Clang -Wunused-local-typedef warnings.

2017-06-22 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT created this revision.

[libcxx] [test] Fix Clang -Wunused-local-typedef warnings.


https://reviews.llvm.org/D34536

Files:
  test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp
  test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp
  
test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.lognormal/eval.pass.cpp
  test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.t/eval.pass.cpp
  
test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp
  
test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
  
test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
  test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp

Index: test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp
@@ -22,7 +22,6 @@
 {
 typedef std::chrono::system_clock Clock;
 typedef Clock::time_point time_point;
-typedef Clock::duration duration;
 std::chrono::milliseconds ms(500);
 time_point t0 = Clock::now();
 std::this_thread::sleep_until(t0 + ms);
Index: test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
===
--- test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
+++ test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
@@ -44,7 +44,6 @@
 test1()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14, 16, 17};
@@ -97,7 +96,6 @@
 test2()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14, 16, 17};
@@ -150,7 +148,6 @@
 test3()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14, 16, 17};
@@ -203,7 +200,6 @@
 test4()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14, 16};
@@ -257,7 +253,6 @@
 test5()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14};
@@ -312,7 +307,6 @@
 test6()
 {
 typedef std::piecewise_linear_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937_64 G;
 G g;
 double b[] = {10, 14, 16, 17};
Index: test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
===
--- test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
+++ test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
@@ -33,7 +33,6 @@
 {
 {
 typedef std::gamma_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937 G;
 G g;
 D d(0.5, 2);
@@ -73,7 +72,6 @@
 }
 {
 typedef std::gamma_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937 G;
 G g;
 D d(1, .5);
@@ -113,7 +111,6 @@
 }
 {
 typedef std::gamma_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937 G;
 G g;
 D d(2, 3);
Index: test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp
===
--- test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp
+++ test/std/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.extreme/eval.pass.cpp
@@ -33,7 +33,6 @@
 test1()
 {
 typedef std::extreme_value_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937 G;
 G g;
 D d(0.5, 2);
@@ -75,7 +74,6 @@
 test2()
 {
 typedef std::extreme_value_distribution<> D;
-typedef D::param_type P;
 typedef std::mt19937 G;
 G g;
 D d(1, 2);
@@ -117,7 +115,6 @@
 test3()
 {
 typedef std::extrem

[PATCH] D34082: [Frontend] 'Show hotness' can be used with a sampling profile

2017-06-22 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 103647.
modocache added a comment.

Update the sampling profile text so that it produces the hotness expected by 
the test. This is ready to go :)


https://reviews.llvm.org/D34082

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
  test/Frontend/optimization-remark-with-hotness.c


Index: test/Frontend/optimization-remark-with-hotness.c
===
--- test/Frontend/optimization-remark-with-hotness.c
+++ test/Frontend/optimization-remark-with-hotness.c
@@ -1,11 +1,21 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
 // RUN: -fdiagnostics-show-hotness -verify
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
+// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
+// RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
+// RUN: -Rpass-analysis=inline -Rpass-missed=inline \
+// RUN: -fdiagnostics-show-hotness -verify
 // The clang version of the previous test.
 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
Index: test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
===
--- /dev/null
+++ test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
@@ -0,0 +1,7 @@
+foo:0:0
+ 0: 0
+bar:29:29
+ 6: foo:0
+main:0:0
+ 0: 0 bar:0
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -892,14 +892,18 @@
 
   Opts.DiagnosticsWithHotness =
   Args.hasArg(options::OPT_fdiagnostics_show_hotness);
+  bool UsingSampleProfile = !Opts.SampleProfileFile.empty();
+
   if (Opts.DiagnosticsWithHotness &&
-  Opts.getProfileUse() == CodeGenOptions::ProfileNone)
+  Opts.getProfileUse() == CodeGenOptions::ProfileNone &&
+  !UsingSampleProfile) {
 Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo);
+  }
 
   // If the user requested to use a sample profile for PGO, then the
   // backend will need to track source location information so the profile
   // can be incorporated into the IR.
-  if (!Opts.SampleProfileFile.empty())
+  if (UsingSampleProfile)
 NeedLocTracking = true;
 
   // If the user requested a flag that requires source locations available in


Index: test/Frontend/optimization-remark-with-hotness.c
===
--- test/Frontend/optimization-remark-with-hotness.c
+++ test/Frontend/optimization-remark-with-hotness.c
@@ -1,11 +1,21 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
 // RUN: -fdiagnostics-show-hotness -verify
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
+// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
+// RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
+// RUN: -Rpass-analysis=inline -Rpass-missed=inline \
+// RUN: -fdiagnostics-show-hotness -verify
 // The clang version of the previous test.
 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
Index: test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
===
--- /dev/null
+++ test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
@@ -0,0 +1,7 @@
+foo:0:0
+ 0: 0
+bar:29:29
+ 6: foo:0
+main:0:0
+ 0: 0 bar:0
+
Index: lib/Frontend/CompilerInvocation.c

[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-22 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> @efriedma hmm...using getBlockManglingNumber causes the name to be 
> duplicated. Ill look into that.

Have you looked at the Itanium mangling implementation?

> However, wouldn't all the block invocation functions be defined and COMDAT'ed?

IIRC, we always emit blocks with internal linkage, not linkonce.  But even if 
we did use linkonce linkage, the block could get inlined.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


r306065 - PR33002: When we instantiate the definition of a static data member, we might

2017-06-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jun 22 17:18:46 2017
New Revision: 306065

URL: http://llvm.org/viewvc/llvm-project?rev=306065&view=rev
Log:
PR33002: When we instantiate the definition of a static data member, we might
have attached an initializer to the in-class declaration. If so, include the
initializer in the update record for the instantiation.

Added:
cfe/trunk/test/Modules/const-var-init-update.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=306065&r1=306064&r2=306065&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jun 22 17:18:46 2017
@@ -4290,9 +4290,6 @@ void Sema::InstantiateVariableDefinition
   InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs);
   PreviousContext.pop();
 
-  // FIXME: Need to inform the ASTConsumer that we instantiated the
-  // initializer?
-
   // This variable may have local implicit instantiations that need to be
   // instantiated within this scope.
   LocalInstantiations.perform();
@@ -4402,7 +4399,6 @@ void Sema::InstantiateVariableDefinition
   if (Def->isStaticDataMember() && !Def->isOutOfLine()) {
 // We're instantiating an inline static data member whose definition was
 // provided inside the class.
-// FIXME: Update record?
 InstantiateVariableInitializer(Var, Def, TemplateArgs);
   } else if (!VarSpec) {
 Var = cast_or_null(SubstDecl(Def, Var->getDeclContext(),

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=306065&r1=306064&r2=306065&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jun 22 17:18:46 2017
@@ -3934,10 +3934,21 @@ void ASTDeclReader::UpdateDecl(Decl *D)
   break;
 }
 
-case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
-  cast(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
+case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: {
+  VarDecl *VD = cast(D);
+  VD->getMemberSpecializationInfo()->setPointOfInstantiation(
   ReadSourceLocation());
+  uint64_t Val = Record.readInt();
+  if (Val && !VD->getInit()) {
+VD->setInit(Record.readExpr());
+if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
+  EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
+  Eval->CheckedICE = true;
+  Eval->IsICE = Val == 3;
+}
+  }
   break;
+}
 
 case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: {
   auto Param = cast(D);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=306065&r1=306064&r2=306065&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Jun 22 17:18:46 2017
@@ -5033,9 +5033,18 @@ void ASTWriter::WriteDeclUpdatesBlocks(R
   case UPD_CXX_ADDED_FUNCTION_DEFINITION:
 break;
 
-  case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
+  case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: {
+const VarDecl *VD = cast(D);
 Record.AddSourceLocation(Update.getLoc());
+if (VD->getInit()) {
+  Record.push_back(!VD->isInitKnownICE() ? 1
+ : (VD->isInitICE() ? 3 : 2));
+  Record.AddStmt(const_cast(VD->getInit()));
+} else {
+  Record.push_back(0);
+}
 break;
+  }
 
   case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
 Record.AddStmt(const_cast(

Added: cfe/trunk/test/Modules/const-var-init-update.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/const-var-init-update.cpp?rev=306065&view=auto
==
--- cfe/trunk/test/Modules/const-var-init-update.cpp (added)
+++ cfe/trunk/test/Modules/const-var-init-update.cpp Thu Jun 22 17:18:46 2017
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++1z -fmodules %s -verify
+// expected-no-diagnostics
+
+#pragma clang module build std
+module std { module limits {} module other {} }
+#pragma clang module contents
+#pragma clang module begin std.limits
+template struct numeric_limits {
+  static constexpr T __max = 5;
+  static constexpr T max() { return __max; }
+};
+#pragma clang module end
+#pragma clang module begin std.other
+inlin

Re: r303322 - [modules] Switch from inferring owning modules based on source location to

2017-06-22 Thread Michael Gottesman via cfe-commits

> On Jun 21, 2017, at 4:56 PM, Richard Smith via cfe-commits 
>  wrote:
> 
> On 21 June 2017 at 16:55, Bruno Cardoso Lopes  > wrote:
> On Wed, Jun 21, 2017 at 4:44 PM, Richard Smith  > wrote:
> > On 21 June 2017 at 14:51, Bruno Cardoso Lopes  > >
> > wrote:
> >>
> >> Hi Richard,
> >>
> >> Somehow this commit caused some methods in ObjC to do not become
> >> visible in an interface when compiling with modules on. I filed
> >> https://bugs.llvm.org/show_bug.cgi?id=33552 
> >> , any idea what could have
> >> gone wrong here? `hasVisibleDeclarationImpl` doesn't seem to have
> >> changed the logic.
> >
> >
> > DeclObjC.cpp is making some incorrect assumptions about what the isHidden()
> > flag on Decls means. Looks like we're going to need to move all of the ObjC
> > lookup machinery out of DeclObjC into Sema to allow it to perform correct
> > visibility checks. (For what it's worth, this would already have been broken
> > for Objective-C++ and local submodule visibility mode prior to this change,
> > as those modes both have situations where the "Hidden" flag is not the
> > complete story with regard to whether a declaration is visible in a
> > particular lookup context.)
> 
> Oh, that's bad.
> 
> Is there any workaround we can do on top of this change for now in
> order to have the previous behavior for non-LSV and ObjC? This is
> keeping Swift from building against upstream right now.
> 
> Yes, I'm working on what should (hopefully) be a fairly quick short-term fix.

Thanks Richard!

Do you have an eta on this?

This is blocking swift from compiling against ToT LLVM. As you know these 
changes come in fast so the longer we wait, the more likely other breakage 
sneaks in. I imagine we are going to probably build against the newer 
llvm/clang in the next bit, so this is the worst time to have a long period of 
time of breakage.

+CC Jordan Rose since I think he ran into this.

Thanks in advance = ),
Michael

>  
> >> Thanks,
> >>
> >> On Wed, May 17, 2017 at 7:29 PM, Richard Smith via cfe-commits
> >> mailto:cfe-commits@lists.llvm.org>> wrote:
> >> > Author: rsmith
> >> > Date: Wed May 17 21:29:20 2017
> >> > New Revision: 303322
> >> >
> >> > URL: http://llvm.org/viewvc/llvm-project?rev=303322&view=rev 
> >> > 
> >> > Log:
> >> > [modules] Switch from inferring owning modules based on source location
> >> > to
> >> > inferring based on the current module at the point of creation.
> >> >
> >> > This should result in no functional change except when building a
> >> > preprocessed
> >> > module (or more generally when using #pragma clang module begin/end to
> >> > switch
> >> > module in the middle of a file), in which case it allows us to correctly
> >> > track
> >> > the owning module for declarations. We can't map from FileID to module
> >> > in the
> >> > preprocessed module case, since all modules would have the same FileID.
> >> >
> >> > There are still a couple of remaining places that try to infer a module
> >> > from a
> >> > source location; I'll clean those up in follow-up changes.
> >> >
> >> > Modified:
> >> > cfe/trunk/include/clang/AST/ASTContext.h
> >> > cfe/trunk/include/clang/AST/DeclBase.h
> >> > cfe/trunk/include/clang/Basic/LangOptions.h
> >> > cfe/trunk/include/clang/Sema/Sema.h
> >> > cfe/trunk/include/clang/Serialization/ASTWriter.h
> >> > cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> >> > cfe/trunk/lib/Sema/SemaDecl.cpp
> >> > cfe/trunk/lib/Sema/SemaLookup.cpp
> >> > cfe/trunk/lib/Sema/SemaTemplate.cpp
> >> > cfe/trunk/lib/Serialization/ASTWriter.cpp
> >> > cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> >> > cfe/trunk/test/Modules/preprocess-module.cpp
> >> > cfe/trunk/test/SemaCXX/modules-ts.cppm
> >> >
> >> > Modified: cfe/trunk/include/clang/AST/ASTContext.h
> >> > URL:
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=303322&r1=303321&r2=303322&view=diff
> >> >  
> >> > 
> >> >
> >> > ==
> >> > --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> >> > +++ cfe/trunk/include/clang/AST/ASTContext.h Wed May 17 21:29:20 2017
> >> > @@ -935,7 +935,7 @@ public:
> >> >
> >> >/// \brief Get the additional modules in which the definition \p Def
> >> > has
> >> >/// been merged.
> >> > -  ArrayRef getModulesWithMergedDefinition(NamedDecl *Def) {
> >> > +  ArrayRef getModulesWithMergedDefinition(const NamedDecl
> >> > *Def) {
> >> >  auto MergedIt = MergedDefModules.find(Def);
> >> >  if (MergedIt == MergedDefModules.end())
> >> >return None;
> >> >
> >> > Modified: cfe/trunk/include/clang/AST/DeclB

[PATCH] D33565: [WebAssembly] Add default -allow-undefined-file to linker args

2017-06-22 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306074: [WebAssembly] Add default -allow-undefined-file to 
linker args (authored by sbc).

Changed prior to commit:
  https://reviews.llvm.org/D33565?vs=103130&id=103668#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33565

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/test/Driver/wasm-toolchain.c


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -83,6 +83,8 @@
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 
+CmdArgs.push_back("-allow-undefined-file");
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("wasm.syms")));
 CmdArgs.push_back("-lc");
 CmdArgs.push_back("-lcompiler_rt");
   }
@@ -104,8 +106,7 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  getFilePaths().push_back(
-  getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64"));
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,18 +27,18 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib32" "crt1.o" "crti.o" 
"[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
 
 // A basic C link command-line with optimization. WebAssembly is somewhat
 // special in enabling --gc-sections by default.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" 
"crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" 
"crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" 
"crtn.o" "-o" "a.out"
 
 // Ditto, but ensure that a user --no-gc-sections comes after the
 // default --gc-sections.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck 
-check-prefix=NO_GC_SECTIONS %s
 // NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" 
"crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" 
"-o" "a.out"
+// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" 
"crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-allow-undefined-file" 
"wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"


Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -83,6 +83,8 @@
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 
+CmdArgs.push_back("-allow-undefined-file");
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("wasm.syms")));
 CmdArgs.push_back("-lc");
 CmdArgs.push_back("-lcompiler_rt");
   }
@@ -104,8 +106,7 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  getFilePaths().push_back(
-  getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64"));
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,18 +27,18 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib32" "crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
 
 // A basic C link command-line with optimization. WebAssembly is somewhat
 /

[PATCH] D33606: [Sema] Fix a crash-on-invalid when a template parameter list has a class definition or non-reference class type

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

LGTM!


https://reviews.llvm.org/D33606



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


r306075 - PR33552: Distinguish between declarations that are owned by no module and

2017-06-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jun 22 20:04:34 2017
New Revision: 306075

URL: http://llvm.org/viewvc/llvm-project?rev=306075&view=rev
Log:
PR33552: Distinguish between declarations that are owned by no module and
declarations that are owned but unconditionally visible.

This allows us to set declarations as visible even if they have a local owning
module, without losing information. In turn, that means that our Objective-C
support can keep on incorrectly assuming the "hidden" bit on the declaration is
the whole story with regard to name visibility. This will also be useful once
we support the C++ Modules TS export semantics.

Objective-C name visibility is still incorrect in any case where the "hidden"
bit is not the complete story: for instance, in Objective-C++ the set of
visible categories will be wrong during template instantiation, and with local
submodule visibility enabled it will be wrong when building modules. Fixing that
will require a major overhaul of how visibility is handled for Objective-C (and
particularly for categories).

Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/test/Misc/ast-dump-decl.c
cfe/trunk/test/Misc/ast-dump-decl.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=306075&r1=306074&r2=306075&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Jun 22 20:04:34 2017
@@ -202,26 +202,33 @@ public:
 OBJC_TQ_CSNullability = 0x40
   };
 
-protected:
-  // Enumeration values used in the bits stored in NextInContextAndBits.
-  enum {
-/// \brief Whether this declaration is a top-level declaration (function,
-/// global variable, etc.) that is lexically inside an objc container
-/// definition.
-TopLevelDeclInObjCContainerFlag = 0x01,
-
-/// \brief Whether this declaration is private to the module in which it 
was
-/// defined.
-ModulePrivateFlag = 0x02
+  /// The kind of ownership a declaration has, for visibility purposes.
+  /// This enumeration is designed such that higher values represent higher
+  /// levels of name hiding.
+  enum class ModuleOwnershipKind : unsigned {
+/// This declaration is not owned by a module.
+Unowned,
+/// This declaration has an owning module, but is globally visible
+/// (typically because its owning module is visible and we know that
+/// modules cannot later become hidden in this compilation).
+/// After serialization and deserialization, this will be converted
+/// to VisibleWhenImported.
+Visible,
+/// This declaration has an owning module, and is visible when that
+/// module is imported.
+VisibleWhenImported,
+/// This declaration has an owning module, but is only visible to
+/// lookups that occur within that module.
+ModulePrivate
   };
-  
+
+protected:
   /// \brief The next declaration within the same lexical
   /// DeclContext. These pointers form the linked list that is
   /// traversed via DeclContext's decls_begin()/decls_end().
   ///
-  /// The extra two bits are used for the TopLevelDeclInObjCContainer and
-  /// ModulePrivate bits.
-  llvm::PointerIntPair NextInContextAndBits;
+  /// The extra two bits are used for the ModuleOwnershipKind.
+  llvm::PointerIntPair NextInContextAndBits;
 
 private:
   friend class DeclContext;
@@ -282,6 +289,11 @@ private:
   /// are regarded as "referenced" but not "used".
   unsigned Referenced : 1;
 
+  /// \brief Whether this declaration is a top-level declaration (function,
+  /// global variable, etc.) that is lexically inside an objc container
+  /// definition.
+  unsigned TopLevelDeclInObjCContainer : 1;
+  
   /// \brief Whether statistic collection is enabled.
   static bool StatisticsEnabled;
 
@@ -294,11 +306,6 @@ protected:
   /// \brief Whether this declaration was loaded from an AST file.
   unsigned FromASTFile : 1;
 
-  /// \brief Whether this declaration is hidden from normal name lookup, e.g.,
-  /// because it is was loaded from an AST file is either module-private or
-  /// because its submodule has not been made visible.
-  unsigned Hidden : 1;
-  
   /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
   unsigned IdentifierNamespace : 13;
 
@@ -332,26 +339,38 @@ protected:
 private:
   bool AccessDeclContextSanity() const;
 
+  /// Get the module ownership kind to use for a local lexical child of \p DC,
+  /// which may be either a local or (rar

Re: r303322 - [modules] Switch from inferring owning modules based on source location to

2017-06-22 Thread Richard Smith via cfe-commits
On 22 June 2017 at 16:18, Michael Gottesman  wrote:

>
> On Jun 21, 2017, at 4:56 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> On 21 June 2017 at 16:55, Bruno Cardoso Lopes 
> wrote:
>
>> On Wed, Jun 21, 2017 at 4:44 PM, Richard Smith 
>> wrote:
>> > On 21 June 2017 at 14:51, Bruno Cardoso Lopes 
>> > wrote:
>> >>
>> >> Hi Richard,
>> >>
>> >> Somehow this commit caused some methods in ObjC to do not become
>> >> visible in an interface when compiling with modules on. I filed
>> >> https://bugs.llvm.org/show_bug.cgi?id=33552, any idea what could have
>> >> gone wrong here? `hasVisibleDeclarationImpl` doesn't seem to have
>> >> changed the logic.
>> >
>> >
>> > DeclObjC.cpp is making some incorrect assumptions about what the
>> isHidden()
>> > flag on Decls means. Looks like we're going to need to move all of the
>> ObjC
>> > lookup machinery out of DeclObjC into Sema to allow it to perform
>> correct
>> > visibility checks. (For what it's worth, this would already have been
>> broken
>> > for Objective-C++ and local submodule visibility mode prior to this
>> change,
>> > as those modes both have situations where the "Hidden" flag is not the
>> > complete story with regard to whether a declaration is visible in a
>> > particular lookup context.)
>>
>> Oh, that's bad.
>>
>> Is there any workaround we can do on top of this change for now in
>> order to have the previous behavior for non-LSV and ObjC? This is
>> keeping Swift from building against upstream right now.
>
>
> Yes, I'm working on what should (hopefully) be a fairly quick short-term
> fix.
>
>
> Thanks Richard!
>
> Do you have an eta on this?
>

Let me know if you're still having problems after r306075.


> This is blocking swift from compiling against ToT LLVM. As you know these
> changes come in fast so the longer we wait, the more likely other breakage
> sneaks in. I imagine we are going to probably build against the newer
> llvm/clang in the next bit, so this is the worst time to have a long period
> of time of breakage.
>
> +CC Jordan Rose since I think he ran into this.
>
> Thanks in advance = ),
> Michael
>
>
>
>> >> Thanks,
>> >>
>> >> On Wed, May 17, 2017 at 7:29 PM, Richard Smith via cfe-commits
>> >>  wrote:
>> >> > Author: rsmith
>> >> > Date: Wed May 17 21:29:20 2017
>> >> > New Revision: 303322
>> >> >
>> >> > URL: http://llvm.org/viewvc/llvm-project?rev=303322&view=rev
>> >> > Log:
>> >> > [modules] Switch from inferring owning modules based on source
>> location
>> >> > to
>> >> > inferring based on the current module at the point of creation.
>> >> >
>> >> > This should result in no functional change except when building a
>> >> > preprocessed
>> >> > module (or more generally when using #pragma clang module begin/end
>> to
>> >> > switch
>> >> > module in the middle of a file), in which case it allows us to
>> correctly
>> >> > track
>> >> > the owning module for declarations. We can't map from FileID to
>> module
>> >> > in the
>> >> > preprocessed module case, since all modules would have the same
>> FileID.
>> >> >
>> >> > There are still a couple of remaining places that try to infer a
>> module
>> >> > from a
>> >> > source location; I'll clean those up in follow-up changes.
>> >> >
>> >> > Modified:
>> >> > cfe/trunk/include/clang/AST/ASTContext.h
>> >> > cfe/trunk/include/clang/AST/DeclBase.h
>> >> > cfe/trunk/include/clang/Basic/LangOptions.h
>> >> > cfe/trunk/include/clang/Sema/Sema.h
>> >> > cfe/trunk/include/clang/Serialization/ASTWriter.h
>> >> > cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> >> > cfe/trunk/lib/Sema/SemaDecl.cpp
>> >> > cfe/trunk/lib/Sema/SemaLookup.cpp
>> >> > cfe/trunk/lib/Sema/SemaTemplate.cpp
>> >> > cfe/trunk/lib/Serialization/ASTWriter.cpp
>> >> > cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>> >> > cfe/trunk/test/Modules/preprocess-module.cpp
>> >> > cfe/trunk/test/SemaCXX/modules-ts.cppm
>> >> >
>> >> > Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> >> > URL:
>> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clan
>> g/AST/ASTContext.h?rev=303322&r1=303321&r2=303322&view=diff
>> >> >
>> >> > 
>> ==
>> >> > --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>> >> > +++ cfe/trunk/include/clang/AST/ASTContext.h Wed May 17 21:29:20
>> 2017
>> >> > @@ -935,7 +935,7 @@ public:
>> >> >
>> >> >/// \brief Get the additional modules in which the definition \p
>> Def
>> >> > has
>> >> >/// been merged.
>> >> > -  ArrayRef getModulesWithMergedDefinition(NamedDecl *Def)
>> {
>> >> > +  ArrayRef getModulesWithMergedDefinition(const NamedDecl
>> >> > *Def) {
>> >> >  auto MergedIt = MergedDefModules.find(Def);
>> >> >  if (MergedIt == MergedDefModules.end())
>> >> >return None;
>> >> >
>> >> > Modified: cfe/trunk/include/clang/AST/DeclBase.h
>> >> > URL:
>> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/inc

r306077 - Add missing file from r306075.

2017-06-22 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jun 22 20:18:27 2017
New Revision: 306077

URL: http://llvm.org/viewvc/llvm-project?rev=306077&view=rev
Log:
Add missing file from r306075.

Added:
cfe/trunk/test/Misc/Inputs/module.modulemap

Added: cfe/trunk/test/Misc/Inputs/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/Inputs/module.modulemap?rev=306077&view=auto
==
--- cfe/trunk/test/Misc/Inputs/module.modulemap (added)
+++ cfe/trunk/test/Misc/Inputs/module.modulemap Thu Jun 22 20:18:27 2017
@@ -0,0 +1 @@
+module X {}


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


[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-22 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
Herald added subscribers: eraman, inglorion.

https://reviews.llvm.org/D34546

Files:
  clang/docs/ThinLTO.rst


Index: clang/docs/ThinLTO.rst
===
--- clang/docs/ThinLTO.rst
+++ clang/docs/ThinLTO.rst
@@ -126,6 +126,38 @@
 - lld (as of LLVM r296702):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
 
+Cache Pruning
+-
+
+To help keep the size of the cache under control, ThinLTO supports cache
+pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
+ELF lld allows you to control the policy with a policy string.  The cache
+policy must be specified with a linker option.
+
+- ELF lld (as of LLVM r298036):
+  ``-Wl,--thinlto-cache-policy,POLICY``
+
+A policy string is a series of key-value pairs separated by ``:`` characters.
+Possible key-value pairs are:
+
+- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent
+  of the available space on the the disk. Set to 100 to indicate no limit,
+  50 to indicate that the cache size will not be left over half the available
+  disk space. A value over 100 is invalid. A value of 0 disables the percentage
+  size-based pruning. The default is 75%.
+
+- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
+  expiration time for cache files to ``X`` seconds (or minutes, hours
+  respectively).  When a file hasn't been accessed for ``prune_after`` seconds,
+  it is removed from the cache. A value of 0 disables the expiration-based
+  pruning. The default is 1 week.
+
+- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``:
+  Sets the pruning interval to ``X`` seconds (or minutes, hours
+  respectively). This is intended to be used to avoid scanning the directory
+  too often. It does not impact the decision of which files to prune. A
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap
 ---
 


Index: clang/docs/ThinLTO.rst
===
--- clang/docs/ThinLTO.rst
+++ clang/docs/ThinLTO.rst
@@ -126,6 +126,38 @@
 - lld (as of LLVM r296702):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
 
+Cache Pruning
+-
+
+To help keep the size of the cache under control, ThinLTO supports cache
+pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
+ELF lld allows you to control the policy with a policy string.  The cache
+policy must be specified with a linker option.
+
+- ELF lld (as of LLVM r298036):
+  ``-Wl,--thinlto-cache-policy,POLICY``
+
+A policy string is a series of key-value pairs separated by ``:`` characters.
+Possible key-value pairs are:
+
+- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent
+  of the available space on the the disk. Set to 100 to indicate no limit,
+  50 to indicate that the cache size will not be left over half the available
+  disk space. A value over 100 is invalid. A value of 0 disables the percentage
+  size-based pruning. The default is 75%.
+
+- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
+  expiration time for cache files to ``X`` seconds (or minutes, hours
+  respectively).  When a file hasn't been accessed for ``prune_after`` seconds,
+  it is removed from the cache. A value of 0 disables the expiration-based
+  pruning. The default is 1 week.
+
+- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``:
+  Sets the pruning interval to ``X`` seconds (or minutes, hours
+  respectively). This is intended to be used to avoid scanning the directory
+  too often. It does not impact the decision of which files to prune. A
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306079 - [Frontend] 'Show hotness' can be used with a sampling profile

2017-06-22 Thread Brian Gesiak via cfe-commits
Author: modocache
Date: Thu Jun 22 21:38:45 2017
New Revision: 306079

URL: http://llvm.org/viewvc/llvm-project?rev=306079&view=rev
Log:
[Frontend] 'Show hotness' can be used with a sampling profile

Summary:
Prior to this change, using `-fdiagnostics-show-hotness` with a sampling
profile specified via `-fprofile-sample-use=` would result in the Clang
frontend emitting a warning: "argument '-fdiagnostics-show-hotness' requires
profile-guided optimization information". Of course, a sampling profile
*is* profile-guided optimization information, so the warning is misleading.
Furthermore, despite the warning, hotness was displayed based on the data in
the sampling profile.

Prevent the warning from being emitted when a sampling profile is used, and
add a test that verifies this.

Reviewers: anemet, davidxl

Reviewed By: davidxl

Subscribers: danielcdh, cfe-commits

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

Added:

cfe/trunk/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Frontend/optimization-remark-with-hotness.c

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=306079&r1=306078&r2=306079&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jun 22 21:38:45 2017
@@ -892,14 +892,18 @@ static bool ParseCodeGenArgs(CodeGenOpti
 
   Opts.DiagnosticsWithHotness =
   Args.hasArg(options::OPT_fdiagnostics_show_hotness);
+  bool UsingSampleProfile = !Opts.SampleProfileFile.empty();
+
   if (Opts.DiagnosticsWithHotness &&
-  Opts.getProfileUse() == CodeGenOptions::ProfileNone)
+  Opts.getProfileUse() == CodeGenOptions::ProfileNone &&
+  !UsingSampleProfile) {
 Diags.Report(diag::warn_drv_fdiagnostics_show_hotness_requires_pgo);
+  }
 
   // If the user requested to use a sample profile for PGO, then the
   // backend will need to track source location information so the profile
   // can be incorporated into the IR.
-  if (!Opts.SampleProfileFile.empty())
+  if (UsingSampleProfile)
 NeedLocTracking = true;
 
   // If the user requested a flag that requires source locations available in

Added: 
cfe/trunk/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext?rev=306079&view=auto
==
--- 
cfe/trunk/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext 
(added)
+++ 
cfe/trunk/test/Frontend/Inputs/optimization-remark-with-hotness-sample.proftext 
Thu Jun 22 21:38:45 2017
@@ -0,0 +1,7 @@
+foo:0:0
+ 0: 0
+bar:29:29
+ 6: foo:0
+main:0:0
+ 0: 0 bar:0
+

Modified: cfe/trunk/test/Frontend/optimization-remark-with-hotness.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark-with-hotness.c?rev=306079&r1=306078&r2=306079&view=diff
==
--- cfe/trunk/test/Frontend/optimization-remark-with-hotness.c (original)
+++ cfe/trunk/test/Frontend/optimization-remark-with-hotness.c Thu Jun 22 
21:38:45 2017
@@ -1,11 +1,21 @@
+// Generate instrumentation and sampling profile data.
 // RUN: llvm-profdata merge \
-// RUN: %S/Inputs/optimization-remark-with-hotness.proftext   \
+// RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
 // RUN: -o %t.profdata
+// RUN: llvm-profdata merge -sample \
+// RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
+// RUN: -o %t-sample.profdata
+//
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
 // RUN: -fdiagnostics-show-hotness -verify
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
+// RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
+// RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
+// RUN: -Rpass-analysis=inline -Rpass-missed=inline \
+// RUN: -fdiagnostics-show-hotness -verify
 // The clang version of the previous test.
 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \


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


[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-22 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:969
+  /// LangAS::Default.
+  virtual unsigned getGlobalAddressSpace() const { return LangAS::Default; }
+

I'm not sure this really needs to exist.



Comment at: include/clang/Basic/TargetInfo.h:959
+  /// \brief Return the target address space which is read only and can be
+  /// casted to the generic address space.
+  virtual llvm::Optional getTargetConstantAddressSpace() const {

yaxunl wrote:
> rjmccall wrote:
> > "Return an AST address space which can be used opportunistically for 
> > constant global memory.  It must be possible to convert pointers into this 
> > address space to LangAS::Default.  If no such address space exists, this 
> > may return None, and such optimizations will be disabled."
> I will change it. Also I think getConstantAddressSpace may be a better name 
> since we will return AST addr space.
Sorry, I typo'ed my original suggestion.  "pointers in this address space".



Comment at: lib/CodeGen/CGBlocks.cpp:1144
+ ? CGM.getNSConcreteGlobalBlock()
+ : CGM.getNullPointer(CGM.VoidPtrPtrTy,
+  QualType(CGM.getContext().VoidPtrTy)));

You used VoidPtrTy above.



Comment at: lib/CodeGen/CGExpr.cpp:342
+static Address createReferenceTemporary(CodeGenFunction &CGF,
+const TargetCodeGenInfo &TCG,
+const MaterializeTemporaryExpr *M,

Why are you passing the TargetCodeGenInfo down separately when it can be easily 
reacquired from the CodeGenFunction?

Oh, it looks like getTargetHooks() is private; there's no reason for that, just 
make it public.



Comment at: lib/CodeGen/CGExpr.cpp:372
+->getPointerTo(CGF.getContext().getTargetAddressSpace(
+LangAS::Default)));
+  // FIXME: Should we put the new global into a COMDAT?

GV->getValueType()->getPointerTo(...)



Comment at: lib/CodeGen/CodeGenModule.cpp:2549
+   AddrSpace == LangAS::opencl_local ||
+   AddrSpace >= LangAS::FirstTargetAddressSpace);
+return AddrSpace;

This does not seem like a very useful assertion.



Comment at: lib/CodeGen/CodeGenModule.cpp:2554
+  if (K == LanguageExpected)
+return D ? D->getType().getAddressSpace() : LangAS::Default;
+

I would expect this to be the general rule for all language modes.  Why is 
OpenCL an exception?

It looks to me like GetGlobalVarAddressSpace is only ever called with a 
possibly-null D by GetOrCreateLLVMGlobal, which is only called with a null D by 
CreateRuntimeVariable.  I expect that every call to CreateRuntimeVariable will 
probably need to be audited if it's going to suddenly start returning pointers 
that aren't in the default address space, and we'll probably end up needing 
some very different behavior at that point.  So for now, let's just move the 
LanguageExpected case out to the one call site that uses it.

I do like the simplification of just taking the declaration instead of taking 
that and an address space.



Comment at: lib/CodeGen/CodeGenModule.cpp:2571
+ AddrSpace >= LangAS::FirstTargetAddressSpace);
+  if (K == LanguageExpected || AddrSpace != LangAS::Default)
+return AddrSpace;

It's impossible for K to be LanguageExpected here, you already checked it above.



Comment at: lib/CodeGen/CodeGenModule.cpp:2578
+  }
+  return getTarget().getGlobalAddressSpace();
 }

Okay, I think I see what you're trying to do here: when you compile normal 
(i.e. non-OpenCL) code for your target, you want to implicitly change where 
global variables are allocated by default, then translate the pointer into 
LangAS::Default.  It's essentially the global-variable equivalent of what we're 
already doing with stack pointers.

The right way to do this is to make a hook on the TargetCodeGenInfo like 
getASTAllocaAddressSpace() which allows the target to override the address 
space for a global on a case-by-case basis.  You can then do whatever 
target-specific logic you need there, and you won't need to introduce 
getGlobalAddressSpace() on TargetInfo.  The default implementation, of course, 
will just return D->getType().getAddressSpace().



Comment at: lib/CodeGen/TargetInfo.cpp:7418
+  if (M.getLangOpts().OpenCL)
+appendOpenCLVersionMD(M);
 }

You have a couple things in this patch that just touch your target and are 
basically unrelated to the rest of your logic.  Please split those into a 
separate patch.


https://reviews.llvm.org/D33842



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.ll

[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-22 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: clang/docs/ThinLTO.rst:160
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap

Why do we document linker-specific option in clang docs? Is it usual?


https://reviews.llvm.org/D34546



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


[libcxx] r306083 - Implement inclusive_scan/transform_inclusive_scan for C++17.

2017-06-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Jun 23 00:12:42 2017
New Revision: 306083

URL: http://llvm.org/viewvc/llvm-project?rev=306083&view=rev
Log:
Implement inclusive_scan/transform_inclusive_scan for C++17.

Added:
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp
Modified:
libcxx/trunk/include/numeric

Modified: libcxx/trunk/include/numeric
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/numeric?rev=306083&r1=306082&r2=306083&view=diff
==
--- libcxx/trunk/include/numeric (original)
+++ libcxx/trunk/include/numeric Fri Jun 23 00:12:42 2017
@@ -81,6 +81,20 @@ template
+OutputIterator
+inclusive_scan(InputIterator first, InputIterator last, OutputIterator 
result);  // C++17
+
+template
+OutputIterator
+inclusive_scan(InputIterator first, InputIterator last,
+   OutputIterator result, BinaryOperation binary_op);  // C++17
+
+template
+OutputIterator
+inclusive_scan(InputIterator first, InputIterator last,
+   OutputIterator result, BinaryOperation binary_op, T init);  
// C++17
+
 template
 OutputIterator
@@ -88,6 +102,21 @@ template
+   OutputIterator
+   transform_inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result,
+ BinaryOperation binary_op, UnaryOperation 
unary_op);  // C++17
+  
+template
+   OutputIterator
+   transform_inclusive_scan(InputIterator first, InputIterator last,
+ OutputIterator result,
+ BinaryOperation binary_op, UnaryOperation 
unary_op,
+ T init);  // C++17
+
 template 
 OutputIterator
 adjacent_difference(InputIterator first, InputIterator last, 
OutputIterator result);
@@ -295,6 +324,38 @@ exclusive_scan(_InputIterator __first, _
 return _VSTD::exclusive_scan(__first, __last, __result, __init, 
_VSTD::plus<>());
 }
 
+template 
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, 
+   _OutputIterator __result, _BinaryOp __b,  _Tp 
__init)
+{
+for (; __first != __last; ++__first, (void) ++__result) {
+__init = __b(__init, *__first);
+*__result = __init;
+}
+return __result;
+}
+
+template 
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, 
+   _OutputIterator __result, _BinaryOp __b)
+{
+if (__first != __last) {
+typename std::iterator_traits<_InputIterator>::value_type __init = 
*__first;
+*__result++ = __init;
+if (++__first != __last)
+return _VSTD::inclusive_scan(__first, __last, __result, __b, 
__init);
+}
+
+return __result;
+}
+
+template 
+_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, 
+   _OutputIterator __result)
+{
+return _VSTD::inclusive_scan(__first, __last, __result, std::plus<>());
+}
+
 template 
 inline _LIBCPP_INLINE_VISIBILITY
@@ -316,6 +377,32 @@ transform_exclusive_scan(_InputIterator
 }
 return __result;
 }
+
+template 
+_OutputIterator transform_inclusive_scan(_InputIterator __first, 
_InputIterator __last, 
+   _OutputIterator __result, _BinaryOp __b, _UnaryOp 
__u, _Tp __init)
+{
+for (; __first != __last; ++__first, (void) ++__result) {
+__init = __b(__init, __u(*__first));
+*__result = __init;
+}
+
+return __result;
+}
+
+template 
+_OutputIterator transform_inclusive_scan(_InputIterator __first, 
_InputIterator __last, 
+   _OutputIterator __result, _BinaryOp __b, 
_UnaryOp __u)
+{
+if (__first != __last) {
+typename std::iterator_traits<_InputIterator>::value_type __init = 
__u(*__first);
+*__result++ = __init;
+if (++__first != __last)
+return _VSTD::transform_inclusive_scan(__first, __last, __result, 
__b, __u, __init);
+}
+
+return __result;
+}
 #endif
 
 template 

Added: 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp?rev=306083&view=aut

[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-22 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added inline comments.



Comment at: clang/docs/ThinLTO.rst:160
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap

mehdi_amini wrote:
> Why do we document linker-specific option in clang docs? Is it usual?
It does seem a little odd, but it's in the same place as the other 
linker-specific options above. I was also imagining that we would eventually 
make this into a clang driver option (similar to the cache location as you 
mentioned in D30522). At that point the clang docs would indeed be the right 
place to document it.


https://reviews.llvm.org/D34546



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


[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-22 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: clang/docs/ThinLTO.rst:160
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap

pcc wrote:
> mehdi_amini wrote:
> > Why do we document linker-specific option in clang docs? Is it usual?
> It does seem a little odd, but it's in the same place as the other 
> linker-specific options above. I was also imagining that we would eventually 
> make this into a clang driver option (similar to the cache location as you 
> mentioned in D30522). At that point the clang docs would indeed be the right 
> place to document it.
Fair!
I'll let Teresa look and approve.


https://reviews.llvm.org/D34546



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