[PATCH] D35068: Detect usages of unsafe I/O functions

2017-07-06 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel created this revision.

There are certain unsafe or deprecated (since C11) buffer handling
functions which should be avoided in safety critical code. They
could cause buffer overflows. Two new checks had been implemented
which warn for every occurrence of such functions
(unsafe or deprecated printf, scanf family and other buffer
handling functions, which now have a secure variant).


https://reviews.llvm.org/D35068

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/Driver/Tools.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  test/Analysis/security-syntax-checks.m

Index: test/Analysis/security-syntax-checks.m
===
--- test/Analysis/security-syntax-checks.m
+++ test/Analysis/security-syntax-checks.m
@@ -13,6 +13,9 @@
 # define BUILTIN(f) f
 #endif /* USE_BUILTINS */
 
+#include "Inputs/system-header-simulator-for-valist.h"
+#include "Inputs/system-header-simulator-for-simple-stream.h"
+
 typedef typeof(sizeof(int)) size_t;
 
 
@@ -202,3 +205,83 @@
   mkdtemp("XX");
 }
 
+
+//===--===
+// deprecated or unsafe buffer handling
+//===--===
+typedef int wchar_t;
+
+int sprintf(char *str, const char *format, ...);
+//int vsprintf (char *s, const char *format, va_list arg);
+int scanf(const char *format, ...);
+int wscanf(const wchar_t *format, ...);
+int fscanf(FILE *stream, const char *format, ...);
+int fwscanf(FILE *stream, const wchar_t *format, ...);
+int vscanf(const char *format, va_list arg);
+int vwscanf(const wchar_t *format, va_list arg);
+int vfscanf(FILE *stream, const char *format, va_list arg);
+int vfwscanf(FILE *stream, const wchar_t *format, va_list arg);
+int sscanf(const char *s, const char *format, ...);
+int swscanf(const wchar_t *ws, const wchar_t *format, ...);
+int vsscanf(const char *s, const char *format, va_list arg);
+int vswscanf(const wchar_t *ws, const wchar_t *format, va_list arg);
+int swprintf(wchar_t *ws, size_t len, const wchar_t *format, ...);
+int snprintf(char *s, size_t n, const char *format, ...);
+int vswprintf(wchar_t *ws, size_t len, const wchar_t *format, va_list arg);
+int vsnprintf(char *s, size_t n, const char *format, va_list arg);
+void *memcpy(void *destination, const void *source, size_t num);
+void *memmove(void *destination, const void *source, size_t num);
+char *strncpy(char *destination, const char *source, size_t num);
+char *strncat(char *destination, const char *source, size_t num);
+void *memset(void *ptr, int value, size_t num);
+
+void test_deprecated_or_unsafe_buffer_handling_1() {
+  char buf [5];
+  wchar_t wbuf [5];
+  int a;
+  FILE *file;
+  sprintf(buf, "a"); // expected-warning{{Using 'sprintf' is depracated as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions introduced in C11 standard that supports length arguments or provides boundary checks such as 'sprintf_s'}}
+  scanf("%d", ); // expected-warning{{Using 'scanf' is depracated as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions introduced in C11 standard that supports length arguments or provides boundary checks such as 'scanf_s'}}
+  scanf("%s", buf); // expected-warning{{Call to function 'scanf' is insecure as it does not provide bounding of the memory buffer. Replace with analogous functions that support length arguments or provides boundary checks such as 'scanf_s' in case of C11}} expected-warning{{Using 'scanf' is depracated as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions introduced in C11 standard that supports length arguments or provides boundary checks such as 'scanf_s'}}
+  scanf("%4s", buf); // expected-warning{{Using 'scanf' is depracated as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions introduced in C11 standard that supports length arguments or provides boundary checks such as 'scanf_s'}}
+  wscanf((const wchar_t*) L"%s", buf); // expected-warning{{Call to function 'wscanf' is insecure as it does not provide bounding of the memory buffer. Replace with analogous functions that support length arguments or provides boundary checks such as 'wscanf_s' in case of C11}} expected-warning{{Using 'wscanf' is depracated as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions introduced in C11 standard that supports length arguments or provides boundary checks such as 'wscanf_s'}}
+  fscanf(file, "%d", ); // expected-warning{{Using 'fscanf' is depracated as it does not provide bounding of the memory buffer or security checks 

[PATCH] D35068: Detect usages of unsafe I/O functions

2017-07-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

This does not do anything more than traversing the AST, shouldn't this be a 
clang-tidy check?
Also, i suspect CERT-MSC24-C 

 might be relevant




Comment at: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:607
+   << Name << "'";
+  out2 << "Using '" << Name << "' is depracated as it does not "
+ "provide bounding of the memory buffer or security "

depr*e*cated


https://reviews.llvm.org/D35068



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


[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:142
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;

arphaman wrote:
> erik.pilkington wrote:
> > Why are we doing this just for partials? Doesn't this also apply to 
> > unavailable/deprecated?
> We warned about the unavailable/deprecated protocols previously, so we should 
> probably keep these warnings. The unguarded availability one is new, so we 
> can drop it.
But this is strictly less diagnostics, dropping diagnostics for unavail/depr 
here won't break anything outside of clang tests. So if they don't make sense 
to emit, then there isn't any reason to keep them around.


Repository:
  rL LLVM

https://reviews.llvm.org/D35061



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


[PATCH] D33109: Enhance synchscope representation (clang)

2017-07-06 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added a comment.

In https://reviews.llvm.org/D33109#73, @mehdi_amini wrote:

> Make sure your commit message correctly reference the LLVM change.


Will do, thanks.


https://reviews.llvm.org/D33109



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


clang-format: Fix deref treated as binary op in throw

2017-07-06 Thread Erik Uhlmann via cfe-commits
When dereferencing a pointer in a throw statement, clang-format assigns 
TT_BinaryOperator to the star token, so it gets formatted as:

throw * x;

With this change the above becomes

throw *x;

Bug tracker: https://bugs.llvm.org/show_bug.cgi?id=33665

Attached is a patch containing the fix.



0001-Format-Fix-deref-treated-as-binary-op-in-throw.patch
Description: 0001-Format-Fix-deref-treated-as-binary-op-in-throw.patch
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 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!




Comment at: lib/Sema/SemaExpr.cpp:132
+   bool ObjCPropertyAccess,
+   bool AvoidAvailabilityChecks = false) {
   std::string Message;

`AvoidPartialAvailabilityChecks`?



Comment at: lib/Sema/SemaExpr.cpp:142
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;

arphaman wrote:
> erik.pilkington wrote:
> > arphaman wrote:
> > > erik.pilkington wrote:
> > > > Why are we doing this just for partials? Doesn't this also apply to 
> > > > unavailable/deprecated?
> > > We warned about the unavailable/deprecated protocols previously, so we 
> > > should probably keep these warnings. The unguarded availability one is 
> > > new, so we can drop it.
> > But this is strictly less diagnostics, dropping diagnostics for 
> > unavail/depr here won't break anything outside of clang tests. So if they 
> > don't make sense to emit, then there isn't any reason to keep them around.
> Swift emits warnings about deprecated/unavailable protocols even in the list 
> of protocol requirements. I'd prefer it if we had the same behaviour.
OK, I agree that we should conform to what swift does here.


Repository:
  rL LLVM

https://reviews.llvm.org/D35061



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


[PATCH] D35041: [analyzer] Fix modeling of bool based types

2017-07-06 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap added a comment.

thanks,

1. evalCastFromNonLoc is actually called there (and that's how i ran into this 
issue) because of (a bit unexpected to me) ImplicitCastExpr 'LValueToRValue' 
inside switch:  F3629685: Screen Shot 2017-07-06 at 11.01.39 AM.png 


(to be honest i don't know why Clang inserts this cast into AST here, but i 
have checked several versions of clang - the behavior is the same)

2. evalCastFromLoc - that's hard to me - so far i have not found a valid 
compilable c++ code to cast a pointer to bool enum.


Repository:
  rL LLVM

https://reviews.llvm.org/D35041



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


[PATCH] D33109: Enhance synchscope representation (clang)

2017-07-06 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl updated this revision to Diff 105499.
kzhuravl marked an inline comment as done.
kzhuravl added a comment.

Address review feedback.


https://reviews.llvm.org/D33109

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/ms-barriers-intrinsics.c

Index: test/CodeGen/ms-barriers-intrinsics.c
===
--- test/CodeGen/ms-barriers-intrinsics.c
+++ test/CodeGen/ms-barriers-intrinsics.c
@@ -13,19 +13,19 @@
 
 void test_ReadWriteBarrier() { _ReadWriteBarrier(); }
 // CHECK-LABEL: define void @test_ReadWriteBarrier
-// CHECK:   fence singlethread seq_cst
+// CHECK:   fence syncscope("singlethread") seq_cst
 // CHECK:   ret void
 // CHECK: }
 
 void test_ReadBarrier() { _ReadBarrier(); }
 // CHECK-LABEL: define void @test_ReadBarrier
-// CHECK:   fence singlethread seq_cst
+// CHECK:   fence syncscope("singlethread") seq_cst
 // CHECK:   ret void
 // CHECK: }
 
 void test_WriteBarrier() { _WriteBarrier(); }
 // CHECK-LABEL: define void @test_WriteBarrier
-// CHECK:   fence singlethread seq_cst
+// CHECK:   fence syncscope("singlethread") seq_cst
 // CHECK:   ret void
 // CHECK: }
 
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1810,12 +1810,12 @@
   case Builtin::BI__atomic_signal_fence:
   case Builtin::BI__c11_atomic_thread_fence:
   case Builtin::BI__c11_atomic_signal_fence: {
-llvm::SynchronizationScope Scope;
+llvm::SyncScope::ID SSID;
 if (BuiltinID == Builtin::BI__atomic_signal_fence ||
 BuiltinID == Builtin::BI__c11_atomic_signal_fence)
-  Scope = llvm::SingleThread;
+  SSID = llvm::SyncScope::SingleThread;
 else
-  Scope = llvm::CrossThread;
+  SSID = llvm::SyncScope::System;
 Value *Order = EmitScalarExpr(E->getArg(0));
 if (isa(Order)) {
   int ord = cast(Order)->getZExtValue();
@@ -1825,17 +1825,16 @@
 break;
   case 1:  // memory_order_consume
   case 2:  // memory_order_acquire
-Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
 break;
   case 3:  // memory_order_release
-Builder.CreateFence(llvm::AtomicOrdering::Release, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
 break;
   case 4:  // memory_order_acq_rel
-Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
 break;
   case 5:  // memory_order_seq_cst
-Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
-Scope);
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
 break;
   }
   return RValue::get(nullptr);
@@ -1852,23 +1851,23 @@
 llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB);
 
 Builder.SetInsertPoint(AcquireBB);
-Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
 Builder.CreateBr(ContBB);
 SI->addCase(Builder.getInt32(1), AcquireBB);
 SI->addCase(Builder.getInt32(2), AcquireBB);
 
 Builder.SetInsertPoint(ReleaseBB);
-Builder.CreateFence(llvm::AtomicOrdering::Release, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
 Builder.CreateBr(ContBB);
 SI->addCase(Builder.getInt32(3), ReleaseBB);
 
 Builder.SetInsertPoint(AcqRelBB);
-Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
 Builder.CreateBr(ContBB);
 SI->addCase(Builder.getInt32(4), AcqRelBB);
 
 Builder.SetInsertPoint(SeqCstBB);
-Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, Scope);
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
 Builder.CreateBr(ContBB);
 SI->addCase(Builder.getInt32(5), SeqCstBB);
 
@@ -8208,13 +8207,13 @@
 
   case X86::BI__faststorefence: {
 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
-   llvm::CrossThread);
+   llvm::SyncScope::System);
   }
   case X86::BI_ReadWriteBarrier:
   case X86::BI_ReadBarrier:
   case X86::BI_WriteBarrier: {
 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
-   llvm::SingleThread);
+   llvm::SyncScope::SingleThread);
   }
   case X86::BI_BitScanForward:
   case X86::BI_BitScanForward64:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35069: [Frontend] Verify that the bitstream is not empty before reading the serialised diagnostics

2017-07-06 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

Clang should avoid calling `report_fatal_error` when the file with the 
serialised diagnostics is empty. This patch changes Clang's serialised 
diagnostic reader, now it reports an appropriate error instead of crashing.


Repository:
  rL LLVM

https://reviews.llvm.org/D35069

Files:
  lib/Frontend/SerializedDiagnosticReader.cpp
  test/Index/Inputs/empty.dia
  test/Index/read-empty-diags.test


Index: test/Index/read-empty-diags.test
===
--- /dev/null
+++ test/Index/read-empty-diags.test
@@ -0,0 +1,2 @@
+// RUN: not c-index-test -read-diagnostics %S/Inputs/empty.dia 2>&1 | 
FileCheck %s
+// CHECK: Trouble deserializing file (Invalid File): Invalid diagnostics 
signature
Index: lib/Frontend/SerializedDiagnosticReader.cpp
===
--- lib/Frontend/SerializedDiagnosticReader.cpp
+++ lib/Frontend/SerializedDiagnosticReader.cpp
@@ -27,6 +27,9 @@
   llvm::BitstreamCursor Stream(**Buffer);
   Optional BlockInfo;
 
+  if (Stream.AtEndOfStream())
+return SDError::InvalidSignature;
+
   // Sniff for the signature.
   if (Stream.Read(8) != 'D' ||
   Stream.Read(8) != 'I' ||


Index: test/Index/read-empty-diags.test
===
--- /dev/null
+++ test/Index/read-empty-diags.test
@@ -0,0 +1,2 @@
+// RUN: not c-index-test -read-diagnostics %S/Inputs/empty.dia 2>&1 | FileCheck %s
+// CHECK: Trouble deserializing file (Invalid File): Invalid diagnostics signature
Index: lib/Frontend/SerializedDiagnosticReader.cpp
===
--- lib/Frontend/SerializedDiagnosticReader.cpp
+++ lib/Frontend/SerializedDiagnosticReader.cpp
@@ -27,6 +27,9 @@
   llvm::BitstreamCursor Stream(**Buffer);
   Optional BlockInfo;
 
+  if (Stream.AtEndOfStream())
+return SDError::InvalidSignature;
+
   // Sniff for the signature.
   if (Stream.Read(8) != 'D' ||
   Stream.Read(8) != 'I' ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35041: [analyzer] Fix modeling of bool based types

2017-07-06 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap added a comment.

>> In https://reviews.llvm.org/D35041#801073, @alexshap wrote:
>> evalCastFromNonLoc is actually called there (and that's how i ran into this 
>> issue) because of (a bit unexpected to me) ImplicitCastExpr 'LValueToRValue' 
>> inside switch
> 
> Yeah, but the NonLoc that's being casted is definitely not 
> nonloc::LocAsInteger.

yea, you are right, sorry about the confusion.


Repository:
  rL LLVM

https://reviews.llvm.org/D35041



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


[PATCH] D35082: [WIP][OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.

Currently Clang uses default address space (0) to represent private address 
space for OpenCL
in AST. There are two issues with this:

1. The error message is confusing since it will output a private pointer as a 
pointer without

address space.

2. There is no mangling for default address space. For example, if `private 
int*` is emitted as

`i32 addrspace(5)*` in IR. It is supposed to be mangled as `PUAS5i` but it is 
mangled as
`Pi` instead.

This patch attempts to represent OpenCL private address space explicitly in 
AST. It adds
a new enum LangAS::opencl_private and adds it to the variable types which are 
implicitly
private:

  automatic variables without address space qualifier
  
  function parameter
  
  pointee type without address space qualifier (OpenCL 1.2 and below)

This is a work in progress for preview.


https://reviews.llvm.org/D35082

Files:
  include/clang/Basic/AddressSpaces.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/address-spaces-mangling.cl
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl

Index: test/SemaOpenCL/address-spaces.cl
===
--- test/SemaOpenCL/address-spaces.cl
+++ test/SemaOpenCL/address-spaces.cl
@@ -17,21 +17,21 @@
   g = (global int*) l;// expected-error {{casting '__local int *' to type '__global int *' changes address space of pointer}}
   g = (global int*) c;// expected-error {{casting '__constant int *' to type '__global int *' changes address space of pointer}}
   g = (global int*) cc;   // expected-error {{casting 'const __constant int *' to type '__global int *' changes address space of pointer}}
-  g = (global int*) p;// expected-error {{casting 'int *' to type '__global int *' changes address space of pointer}}
+  g = (global int*) p;// expected-error {{casting '__private int *' to type '__global int *' changes address space of pointer}}
 
   l = (local int*) g; // expected-error {{casting '__global int *' to type '__local int *' changes address space of pointer}}
   l = (local int*) c; // expected-error {{casting '__constant int *' to type '__local int *' changes address space of pointer}}
   l = (local int*) cc;// expected-error {{casting 'const __constant int *' to type '__local int *' changes address space of pointer}}
-  l = (local int*) p; // expected-error {{casting 'int *' to type '__local int *' changes address space of pointer}}
+  l = (local int*) p; // expected-error {{casting '__private int *' to type '__local int *' changes address space of pointer}}
 
   c = (constant int*) g;  // expected-error {{casting '__global int *' to type '__constant int *' changes address space of pointer}}
   c = (constant int*) l;  // expected-error {{casting '__local int *' to type '__constant int *' changes address space of pointer}}
-  c = (constant int*) p;  // expected-error {{casting 'int *' to type '__constant int *' changes address space of pointer}}
+  c = (constant int*) p;  // expected-error {{casting '__private int *' to type '__constant int *' changes address space of pointer}}
 
-  p = (private int*) g;   // expected-error {{casting '__global int *' to type 'int *' changes address space of pointer}}
-  p = (private int*) l;   // expected-error {{casting '__local int *' to type 'int *' changes address space of pointer}}
-  p = (private int*) c;   // expected-error {{casting '__constant int *' to type 'int *' changes address space of pointer}}
-  p = (private int*) cc;  // expected-error {{casting 'const __constant int *' to type 'int *' changes address space of pointer}}
+  p = (private int*) g;   // expected-error {{casting '__global int *' to type '__private int *' changes address space of pointer}}
+  p = (private int*) l;   // expected-error {{casting '__local int *' to type '__private int *' changes address space of pointer}}
+  p = (private int*) c;   // expected-error {{casting '__constant int *' to type '__private int *' changes address space of pointer}}
+  p = (private int*) cc;  // expected-error {{casting 'const __constant int *' to type '__private int *' changes address space of pointer}}
 }
 
 void ok_explicit_casts(global int *g, global int* g2, local int* l, local int* l2, private int* p, private int* p2)
Index: test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
===
--- test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
+++ test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
@@ -76,7 +76,7 @@
 
   AS int *var_init4 = arg_priv;
 #ifndef GENERIC
-// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}}
+// expected-error-re@-2{{initializing '__{{global|constant}} int *' 

[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:142
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;

erik.pilkington wrote:
> Why are we doing this just for partials? Doesn't this also apply to 
> unavailable/deprecated?
We warned about the unavailable/deprecated protocols previously, so we should 
probably keep these warnings. The unguarded availability one is new, so we can 
drop it.


Repository:
  rL LLVM

https://reviews.llvm.org/D35061



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


[PATCH] D35078: [clang-tidy] Fix modernize-use-override incorrect replacement

2017-07-06 Thread Victor Gao via Phabricator via cfe-commits
vgao created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

For the following code: `modernize-use-override` generates a replacement with 
incorrect location.

  struct IntPair
  {
int first, second;
  };
  
  struct A
  {
virtual void il(IntPair);
  };
  
  struct B : A
  {
void il(IntPair p = {1, (2 + 3)}) {};
// Generated Fixit: void il(IntPair p = override {1, (2 + 3)}) {};
// Should be: void il(IntPair p = {1, (2 + 3)}) override {};
  };

This fixes that and adds a unit test.


Repository:
  rL LLVM

https://reviews.llvm.org/D35078

Files:
  clang-tidy/modernize/UseOverrideCheck.cpp
  test/clang-tidy/modernize-use-override.cpp


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -12,6 +12,10 @@
 
 struct MUST_USE_RESULT MustUseResultObject {};
 
+struct IntPair {
+  int First, Second;
+};
+
 struct Base {
   virtual ~Base() {}
   virtual void a();
@@ -41,6 +45,8 @@
 
   virtual void ne() noexcept(false);
   virtual void t() throw();
+
+  virtual void il(IntPair);
 };
 
 struct SimpleCases : public Base {
@@ -221,6 +227,14 @@
   // CHECK-FIXES: {{^}}  void cv2() const volatile override // some comment
 };
 
+struct DefaultArguments : public Base {
+  // Tests for default arguments (with initializer lists).
+  // Make sure the override fix is placed after the argument list.
+  void il(IntPair p = {1, (2 + (3))}) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void il(IntPair p = {1, (2 + (3))}) override {}
+};
+
 struct Macros : public Base {
   // Tests for 'virtual' and 'override' being defined through macros. Basically
   // give up for now.
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@
  File.end());
   SmallVector Tokens;
   Token Tok;
+  int Parens = 0;
   while (!RawLexer.LexFromRawLexer(Tok)) {
-if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && !Parens)
   break;
 if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
   break;
+if (Tok.is(tok::l_paren))
+  ++Parens;
+else if (Tok.is(tok::r_paren))
+  --Parens;
 if (Tok.is(tok::raw_identifier)) {
   IdentifierInfo  = Result.Context->Idents.get(StringRef(
   Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -12,6 +12,10 @@
 
 struct MUST_USE_RESULT MustUseResultObject {};
 
+struct IntPair {
+  int First, Second;
+};
+
 struct Base {
   virtual ~Base() {}
   virtual void a();
@@ -41,6 +45,8 @@
 
   virtual void ne() noexcept(false);
   virtual void t() throw();
+
+  virtual void il(IntPair);
 };
 
 struct SimpleCases : public Base {
@@ -221,6 +227,14 @@
   // CHECK-FIXES: {{^}}  void cv2() const volatile override // some comment
 };
 
+struct DefaultArguments : public Base {
+  // Tests for default arguments (with initializer lists).
+  // Make sure the override fix is placed after the argument list.
+  void il(IntPair p = {1, (2 + (3))}) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void il(IntPair p = {1, (2 + (3))}) override {}
+};
+
 struct Macros : public Base {
   // Tests for 'virtual' and 'override' being defined through macros. Basically
   // give up for now.
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@
  File.end());
   SmallVector Tokens;
   Token Tok;
+  int Parens = 0;
   while (!RawLexer.LexFromRawLexer(Tok)) {
-if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && !Parens)
   break;
 if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
   break;
+if (Tok.is(tok::l_paren))
+  ++Parens;
+else if (Tok.is(tok::r_paren))
+  --Parens;
 if (Tok.is(tok::raw_identifier)) {
   IdentifierInfo  = Result.Context->Idents.get(StringRef(
   Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34860: [Objective-C] Fix non-determinism in clang

2017-07-06 Thread Mandeep Singh Grang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307296:  [Objective-C] Fix non-determinism in clang 
(authored by mgrang).

Changed prior to commit:
  https://reviews.llvm.org/D34860?vs=104811=105498#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34860

Files:
  cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm


Index: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
===
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -146,7 +146,7 @@
 
 llvm::DenseMap RewrittenBlockExprs;
 llvm::DenseMap > ReferencedIvars;
+llvm::SmallSetVector > ReferencedIvars;
 
 // ivar bitfield grouping containers
 llvm::DenseSet ObjCInterefaceHasBitfieldGroups;
@@ -1013,7 +1013,7 @@
 Setr = "\nextern \"C\" __declspec(dllimport) "
 "void objc_setProperty (id, SEL, long, id, bool, bool);\n";
   }
-  
+
   RewriteObjCMethodDecl(OID->getContainingInterface(), 
 PD->getSetterMethodDecl(), Setr);
   Setr += "{ ";
@@ -3965,10 +3965,11 @@
   std::string ) {
   // write out ivar offset symbols which have been referenced in an ivar
   // access expression.
-  llvm::SmallPtrSet Ivars = ReferencedIvars[CDecl];
+  llvm::SmallSetVector Ivars = ReferencedIvars[CDecl];
+
   if (Ivars.empty())
 return;
-  
+
   llvm::DenseSet 
GroupSymbolOutput;
   for (ObjCIvarDecl *IvarDecl : Ivars) {
 const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface();
Index: cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
===
--- cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
+++ cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
@@ -0,0 +1,45 @@
+// REQUIRES: abi-breaking-checks
+// NOTE: This test has been split from objc-modern-metadata-visibility.mm in
+// order to test with -reverse-iterate as this flag is only present with
+// ABI_BREAKING_CHECKS.
+
+// RUN: %clang_cc1 -E %s -o %t.mm -mllvm -reverse-iterate
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc 
%t.mm -mllvm -reverse-iterate -o - | FileCheck %s
+// rdar://11144048
+
+@class NSString;
+
+@interface NSObject {
+Class isa;
+}
+@end
+
+@interface Sub : NSObject {
+int subIvar;
+NSString *nsstring;
+@private
+id PrivateIvar;
+}
+@end
+
+@implementation Sub
+- (id) MyNSString { return subIvar ? PrivateIvar : nsstring; }
+@end
+
+@interface NSString @end
+@implementation NSString @end
+
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$subIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long 
OBJC_IVAR_$_Sub$PrivateIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$nsstring;
+// CHECK: #pragma warning(disable:4273)
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$subIvar
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$nsstring
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long int 
OBJC_IVAR_$_Sub$PrivateIvar
+// CHECK: extern "C" __declspec(dllimport) struct _class_t 
OBJC_METACLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_Sub
+// CHECK: extern "C" __declspec(dllimport) struct _class_t 
OBJC_CLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_Sub
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_CLASS_$_NSString;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_METACLASS_$_NSString
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_CLASS_$_NSString


Index: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
===
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -146,7 +146,7 @@
 
 llvm::DenseMap RewrittenBlockExprs;
 llvm::DenseMap > ReferencedIvars;
+llvm::SmallSetVector > ReferencedIvars;
 
 // ivar bitfield grouping containers
 llvm::DenseSet ObjCInterefaceHasBitfieldGroups;
@@ -1013,7 +1013,7 @@
 Setr = "\nextern \"C\" __declspec(dllimport) "
 "void objc_setProperty (id, SEL, long, id, bool, bool);\n";
   }
-  
+
   RewriteObjCMethodDecl(OID->getContainingInterface(), 
 PD->getSetterMethodDecl(), Setr);
   Setr += "{ ";
@@ -3965,10 +3965,11 @@
   std::string ) {
   // write out 

[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
Herald added a subscriber: inglorion.

When combining modules with entries that allow multiple definitions,
the combined index can contain multiple summaries for a single GUID.
Unless I miss something here, we should be able to continue by just
picking the first summary,  if all entries in the list allow
multiple definitions.

I am not sure if we should relax the assertion here or select a single
summary when building the index?


https://reviews.llvm.org/D35081

Files:
  lib/CodeGen/BackendUtil.cpp


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -56,6 +56,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
+#include 
 #include 
 using namespace clang;
 using namespace llvm;
@@ -1014,8 +1015,18 @@
   continue;
 
 auto GUID = GlobalList.first;
-assert(GlobalList.second.SummaryList.size() == 1 &&
-   "Expected individual combined index to have one summary per GUID");
+auto  = GlobalList.second.SummaryList;
+auto MultipleDefPred = [](std::unique_ptr ) {
+auto Linkage = S->linkage();
+return GlobalValue::isAvailableExternallyLinkage(Linkage) ||
+   GlobalValue::isLinkOnceODRLinkage(Linkage) ||
+   GlobalValue::isWeakODRLinkage(Linkage);
+};
+assert((SummaryList.size() == 1 || (SummaryList.size() > 1 &&
+std::all_of(SummaryList.begin(), SummaryList.end(),
+MultipleDefPred))) &&
+   "Expected individual combined index to have one summary per GUID or 
"
+   "multiple entries if the allow multiple definitions.");
 auto  = GlobalList.second.SummaryList[0];
 // Skip the summaries for the importing module. These are included to
 // e.g. record required linkage changes.


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -56,6 +56,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
+#include 
 #include 
 using namespace clang;
 using namespace llvm;
@@ -1014,8 +1015,18 @@
   continue;
 
 auto GUID = GlobalList.first;
-assert(GlobalList.second.SummaryList.size() == 1 &&
-   "Expected individual combined index to have one summary per GUID");
+auto  = GlobalList.second.SummaryList;
+auto MultipleDefPred = [](std::unique_ptr ) {
+auto Linkage = S->linkage();
+return GlobalValue::isAvailableExternallyLinkage(Linkage) ||
+   GlobalValue::isLinkOnceODRLinkage(Linkage) ||
+   GlobalValue::isWeakODRLinkage(Linkage);
+};
+assert((SummaryList.size() == 1 || (SummaryList.size() > 1 &&
+std::all_of(SummaryList.begin(), SummaryList.end(),
+MultipleDefPred))) &&
+   "Expected individual combined index to have one summary per GUID or "
+   "multiple entries if the allow multiple definitions.");
 auto  = GlobalList.second.SummaryList[0];
 // Skip the summaries for the importing module. These are included to
 // e.g. record required linkage changes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r307175 - [Sema] Don't allow -Wunguarded-availability to be silenced with redecls

2017-07-06 Thread Nico Weber via cfe-commits
We currently rely on this for chromium; that's how the warning used to work
when I added it. What's the transition plan? Can we have a flag to
incrementally transition to whatever the new way is? (Is it documented
anywhere?)

Also, I think the replacement somehow needs the new runtime stuff from
libbuiltin -- does the driver know when to add that to the link line? If
so, where's the logic for that? If not, what library is supposed to provide
the runtime check function?

On Jul 5, 2017 7:09 PM, "Erik Pilkington via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: epilk
Date: Wed Jul  5 10:08:56 2017
New Revision: 307175

URL: http://llvm.org/viewvc/llvm-project?rev=307175=rev
Log:
[Sema] Don't allow -Wunguarded-availability to be silenced with redecls

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/attr-availability.c
cfe/trunk/test/Sema/attr-deprecated.c
cfe/trunk/test/Sema/attr-unavailable-message.c
cfe/trunk/test/SemaCXX/attr-deprecated.cpp
cfe/trunk/test/SemaObjC/attr-availability.m
cfe/trunk/test/SemaObjC/unguarded-availability-new.m
cfe/trunk/test/SemaObjC/unguarded-availability.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
DiagnosticSemaKinds.td?rev=307175=307174=307175=diff

==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul  5
10:08:56 2017
@@ -2880,7 +2880,7 @@ def warn_partial_availability : Warning<
 def warn_partial_availability_new : Warning,
   InGroup;
 def note_partial_availability_silence : Note<
-  "explicitly redeclare %0 to silence this warning">;
+  "annotate %select{%1|anonymous %1}0 with an availability attribute to
silence">;
 def note_unguarded_available_silence : Note<
   "enclose %0 in %select{an @available|a __builtin_available}1 check to
silence"
   " this warning">;

Modified: cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
clang/Sema/DelayedDiagnostic.h?rev=307175=307174=307175=diff

==
--- cfe/trunk/include/clang/Sema/DelayedDiagnostic.h (original)
+++ cfe/trunk/include/clang/Sema/DelayedDiagnostic.h Wed Jul  5 10:08:56
2017
@@ -124,7 +124,8 @@ public:

   static DelayedDiagnostic makeAvailability(AvailabilityResult AR,
 SourceLocation Loc,
-const NamedDecl *D,
+const NamedDecl *ReferringDecl,
+const NamedDecl *OffendingDecl,
 const ObjCInterfaceDecl
*UnknownObjCClass,
 const ObjCPropertyDecl
*ObjCProperty,
 StringRef Msg,
@@ -164,9 +165,13 @@ public:
 return *reinterpret_cast(AccessData);
   }

-  const NamedDecl *getAvailabilityDecl() const {
+  const NamedDecl *getAvailabilityReferringDecl() const {
 assert(Kind == Availability && "Not an availability diagnostic.");
-return AvailabilityData.Decl;
+return AvailabilityData.ReferringDecl;
+  }
+
+  const NamedDecl *getAvailabilityOffendingDecl() const {
+return AvailabilityData.OffendingDecl;
   }

   StringRef getAvailabilityMessage() const {
@@ -213,7 +218,8 @@ public:
 private:

   struct AD {
-const NamedDecl *Decl;
+const NamedDecl *ReferringDecl;
+const NamedDecl *OffendingDecl;
 const ObjCInterfaceDecl *UnknownObjCClass;
 const ObjCPropertyDecl  *ObjCProperty;
 const char *Message;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
clang/Sema/Sema.h?rev=307175=307174=307175=diff

==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jul  5 10:08:56 2017
@@ -3881,7 +3881,9 @@ public:

   void redelayDiagnostics(sema::DelayedDiagnosticPool );

-  void EmitAvailabilityWarning(AvailabilityResult AR, NamedDecl *D,
+  void EmitAvailabilityWarning(AvailabilityResult AR,
+   const NamedDecl *ReferringDecl,
+   const NamedDecl *OffendingDecl,
StringRef Message, SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass,
const 

[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-06 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

How are you invoking this? Typically this path is invoked for distributed 
builds, when the individual index files for each backend were written during 
the thin link (e.g. via gold plugin's -thinlto-index-only option). In that 
case, we only expect a single summary to exist per GUID, since it is indicating 
which copy to import. We don't typically pass in the entire combined index 
(which would cause other issues as I believe we are simply importing every 
summary in the index on this path).


https://reviews.llvm.org/D35081



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


[PATCH] D34158: to support gcc 4.8 (and newer) compatibility on Linux, preinclude

2017-07-06 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 105526.
mibintc added a comment.

I rewrote the patch the way that Richard suggested, adding a cc1 option 
"finclude-if-exists" and injecting #if __has_include etc. [OK to use finclude? 
include-if-exists preferred?]
I responded to James' remarks and removed the gcc version check. 
Does this look better?


https://reviews.llvm.org/D34158

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Linux.cpp
  lib/Driver/ToolChains/Linux.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/Inputs/stdc-predef/bin/.keep
  test/Driver/Inputs/stdc-predef/usr/i386-unknown-linux/lib/.keep
  test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  test/Driver/Inputs/stdc-predef/usr/lib/.keep
  test/Driver/Inputs/stdc-predef/usr/x86_64-unknown-linux/lib/.keep
  test/Driver/clang_cpp.c
  test/Driver/crash report spaces.c
  test/Driver/crash-report-header.h
  test/Driver/crash-report.c
  test/Driver/gcc-predef-not.c
  test/Driver/gcc-predef.c
  test/Driver/rewrite-map-in-diagnostics.c
  test/Index/IBOutletCollection.m
  test/Index/annotate-macro-args.m
  test/Index/annotate-tokens-pp.c
  test/Index/annotate-tokens.c
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor-macro-args.m
  test/Index/get-cursor.cpp
  test/Preprocessor/ignore-pragmas.c
  unittests/Tooling/TestVisitor.h

Index: lib/Driver/ToolChains/Linux.h
===
--- lib/Driver/ToolChains/Linux.h
+++ lib/Driver/ToolChains/Linux.h
@@ -31,6 +31,8 @@
   void addLibStdCxxIncludePaths(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
+  void AddGnuIncludeArgs(const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const;
   void AddCudaIncludeArgs(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
   void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -705,6 +705,8 @@
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
 
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
+
+  AddGnuIncludeArgs(DriverArgs, CC1Args);
 }
 
 static std::string DetectLibcxxIncludePath(StringRef base) {
@@ -743,6 +745,20 @@
   return "";
 }
 
+void Linux::AddGnuIncludeArgs(const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const {
+  if (GCCInstallation.isValid()) {
+if (!DriverArgs.hasArg(options::OPT_ffreestanding) &&
+!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) {
+  // For gcc compatibility, clang will preinclude 
+  // -ffreestanding suppresses this behavior.
+  CC1Args.push_back("-finclude-if-exists");
+  CC1Args.push_back("stdc-predef.h");
+}
+  }
+}
+
+
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ) const {
   // We need a detected GCC installation on Linux to provide libstdc++'s
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2425,6 +2425,10 @@
   for (const Arg *A : Args.filtered(OPT_chain_include))
 Opts.ChainedIncludes.emplace_back(A->getValue());
 
+  // Add the ordered list of -finclude-if-exists.
+  for (const Arg *A : Args.filtered(OPT_finclude_if_exists))
+Opts.FIncludeIfExists.emplace_back(A->getValue());
+
   for (const Arg *A : Args.filtered(OPT_remap_file)) {
 std::pair Split = StringRef(A->getValue()).split(';');
 
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -69,6 +69,12 @@
   Builder.append(Twine("#include \"") + File + "\"");
 }
 
+static void AddImplicitIncludeIfExists(MacroBuilder , StringRef File) {
+  Builder.append(Twine("#if __has_include( \"") + File + "\")");
+  Builder.append(Twine("#include \"") + File + "\"");
+  Builder.append(Twine("#endif"));
+}
+
 static void AddImplicitIncludeMacros(MacroBuilder , StringRef File) {
   Builder.append(Twine("#__include_macros \"") + File + "\"");
   // Marker token to stop the __include_macros fetch loop.
@@ -1088,6 +1094,12 @@
   // Exit the command line and go back to  (2 is LC_LEAVE).
   if (!PP.getLangOpts().AsmPreprocessor)
 Builder.append("# 1 \"\" 2");
+  
+  // Process -finclude-if-exists directives.
+  for (unsigned i = 0, e = InitOpts.FIncludeIfExists.size(); i != e; ++i) {
+const std::string  = InitOpts.FIncludeIfExists[i];
+AddImplicitIncludeIfExists(Builder, Path);
+  }
 
   // If -imacros are 

[PATCH] D35069: [Frontend] Verify that the bitstream is not empty before reading the serialised diagnostics

2017-07-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D35069



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


r307315 - Allow CompilerInvocations to generate .d files.

2017-07-06 Thread Sterling Augustine via cfe-commits
Author: saugustine
Date: Thu Jul  6 14:02:52 2017
New Revision: 307315

URL: http://llvm.org/viewvc/llvm-project?rev=307315=rev
Log:
Allow CompilerInvocations to generate .d files.

Summary:
Most clang tools should ignore the -M
family of options because one wouldn't want them
to generate a new dependency (.d) file. However,
some tools may want this dependency file. This
patch creates a mechanism for them to do this.

This implementation just plumbs a boolean down
several layers of calls. Each of the modified calls
has several call sites, and so a single member
variable or new API entry point won't work.

An alternative would be to write a function to filter
the -M family of arguments out of CC1Args, and have
each caller call that function by hand before calling
newInvocation, Invocation::run, or buildAstFromCodeWithArgs.
This is a more complicated and error-prone solution.
Why burden all the callers to remember to use
this function?

But I could rewrite this patch to use that method if
that is deemed more appropriate.

Reviewers: klimek

Reviewed By: klimek

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h?rev=307315=307314=307315=diff
==
--- cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h (original)
+++ cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h Thu Jul  6 14:02:52 
2017
@@ -44,6 +44,10 @@ ArgumentsAdjuster getClangSyntaxOnlyAdju
 /// arguments.
 ArgumentsAdjuster getClangStripOutputAdjuster();
 
+/// \brief Gets an argument adjuster which removes dependency-file
+/// related command line arguments.
+ArgumentsAdjuster getClangStripDependencyFileAdjuster();
+
 enum class ArgumentInsertPosition { BEGIN, END };
 
 /// \brief Gets an argument adjuster which inserts \p Extra arguments in the

Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=307315=307314=307315=diff
==
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Thu Jul  6 14:02:52 2017
@@ -202,12 +202,15 @@ buildASTFromCode(const Twine , cons
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
+/// \param Adjuster A function to filter the command line arguments as 
specified.
+///
 /// \return The resulting AST or null if an error occurred.
 std::unique_ptr buildASTFromCodeWithArgs(
 const Twine , const std::vector ,
 const Twine  = "input.cc", const Twine  = "clang-tool",
 std::shared_ptr PCHContainerOps =
-std::make_shared());
+  std::make_shared(),
+ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster());
 
 /// \brief Utility to run a FrontendAction in a single clang invocation.
 class ToolInvocation {

Modified: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp?rev=307315=307314=307315=diff
==
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp (original)
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Thu Jul  6 14:02:52 2017
@@ -42,7 +42,7 @@ ArgumentsAdjuster getClangStripOutputAdj
 AdjustedArgs.push_back(Args[i]);
 
   if (Arg == "-o") {
-// Output is specified as -o foo. Skip the next argument also.
+// Output is specified as -o foo. Skip the next argument too.
 ++i;
   }
   // Else, the output is specified as -ofoo. Just do nothing.
@@ -51,6 +51,26 @@ ArgumentsAdjuster getClangStripOutputAdj
   };
 }
 
+ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
+  return [](const CommandLineArguments , StringRef /*unused*/) {
+CommandLineArguments AdjustedArgs;
+for (size_t i = 0, e = Args.size(); i < e; ++i) {
+  StringRef Arg = Args[i];
+  // All dependency-file options begin with -M. These include -MM,
+  // -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
+  if (!Arg.startswith("-M"))
+AdjustedArgs.push_back(Args[i]);
+
+  if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
+  (Arg == "-MD") || (Arg == "-MMD")) {
+// Output is specified as -MX foo. Skip the next argument also.
+++i;
+  }
+}
+return AdjustedArgs;
+  };
+}
+
 ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments ,
 ArgumentInsertPosition Pos) {
   return 

Re: r307175 - [Sema] Don't allow -Wunguarded-availability to be silenced with redecls

2017-07-06 Thread Erik Pilkington via cfe-commits



On 7/6/17 2:12 PM, Nico Weber wrote:
We currently rely on this for chromium; that's how the warning used to 
work when I added it. What's the transition plan? Can we have a flag 
to incrementally transition to whatever the new way is? (Is it 
documented anywhere?)
We currently have -Wunguarded-availability-new, which only warns for 
things introduced as of macOS 10.13. If you switch to that flag then you 
won't get warnings for code that used the redecl thing before 10.13, 
anything that uses APIs newer than that should either use @available or 
annotate the context declaration with an availability attribute. This is 
"documented" at the start of this wwdc talk: 
https://developer.apple.com/videos/play/wwdc2017/411/


-Wunguarded-availability-new is somewhat unfortunate in that it won't 
catch new code that you write today that uses older APIs, but maybe you 
can use it and slowly change the redecl thing you have to use 
@available/availability attributes then turn -Wunguarded-availability 
back on when that is done.
Also, I think the replacement somehow needs the new runtime stuff from 
libbuiltin -- does the driver know when to add that to the link line? 
If so, where's the logic for that? If not, what library is supposed to 
provide the runtime check function?
The runtime component (__isOSVersionAtLeast) is in compiler-rt/builtins. 
Are you having problems linking with it?


Erik


On Jul 5, 2017 7:09 PM, "Erik Pilkington via cfe-commits" 
> wrote:


Author: epilk
Date: Wed Jul  5 10:08:56 2017
New Revision: 307175

URL: http://llvm.org/viewvc/llvm-project?rev=307175=rev

Log:
[Sema] Don't allow -Wunguarded-availability to be silenced with
redecls

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/attr-availability.c
cfe/trunk/test/Sema/attr-deprecated.c
cfe/trunk/test/Sema/attr-unavailable-message.c
cfe/trunk/test/SemaCXX/attr-deprecated.cpp
cfe/trunk/test/SemaObjC/attr-availability.m
cfe/trunk/test/SemaObjC/unguarded-availability-new.m
cfe/trunk/test/SemaObjC/unguarded-availability.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307175=307174=307175=diff



==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul 
5 10:08:56 2017

@@ -2880,7 +2880,7 @@ def warn_partial_availability : Warning<
 def warn_partial_availability_new :
Warning,
   InGroup;
 def note_partial_availability_silence : Note<
-  "explicitly redeclare %0 to silence this warning">;
+  "annotate %select{%1|anonymous %1}0 with an availability
attribute to silence">;
 def note_unguarded_available_silence : Note<
   "enclose %0 in %select{an @available|a __builtin_available}1
check to silence"
   " this warning">;

Modified: cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DelayedDiagnostic.h?rev=307175=307174=307175=diff



==
--- cfe/trunk/include/clang/Sema/DelayedDiagnostic.h (original)
+++ cfe/trunk/include/clang/Sema/DelayedDiagnostic.h Wed Jul  5
10:08:56 2017
@@ -124,7 +124,8 @@ public:

   static DelayedDiagnostic makeAvailability(AvailabilityResult AR,
 SourceLocation Loc,
-const NamedDecl *D,
+const NamedDecl
*ReferringDecl,
+const NamedDecl
*OffendingDecl,
 const
ObjCInterfaceDecl *UnknownObjCClass,
 const
ObjCPropertyDecl  *ObjCProperty,
 StringRef Msg,
@@ -164,9 +165,13 @@ public:
 return *reinterpret_cast(AccessData);
   }

- 

[PATCH] D34158: to support gcc 4.8 (and newer) compatibility on Linux, preinclude

2017-07-06 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: lib/Driver/ToolChains/Linux.cpp:755
+!Version.isOlderThan(4, 8, 0)) {
+  // For gcc >= 4.8.x, clang will preinclude 
+  // -ffreestanding suppresses this behavior.

jyknight wrote:
> I don't see why it makes any sense to condition this based on a GCC 
> installation existing and being >= 4.8, since this header comes from libc, 
> and is necessary for standards compliance even if there's absolutely no GCC 
> installed or involved.
> 
> Additionally, something like this -- a way for the libc to be involved in 
> setting up predefined macros -- seems probably necessary for *any* libc, if 
> they want to be strictly standards-compliant. Some of the 
> required-to-be-predefined macros like `__STDC_ISO_10646__` can only really be 
> provided by the libc, since the appropriate value is dependent on the locale 
> implementation in the libc, and not on the compiler at all.
> 
> It's possible that glibc on Linux is the only one who's cared to implement it 
> thus far (and, only when you're using GCC, at that, hence this change...). 
> That seems likely, really, since mostly the impacted macros are nearly 
> useless, so who cares... :) However, if others want to be conforming, I 
> expect they _ought_ to be using this mechanism, as well...
> 
> Thus, perhaps it ought to be an unconditional behavior of clang to include 
> the file if it exists, unless `-ffreestanding` is passed.
This is still checking GCCInstallation.isValid(), OPT_nostdinc, and only 
attempting to load the header on Linux OSes.

I don't think it shouldn't be conditioned by the former two, and I think it 
should attempt to include stdc-predef.h if it exists on *all* OSes, not just 
Linux (for the reasons described in the above comment).


https://reviews.llvm.org/D34158



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


Re: r307175 - [Sema] Don't allow -Wunguarded-availability to be silenced with redecls

2017-07-06 Thread Nico Weber via cfe-commits
Thanks for the fast reply!

On Jul 6, 2017 11:42 PM, "Erik Pilkington" 
wrote:



On 7/6/17 2:12 PM, Nico Weber wrote:

We currently rely on this for chromium; that's how the warning used to work
when I added it. What's the transition plan? Can we have a flag to
incrementally transition to whatever the new way is? (Is it documented
anywhere?)

We currently have -Wunguarded-availability-new, which only warns for things
introduced as of macOS 10.13. If you switch to that flag then you won't get
warnings for code that used the redecl thing before 10.13,


Do we still get warnings for non-redecl'd older things then? We've been
using the redecl thing since 10.7 or so, and we rely on these warnings.

anything that uses APIs newer than that should either use @available or
annotate the context declaration with an availability attribute. This is
"documented" at the start of this wwdc talk: https://developer.apple.com/
videos/play/wwdc2017/411/

-Wunguarded-availability-new is somewhat unfortunate in that it won't catch
new code that you write today that uses older APIs, but maybe you can use
it and slowly change the redecl thing you have to use
@available/availability attributes then turn -Wunguarded-availability back
on when that is done.


Ah, that answers the above question.


Also, I think the replacement somehow needs the new runtime stuff from
libbuiltin -- does the driver know when to add that to the link line? If
so, where's the logic for that? If not, what library is supposed to provide
the runtime check function?

The runtime component (__isOSVersionAtLeast) is in compiler-rt/builtins.
Are you having problems linking with it?


I'm traveling and without a real computer, but iirc we tried using the new
thing and it got us a linker error. We don't currently bundle libBuiltin,
but -### didn't show clang trying to link it in and we failed to find
driver code that would add it. (We didn't look very hard though.) We were
also surprised that nothing else so far seemed to need libBuiltin.

It sounds like a transition path could be:

1. Bundle libBuiltin at older clang rev
2. Move stuff to @available
3. Move clang past this revision

Does that sound right?



Erik


On Jul 5, 2017 7:09 PM, "Erik Pilkington via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: epilk
Date: Wed Jul  5 10:08:56 2017
New Revision: 307175

URL: http://llvm.org/viewvc/llvm-project?rev=307175=rev
Log:
[Sema] Don't allow -Wunguarded-availability to be silenced with redecls

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/attr-availability.c
cfe/trunk/test/Sema/attr-deprecated.c
cfe/trunk/test/Sema/attr-unavailable-message.c
cfe/trunk/test/SemaCXX/attr-deprecated.cpp
cfe/trunk/test/SemaObjC/attr-availability.m
cfe/trunk/test/SemaObjC/unguarded-availability-new.m
cfe/trunk/test/SemaObjC/unguarded-availability.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
Basic/DiagnosticSemaKinds.td?rev=307175=307174=307175=diff

==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul  5
10:08:56 2017
@@ -2880,7 +2880,7 @@ def warn_partial_availability : Warning<
 def warn_partial_availability_new : Warning,
   InGroup;
 def note_partial_availability_silence : Note<
-  "explicitly redeclare %0 to silence this warning">;
+  "annotate %select{%1|anonymous %1}0 with an availability attribute to
silence">;
 def note_unguarded_available_silence : Note<
   "enclose %0 in %select{an @available|a __builtin_available}1 check to
silence"
   " this warning">;

Modified: cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
Sema/DelayedDiagnostic.h?rev=307175=307174=307175=diff

==
--- cfe/trunk/include/clang/Sema/DelayedDiagnostic.h (original)
+++ cfe/trunk/include/clang/Sema/DelayedDiagnostic.h Wed Jul  5 10:08:56
2017
@@ -124,7 +124,8 @@ public:

   static DelayedDiagnostic makeAvailability(AvailabilityResult AR,
 SourceLocation Loc,
-const NamedDecl *D,
+const NamedDecl *ReferringDecl,
+const NamedDecl *OffendingDecl,
 const ObjCInterfaceDecl
*UnknownObjCClass,
 const 

[PATCH] D34985: Do not read the file to determine its name.

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

@v.g.vassilev will this also benefit from `ContentCache::getBuffer` 
improvements from https://reviews.llvm.org/D33275? I guess if `getBuffer` 
transparently handles pointing to right buffer we won't need this change?


Repository:
  rL LLVM

https://reviews.llvm.org/D34985



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2017-07-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Ping!


https://reviews.llvm.org/D34331



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


[PATCH] D34578: cmath: Support clang's -fdelayed-template-parsing

2017-07-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Ping!  Hal, you committed r283051.  Do you have a problem with this?


https://reviews.llvm.org/D34578



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


r307316 - Reject attempts to build a module without -fmodules, rather than silently doing weird things.

2017-07-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Jul  6 14:05:56 2017
New Revision: 307316

URL: http://llvm.org/viewvc/llvm-project?rev=307316=rev
Log:
Reject attempts to build a module without -fmodules, rather than silently doing 
weird things.

Added:
cfe/trunk/test/Modules/missing-flag.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Frontend/FrontendActions.h
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/test/Modules/preprocess-build.cpp
cfe/trunk/test/Modules/relative-dep-gen.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=307316=307315=307316=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Thu Jul  6 
14:05:56 2017
@@ -179,6 +179,8 @@ def warn_incompatible_analyzer_plugin_ap
 def note_incompatible_analyzer_plugin_api : Note<
 "current API version is '%0', but plugin was compiled with version '%1'">;
 
+def err_module_build_requires_fmodules : Error<
+  "module compilation requires '-fmodules'">;
 def err_module_interface_requires_modules_ts : Error<
   "module interface compilation requires '-fmodules-ts'">;
 def warn_module_config_mismatch : Warning<

Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=307316=307315=307316=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Thu Jul  6 14:05:56 2017
@@ -111,6 +111,8 @@ protected:
 
 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
 private:
+  bool BeginSourceFileAction(CompilerInstance ) override;
+
   std::unique_ptr
   CreateOutputFile(CompilerInstance , StringRef InFile) override;
 };

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=307316=307315=307316=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Jul  6 14:05:56 2017
@@ -163,6 +163,16 @@ GenerateModuleAction::CreateASTConsumer(
   return llvm::make_unique(std::move(Consumers));
 }
 
+bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
+CompilerInstance ) {
+  if (!CI.getLangOpts().Modules) {
+CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
+return false;
+  }
+
+  return GenerateModuleAction::BeginSourceFileAction(CI);
+}
+
 std::unique_ptr
 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance ,
 StringRef InFile) {

Added: cfe/trunk/test/Modules/missing-flag.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/missing-flag.cpp?rev=307316=auto
==
--- cfe/trunk/test/Modules/missing-flag.cpp (added)
+++ cfe/trunk/test/Modules/missing-flag.cpp Thu Jul  6 14:05:56 2017
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -x c++-module-map %s -emit-module -fmodule-name=Foo -o 
%t 2>&1 | FileCheck %s
+// CHECK: module compilation requires '-fmodules'
+module Foo {}
+#pragma clang module contents

Modified: cfe/trunk/test/Modules/preprocess-build.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-build.cpp?rev=307316=307315=307316=diff
==
--- cfe/trunk/test/Modules/preprocess-build.cpp (original)
+++ cfe/trunk/test/Modules/preprocess-build.cpp Thu Jul  6 14:05:56 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z %s -verify
+// RUN: %clang_cc1 -std=c++1z -fmodules %s -verify
 
 #pragma clang module build baz
   module baz {}

Modified: cfe/trunk/test/Modules/relative-dep-gen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/relative-dep-gen.cpp?rev=307316=307315=307316=diff
==
--- cfe/trunk/test/Modules/relative-dep-gen.cpp (original)
+++ cfe/trunk/test/Modules/relative-dep-gen.cpp Thu Jul  6 14:05:56 2017
@@ -2,17 +2,17 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-name=relative-dep-gen 
-emit-module -x c++ Inputs/relative-dep-gen.modulemap -dependency-file 
%t/build.d -MT mod.pcm -o %t/mod.pcm
-// RUN: %clang_cc1 -cc1 -fno-implicit-modules 
-fmodule-map-file=Inputs/relative-dep-gen.modulemap -fmodule-file=%t/mod.pcm 
-dependency-file %t/use-explicit.d -MT use.o relative-dep-gen.cpp -fsyntax-only
-// 

r307320 - Change remaining references to lit.util.capture to use subprocess.check_output.

2017-07-06 Thread David L. Jones via cfe-commits
Author: dlj
Date: Thu Jul  6 14:46:47 2017
New Revision: 307320

URL: http://llvm.org/viewvc/llvm-project?rev=307320=rev
Log:
Change remaining references to lit.util.capture to use subprocess.check_output.

Summary:
The capture() function was removed in r306625. This should fix PGO breakages
reported by Michael Zolotukhin.

Reviewers: mzolotukhin

Subscribers: sanjoy, llvm-commits

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

Modified:
cfe/trunk/test/Unit/lit.cfg
cfe/trunk/test/lit.cfg

Modified: cfe/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.cfg?rev=307320=307319=307320=diff
==
--- cfe/trunk/test/Unit/lit.cfg (original)
+++ cfe/trunk/test/Unit/lit.cfg Thu Jul  6 14:46:47 2017
@@ -4,6 +4,7 @@
 
 import os
 import platform
+import subprocess
 
 import lit.formats
 import lit.util
@@ -65,8 +66,8 @@ if config.test_exec_root is None:
 lit_config.fatal('No site specific configuration available!')
 
 # Get the source and object roots.
-llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
-llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
+llvm_src_root = subprocess.check_output(['llvm-config', 
'--src-root']).strip()
+llvm_obj_root = subprocess.check_output(['llvm-config', 
'--obj-root']).strip()
 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
 

Modified: cfe/trunk/test/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg?rev=307320=307319=307320=diff
==
--- cfe/trunk/test/lit.cfg (original)
+++ cfe/trunk/test/lit.cfg Thu Jul  6 14:46:47 2017
@@ -148,8 +148,8 @@ if config.test_exec_root is None:
 lit_config.fatal('No site specific configuration available!')
 
 # Get the source and object roots.
-llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
-llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
+llvm_src_root = subprocess.check_output(['llvm-config', 
'--src-root']).strip()
+llvm_obj_root = subprocess.check_output(['llvm-config', 
'--obj-root']).strip()
 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
 


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


[PATCH] D33275: Keep into account if files were virtual.

2017-07-06 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

We're hitting a very similar problem to this one, which I think this patch will 
likely fix. I can't come up with a reproducible testcase either. If you can 
write one better yet, but I'm ok with this as is. LGTM.


https://reviews.llvm.org/D33275



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


Re: r307296 - [Objective-C] Fix non-determinism in clang

2017-07-06 Thread Bruno Cardoso Lopes via cfe-commits
Awesome, thanks!

On Thu, Jul 6, 2017 at 11:49 AM, Mandeep Singh Grang via cfe-commits
 wrote:
> Author: mgrang
> Date: Thu Jul  6 11:49:57 2017
> New Revision: 307296
>
> URL: http://llvm.org/viewvc/llvm-project?rev=307296=rev
> Log:
>  [Objective-C] Fix non-determinism in clang
>
> Summary: Iteration of the unordered Ivars causes 
> objc-modern-metadata-visibility.mm (uncovered by reverse iterating 
> SmallPtrSet).
>
> Reviewers: dblaikie, davide, rsmith
>
> Reviewed By: dblaikie
>
> Subscribers: cfe-commits, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D34860
>
> Added:
> cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
> Modified:
> cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
>
> Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=307296=307295=307296=diff
> ==
> --- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original)
> +++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Thu Jul  6 11:49:57 
> 2017
> @@ -146,7 +146,7 @@ namespace {
>
>  llvm::DenseMap RewrittenBlockExprs;
>  llvm::DenseMap -llvm::SmallPtrSet > ReferencedIvars;
> +llvm::SmallSetVector > 
> ReferencedIvars;
>
>  // ivar bitfield grouping containers
>  llvm::DenseSet 
> ObjCInterefaceHasBitfieldGroups;
> @@ -1013,7 +1013,7 @@ void RewriteModernObjC::RewritePropertyI
>  Setr = "\nextern \"C\" __declspec(dllimport) "
>  "void objc_setProperty (id, SEL, long, id, bool, bool);\n";
>}
> -
> +
>RewriteObjCMethodDecl(OID->getContainingInterface(),
>  PD->getSetterMethodDecl(), Setr);
>Setr += "{ ";
> @@ -3965,10 +3965,11 @@ void RewriteModernObjC::RewriteIvarOffse
>std::string ) {
>// write out ivar offset symbols which have been referenced in an ivar
>// access expression.
> -  llvm::SmallPtrSet Ivars = ReferencedIvars[CDecl];
> +  llvm::SmallSetVector Ivars = ReferencedIvars[CDecl];
> +
>if (Ivars.empty())
>  return;
> -
> +
>llvm::DenseSet 
> GroupSymbolOutput;
>for (ObjCIvarDecl *IvarDecl : Ivars) {
>  const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface();
>
> Added: cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm?rev=307296=auto
> ==
> --- cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm (added)
> +++ cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm Thu Jul  6 
> 11:49:57 2017
> @@ -0,0 +1,45 @@
> +// REQUIRES: abi-breaking-checks
> +// NOTE: This test has been split from objc-modern-metadata-visibility.mm in
> +// order to test with -reverse-iterate as this flag is only present with
> +// ABI_BREAKING_CHECKS.
> +
> +// RUN: %clang_cc1 -E %s -o %t.mm -mllvm -reverse-iterate
> +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc 
> %t.mm -mllvm -reverse-iterate -o - | FileCheck %s
> +// rdar://11144048
> +
> +@class NSString;
> +
> +@interface NSObject {
> +Class isa;
> +}
> +@end
> +
> +@interface Sub : NSObject {
> +int subIvar;
> +NSString *nsstring;
> +@private
> +id PrivateIvar;
> +}
> +@end
> +
> +@implementation Sub
> +- (id) MyNSString { return subIvar ? PrivateIvar : nsstring; }
> +@end
> +
> +@interface NSString @end
> +@implementation NSString @end
> +
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
> __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$subIvar;
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long 
> OBJC_IVAR_$_Sub$PrivateIvar;
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
> __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$nsstring;
> +// CHECK: #pragma warning(disable:4273)
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
> __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$subIvar
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
> __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$nsstring
> +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long int 
> OBJC_IVAR_$_Sub$PrivateIvar
> +// CHECK: extern "C" __declspec(dllimport) struct _class_t 
> OBJC_METACLASS_$_NSObject;
> +// CHECK: extern "C" __declspec(dllexport) struct _class_t 
> OBJC_METACLASS_$_Sub
> +// CHECK: extern "C" __declspec(dllimport) struct _class_t 
> OBJC_CLASS_$_NSObject;
> +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_Sub
> +// CHECK: extern "C" __declspec(dllexport) struct _class_t 
> OBJC_CLASS_$_NSString;
> +// CHECK: extern "C" __declspec(dllexport) struct _class_t 
> 

[PATCH] D35041: [analyzer] Fix modeling of bool based types

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

Add a test where evalCastFromLoc is called 
and the line unsigned BitWidth = Context.getIntWidth(castTy);
is hit.
I am planning to update this patch once again with a proper test where 
the path inside evalCastFromNonLoc is executed (need a bit more time)


Repository:
  rL LLVM

https://reviews.llvm.org/D35041

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/enum.cpp


Index: test/Analysis/enum.cpp
===
--- test/Analysis/enum.cpp
+++ test/Analysis/enum.cpp
@@ -37,3 +37,22 @@
   }
   return true;
 }
+
+bool testNoCrashOnSwitchEnumBoolConstant() {
+  EnumBool E = EnumBool::F;
+  switch (E) {
+case EnumBool::F:
+  return false; 
+  }
+  return true; 
+}
+
+typedef __INTPTR_TYPE__ intptr_t;
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromPointer() {
+  EnumBool E = static_cast((intptr_t)nullptr);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -71,18 +71,15 @@
 }
 
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-
   bool isLocType = Loc::isLocType(castTy);
-
   if (val.getAs())
 return val;
 
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
-
 // FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getTypeSize(castTy);
+unsigned castSize = Context.getIntWidth(castTy);
 if (castSize == LI->getNumBits())
   return val;
 return makeLocAsInteger(LI->getLoc(), castSize);
@@ -173,7 +170,7 @@
   }
 
   if (castTy->isIntegralOrEnumerationType()) {
-unsigned BitWidth = Context.getTypeSize(castTy);
+unsigned BitWidth = Context.getIntWidth(castTy);
 
 if (!val.getAs())
   return makeLocAsInteger(val, BitWidth);
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -124,7 +124,7 @@
   /// Returns the type of the APSInt used to store values of the given 
QualType.
   APSIntType getAPSIntType(QualType T) const {
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
-return APSIntType(Ctx.getTypeSize(T),
+return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }
 


Index: test/Analysis/enum.cpp
===
--- test/Analysis/enum.cpp
+++ test/Analysis/enum.cpp
@@ -37,3 +37,22 @@
   }
   return true;
 }
+
+bool testNoCrashOnSwitchEnumBoolConstant() {
+  EnumBool E = EnumBool::F;
+  switch (E) {
+case EnumBool::F:
+  return false; 
+  }
+  return true; 
+}
+
+typedef __INTPTR_TYPE__ intptr_t;
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromPointer() {
+  EnumBool E = static_cast((intptr_t)nullptr);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -71,18 +71,15 @@
 }
 
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-
   bool isLocType = Loc::isLocType(castTy);
-
   if (val.getAs())
 return val;
 
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
-
 // FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getTypeSize(castTy);
+unsigned castSize = Context.getIntWidth(castTy);
 if (castSize == LI->getNumBits())
   return val;
 return makeLocAsInteger(LI->getLoc(), castSize);
@@ -173,7 +170,7 @@
   }
 
   if (castTy->isIntegralOrEnumerationType()) {
-unsigned BitWidth = Context.getTypeSize(castTy);
+unsigned BitWidth = Context.getIntWidth(castTy);
 
 if (!val.getAs())
   return makeLocAsInteger(val, BitWidth);
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -124,7 +124,7 @@
   /// Returns the type of the APSInt used to store values of the given QualType.
   APSIntType getAPSIntType(QualType T) const {
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
-return APSIntType(Ctx.getTypeSize(T),
+return 

[PATCH] D29905: [OpenMP] Pass argument to device kernel by reference when map is used.

2017-07-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In https://reviews.llvm.org/D29905#800416, @Hahnfeld wrote:

> In https://reviews.llvm.org/D34888#799576, @gtbercea wrote:
>
> > Does this also include the fixes in the following revision?
> >
> > https://reviews.llvm.org/D29905
>
>
> Sorry, I wasn't aware of this revision and thought that it had long been 
> committed. I just verified that the bug referenced in the summary is also 
> fixed by my patch in https://reviews.llvm.org/D34888. However, I can't 
> comment on whether this patch is still needed. Sorry for the conflicts if 
> yes...
>
> You probably should commit your patches earlier, you currently have 10 
> accepted revisions that have not yet been committed. This will also avoid 
> complicated rebases and so on.


No problem at all! I am trying to commit the rest of the patches. Currently 
waiting on one more patch to get approved that will unlock the rest. I do 
encourage you to review/comment on it: https://reviews.llvm.org/D34784 :)


Repository:
  rL LLVM

https://reviews.llvm.org/D29905



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


[PATCH] D35078: [clang-tidy] Fix modernize-use-override incorrect replacement

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

Looks good with a nit.

Thank you for the fix!




Comment at: clang-tidy/modernize/UseOverrideCheck.cpp:43
   while (!RawLexer.LexFromRawLexer(Tok)) {
-if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && !Parens)
   break;

s/!Parens/Parens == 0/

Maybe also change Parens to NestedParens or NestingLevel.


Repository:
  rL LLVM

https://reviews.llvm.org/D35078



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


[PATCH] D33275: Keep into account if files were virtual.

2017-07-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@rsmith suggested to move this one interface layer down, that is 
`ContentCache::getBuffer`. Moving it there might fix more issues. I will try to 
improve it and land the new version if that's not urgent for you.


https://reviews.llvm.org/D33275



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


[PATCH] D33275: Keep into account if files were virtual.

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

That sounds even better. Thanks @v.g.vassilev


https://reviews.llvm.org/D33275



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


[PATCH] D33277: [Clang][x86][Inline Asm] - Enum support for MS syntax

2017-07-06 Thread Matan via Phabricator via cfe-commits
mharoush added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D33277



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


[PATCH] D33278: [LLVM][x86][Inline Asm] - Enum support for MS syntax

2017-07-06 Thread Matan via Phabricator via cfe-commits
mharoush added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D33278



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


[PATCH] D29905: [OpenMP] Pass argument to device kernel by reference when map is used.

2017-07-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D34888#799576, @gtbercea wrote:

> Does this also include the fixes in the following revision?
>
> https://reviews.llvm.org/D29905


Sorry, I wasn't aware of this revision and thought that it had long been 
committed. I just verified that the bug referenced in the summary is also fixed 
by my patch in https://reviews.llvm.org/D34888. However, I can't comment on 
whether this patch is still needed. Sorry for the conflicts if yes...

You probably should commit your patches earlier, you currently have 10 accepted 
revisions that have not yet been committed. This will also avoid complicated 
rebases and so on.


Repository:
  rL LLVM

https://reviews.llvm.org/D29905



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


[PATCH] D29658: [OpenMP] Customize CUDA-based tool chain selection

2017-07-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Driver/Driver.cpp:564
+  auto  =
+  ToolChains[TT.str() + "/" + HostTC->getTriple().normalize()];
+  if (!CudaTC)

gtbercea wrote:
> Hahnfeld wrote:
> > The code above uses `HostTriple.str()`, maybe better align to this?
> HostTriple is equivalent with HostTC->getTriple(). HostTC->getTriple() is 
> only used once so no need for a local variable unless you want me to refactor 
> the CUDA code above and take out HostTriple from within the if statement and 
> then re0use HostTriple that way. I'd rather not make changes to the CUDA 
> toolchain above.
Sorry, I meant the mismatch between `.str()` above and `.normalize()` here


https://reviews.llvm.org/D29658



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


[PATCH] D35041: [analyzer] Fix modeling of bool based types

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

Thanks, these are very helpful.

Sending changes in smaller chunks is great even if you already have one large 
chunk perfectly working :)

The test covers only the `BasicValueFactory`-related part of your patch; the 
Loc-related changes are still to be tested. I suspect the following may work:

1. For `evalCastFromNonLoc`: casting a symbolic pointer to an integer, then 
casting this integer to the enum class.
2. For `evalCastFromLoc`: Casting a concrete pointer (eg. null pointer) to the 
enum class (not sure if you can trick the analyzer into such cast directly 
while following the c++ standard).


Repository:
  rL LLVM

https://reviews.llvm.org/D35041



___
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-07-06 Thread Stephen Hines via Phabricator via cfe-commits
srhines added a comment.

Richard's points are really valid here. I missed the aspect that packed always 
implies alignment 1, which does have an effect on the code in most of the cases 
listed here. I agree that the value of this warning is low, since the 
possibility of false-positive is quite high. Would this make for a better 
clang-tidy check instead (although only for cases where there is no padding 
and/or cases where the struct is also declared to have a stricter alignment 
guarantee)?




Comment at: test/CodeGenCXX/warn-padded-packed.cpp:19
 
-struct S4 {
-  int i; // expected-warning {{packed attribute is unnecessary for 'i'}}
+struct S4 { // expected-warning {{packed attribute is unnecessary for field: 
'i'}}
+  int i;

rsmith wrote:
> This looks backwards: the packed attribute *is* necessary for field `i` here 
> (because it reduces `i`'s alignment from 4 to 1), but not for field `c`.
Yeah, even if we wanted to suggest that aligned(1) is a better fit for these 
kinds of packed structs, it isn't sufficient. In this case, packed grants the 
1-byte alignment, as well as ensures that arrays of this type are placed 
contiguously with no padding. Thus, the only place where this warning would 
make sense is for already packed structures that also require no padding at the 
end.


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] D35000: [OpenCL] Added extended tests on metadata generation for half data type and arrays.

2017-07-06 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 105375.
echuraev marked an inline comment as done.

https://reviews.llvm.org/D35000

Files:
  test/CodeGenOpenCL/kernel-arg-info.cl


Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -61,6 +61,37 @@
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
 
+kernel void foo6(constant half * constanthalfp,
+ constant half * restrict constanthalfrestrictp,
+ global half * globalhalfp,
+ global half * restrict globalhalfrestrictp,
+ global const half * globalconsthalfp,
+ global const half * restrict globalconsthalfrestrictp,
+
+ global volatile half * globalvolatilehalfp,
+ global volatile half * restrict globalvolatilehalfrestrictp,
+ global const volatile half * globalconstvolatilehalfp)
+{}
+// CHECK: !kernel_arg_type ![[MD61:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+kernel void foo6_2(global const volatile half * restrict 
globalconstvolatilehalfrestrictp,
+   local half * localhalfp,
+   local half * restrict localhalfrestrictp,
+   local const half * localconsthalfp,
+   local const half * restrict localconsthalfrestrictp,
+   local volatile half * localvolatilehalfp,
+   local volatile half * restrict localvolatilehalfrestrictp,
+   local const volatile half * localconstvolatilehalfp,
+   local const volatile half * restrict 
localconstvolatilehalfrestrictp)
+{}
+// CHECK: !kernel_arg_type ![[MD61]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+typedef char char16 __attribute__((ext_vector_type(16)));
+__kernel void foo7(__global char16 arg[]) {}
+// CHECK: !kernel_arg_type ![[MD71:[0-9]+]]
+
 // CHECK: ![[MD11]] = !{i32 1, i32 0, i32 0, i32 2, i32 1, i32 1}
 // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none"}
 // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*", !"int*", !"int*"}
@@ -86,4 +117,6 @@
 // CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
 // CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
 // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
+// CHECK: ![[MD61]] = !{!"half*", !"half*", !"half*", !"half*", !"half*", 
!"half*", !"half*", !"half*", !"half*"}
+// CHECK: ![[MD71]] = !{!"char16*"}
 


Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -61,6 +61,37 @@
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
 
+kernel void foo6(constant half * constanthalfp,
+ constant half * restrict constanthalfrestrictp,
+ global half * globalhalfp,
+ global half * restrict globalhalfrestrictp,
+ global const half * globalconsthalfp,
+ global const half * restrict globalconsthalfrestrictp,
+
+ global volatile half * globalvolatilehalfp,
+ global volatile half * restrict globalvolatilehalfrestrictp,
+ global const volatile half * globalconstvolatilehalfp)
+{}
+// CHECK: !kernel_arg_type ![[MD61:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+kernel void foo6_2(global const volatile half * restrict globalconstvolatilehalfrestrictp,
+   local half * localhalfp,
+   local half * restrict localhalfrestrictp,
+   local const half * localconsthalfp,
+   local const half * restrict localconsthalfrestrictp,
+   local volatile half * localvolatilehalfp,
+   local volatile half * restrict localvolatilehalfrestrictp,
+   local const volatile half * localconstvolatilehalfp,
+   local const volatile half * restrict localconstvolatilehalfrestrictp)
+{}
+// CHECK: !kernel_arg_type ![[MD61]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+typedef char char16 __attribute__((ext_vector_type(16)));
+__kernel void foo7(__global char16 arg[]) {}
+// CHECK: !kernel_arg_type ![[MD71:[0-9]+]]
+
 // CHECK: ![[MD11]] = !{i32 1, i32 0, i32 0, i32 2, i32 1, i32 1}
 // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none"}
 // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*", !"int*", !"int*"}
@@ -86,4 +117,6 @@
 // CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
 // CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
 // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
+// CHECK: ![[MD61]] = !{!"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*"}
+// CHECK: ![[MD71]] = !{!"char16*"}
 
___
cfe-commits mailing 

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

2017-07-06 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

These warnings are triggered by -Wpadded -Wpacked
or clang-tidy's clang-diagnostic-packed check.
I agree that they should be ignored or suppressed in many cases.
What I am not sure is the amount of real positive cases.

I found it too tedious to suppress one warning per struct field,
and hence liked this CL to consolidate those per-field warnings
into one per struct type. With this change we can use one NOLINT to
suppress all such warnings of a struct type, in the header file.

One alternative for users is to ignore these checks or warnings
for the whole compilation unit. That has the risk of masking
out valid warnings to other packed struct types in the same
compilation unit. Since the types are defined in header files,
these warnings would need to be suppressed in all compilation
units that include those header files.

I am not against removing these warnings completely.
If not removed, I hope that we can consolidate multiple
per-field warnings to one at the struct type level.


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] D35046: [coroutines] Include "this" type when looking up coroutine_traits

2017-07-06 Thread Toby Allsopp via Phabricator via cfe-commits
toby-allsopp created this revision.

In N4663, section [dcl.fct.def.coroutine] states that, in a coroutine
that is a non-static member function, the type of the implicit object
parameter is included immediately before the types of the function
parameters.


https://reviews.llvm.org/D35046

Files:
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutine-nonstatic-member-function.cpp

Index: test/SemaCXX/coroutine-nonstatic-member-function.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-nonstatic-member-function.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++1z -fcoroutines-ts -fsyntax-only -Wall -Wextra -Wuninitialized  -fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+struct coro_t {};
+
+struct coro_promise_type {
+  coro_t get_return_object() { return {}; }
+  suspend_never initial_suspend() { return {}; }
+  suspend_never final_suspend() { return {}; }
+  void return_void() {}
+  static void unhandled_exception() {}
+};
+
+struct C {
+  coro_t f();
+};
+
+namespace std::experimental {
+  template<>
+  struct coroutine_traits {
+using promise_type = coro_promise_type;
+  };
+}
+
+coro_t C::f() {
+  co_return;
+}
+
+int main() {
+  C c;
+  c.f();
+}
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -13,6 +13,7 @@
 
 #include "CoroutineStmtBuilder.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/Lex/Preprocessor.h"
@@ -43,9 +44,10 @@
 
 /// Look up the std::coroutine_traits<...>::promise_type for the given
 /// function type.
-static QualType lookupPromiseType(Sema , const FunctionProtoType *FnType,
+static QualType lookupPromiseType(Sema , const FunctionDecl *FD,
   SourceLocation KwLoc,
   SourceLocation FuncLoc) {
+  const FunctionProtoType *FnType = FD->getType()->castAs();
   // FIXME: Cache std::coroutine_traits once we've found it.
   NamespaceDecl *StdExp = S.lookupStdExperimentalNamespace();
   if (!StdExp) {
@@ -76,8 +78,15 @@
   Args.addArgument(TemplateArgumentLoc(
   TemplateArgument(FnType->getReturnType()),
   S.Context.getTrivialTypeSourceInfo(FnType->getReturnType(), KwLoc)));
-  // FIXME: If the function is a non-static member function, add the type
+  // If the function is a non-static member function, add the type
   // of the implicit object parameter before the formal parameters.
+  if (auto *MD = dyn_cast_or_null(FD)) {
+if (MD->isInstance()) {
+  QualType T = MD->getThisType(S.Context);
+  Args.addArgument(TemplateArgumentLoc(
+  TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc)));
+}
+  }
   for (QualType T : FnType->getParamTypes())
 Args.addArgument(TemplateArgumentLoc(
 TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc)));
@@ -424,12 +433,17 @@
 VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
   assert(isa(CurContext) && "not in a function scope");
   auto *FD = cast(CurContext);
+  bool IsThisDependentType = [&] {
+if (auto *MD = dyn_cast_or_null(FD))
+  return MD->isInstance() && MD->getThisType(Context)->isDependentType();
+else
+  return false;
+  }();
 
   QualType T =
-  FD->getType()->isDependentType()
+  FD->getType()->isDependentType() || IsThisDependentType
   ? Context.DependentTy
-  : lookupPromiseType(*this, FD->getType()->castAs(),
-  Loc, FD->getLocation());
+  : lookupPromiseType(*this, FD, Loc, FD->getLocation());
   if (T.isNull())
 return nullptr;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

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

Because this patch affects the default behavior, i think it's necessary to 
understand the performance impact on a large codebase. I may lend a hand 
eventually, but if you're in a hurry you could probably at least run an 
overnight analysis over llvm and sqlite with range constraint manager and see 
how performance changes with this patch, and ideally also if we get new reports 
or lose old reports.

In https://reviews.llvm.org/D28953#785679, @ddcc wrote:

> I forgot to mention that the only remaining (Z3) test failure is on 
> `plist-macros.cpp`; there is a `Assuming condition is true` path note that 
> only appears with the RangeConstraintManager but not with 
> Z3ConstraintManager, and I can't `#ifdef` it because the annotations are 
> checked by `FileCheck`.


This test case could be separated into a different file if nothing else helps.




Comment at: lib/StaticAnalyzer/Core/SValBuilder.cpp:363
   // instead of generating an Unknown value and propagate the taint info to it.
-  const unsigned MaxComp = 1; // 10 28X
 

ddcc wrote:
> zaks.anna wrote:
> > Reducing the MaxComp is going to regress taint analysis..
> > 
> > > I've updated this revision to account for the recent SVal simplification 
> > > commit by @NoQ, 
> > 
> > Which commit introduced the regression?
> > 
> > > but now there is an exponential blowup problem that prevents testcase 
> > > PR24184.cpp from terminating, 
> > 
> > What triggers the regression? Removing the if statement above? Does the 
> > regression only effect the Z3 "mode" (I am guessing not since you said "due 
> > to an interaction between Simplifier::VisitNonLocSymbolVal() and 
> > SValBuilder::makeSymExprValNN()")? 
> > 
> > Reducing the MaxComp is going to regress taint analysis..
> 
> I think the original intention was to increase `MaxComp`, not decrease it, 
> but I will restore the original value here.
> 
> > What triggers the regression? Removing the if statement above? Does the 
> > regression only effect the Z3 "mode"
> 
> No, the regression isn't specifically due to this code, but with @NoQ 's 
> patch for `SVal` simplification (rL300178), and this commit extending it to 
> handle `SymbolCast` and `IntSymExpr`, the cast of `ST *` used in the loop of 
> case 3 of PR24184.cpp becomes "simplified" (inlined) repeatedly on each 
> recursive iteration through `Simplifier::VisitNonLocSymbolVal()` -> 
> `SValBuilder::makeSymExprValNN()`, causing a big slowdown in runtime 
> performance.
> 
> The naive way to prevent it is to drop `MaxComp` (but this isn't reasonable, 
> since it needs to be absurdly low, e.g. `10`). Alternatively, simplification 
> for `SymbolCast` can be dropped from this commit (but it will eliminate some 
> of the other analysis improvements), or, most likely, introduce another 
> parameter to reduce recursion between these two functions.
We talked a bit and we're pretty much fine with reduce `MaxComp` to 10 if it's 
worth it in terms of performance.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:997-1003
   if (SymbolRef Sym = V.getAsSymbol())
 return state->getConstraintManager().getSymVal(state, Sym);
 
-  // FIXME: Add support for SymExprs.
+  if (Optional NV = V.getAs())
+if (SymbolRef Sym = NV->getAsSymExpr())
+  return state->getConstraintManager().getSymVal(state, Sym);
+

These two ifs are completely identical (apart from the fact that the one you 
added ignores symbolic region values due to explicit NonLoc cast). In fact 
`getAsSymbol()` (with its optional argument equal to `false`) and 
`getAsSymExpr()` are equivalent; we need to refactor this API.

I believe that the FIXME should in fact be addressed in 
`RangeConstraintManager`, in which currently `getSymVal()` works for atomic 
symbols only. Or, alternatively, we should stick `simplifySVal()` here - i 
think i'd have a look at this soon.

In any case, i suggest removing this change for now, unless i missed anything 
and it does in fact have an effect.



Comment at: test/Analysis/plist-macros.cpp:2
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix 
-analyzer-eagerly-assume -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix 
-analyzer-eagerly-assume -analyzer-output=plist-multi-file -analyzer-config 
path-diagnostics-alternate=ture %s -o %t.plist
 // RUN: FileCheck --input-file=%t.plist %s

> `path-diagnostics-alternate=ture`

Ouch. Thanks for fixing this.

Maybe it'd be great to implement an option that enables validating analyzer 
config option values, and turn this option on in `%clang_analyze_cc1`.


https://reviews.llvm.org/D28953



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


r307238 - [OpenCL] Test on image access modifiers and image type can only be a type of a function argument.

2017-07-06 Thread Egor Churaev via cfe-commits
Author: echuraev
Date: Thu Jul  6 00:06:11 2017
New Revision: 307238

URL: http://llvm.org/viewvc/llvm-project?rev=307238=rev
Log:
[OpenCL] Test on image access modifiers and image type can only be a type of a 
function argument.

Reviewers: Anastasia

Reviewed By: Anastasia

Subscribers: yaxunl, cfe-commits, bader

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

Modified:
cfe/trunk/test/SemaOpenCL/images.cl

Modified: cfe/trunk/test/SemaOpenCL/images.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/images.cl?rev=307238=307237=307238=diff
==
--- cfe/trunk/test/SemaOpenCL/images.cl (original)
+++ cfe/trunk/test/SemaOpenCL/images.cl Thu Jul  6 00:06:11 2017
@@ -1,9 +1,32 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 
-void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument 
to parameter 'img' here}} expected-note{{passing argument to parameter 'img' 
here}}
+void img2d_ro(read_only image2d_t); // expected-note 3{{passing argument to 
parameter here}}
+void img2d_wo(write_only image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void img2d_rw(read_write image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void img2d_default(image2d_t); // expected-note 2{{passing argument to 
parameter here}}
 
-void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, 
image3d_t img3dro) {
-  img2d_ro(img2dro);
-  img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+void imgage_access_test(image2d_t img2dro, image3d_t img3dro) {
+  img2d_ro(img2dro); // read_only = read_only
   img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
 }
+
+kernel void read_only_access_test(read_only image2d_t img) {
+  img2d_ro(img); // read_only = read_only
+  img2d_wo(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+  img2d_rw(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__read_write image2d_t'}}
+  img2d_default(img); // read_only = read_only
+}
+
+kernel void write_only_access_test(write_only image2d_t img) {
+  img2d_ro(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  img2d_wo(img); // write_only = write_only
+  img2d_rw(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_write image2d_t'}}
+  img2d_default(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}
+
+kernel void read_write_access_test(read_write image2d_t img) {
+  img2d_ro(img);  // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  img2d_wo(img); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+  img2d_rw(img); //read_write = read_write
+  img2d_default(img); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}


___
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-07-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

It looks like Richard approved libTooling as a dependency for clang on the 
mailing list (http://lists.llvm.org/pipermail/cfe-dev/2017-July/054536.html).
If it is ok to have this code in libTooling (for now), I think we could 
start/continue the review of this patch.


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] D35008: [AArch64] Produce the right kind of va_arg for windows

2017-07-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo marked an inline comment as done.
mstorsjo added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:4769
 DarwinPCS
   };
 

efriedma wrote:
> Can we extend ABIKind rather than adding a separate boolean?
Sure. I was afraid there was a lot of checks like `Kind == AAPCS` which would 
need to be changed into `Kind == AAPCS || Kind == Win64`, but it didn't turn 
out to be an issue.


https://reviews.llvm.org/D35008



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


[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307241: [clangd] Add support for per-file extra flags 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D34947

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
  clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/test/clangd/extra-flags.test

Index: clang-tools-extra/trunk/clangd/Protocol.h
===
--- clang-tools-extra/trunk/clangd/Protocol.h
+++ clang-tools-extra/trunk/clangd/Protocol.h
@@ -118,6 +118,12 @@
   static std::string unparse(const Location );
 };
 
+struct Metadata {
+  std::vector extraFlags;
+
+  static llvm::Optional parse(llvm::yaml::MappingNode *Params);
+};
+
 struct TextEdit {
   /// The range of the text document to be manipulated. To insert
   /// text into a document create a range where start === end.
@@ -152,6 +158,9 @@
   /// The document that was opened.
   TextDocumentItem textDocument;
 
+  /// Extension storing per-file metadata, such as compilation flags.
+  llvm::Optional metadata;
+
   static llvm::Optional
   parse(llvm::yaml::MappingNode *Params);
 };
Index: clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
@@ -22,13 +22,12 @@
   OpenedFiles.erase(It);
 }
 
-std::vector ClangdUnitStore::getCompileCommands(GlobalCompilationDatabase , PathRef File) {
+std::vector
+ClangdUnitStore::getCompileCommands(GlobalCompilationDatabase ,
+PathRef File) {
   std::vector Commands = CDB.getCompileCommands(File);
-  if (Commands.empty()) {
+  if (Commands.empty())
 // Add a fake command line if we know nothing.
-Commands.push_back(tooling::CompileCommand(
-llvm::sys::path::parent_path(File), llvm::sys::path::filename(File),
-{"clang", "-fsyntax-only", File.str()}, ""));
-  }
+Commands.push_back(getDefaultCompileCommand(File));
   return Commands;
 }
Index: clang-tools-extra/trunk/clangd/Protocol.cpp
===
--- clang-tools-extra/trunk/clangd/Protocol.cpp
+++ clang-tools-extra/trunk/clangd/Protocol.cpp
@@ -204,6 +204,33 @@
   return Result;
 }
 
+llvm::Optional Metadata::parse(llvm::yaml::MappingNode *Params) {
+  Metadata Result;
+  for (auto  : *Params) {
+auto *KeyString = dyn_cast(NextKeyValue.getKey());
+if (!KeyString)
+  return llvm::None;
+
+llvm::SmallString<10> KeyStorage;
+StringRef KeyValue = KeyString->getValue(KeyStorage);
+auto *Value = NextKeyValue.getValue();
+
+llvm::SmallString<10> Storage;
+if (KeyValue == "extraFlags") {
+  auto *Seq = dyn_cast(Value);
+  if (!Seq)
+return llvm::None;
+  for (auto  : *Seq) {
+auto *Node = dyn_cast();
+if (!Node)
+  return llvm::None;
+Result.extraFlags.push_back(Node->getValue(Storage));
+  }
+}
+  }
+  return Result;
+}
+
 llvm::Optional TextEdit::parse(llvm::yaml::MappingNode *Params) {
   TextEdit Result;
   for (auto  : *Params) {
@@ -265,6 +292,11 @@
   if (!Parsed)
 return llvm::None;
   Result.textDocument = std::move(*Parsed);
+} else if (KeyValue == "metadata") {
+  auto Parsed = Metadata::parse(Value);
+  if (!Parsed)
+return llvm::None;
+  Result.metadata = std::move(*Parsed);
 } else {
   return llvm::None;
 }
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -97,6 +97,9 @@
 
 void ClangdLSPServer::LSPProtocolCallbacks::onDocumentDidOpen(
 DidOpenTextDocumentParams Params, JSONOutput ) {
+  if (Params.metadata && !Params.metadata->extraFlags.empty())
+LangServer.CDB.setExtraFlagsForFile(Params.textDocument.uri.file,
+std::move(Params.metadata->extraFlags));
   LangServer.Server.addDocument(Params.textDocument.uri.file,
 Params.textDocument.text);
 }
Index: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
===
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
@@ -25,6 +25,9 @@
 
 namespace clangd {
 
+/// Returns a default compile command to use for \p File.
+tooling::CompileCommand getDefaultCompileCommand(PathRef File);
+
 /// Provides compilation 

[clang-tools-extra] r307241 - [clangd] Add support for per-file extra flags

2017-07-06 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Jul  6 01:44:54 2017
New Revision: 307241

URL: http://llvm.org/viewvc/llvm-project?rev=307241=rev
Log:
[clangd] Add support for per-file extra flags

Summary:
This patch adds the ability to specify user-defined extra flags per opened file
through the LSP layer. This is a non-standard extension to the protocol.
I've already created a feature request about it for upstream lsp:
https://github.com/Microsoft/language-server-protocol/issues/255

The particular use-case is ycmd, which has a python script for figuring out
extra flags per file:
https://github.com/Valloric/ycmd#flagsforfile-filename-kwargs-

Reviewers: ilya-biryukov, klimek, bkramer

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clangd/extra-flags.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=307241=307240=307241=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Jul  6 01:44:54 2017
@@ -97,6 +97,9 @@ void ClangdLSPServer::LSPProtocolCallbac
 
 void ClangdLSPServer::LSPProtocolCallbacks::onDocumentDidOpen(
 DidOpenTextDocumentParams Params, JSONOutput ) {
+  if (Params.metadata && !Params.metadata->extraFlags.empty())
+LangServer.CDB.setExtraFlagsForFile(Params.textDocument.uri.file,
+
std::move(Params.metadata->extraFlags));
   LangServer.Server.addDocument(Params.textDocument.uri.file,
 Params.textDocument.text);
 }

Modified: clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp?rev=307241=307240=307241=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp Thu Jul  6 01:44:54 2017
@@ -22,13 +22,12 @@ void ClangdUnitStore::removeUnitIfPresen
   OpenedFiles.erase(It);
 }
 
-std::vector 
ClangdUnitStore::getCompileCommands(GlobalCompilationDatabase , PathRef 
File) {
+std::vector
+ClangdUnitStore::getCompileCommands(GlobalCompilationDatabase ,
+PathRef File) {
   std::vector Commands = CDB.getCompileCommands(File);
-  if (Commands.empty()) {
+  if (Commands.empty())
 // Add a fake command line if we know nothing.
-Commands.push_back(tooling::CompileCommand(
-llvm::sys::path::parent_path(File), llvm::sys::path::filename(File),
-{"clang", "-fsyntax-only", File.str()}, ""));
-  }
+Commands.push_back(getDefaultCompileCommand(File));
   return Commands;
 }

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=307241=307240=307241=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Thu Jul  6 
01:44:54 2017
@@ -12,17 +12,53 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
-using namespace clang::clangd;
-using namespace clang;
+namespace clang {
+namespace clangd {
+
+static void addExtraFlags(tooling::CompileCommand ,
+  const std::vector ) {
+  if (ExtraFlags.empty())
+return;
+  assert(Command.CommandLine.size() >= 2 &&
+ "Expected a command line containing at least 2 arguments, the "
+ "compiler binary and the output file");
+  // The last argument of CommandLine is the name of the input file.
+  // Add ExtraFlags before it.
+  auto It = Command.CommandLine.end();
+  --It;
+  Command.CommandLine.insert(It, ExtraFlags.begin(), ExtraFlags.end());
+}
+
+tooling::CompileCommand getDefaultCompileCommand(PathRef File) {
+  std::vector CommandLine{"clang", "-fsyntax-only", File.str()};
+  return tooling::CompileCommand(llvm::sys::path::parent_path(File),
+ llvm::sys::path::filename(File), CommandLine,
+ /*Output=*/"");
+}
 
 std::vector
 DirectoryBasedGlobalCompilationDatabase::getCompileCommands(PathRef File) {
   std::vector Commands;
 
   auto CDB = getCompilationDatabase(File);
-  if (!CDB)

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

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

In https://reviews.llvm.org/D34512#800490, @xazax.hun wrote:

> It looks like Richard approved libTooling as a dependency for clang on the 
> mailing list (http://lists.llvm.org/pipermail/cfe-dev/2017-July/054536.html).
>  If it is ok to have this code in libTooling (for now), I think we could 
> start/continue the review of this patch.


I read that somewhat differently? It seems like Richard basically proposes 
adding a new library for things that control how we run clang in a multi-TU 
scenario. I'd call it libIndex, but that already exists :)


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] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

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

In https://reviews.llvm.org/D34512#800499, @klimek wrote:

> In https://reviews.llvm.org/D34512#800490, @xazax.hun wrote:
>
> > It looks like Richard approved libTooling as a dependency for clang on the 
> > mailing list 
> > (http://lists.llvm.org/pipermail/cfe-dev/2017-July/054536.html).
> >  If it is ok to have this code in libTooling (for now), I think we could 
> > start/continue the review of this patch.
>
>
> I read that somewhat differently? It seems like Richard basically proposes 
> adding a new library for things that control how we run clang in a multi-TU 
> scenario. I'd call it libIndex, but that already exists :)


No, but since Richard said he did not see any justifications to include this in 
libTooling, I had the impression this is not his final word, and in case you 
see it justified, this remains the suggested direction. 
But in this case I will rewrite this patch to create a new library. Are you 
still interested in reviewing it? Do you have any other name in mind? What 
about libCrossTU?


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] D35008: [AArch64] Produce the right kind of va_arg for windows

2017-07-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 105392.
mstorsjo marked an inline comment as done.
mstorsjo added a comment.
Herald added a subscriber: javed.absar.

Added a testcase, using a different Kind instead of adding a separate bool.


https://reviews.llvm.org/D35008

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/aarch64-varargs-ms.c


Index: test/CodeGen/aarch64-varargs-ms.c
===
--- /dev/null
+++ test/CodeGen/aarch64-varargs-ms.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-windows-msvc -emit-llvm -o - %s | FileCheck 
--check-prefix=CHECK %s
+
+#include 
+
+int simple_int(va_list ap) {
+// CHECK-LABEL: define i32 @simple_int
+  return va_arg(ap, int);
+// CHECK: [[ADDR:%[a-z_0-9]+]] = bitcast i8* %argp.cur to i32*
+// CHECK: [[RESULT:%[a-z_0-9]+]] = load i32, i32* [[ADDR]]
+// CHECK: ret i32 [[RESULT]]
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4765,7 +4765,8 @@
 public:
   enum ABIKind {
 AAPCS = 0,
-DarwinPCS
+DarwinPCS,
+Win64
   };
 
 private:
@@ -4803,10 +4804,14 @@
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
 QualType Ty) const override {
-return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
- : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
+return Kind == Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty)
+ : isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
+ : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
   }
 
+  Address EmitMSVAArg(CodeGenFunction , Address VAListAddr,
+  QualType Ty) const override;
+
   bool shouldPassIndirectlyForSwift(CharUnits totalSize,
 ArrayRef scalars,
 bool asReturnValue) const override {
@@ -5312,6 +5317,14 @@
   TyInfo, SlotSize, /*AllowHigherAlign*/ true);
 }
 
+Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction , Address VAListAddr,
+QualType Ty) const {
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+  CGF.getContext().getTypeInfoInChars(Ty),
+  CharUnits::fromQuantity(8),
+  /*allowHigherAlign*/ false);
+}
+
 
//===--===//
 // ARM ABI Implementation
 
//===--===//
@@ -8447,6 +8460,8 @@
 AArch64ABIInfo::ABIKind Kind = AArch64ABIInfo::AAPCS;
 if (getTarget().getABI() == "darwinpcs")
   Kind = AArch64ABIInfo::DarwinPCS;
+else if (Triple.getOS() == llvm::Triple::Win32)
+  Kind = AArch64ABIInfo::Win64;
 
 return SetCGInfo(new AArch64TargetCodeGenInfo(Types, Kind));
   }


Index: test/CodeGen/aarch64-varargs-ms.c
===
--- /dev/null
+++ test/CodeGen/aarch64-varargs-ms.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-windows-msvc -emit-llvm -o - %s | FileCheck --check-prefix=CHECK %s
+
+#include 
+
+int simple_int(va_list ap) {
+// CHECK-LABEL: define i32 @simple_int
+  return va_arg(ap, int);
+// CHECK: [[ADDR:%[a-z_0-9]+]] = bitcast i8* %argp.cur to i32*
+// CHECK: [[RESULT:%[a-z_0-9]+]] = load i32, i32* [[ADDR]]
+// CHECK: ret i32 [[RESULT]]
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4765,7 +4765,8 @@
 public:
   enum ABIKind {
 AAPCS = 0,
-DarwinPCS
+DarwinPCS,
+Win64
   };
 
 private:
@@ -4803,10 +4804,14 @@
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
 QualType Ty) const override {
-return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
- : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
+return Kind == Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty)
+ : isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
+ : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
   }
 
+  Address EmitMSVAArg(CodeGenFunction , Address VAListAddr,
+  QualType Ty) const override;
+
   bool shouldPassIndirectlyForSwift(CharUnits totalSize,
 ArrayRef scalars,
 bool asReturnValue) const override {
@@ -5312,6 +5317,14 @@
   TyInfo, SlotSize, /*AllowHigherAlign*/ true);
 }
 
+Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction , Address VAListAddr,
+QualType Ty) const {
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+  

[PATCH] D35015: [clang-format] Add space between a message field key and the opening bracket in proto messages

2017-07-06 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D35015



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


[PATCH] D34512: Add preliminary Cross Translation Unit support library

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

In https://reviews.llvm.org/D34512#800618, @klimek wrote:

> +Richard as top-level code owner for new libs.
>
> For bikeshedding the name: I'd have liked libIndex, but that's already taken. 
> CrossTU doesn't seem too bad to me, too, though.


Some brainstorming for the bikeshedding: libProjet, libProjectIndex, libImport
The reason I am not sure about the Index in the name because this code does not 
contain (yet) an interface to create/handle indexes. 
The import might be a good once, since this library is basically wrapping the 
ASTImporter to import code from external sources, but it might be misleading, 
since ASTImporter is in the AST module.


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] D35051: [clang-tidy] Add misc-undefined-memory-manipulation check.

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

Finds calls of memory manipulation functions `memset()`, `memcpy()` and 
`memmove()` on not TriviallyCopyable objects resulting in undefined behavior.

Related discussion .


https://reviews.llvm.org/D35051

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/UndefinedMemoryManipulationCheck.cpp
  clang-tidy/misc/UndefinedMemoryManipulationCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-undefined-memory-manipulation.rst
  test/clang-tidy/misc-undefined-memory-manipulation.cpp

Index: test/clang-tidy/misc-undefined-memory-manipulation.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-undefined-memory-manipulation.cpp
@@ -0,0 +1,178 @@
+// RUN: %check_clang_tidy %s misc-undefined-memory-manipulation %t
+
+void *memset(void *, int, __SIZE_TYPE__);
+void *memcpy(void *, const void *, __SIZE_TYPE__);
+void *memmove(void *, const void *, __SIZE_TYPE__);
+
+namespace std {
+using ::memcpy;
+using ::memmove;
+using ::memset;
+}
+
+// TriviallyCopyable types:
+struct Plain {
+  int n;
+};
+
+enum E {
+  X,
+  Y,
+  Z
+};
+
+struct Base {
+  float b;
+};
+
+struct Derived : Base {
+  bool d;
+};
+
+// not TriviallyCopyable types:
+struct Destruct {
+  ~Destruct() {};
+};
+
+struct Copy {
+  Copy() {};
+  Copy(const Copy &) {};
+};
+
+struct Move {
+  Move() {};
+  Move(Move &&) {};
+};
+
+struct VirtualFunc {
+  virtual void f() {};
+};
+
+struct VirtualBase : virtual Base {
+  int vb;
+};
+
+template 
+void memset_temp(T *b) {
+  memset(b, 0, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+}
+
+template 
+void memcpy_temp(S *a, T *b) {
+  memcpy(a, b, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+}
+
+template 
+void memmove_temp(S *a, T *b) {
+  memmove(a, b, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+}
+
+void notTriviallyCopyable() {
+  Plain p; // TriviallyCopyable for variety
+  Destruct d;
+  Copy c;
+  Move m;
+  VirtualFunc vf;
+  VirtualBase vb;
+
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  std::memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  ::memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  std::memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  ::memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [misc-undefined-memory-manipulation]
+  std::memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable 

[PATCH] D32700: [clang-tidy] Add misc-suspicious-memset-usage check.

2017-07-06 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 105401.
rnkovacs edited the summary of this revision.
rnkovacs added a comment.

- Merged in the `google-runtime-memset-zero-length` check.
- Added a separate check for memory manipulation functions: 
`misc-undefined-memory-manipulation` .


https://reviews.llvm.org/D32700

Files:
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GoogleTidyModule.cpp
  clang-tidy/google/MemsetZeroLengthCheck.cpp
  clang-tidy/google/MemsetZeroLengthCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/SuspiciousMemsetUsageCheck.cpp
  clang-tidy/misc/SuspiciousMemsetUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-runtime-memset.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-suspicious-memset-usage.rst
  test/clang-tidy/google-runtime-memset-zero-length.cpp
  test/clang-tidy/misc-suspicious-memset-usage.cpp

Index: test/clang-tidy/misc-suspicious-memset-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-suspicious-memset-usage.cpp
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy %s misc-suspicious-memset-usage %t
+
+void *memset(void *, int, __SIZE_TYPE__);
+
+namespace std {
+  using ::memset;
+}
+
+template 
+void mtempl(int *ptr) {
+  memset(ptr, '0', sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is char '0', potentially mistaken for int 0 [misc-suspicious-memset-usage]
+// CHECK-FIXES: memset(ptr, 0, sizeof(T));
+  memset(ptr, 256, sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is out of unsigned character range, gets truncated [misc-suspicious-memset-usage]
+  memset(0, sizeof(T), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [misc-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(T));
+  memset(0, sizeof(int), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [misc-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(int));
+}
+
+void foo(int xsize, int ysize) {
+  int i[5] = {1, 2, 3, 4, 5};
+  int *p = i;
+  int l = 5;
+  char z = '1';
+  char *c = 
+  int v = 0;
+
+  memset(p, '0', l);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: memset fill value is char '0', potentially mistaken for int 0 [misc-suspicious-memset-usage]
+// CHECK-FIXES: memset(p, 0, l);
+
+  memset(p, 0xabcd, l);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: memset fill value is out of unsigned character range, gets truncated [misc-suspicious-memset-usage]
+
+  memset(p, sizeof(int), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [misc-suspicious-memset-usage]
+// CHECK-FIXES: memset(p, 0, sizeof(int));
+  std::memset(p, sizeof(int), 0x00);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [misc-suspicious-memset-usage]
+// CHECK-FIXES: std::memset(p, 0x00, sizeof(int));
+
+#define M_CHAR_ZERO memset(p, '0', l);
+  M_CHAR_ZERO
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset fill value is char '0', potentially mistaken for int 0 [misc-suspicious-memset-usage]
+
+#define M_OUTSIDE_RANGE memset(p, 0xabcd, l);
+  M_OUTSIDE_RANGE
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset fill value is out of unsigned character range, gets truncated [misc-suspicious-memset-usage]
+
+#define M_ZERO_LENGTH memset(p, sizeof(int), 0);
+  M_ZERO_LENGTH
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [misc-suspicious-memset-usage]
+
+  memset(p, '2', l);
+  memset(p, 0, l);
+  memset(c, '0', 1);
+
+  memset(p, 0x00, l);
+  mtempl(p);
+
+  memset(p, sizeof(int), v + 1);
+  memset(p, 0xcd, 1);
+
+  // Don't warn when the fill char and the length are both known to be
+  // zero.  No bug is possible.
+  memset(p, 0, v);
+
+  // -1 is clearly not a length by virtue of being negative, so no warning
+  // despite v == 0.
+  memset(p, -1, v);
+}
Index: test/clang-tidy/google-runtime-memset-zero-length.cpp
===
--- test/clang-tidy/google-runtime-memset-zero-length.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// RUN: %check_clang_tidy %s google-runtime-memset %t
-
-void *memset(void *, int, __SIZE_TYPE__);
-
-namespace std {
-  using ::memset;
-}
-
-template 
-void memtmpl() {
-  memset(0, sizeof(int), i);
-  memset(0, sizeof(T), sizeof(T));
-  memset(0, sizeof(T), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(T));
-  memset(0, sizeof(int), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(int));
-}
-
-void foo(void *a, int xsize, int ysize) {
-  memset(a, sizeof(int), 0);
-// CHECK-MESSAGES: 

[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-07-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 105412.
xazax.hun marked an inline comment as done.
xazax.hun added a comment.

- Fix a copy and paste error and removed an unintended change.


https://reviews.llvm.org/D34512

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  include/clang/CrossTU/CrossTranslationUnit.h
  lib/AST/ASTImporter.cpp
  lib/CrossTU/CMakeLists.txt
  lib/CrossTU/CrossTranslationUnit.cpp
  test/Analysis/func-mapping-test.cpp
  test/CMakeLists.txt
  test/lit.cfg
  tools/CMakeLists.txt
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp
  unittests/CrossTU/CMakeLists.txt
  unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- /dev/null
+++ unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -0,0 +1,98 @@
+//===- unittest/Tooling/CrossTranslationUnitTest.cpp - Tooling unit 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/CrossTU/CrossTranslationUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace crossTU {
+
+namespace {
+StringRef IndexFileName = "index.txt";
+StringRef ASTFileName = "f.ast";
+StringRef DefinitionFileName = "input.cc";
+
+class CTUASTConsumer : public clang::ASTConsumer {
+public:
+  explicit CTUASTConsumer(clang::CompilerInstance , bool *Success)
+  : CTU(CI), Success(Success) {}
+
+  void HandleTranslationUnit(ASTContext ) {
+const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
+const FunctionDecl *FD = nullptr;
+for (const Decl *D : TU->decls()) {
+  FD = dyn_cast(D);
+  if (FD && FD->getName() == "f")
+break;
+}
+assert(FD);
+bool OrigFDHasBody = FD->hasBody();
+
+// Prepare the index file and the AST file.
+std::error_code EC;
+llvm::raw_fd_ostream OS(IndexFileName, EC, llvm::sys::fs::F_Text);
+OS << "c:@F@f#I# " << ASTFileName << "\n";
+OS.flush();
+StringRef SourceText = "int f(int) { return 0; }\n";
+// This file must exist since the saved ASTFile will reference it.
+llvm::raw_fd_ostream OS2(DefinitionFileName, EC, llvm::sys::fs::F_Text);
+OS2 << SourceText;
+OS2.flush();
+std::unique_ptr ASTWithDefinition =
+tooling::buildASTFromCode(SourceText);
+ASTWithDefinition->Save(ASTFileName);
+
+// Load the definition from the AST file.
+const FunctionDecl *NewFD =
+CTU.getCrossTUDefinition(FD, ".", IndexFileName);
+
+*Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
+  }
+
+private:
+  CrossTranslationUnit CTU;
+  bool *Success;
+};
+
+class CTUAction : public clang::ASTFrontendAction {
+public:
+  CTUAction(bool *Success) : Success(Success) {}
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance , StringRef) override {
+return llvm::make_unique(CI, Success);
+  }
+
+private:
+  bool *Success;
+};
+
+} // end namespace
+
+TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
+  bool Success = false;
+  EXPECT_TRUE(tooling::runToolOnCode(new CTUAction(), "int f(int);"));
+  EXPECT_TRUE(Success);
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(IndexFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(ASTFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(DefinitionFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(DefinitionFileName));
+}
+
+} // end namespace tooling
+} // end namespace clang
Index: unittests/CrossTU/CMakeLists.txt
===
--- /dev/null
+++ unittests/CrossTU/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Support
+  )
+
+add_clang_unittest(CrossTUTests
+  CrossTranslationUnitTest.cpp
+  )
+
+target_link_libraries(CrossTUTests
+  clangAST
+  clangBasic
+  clangCrossTU
+  clangFrontend
+  clangTooling
+  )
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 

[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-07-06 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a reviewer: rsmith.
klimek added a comment.

+Richard as top-level code owner for new libs.

For bikeshedding the name: I'd have liked libIndex, but that's already taken. 
CrossTU doesn't seem too bad to me, too, though.


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] D34512: Add preliminary Cross Translation Unit support library

2017-07-06 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In https://reviews.llvm.org/D34512#800502, @xazax.hun wrote:

> In https://reviews.llvm.org/D34512#800499, @klimek wrote:
>
> > In https://reviews.llvm.org/D34512#800490, @xazax.hun wrote:
> >
> > > It looks like Richard approved libTooling as a dependency for clang on 
> > > the mailing list 
> > > (http://lists.llvm.org/pipermail/cfe-dev/2017-July/054536.html).
> > >  If it is ok to have this code in libTooling (for now), I think we could 
> > > start/continue the review of this patch.
> >
> >
> > I read that somewhat differently? It seems like Richard basically proposes 
> > adding a new library for things that control how we run clang in a multi-TU 
> > scenario. I'd call it libIndex, but that already exists :)
>
>
> No, but since Richard said he did not see any justifications to include this 
> in libTooling, I had the impression this is not his final word, and in case 
> you see it justified, this remains the suggested direction. 
>  But in this case I will rewrite this patch to create a new library. Are you 
> still interested in reviewing it? Do you have any other name in mind? What 
> about libCrossTU?




In https://reviews.llvm.org/D34512#800625, @xazax.hun wrote:

> In https://reviews.llvm.org/D34512#800618, @klimek wrote:
>
> > +Richard as top-level code owner for new libs.
> >
> > For bikeshedding the name: I'd have liked libIndex, but that's already 
> > taken. CrossTU doesn't seem too bad to me, too, though.
>
>
> Some brainstorming for the bikeshedding: libProjet, libProjectIndex, libImport
>  The reason I am not sure about the Index in the name because this code does 
> not contain (yet) an interface to create/handle indexes. 
>  The import might be a good once, since this library is basically wrapping 
> the ASTImporter to import code from external sources, but it might be 
> misleading, since ASTImporter is in the AST module.


Cross-TU is now used (in the lifeline of these features introduced by the team) 
in multiple contexts: CTU analysis, and now CTU lookup.
Maybe the name of this lib should reflect on the fact that the lib is used to 
support **cross-TU definition lookup**.

Hmm... `libCrossTULocator`?


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] D34512: Add preliminary Cross Translation Unit support library

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

In https://reviews.llvm.org/D34512#800626, @whisperity wrote:

> In https://reviews.llvm.org/D34512#800502, @xazax.hun wrote:
>
> > In https://reviews.llvm.org/D34512#800499, @klimek wrote:
> >
> > > In https://reviews.llvm.org/D34512#800490, @xazax.hun wrote:
> > >
> > > > It looks like Richard approved libTooling as a dependency for clang on 
> > > > the mailing list 
> > > > (http://lists.llvm.org/pipermail/cfe-dev/2017-July/054536.html).
> > > >  If it is ok to have this code in libTooling (for now), I think we 
> > > > could start/continue the review of this patch.
> > >
> > >
> > > I read that somewhat differently? It seems like Richard basically 
> > > proposes adding a new library for things that control how we run clang in 
> > > a multi-TU scenario. I'd call it libIndex, but that already exists :)
> >
> >
> > No, but since Richard said he did not see any justifications to include 
> > this in libTooling, I had the impression this is not his final word, and in 
> > case you see it justified, this remains the suggested direction. 
> >  But in this case I will rewrite this patch to create a new library. Are 
> > you still interested in reviewing it? Do you have any other name in mind? 
> > What about libCrossTU?
>
>
>
>
> In https://reviews.llvm.org/D34512#800625, @xazax.hun wrote:
>
> > In https://reviews.llvm.org/D34512#800618, @klimek wrote:
> >
> > > +Richard as top-level code owner for new libs.
> > >
> > > For bikeshedding the name: I'd have liked libIndex, but that's already 
> > > taken. CrossTU doesn't seem too bad to me, too, though.
> >
> >
> > Some brainstorming for the bikeshedding: libProjet, libProjectIndex, 
> > libImport
> >  The reason I am not sure about the Index in the name because this code 
> > does not contain (yet) an interface to create/handle indexes. 
> >  The import might be a good once, since this library is basically wrapping 
> > the ASTImporter to import code from external sources, but it might be 
> > misleading, since ASTImporter is in the AST module.
>
>
> Cross-TU is now used (in the lifeline of these features introduced by the 
> team) in multiple contexts: CTU analysis, and now CTU lookup.
>  Maybe the name of this lib should reflect on the fact that the lib is used 
> to support **cross-TU definition lookup**.
>
> Hmm... `libCrossTULocator`?


Well, a better name for locator is index :)


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] D35015: [clang-format] Add space between a message field key and the opening bracket in proto messages

2017-07-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307261: [clang-format] Add space between a message field key 
and the opening bracket in… (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D35015

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2301,6 +2301,8 @@
 if (Right.is(tok::l_paren) &&
 Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
   return true;
+if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
+  return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -199,11 +199,11 @@
"};");
   verifyFormat("option (MyProto.options) = {\n"
"  field_c: \"OK\"\n"
-   "  msg_field{field_d: 123}\n"
+   "  msg_field {field_d: 123}\n"
"};");
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: OK\n"
-   "  field_b{field_c: OK}\n"
+   "  field_b {field_c: OK}\n"
"  field_d: OKOKOK\n"
"  field_e: OK\n"
"}");
@@ -216,7 +216,7 @@
 
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: OK\n"
-   "  field_b\n"
+   "  field_b \n"
"  field_d: OKOKOK\n"
"  field_e: OK\n"
"}");
@@ -255,7 +255,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -267,7 +267,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK,\n"
"field_c: OK,\n"
"field_d: OK,\n"
@@ -303,7 +303,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field{\n"
+   "  msg_field {\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -315,7 +315,7 @@
 
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -339,18 +339,18 @@
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field{\n"
+   "  msg_field {\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
-   "msg_field<\n"
+   "msg_field <\n"
"  field_A: 1\n"
"  field_B: 2\n"
"  field_C: 3\n"
"  field_D: 4\n"
"  field_E: 5\n"
">\n"
-   "msg_field\n"
+   "msg_field \n"
"field_e: OK\n"
"field_f: OK\n"
"  }\n"
Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -61,13 +61,13 @@
"  field_e: 23\n"
"}");
 
-  verifyFormat("msg_field{}");
+  verifyFormat("msg_field {}");
 
-  verifyFormat("msg_field{field_a: A}");
+  verifyFormat("msg_field {field_a: A}");
 
-  verifyFormat("msg_field{field_a: \"OK\" field_b: 123}");
+  verifyFormat("msg_field {field_a: \"OK\" field_b: 123}");
 
-  verifyFormat("msg_field{\n"
+  verifyFormat("msg_field {\n"
"  field_a: 1\n"
"  field_b: OK\n"
"  field_c: \"OK\"\n"
@@ -78,12 +78,12 @@
"  field_h: 1234.567e-89\n"
"}");
 
-  verifyFormat("msg_field: {msg_field{field_a: 1}}");
+  verifyFormat("msg_field: {msg_field {field_a: 1}}");
 
   verifyFormat("id: \"ala.bala\"\n"
-   "item{type: ITEM_A rank: 1 score: 90.0}\n"
-   "item{type: ITEM_B rank: 2 score: 70.5}\n"
-   "item{\n"
+   

r307261 - [clang-format] Add space between a message field key and the opening bracket in proto messages

2017-07-06 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Jul  6 06:58:29 2017
New Revision: 307261

URL: http://llvm.org/viewvc/llvm-project?rev=307261=rev
Log:
[clang-format] Add space between a message field key and the opening bracket in 
proto messages

Summary:
This patch updates the formatting of message fields of type `a{...}` to `a 
{...}`
for proto messages.

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=307261=307260=307261=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jul  6 06:58:29 2017
@@ -2301,6 +2301,8 @@ bool TokenAnnotator::spaceRequiredBefore
 if (Right.is(tok::l_paren) &&
 Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
   return true;
+if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
+  return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=307261=307260=307261=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Jul  6 06:58:29 2017
@@ -199,11 +199,11 @@ TEST_F(FormatTestProto, FormatsOptions)
"};");
   verifyFormat("option (MyProto.options) = {\n"
"  field_c: \"OK\"\n"
-   "  msg_field{field_d: 123}\n"
+   "  msg_field {field_d: 123}\n"
"};");
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: OK\n"
-   "  field_b{field_c: OK}\n"
+   "  field_b {field_c: OK}\n"
"  field_d: OKOKOK\n"
"  field_e: OK\n"
"}");
@@ -216,7 +216,7 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: OK\n"
-   "  field_b\n"
+   "  field_b \n"
"  field_d: OKOKOK\n"
"  field_e: OK\n"
"}");
@@ -255,7 +255,7 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -267,7 +267,7 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK,\n"
"field_c: OK,\n"
"field_d: OK,\n"
@@ -303,7 +303,7 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field{\n"
+   "  msg_field {\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -315,7 +315,7 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = {\n"
"  field_a: \"OK\"\n"
-   "  msg_field<\n"
+   "  msg_field <\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
@@ -339,18 +339,18 @@ TEST_F(FormatTestProto, FormatsOptions)
 
   verifyFormat("option (MyProto.options) = <\n"
"  field_a: \"OK\"\n"
-   "  msg_field{\n"
+   "  msg_field {\n"
"field_b: OK\n"
"field_c: OK\n"
"field_d: OK\n"
-   "msg_field<\n"
+   "msg_field <\n"
"  field_A: 1\n"
"  field_B: 2\n"
"  field_C: 3\n"
"  field_D: 4\n"
"  field_E: 5\n"
">\n"
-   "msg_field\n"
+   "msg_field \n"
"field_e: OK\n"
"field_f: OK\n"
"  }\n"

Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=307261=307260=307261=diff
==
--- 

Re: r307104 - Enable LLVM asan support for NetBSD/amd64

2017-07-06 Thread Kamil Rytarowski via cfe-commits
On 06.07.2017 14:57, Joerg Sonnenberger wrote:
> On Tue, Jul 04, 2017 at 07:55:56PM -, Kamil Rytarowski via cfe-commits 
> wrote:
>> Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=307104=307103=307104=diff
>> ==
>> --- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Tue Jul  4 12:55:56 2017
>> @@ -524,6 +524,7 @@ void tools::linkSanitizerRuntimeDeps(con
>>CmdArgs.push_back("-lm");
>>// There's no libdl on FreeBSD or RTEMS.
>>if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
>> +  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
>>TC.getTriple().getOS() != llvm::Triple::RTEMS)
>>  CmdArgs.push_back("-ldl");
>>  }
> 
> I'd really prefer if we switched to a positive list here, i.e. only link
> libdl on platforms that actually need it. I'm not sure who does, beside
> Linux.
> 
> Joerg
> 

I have no preference.

SunOS (at least SmartOS) ships with ldl. Most GNU systems (HURD, Linux,
KFREEBSD/GNU) use it too. I think the same applies for HPUX, AIX, IRIX
and Darwin?

There are more switches for the same purpose in the code, but for other
kind of instrumentation. At the moment NetBSD isn't used there.



signature.asc
Description: OpenPGP digital signature
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307264 - [clang-format] Add TextProto language name, NFC

2017-07-06 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Jul  6 07:39:39 2017
New Revision: 307264

URL: http://llvm.org/viewvc/llvm-project?rev=307264=rev
Log:
[clang-format] Add TextProto language name, NFC

Modified:
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=307264=307263=307264=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Jul  6 07:39:39 2017
@@ -1753,6 +1753,8 @@ inline StringRef getLanguageName(FormatS
 return "JavaScript";
   case FormatStyle::LK_Proto:
 return "Proto";
+  case FormatStyle::LK_TextProto:
+return "TextProto";
   default:
 return "Unknown";
   }


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


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

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

Patch by  Bernd Schmidt!

Fixes PR19668 and PR23034.


Repository:
  rL LLVM

https://reviews.llvm.org/D35056

Files:
  lib/CodeGen/CGCXXABI.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/uncopyable-args.cpp

Index: test/CodeGenCXX/uncopyable-args.cpp
===
--- test/CodeGenCXX/uncopyable-args.cpp
+++ test/CodeGenCXX/uncopyable-args.cpp
@@ -52,12 +52,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN9move_ctor3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
+// CHECK-LABEL: define void @_ZN9move_ctor3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@move_ctor@@YAXUA@1@@Z"(%"struct.move_ctor::A"*)
 }
@@ -73,12 +72,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11all_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11all_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@all_deleted@@YAXUA@1@@Z"(%"struct.all_deleted::A"*)
 }
@@ -93,12 +91,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy and move ctors are implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN18implicitly_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
+// CHECK-LABEL: define void @_ZN18implicitly_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@implicitly_deleted@@YAXUA@1@@Z"(%"struct.implicitly_deleted::A"*)
 }
@@ -113,12 +110,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy constructor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11one_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11one_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@one_deleted@@YAXUA@1@@Z"(%"struct.one_deleted::A"*)
 }
@@ -195,12 +191,10 @@
 void bar() {
   foo({});
 }
-// FIXME: This class has a non-trivial copy ctor and a trivial copy ctor.  It's
-// not clear whether we should pass by address or in registers.
-// CHECK-DISABLED-LABEL: define void @_ZN14two_copy_ctors3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
+// CHECK-LABEL: define void @_ZN14two_copy_ctors3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
 
 // WIN64-LABEL: declare void @"\01?foo@two_copy_ctors@@YAXUB@1@@Z"(%"struct.two_copy_ctors::B"*)
 }
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -63,11 +63,8 @@
   bool classifyReturnType(CGFunctionInfo ) const override;
 
   RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const override {
-// Structures with either a non-trivial destructor or a 

[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-07-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 105409.
xazax.hun retitled this revision from "[libTooling] Add preliminary Cross 
Translation Unit support for libTooling" to "Add preliminary Cross Translation 
Unit support library".
xazax.hun added a comment.

- Move CrossTU functionality into its own library


https://reviews.llvm.org/D34512

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  include/clang/CrossTU/CrossTranslationUnit.h
  lib/AST/ASTImporter.cpp
  lib/CrossTU/CMakeLists.txt
  lib/CrossTU/CrossTranslationUnit.cpp
  lib/Tooling/CMakeLists.txt
  test/Analysis/func-mapping-test.cpp
  test/CMakeLists.txt
  test/lit.cfg
  tools/CMakeLists.txt
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp
  unittests/CrossTU/CMakeLists.txt
  unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- /dev/null
+++ unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -0,0 +1,98 @@
+//===- unittest/Tooling/CrossTranslationUnitTest.cpp - Tooling unit 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/CrossTU/CrossTranslationUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace crossTU {
+
+namespace {
+StringRef IndexFileName = "index.txt";
+StringRef ASTFileName = "f.ast";
+StringRef DefinitionFileName = "input.cc";
+
+class CTUASTConsumer : public clang::ASTConsumer {
+public:
+  explicit CTUASTConsumer(clang::CompilerInstance , bool *Success)
+  : CTU(CI), Success(Success) {}
+
+  void HandleTranslationUnit(ASTContext ) {
+const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
+const FunctionDecl *FD = nullptr;
+for (const Decl *D : TU->decls()) {
+  FD = dyn_cast(D);
+  if (FD && FD->getName() == "f")
+break;
+}
+assert(FD);
+bool OrigFDHasBody = FD->hasBody();
+
+// Prepare the index file and the AST file.
+std::error_code EC;
+llvm::raw_fd_ostream OS(IndexFileName, EC, llvm::sys::fs::F_Text);
+OS << "c:@F@f#I# " << ASTFileName << "\n";
+OS.flush();
+StringRef SourceText = "int f(int) { return 0; }\n";
+// This file must exist since the saved ASTFile will reference it.
+llvm::raw_fd_ostream OS2(DefinitionFileName, EC, llvm::sys::fs::F_Text);
+OS2 << SourceText;
+OS2.flush();
+std::unique_ptr ASTWithDefinition =
+tooling::buildASTFromCode(SourceText);
+ASTWithDefinition->Save(ASTFileName);
+
+// Load the definition from the AST file.
+const FunctionDecl *NewFD =
+CTU.getCrossTUDefinition(FD, ".", IndexFileName);
+
+*Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
+  }
+
+private:
+  CrossTranslationUnit CTU;
+  bool *Success;
+};
+
+class CTUAction : public clang::ASTFrontendAction {
+public:
+  CTUAction(bool *Success) : Success(Success) {}
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance , StringRef) override {
+return llvm::make_unique(CI, Success);
+  }
+
+private:
+  bool *Success;
+};
+
+} // end namespace
+
+TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
+  bool Success = false;
+  EXPECT_TRUE(tooling::runToolOnCode(new CTUAction(), "int f(int);"));
+  EXPECT_TRUE(Success);
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(IndexFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(ASTFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(DefinitionFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(DefinitionFileName));
+}
+
+} // end namespace tooling
+} // end namespace clang
Index: unittests/CrossTU/CMakeLists.txt
===
--- /dev/null
+++ unittests/CrossTU/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Support
+  )
+
+add_clang_unittest(CrossTUTests
+  CrossTranslationUnitTest.cpp
+  )
+
+target_link_libraries(ToolingTests
+  clangAST
+  clangBasic
+  clangCrossTU
+  clangFrontend
+  clangTooling
+  )
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 

[PATCH] D33826: [clang-tidy] avoid pointer cast to more strict alignment check

2017-07-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

What will this check say about the following code?

  c++
  void function(void) {
char c = 'x';
int *ip = reinterpret_cast();
  }

The clang'g `-Wcast-align` does not warn: https://godbolt.org/g/hVwD5S


Repository:
  rL LLVM

https://reviews.llvm.org/D33826



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


Re: r307104 - Enable LLVM asan support for NetBSD/amd64

2017-07-06 Thread Joerg Sonnenberger via cfe-commits
On Tue, Jul 04, 2017 at 07:55:56PM -, Kamil Rytarowski via cfe-commits 
wrote:
> Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=307104=307103=307104=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Tue Jul  4 12:55:56 2017
> @@ -524,6 +524,7 @@ void tools::linkSanitizerRuntimeDeps(con
>CmdArgs.push_back("-lm");
>// There's no libdl on FreeBSD or RTEMS.
>if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
> +  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
>TC.getTriple().getOS() != llvm::Triple::RTEMS)
>  CmdArgs.push_back("-ldl");
>  }

I'd really prefer if we switched to a positive list here, i.e. only link
libdl on platforms that actually need it. I'm not sure who does, beside
Linux.

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


[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-07-06 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: unittests/CrossTU/CMakeLists.txt:10
+
+target_link_libraries(ToolingTests
+  clangAST

`CrossTUTests`?


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] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-06 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 105440.
wangxindsb added a comment.

- Rename the BugType.
- Correct the code style to be clang format.
- Rename the arguments to start with uppercase letter.
- Add the support to check for the constructor called by the New expr.

You don't need to put effort to review the code, because I will make some 
changes to the bug report system and the GDM of the checker which has not been 
done now.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,90 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-06 Thread wangxin via Phabricator via cfe-commits
wangxindsb added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:332
+// Check the base of the callexpr is equal to the this of the ctor
+bool VirtualCallChecker::isCalledbyCtor(const CallExpr *CE,ProgramStateRef 
State,const LocationContext *LCtx) const {
+  if (const MemberExpr *CME = dyn_cast(CE->getCallee())) {

xazax.hun wrote:
> Maybe instead of callExpr, you should get CXXInstanceCall, which has a 
> getCXXThisVal method. 
I tried to use the CXXInstanceCall, but I can't use it to get the expr which 
call the function.


https://reviews.llvm.org/D34275



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


[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

The unguarded availability warnings in the protocol requirements of a 
protocol/class/category declaration can be avoided. This matches the behaviour 
of Swift's diagnostics.


Repository:
  rL LLVM

https://reviews.llvm.org/D35061

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -263,3 +263,27 @@
 new_int x; // expected-warning{{'new_int' is partial}}
   };
 }
+
+// rdar://33156429:
+// Avoid the warning on protocol requirements.
+
+AVAILABLE_10_12
+@protocol NewProtocol // expected-note {{'NewProtocol' has been explicitly marked partial here}}
+@end
+
+@protocol ProtocolWithNewProtocolRequirement  // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}}
+
+@property(copy) id prop; // expected-warning {{'NewProtocol' is partial: introduced in macOS 10.12}}
+
+@end
+
+@interface BaseClass
+@end
+
+@interface ClassWithNewProtocolRequirement : BaseClass 
+
+@end
+
+@interface BaseClass (CategoryWithNewProtocolRequirement) 
+
+@end
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -128,7 +128,8 @@
 static void
 DiagnoseAvailabilityOfDecl(Sema , NamedDecl *D, SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass,
-   bool ObjCPropertyAccess) {
+   bool ObjCPropertyAccess,
+   bool AvoidAvailabilityChecks = false) {
   std::string Message;
   AvailabilityResult Result;
   const NamedDecl* OffendingDecl;
@@ -138,6 +139,8 @@
 return;
 
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;
 if (S.getCurFunctionOrMethodDecl()) {
   S.getEnclosingFunction()->HasPotentialAvailabilityViolations = true;
   return;
@@ -275,7 +278,8 @@
 ///
 bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
  const ObjCInterfaceDecl *UnknownObjCClass,
- bool ObjCPropertyAccess) {
+ bool ObjCPropertyAccess,
+ bool AvoidAvailabilityChecks) {
   if (getLangOpts().CPlusPlus && isa(D)) {
 // If there were any diagnostics suppressed by template argument deduction,
 // emit them now.
@@ -360,7 +364,7 @@
   }
 
   DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass,
- ObjCPropertyAccess);
+ ObjCPropertyAccess, AvoidAvailabilityChecks);
 
   DiagnoseUnusedOfDecl(*this, D, Loc);
 
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -458,7 +458,10 @@
   // Diagnose availability in the context of the ObjC container.
   Sema::ContextRAII SavedContext(TheSema, CD);
   for (unsigned i = 0; i < NumProtoRefs; ++i) {
-(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i]);
+(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i],
+/*UnknownObjCClass=*/nullptr,
+/*ObjCPropertyAccess=*/false,
+/*AvoidAvailabilityChecks=*/true);
   }
 }
 
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -3900,8 +3900,9 @@
 
   bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
   bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
- const ObjCInterfaceDecl *UnknownObjCClass=nullptr,
- bool ObjCPropertyAccess=false);
+ const ObjCInterfaceDecl *UnknownObjCClass = nullptr,
+ bool ObjCPropertyAccess = false,
+ bool AvoidAvailabilityChecks = false);
   void NoteDeletedFunction(FunctionDecl *FD);
   void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD);
   std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r307266 - Add a test harness

2017-07-06 Thread Jonathan Roelofs via cfe-commits
Author: jroelofs
Date: Thu Jul  6 08:20:12 2017
New Revision: 307266

URL: http://llvm.org/viewvc/llvm-project?rev=307266=rev
Log:
Add a test harness

Mostly cargo-culted from libcxxabi, since the unwinder was forked from there in
the first place. There may still be cruft that's only applicable to libcxxabi,
but that can be addressed in-tree.

https://reviews.llvm.org/D35038

Added:
libunwind/trunk/test/CMakeLists.txt
libunwind/trunk/test/libunwind/
libunwind/trunk/test/libunwind/__init__.py
libunwind/trunk/test/libunwind/test/
libunwind/trunk/test/libunwind/test/__init__.py
libunwind/trunk/test/libunwind/test/config.py
libunwind/trunk/test/lit.cfg
libunwind/trunk/test/lit.site.cfg.in
Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/test/libunwind_02.pass.cpp

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=307266=307265=307266=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Thu Jul  6 08:20:12 2017
@@ -321,3 +321,5 @@ add_subdirectory(src)
 if (LIBUNWIND_INCLUDE_DOCS)
   add_subdirectory(docs)
 endif()
+
+add_subdirectory(test)

Added: libunwind/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/test/CMakeLists.txt?rev=307266=auto
==
--- libunwind/trunk/test/CMakeLists.txt (added)
+++ libunwind/trunk/test/CMakeLists.txt Thu Jul  6 08:20:12 2017
@@ -0,0 +1,35 @@
+include(AddLLVM) # for add_lit_testsuite
+macro(pythonize_bool var)
+  if (${var})
+set(${var} True)
+  else()
+set(${var} False)
+  endif()
+endmacro()
+
+if (NOT DEFINED LIBCXX_ENABLE_SHARED)
+  set(LIBCXX_ENABLE_SHARED ON)
+endif()
+
+pythonize_bool(LIBUNWIND_BUILD_32_BITS)
+pythonize_bool(LIBCXX_ENABLE_SHARED)
+pythonize_bool(LIBUNWIND_ENABLE_SHARED)
+pythonize_bool(LIBUNWIND_ENABLE_THREADS)
+pythonize_bool(LIBUNWIND_ENABLE_EXCEPTIONS)
+pythonize_bool(LIBUNWIND_USE_LLVM_UNWINDER)
+pythonize_bool(LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY)
+set(LIBUNWIND_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
+"TargetInfo to use when setting up test environment.")
+set(LIBUNWIND_EXECUTOR "None" CACHE STRING
+"Executor to use when running tests.")
+
+set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not 
edit!")
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  @ONLY)
+
+add_lit_testsuite(check-unwind "Running libunwind tests"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  DEPENDS ${LIBUNWIND_TEST_DEPS}
+  )

Added: libunwind/trunk/test/libunwind/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/test/libunwind/__init__.py?rev=307266=auto
==
(empty)

Added: libunwind/trunk/test/libunwind/test/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/test/libunwind/test/__init__.py?rev=307266=auto
==
(empty)

Added: libunwind/trunk/test/libunwind/test/config.py
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/test/libunwind/test/config.py?rev=307266=auto
==
--- libunwind/trunk/test/libunwind/test/config.py (added)
+++ libunwind/trunk/test/libunwind/test/config.py Thu Jul  6 08:20:12 2017
@@ -0,0 +1,70 @@
+#===--===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is dual licensed under the MIT and the University of Illinois Open
+# Source Licenses. See LICENSE.TXT for details.
+#
+#===--===##
+import os
+import sys
+
+from libcxx.test.config import Configuration as LibcxxConfiguration
+
+
+class Configuration(LibcxxConfiguration):
+# pylint: disable=redefined-outer-name
+def __init__(self, lit_config, config):
+super(Configuration, self).__init__(lit_config, config)
+self.libunwind_src_root = None
+self.libunwind_obj_root = None
+self.abi_library_path = None
+self.libcxx_src_root = None
+
+def configure_src_root(self):
+self.libunwind_src_root = self.get_lit_conf(
+'libunwind_src_root',
+os.path.dirname(self.config.test_source_root))
+self.libcxx_src_root = self.get_lit_conf(
+'libcxx_src_root',
+os.path.join(self.libunwind_src_root, '/../libcxx'))
+
+def configure_obj_root(self):
+self.libunwind_obj_root = self.get_lit_conf('libunwind_obj_root')
+super(Configuration, self).configure_obj_root()
+
+def has_cpp_feature(self, feature, required_value):
+ 

[PATCH] D35038: [libunwind] Add a test harness

2017-07-06 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs closed this revision.
jroelofs added a comment.

r307266


https://reviews.llvm.org/D35038



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


[PATCH] D29658: [OpenMP] Customize CUDA-based tool chain selection

2017-07-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 105446.
gtbercea added a comment.

Use str()


https://reviews.llvm.org/D29658

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -572,8 +572,22 @@
   if (TT.getArch() == llvm::Triple::UnknownArch)
 Diag(clang::diag::err_drv_invalid_omp_target) << Val;
   else {
-const ToolChain  = getToolChain(C.getInputArgs(), TT);
-C.addOffloadDeviceToolChain(, Action::OFK_OpenMP);
+const ToolChain *TC;
+// CUDA toolchains have to be selected differently. They pair host
+// and device in their implementation.
+if (TT.isNVPTX()) {
+  const ToolChain *HostTC =
+  C.getSingleOffloadToolChain();
+  assert(HostTC && "Host toolchain should be always defined.");
+  auto  =
+  ToolChains[TT.str() + "/" + HostTC->getTriple().str()];
+  if (!CudaTC)
+CudaTC = llvm::make_unique(
+*this, TT, *HostTC, C.getInputArgs());
+  TC = CudaTC.get();
+} else
+  TC = (C.getInputArgs(), TT);
+C.addOffloadDeviceToolChain(TC, Action::OFK_OpenMP);
   }
 }
   } else


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -572,8 +572,22 @@
   if (TT.getArch() == llvm::Triple::UnknownArch)
 Diag(clang::diag::err_drv_invalid_omp_target) << Val;
   else {
-const ToolChain  = getToolChain(C.getInputArgs(), TT);
-C.addOffloadDeviceToolChain(, Action::OFK_OpenMP);
+const ToolChain *TC;
+// CUDA toolchains have to be selected differently. They pair host
+// and device in their implementation.
+if (TT.isNVPTX()) {
+  const ToolChain *HostTC =
+  C.getSingleOffloadToolChain();
+  assert(HostTC && "Host toolchain should be always defined.");
+  auto  =
+  ToolChains[TT.str() + "/" + HostTC->getTriple().str()];
+  if (!CudaTC)
+CudaTC = llvm::make_unique(
+*this, TT, *HostTC, C.getInputArgs());
+  TC = CudaTC.get();
+} else
+  TC = (C.getInputArgs(), TT);
+C.addOffloadDeviceToolChain(TC, Action::OFK_OpenMP);
   }
 }
   } else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307271 - [OpenMP] Customize CUDA-based tool chain selection

2017-07-06 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Thu Jul  6 09:08:15 2017
New Revision: 307271

URL: http://llvm.org/viewvc/llvm-project?rev=307271=rev
Log:
[OpenMP] Customize CUDA-based tool chain selection

Summary: This patch provides a generic way of selecting CUDA based tool chains 
as host-device pairs.

Reviewers: arpith-jacob, caomhin, carlo.bertolli, ABataev, Hahnfeld, jlebar, 
hfinkel, tstellar

Reviewed By: Hahnfeld

Subscribers: rengolin, cfe-commits

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

Modified:
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=307271=307270=307271=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Jul  6 09:08:15 2017
@@ -572,8 +572,22 @@ void Driver::CreateOffloadingDeviceToolC
   if (TT.getArch() == llvm::Triple::UnknownArch)
 Diag(clang::diag::err_drv_invalid_omp_target) << Val;
   else {
-const ToolChain  = getToolChain(C.getInputArgs(), TT);
-C.addOffloadDeviceToolChain(, Action::OFK_OpenMP);
+const ToolChain *TC;
+// CUDA toolchains have to be selected differently. They pair host
+// and device in their implementation.
+if (TT.isNVPTX()) {
+  const ToolChain *HostTC =
+  C.getSingleOffloadToolChain();
+  assert(HostTC && "Host toolchain should be always defined.");
+  auto  =
+  ToolChains[TT.str() + "/" + HostTC->getTriple().str()];
+  if (!CudaTC)
+CudaTC = llvm::make_unique(
+*this, TT, *HostTC, C.getInputArgs());
+  TC = CudaTC.get();
+} else
+  TC = (C.getInputArgs(), TT);
+C.addOffloadDeviceToolChain(TC, Action::OFK_OpenMP);
   }
 }
   } else


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


[PATCH] D29647: [OpenMP] Extend CLANG target options with device offloading kind.

2017-07-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 105453.
gtbercea added a comment.

.


https://reviews.llvm.org/D29647

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/BareMetal.cpp
  lib/Driver/ToolChains/BareMetal.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Cuda.cpp
  lib/Driver/ToolChains/Cuda.h
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/Darwin.h
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  lib/Driver/ToolChains/Hexagon.cpp
  lib/Driver/ToolChains/Hexagon.h
  lib/Driver/ToolChains/WebAssembly.cpp
  lib/Driver/ToolChains/WebAssembly.h
  lib/Driver/ToolChains/XCore.cpp
  lib/Driver/ToolChains/XCore.h

Index: lib/Driver/ToolChains/XCore.h
===
--- lib/Driver/ToolChains/XCore.h
+++ lib/Driver/ToolChains/XCore.h
@@ -67,7 +67,8 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
   void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const override;
+ llvm::opt::ArgStringList ,
+ Action::OffloadKind DeviceOffloadKind) const override;
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
Index: lib/Driver/ToolChains/XCore.cpp
===
--- lib/Driver/ToolChains/XCore.cpp
+++ lib/Driver/ToolChains/XCore.cpp
@@ -124,7 +124,8 @@
 }
 
 void XCoreToolChain::addClangTargetOptions(const ArgList ,
-   ArgStringList ) const {
+   ArgStringList ,
+   Action::OffloadKind) const {
   CC1Args.push_back("-nostdsysteminc");
 }
 
Index: lib/Driver/ToolChains/WebAssembly.h
===
--- lib/Driver/ToolChains/WebAssembly.h
+++ lib/Driver/ToolChains/WebAssembly.h
@@ -53,7 +53,8 @@
   bool SupportsProfiling() const override;
   bool HasNativeLLVMSupport() const override;
   void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const override;
+ llvm::opt::ArgStringList ,
+ Action::OffloadKind DeviceOffloadKind) const override;
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
   void AddClangSystemIncludeArgs(
Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -134,7 +134,8 @@
 bool WebAssembly::HasNativeLLVMSupport() const { return true; }
 
 void WebAssembly::addClangTargetOptions(const ArgList ,
-ArgStringList ) const {
+ArgStringList ,
+Action::OffloadKind) const {
   if (DriverArgs.hasFlag(clang::driver::options::OPT_fuse_init_array,
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
Index: lib/Driver/ToolChains/Hexagon.h
===
--- lib/Driver/ToolChains/Hexagon.h
+++ lib/Driver/ToolChains/Hexagon.h
@@ -69,7 +69,8 @@
   ~HexagonToolChain() override;
 
   void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const override;
+ llvm::opt::ArgStringList ,
+ Action::OffloadKind DeviceOffloadKind) const override;
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
Index: lib/Driver/ToolChains/Hexagon.cpp
===
--- lib/Driver/ToolChains/Hexagon.cpp
+++ lib/Driver/ToolChains/Hexagon.cpp
@@ -428,7 +428,8 @@
 }
 
 void HexagonToolChain::addClangTargetOptions(const ArgList ,
- ArgStringList ) const {
+ ArgStringList ,
+ Action::OffloadKind) const {
   if (DriverArgs.hasArg(options::OPT_ffp_contract))
 return;
   unsigned OptLevel = getOptimizationLevel(DriverArgs);
Index: lib/Driver/ToolChains/Gnu.h
===
--- lib/Driver/ToolChains/Gnu.h
+++ lib/Driver/ToolChains/Gnu.h
@@ -341,7 +341,8 @@
   : Generic_GCC(D, Triple, Args) {}
 
   void addClangTargetOptions(const llvm::opt::ArgList ,
-   

r307272 - [OpenMP] Extend CLANG target options with device offloading kind.

2017-07-06 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Thu Jul  6 09:22:21 2017
New Revision: 307272

URL: http://llvm.org/viewvc/llvm-project?rev=307272=rev
Log:
[OpenMP] Extend CLANG target options with device offloading kind.

Summary: Pass the type of the device offloading when building the tool chain 
for a particular target architecture. This is required when supporting multiple 
tool chains that target a single device type. In our particular use case, the 
OpenMP and CUDA tool chains will use the same ```addClangTargetOptions ``` 
method. This enables the reuse of common options and ensures control over 
options only supported by a particular tool chain.

Reviewers: arpith-jacob, caomhin, carlo.bertolli, ABataev, jlebar, hfinkel, 
tstellar, Hahnfeld

Reviewed By: hfinkel

Subscribers: jgravelle-google, aheejin, rengolin, jfb, dschuff, sbc100, 
cfe-commits

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

Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/BareMetal.cpp
cfe/trunk/lib/Driver/ToolChains/BareMetal.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.h
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.h
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.h
cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
cfe/trunk/lib/Driver/ToolChains/Hexagon.h
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
cfe/trunk/lib/Driver/ToolChains/XCore.cpp
cfe/trunk/lib/Driver/ToolChains/XCore.h

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=307272=307271=307272=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Thu Jul  6 09:22:21 2017
@@ -411,7 +411,8 @@ public:
 
   /// \brief Add options that need to be passed to cc1 for this target.
   virtual void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const;
+ llvm::opt::ArgStringList ,
+ Action::OffloadKind DeviceOffloadKind) 
const;
 
   /// \brief Add warning options that need to be passed to cc1 for this target.
   virtual void addClangWarningOptions(llvm::opt::ArgStringList ) const;

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=307272=307271=307272=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Thu Jul  6 09:22:21 2017
@@ -544,9 +544,9 @@ void ToolChain::AddClangSystemIncludeArg
   // Each toolchain should provide the appropriate include flags.
 }
 
-void ToolChain::addClangTargetOptions(const ArgList ,
-  ArgStringList ) const {
-}
+void ToolChain::addClangTargetOptions(
+const ArgList , ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {}
 
 void ToolChain::addClangWarningOptions(ArgStringList ) const {}
 

Modified: cfe/trunk/lib/Driver/ToolChains/BareMetal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/BareMetal.cpp?rev=307272=307271=307272=diff
==
--- cfe/trunk/lib/Driver/ToolChains/BareMetal.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/BareMetal.cpp Thu Jul  6 09:22:21 2017
@@ -98,7 +98,8 @@ void BareMetal::AddClangSystemIncludeArg
 }
 
 void BareMetal::addClangTargetOptions(const ArgList ,
-  ArgStringList ) const {
+  ArgStringList ,
+  Action::OffloadKind) const {
   CC1Args.push_back("-nostdsysteminc");
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/BareMetal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/BareMetal.h?rev=307272=307271=307272=diff
==
--- cfe/trunk/lib/Driver/ToolChains/BareMetal.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/BareMetal.h Thu Jul  6 09:22:21 2017
@@ -54,7 +54,8 @@ public:
   void AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ) const 
override;
   void addClangTargetOptions(const llvm::opt::ArgList ,
- llvm::opt::ArgStringList ) const override;
+ llvm::opt::ArgStringList ,
+   

[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:142
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;

erik.pilkington wrote:
> arphaman wrote:
> > erik.pilkington wrote:
> > > Why are we doing this just for partials? Doesn't this also apply to 
> > > unavailable/deprecated?
> > We warned about the unavailable/deprecated protocols previously, so we 
> > should probably keep these warnings. The unguarded availability one is new, 
> > so we can drop it.
> But this is strictly less diagnostics, dropping diagnostics for unavail/depr 
> here won't break anything outside of clang tests. So if they don't make sense 
> to emit, then there isn't any reason to keep them around.
Swift emits warnings about deprecated/unavailable protocols even in the list of 
protocol requirements. I'd prefer it if we had the same behaviour.


Repository:
  rL LLVM

https://reviews.llvm.org/D35061



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


[PATCH]:[Clang] Add -fno-plt,-fplt to ignored flags

2017-07-06 Thread Jordan Glover via cfe-commits
In GCC there is a -fno-plt flag not implemented in Clang which results in 
compilation failure:

clang-4.0: error: unknown argument: '-fno-plt'

Proposed patch adds -fno-plt and -fplt to existing ignored flags list making it 
compatible with gcc for package building. You can see more info about those 
flags in gcc manual:
https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Code-Gen-Options.html#Code-Gen-Options
Thank you for your attention.
Jordan GloverIndex: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td	(revision 307280)
+++ include/clang/Driver/Options.td	(working copy)
@@ -2497,6 +2497,7 @@
 defm non_call_exceptions : BooleanFFlag<"non-call-exceptions">, Group;
 defm peel_loops : BooleanFFlag<"peel-loops">, Group;
 defm permissive : BooleanFFlag<"permissive">, Group;
+defm plt : BooleanFFlag<"plt">, Group;
 defm prefetch_loop_arrays : BooleanFFlag<"prefetch-loop-arrays">, Group;
 defm printf : BooleanFFlag<"printf">, Group;
 defm profile : BooleanFFlag<"profile">, Group;
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c	(revision 307280)
+++ test/Driver/clang_f_opts.c	(working copy)
@@ -275,6 +275,7 @@
 // RUN: -fno-fat-lto-objects -ffat-lto-objects\
 // RUN: -fno-merge-constants -fmerge-constants\
 // RUN: -fno-caller-saves -fcaller-saves  \
+// RUN: -fno-plt  \
 // RUN: -fno-reorder-blocks -freorder-blocks  \
 // RUN: -fno-schedule-insns2 -fschedule-insns2\
 // RUN: -fno-stack-check  \
@@ -281,6 +282,7 @@
 // RUN: -fno-check-new -fcheck-new\
 // RUN: -ffriend-injection\
 // RUN: -fno-implement-inlines -fimplement-inlines\
+// RUN: -fplt \
 // RUN: -fstack-check \
 // RUN: -fforce-addr  \
 // RUN: -malign-functions=100 \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35041: [analyzer] Fix modeling of bool based types

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

In https://reviews.llvm.org/D35041#801073, @alexshap wrote:

> evalCastFromNonLoc is actually called there (and that's how i ran into this 
> issue) because of (a bit unexpected to me) ImplicitCastExpr 'LValueToRValue' 
> inside switch


Yeah, but the `NonLoc` that's being casted is definitely not 
`nonloc::LocAsInteger`.
And i also tried to run your test with only `BasicValueFactory` fix and it 
passed.

In https://reviews.llvm.org/D35041#801073, @alexshap wrote:

> evalCastFromLoc - that's hard to me - so far i have not found a valid 
> compilable c++ code to cast a pointer to bool enum.


I didn't see if that's exactly what we're looking for, but the following 
compiles and crashes:

  EnumBool E = static_cast((intptr_t)nullptr);
  switch (E) {
  case EnumBool::F:
return false;
  }
  return true;


Repository:
  rL LLVM

https://reviews.llvm.org/D35041



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


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

2017-07-06 Thread Frederich Munch via Phabricator via cfe-commits
marsupial created this revision.
Herald added a subscriber: mgorny.

Getting this to work is not particularly obvious, and having it as an example 
should be helpful.
Portions of this could be placed into LLVM, but as a whole it seems necessary 
to do this a higher level.


https://reviews.llvm.org/D35103

Files:
  examples/clang-interpreter/CMakeLists.txt
  examples/clang-interpreter/Invoke.cpp
  examples/clang-interpreter/Invoke.h
  examples/clang-interpreter/Manager.cpp
  examples/clang-interpreter/Manager.h
  examples/clang-interpreter/README.txt
  examples/clang-interpreter/Test.cxx
  examples/clang-interpreter/main.cpp

Index: examples/clang-interpreter/main.cpp
===
--- examples/clang-interpreter/main.cpp
+++ examples/clang-interpreter/main.cpp
@@ -7,6 +7,9 @@
 //
 //===--===//
 
+#include "Invoke.h"
+#include "Manager.h"
+
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Driver/Compilation.h"
@@ -26,73 +29,61 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
+
 using namespace clang;
 using namespace clang::driver;
 
+namespace interpreter {
+
+static llvm::ExecutionEngine *
+createExecutionEngine(std::unique_ptr M, std::string *ErrorStr) {
+  llvm::EngineBuilder EB(std::move(M));
+  EB.setErrorStr(ErrorStr);
+  EB.setMemoryManager(llvm::make_unique());
+  llvm::ExecutionEngine *EE = EB.create();
+  EE->finalizeObject();
+  return EE;
+}
+
+// Invoked from a try/catch block in invoke.cpp.
+//
+static int Invoke(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
+  const std::vector , char *const *EnvP) {
+  return EE->runFunctionAsMain(EntryFn, Args, EnvP);
+}
+
 // This function isn't referenced outside its translation unit, but it
 // can't use the "static" keyword because its address is used for
 // GetMainExecutable (since some platforms don't support taking the
 // address of main, and some platforms can't implement GetMainExecutable
 // without being given the address of a function in the main executable).
-std::string GetExecutablePath(const char *Argv0) {
-  // This just needs to be some symbol in the binary; C++ doesn't
-  // allow taking the address of ::main however.
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-static llvm::ExecutionEngine *
-createExecutionEngine(std::unique_ptr M, std::string *ErrorStr) {
-  return llvm::EngineBuilder(std::move(M))
-  .setEngineKind(llvm::EngineKind::Either)
-  .setErrorStr(ErrorStr)
-  .create();
-}
-
-static int Execute(std::unique_ptr Mod, char *const *envp) {
-  llvm::InitializeNativeTarget();
-  llvm::InitializeNativeTargetAsmPrinter();
-
-  llvm::Module  = *Mod;
-  std::string Error;
-  std::unique_ptr EE(
-  createExecutionEngine(std::move(Mod), ));
-  if (!EE) {
-llvm::errs() << "unable to make execution engine: " << Error << "\n";
-return 255;
-  }
-
-  llvm::Function *EntryFn = M.getFunction("main");
-  if (!EntryFn) {
-llvm::errs() << "'main' function not found in module.\n";
-return 255;
-  }
-
-  // FIXME: Support passing arguments.
-  std::vector Args;
-  Args.push_back(M.getModuleIdentifier());
-
-  EE->finalizeObject();
-  return EE->runFunctionAsMain(EntryFn, Args, envp);
-}
+} // namespace interpreter
 
 int main(int argc, const char **argv, char * const *envp) {
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
-  std::string Path = GetExecutablePath(argv[0]);
+  // This just needs to be some symbol in the binary; C++ doesn't
+  // allow taking the address of ::main however.
+  void *MainAddr = (void*) (intptr_t) interpreter::GetExecutablePath;
+  std::string Path = interpreter::GetExecutablePath(argv[0], MainAddr);
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   TextDiagnosticPrinter *DiagClient =
 new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
 
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
 
-  // Use ELF on windows for now.
-  std::string TripleStr = llvm::sys::getProcessTriple();
+  const std::string TripleStr = llvm::sys::getProcessTriple();
   llvm::Triple T(TripleStr);
+
+  // Use ELF on Windows-32 for now.
+#if defined(_WIN32) && !defined(_WIN64)
   if (T.isOSBinFormatCOFF())
 T.setObjectFormat(llvm::Triple::ELF);
-
+#endif
+	
   Driver TheDriver(Path, T.str(), Diags);
   TheDriver.setTitle("clang interpreter");
   TheDriver.setCheckInputsExist(false);
@@ -163,12 +154,36 @@
   if (!Clang.ExecuteAction(*Act))
 return 1;
 
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
   int Res = 255;
-  if (std::unique_ptr Module = Act->takeModule())
-Res = 

[PATCH] D35078: [clang-tidy] Fix modernize-use-override incorrect replacement

2017-07-06 Thread Victor Gao via Phabricator via cfe-commits
vgao added a comment.

@alexfh Could you please land this for me? Thanks!


https://reviews.llvm.org/D35078



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


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

2017-07-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Looks great, thanks!  Just a few minor changes.




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

yaxunl wrote:
> rjmccall wrote:
> > You used VoidPtrTy above.
> They are different fields with different types.
They're both the isa field of a block object.  The difference is just between 
allocating the block globally and allocating it on the stack.



Comment at: lib/CodeGen/TargetInfo.h:237
+  virtual unsigned getGlobalVarAddressSpace(const VarDecl *D,
+CodeGenModule ) const;
+

The CGM is conventionally the first argument.



Comment at: lib/CodeGen/TargetInfo.h:262
+   unsigned DestAddr,
+   llvm::Type *DestTy) const;
 };

This should probably take the CGM for completeness.


https://reviews.llvm.org/D33842



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


[PATCH] D34578: cmath: Support clang's -fdelayed-template-parsing

2017-07-06 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D34578#801357, @dexonsmith wrote:

> Ping!  Hal, you committed r283051.  Do you have a problem with this?


It looks like you're just renaming `__libcpp_isnan` and friends to 
__libcpp_isnan_or_builtin` and similar. LGTM

> (Incidentally, I noticed that r283051 was optimizing the implementation of 
> . I wonder why we have so much code in that header, instead of 
> calling out to libc's already-optimized  implementation?)

This is definitely worth looking at (especially given that we don't support 
complex of user-defined types with those functions). Would making 
complex use _Complex double, and so on, be an API break? Would that 
matter?


https://reviews.llvm.org/D34578



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


r307341 - Update Cross-DSO CFI documentation.

2017-07-06 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Jul  6 17:48:12 2017
New Revision: 307341

URL: http://llvm.org/viewvc/llvm-project?rev=307341=rev
Log:
Update Cross-DSO CFI documentation.

Reviewers: pcc

Subscribers: llvm-commits

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

Modified:
cfe/trunk/docs/ControlFlowIntegrityDesign.rst

Modified: cfe/trunk/docs/ControlFlowIntegrityDesign.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrityDesign.rst?rev=307341=307340=307341=diff
==
--- cfe/trunk/docs/ControlFlowIntegrityDesign.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrityDesign.rst Thu Jul  6 17:48:12 2017
@@ -437,12 +437,17 @@ export this information, every DSO imple
 
 .. code-block:: none
 
-   void __cfi_check(uint64 CallSiteTypeId, void *TargetAddr)
+   void __cfi_check(uint64 CallSiteTypeId, void *TargetAddr, void *DiagData)
 
-This function provides external modules with access to CFI checks for the
-targets inside this DSO.  For each known ``CallSiteTypeId``, this function
-performs an ``llvm.type.test`` with the corresponding type identifier. It
-aborts if the type is unknown, or if the check fails.
+This function provides external modules with access to CFI checks for
+the targets inside this DSO.  For each known ``CallSiteTypeId``, this
+function performs an ``llvm.type.test`` with the corresponding type
+identifier. It reports an error if the type is unknown, or if the
+check fails. Depending on the values of compiler flags
+``-fsanitize-trap`` and ``-fsanitize-recover``, this function may
+print an error, abort and/or return to the caller. ``DiagData`` is an
+opaque pointer to the diagnostic information about the error, or
+``null`` if the caller does not provide this information.
 
 The basic implementation is a large switch statement over all values
 of CallSiteTypeId supported by this DSO, and each case is similar to
@@ -452,11 +457,10 @@ CFI Shadow
 --
 
 To route CFI checks to the target DSO's __cfi_check function, a
-mapping from possible virtual / indirect call targets to
-the corresponding __cfi_check functions is maintained. This mapping is
+mapping from possible virtual / indirect call targets to the
+corresponding __cfi_check functions is maintained. This mapping is
 implemented as a sparse array of 2 bytes for every possible page (4096
-bytes) of memory. The table is kept readonly (FIXME: not yet) most of
-the time.
+bytes) of memory. The table is kept readonly most of the time.
 
 There are 3 types of shadow values:
 
@@ -481,14 +485,24 @@ them.
 CFI_SlowPath
 
 
-The slow path check is implemented in compiler-rt library as
+The slow path check is implemented in a runtime support library as
 
 .. code-block:: none
 
   void __cfi_slowpath(uint64 CallSiteTypeId, void *TargetAddr)
+  void __cfi_slowpath_diag(uint64 CallSiteTypeId, void *TargetAddr, void 
*DiagData)
 
-This functions loads a shadow value for ``TargetAddr``, finds the
-address of __cfi_check as described above and calls that.
+These functions loads a shadow value for ``TargetAddr``, finds the
+address of ``__cfi_check`` as described above and calls
+that. ``DiagData`` is an opaque pointer to diagnostic data which is
+passed verbatim to ``__cfi_check``, and ``__cfi_slowpath`` passes
+``nullptr`` instead.
+
+Compiler-RT library contains reference implementations of slowpath
+functions, but they have unresolvable issues with correctness and
+performance in the handling of dlopen(). It is recommended that
+platforms provide their own implementations, usually as part of libc
+or libdl.
 
 Position-independent executable requirement
 ---


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


[PATCH] D35078: [clang-tidy] Fix modernize-use-override incorrect replacement

2017-07-06 Thread Victor Gao via Phabricator via cfe-commits
vgao updated this revision to Diff 105554.
vgao added a comment.

Change variable name `Parens` to `NestedParens`


https://reviews.llvm.org/D35078

Files:
  clang-tidy/modernize/UseOverrideCheck.cpp
  test/clang-tidy/modernize-use-override.cpp


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -12,6 +12,10 @@
 
 struct MUST_USE_RESULT MustUseResultObject {};
 
+struct IntPair {
+  int First, Second;
+};
+
 struct Base {
   virtual ~Base() {}
   virtual void a();
@@ -41,6 +45,8 @@
 
   virtual void ne() noexcept(false);
   virtual void t() throw();
+
+  virtual void il(IntPair);
 };
 
 struct SimpleCases : public Base {
@@ -221,6 +227,14 @@
   // CHECK-FIXES: {{^}}  void cv2() const volatile override // some comment
 };
 
+struct DefaultArguments : public Base {
+  // Tests for default arguments (with initializer lists).
+  // Make sure the override fix is placed after the argument list.
+  void il(IntPair p = {1, (2 + (3))}) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void il(IntPair p = {1, (2 + (3))}) override {}
+};
+
 struct Macros : public Base {
   // Tests for 'virtual' and 'override' being defined through macros. Basically
   // give up for now.
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@
  File.end());
   SmallVector Tokens;
   Token Tok;
+  int NestedParens = 0;
   while (!RawLexer.LexFromRawLexer(Tok)) {
-if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && NestedParens == 0)
   break;
 if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
   break;
+if (Tok.is(tok::l_paren))
+  ++NestedParens;
+else if (Tok.is(tok::r_paren))
+  --NestedParens;
 if (Tok.is(tok::raw_identifier)) {
   IdentifierInfo  = Result.Context->Idents.get(StringRef(
   Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));


Index: test/clang-tidy/modernize-use-override.cpp
===
--- test/clang-tidy/modernize-use-override.cpp
+++ test/clang-tidy/modernize-use-override.cpp
@@ -12,6 +12,10 @@
 
 struct MUST_USE_RESULT MustUseResultObject {};
 
+struct IntPair {
+  int First, Second;
+};
+
 struct Base {
   virtual ~Base() {}
   virtual void a();
@@ -41,6 +45,8 @@
 
   virtual void ne() noexcept(false);
   virtual void t() throw();
+
+  virtual void il(IntPair);
 };
 
 struct SimpleCases : public Base {
@@ -221,6 +227,14 @@
   // CHECK-FIXES: {{^}}  void cv2() const volatile override // some comment
 };
 
+struct DefaultArguments : public Base {
+  // Tests for default arguments (with initializer lists).
+  // Make sure the override fix is placed after the argument list.
+  void il(IntPair p = {1, (2 + (3))}) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void il(IntPair p = {1, (2 + (3))}) override {}
+};
+
 struct Macros : public Base {
   // Tests for 'virtual' and 'override' being defined through macros. Basically
   // give up for now.
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@
  File.end());
   SmallVector Tokens;
   Token Tok;
+  int NestedParens = 0;
   while (!RawLexer.LexFromRawLexer(Tok)) {
-if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && NestedParens == 0)
   break;
 if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
   break;
+if (Tok.is(tok::l_paren))
+  ++NestedParens;
+else if (Tok.is(tok::r_paren))
+  --NestedParens;
 if (Tok.is(tok::raw_identifier)) {
   IdentifierInfo  = Result.Context->Idents.get(StringRef(
   Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307329 - This call-site should have been updated as part of D34304.

2017-07-06 Thread Sterling Augustine via cfe-commits
Author: saugustine
Date: Thu Jul  6 15:47:19 2017
New Revision: 307329

URL: http://llvm.org/viewvc/llvm-project?rev=307329=rev
Log:
This call-site should have been updated as part of D34304.

Summary: Use an argument adjuster to preserve behavior inadvertantly changed by 
D34304.

Reviewers: klimek

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

Modified:
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=307329=307328=307329=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Thu Jul  6 15:47:19 2017
@@ -139,9 +139,11 @@ bool runToolOnCodeWithArgs(
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   llvm::IntrusiveRefCntPtr Files(
   new FileManager(FileSystemOptions(), OverlayFileSystem));
-  ToolInvocation Invocation(getSyntaxOnlyToolArgs(ToolName, Args, FileNameRef),
-ToolAction, Files.get(),
-std::move(PCHContainerOps));
+  ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster();
+  ToolInvocation Invocation(
+  getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), 
FileNameRef),
+  ToolAction, Files.get(),
+  std::move(PCHContainerOps));
 
   SmallString<1024> CodeStorage;
   InMemoryFileSystem->addFile(FileNameRef, 0,


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


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

2017-07-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

If this is a common algorithm across all ABIs, can we just put Sema / the AST 
in charge of computing it?  It's not a cheap thing to recompute retroactively, 
especially for an imported type, and it seems like it's easily derived from the 
things that go into DerivedData.


Repository:
  rL LLVM

https://reviews.llvm.org/D35056



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


[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations

2017-07-06 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:142
   if (Result == AR_NotYetIntroduced) {
+if (AvoidAvailabilityChecks)
+  return;

Why are we doing this just for partials? Doesn't this also apply to 
unavailable/deprecated?


Repository:
  rL LLVM

https://reviews.llvm.org/D35061



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


[PATCH] D33659: Extend DynamicLibrary class to be usable without loading permanently.

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

ping


https://reviews.llvm.org/D33659



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


[PATCH] D33659: Extend DynamicLibrary class to be usable without loading permanently.

2017-07-06 Thread Frederich Munch via Phabricator via cfe-commits
marsupial updated this revision to Diff 105466.

https://reviews.llvm.org/D33659

Files:
  lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp


Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -53,23 +53,23 @@
i != e; ++i) {
 // Get access to the plugin.
 std::string err;
-DynamicLibrary lib = DynamicLibrary::getPermanentLibrary(i->c_str(), );
-if (!lib.isValid()) {
+DynamicLibrary *lib = DynamicLibrary::getPermanentLibrary(i->c_str(), 
);
+if (!lib) {
   diags->Report(diag::err_fe_unable_to_load_plugin) << *i << err;
   continue;
 }
 
 // See if it's compatible with this build of clang.
 const char *pluginAPIVersion =
-  (const char *) lib.getAddressOfSymbol("clang_analyzerAPIVersionString");
+  (const char *) lib->getAddressOfSymbol("clang_analyzerAPIVersionString");
 if (!isCompatibleAPIVersion(pluginAPIVersion)) {
   warnIncompatible(diags, *i, pluginAPIVersion);
   continue;
 }
 
 // Register its checkers.
 RegisterCheckersFn registerPluginCheckers =
-  (RegisterCheckersFn) (intptr_t) lib.getAddressOfSymbol(
+  (RegisterCheckersFn) (intptr_t) lib->getAddressOfSymbol(
   
"clang_registerCheckers");
 if (registerPluginCheckers)
   registerPluginCheckers(*this);


Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -53,23 +53,23 @@
i != e; ++i) {
 // Get access to the plugin.
 std::string err;
-DynamicLibrary lib = DynamicLibrary::getPermanentLibrary(i->c_str(), );
-if (!lib.isValid()) {
+DynamicLibrary *lib = DynamicLibrary::getPermanentLibrary(i->c_str(), );
+if (!lib) {
   diags->Report(diag::err_fe_unable_to_load_plugin) << *i << err;
   continue;
 }
 
 // See if it's compatible with this build of clang.
 const char *pluginAPIVersion =
-  (const char *) lib.getAddressOfSymbol("clang_analyzerAPIVersionString");
+  (const char *) lib->getAddressOfSymbol("clang_analyzerAPIVersionString");
 if (!isCompatibleAPIVersion(pluginAPIVersion)) {
   warnIncompatible(diags, *i, pluginAPIVersion);
   continue;
 }
 
 // Register its checkers.
 RegisterCheckersFn registerPluginCheckers =
-  (RegisterCheckersFn) (intptr_t) lib.getAddressOfSymbol(
+  (RegisterCheckersFn) (intptr_t) lib->getAddressOfSymbol(
   "clang_registerCheckers");
 if (registerPluginCheckers)
   registerPluginCheckers(*this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35000: [OpenCL] Added extended tests on metadata generation for half data type and arrays.

2017-07-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In https://reviews.llvm.org/D35000#799705, @Anastasia wrote:

> Btw, is there any reason to add testing specifically for half? Is there 
> anything specific to half in the implementation of this?


Trying to understand the reason for this change though...


https://reviews.llvm.org/D35000



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


r307296 - [Objective-C] Fix non-determinism in clang

2017-07-06 Thread Mandeep Singh Grang via cfe-commits
Author: mgrang
Date: Thu Jul  6 11:49:57 2017
New Revision: 307296

URL: http://llvm.org/viewvc/llvm-project?rev=307296=rev
Log:
 [Objective-C] Fix non-determinism in clang

Summary: Iteration of the unordered Ivars causes 
objc-modern-metadata-visibility.mm (uncovered by reverse iterating SmallPtrSet).

Reviewers: dblaikie, davide, rsmith

Reviewed By: dblaikie

Subscribers: cfe-commits, llvm-commits

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

Added:
cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
Modified:
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=307296=307295=307296=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Thu Jul  6 11:49:57 
2017
@@ -146,7 +146,7 @@ namespace {
 
 llvm::DenseMap RewrittenBlockExprs;
 llvm::DenseMap > ReferencedIvars;
+llvm::SmallSetVector > ReferencedIvars;
 
 // ivar bitfield grouping containers
 llvm::DenseSet ObjCInterefaceHasBitfieldGroups;
@@ -1013,7 +1013,7 @@ void RewriteModernObjC::RewritePropertyI
 Setr = "\nextern \"C\" __declspec(dllimport) "
 "void objc_setProperty (id, SEL, long, id, bool, bool);\n";
   }
-  
+
   RewriteObjCMethodDecl(OID->getContainingInterface(), 
 PD->getSetterMethodDecl(), Setr);
   Setr += "{ ";
@@ -3965,10 +3965,11 @@ void RewriteModernObjC::RewriteIvarOffse
   std::string ) {
   // write out ivar offset symbols which have been referenced in an ivar
   // access expression.
-  llvm::SmallPtrSet Ivars = ReferencedIvars[CDecl];
+  llvm::SmallSetVector Ivars = ReferencedIvars[CDecl];
+
   if (Ivars.empty())
 return;
-  
+
   llvm::DenseSet 
GroupSymbolOutput;
   for (ObjCIvarDecl *IvarDecl : Ivars) {
 const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface();

Added: cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm?rev=307296=auto
==
--- cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm (added)
+++ cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm Thu Jul  6 
11:49:57 2017
@@ -0,0 +1,45 @@
+// REQUIRES: abi-breaking-checks
+// NOTE: This test has been split from objc-modern-metadata-visibility.mm in
+// order to test with -reverse-iterate as this flag is only present with
+// ABI_BREAKING_CHECKS.
+
+// RUN: %clang_cc1 -E %s -o %t.mm -mllvm -reverse-iterate
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc 
%t.mm -mllvm -reverse-iterate -o - | FileCheck %s
+// rdar://11144048
+
+@class NSString;
+
+@interface NSObject {
+Class isa;
+}
+@end
+
+@interface Sub : NSObject {
+int subIvar;
+NSString *nsstring;
+@private
+id PrivateIvar;
+}
+@end
+
+@implementation Sub
+- (id) MyNSString { return subIvar ? PrivateIvar : nsstring; }
+@end
+
+@interface NSString @end
+@implementation NSString @end
+
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$subIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long 
OBJC_IVAR_$_Sub$PrivateIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$nsstring;
+// CHECK: #pragma warning(disable:4273)
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$subIvar
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" 
__declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$nsstring
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long int 
OBJC_IVAR_$_Sub$PrivateIvar
+// CHECK: extern "C" __declspec(dllimport) struct _class_t 
OBJC_METACLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_Sub
+// CHECK: extern "C" __declspec(dllimport) struct _class_t 
OBJC_CLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_Sub
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_CLASS_$_NSString;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_METACLASS_$_NSString
+// CHECK: extern "C" __declspec(dllexport) struct _class_t 
OBJC_CLASS_$_NSString


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


[PATCH] D34784: [OpenMP] Add flag for specifying the target device architecture for OpenMP device offloading

2017-07-06 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:474
+for (StringRef Opt : OptList) {
+  AddMArchOption(DAL, Opts, Opt);
+}

gtbercea wrote:
> hfinkel wrote:
> > Shouldn't you be adding all of the options, not just the -march= ones?
> I thought that that would be the case but there are a few issues:
> 
> 1. PTXAS and NVLINK each use a different flag for specifying the arch, and, 
> in turn, each flag is different from -march.
> 
> 2. -Xopenmp-target passes a flag to the entire toolchain not to individual 
> components of the toolchain so a translation of flags is required in some 
> cases to adapt the flag to the actual tool. -march is one example, I'm not 
> sure if there are others.
> 
> 3. At this point in the code, in order to add a flag and its value to the DAL 
> list, I need to be able to specify the option type (i.e. 
> options::OPT_march_EQ). I therefore need to manually recognize the flag in 
> the string representing the value of -Xopenmp-target or 
> -Xopenmp-target=triple.
> 
> 4. This patch handles the passing of the arch and can be extended to pass 
> other flags (as is stands, no other flags are passed through to the CUDA 
> toolchain). This can be extended on a flag by flag basis for flags that need 
> translating to a particular tool's flag. If the flag doesn't need translating 
> then the flag and it's value can be appended to the command line as they are.
> 1. PTXAS and NVLINK each use a different flag for specifying the arch, and, 
> in turn, each flag is different from -march.

I don't understand why this is relevant. Don't NVPTX::Assembler::ConstructJob 
and NVPTX::Linker::ConstructJob handle that in either case?

This seems to be the same comment to point 2 as well.

> 3. At this point in the code, in order to add a flag and its value to the DAL 
> list, I need to be able to specify the option type (i.e. 
> options::OPT_march_EQ). I therefore need to manually recognize the flag in 
> the string representing the value of -Xopenmp-target or 
> -Xopenmp-target=triple.

I don't understand why this is true. Doesn't the code just below this, which 
handles -Xarch, do the general thing (it calls Opts.ParseOneArg and then adds 
it to the list of derived arguments)? Can't we handle this like -Xarch?

> This patch handles the passing of the arch and can be extended to pass other 
> flags (as is stands, no other flags are passed through to the CUDA 
> toolchain). This can be extended on a flag by flag basis for flags that need 
> translating to a particular tool's flag. If the flag doesn't need translating 
> then the flag and it's value can be appended to the command line as they are.

I don't understand this either. If we need to extend this on a flag-by-flag 
basis, then it seems fundamentally broken. How could we append a flag to the 
command line without it also affecting the host compile?



Comment at: test/Driver/openmp-offload.c:607
+
+// CHK-FOPENMP-EQ-TARGET: clang{{.*}} argument unused during compilation: 
'-Xopenmp-target=powerpc64le-ibm-linux-gnu -march=pwr8'
+

gtbercea wrote:
> hfinkel wrote:
> > I don't see why you'd check that the arguments are unused. They should be 
> > used. One exception might be that you might want to force 
> > -Xopenmp-target=foo to be unused if foo is not a currently-targeted 
> > offloading triple. There could be a separate test case for that.
> > 
> > Otherwise, I think you should be able to check the relevant backend 
> > commands, no? (something like where CHK-COMMANDS is used above in this 
> > file).
> Only the CUDA toolchain currently contains code which considers the value of 
> the -Xopenmp-target flag. The CUDA toolchain is not capable of offloading 
> until the next patch lands so any test for how the flag propagates to the 
> CUDA toolchain will have to wait.
> 
> Passing a flag to some other toolchain again doesn't work because the other 
> toolchains have not been instructed to look at this flag so they won't 
> contain the passed flag in their respective command lines.
> 
> For a lack of a better test, what I wanted to show is that the usage of this 
> flag doesn't throw an error such as unknown flag and is correctly recognized: 
> "-Xopenmp-target=powerpc64le-ibm-linux-gnu -march=pwr8". 
> 
> 
> 
> Passing a flag to some other toolchain again doesn't work because the other 
> toolchains have not been instructed to look at this flag so they won't 
> contain the passed flag in their respective command lines.

I think, however, that we need to refactor this so that it works for all 
toolchains. If you convince me otherwise, then this will be fine as well :-)



https://reviews.llvm.org/D34784



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


[PATCH] D35041: [analyzer] Fix modeling of bool based types

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

Add a test where SimpleSValBuilder::evalCastFromNonLoc is called and we hit the 
line unsigned castSize = Context.getIntWidth(castTy);


Repository:
  rL LLVM

https://reviews.llvm.org/D35041

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/enum.cpp


Index: test/Analysis/enum.cpp
===
--- test/Analysis/enum.cpp
+++ test/Analysis/enum.cpp
@@ -37,3 +37,33 @@
   }
   return true;
 }
+
+bool testNoCrashOnSwitchEnumBoolConstant() {
+  EnumBool E = EnumBool::F;
+  switch (E) {
+case EnumBool::F:
+  return false; 
+  }
+  return true; 
+}
+
+typedef __INTPTR_TYPE__ intptr_t;
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromNullptr() {
+  EnumBool E = static_cast((intptr_t)nullptr);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
+
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromPtr() {
+  int X;
+  intptr_t P =  
+  EnumBool E = static_cast(P);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -71,18 +71,15 @@
 }
 
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-
   bool isLocType = Loc::isLocType(castTy);
-
   if (val.getAs())
 return val;
 
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
-
 // FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getTypeSize(castTy);
+unsigned castSize = Context.getIntWidth(castTy);
 if (castSize == LI->getNumBits())
   return val;
 return makeLocAsInteger(LI->getLoc(), castSize);
@@ -173,7 +170,7 @@
   }
 
   if (castTy->isIntegralOrEnumerationType()) {
-unsigned BitWidth = Context.getTypeSize(castTy);
+unsigned BitWidth = Context.getIntWidth(castTy);
 
 if (!val.getAs())
   return makeLocAsInteger(val, BitWidth);
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -124,7 +124,7 @@
   /// Returns the type of the APSInt used to store values of the given 
QualType.
   APSIntType getAPSIntType(QualType T) const {
 assert(T->isIntegralOrEnumerationType() || Loc::isLocType(T));
-return APSIntType(Ctx.getTypeSize(T),
+return APSIntType(Ctx.getIntWidth(T),
   !T->isSignedIntegerOrEnumerationType());
   }
 


Index: test/Analysis/enum.cpp
===
--- test/Analysis/enum.cpp
+++ test/Analysis/enum.cpp
@@ -37,3 +37,33 @@
   }
   return true;
 }
+
+bool testNoCrashOnSwitchEnumBoolConstant() {
+  EnumBool E = EnumBool::F;
+  switch (E) {
+case EnumBool::F:
+  return false; 
+  }
+  return true; 
+}
+
+typedef __INTPTR_TYPE__ intptr_t;
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromNullptr() {
+  EnumBool E = static_cast((intptr_t)nullptr);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
+
+bool testNoCrashOnSwitchEnumBoolConstantCastedFromPtr() {
+  int X;
+  intptr_t P =  
+  EnumBool E = static_cast(P);
+  switch (E) {
+  case EnumBool::F:
+return false;
+  }
+  return true;
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -71,18 +71,15 @@
 }
 
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-
   bool isLocType = Loc::isLocType(castTy);
-
   if (val.getAs())
 return val;
 
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
-
 // FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getTypeSize(castTy);
+unsigned castSize = Context.getIntWidth(castTy);
 if (castSize == LI->getNumBits())
   return val;
 return makeLocAsInteger(LI->getLoc(), castSize);
@@ -173,7 +170,7 @@
   }
 
   if (castTy->isIntegralOrEnumerationType()) {
-unsigned BitWidth = Context.getTypeSize(castTy);
+unsigned BitWidth = Context.getIntWidth(castTy);
 
 if (!val.getAs())
   return makeLocAsInteger(val, BitWidth);
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h

[libcxx] r307357 - cmath: Support clang's -fdelayed-template-parsing

2017-07-06 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Thu Jul  6 22:13:36 2017
New Revision: 307357

URL: http://llvm.org/viewvc/llvm-project?rev=307357=rev
Log:
cmath: Support clang's -fdelayed-template-parsing

r283051 added some functions to cmath (in namespace std) that have the
same name as functions in math.h (in the global namespace).  Clang's
limited support for `-fdelayed-template-parsing` chokes on this.  Rename
the ones in `cmath` and their uses in `complex` and the test.

rdar://problem/32848355

Added:
libcxx/trunk/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp
Modified:
libcxx/trunk/include/cmath
libcxx/trunk/include/complex
libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
libcxx/trunk/utils/libcxx/test/config.py

Modified: libcxx/trunk/include/cmath
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cmath?rev=307357=307356=307357=diff
==
--- libcxx/trunk/include/cmath (original)
+++ libcxx/trunk/include/cmath Thu Jul  6 22:13:36 2017
@@ -549,7 +549,7 @@ hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type
-__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 #if __has_builtin(__builtin_isnan)
 return __builtin_isnan(__lcpp_x);
@@ -561,7 +561,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, 
bool>::type
-__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 return isnan(__lcpp_x);
 }
@@ -569,7 +569,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type
-__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 #if __has_builtin(__builtin_isinf)
 return __builtin_isinf(__lcpp_x);
@@ -581,7 +581,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, 
bool>::type
-__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 return isinf(__lcpp_x);
 }
@@ -589,7 +589,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type
-__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 #if __has_builtin(__builtin_isfinite)
 return __builtin_isfinite(__lcpp_x);
@@ -601,7 +601,7 @@ __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEP
 template 
 _LIBCPP_ALWAYS_INLINE
 _LIBCPP_CONSTEXPR typename enable_if::value, 
bool>::type
-__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
+__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
 {
 return isfinite(__lcpp_x);
 }

Modified: libcxx/trunk/include/complex
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/complex?rev=307357=307356=307357=diff
==
--- libcxx/trunk/include/complex (original)
+++ libcxx/trunk/include/complex Thu Jul  6 22:13:36 2017
@@ -599,39 +599,39 @@ operator*(const complex<_Tp>& __z, const
 _Tp __bc = __b * __c;
 _Tp __x = __ac - __bd;
 _Tp __y = __ad + __bc;
-if (__libcpp_isnan(__x) && __libcpp_isnan(__y))
+if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y))
 {
 bool __recalc = false;
-if (__libcpp_isinf(__a) || __libcpp_isinf(__b))
+if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b))
 {
-__a = copysign(__libcpp_isinf(__a) ? _Tp(1) : _Tp(0), __a);
-__b = copysign(__libcpp_isinf(__b) ? _Tp(1) : _Tp(0), __b);
-if (__libcpp_isnan(__c))
+__a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), 
__a);
+__b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), 
__b);
+if (__libcpp_isnan_or_builtin(__c))
 __c = copysign(_Tp(0), __c);
-if (__libcpp_isnan(__d))
+if (__libcpp_isnan_or_builtin(__d))
 __d = copysign(_Tp(0), __d);
 __recalc = true;
 }
-if (__libcpp_isinf(__c) || __libcpp_isinf(__d))
+if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d))
 {
-__c = copysign(__libcpp_isinf(__c) ? _Tp(1) : _Tp(0), __c);
-__d = copysign(__libcpp_isinf(__d) ? _Tp(1) : _Tp(0), __d);
-if (__libcpp_isnan(__a))
+__c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), 
__c);
+__d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), 
__d);
+if (__libcpp_isnan_or_builtin(__a))
 __a = copysign(_Tp(0), __a);
-if (__libcpp_isnan(__b))

[PATCH] D34578: cmath: Support clang's -fdelayed-template-parsing

2017-07-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith closed this revision.
dexonsmith added a comment.

In https://reviews.llvm.org/D34578#801519, @hfinkel wrote:

> In https://reviews.llvm.org/D34578#801357, @dexonsmith wrote:
>
> > Ping!  Hal, you committed r283051.  Do you have a problem with this?
>
>
> It looks like you're just renaming `__libcpp_isnan` and friends to 
> __libcpp_isnan_or_builtin` and similar. LGTM


Thanks; committed in r307357.

>> (Incidentally, I noticed that r283051 was optimizing the implementation of 
>> . I wonder why we have so much code in that header, instead of 
>> calling out to libc's already-optimized  implementation?)
> 
> This is definitely worth looking at (especially given that we don't support 
> complex of user-defined types with those functions). Would making 
> complex use _Complex double, and so on, be an API break? Would that 
> matter?

I think paragraph 4 of complex.numbers (from n4640) effectively enforces that 
`complex` and `_Complex T` are ABI-compatible.


https://reviews.llvm.org/D34578



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