[PATCH] D37599: Add '\n' in ClangDataCollectorsEmitter

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

LGTM. Do you have commit access?


https://reviews.llvm.org/D37599



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


[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

2017-09-07 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 114303.
vsk edited the summary of this revision.
vsk added a comment.

Address review feedback:

- Enable this change on all platforms.
- Bump the function signature version.
- Store the indirect RTTI pointer as an IntPtrTy. This saves a "ptrtoint" 
instruction. Truncating to Int32Ty should be possible, but causes dyld to 
crash, and also requires an extra sign-extension.


https://reviews.llvm.org/D37597

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenCXX/catch-undef-behavior.cpp

Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -16,6 +16,10 @@
 // Check that type mismatch handler is not modified by ASan.
 // CHECK-ASAN: private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8*, i8 } { {{.*}}, { i16, i16, [4 x i8] }* [[TYPE_DESCR]], {{.*}} }
 
+// CHECK: [[IndirectRTTI_ZTIFvPFviEE:@.+]] = private global i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*)
+// CHECK-X86: [[IndirectRTTI_ZTIFvPFviEE:@.+]] = private global i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*)
+// CHECK-X32: [[IndirectRTTI_ZTIFvPFviEE:@.+]] = private global i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*)
+
 struct T : S {};
 
 // CHECK-LABEL: @_Z17reference_binding
@@ -395,23 +399,29 @@
   // CHECK-NEXT: br i1 [[AND]]
 }
 
-// CHECK-LABEL: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413876459, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
-// CHECK-X32: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413875435, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
-// CHECK-X86: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413875435, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
+//
+// CHECK-LABEL: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i64 }> <{ i32 846596843, i64 sub (i64 ptrtoint (i8** @{{.*}} to i64), i64 ptrtoint (void (void (i32)*)* @_Z22indirect_function_callPFviE to i64)) }>
+// CHECK-X32: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i32 }> <{ i32 846595819, i32 sub (i32 ptrtoint (i8** [[IndirectRTTI_ZTIFvPFviEE]] to i32), i32 ptrtoint (void (void (i32)*)* @_Z22indirect_function_callPFviE to i32)) }>
+// CHECK-X86: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i32 }> <{ i32 846595819, i32 sub (i32 ptrtoint (i8** [[IndirectRTTI_ZTIFvPFviEE]] to i32), i32 ptrtoint (void (void (i32)*)* @_Z22indirect_function_callPFviE to i32)) }>
 void indirect_function_call(void (*p)(int)) {
-  // CHECK: [[PTR:%.+]] = bitcast void (i32)* {{.*}} to <{ i32, i8* }>*
+  // CHECK: [[PTR:%.+]] = bitcast void (i32)* {{.*}} to <{ i32, i64 }>*
 
   // Signature check
-  // CHECK-NEXT: [[SIGPTR:%.+]] = getelementptr <{ i32, i8* }>, <{ i32, i8* }>* [[PTR]], i32 0, i32 0
+  // CHECK-NEXT: [[SIGPTR:%.+]] = getelementptr <{ i32, i64 }>, <{ i32, i64 }>* [[PTR]], i32 0, i32 0
   // CHECK-NEXT: [[SIG:%.+]] = load i32, i32* [[SIGPTR]]
-  // CHECK-NEXT: [[SIGCMP:%.+]] = icmp eq i32 [[SIG]], 1413876459
+  // CHECK-NEXT: [[SIGCMP:%.+]] = icmp eq i32 [[SIG]], 846596843
   // CHECK-NEXT: br i1 [[SIGCMP]]
 
   // RTTI pointer check
-  // CHECK: [[RTTIPTR:%.+]] = getelementptr <{ i32, i8* }>, <{ i32, i8* }>* [[PTR]], i32 0, i32 1
-  // CHECK-NEXT: [[RTTI:%.+]] = load i8*, i8** [[RTTIPTR]]
+  // CHECK: [[RTTIPTR:%.+]] = getelementptr <{ i32, i64 }>, <{ i32, i64 }>* [[PTR]], i32 0, i32 1
+  // CHECK-NEXT: [[RTTIEncInt:%.+]] = load i64, i64* [[RTTIPTR]]
+  // CHECK-NEXT: [[FuncAddrInt:%.+]] = ptrtoint void (i32)* {{.*}} to i64
+  // CHECK-NEXT: [[IndirectGVInt:%.+]] = add i64 [[RTTIEncInt]], [[FuncAddrInt]]
+  // CHECK-NEXT: [[IndirectGV:%.+]] = inttoptr i64 [[IndirectGVInt]] to i8**
+  // CHECK-NEXT: [[RTTI:%.+]] = load i8*, i8** [[IndirectGV]], align 8
   // CHECK-NEXT: [[RTTICMP:%.+]] = icmp eq i8* [[RTTI]], bitcast ({ i8*, i8* }* @_ZTIFviE to i8*)
   // CHECK-NEXT: br i1 [[RTTICMP]]
+
   p(42);
 }
 
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1073,8 +1073,8 @@
   getUBSanFunctionSignature(CodeGen::CodeGenModule ) const override {
 unsigned Sig = (0xeb << 0) |  // jmp rel8
(0x06 << 8) |  //   .+0x08
-   ('F' << 16) |
-   ('T' << 24);
+   ('v' << 16) |
+   ('2' << 24);
 return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
   }
 
@@ -2263,13 +2263,13 @@
 if (getABIInfo().has64BitPointers())
   Sig = (0xeb << 0) |  // jmp rel8
 (0x0a << 8) |  //   .+0x0c
-('F' << 16) |
-('T' << 24);
+('v' << 16) |
+('2' << 24);
 else
   Sig = (0xeb 

[PATCH] D37310: [Atomic] Merge alignment information from Decl and from Type when emit atomic expression.

2017-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D37310



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


[PATCH] D37310: [Atomic] Merge alignment information from Decl and from Type when emit atomic expression.

2017-09-07 Thread Wei Mi via Phabricator via cfe-commits
wmi updated this revision to Diff 114300.
wmi added a comment.

Address John's comment.


Repository:
  rL LLVM

https://reviews.llvm.org/D37310

Files:
  lib/CodeGen/CGAtomic.cpp
  test/CodeGenCXX/atomic-align.cpp


Index: test/CodeGenCXX/atomic-align.cpp
===
--- test/CodeGenCXX/atomic-align.cpp
+++ test/CodeGenCXX/atomic-align.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load2v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
Index: lib/CodeGen/CGAtomic.cpp
===
--- lib/CodeGen/CGAtomic.cpp
+++ lib/CodeGen/CGAtomic.cpp
@@ -745,19 +745,19 @@
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = (sizeChars != Ptr.getAlignment() ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {


Index: test/CodeGenCXX/atomic-align.cpp
===
--- test/CodeGenCXX/atomic-align.cpp
+++ test/CodeGenCXX/atomic-align.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load2v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
Index: lib/CodeGen/CGAtomic.cpp
===
--- lib/CodeGen/CGAtomic.cpp
+++ lib/CodeGen/CGAtomic.cpp
@@ -745,19 +745,19 @@
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = (sizeChars != Ptr.getAlignment() ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37529: [codeview] omit debug locations for nested exprs unless column info enabled

2017-09-07 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

@inglorion : Since we're already in this code anyway, should we at least do due 
diligence and check the basics, even if only manually?  As in, at least we 
should check in MSVC if any of those other types of examples that I came up 
with present a problem.  Otherwise we're going to be back here fixing this 
again in a few weeks.  And it doesn't seem like it would be that hard to whip 
up some sample code with 10 or 12 cases and just do a sanity check that they 
all work.  If they don't, we can then decide whether it should be fixed in this 
patch, or a bug can be filed to track it.


https://reviews.llvm.org/D37529



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


[PATCH] D37529: [codeview] omit debug locations for nested exprs unless column info enabled

2017-09-07 Thread Bob Haarman via Phabricator via cfe-commits
inglorion updated this revision to Diff 114299.
inglorion added a comment.

removed compound statement; that was only in there to double check that the 
debugger stops on the first child statement, but that's true with or without 
this change


https://reviews.llvm.org/D37529

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenCXX/debug-info-nested-exprs.cpp

Index: clang/test/CodeGenCXX/debug-info-nested-exprs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-nested-exprs.cpp
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited \
+// RUN:-gcodeview -emit-llvm -o - %s | FileCheck -check-prefix=NONEST %s
+// RUN: %clang_cc1 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited \
+// RUN:-gcodeview -dwarf-column-info -emit-llvm -o - %s \
+// RUN:| FileCheck -check-prefix=COLUMNS %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -debug-info-kind=limited \
+// RUN:-emit-llvm -o - %s | FileCheck -check-prefix=NESTED %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -debug-info-kind=limited \
+// RUN:-dwarf-column-info -emit-llvm -o - %s \
+// RUN:| FileCheck -check-prefix=COLUMNS %s
+
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[LOC:[0-9]+]]
+// NONEST: call i32 @{{.*}}baz{{.*}}, !dbg ![[LOC]]
+// NONEST: call i32 @{{.*}}qux{{.*}}, !dbg ![[LOC]]
+// NONEST: store i32 {{.*}}, !dbg ![[LOC]]
+// NONEST: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// NONEST: store i32 0, i32* %b,{{.*}} !dbg ![[ILOC]]
+// NONEST: store i32 0, i32* %c,{{.*}} !dbg ![[ILOC]]
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// NONEST: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// NONEST: mul nsw i32 {{.*}}, !dbg ![[RETLOC:[0-9]+]]
+// NONEST: sub nsw i32 {{.*}}, !dbg ![[RETLOC]]
+// NONEST: ret i32 {{.*}}, !dbg ![[RETLOC]]
+// NONEST: ![[WHILE1]] = !DILocation(
+// NONEST: ![[WHILE2]] = !DILocation(
+// NONEST: ![[FOR1]] = !DILocation(
+// NONEST: ![[FOR2]] = !DILocation(
+// NONEST: ![[IF1]] = !DILocation(
+// NONEST: ![[IF2]] = !DILocation(
+// NONEST: ![[IF3]] = !DILocation(
+
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[BAR:[0-9]+]]
+// NESTED: call i32 @{{.*}}baz{{.*}}, !dbg ![[BAZ:[0-9]+]]
+// NESTED: call i32 @{{.*}}qux{{.*}}, !dbg ![[QUX:[0-9]+]]
+// NESTED: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// NESTED: store i32 0, i32* %b,{{.*}} !dbg ![[ILOC]]
+// NESTED: store i32 0, i32* %c,{{.*}} !dbg ![[ILOC]]
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// NESTED: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// NESTED: mul nsw i32 {{.*}}, !dbg ![[RETMUL:[0-9]+]]
+// NESTED: sub nsw i32 {{.*}}, !dbg ![[RETSUB:[0-9]+]]
+// NESTED: ret i32 {{.*}}, !dbg !
+// NESTED: ![[BAR]] = !DILocation(
+// NESTED: ![[BAZ]] = !DILocation(
+// NESTED: ![[QUX]] = !DILocation(
+// NESTED: ![[RETSUB]] = !DILocation(
+// NESTED: ![[RETMUL]] = !DILocation(
+
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[BAR:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}baz{{.*}}, !dbg ![[BAZ:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}qux{{.*}}, !dbg ![[QUX:[0-9]+]]
+// COLUMNS: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// COLUMNS: store i32 0, i32* %b,{{.*}} !dbg ![[BLOC:[0-9]+]]
+// COLUMNS: store i32 0, i32* %c,{{.*}} !dbg ![[CLOC:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// COLUMNS: mul nsw i32 {{.*}}, !dbg ![[RETMUL:[0-9]+]]
+// COLUMNS: sub nsw i32 {{.*}}, !dbg ![[RETSUB:[0-9]+]]
+// COLUMNS: ret i32 {{.*}}, !dbg !
+// COLUMNS: ![[BAR]] = !DILocation(
+// COLUMNS: ![[BAZ]] = !DILocation(
+// COLUMNS: ![[QUX]] = !DILocation(
+// COLUMNS: ![[ILOC]] = !DILocation(
+// COLUMNS: ![[BLOC]] = !DILocation(
+// COLUMNS: ![[CLOC]] = !DILocation(
+// COLUNMS: ![[RETSUB]] = !DILocation(
+// COLUMNS: 

[PATCH] D37529: [codeview] omit debug locations for nested exprs unless column info enabled

2017-09-07 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added a comment.

@zturner: I am still thinking about your comment about other cases to test. My 
concern is that there are very many possible combinations.

I'm actually not too concerned about not exactly matching cl's behavior in 
every single case. The difference in behavior here is us emitting a debug 
location for an expression that doesn't get its own debug location from cl. In 
general, I think having more fine-grained information is good, so I don't think 
differing in this way is a problem. That is, unless we end up breaking 
functionality in the debugger (Visual Studio). The behavior I know of we can 
end up breaking this way is step into specific, which appears to require 
multiple calls that are associated with a single debug location.

I think, at a minimum, the test case should cover a scenario where we would 
normally like to emit some debug locations, but need to elide them if we want 
to be compatible with Visual Studio. I also think it makes sense to include 
some cases where we want the behavior to be the same whether or not we're 
targeting MS compatibility. That way, we can verify that we aren't throwing 
away too much information. Beyond that, I feel there are diminishing returns. 
To avoid going too far down that path, I would like to start with a relatively 
small test case (as I've done), fix the bug that prompted me to write this 
code, and then add additional tests if we find out there are other cases where 
people care strongly about the granularity of the debug locations we emit. Does 
that sound reasonable?


https://reviews.llvm.org/D37529



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


r312770 - COFF: Implement ThinLTO cache and cache pruning support.

2017-09-07 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Thu Sep  7 17:50:50 2017
New Revision: 312770

URL: http://llvm.org/viewvc/llvm-project?rev=312770=rev
Log:
COFF: Implement ThinLTO cache and cache pruning support.

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

Modified:
cfe/trunk/docs/ThinLTO.rst

Modified: cfe/trunk/docs/ThinLTO.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThinLTO.rst?rev=312770=312769=312770=diff
==
--- cfe/trunk/docs/ThinLTO.rst (original)
+++ cfe/trunk/docs/ThinLTO.rst Thu Sep  7 17:50:50 2017
@@ -119,23 +119,27 @@ Incremental
 ThinLTO supports fast incremental builds through the use of a cache,
 which currently must be enabled through a linker option.
 
-- gold (as of LLVM r279883):
+- gold (as of LLVM 4.0):
   ``-Wl,-plugin-opt,cache-dir=/path/to/cache``
 - ld64 (support in clang 3.9 and Xcode 8):
   ``-Wl,-cache_path_lto,/path/to/cache``
-- lld (as of LLVM r296702):
+- ELF lld (as of LLVM 5.0):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
+- COFF lld (as of LLVM 6.0):
+  ``/lldltocache:/path/to/cache``
 
 Cache Pruning
 -
 
 To help keep the size of the cache under control, ThinLTO supports cache
-pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
-ELF lld allows you to control the policy with a policy string.  The cache
-policy must be specified with a linker option.
+pruning. Cache pruning is supported with ld64 and ELF and COFF lld, but
+currently only ELF and COFF lld allow you to control the policy with a
+policy string. The cache policy must be specified with a linker option.
 
-- ELF lld (as of LLVM r298036):
+- ELF lld (as of LLVM 5.0):
   ``-Wl,--thinlto-cache-policy,POLICY``
+- COFF lld (as of LLVM 6.0):
+  ``/lldltocachepolicy:POLICY``
 
 A policy string is a series of key-value pairs separated by ``:`` characters.
 Possible key-value pairs are:


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


[clang-tools-extra] r312769 - Update for PrintHelpMessage not calling exit.

2017-09-07 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Sep  7 17:33:39 2017
New Revision: 312769

URL: http://llvm.org/viewvc/llvm-project?rev=312769=rev
Log:
Update for PrintHelpMessage not calling exit.

Modified:
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/modularize/Modularize.cpp

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=312769=312768=312769=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Thu Sep  7 
17:33:39 2017
@@ -392,13 +392,13 @@ static int clangTidyMain(int argc, const
   if (EnabledChecks.empty()) {
 llvm::errs() << "Error: no checks enabled.\n";
 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
-return 1;
+return 0;
   }
 
   if (PathList.empty()) {
 llvm::errs() << "Error: no input files specified.\n";
 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
-return 1;
+return 0;
   }
 
   ProfileData Profile;

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=312769=312768=312769=diff
==
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Thu Sep  7 17:33:39 2017
@@ -825,7 +825,7 @@ int main(int Argc, const char **Argv) {
   // No go if we have no header list file.
   if (ListFileNames.size() == 0) {
 cl::PrintHelpMessage();
-return 1;
+return 0;
   }
 
   std::unique_ptr ModUtil;


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


[PATCH] D37529: [codeview] omit debug locations for nested exprs unless column info enabled

2017-09-07 Thread Bob Haarman via Phabricator via cfe-commits
inglorion updated this revision to Diff 114292.
inglorion added a comment.

Following conversation with @rnk, I managed to whittle this down to a very 
small change that seems to do what we need. Step into specific works and single 
stepping through the program behaves similarly whether compiled with clang-cl 
or cl.


https://reviews.llvm.org/D37529

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenCXX/debug-info-nested-exprs.cpp

Index: clang/test/CodeGenCXX/debug-info-nested-exprs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-nested-exprs.cpp
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited \
+// RUN:-gcodeview -emit-llvm -o - %s | FileCheck -check-prefix=NONEST %s
+// RUN: %clang_cc1 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited \
+// RUN:-gcodeview -dwarf-column-info -emit-llvm -o - %s \
+// RUN:| FileCheck -check-prefix=COLUMNS %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -debug-info-kind=limited \
+// RUN:-emit-llvm -o - %s | FileCheck -check-prefix=NESTED %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -debug-info-kind=limited \
+// RUN:-dwarf-column-info -emit-llvm -o - %s \
+// RUN:| FileCheck -check-prefix=COLUMNS %s
+
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[LOC:[0-9]+]]
+// NONEST: call i32 @{{.*}}baz{{.*}}, !dbg ![[LOC]]
+// NONEST: call i32 @{{.*}}qux{{.*}}, !dbg ![[LOC]]
+// NONEST: store i32 {{.*}}, !dbg ![[LOC]]
+// NONEST: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// NONEST: store i32 0, i32* %b,{{.*}} !dbg ![[ILOC]]
+// NONEST: store i32 0, i32* %c,{{.*}} !dbg ![[ILOC]]
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// NONEST: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// NONEST: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// NONEST: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// NONEST: mul nsw i32 {{.*}}, !dbg ![[RETLOC:[0-9]+]]
+// NONEST: sub nsw i32 {{.*}}, !dbg ![[RETLOC]]
+// NONEST: ret i32 {{.*}}, !dbg ![[RETLOC]]
+// NONEST: ![[WHILE1]] = !DILocation(
+// NONEST: ![[WHILE2]] = !DILocation(
+// NONEST: ![[FOR1]] = !DILocation(
+// NONEST: ![[FOR2]] = !DILocation(
+// NONEST: ![[IF1]] = !DILocation(
+// NONEST: ![[IF2]] = !DILocation(
+// NONEST: ![[IF3]] = !DILocation(
+
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[BAR:[0-9]+]]
+// NESTED: call i32 @{{.*}}baz{{.*}}, !dbg ![[BAZ:[0-9]+]]
+// NESTED: call i32 @{{.*}}qux{{.*}}, !dbg ![[QUX:[0-9]+]]
+// NESTED: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// NESTED: store i32 0, i32* %b,{{.*}} !dbg ![[ILOC]]
+// NESTED: store i32 0, i32* %c,{{.*}} !dbg ![[ILOC]]
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// NESTED: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// NESTED: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// NESTED: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// NESTED: mul nsw i32 {{.*}}, !dbg ![[RETMUL:[0-9]+]]
+// NESTED: sub nsw i32 {{.*}}, !dbg ![[RETSUB:[0-9]+]]
+// NESTED: ret i32 {{.*}}, !dbg !
+// NESTED: ![[BAR]] = !DILocation(
+// NESTED: ![[BAZ]] = !DILocation(
+// NESTED: ![[QUX]] = !DILocation(
+// NESTED: ![[RETSUB]] = !DILocation(
+// NESTED: ![[RETMUL]] = !DILocation(
+
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[BAR:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}baz{{.*}}, !dbg ![[BAZ:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}qux{{.*}}, !dbg ![[QUX:[0-9]+]]
+// COLUMNS: store i32 1, i32* %i,{{.*}} !dbg ![[ILOC:[0-9]+]]
+// COLUMNS: store i32 0, i32* %b,{{.*}} !dbg ![[BLOC:[0-9]+]]
+// COLUMNS: store i32 0, i32* %c,{{.*}} !dbg ![[CLOC:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[WHILE1:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %i,{{.*}} !dbg ![[WHILE2:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}bar{{.*}}, !dbg ![[FOR1:[0-9]+]]
+// COLUMNS: call i32 @{{.*}}qux{{.*}}, !dbg ![[FOR2:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %t,{{.*}} !dbg ![[IF1:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %a,{{.*}} !dbg ![[IF2:[0-9]+]]
+// COLUMNS: store i32 %{{[^,]+}}, i32* %b,{{.*}} !dbg ![[IF3:[0-9]+]]
+// COLUMNS: mul nsw i32 {{.*}}, !dbg ![[RETMUL:[0-9]+]]
+// COLUMNS: sub nsw i32 {{.*}}, !dbg ![[RETSUB:[0-9]+]]
+// COLUMNS: ret i32 {{.*}}, !dbg !
+// COLUMNS: ![[BAR]] = !DILocation(
+// COLUMNS: ![[BAZ]] = !DILocation(
+// COLUMNS: ![[QUX]] = !DILocation(
+// COLUMNS: ![[ILOC]] = !DILocation(
+// COLUMNS: ![[BLOC]] = !DILocation(
+// COLUMNS: ![[CLOC]] = 

[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

2017-09-07 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for your comments!




Comment at: lib/CodeGen/CodeGenFunction.cpp:434
+llvm::Constant *Addr) {
+  if (!CGM.getTriple().isOSDarwin())
+return Addr;

pcc wrote:
> I think you can just do this unconditionally. As far as I know, all three 
> object formats should support 32-bit relative relocations on x86 and x86_64, 
> which are the only two architectures which currently support 
> `-fsanitize=function`.
Ok! I'll make this change in the next version of this patch (probably tomorrow).



Comment at: lib/CodeGen/CodeGenFunction.cpp:445
+  auto *GV = new llvm::GlobalVariable(CGM.getModule(), Addr->getType(),
+  /*isConstant=*/false,
+  llvm::GlobalValue::PrivateLinkage, Addr);

pcc wrote:
> This can be constant I think.
Can the value of the global change if a dynamic library is unloaded? I'm unsure 
about this case: A.dylib and B.dylib both have linkonce_odr definitions of X, 
dyld picks the definition from A, and A is unloaded.



Comment at: lib/CodeGen/CodeGenFunction.cpp:463
+  auto *PCRelAsInt =
+  Builder.CreatePtrToInt(EncodedAddr, IntPtrTy, "encoded_addr.int");
+  auto *FuncAsInt = Builder.CreatePtrToInt(F, IntPtrTy, "func_addr.int");

pcc wrote:
> pcc wrote:
> > Maybe use `Int32Ty` (here and below). That should be sufficient under the 
> > small code model.
> Sorry, I meant that the difference could be truncated to `Int32Ty`, and 
> stored as an integer, not a pointer.
I tried this out but it resulted in a mysterious dyld crash after the indirect 
callee returns, which I've yet to understand. I'll have to try using a Debug 
build of dyld to see what's happening.


https://reviews.llvm.org/D37597



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


r312766 - Update for llvm change.

2017-09-07 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Thu Sep  7 17:01:26 2017
New Revision: 312766

URL: http://llvm.org/viewvc/llvm-project?rev=312766=rev
Log:
Update for llvm change.

Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp
cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=312766=312765=312766=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Thu Sep  7 17:01:26 2017
@@ -351,8 +351,10 @@ int main(int argc, const char **argv) {
   "together with s, the files are edited in-place. Otherwise, the\n"
   "result is written to the standard output.\n");
 
-  if (Help)
+  if (Help) {
 cl::PrintHelpMessage();
+return 0;
+  }
 
   if (DumpConfig) {
 llvm::Expected FormatStyle =

Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp?rev=312766=312765=312766=diff
==
--- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp (original)
+++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Thu Sep  7 
17:01:26 2017
@@ -931,8 +931,10 @@ int main(int argc, const char **argv) {
   "one. The resulting file can also be unbundled into different files by 
\n"
   "this tool if -unbundle is provided.\n");
 
-  if (Help)
+  if (Help) {
 cl::PrintHelpMessage();
+return 0;
+  }
 
   bool Error = false;
   if (Unbundle) {


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


[PATCH] D37604: Disable debuginfo-tests for non-native configurations

2017-09-07 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

This seems reasonable to me, thanks!
When you commit this, could you please double-check that the tests are still 
running on the green dragon builders? I'll also keep an eye on them.


https://reviews.llvm.org/D37604



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


[PATCH] D37604: Disable debuginfo-tests for non-native configurations

2017-09-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

The new file goes in the debuginfo-tests directory.  It's a separate project so 
that's probably not obvious from the diff.


https://reviews.llvm.org/D37604



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


[PATCH] D37604: Disable debuginfo-tests for non-native configurations

2017-09-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.

This requires the host triple to match the default target triple, in order to 
run debuginfo-tests.
It's possible this is too restrictive, but offhand it seems like a reasonable 
starting point.


https://reviews.llvm.org/D37604

Files:
  lit.local.cfg


Index: lit.local.cfg
===
--- lit.local.cfg
+++ lit.local.cfg
@@ -0,0 +1,3 @@
+# debuginfo-tests are not expected to pass in a cross-compilation setup.
+if 'native' not in config.available_features:
+config.unsupported = True


Index: lit.local.cfg
===
--- lit.local.cfg
+++ lit.local.cfg
@@ -0,0 +1,3 @@
+# debuginfo-tests are not expected to pass in a cross-compilation setup.
+if 'native' not in config.available_features:
+config.unsupported = True
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

2017-09-07 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:463
+  auto *PCRelAsInt =
+  Builder.CreatePtrToInt(EncodedAddr, IntPtrTy, "encoded_addr.int");
+  auto *FuncAsInt = Builder.CreatePtrToInt(F, IntPtrTy, "func_addr.int");

pcc wrote:
> Maybe use `Int32Ty` (here and below). That should be sufficient under the 
> small code model.
Sorry, I meant that the difference could be truncated to `Int32Ty`, and stored 
as an integer, not a pointer.


https://reviews.llvm.org/D37597



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


[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

2017-09-07 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Thanks. Once we apply this fix to other platforms this would seem to fix 
PR17633.

We may also want to change the ubsan function signature in order to avoid bad 
pointer reads in case of version mismatches.




Comment at: lib/CodeGen/CodeGenFunction.cpp:434
+llvm::Constant *Addr) {
+  if (!CGM.getTriple().isOSDarwin())
+return Addr;

I think you can just do this unconditionally. As far as I know, all three 
object formats should support 32-bit relative relocations on x86 and x86_64, 
which are the only two architectures which currently support 
`-fsanitize=function`.



Comment at: lib/CodeGen/CodeGenFunction.cpp:445
+  auto *GV = new llvm::GlobalVariable(CGM.getModule(), Addr->getType(),
+  /*isConstant=*/false,
+  llvm::GlobalValue::PrivateLinkage, Addr);

This can be constant I think.



Comment at: lib/CodeGen/CodeGenFunction.cpp:463
+  auto *PCRelAsInt =
+  Builder.CreatePtrToInt(EncodedAddr, IntPtrTy, "encoded_addr.int");
+  auto *FuncAsInt = Builder.CreatePtrToInt(F, IntPtrTy, "func_addr.int");

Maybe use `Int32Ty` (here and below). That should be sufficient under the small 
code model.


https://reviews.llvm.org/D37597



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


[PATCH] D37599: Add '\n' in ClangDataCollectorsEmitter

2017-09-07 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl created this revision.
Herald added subscribers: ilya-biryukov, wdng.

Otherwise it breaks our internal windows builders:

  StmtDataCollectors.inc: error C2220: warning treated as error - no 'object' 
file generated
  StmtDataCollectors.inc: warning C4335: Mac file format detected: please 
convert the source file to either DOS or UNIX format


https://reviews.llvm.org/D37599

Files:
  utils/TableGen/ClangDataCollectorsEmitter.cpp


Index: utils/TableGen/ClangDataCollectorsEmitter.cpp
===
--- utils/TableGen/ClangDataCollectorsEmitter.cpp
+++ utils/TableGen/ClangDataCollectorsEmitter.cpp
@@ -8,7 +8,7 @@
   const auto  = RK.getClasses();
   for (const auto  : Defs) {
 Record  = *Entry.second;
-OS << "DEF_ADD_DATA(" << R.getName() << ", {";
+OS << "DEF_ADD_DATA(" << R.getName() << ", {\n";
 auto Code = R.getValue("Code")->getValue();
 OS << Code->getAsUnquotedString() << "}\n)";
 OS << "\n";


Index: utils/TableGen/ClangDataCollectorsEmitter.cpp
===
--- utils/TableGen/ClangDataCollectorsEmitter.cpp
+++ utils/TableGen/ClangDataCollectorsEmitter.cpp
@@ -8,7 +8,7 @@
   const auto  = RK.getClasses();
   for (const auto  : Defs) {
 Record  = *Entry.second;
-OS << "DEF_ADD_DATA(" << R.getName() << ", {";
+OS << "DEF_ADD_DATA(" << R.getName() << ", {\n";
 auto Code = R.getValue("Code")->getValue();
 OS << Code->getAsUnquotedString() << "}\n)";
 OS << "\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37598: [ubsan] Enable -fsanitize=function on Darwin

2017-09-07 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

Depends on https://reviews.llvm.org/D37597


https://reviews.llvm.org/D37598

Files:
  docs/UndefinedBehaviorSanitizer.rst
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -11,7 +11,7 @@
 // CHECK-UNDEFINED: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
+// CHECK-UNDEFINED-DARWIN: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
 
 // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
 // CHECK-UNDEFINED-OPENBSD: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
@@ -354,10 +354,8 @@
 // CHECK-TSAN-ATOMICS-BOTH-OFF: -cc1{{.*}}tsan-instrument-atomics=0
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=function %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-FSAN-DARWIN
-// CHECK-FSAN-DARWIN: unsupported option '-fsanitize=function' for target 
'x86_64-apple-darwin10'
-
-// RUN: %clang -target x86_64-apple-darwin10 -fsanitize=function 
-fsanitize=undefined %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-FSAN-UBSAN-DARWIN
-// CHECK-FSAN-UBSAN-DARWIN: unsupported option '-fsanitize=function' for 
target 'x86_64-apple-darwin10'
+// RUN: %clang -target i386-apple-darwin10 -fsanitize=function %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-FSAN-DARWIN
+// CHECK-FSAN-DARWIN: -cc1{{.*}}"-fsanitize=function" 
"-fsanitize-recover=function"
 
 // RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.8 
-fsanitize=vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-DARWIN-OLD
 // CHECK-VPTR-DARWIN-OLD: unsupported option '-fsanitize=vptr' for target 
'x86_64-apple-darwin10'
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -2018,6 +2018,7 @@
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Leak;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::Function;
   if (isTargetMacOS()) {
 if (!isMacosxVersionLT(10, 9))
   Res |= SanitizerKind::Vptr;
Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -87,7 +87,8 @@
   -  ``-fsanitize=float-divide-by-zero``: Floating point division by
  zero.
   -  ``-fsanitize=function``: Indirect call of a function through a
- function pointer of the wrong type (Linux, C++ and x86/x86_64 only).
+ function pointer of the wrong type (Darwin/Linux, C++ and x86/x86_64
+ only).
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -11,7 +11,7 @@
 // CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: 

[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

2017-09-07 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

This change will make it possible to use -fsanitize=function on Darwin and
possibly on other platforms. It fixes an issue with the way RTTI is stored into
function prologue data.

On Darwin, addresses stored in prologue data can't require run-time fixups and
must be PC-relative. Run-time fixups are undesirable because they necessitate
writable text segments, which can lead to security issues. And absolute
addresses are undesirable because they break PIE mode.

The fix is to create a private global which points to the RTTI, and then to
encode a PC-relative reference to the global into prologue data. For now, the
behavior change is only enabled for Darwin.


https://reviews.llvm.org/D37597

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/catch-undef-behavior.cpp

Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -fsanitize-recover=vptr -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=DOWNCAST-NULL
 // RUN: %clang_cc1 -std=c++11 -fsanitize=function -emit-llvm %s -o - -triple x86_64-linux-gnux32 | FileCheck %s --check-prefix=CHECK-X32
 // RUN: %clang_cc1 -std=c++11 -fsanitize=function -emit-llvm %s -o - -triple i386-linux-gnu | FileCheck %s --check-prefix=CHECK-X86
+// RUN: %clang_cc1 -std=c++11 -fsanitize=function -emit-llvm %s -o - -triple x86_64-apple-darwin | FileCheck %s --check-prefix=FSAN-DARWIN
 
 struct S {
   double d;
@@ -16,6 +17,8 @@
 // Check that type mismatch handler is not modified by ASan.
 // CHECK-ASAN: private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8*, i8 } { {{.*}}, { i16, i16, [4 x i8] }* [[TYPE_DESCR]], {{.*}} }
 
+// FSAN-DARWIN: [[IndirectRTTI_ZTIFvPFviEE:@.+]] = private global i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*)
+
 struct T : S {};
 
 // CHECK-LABEL: @_Z17reference_binding
@@ -395,6 +398,8 @@
   // CHECK-NEXT: br i1 [[AND]]
 }
 
+//
+// FSAN-DARWIN: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8** }> <{ i32 1413876459, i8** inttoptr (i64 sub (i64 ptrtoint (i8** [[IndirectRTTI_ZTIFvPFviEE]] to i64), i64 ptrtoint (void (void (i32)*)* @_Z22indirect_function_callPFviE to i64)) to i8**) }> 
 // CHECK-LABEL: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413876459, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
 // CHECK-X32: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413875435, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
 // CHECK-X86: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413875435, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
@@ -412,6 +417,26 @@
   // CHECK-NEXT: [[RTTI:%.+]] = load i8*, i8** [[RTTIPTR]]
   // CHECK-NEXT: [[RTTICMP:%.+]] = icmp eq i8* [[RTTI]], bitcast ({ i8*, i8* }* @_ZTIFviE to i8*)
   // CHECK-NEXT: br i1 [[RTTICMP]]
+
+  // FSAN-DARWIN: [[PTR:%.+]] = bitcast void (i32)* {{.*}} to <{ i32, i8** }>*
+
+  // Signature check
+  // FSAN-DARWIN-NEXT: [[SIGPTR:%.+]] = getelementptr <{ i32, i8** }>, <{ i32, i8** }>* [[PTR]], i32 0, i32 0
+  // FSAN-DARWIN-NEXT: [[SIG:%.+]] = load i32, i32* [[SIGPTR]]
+  // FSAN-DARWIN-NEXT: [[SIGCMP:%.+]] = icmp eq i32 [[SIG]], 1413876459
+  // FSAN-DARWIN-NEXT: br i1 [[SIGCMP]]
+
+  // RTTI pointer check
+  // FSAN-DARWIN: [[RTTIPTR:%.+]] = getelementptr <{ i32, i8** }>, <{ i32, i8** }>* [[PTR]], i32 0, i32 1
+  // FSAN-DARWIN-NEXT: [[RTTIEnc:%.+]] = load i8**, i8*** [[RTTIPTR]]
+  // FSAN-DARWIN-NEXT: [[RTTIEncInt:%.+]] = ptrtoint i8** [[RTTIEnc]] to i64
+  // FSAN-DARWIN-NEXT: [[FuncAddrInt:%.+]] = ptrtoint void (i32)* {{.*}} to i64
+  // FSAN-DARWIN-NEXT: [[IndirectGVInt:%.+]] = add i64 [[RTTIEncInt]], [[FuncAddrInt]]
+  // FSAN-DARWIN-NEXT: [[IndirectGV:%.+]] = inttoptr i64 [[IndirectGVInt]] to i8**
+  // FSAN-DARWIN-NEXT: [[RTTI:%.+]] = load i8*, i8** [[IndirectGV]], align 8
+  // FSAN-DARWIN-NEXT: [[RTTICMP:%.+]] = icmp eq i8* [[RTTI]], bitcast ({ i8*, i8* }* @_ZTIFviE to i8*)
+  // FSAN-DARWIN-NEXT: br i1 [[RTTICMP]]
+
   p(42);
 }
 
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1775,6 +1775,15 @@
   /// EmitMCountInstrumentation - Emit call to .mcount.
   void EmitMCountInstrumentation();
 
+  /// Encode an address into a form suitable for use in a function prologue.
+  llvm::Constant *EncodeAddrForUseInPrologue(llvm::Function *F,
+ llvm::Constant *Addr);
+
+  /// Decode an address used in a function prologue, encoded by \c
+  /// EncodeAddrForUseInPrologue.
+  llvm::Value *DecodeAddrUsedInPrologue(llvm::Value *F,
+

Re: r312696 - [modules ts] Add test for [basic.link]p3.

2017-09-07 Thread Richard Smith via cfe-commits
On 7 September 2017 at 13:36, Galina Kistanova via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hello Richard,
>
> This commit broke one of our builders:
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensiv
> e-checks-win/builds/4705
>
> Failing Tests (1):
> Clang :: CXX/modules-ts/basic/basic.link/p3.cppm
>
> Please have a look?
>

Should be fixed by r312749. FYI, I did not receive any email about this
failure :(


> Thanks
>
> Galina
>
> On Wed, Sep 6, 2017 at 10:29 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Wed Sep  6 22:29:39 2017
>> New Revision: 312696
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=312696=rev
>> Log:
>> [modules ts] Add test for [basic.link]p3.
>>
>> Added:
>> cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm
>>
>> Added: cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modul
>> es-ts/basic/basic.link/p3.cppm?rev=312696=auto
>> 
>> ==
>> --- cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm (added)
>> +++ cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm Wed Sep  6
>> 22:29:39 2017
>> @@ -0,0 +1,11 @@
>> +// RUN: %clang_cc1 -fmodules-ts %s -emit-module-interface -o %t
>> +// RUN: %clang_cc1 -fmodules-ts -x pcm %t -emit-llvm -o - | FileCheck %s
>> +
>> +export module M;
>> +
>> +// CHECK-DAG: @_ZW1ME1a = constant i32 1
>> +const int a = 1;
>> +// CHECK-DAG: @b = constant i32 2
>> +export const int b = 2;
>> +
>> +export int f() { return a + b; }
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312750: [Sema] -Wtautological-compare: handle comparison of 
unsigned with 0S. (authored by lebedevri).

Changed prior to commit:
  https://reviews.llvm.org/D37565?vs=114260=114265#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  cfe/trunk/docs/ReleaseNotes.rst
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/compare.c
  cfe/trunk/test/Sema/outof-range-constant-compare.c
  cfe/trunk/test/SemaCXX/compare.cpp

Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -8567,32 +8567,51 @@
   return E->getType()->isEnumeralType();
 }
 
-void CheckTrivialUnsignedComparison(Sema , BinaryOperator *E) {
+bool isNonBooleanUnsignedValue(Expr *E) {
+  // We are checking that the expression is not known to have boolean value,
+  // is an integer type; and is either unsigned after implicit casts,
+  // or was unsigned before implicit casts.
+  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType() &&
+ (!E->getType()->isSignedIntegerType() ||
+  !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
+}
+
+bool CheckTautologicalComparisonWithZero(Sema , BinaryOperator *E) {
   // Disable warning in template instantiations.
   if (S.inTemplateInstantiation())
-return;
+return false;
+
+  // bool values are handled by DiagnoseOutOfRangeComparison().
 
   BinaryOperatorKind op = E->getOpcode();
   if (E->isValueDependent())
-return;
+return false;
+
+  Expr *LHS = E->getLHS();
+  Expr *RHS = E->getRHS();
+
+  bool Match = true;
 
-  if (op == BO_LT && IsZero(S, E->getRHS())) {
+  if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << "< 0" << "false" << HasEnumType(E->getLHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_GE && IsZero(S, E->getRHS())) {
+  << "< 0" << "false" << HasEnumType(LHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << ">= 0" << "true" << HasEnumType(E->getLHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_GT && IsZero(S, E->getLHS())) {
+  << ">= 0" << "true" << HasEnumType(LHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
-  << "0 >" << "false" << HasEnumType(E->getRHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_LE && IsZero(S, E->getLHS())) {
+  << "0 >" << "false" << HasEnumType(RHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_LE && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
-  << "0 <=" << "true" << HasEnumType(E->getRHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  }
+  << "0 <=" << "true" << HasEnumType(RHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else
+Match = false;
+
+  return Match;
 }
 
 void DiagnoseOutOfRangeComparison(Sema , BinaryOperator *E, Expr *Constant,
@@ -8612,7 +8631,7 @@
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();
 
-  // 0 values are handled later by CheckTrivialUnsignedComparison().
+  // 0 values are handled later by CheckTautologicalComparisonWithZero().
   if ((Value == 0) && (!OtherIsBooleanType))
 return;
 
@@ -8849,16 +8868,22 @@
 (IsRHSIntegralLiteral && IsLHSIntegralLiteral);
   } else if (!T->hasUnsignedIntegerRepresentation())
   IsComparisonConstant = E->isIntegerConstantExpr(S.Context);
-  
+
+  // We don't care about value-dependent expressions or expressions
+  // whose result is a constant.
+  if (IsComparisonConstant)
+return AnalyzeImpConvsInComparison(S, E);
+
+  // If this is a tautological comparison, suppress -Wsign-compare.
+  if (CheckTautologicalComparisonWithZero(S, E))
+return AnalyzeImpConvsInComparison(S, E);
+
   // We don't do anything special if this isn't an unsigned integral
   // comparison:  we're only interested in integral comparisons, and
   // signed comparisons only happen in cases we don't care to warn about.
-  //
-  // We also don't care about value-dependent expressions or expressions
-  // whose result is a constant.
-  if (!T->hasUnsignedIntegerRepresentation() || IsComparisonConstant)
+  if (!T->hasUnsignedIntegerRepresentation())
 return 

r312750 - [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Sep  7 15:14:25 2017
New Revision: 312750

URL: http://llvm.org/viewvc/llvm-project?rev=312750=rev
Log:
[Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

Summary:
This is a first half(?) of a fix for the following bug:
https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)

GCC's -Wtype-limits does warn on comparison of unsigned value
with signed zero (as in, with 0), but clang only warns if the
zero is unsigned (i.e. 0U).

Also, be careful not to double-warn, or falsely warn on
comparison of signed/fp variable and signed 0.

Yes, all these testcases are needed.

Testing: $ ninja check-clang-sema check-clang-semacxx
Also, no new warnings for clang stage-2 build.

Reviewers: rjmccall, rsmith, aaron.ballman

Reviewed By: rjmccall

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/compare.c
cfe/trunk/test/Sema/outof-range-constant-compare.c
cfe/trunk/test/SemaCXX/compare.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=312750=312749=312750=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Thu Sep  7 15:14:25 2017
@@ -71,6 +71,13 @@ Improvements to Clang's diagnostics
   errors/warnings, as the system frameworks might add a method with the same
   selector which could make the message send to ``id`` ambiguous.
 
+- ``-Wtautological-compare`` now warns when comparing an unsigned integer and 0
+  regardless of whether the constant is signed or unsigned."
+
+- ``-Wtautological-compare`` now warns about comparing a signed integer and 0
+  when the signed integer is coerced to an unsigned type for the comparison.
+  ``-Wsign-compare`` was adjusted not to warn in this case.
+
 Non-comprehensive list of changes in this release
 -
 

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=312750=312749=312750=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep  7 15:14:25 2017
@@ -8567,32 +8567,51 @@ bool HasEnumType(Expr *E) {
   return E->getType()->isEnumeralType();
 }
 
-void CheckTrivialUnsignedComparison(Sema , BinaryOperator *E) {
+bool isNonBooleanUnsignedValue(Expr *E) {
+  // We are checking that the expression is not known to have boolean value,
+  // is an integer type; and is either unsigned after implicit casts,
+  // or was unsigned before implicit casts.
+  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType() &&
+ (!E->getType()->isSignedIntegerType() ||
+  !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
+}
+
+bool CheckTautologicalComparisonWithZero(Sema , BinaryOperator *E) {
   // Disable warning in template instantiations.
   if (S.inTemplateInstantiation())
-return;
+return false;
+
+  // bool values are handled by DiagnoseOutOfRangeComparison().
 
   BinaryOperatorKind op = E->getOpcode();
   if (E->isValueDependent())
-return;
+return false;
 
-  if (op == BO_LT && IsZero(S, E->getRHS())) {
+  Expr *LHS = E->getLHS();
+  Expr *RHS = E->getRHS();
+
+  bool Match = true;
+
+  if (op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << "< 0" << "false" << HasEnumType(E->getLHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_GE && IsZero(S, E->getRHS())) {
+  << "< 0" << "false" << HasEnumType(LHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
-  << ">= 0" << "true" << HasEnumType(E->getLHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_GT && IsZero(S, E->getLHS())) {
+  << ">= 0" << "true" << HasEnumType(LHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
 S.Diag(E->getOperatorLoc(), diag::warn_runsigned_always_true_comparison)
-  << "0 >" << "false" << HasEnumType(E->getRHS())
-  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
-  } else if (op == BO_LE && IsZero(S, E->getLHS())) {
+  << "0 >" << "false" << HasEnumType(RHS)
+  << LHS->getSourceRange() << RHS->getSourceRange();
+  } else if (op == BO_LE && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
 

r312749 - Add target triple to improve the happiness of MSVC buildbots.

2017-09-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Sep  7 15:07:52 2017
New Revision: 312749

URL: http://llvm.org/viewvc/llvm-project?rev=312749=rev
Log:
Add target triple to improve the happiness of MSVC buildbots.

Modified:
cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm

Modified: cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm?rev=312749=312748=312749=diff
==
--- cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm (original)
+++ cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm Thu Sep  7 15:07:52 
2017
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fmodules-ts %s -emit-module-interface -o %t
-// RUN: %clang_cc1 -fmodules-ts -x pcm %t -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fmodules-ts -triple x86_64-linux %s -emit-module-interface 
-o %t
+// RUN: %clang_cc1 -fmodules-ts -triple x86_64-linux -x pcm %t -emit-llvm -o - 
| FileCheck %s
 
 export module M;
 


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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: docs/ReleaseNotes.rst:79
+- ``-Wtautological-compare`` now warns about comparison of signed integer and
+  ``0U`` constant when appropriate.
+

rjmccall wrote:
> Probably better to be clear here: "now warns about comparing a signed integer 
> and 0 when the signed integer is coerced to an unsigned type for the 
> comparison."
That's great, thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37496: Fix validation of the -mthread-model flag in the Clang driver

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

r312748


https://reviews.llvm.org/D37496



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


r312748 - Fix validation of the -mthread-model flag in the Clang driver

2017-09-07 Thread Jonathan Roelofs via cfe-commits
Author: jroelofs
Date: Thu Sep  7 15:01:25 2017
New Revision: 312748

URL: http://llvm.org/viewvc/llvm-project?rev=312748=rev
Log:
Fix validation of the -mthread-model flag in the Clang driver

The ToolChain class validates the -mthread-model flag in the constructor which
doesn't work correctly since the thread model methods are virtual methods. The
check is moved into Clang::ConstructJob() when constructing the internal
command line.

https://reviews.llvm.org/D37496

Patch by: Ian Tessier!

Modified:
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=312748=312747=312748=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Thu Sep  7 15:01:25 2017
@@ -74,11 +74,6 @@ ToolChain::ToolChain(const Driver , co
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
   EffectiveTriple() {
-  if (Arg *A = Args.getLastArg(options::OPT_mthread_model))
-if (!isThreadModelSupported(A->getValue()))
-  D.Diag(diag::err_drv_invalid_thread_model_for_target)
-  << A->getValue() << A->getAsString(Args);
-
   std::string CandidateLibPath = getArchSpecificLibPath();
   if (getVFS().exists(CandidateLibPath))
 getFilePaths().push_back(CandidateLibPath);

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=312748=312747=312748=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Sep  7 15:01:25 2017
@@ -3235,8 +3235,12 @@ void Clang::ConstructJob(Compilation ,
   }
 
   CmdArgs.push_back("-mthread-model");
-  if (Arg *A = Args.getLastArg(options::OPT_mthread_model))
+  if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
+if (!getToolChain().isThreadModelSupported(A->getValue()))
+  D.Diag(diag::err_drv_invalid_thread_model_for_target)
+  << A->getValue() << A->getAsString(Args);
 CmdArgs.push_back(A->getValue());
+  }
   else
 CmdArgs.push_back(Args.MakeArgString(getToolChain().getThreadModel()));
 


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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114260.
lebedev.ri marked 3 inline comments as done.
lebedev.ri added a comment.

Address review notes.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaChecking.cpp
  test/Sema/compare.c
  test/Sema/outof-range-constant-compare.c
  test/SemaCXX/compare.cpp

Index: test/SemaCXX/compare.cpp
===
--- test/SemaCXX/compare.cpp
+++ test/SemaCXX/compare.cpp
@@ -73,16 +73,16 @@
  ((int) a == (unsigned int) B) +
  ((short) a == (unsigned short) B) +
  ((signed char) a == (unsigned char) B) +
- (a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned long) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
  (a < (unsigned int) B) +
  (a < (unsigned short) B) +
  (a < (unsigned char) B) +
  ((long) a < B) +
  ((int) a < B) +
  ((short) a < B) +
  ((signed char) a < B) +
- ((long) a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
- ((int) a < (unsigned int) B) +  // expected-warning {{comparison of integers of different signs}}
+ ((long) a < (unsigned long) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
+ ((int) a < (unsigned int) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
  ((short) a < (unsigned short) B) +
  ((signed char) a < (unsigned char) B) +
 
Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -6,6 +6,59 @@
 int main()
 {
 int a = value();
+
+if (a == 0xL)
+return 0;
+if (a != 0xL)
+return 0;
+if (a < 0xL)
+return 0;
+if (a <= 0xL)
+return 0;
+if (a > 0xL)
+return 0;
+if (a >= 0xL)
+return 0;
+
+if (0xL == a)
+return 0;
+if (0xL != a)
+return 0;
+if (0xL < a)
+return 0;
+if (0xL <= a)
+return 0;
+if (0xL > a)
+return 0;
+if (0xL >= a)
+return 0;
+
+if (a == 0xUL)
+return 0;
+if (a != 0xUL)
+return 0;
+if (a < 0xUL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (a <= 0xUL)
+return 0;
+if (a > 0xUL)
+return 0;
+if (a >= 0xUL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+
+if (0xUL == a)
+return 0;
+if (0xUL != a)
+return 0;
+if (0xUL < a)
+return 0;
+if (0xUL <= a) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+return 0;
+if (0xUL > a) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+return 0;
+if (0xUL >= a)
+return 0;
+
 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
 return 0;
 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
@@ -74,6 +127,7 @@
 return 0;
 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
 return 0;
+
 long l = value();
 if (l == 0x1234567812345678L)
 return 0;
@@ -106,34 +160,107 @@
 return 0;
 if (un != 0xL)
 return 0;
-if (un < 0xL)
+if (un < 0xL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
 return 0;
 if (un <= 0xL)
 return 0;
 if (un > 0xL)
 return 0;
-if (un >= 0xL)
+if (un >= 0xL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
 return 0;
 
 if (0xL == un)
 return 0;
 if (0xL != un)
 return 0;
 if (0xL < un)
 return 0;
-if (0xL <= un)
+if (0xL <= un) // expected-warning {{comparison of 0 <= unsigned expression is 

[PATCH] D37577: [libclang] add 'clang_getCursorTLSKind'

2017-09-07 Thread Masud Rahman via Phabricator via cfe-commits
frutiger updated this revision to Diff 114256.
frutiger added a comment.

Exports 'TLSKind' in the '__all__' array.


https://reviews.llvm.org/D37577

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_tls_kind.py
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -189,6 +189,7 @@
 clang_getCursorResultType
 clang_getCursorSemanticParent
 clang_getCursorSpelling
+clang_getCursorTLSKind
 clang_getCursorType
 clang_getCursorUSR
 clang_getCursorVisibility
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7412,6 +7412,22 @@
   return CXLanguage_Invalid;
 }
 
+CXTLSKind clang_getCursorTLSKind(CXCursor cursor) {
+  const Decl *D  = cxcursor::getCursorDecl(cursor);
+  if (const VarDecl *VD = dyn_cast(D)) {
+switch (VD->getTLSKind()) {
+  case VarDecl::TLS_None:
+return CXTLS_None;
+  case VarDecl::TLS_Dynamic:
+return CXTLS_Dynamic;
+  case VarDecl::TLS_Static:
+return CXTLS_Static;
+}
+  }
+
+  return CXTLS_None;
+}
+
  /// \brief If the given cursor is the "templated" declaration
  /// descibing a class or function template, return the class or
  /// function template.
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -2836,6 +2836,20 @@
  */
 CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
 
+/**
+ * \brief Describe the "TLS kind" of the declaration referred to by a cursor.
+ */
+enum CXTLSKind {
+  CXTLS_None = 0,
+  CXTLS_Dynamic,
+  CXTLS_Static
+};
+
+/**
+ * \brief Determine the "TLS kind" of the declaration referred to by a cursor.
+ */
+CINDEX_LINKAGE enum CXTLSKind clang_getCursorTLSKind(CXCursor cursor);
+
 /**
  * \brief Returns the translation unit that a cursor originated from.
  */
Index: bindings/python/tests/cindex/test_tls_kind.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_tls_kind.py
@@ -0,0 +1,22 @@
+
+from clang.cindex import TLSKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_tls_kind():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+int tls_none;
+thread_local tls_dynamic;
+""", lang = 'cpp')
+
+tls_none = get_cursor(tu.cursor, 'tls_none')
+assert tls_none.tls_kind == TLSKind.NONE;
+
+tls_dynamic = get_cursor(tu.cursor, 'tls_dynamic')
+assert tls_dynamic.tls_kind == TLSKind.DYNAMIC
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def tls_kind(self):
+"""Return the TLS kind of this cursor."""
+if not hasattr(self, '_tls_kind'):
+self._tls_kind = conf.lib.clang_getCursorTLSKind(self)
+
+return TLSKind.from_id(self._tls_kind)
+
 @property
 def extent(self):
 """
@@ -2061,6 +2069,23 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class TLSKind(BaseEnumeration):
+"""Describes the kind of thread local storage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'TLSKind.%s' % (self.name,)
+
+TLSKind.NONE = TLSKind(0)
+TLSKind.DYNAMIC = TLSKind(1)
+TLSKind.STATIC = TLSKind(2)
+
 class Type(Structure):
 """
 The type of an element in the abstract syntax tree.
@@ -4066,6 +4091,7 @@
 'Index',
 'SourceLocation',
 'SourceRange',
+'TLSKind',
 'TokenKind',
 'Token',
 'TranslationUnitLoadError',
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37573: [bindings] add Cursor.linkage

2017-09-07 Thread Masud Rahman via Phabricator via cfe-commits
frutiger updated this revision to Diff 114257.
frutiger added a comment.

Export 'LinkageKind' in '__all__'.  Use consistent quotes in test drivers.


https://reviews.llvm.org/D37573

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_linkage.py


Index: bindings/python/tests/cindex/test_linkage.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,30 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, 'no_linkage')
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, 'internal')
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, 'unique_external')
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, 'external')
+assert external.linkage == LinkageKind.EXTERNAL
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def linkage(self):
+"""Return the linkage of this cursor."""
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
 @property
 def extent(self):
 """
@@ -2061,6 +2069,25 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class LinkageKind(BaseEnumeration):
+"""Describes the kind of linkage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)
+LinkageKind.EXTERNAL = LinkageKind(4)
+
 class Type(Structure):
 """
 The type of an element in the abstract syntax tree.
@@ -4064,6 +4091,7 @@
 'File',
 'FixIt',
 'Index',
+'LinkageKind',
 'SourceLocation',
 'SourceRange',
 'TokenKind',


Index: bindings/python/tests/cindex/test_linkage.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,30 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, 'no_linkage')
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, 'internal')
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, 'unique_external')
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, 'external')
+assert external.linkage == LinkageKind.EXTERNAL
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def linkage(self):
+"""Return the linkage of this cursor."""
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
 @property
 def extent(self):
 """
@@ -2061,6 +2069,25 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class LinkageKind(BaseEnumeration):
+"""Describes the kind of linkage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)

[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

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

Great, thanks.  Just a few tweaks.




Comment at: docs/ReleaseNotes.rst:76
+  ``0`` constant was adjusted to warn regardless of whether the constant is
+  signed or unsigned.
+

"now warns when comparing an unsigned integer and 0 regardless of whether the 
constant is signed or unsigned."



Comment at: docs/ReleaseNotes.rst:79
+- ``-Wtautological-compare`` now warns about comparison of signed integer and
+  ``0U`` constant when appropriate.
+

Probably better to be clear here: "now warns about comparing a signed integer 
and 0 when the signed integer is coerced to an unsigned type for the 
comparison."



Comment at: docs/ReleaseNotes.rst:83
+  already warned about comparison of signed integer (which is automatically
+  promoted to an unsigned integer) and ``0U`` constant.
+

I'm not sure this level of detail is necessary in release notes.



Comment at: lib/Sema/SemaChecking.cpp:8879
+  // on -Wsign-compare
+  if(CheckTautologicalComparisonWithZero(S, E))
+return AnalyzeImpConvsInComparison(S, E);

Space after 'if', and I would suggest for the comment:

  "If this is a tautological comparison, suppress -Wsign-compare."


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114249.
lebedev.ri marked 4 inline comments as done.
lebedev.ri added a comment.

Address review notes.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaChecking.cpp
  test/Sema/compare.c
  test/Sema/outof-range-constant-compare.c
  test/SemaCXX/compare.cpp

Index: test/SemaCXX/compare.cpp
===
--- test/SemaCXX/compare.cpp
+++ test/SemaCXX/compare.cpp
@@ -73,16 +73,16 @@
  ((int) a == (unsigned int) B) +
  ((short) a == (unsigned short) B) +
  ((signed char) a == (unsigned char) B) +
- (a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
+ (a < (unsigned long) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
  (a < (unsigned int) B) +
  (a < (unsigned short) B) +
  (a < (unsigned char) B) +
  ((long) a < B) +
  ((int) a < B) +
  ((short) a < B) +
  ((signed char) a < B) +
- ((long) a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
- ((int) a < (unsigned int) B) +  // expected-warning {{comparison of integers of different signs}}
+ ((long) a < (unsigned long) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
+ ((int) a < (unsigned int) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
  ((short) a < (unsigned short) B) +
  ((signed char) a < (unsigned char) B) +
 
Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -6,6 +6,59 @@
 int main()
 {
 int a = value();
+
+if (a == 0xL)
+return 0;
+if (a != 0xL)
+return 0;
+if (a < 0xL)
+return 0;
+if (a <= 0xL)
+return 0;
+if (a > 0xL)
+return 0;
+if (a >= 0xL)
+return 0;
+
+if (0xL == a)
+return 0;
+if (0xL != a)
+return 0;
+if (0xL < a)
+return 0;
+if (0xL <= a)
+return 0;
+if (0xL > a)
+return 0;
+if (0xL >= a)
+return 0;
+
+if (a == 0xUL)
+return 0;
+if (a != 0xUL)
+return 0;
+if (a < 0xUL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (a <= 0xUL)
+return 0;
+if (a > 0xUL)
+return 0;
+if (a >= 0xUL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+
+if (0xUL == a)
+return 0;
+if (0xUL != a)
+return 0;
+if (0xUL < a)
+return 0;
+if (0xUL <= a) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+return 0;
+if (0xUL > a) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+return 0;
+if (0xUL >= a)
+return 0;
+
 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
 return 0;
 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
@@ -74,6 +127,7 @@
 return 0;
 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
 return 0;
+
 long l = value();
 if (l == 0x1234567812345678L)
 return 0;
@@ -106,34 +160,107 @@
 return 0;
 if (un != 0xL)
 return 0;
-if (un < 0xL)
+if (un < 0xL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
 return 0;
 if (un <= 0xL)
 return 0;
 if (un > 0xL)
 return 0;
-if (un >= 0xL)
+if (un >= 0xL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
 return 0;
 
 if (0xL == un)
 return 0;
 if (0xL != un)
 return 0;
 if (0xL < un)
 return 0;
-if (0xL <= un)
+if (0xL <= un) // expected-warning {{comparison of 0 <= unsigned expression is 

Re: r312696 - [modules ts] Add test for [basic.link]p3.

2017-09-07 Thread Galina Kistanova via cfe-commits
Hello Richard,

This commit broke one of our builders:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/4705

Failing Tests (1):
Clang :: CXX/modules-ts/basic/basic.link/p3.cppm

Please have a look?

Thanks

Galina

On Wed, Sep 6, 2017 at 10:29 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Wed Sep  6 22:29:39 2017
> New Revision: 312696
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312696=rev
> Log:
> [modules ts] Add test for [basic.link]p3.
>
> Added:
> cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm
>
> Added: cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/
> modules-ts/basic/basic.link/p3.cppm?rev=312696=auto
> 
> ==
> --- cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm (added)
> +++ cfe/trunk/test/CXX/modules-ts/basic/basic.link/p3.cppm Wed Sep  6
> 22:29:39 2017
> @@ -0,0 +1,11 @@
> +// RUN: %clang_cc1 -fmodules-ts %s -emit-module-interface -o %t
> +// RUN: %clang_cc1 -fmodules-ts -x pcm %t -emit-llvm -o - | FileCheck %s
> +
> +export module M;
> +
> +// CHECK-DAG: @_ZW1ME1a = constant i32 1
> +const int a = 1;
> +// CHECK-DAG: @b = constant i32 2
> +export const int b = 2;
> +
> +export int f() { return a + b; }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r312743 - Add IDNS_Tag to C++ declarations that conflict with tag declarations.

2017-09-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Sep  7 13:22:00 2017
New Revision: 312743

URL: http://llvm.org/viewvc/llvm-project?rev=312743=rev
Log:
Add IDNS_Tag to C++ declarations that conflict with tag declarations.

Fixes some accepts-invalids with tags and other declarations declared in the
same scope.

Added:
cfe/trunk/test/CXX/basic/basic.scope/basic.scope.declarative/p4.cpp
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=312743=312742=312743=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Sep  7 13:22:00 2017
@@ -1002,13 +1002,15 @@ public:
   /// declaration, but in the semantic context of the enclosing namespace
   /// scope.
   void setLocalExternDecl() {
-assert((IdentifierNamespace == IDNS_Ordinary ||
-IdentifierNamespace == IDNS_OrdinaryFriend) &&
-   "namespace is not ordinary");
-
 Decl *Prev = getPreviousDecl();
 IdentifierNamespace &= ~IDNS_Ordinary;
 
+// It's OK for the declaration to still have the "invisible friend" flag or
+// the "conflicts with tag declarations in this scope" flag for the outer
+// scope.
+assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 &&
+   "namespace is not ordinary");
+
 IdentifierNamespace |= IDNS_LocalExtern;
 if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)
   IdentifierNamespace |= IDNS_Ordinary;

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=312743=312742=312743=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Sep  7 13:22:00 2017
@@ -681,7 +681,6 @@ unsigned Decl::getIdentifierNamespaceFor
 case CXXConversion:
 case EnumConstant:
 case Var:
-case Binding:
 case ImplicitParam:
 case ParmVar:
 case ObjCMethod:
@@ -693,10 +692,11 @@ unsigned Decl::getIdentifierNamespaceFor
 case IndirectField:
   return IDNS_Ordinary | IDNS_Member;
 
+case Binding:
 case NonTypeTemplateParm:
-  // Non-type template parameters are not found by lookups that ignore
-  // non-types, but they are found by redeclaration lookups for tag types,
-  // so we include them in the tag namespace.
+case VarTemplate:
+  // These (C++-only) declarations are found by redeclaration lookup for
+  // tag types, so we include them in the tag namespace.
   return IDNS_Ordinary | IDNS_Tag;
 
 case ObjCCompatibleAlias:
@@ -705,7 +705,6 @@ unsigned Decl::getIdentifierNamespaceFor
 
 case Typedef:
 case TypeAlias:
-case TypeAliasTemplate:
 case TemplateTypeParm:
 case ObjCTypeParam:
   return IDNS_Ordinary | IDNS_Type;
@@ -741,11 +740,11 @@ unsigned Decl::getIdentifierNamespaceFor
   return IDNS_Namespace;
 
 case FunctionTemplate:
-case VarTemplate:
   return IDNS_Ordinary;
 
 case ClassTemplate:
 case TemplateTemplateParm:
+case TypeAliasTemplate:
   return IDNS_Ordinary | IDNS_Tag | IDNS_Type;
 
 case OMPDeclareReduction:

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=312743=312742=312743=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep  7 13:22:00 2017
@@ -5288,13 +5288,6 @@ NamedDecl *Sema::HandleDeclarator(Scope
   TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
   QualType R = TInfo->getType();
 
-  if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
-// If this is a typedef, we'll end up spewing multiple diagnostics.
-// Just return early; it's safer. If this is a function, let the
-// "constructor cannot have a return type" diagnostic handle it.
-if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
-  return nullptr;
-
   if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
   UPPC_DeclarationType))
 D.setInvalidType();
@@ -5373,12 +5366,17 @@ NamedDecl *Sema::HandleDeclarator(Scope
 Previous.clear();
   }
 
+  if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
+// Forget that the previous declaration is the injected-class-name.
+Previous.clear();
+
   // In C++, the previous declaration we find might be a tag type
   // (class or enum). In this case, the new declaration will hide the
-  // tag type. Note that this does does not apply if we're declaring a
-  // typedef (C++ [dcl.typedef]p4).
+  // tag type. Note that 

[PATCH] D37101: [clangd] Add support for snippet completions

2017-09-07 Thread Raoul Wols via Phabricator via cfe-commits
rwols updated this revision to Diff 114242.
rwols added a comment.

Change command-line option back to "-enable-snippets", disable snippets by 
default. This is a temporary solution and we should instead inspect the 
"initialize" request from the client to check wether the client supports 
snippets.


https://reviews.llvm.org/D37101

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.cpp
  clangd/clients/clangd-vscode/package.json
  clangd/tool/ClangdMain.cpp
  test/clangd/authority-less-uri.test
  test/clangd/completion-snippet.test
  test/clangd/completion.test

Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -16,25 +16,25 @@
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a","insertTextFormat":1}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb","insertTextFormat":1}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc","insertTextFormat":1}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator=","insertTextFormat":1}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake","insertTextFormat":1}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","filterText":"f","insertText":"f","insertTextFormat":1}
 # CHECK: ]}
 Content-Length: 148
 
 {"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # Repeat the completion request, expect the same results.
 #
 # CHECK: {"jsonrpc":"2.0","id":2,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"00035a","filterText":"a","insertText":"a","insertTextFormat":1}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"00035bb","filterText":"bb","insertText":"bb","insertTextFormat":1}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"00035ccc","filterText":"ccc","insertText":"ccc","insertTextFormat":1}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"00034operator=","filterText":"operator=","insertText":"operator=","insertTextFormat":1}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"00034~fake","filterText":"~fake","insertText":"~fake","insertTextFormat":1}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"00035f","filterText":"f","insertText":"f","insertTextFormat":1}
 # CHECK: ]}
 # Update the source file and check for completions again.
 Content-Length: 226
@@ -47,7 +47,7 @@
 # Repeat the completion request, expect the same results.
 #
 # CHECK: {"jsonrpc":"2.0","id":3,"result":[
-# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"00034func","filterText":"func","insertText":"func"}
+# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, 

[PATCH] D37231: Add half load and store builtins

2017-09-07 Thread Jan Vesely via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312742: [OpenCL] Add half load and store builtins (authored 
by jvesely).

Changed prior to commit:
  https://reviews.llvm.org/D37231?vs=113624=114240#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37231

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/include/clang/Basic/Builtins.h
  cfe/trunk/lib/Basic/Builtins.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGenOpenCL/no-half.cl

Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -2768,6 +2768,24 @@
 Name),
 {NDRange, Block}));
   }
+
+  case Builtin::BI__builtin_store_half:
+  case Builtin::BI__builtin_store_halff: {
+Value *Val = EmitScalarExpr(E->getArg(0));
+Address Address = EmitPointerWithAlignment(E->getArg(1));
+Value *HalfVal = Builder.CreateFPTrunc(Val, Builder.getHalfTy());
+return RValue::get(Builder.CreateStore(HalfVal, Address));
+  }
+  case Builtin::BI__builtin_load_half: {
+Address Address = EmitPointerWithAlignment(E->getArg(0));
+Value *HalfVal = Builder.CreateLoad(Address);
+return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getDoubleTy()));
+  }
+  case Builtin::BI__builtin_load_halff: {
+Address Address = EmitPointerWithAlignment(E->getArg(0));
+Value *HalfVal = Builder.CreateLoad(Address);
+return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getFloatTy()));
+  }
   case Builtin::BIprintf:
 if (getTarget().getTriple().isNVPTX())
   return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);
Index: cfe/trunk/lib/Basic/Builtins.cpp
===
--- cfe/trunk/lib/Basic/Builtins.cpp
+++ cfe/trunk/lib/Basic/Builtins.cpp
@@ -69,9 +69,14 @@
   bool MSModeUnsupported =
   !LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG);
   bool ObjCUnsupported = !LangOpts.ObjC1 && BuiltinInfo.Langs == OBJC_LANG;
-  bool OclCUnsupported = LangOpts.OpenCLVersion != 200 &&
- BuiltinInfo.Langs == OCLC20_LANG;
+  bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
+  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) ==  OCLC1X_LANG;
+  bool OclC2Unsupported = LangOpts.OpenCLVersion != 200 &&
+  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
+  bool OclCUnsupported = !LangOpts.OpenCL &&
+ (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
+ !OclC1Unsupported && !OclC2Unsupported &&
  !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
 }
 
Index: cfe/trunk/include/clang/Basic/Builtins.h
===
--- cfe/trunk/include/clang/Basic/Builtins.h
+++ cfe/trunk/include/clang/Basic/Builtins.h
@@ -36,10 +36,12 @@
   CXX_LANG = 0x4, // builtin for cplusplus only.
   OBJC_LANG = 0x8,// builtin for objective-c and objective-c++
   MS_LANG = 0x10, // builtin requires MS mode.
-  OCLC20_LANG = 0x20, // builtin for OpenCL C only.
+  OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
+  OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
-  ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
+  ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG,// builtin requires MS mode.
+  ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC20_LANG // builtin for OCLC languages.
 };
 
 namespace Builtin {
Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -1424,6 +1424,12 @@
 LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
 
+// OpenCL half load/store builtin
+LANGBUILTIN(__builtin_store_half, "vdh*", "n", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_store_halff, "vfh*", "n", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_load_half, "dhC*", "nc", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_load_halff, "fhC*", "nc", ALL_OCLC_LANGUAGES)
+
 // Builtins for os_log/os_trace
 BUILTIN(__builtin_os_log_format_buffer_size, "zcC*.", "p:0:nut")
 BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")
Index: cfe/trunk/test/CodeGenOpenCL/no-half.cl
===
--- cfe/trunk/test/CodeGenOpenCL/no-half.cl
+++ cfe/trunk/test/CodeGenOpenCL/no-half.cl
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -cl-std=cl2.0 -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=cl1.2 

r312742 - [OpenCL] Add half load and store builtins

2017-09-07 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Sep  7 12:39:10 2017
New Revision: 312742

URL: http://llvm.org/viewvc/llvm-project?rev=312742=rev
Log:
[OpenCL] Add half load and store builtins

This enables load/stores of half type, without half being a legal type.

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

Added:
cfe/trunk/test/CodeGenOpenCL/no-half.cl
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/lib/Basic/Builtins.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=312742=312741=312742=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Thu Sep  7 12:39:10 2017
@@ -1424,6 +1424,12 @@ LANGBUILTIN(to_global, "v*v*", "tn", OCL
 LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
 
+// OpenCL half load/store builtin
+LANGBUILTIN(__builtin_store_half, "vdh*", "n", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_store_halff, "vfh*", "n", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_load_half, "dhC*", "nc", ALL_OCLC_LANGUAGES)
+LANGBUILTIN(__builtin_load_halff, "fhC*", "nc", ALL_OCLC_LANGUAGES)
+
 // Builtins for os_log/os_trace
 BUILTIN(__builtin_os_log_format_buffer_size, "zcC*.", "p:0:nut")
 BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=312742=312741=312742=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Thu Sep  7 12:39:10 2017
@@ -36,10 +36,12 @@ enum LanguageID {
   CXX_LANG = 0x4, // builtin for cplusplus only.
   OBJC_LANG = 0x8,// builtin for objective-c and objective-c++
   MS_LANG = 0x10, // builtin requires MS mode.
-  OCLC20_LANG = 0x20, // builtin for OpenCL C only.
+  OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
+  OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
-  ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
+  ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG,// builtin requires MS mode.
+  ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC20_LANG // builtin for OCLC languages.
 };
 
 namespace Builtin {

Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=312742=312741=312742=diff
==
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Thu Sep  7 12:39:10 2017
@@ -69,9 +69,14 @@ bool Builtin::Context::builtinIsSupporte
   bool MSModeUnsupported =
   !LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG);
   bool ObjCUnsupported = !LangOpts.ObjC1 && BuiltinInfo.Langs == OBJC_LANG;
-  bool OclCUnsupported = LangOpts.OpenCLVersion != 200 &&
- BuiltinInfo.Langs == OCLC20_LANG;
+  bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
+  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) ==  
OCLC1X_LANG;
+  bool OclC2Unsupported = LangOpts.OpenCLVersion != 200 &&
+  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == 
OCLC20_LANG;
+  bool OclCUnsupported = !LangOpts.OpenCL &&
+ (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported 
&&
+ !OclC1Unsupported && !OclC2Unsupported &&
  !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=312742=312741=312742=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Sep  7 12:39:10 2017
@@ -2768,6 +2768,24 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 Name),
 {NDRange, Block}));
   }
+
+  case Builtin::BI__builtin_store_half:
+  case Builtin::BI__builtin_store_halff: {
+Value *Val = EmitScalarExpr(E->getArg(0));
+Address Address = EmitPointerWithAlignment(E->getArg(1));
+Value *HalfVal = Builder.CreateFPTrunc(Val, Builder.getHalfTy());
+return RValue::get(Builder.CreateStore(HalfVal, Address));
+  }
+  case Builtin::BI__builtin_load_half: {
+Address Address = EmitPointerWithAlignment(E->getArg(0));
+Value *HalfVal = Builder.CreateLoad(Address);
+

[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D37568#863735, @b-sumner wrote:

> The assembler accepts v[N] in addition to vN.  I'm not sure if that is needed 
> here.


Then we'd better also allow that in constraints to avoid confusion of users.


https://reviews.llvm.org/D37568



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


[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Brian Sumner via Phabricator via cfe-commits
b-sumner added a comment.

The assembler accepts v[N] in addition to vN.  I'm not sure if that is needed 
here.


https://reviews.llvm.org/D37568



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


[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-07 Thread Cameron via Phabricator via cfe-commits
cameron314 updated this revision to Diff 114228.
cameron314 added a comment.

Here's an updated patch. The code required to make it work is much simpler when 
the BOM is simply ignored :-)


https://reviews.llvm.org/D37491

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  include/clang/Lex/Lexer.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/FrontendActions.cpp
  lib/Frontend/PrecompiledPreamble.cpp
  lib/Lex/Lexer.cpp
  lib/Lex/Preprocessor.cpp
  unittests/Frontend/PchPreambleTest.cpp

Index: unittests/Frontend/PchPreambleTest.cpp
===
--- unittests/Frontend/PchPreambleTest.cpp
+++ unittests/Frontend/PchPreambleTest.cpp
@@ -91,8 +91,19 @@
 PreprocessorOptions  = CI->getPreprocessorOpts();
 PPOpts.RemappedFilesKeepOriginalName = true;
 
+struct DebugConsumer : DiagnosticConsumer
+{
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
+SmallString<16> DiagText;
+Info.FormatDiagnostic(DiagText);
+llvm::errs() << DiagText << '\n';
+  }
+};
+
 IntrusiveRefCntPtr
-  Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, new DiagnosticConsumer));
+  Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, new DebugConsumer));
 
 FileManager *FileMgr = new FileManager(FSOpts, VFS);
 
@@ -153,4 +164,70 @@
   ASSERT_EQ(initialCounts[2], GetFileReadCount(Header2));
 }
 
+TEST_F(PchPreambleTest, ReparseWithDisappearingBom) {
+  std::string Header = "//./header.h";
+  std::string Main = "//./main.cpp";
+  AddFile(Header, "int random() { return 4; }");
+  AddFile(Main,
+"\xef\xbb\xbf"
+"#include \"//./header.h\"\n"
+"int main() { return random() * 2; }");
+
+  std::unique_ptr AST(ParseAST(Main));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  // Check the file counts to make sure the preamble is
+  // really being used (and the header isn't being read
+  // again)
+  unsigned initialCounts[] = {
+GetFileReadCount(Main),
+GetFileReadCount(Header)
+  };
+
+  // Remove BOM but keep the rest the same
+  RemapFile(Main,
+"#include \"//./header.h\"\n"
+"int main() { return random() * 2; }");
+
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  ASSERT_EQ(initialCounts[0], GetFileReadCount(Main));
+  ASSERT_EQ(initialCounts[1], GetFileReadCount(Header));
+}
+
+TEST_F(PchPreambleTest, ReparseWithAppearingBom) {
+  std::string Header = "//./header.h";
+  std::string Main = "//./main.cpp";
+  AddFile(Header, "int random() { return 4; }");
+  AddFile(Main,
+"#include \"//./header.h\"\n"
+"int main() { return random() * 2; }");
+
+  std::unique_ptr AST(ParseAST(Main));
+  ASSERT_TRUE(AST.get());
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  // Check the file counts to make sure the preamble is
+  // really being used (and the header isn't being read
+  // again)
+  unsigned initialCounts[] = {
+GetFileReadCount(Main),
+GetFileReadCount(Header)
+  };
+
+  // Suddenly, a BOM appeared
+  RemapFile(Main,
+"\xef\xbb\xbf"
+"#include \"//./header.h\"\n"
+"int main() { return random() * 2; }");
+
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  ASSERT_EQ(initialCounts[0], GetFileReadCount(Main));
+  ASSERT_EQ(initialCounts[1], GetFileReadCount(Header));
+}
+
 } // anonymous namespace
Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -516,9 +516,9 @@
 // If we've been asked to skip bytes in the main file (e.g., as part of a
 // precompiled preamble), do so now.
 if (SkipMainFilePreamble.first > 0)
-  CurLexer->SkipBytes(SkipMainFilePreamble.first, 
+  CurLexer->SkipBytes(SkipMainFilePreamble.first,
   SkipMainFilePreamble.second);
-
+
 // Tell the header info that the main file was entered.  If the file is later
 // #imported, it won't be re-entered.
 if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -552,9 +552,9 @@
 
 } // end anonymous namespace
 
-std::pair Lexer::ComputePreamble(StringRef Buffer,
- const LangOptions ,
- unsigned MaxLines) {
+PreambleBounds Lexer::ComputePreamble(StringRef Buffer,
+  const LangOptions ,
+  unsigned MaxLines) {
   // Create a lexer starting at the beginning of the file. Note that we use a
   

[PATCH] D36410: [OpenCL] Handle taking address of block captures

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D36410#863579, @Anastasia wrote:

> In https://reviews.llvm.org/D36410#863508, @yaxunl wrote:
>
> > In https://reviews.llvm.org/D36410#863426, @Anastasia wrote:
> >
> > > In https://reviews.llvm.org/D36410#863409, @yaxunl wrote:
> > >
> > > > LGTM as a temporary measure until we have a solution for properly 
> > > > emitting blocks as enqueued kernel.
> > >
> > >
> > > Should I start discussion with Khronos on that? What would our preference 
> > > be - implicitly `generic` AS for capture addresses?
> >
> >
> > I had a discussion with Brian and we realized that captured variable in 
> > global address space is kind of unusual since that means each work item 
> > needs to have a different global pointer as the block context argument to 
> > the kernel, whereas usually when you set global pointer kernel argument for 
> > a kernel, different work items get the same global pointer. However, we 
> > cannot totally rule out an implementation of enqueue_kernel like that.
> >
> > That said, I kind of think the address space of captured variable is 
> > implementation dependent, though normally it seems private address space 
> > makes more sense.
>
>
> Would it not be a problem generally though? Because private AS memory won't 
> be accessed elsewhere and therefore if the block is enqueued to run on a 
> different core or any place with different memory segment it would cause an 
> issue...


The block context can be passed to the kernel directly. In this case it ends up 
in the stack of the callee and takes private address space.

> 
> 
>> I do not object to open a discussion at khronos to clarify this.
> 
> Bug #16398 in case you would like to track it.




Repository:
  rL LLVM

https://reviews.llvm.org/D36410



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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri planned changes to this revision.
lebedev.ri added inline comments.



Comment at: test/Sema/outof-range-constant-compare.c:41
+if (a < 0xUL)
+return 0;
+if (a <= 0xUL)

rjmccall wrote:
> Hmm.  I think this should probably still warn under -Wtautological-compare, 
> shouldn't it?  The fact that it also warns under -Wsign-compare is something 
> we should try to suppress, but it's definitely still a tautological 
> comparison because of the promotion to an unsigned type.
Hmm, actually, i guess so?
```
int value(void);
int main()
{
int a = value();
if (a <= 0xUL)
return 0;   
}
```
```
  |-BinaryOperator  '_Bool' '<='
  | |-ImplicitCastExpr  'unsigned long' 
  | | `-ImplicitCastExpr  'int' 
  | |   `-DeclRefExpr  'int' lvalue Var 0x7028450 'a' 'int'
  | `-IntegerLiteral  'unsigned long' 0
```
Here,  clang and gcc both only warn about different sign comparison.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D31140: [LLVMbugs] [Bug 18710] Only generate .ARM.exidx and .ARM.extab when needed in EHABI

2017-09-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

If you want to follow what we do for x86-64 on ARM, you should be doing this in 
the driver, not codegen (grep for IsUnwindTablesDefault).


https://reviews.llvm.org/D31140



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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:8589
+  Expr *LHS = E->getLHS()->IgnoreParenImpCasts();
+  Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
+

lebedev.ri wrote:
> rjmccall wrote:
> > Do you still need these?  I'm always antsy about code that ignores implicit 
> > casts, especially before evaluation.
> Yes, absolutely. I did check without them, and they are needed. Else:
> ```
> $ ninja check-clang-sema check-clang-semacxx
> [27/29] Running lit suite /build/clang/test/Sema
> lit.py: /build/clang/test/lit.cfg:200: note: using clang: 
> '/build/llvm-build-Clang-release/./bin/clang'
> FAIL: Clang :: Sema/compare.c (195 of 548)
>  TEST 'Clang :: Sema/compare.c' FAILED 
> 
> Script:
> --
> /build/llvm-build-Clang-release/./bin/clang -cc1 -internal-isystem 
> /build/llvm-build-Clang-release/lib/clang/6.0.0/include -nostdsysteminc 
> -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare 
> /build/clang/test/Sema/compare.c -Wno-unreachable-code
> --
> Exit Code: 1
> 
> Command Output (stderr):
> --
> error: 'warning' diagnostics seen but not expected: 
>   File /build/clang/test/Sema/compare.c Line 80: comparison of unsigned 
> expression < 0 is always false
>   File /build/clang/test/Sema/compare.c Line 88: comparison of unsigned 
> expression < 0 is always false
>   File /build/clang/test/Sema/compare.c Line 89: comparison of unsigned 
> expression < 0 is always false
> 3 errors generated.
> 
> --
> 
> 
> FAIL: Clang :: Sema/outof-range-constant-compare.c (357 of 548)
>  TEST 'Clang :: Sema/outof-range-constant-compare.c' 
> FAILED 
> Script:
> --
> /build/llvm-build-Clang-release/./bin/clang -cc1 -internal-isystem 
> /build/llvm-build-Clang-release/lib/clang/6.0.0/include -nostdsysteminc 
> -triple x86_64-apple-darwin -fsyntax-only 
> -Wtautological-constant-out-of-range-compare -verify 
> /build/clang/test/Sema/outof-range-constant-compare.c
> --
> Exit Code: 1
> 
> Command Output (stderr):
> --
> error: 'warning' diagnostics expected but not seen: 
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 163: 
> comparison of unsigned expression < 0 is always false
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 169: 
> comparison of unsigned expression >= 0 is always true
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 178: 
> comparison of 0 <= unsigned expression is always true
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 180: 
> comparison of 0 > unsigned expression is always false
> error: 'warning' diagnostics seen but not expected: 
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 40: 
> comparison of unsigned expression < 0 is always false
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 46: 
> comparison of unsigned expression >= 0 is always true
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 55: 
> comparison of 0 <= unsigned expression is always true
>   File /build/clang/test/Sema/outof-range-constant-compare.c Line 57: 
> comparison of 0 > unsigned expression is always false
> 8 errors generated.
> 
> --
> 
> 
> Testing Time: 2.05s
> 
> Failing Tests (2):
> Clang :: Sema/compare.c
> Clang :: Sema/outof-range-constant-compare.c
> 
>   Expected Passes: 546
>   Unexpected Failures: 2
> FAILED: tools/clang/test/CMakeFiles/check-clang-sema 
> cd /build/llvm-build-Clang-release/tools/clang/test && /usr/bin/python2.7 
> /build/llvm/utils/lit/lit.py -sv --param 
> clang_site_config=/build/llvm-build-Clang-release/tools/clang/test/lit.site.cfg
>  /build/clang/test/Sema
> ninja: build stopped: subcommand failed.
> ```
What happens if you just move them into isNonBooleanUnsignedValue?



Comment at: test/Sema/outof-range-constant-compare.c:41
+if (a < 0xUL)
+return 0;
+if (a <= 0xUL)

Hmm.  I think this should probably still warn under -Wtautological-compare, 
shouldn't it?  The fact that it also warns under -Wsign-compare is something we 
should try to suppress, but it's definitely still a tautological comparison 
because of the promotion to an unsigned type.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:8879
+  if (IsComparisonConstant)
 return AnalyzeImpConvsInComparison(S, E);
   

rjmccall wrote:
> lebedev.ri wrote:
> > rjmccall wrote:
> > > Part of the purpose of checking for signed comparisons up here is to 
> > > avoid unnecessarily computing ranges for the operands when we aren't 
> > > going to use them.  That's still something we want to avoid.  I think you 
> > > just need to call CheckTrivialUnsignedComparison in this fallback case, 
> > > at least when the comparison is not constant.
> > > 
> > > You should also rename CheckTrivialUnsignedComparison to something like 
> > > CheckTautologicalComparison.
> > Ok, i must admit that i understand the idea to have minimal overhead. But i 
> > don't really follow the code in here :)
> > This seems to work, and `check-clang-sema`+`check-clang-semacxx`+stage2 
> > still pass.
> > Is this obviously-wrong / some testcase is missing? 
> There's a lot of code here doing very similar checks, and we just want to 
> ensure that we aren't doing too much redundant work.  I think the way you've 
> structured it now is fine.
OK :)



Comment at: lib/Sema/SemaChecking.cpp:8589
+  Expr *LHS = E->getLHS()->IgnoreParenImpCasts();
+  Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
+

rjmccall wrote:
> Do you still need these?  I'm always antsy about code that ignores implicit 
> casts, especially before evaluation.
Yes, absolutely. I did check without them, and they are needed. Else:
```
$ ninja check-clang-sema check-clang-semacxx
[27/29] Running lit suite /build/clang/test/Sema
lit.py: /build/clang/test/lit.cfg:200: note: using clang: 
'/build/llvm-build-Clang-release/./bin/clang'
FAIL: Clang :: Sema/compare.c (195 of 548)
 TEST 'Clang :: Sema/compare.c' FAILED 
Script:
--
/build/llvm-build-Clang-release/./bin/clang -cc1 -internal-isystem 
/build/llvm-build-Clang-release/lib/clang/6.0.0/include -nostdsysteminc -triple 
x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare 
/build/clang/test/Sema/compare.c -Wno-unreachable-code
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics seen but not expected: 
  File /build/clang/test/Sema/compare.c Line 80: comparison of unsigned 
expression < 0 is always false
  File /build/clang/test/Sema/compare.c Line 88: comparison of unsigned 
expression < 0 is always false
  File /build/clang/test/Sema/compare.c Line 89: comparison of unsigned 
expression < 0 is always false
3 errors generated.

--


FAIL: Clang :: Sema/outof-range-constant-compare.c (357 of 548)
 TEST 'Clang :: Sema/outof-range-constant-compare.c' FAILED 

Script:
--
/build/llvm-build-Clang-release/./bin/clang -cc1 -internal-isystem 
/build/llvm-build-Clang-release/lib/clang/6.0.0/include -nostdsysteminc -triple 
x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare 
-verify /build/clang/test/Sema/outof-range-constant-compare.c
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics expected but not seen: 
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 163: 
comparison of unsigned expression < 0 is always false
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 169: 
comparison of unsigned expression >= 0 is always true
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 178: 
comparison of 0 <= unsigned expression is always true
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 180: 
comparison of 0 > unsigned expression is always false
error: 'warning' diagnostics seen but not expected: 
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 40: 
comparison of unsigned expression < 0 is always false
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 46: 
comparison of unsigned expression >= 0 is always true
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 55: 
comparison of 0 <= unsigned expression is always true
  File /build/clang/test/Sema/outof-range-constant-compare.c Line 57: 
comparison of 0 > unsigned expression is always false
8 errors generated.

--


Testing Time: 2.05s

Failing Tests (2):
Clang :: Sema/compare.c
Clang :: Sema/outof-range-constant-compare.c

  Expected Passes: 546
  Unexpected Failures: 2
FAILED: tools/clang/test/CMakeFiles/check-clang-sema 
cd /build/llvm-build-Clang-release/tools/clang/test && /usr/bin/python2.7 
/build/llvm/utils/lit/lit.py -sv --param 
clang_site_config=/build/llvm-build-Clang-release/tools/clang/test/lit.site.cfg 
/build/clang/test/Sema
ninja: build stopped: subcommand failed.
```


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:8879
+  if (IsComparisonConstant)
 return AnalyzeImpConvsInComparison(S, E);
   

lebedev.ri wrote:
> rjmccall wrote:
> > Part of the purpose of checking for signed comparisons up here is to avoid 
> > unnecessarily computing ranges for the operands when we aren't going to use 
> > them.  That's still something we want to avoid.  I think you just need to 
> > call CheckTrivialUnsignedComparison in this fallback case, at least when 
> > the comparison is not constant.
> > 
> > You should also rename CheckTrivialUnsignedComparison to something like 
> > CheckTautologicalComparison.
> Ok, i must admit that i understand the idea to have minimal overhead. But i 
> don't really follow the code in here :)
> This seems to work, and `check-clang-sema`+`check-clang-semacxx`+stage2 still 
> pass.
> Is this obviously-wrong / some testcase is missing? 
There's a lot of code here doing very similar checks, and we just want to 
ensure that we aren't doing too much redundant work.  I think the way you've 
structured it now is fine.



Comment at: lib/Sema/SemaChecking.cpp:8589
+  Expr *LHS = E->getLHS()->IgnoreParenImpCasts();
+  Expr *RHS = E->getRHS()->IgnoreParenImpCasts();
+

Do you still need these?  I'm always antsy about code that ignores implicit 
casts, especially before evaluation.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 114223.
yaxunl marked 3 inline comments as done.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Revised by Matt's comments.


https://reviews.llvm.org/D37568

Files:
  lib/Basic/Targets/AMDGPU.h
  test/CodeGenOpenCL/amdgcn-inline-asm.cl
  test/Sema/inline-asm-validate-amdgpu.cl

Index: test/Sema/inline-asm-validate-amdgpu.cl
===
--- test/Sema/inline-asm-validate-amdgpu.cl
+++ test/Sema/inline-asm-validate-amdgpu.cl
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -x cl -triple amdgcn -fsyntax-only  %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -triple amdgcn -fsyntax-only -verify %s
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 kernel void test () {
 
@@ -12,3 +13,45 @@
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
 }
+
+__kernel void
+test_float(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : ""(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "="(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}a"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1}a' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, exec" : "={v1}"(ci) : "{v2}"(ai), "{exec}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, exec" : "={v1}"(ci) : "{v2}"(ai), "{exec}a"(bi) : ); // expected-error {{invalid input constraint '{exec}a' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "=v"(ci) : "v"(ai), "v"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// expected-error {{invalid output constraint '=v1' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{a}"(ai), "{v3}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{a}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+c[i] = ci;
+}
+
+__kernel void
+test_double(const __global double *a, const __global double *b, __global double *c, unsigned i)
+{
+double ai = a[i];
+double bi = b[i];
+double ci;
+
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : );
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "=v{[1:2]}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '=v{[1:2]}' in asm}}
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]a}"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '={v[1:2]a}' in asm}}
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "={v[1:2]}a"(ci) : "{v[3:4]}"(ai), "{v[5:6]}"(bi) : ); //expected-error {{invalid output constraint '={v[1:2]}a' in asm}}
+
+__asm("v_add_f64_e64 v[1:2], v[3:4], v[5:6]" : "=v[1:2]"(ci) : "v[3:4]"(ai), "v[5:6]"(bi) : ); //expected-error {{invalid output constraint '=v[1:2]' in asm}}
+
+c[i] = ci;
+}
Index: test/CodeGenOpenCL/amdgcn-inline-asm.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgcn-inline-asm.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn -O0 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @ker
+__kernel void
+ker(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+// CHECK: call float asm "v_add_f32_e32 v1, v2, v3", "={v1},{v2},{v3}"(float %{{.*}}, float %{{.*}})
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+// CHECK: call float asm "v_add_f32_e32 $0, $1, $2", "={v1},{v2},{v3}"(float %{{.*}}, float %{{.*}})
+__asm("v_add_f32_e32 %0, %1, %2" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+c[i] = ci;
+}
Index: lib/Basic/Targets/AMDGPU.h
===
--- lib/Basic/Targets/AMDGPU.h
+++ lib/Basic/Targets/AMDGPU.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Compiler.h"
 
@@ -115,17 +116,79 @@
 return None;
   }
 
+  /// Accepted register names: (n, m 

[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:8592
+  bool BadR = !RType->isIntegerType() || RType->isSignedIntegerType() ||
+  RHS->isKnownToHaveBooleanValue();
+

rjmccall wrote:
> Please extract a function which computes this for an Expr* and then call it 
> as part of the conditions below, e.g.:
> 
>   if (op == BO_LT && isNonBooleanUnsignedValue(E->getLHS()) && IsZero(S, 
> E->getRHS()))
Yes, that is indeed a better way :)



Comment at: lib/Sema/SemaChecking.cpp:8879
+  if (IsComparisonConstant)
 return AnalyzeImpConvsInComparison(S, E);
   

rjmccall wrote:
> Part of the purpose of checking for signed comparisons up here is to avoid 
> unnecessarily computing ranges for the operands when we aren't going to use 
> them.  That's still something we want to avoid.  I think you just need to 
> call CheckTrivialUnsignedComparison in this fallback case, at least when the 
> comparison is not constant.
> 
> You should also rename CheckTrivialUnsignedComparison to something like 
> CheckTautologicalComparison.
Ok, i must admit that i understand the idea to have minimal overhead. But i 
don't really follow the code in here :)
This seems to work, and `check-clang-sema`+`check-clang-semacxx`+stage2 still 
pass.
Is this obviously-wrong / some testcase is missing? 


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114221.
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.

Address review notes.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-constant-compare.c

Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -6,6 +6,59 @@
 int main()
 {
 int a = value();
+
+if (a == 0xL)
+return 0;
+if (a != 0xL)
+return 0;
+if (a < 0xL)
+return 0;
+if (a <= 0xL)
+return 0;
+if (a > 0xL)
+return 0;
+if (a >= 0xL)
+return 0;
+
+if (0xL == a)
+return 0;
+if (0xL != a)
+return 0;
+if (0xL < a)
+return 0;
+if (0xL <= a)
+return 0;
+if (0xL > a)
+return 0;
+if (0xL >= a)
+return 0;
+
+if (a == 0xUL)
+return 0;
+if (a != 0xUL)
+return 0;
+if (a < 0xUL)
+return 0;
+if (a <= 0xUL)
+return 0;
+if (a > 0xUL)
+return 0;
+if (a >= 0xUL)
+return 0;
+
+if (0xUL == a)
+return 0;
+if (0xUL != a)
+return 0;
+if (0xUL < a)
+return 0;
+if (0xUL <= a)
+return 0;
+if (0xUL > a)
+return 0;
+if (0xUL >= a)
+return 0;
+
 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
 return 0;
 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
@@ -74,6 +127,7 @@
 return 0;
 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
 return 0;
+
 long l = value();
 if (l == 0x1234567812345678L)
 return 0;
@@ -106,34 +160,107 @@
 return 0;
 if (un != 0xL)
 return 0;
-if (un < 0xL)
+if (un < 0xL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
 return 0;
 if (un <= 0xL)
 return 0;
 if (un > 0xL)
 return 0;
-if (un >= 0xL)
+if (un >= 0xL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
 return 0;
 
 if (0xL == un)
 return 0;
 if (0xL != un)
 return 0;
 if (0xL < un)
 return 0;
-if (0xL <= un)
+if (0xL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
 return 0;
-if (0xL > un)
+if (0xL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
 return 0;
 if (0xL >= un)
 return 0;
-float fl = 0;
-if (fl == 0xL) // no warning
-  return 0;
 
-float dl = 0;
-if (dl == 0xL) // no warning
-  return 0;
+if (un == 0xUL)
+return 0;
+if (un != 0xUL)
+return 0;
+if (un < 0xUL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (un <= 0xUL)
+return 0;
+if (un > 0xUL)
+return 0;
+if (un >= 0xUL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+
+if (0xUL == un)
+return 0;
+if (0xUL != un)
+return 0;
+if (0xUL < un)
+return 0;
+if (0xUL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+return 0;
+if (0xUL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+return 0;
+if (0xUL >= un)
+return 0;
+
+float fl = 0;
+if (fl == 0xL)
+return 0;
+if (fl != 0xL)
+return 0;
+if (fl < 0xL)
+return 0;
+if (fl <= 0xL)
+return 0;
+if (fl > 

[PATCH] D37548: [CUDA] When compilation fails, print the compilation mode.

2017-09-07 Thread Justin Lebar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312736: [CUDA] When compilation fails, print the compilation 
mode. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D37548?vs=114112=114222#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37548

Files:
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/test/SemaCUDA/error-includes-mode.cu


Index: cfe/trunk/test/SemaCUDA/error-includes-mode.cu
===
--- cfe/trunk/test/SemaCUDA/error-includes-mode.cu
+++ cfe/trunk/test/SemaCUDA/error-includes-mode.cu
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck --check-prefix HOST %s
+// RUN: not %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_35 \
+// RUN:   -fcuda-is-device -fsyntax-only %s 2>&1 | FileCheck --check-prefix 
SM35 %s
+
+// HOST: 1 error generated when compiling for host
+// SM35: 1 error generated when compiling for sm_35
+error;
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -1003,8 +1003,17 @@
   OS << " and ";
 if (NumErrors)
   OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
-if (NumWarnings || NumErrors)
-  OS << " generated.\n";
+if (NumWarnings || NumErrors) {
+  OS << " generated";
+  if (getLangOpts().CUDA) {
+if (!getLangOpts().CUDAIsDevice) {
+  OS << " when compiling for host";
+} else {
+  OS << " when compiling for " << getTargetOpts().CPU;
+}
+  }
+  OS << ".\n";
+}
   }
 
   if (getFrontendOpts().ShowStats) {


Index: cfe/trunk/test/SemaCUDA/error-includes-mode.cu
===
--- cfe/trunk/test/SemaCUDA/error-includes-mode.cu
+++ cfe/trunk/test/SemaCUDA/error-includes-mode.cu
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck --check-prefix HOST %s
+// RUN: not %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_35 \
+// RUN:   -fcuda-is-device -fsyntax-only %s 2>&1 | FileCheck --check-prefix SM35 %s
+
+// HOST: 1 error generated when compiling for host
+// SM35: 1 error generated when compiling for sm_35
+error;
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -1003,8 +1003,17 @@
   OS << " and ";
 if (NumErrors)
   OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
-if (NumWarnings || NumErrors)
-  OS << " generated.\n";
+if (NumWarnings || NumErrors) {
+  OS << " generated";
+  if (getLangOpts().CUDA) {
+if (!getLangOpts().CUDAIsDevice) {
+  OS << " when compiling for host";
+} else {
+  OS << " when compiling for " << getTargetOpts().CPU;
+}
+  }
+  OS << ".\n";
+}
   }
 
   if (getFrontendOpts().ShowStats) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r312736 - [CUDA] When compilation fails, print the compilation mode.

2017-09-07 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Sep  7 11:37:16 2017
New Revision: 312736

URL: http://llvm.org/viewvc/llvm-project?rev=312736=rev
Log:
[CUDA] When compilation fails, print the compilation mode.

Summary:
That is, instead of "1 error generated", we now say "1 error generated
when compiling for sm_35".

This (partially) solves a usability foogtun wherein e.g. users call a
function that's only defined on sm_60 when compiling for sm_35, and they
get an unhelpful error message.

Reviewers: tra

Subscribers: sanjoy, cfe-commits

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

Added:
cfe/trunk/test/SemaCUDA/error-includes-mode.cu
Modified:
cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=312736=312735=312736=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Sep  7 11:37:16 2017
@@ -1003,8 +1003,17 @@ bool CompilerInstance::ExecuteAction(Fro
   OS << " and ";
 if (NumErrors)
   OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
-if (NumWarnings || NumErrors)
-  OS << " generated.\n";
+if (NumWarnings || NumErrors) {
+  OS << " generated";
+  if (getLangOpts().CUDA) {
+if (!getLangOpts().CUDAIsDevice) {
+  OS << " when compiling for host";
+} else {
+  OS << " when compiling for " << getTargetOpts().CPU;
+}
+  }
+  OS << ".\n";
+}
   }
 
   if (getFrontendOpts().ShowStats) {

Added: cfe/trunk/test/SemaCUDA/error-includes-mode.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/error-includes-mode.cu?rev=312736=auto
==
--- cfe/trunk/test/SemaCUDA/error-includes-mode.cu (added)
+++ cfe/trunk/test/SemaCUDA/error-includes-mode.cu Thu Sep  7 11:37:16 2017
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck --check-prefix HOST %s
+// RUN: not %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_35 \
+// RUN:   -fcuda-is-device -fsyntax-only %s 2>&1 | FileCheck --check-prefix 
SM35 %s
+
+// HOST: 1 error generated when compiling for host
+// SM35: 1 error generated when compiling for sm_35
+error;


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


[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-09-07 Thread Simon Schroeder via Phabricator via cfe-commits
schroedersi added a comment.

Hello Richard, what do you think about the printing context changes? Are they 
what you expected?


https://reviews.llvm.org/D30946



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


[PATCH] D37576: [CUDA] Added rudimentary support for CUDA-9 and sm_70.

2017-09-07 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312734: [CUDA] Added rudimentary support for CUDA-9 and 
sm_70. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D37576?vs=114206=114216#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37576

Files:
  cfe/trunk/include/clang/Basic/Cuda.h
  cfe/trunk/lib/Basic/Cuda.cpp
  cfe/trunk/lib/Basic/Targets/NVPTX.cpp
  cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
  cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
  cfe/trunk/test/Driver/cuda-arch-translation.cu
  llvm/trunk/lib/Target/NVPTX/NVPTX.td
  llvm/trunk/test/CodeGen/NVPTX/sm-version-70.ll

Index: llvm/trunk/lib/Target/NVPTX/NVPTX.td
===
--- llvm/trunk/lib/Target/NVPTX/NVPTX.td
+++ llvm/trunk/lib/Target/NVPTX/NVPTX.td
@@ -50,6 +50,8 @@
  "Target SM 6.1">;
 def SM62 : SubtargetFeature<"sm_62", "SmVersion", "62",
  "Target SM 6.2">;
+def SM70 : SubtargetFeature<"sm_70", "SmVersion", "70",
+ "Target SM 7.0">;
 
 def SATOM : SubtargetFeature<"satom", "HasAtomScope", "true",
  "Atomic operations with scope">;
@@ -67,6 +69,8 @@
  "Use PTX version 4.3">;
 def PTX50 : SubtargetFeature<"ptx50", "PTXVersion", "50",
  "Use PTX version 5.0">;
+def PTX60 : SubtargetFeature<"ptx60", "PTXVersion", "60",
+ "Use PTX version 6.0">;
 
 //===--===//
 // NVPTX supported processors.
@@ -87,6 +91,7 @@
 def : Proc<"sm_60", [SM60, PTX50, SATOM]>;
 def : Proc<"sm_61", [SM61, PTX50, SATOM]>;
 def : Proc<"sm_62", [SM62, PTX50, SATOM]>;
+def : Proc<"sm_70", [SM70, PTX60, SATOM]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: llvm/trunk/test/CodeGen/NVPTX/sm-version-70.ll
===
--- llvm/trunk/test/CodeGen/NVPTX/sm-version-70.ll
+++ llvm/trunk/test/CodeGen/NVPTX/sm-version-70.ll
@@ -0,0 +1,5 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_70 | FileCheck %s
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 | FileCheck %s
+
+; CHECK: .version 6.0
+; CHECK: .target sm_70
Index: cfe/trunk/include/clang/Basic/Cuda.h
===
--- cfe/trunk/include/clang/Basic/Cuda.h
+++ cfe/trunk/include/clang/Basic/Cuda.h
@@ -21,6 +21,7 @@
   CUDA_70,
   CUDA_75,
   CUDA_80,
+  CUDA_90,
 };
 const char *CudaVersionToString(CudaVersion V);
 
@@ -41,6 +42,7 @@
   SM_60,
   SM_61,
   SM_62,
+  SM_70,
 };
 const char *CudaArchToString(CudaArch A);
 
@@ -60,6 +62,7 @@
   COMPUTE_60,
   COMPUTE_61,
   COMPUTE_62,
+  COMPUTE_70,
 };
 const char *CudaVirtualArchToString(CudaVirtualArch A);
 
Index: cfe/trunk/test/Driver/cuda-arch-translation.cu
===
--- cfe/trunk/test/Driver/cuda-arch-translation.cu
+++ cfe/trunk/test/Driver/cuda-arch-translation.cu
@@ -5,26 +5,36 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
-// CHECK:fatbinary
-
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM20 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM20 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_21 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM21 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM21 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_30 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM30 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM30 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_32 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM32 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM32 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_35 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM35 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM35 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_37 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM37 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM37 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_50 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM50 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM50 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_52 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM52 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM52 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_53 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM53 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM53 %s
+// 

r312734 - [CUDA] Added rudimentary support for CUDA-9 and sm_70.

2017-09-07 Thread Artem Belevich via cfe-commits
Author: tra
Date: Thu Sep  7 11:14:32 2017
New Revision: 312734

URL: http://llvm.org/viewvc/llvm-project?rev=312734=rev
Log:
[CUDA] Added rudimentary support for CUDA-9 and sm_70.

For now CUDA-9 is not included in the list of CUDA versions clang
searches for, so the path to CUDA-9 must be explicitly passed
via --cuda-path=.

On LLVM side NVPTX added sm_70 GPU type which bumps required
PTX version to 6.0, but otherwise is equivalent to sm_62 at the moment.

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

Modified:
cfe/trunk/include/clang/Basic/Cuda.h
cfe/trunk/lib/Basic/Cuda.cpp
cfe/trunk/lib/Basic/Targets/NVPTX.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Headers/__clang_cuda_runtime_wrapper.h
cfe/trunk/test/Driver/cuda-arch-translation.cu

Modified: cfe/trunk/include/clang/Basic/Cuda.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Cuda.h?rev=312734=312733=312734=diff
==
--- cfe/trunk/include/clang/Basic/Cuda.h (original)
+++ cfe/trunk/include/clang/Basic/Cuda.h Thu Sep  7 11:14:32 2017
@@ -21,6 +21,7 @@ enum class CudaVersion {
   CUDA_70,
   CUDA_75,
   CUDA_80,
+  CUDA_90,
 };
 const char *CudaVersionToString(CudaVersion V);
 
@@ -41,6 +42,7 @@ enum class CudaArch {
   SM_60,
   SM_61,
   SM_62,
+  SM_70,
 };
 const char *CudaArchToString(CudaArch A);
 
@@ -60,6 +62,7 @@ enum class CudaVirtualArch {
   COMPUTE_60,
   COMPUTE_61,
   COMPUTE_62,
+  COMPUTE_70,
 };
 const char *CudaVirtualArchToString(CudaVirtualArch A);
 

Modified: cfe/trunk/lib/Basic/Cuda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Cuda.cpp?rev=312734=312733=312734=diff
==
--- cfe/trunk/lib/Basic/Cuda.cpp (original)
+++ cfe/trunk/lib/Basic/Cuda.cpp Thu Sep  7 11:14:32 2017
@@ -16,6 +16,8 @@ const char *CudaVersionToString(CudaVers
 return "7.5";
   case CudaVersion::CUDA_80:
 return "8.0";
+  case CudaVersion::CUDA_90:
+return "9.0";
   }
   llvm_unreachable("invalid enum");
 }
@@ -48,6 +50,8 @@ const char *CudaArchToString(CudaArch A)
 return "sm_61";
   case CudaArch::SM_62:
 return "sm_62";
+  case CudaArch::SM_70:
+return "sm_70";
   }
   llvm_unreachable("invalid enum");
 }
@@ -66,6 +70,7 @@ CudaArch StringToCudaArch(llvm::StringRe
   .Case("sm_60", CudaArch::SM_60)
   .Case("sm_61", CudaArch::SM_61)
   .Case("sm_62", CudaArch::SM_62)
+  .Case("sm_70", CudaArch::SM_70)
   .Default(CudaArch::UNKNOWN);
 }
 
@@ -95,6 +100,8 @@ const char *CudaVirtualArchToString(Cuda
 return "compute_61";
   case CudaVirtualArch::COMPUTE_62:
 return "compute_62";
+  case CudaVirtualArch::COMPUTE_70:
+return "compute_70";
   }
   llvm_unreachable("invalid enum");
 }
@@ -112,6 +119,7 @@ CudaVirtualArch StringToCudaVirtualArch(
   .Case("compute_60", CudaVirtualArch::COMPUTE_60)
   .Case("compute_61", CudaVirtualArch::COMPUTE_61)
   .Case("compute_62", CudaVirtualArch::COMPUTE_62)
+  .Case("compute_70", CudaVirtualArch::COMPUTE_70)
   .Default(CudaVirtualArch::UNKNOWN);
 }
 
@@ -142,6 +150,8 @@ CudaVirtualArch VirtualArchForCudaArch(C
 return CudaVirtualArch::COMPUTE_61;
   case CudaArch::SM_62:
 return CudaVirtualArch::COMPUTE_62;
+  case CudaArch::SM_70:
+return CudaVirtualArch::COMPUTE_70;
   }
   llvm_unreachable("invalid enum");
 }
@@ -164,6 +174,8 @@ CudaVersion MinVersionForCudaArch(CudaAr
   case CudaArch::SM_61:
   case CudaArch::SM_62:
 return CudaVersion::CUDA_80;
+  case CudaArch::SM_70:
+return CudaVersion::CUDA_90;
   }
   llvm_unreachable("invalid enum");
 }

Modified: cfe/trunk/lib/Basic/Targets/NVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/NVPTX.cpp?rev=312734=312733=312734=diff
==
--- cfe/trunk/lib/Basic/Targets/NVPTX.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/NVPTX.cpp Thu Sep  7 11:14:32 2017
@@ -183,6 +183,8 @@ void NVPTXTargetInfo::getTargetDefines(c
 return "610";
   case CudaArch::SM_62:
 return "620";
+  case CudaArch::SM_70:
+return "700";
   }
   llvm_unreachable("unhandled CudaArch");
 }();

Modified: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Cuda.cpp?rev=312734=312733=312734=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp Thu Sep  7 11:14:32 2017
@@ -49,6 +49,8 @@ static CudaVersion ParseCudaVersionFile(
 return CudaVersion::CUDA_75;
   if (Major == 8 && Minor == 0)
 return CudaVersion::CUDA_80;
+  if (Major == 9 && Minor == 0)
+return CudaVersion::CUDA_90;
   return CudaVersion::UNKNOWN;
 }
 
@@ -112,43 +114,55 @@ 

[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: test/Sema/inline-asm-validate-amdgpu.cl:38
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// 
expected-error {{invalid output constraint '=v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1:2"(ci) : "v3:4"(ai), "v4:5"(bi) : 
);  // expected-error {{invalid output constraint '=v1:2' in asm}}
+

arsenm wrote:
> arsenm wrote:
> > I don't understand. The backend parsed syntax is v[3:4]. Why should v3:4 be 
> > valid? Also in this example you are using a 64-bit input to a 32-bit operand
> i.e. this won't parse in the backend and is invalid. The brackets are required
Will fix the syntax about [].

The test did not consider validity of the inline assembly for the backend since 
FE only check format. I agree it is better to make it valid for backend and 
will try to fix that.



https://reviews.llvm.org/D37568



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


[PATCH] D37577: [libclang] add 'clang_getCursorTLSKind'

2017-09-07 Thread Masud Rahman via Phabricator via cfe-commits
frutiger created this revision.

Introduce the 'TLS Kind' property of variable declarations through
libclang.  Additionally, provide a Python accessor for it, and test that
functionality.


https://reviews.llvm.org/D37577

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_tls_kind.py
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -189,6 +189,7 @@
 clang_getCursorResultType
 clang_getCursorSemanticParent
 clang_getCursorSpelling
+clang_getCursorTLSKind
 clang_getCursorType
 clang_getCursorUSR
 clang_getCursorVisibility
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7412,6 +7412,22 @@
   return CXLanguage_Invalid;
 }
 
+CXTLSKind clang_getCursorTLSKind(CXCursor cursor) {
+  const Decl *D  = cxcursor::getCursorDecl(cursor);
+  if (const VarDecl *VD = dyn_cast(D)) {
+switch (VD->getTLSKind()) {
+  case VarDecl::TLS_None:
+return CXTLS_None;
+  case VarDecl::TLS_Dynamic:
+return CXTLS_Dynamic;
+  case VarDecl::TLS_Static:
+return CXTLS_Static;
+}
+  }
+
+  return CXTLS_None;
+}
+
  /// \brief If the given cursor is the "templated" declaration
  /// descibing a class or function template, return the class or
  /// function template.
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -2836,6 +2836,20 @@
  */
 CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
 
+/**
+ * \brief Describe the "TLS kind" of the declaration referred to by a cursor.
+ */
+enum CXTLSKind {
+  CXTLS_None = 0,
+  CXTLS_Dynamic,
+  CXTLS_Static
+};
+
+/**
+ * \brief Determine the "TLS kind" of the declaration referred to by a cursor.
+ */
+CINDEX_LINKAGE enum CXTLSKind clang_getCursorTLSKind(CXCursor cursor);
+
 /**
  * \brief Returns the translation unit that a cursor originated from.
  */
Index: bindings/python/tests/cindex/test_tls_kind.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_tls_kind.py
@@ -0,0 +1,22 @@
+
+from clang.cindex import TLSKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_tls_kind():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+int tls_none;
+thread_local tls_dynamic;
+""", lang = 'cpp')
+
+tls_none = get_cursor(tu.cursor, 'tls_none')
+assert tls_none.tls_kind == TLSKind.NONE;
+
+tls_dynamic = get_cursor(tu.cursor, 'tls_dynamic')
+assert tls_dynamic.tls_kind == TLSKind.DYNAMIC
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def tls_kind(self):
+"""Return the TLS kind of this cursor."""
+if not hasattr(self, '_tls_kind'):
+self._tls_kind = conf.lib.clang_getCursorTLSKind(self)
+
+return TLSKind.from_id(self._tls_kind)
+
 @property
 def extent(self):
 """
@@ -2061,6 +2069,23 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class TLSKind(BaseEnumeration):
+"""Describes the kind of thread local storage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'TLSKind.%s' % (self.name,)
+
+TLSKind.NONE = TLSKind(0)
+TLSKind.DYNAMIC = TLSKind(1)
+TLSKind.STATIC = TLSKind(2)
+
 class Type(Structure):
 """
 The type of an element in the abstract syntax tree.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37496: Fix validation of the -mthread-model flag in the Clang driver

2017-09-07 Thread Ian Tessier via Phabricator via cfe-commits
itessier added a comment.

Do you mind submitting this CL? I don't have access to SVN.


https://reviews.llvm.org/D37496



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


[PATCH] D37576: [CUDA] Added rudimentary support for CUDA-9 and sm_70.

2017-09-07 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added a comment.
This revision is now accepted and ready to land.

Looks great.


https://reviews.llvm.org/D37576



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


[PATCH] D37576: [CUDA] Added rudimentary support for CUDA-9 and sm_70.

2017-09-07 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 114206.
tra added a comment.

Added tests for sm_70 support.


https://reviews.llvm.org/D37576

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/test/Driver/cuda-arch-translation.cu
  llvm/lib/Target/NVPTX/NVPTX.td
  llvm/test/CodeGen/NVPTX/sm-version-70.ll

Index: llvm/test/CodeGen/NVPTX/sm-version-70.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/sm-version-70.ll
@@ -0,0 +1,5 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_70 | FileCheck %s
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 | FileCheck %s
+
+; CHECK: .version 6.0
+; CHECK: .target sm_70
Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -50,6 +50,8 @@
  "Target SM 6.1">;
 def SM62 : SubtargetFeature<"sm_62", "SmVersion", "62",
  "Target SM 6.2">;
+def SM70 : SubtargetFeature<"sm_70", "SmVersion", "70",
+ "Target SM 7.0">;
 
 def SATOM : SubtargetFeature<"satom", "HasAtomScope", "true",
  "Atomic operations with scope">;
@@ -67,6 +69,8 @@
  "Use PTX version 4.3">;
 def PTX50 : SubtargetFeature<"ptx50", "PTXVersion", "50",
  "Use PTX version 5.0">;
+def PTX60 : SubtargetFeature<"ptx60", "PTXVersion", "60",
+ "Use PTX version 6.0">;
 
 //===--===//
 // NVPTX supported processors.
@@ -87,6 +91,7 @@
 def : Proc<"sm_60", [SM60, PTX50, SATOM]>;
 def : Proc<"sm_61", [SM61, PTX50, SATOM]>;
 def : Proc<"sm_62", [SM62, PTX50, SATOM]>;
+def : Proc<"sm_70", [SM70, PTX60, SATOM]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/test/Driver/cuda-arch-translation.cu
===
--- clang/test/Driver/cuda-arch-translation.cu
+++ clang/test/Driver/cuda-arch-translation.cu
@@ -5,26 +5,36 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
-// CHECK:fatbinary
-
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM20 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM20 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_21 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM21 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM21 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_30 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM30 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM30 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_32 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM32 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM32 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_35 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM35 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM35 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_37 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM37 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM37 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_50 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM50 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM50 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_52 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM52 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM52 %s
 // RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_53 %s 2>&1 \
-// RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM53 %s
+// RUN: | FileCheck -check-prefixes=COMMON,SM53 %s
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_60 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=COMMON,SM60 %s
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_61 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=COMMON,SM61 %s
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_62 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=COMMON,SM62 %s
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_70 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=COMMON,SM70 %s
+
+// COMMON: ptxas
+// COMMON-SAME: -m64
+// COMMON: fatbinary
 
 // SM20:--image=profile=sm_20{{.*}}--image=profile=compute_20
 // SM21:--image=profile=sm_21{{.*}}--image=profile=compute_20
@@ -35,3 +45,7 @@
 // SM50:--image=profile=sm_50{{.*}}--image=profile=compute_50
 // SM52:--image=profile=sm_52{{.*}}--image=profile=compute_52

[PATCH] D37442: [C++17] Disallow lambdas in template parameters (PR33696).

2017-09-07 Thread Blitz Rakete via Phabricator via cfe-commits
Rakete updated this revision to Diff 114204.
Rakete added a comment.

Good idea! Updated diff :)


https://reviews.llvm.org/D37442

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseStmt.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/TreeTransform.h
  test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp

Index: test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp
===
--- test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp
+++ test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++17 %s -verify
+
+template struct Nothing {};
+
+void pr33696() {
+Nothing<[]() { return 0; }()> nothing; // expected-error{{a lambda expression cannot appear in this context}}
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -5450,7 +5450,7 @@
   // decltype expressions are not potentially evaluated contexts
   EnterExpressionEvaluationContext Unevaluated(
   SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
-  /*IsDecltype=*/true);
+  Sema::ExpressionType::Decltype);
 
   ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
   if (E.isInvalid())
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6146,7 +6146,7 @@
   if (RD->isInvalidDecl() || RD->isDependentContext())
 return E;
 
-  bool IsDecltype = ExprEvalContexts.back().IsDecltype;
+  bool IsDecltype = ExprEvalContexts.back().Type == ExpressionType::Decltype;
   CXXDestructorDecl *Destructor = IsDecltype ? nullptr : LookupDestructor(RD);
 
   if (Destructor) {
@@ -6229,7 +6229,8 @@
 /// are omitted for the 'topmost' call in the decltype expression. If the
 /// topmost call bound a temporary, strip that temporary off the expression.
 ExprResult Sema::ActOnDecltypeExpression(Expr *E) {
-  assert(ExprEvalContexts.back().IsDecltype && "not in a decltype expression");
+  assert(ExprEvalContexts.back().Type == ExpressionType::Decltype &&
+ "not in a decltype expression");
 
   // C++11 [expr.call]p11:
   //   If a function call is a prvalue of object type,
@@ -6271,7 +6272,7 @@
 TopBind = nullptr;
 
   // Disable the special decltype handling now.
-  ExprEvalContexts.back().IsDecltype = false;
+  ExprEvalContexts.back().Type = ExpressionType::Other;
 
   // In MS mode, don't perform any extra checking of call return types within a
   // decltype expression.
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13355,9 +13355,9 @@
 void
 Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   Decl *LambdaContextDecl,
-  bool IsDecltype) {
+  ExpressionType Type) {
   ExprEvalContexts.emplace_back(NewContext, ExprCleanupObjects.size(), Cleanup,
-LambdaContextDecl, IsDecltype);
+LambdaContextDecl, Type);
   Cleanup.reset();
   if (!MaybeODRUseExprs.empty())
 std::swap(MaybeODRUseExprs, ExprEvalContexts.back().SavedMaybeODRUseExprs);
@@ -13366,9 +13366,9 @@
 void
 Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   ReuseLambdaContextDecl_t,
-  bool IsDecltype) {
+  ExpressionType Type) {
   Decl *ClosureContextDecl = ExprEvalContexts.back().ManglingContextDecl;
-  PushExpressionEvaluationContext(NewContext, ClosureContextDecl, IsDecltype);
+  PushExpressionEvaluationContext(NewContext, ClosureContextDecl, Type);
 }
 
 void Sema::PopExpressionEvaluationContext() {
@@ -13376,7 +13376,8 @@
   unsigned NumTypos = Rec.NumTypos;
 
   if (!Rec.Lambdas.empty()) {
-if (Rec.isUnevaluated() || Rec.isConstantEvaluated()) {
+if (Rec.Type == ExpressionType::TemplateParameter || Rec.isUnevaluated() ||
+(Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus1z)) {
   unsigned D;
   if (Rec.isUnevaluated()) {
 // C++11 [expr.prim.lambda]p2:
@@ -13383,23 +13384,21 @@
 //   A lambda-expression shall not appear in an unevaluated operand
 //   (Clause 5).
 D = diag::err_lambda_unevaluated_operand;
-  } else {
+  } else if (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus1z) {
 // C++1y [expr.const]p2:
 //   A conditional-expression e is a core constant expression unless the
  

[PATCH] D36410: [OpenCL] Handle taking address of block captures

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

In https://reviews.llvm.org/D36410#863508, @yaxunl wrote:

> In https://reviews.llvm.org/D36410#863426, @Anastasia wrote:
>
> > In https://reviews.llvm.org/D36410#863409, @yaxunl wrote:
> >
> > > LGTM as a temporary measure until we have a solution for properly 
> > > emitting blocks as enqueued kernel.
> >
> >
> > Should I start discussion with Khronos on that? What would our preference 
> > be - implicitly `generic` AS for capture addresses?
>
>
> I had a discussion with Brian and we realized that captured variable in 
> global address space is kind of unusual since that means each work item needs 
> to have a different global pointer as the block context argument to the 
> kernel, whereas usually when you set global pointer kernel argument for a 
> kernel, different work items get the same global pointer. However, we cannot 
> totally rule out an implementation of enqueue_kernel like that.
>
> That said, I kind of think the address space of captured variable is 
> implementation dependent, though normally it seems private address space 
> makes more sense.


Would it not be a problem generally though? Because private AS memory won't be 
accessed elsewhere and therefore if the block is enqueued to run on a different 
core or any place with different memory segment it would cause an issue...

> I do not object to open a discussion at khronos to clarify this.

Bug #16398 in case you would like to track it.


Repository:
  rL LLVM

https://reviews.llvm.org/D36410



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


[PATCH] D37308: Interface class with uuid base record

2017-09-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:2377
+/// \brief Tests if the __interface base is public.
+static bool IsBasePublicInterface(const CXXRecordDecl *RD,
+  AccessSpecifier spec) {

This function isn't testing the 'base', it is testing the actual record decl.



Comment at: lib/Sema/SemaDeclCXX.cpp:2391
+
+static bool IsInheritatedBaseUuid(const CXXRecordDecl *RD) {
+  for (unsigned int n = 0; n < RD->getNumBases(); n++) {

This function isn't nearly correct.  IT is only testing the first base (over 
and over, but returns immediately...).



Comment at: lib/Sema/SemaDeclCXX.cpp:2396
+
+return (Base && Base->getName() == "IUnknown" &&
+!strcmp(Base->getAttr()->getSpelling(),"uuid"));

Note that this can go down a number of layers.  You have to ensure that it goes 
multiple layers down.  You may wish to make this recursive, and to use your 
"IsUnknownType" function..


https://reviews.llvm.org/D37308



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


[PATCH] D37576: [CUDA] Added rudimentary support for CUDA-9 and sm_70.

2017-09-07 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added subscribers: hiraditya, sanjoy, jholewinski.

For now CUDA-9 is not included in the list of CUDA versions clang
searches for, so the path to CUDA-9 must be explicitly passed
via --cuda-path=.

On LLVM side NVPTX added sm_70 GPU type which bumps required
PTX version to 6.0, but otherwise is equivalent to sm_62 at the moment.


https://reviews.llvm.org/D37576

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  llvm/lib/Target/NVPTX/NVPTX.td

Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -50,6 +50,8 @@
  "Target SM 6.1">;
 def SM62 : SubtargetFeature<"sm_62", "SmVersion", "62",
  "Target SM 6.2">;
+def SM70 : SubtargetFeature<"sm_70", "SmVersion", "70",
+ "Target SM 7.0">;
 
 def SATOM : SubtargetFeature<"satom", "HasAtomScope", "true",
  "Atomic operations with scope">;
@@ -67,6 +69,8 @@
  "Use PTX version 4.3">;
 def PTX50 : SubtargetFeature<"ptx50", "PTXVersion", "50",
  "Use PTX version 5.0">;
+def PTX60 : SubtargetFeature<"ptx60", "PTXVersion", "60",
+ "Use PTX version 6.0">;
 
 //===--===//
 // NVPTX supported processors.
@@ -87,6 +91,7 @@
 def : Proc<"sm_60", [SM60, PTX50, SATOM]>;
 def : Proc<"sm_61", [SM61, PTX50, SATOM]>;
 def : Proc<"sm_62", [SM62, PTX50, SATOM]>;
+def : Proc<"sm_70", [SM70, PTX60, SATOM]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/lib/Headers/__clang_cuda_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ clang/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -62,7 +62,7 @@
 #include "cuda.h"
 #if !defined(CUDA_VERSION)
 #error "cuda.h did not define CUDA_VERSION"
-#elif CUDA_VERSION < 7000 || CUDA_VERSION > 8000
+#elif CUDA_VERSION < 7000 || CUDA_VERSION > 9000
 #error "Unsupported CUDA version!"
 #endif
 
@@ -86,14 +86,19 @@
 #define __COMMON_FUNCTIONS_H__
 
 #undef __CUDACC__
+#if CUDA_VERSION < 9000
 #define __CUDABE__
+#else
+#define __CUDA_LIBDEVICE__
+#endif
 // Disables definitions of device-side runtime support stubs in
 // cuda_device_runtime_api.h
 #include "driver_types.h"
 #include "host_config.h"
 #include "host_defines.h"
 
 #undef __CUDABE__
+#undef __CUDA_LIBDEVICE__
 #define __CUDACC__
 #include "cuda_runtime.h"
 
@@ -105,7 +110,9 @@
 #define __nvvm_memcpy(s, d, n, a) __builtin_memcpy(s, d, n)
 #define __nvvm_memset(d, c, n, a) __builtin_memset(d, c, n)
 
+#if CUDA_VERSION < 9000
 #include "crt/device_runtime.h"
+#endif
 #include "crt/host_runtime.h"
 // device_runtime.h defines __cxa_* macros that will conflict with
 // cxxabi.h.
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -49,6 +49,8 @@
 return CudaVersion::CUDA_75;
   if (Major == 8 && Minor == 0)
 return CudaVersion::CUDA_80;
+  if (Major == 9 && Minor == 0)
+return CudaVersion::CUDA_90;
   return CudaVersion::UNKNOWN;
 }
 
@@ -112,43 +114,55 @@
   Version = ParseCudaVersionFile((*VersionFile)->getBuffer());
 }
 
-std::error_code EC;
-for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE;
- !EC && LI != LE; LI = LI.increment(EC)) {
-  StringRef FilePath = LI->path();
-  StringRef FileName = llvm::sys::path::filename(FilePath);
-  // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc
-  const StringRef LibDeviceName = "libdevice.";
-  if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc")))
-continue;
-  StringRef GpuArch = FileName.slice(
-  LibDeviceName.size(), FileName.find('.', LibDeviceName.size()));
-  LibDeviceMap[GpuArch] = FilePath.str();
-  // Insert map entries for specifc devices with this compute
-  // capability. NVCC's choice of the libdevice library version is
-  // rather peculiar and depends on the CUDA version.
-  if (GpuArch == "compute_20") {
-LibDeviceMap["sm_20"] = FilePath;
-LibDeviceMap["sm_21"] = FilePath;
-LibDeviceMap["sm_32"] = FilePath;
-  } else if (GpuArch == "compute_30") {
-LibDeviceMap["sm_30"] = FilePath;
-if (Version < CudaVersion::CUDA_80) {
-  LibDeviceMap["sm_50"] = FilePath;
-  LibDeviceMap["sm_52"] = FilePath;
-  LibDeviceMap["sm_53"] = FilePath;
-}
-LibDeviceMap["sm_60"] = FilePath;
-LibDeviceMap["sm_61"] = FilePath;

[PATCH] D37308: Interface class with uuid base record

2017-09-07 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 114201.
zahiraam added a comment.

Just upload a new patch. Please review.


https://reviews.llvm.org/D37308

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/ms-uuid.cpp


Index: test/SemaCXX/ms-uuid.cpp
===
--- test/SemaCXX/ms-uuid.cpp
+++ test/SemaCXX/ms-uuid.cpp
@@ -93,3 +93,28 @@
 [uuid("00A0---C000-0049"),
  uuid("00A0---C000-0049")] class C10;
 }
+
+struct __declspec(uuid("---C000-0046")) IUnknown {};
+__interface ISfFileIOPropertyPage : public IUnknown {};
+
+struct __declspec(uuid("---C000-0045")) IUnknown1 {};
+__interface ISfFileIOPropertyPage1 : public IUnknown1 {};  // expected-error 
{{interface type cannot inherit from}}
+
+struct __declspec(uuid("---C000-0046")) IUnknown2 {};
+struct IPropertyPage2 : public IUnknown2 {};
+__interface ISfFileIOPropertyPage2 : public IPropertyPage2 {}; // 
expected-error {{interface type cannot inherit from}}
+
+struct IPropertyPage3 : public IUnknown {};
+__interface ISfFileIOPropertyPage3 : public IPropertyPage3 {};
+
+
+__interface __declspec(dllimport) ISfFileIOPropertyPage33 : public IUnknown {};
+
+struct __declspec(uuid("---C000-0046")) IUnknown4 {};
+__interface ISfFileIOPropertyPage4 : public IUnknown4 {}; // expected-error 
{{interface type cannot inherit from}}
+
+class __declspec(uuid("---C000-0046")) IUnknown5 {};
+__interface ISfFileIOPropertyPage5 : public IUnknown5 {}; // expected-error 
{{interface type cannot inherit from}}
+
+struct __declspec(dllexport) IUnknown6{};
+__interface foo : public IUnknown6{}; // expected-error {{interface type 
cannot inherit from}}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -2373,6 +2373,32 @@
   return true;
 }
 
+/// \brief Tests if the __interface base is public.
+static bool IsBasePublicInterface(const CXXRecordDecl *RD,
+  AccessSpecifier spec) {
+  return RD->isInterface() && spec == AS_public;
+}
+
+/// \brief Test is base RD is an uuid Unknown type.
+static bool IsUnknownType(const CXXRecordDecl *RD) {
+  return RD->isStruct() && RD->hasAttr() &&
+ RD->getName() == "IUnknown" &&
+ (RD->getAttr())->getGuid() ==
+ "---C000-0046" &&
+ RD->isEmpty();
+}
+
+static bool IsInheritatedBaseUuid(const CXXRecordDecl *RD) {
+  for (unsigned int n = 0; n < RD->getNumBases(); n++) {
+const CXXRecordDecl *Base =
+RD->bases_begin()->getType()->getAsCXXRecordDecl();
+
+return (Base && Base->getName() == "IUnknown" &&
+!strcmp(Base->getAttr()->getSpelling(),"uuid"));
+  }
+  return false;
+}
+
 /// Use small set to collect indirect bases.  As this is only used
 /// locally, there's no need to abstract the small size parameter.
 typedef llvm::SmallPtrSet IndirectBaseSet;
@@ -2450,8 +2476,8 @@
   if (const RecordType *Record = NewBaseType->getAs()) {
 const CXXRecordDecl *RD = cast(Record->getDecl());
 if (Class->isInterface() &&
-  (!RD->isInterface() ||
-   KnownBase->getAccessSpecifier() != AS_public)) {
+!IsBasePublicInterface(RD, KnownBase->getAccessSpecifier()) &&
+!IsUnknownType(RD) && !IsInheritatedBaseUuid(RD)) {
   // The Microsoft extension __interface does not permit bases that
   // are not themselves public interfaces.
   Diag(KnownBase->getLocStart(), diag::err_invalid_base_in_interface)


Index: test/SemaCXX/ms-uuid.cpp
===
--- test/SemaCXX/ms-uuid.cpp
+++ test/SemaCXX/ms-uuid.cpp
@@ -93,3 +93,28 @@
 [uuid("00A0---C000-0049"),
  uuid("00A0---C000-0049")] class C10;
 }
+
+struct __declspec(uuid("---C000-0046")) IUnknown {};
+__interface ISfFileIOPropertyPage : public IUnknown {};
+
+struct __declspec(uuid("---C000-0045")) IUnknown1 {};
+__interface ISfFileIOPropertyPage1 : public IUnknown1 {};  // expected-error {{interface type cannot inherit from}}
+
+struct __declspec(uuid("---C000-0046")) IUnknown2 {};
+struct IPropertyPage2 : public IUnknown2 {};
+__interface ISfFileIOPropertyPage2 : public IPropertyPage2 {}; // expected-error {{interface type cannot inherit from}}
+
+struct IPropertyPage3 : public IUnknown {};
+__interface ISfFileIOPropertyPage3 : public IPropertyPage3 {};
+
+
+__interface __declspec(dllimport) ISfFileIOPropertyPage33 : public IUnknown {};
+
+struct __declspec(uuid("---C000-0046")) IUnknown4 {};
+__interface ISfFileIOPropertyPage4 : public IUnknown4 {}; // expected-error {{interface type 

[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: test/Sema/inline-asm-validate-amdgpu.cl:38
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// 
expected-error {{invalid output constraint '=v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1:2"(ci) : "v3:4"(ai), "v4:5"(bi) : 
);  // expected-error {{invalid output constraint '=v1:2' in asm}}
+

arsenm wrote:
> I don't understand. The backend parsed syntax is v[3:4]. Why should v3:4 be 
> valid? Also in this example you are using a 64-bit input to a 32-bit operand
i.e. this won't parse in the backend and is invalid. The brackets are required


https://reviews.llvm.org/D37568



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


[PATCH] D37150: [clangd] Command line arg to specify compile_commands.json path

2017-09-07 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 114199.
Nebiroth marked 7 inline comments as done.
Nebiroth added a comment.

Modified CompileCommandsDir to only look in the specified path if the value is 
set.
Moved CompileCommandsDir field to DirectoryBasedGlobalCompilationDatabase class.
Minor refactoring.


https://reviews.llvm.org/D37150

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/tool/ClangdMain.cpp

Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -12,7 +12,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Program.h"
-
+#include "llvm/Support/Path.h"
 #include 
 #include 
 #include 
@@ -25,16 +25,36 @@
  llvm::cl::desc("parse on main thread"),
  llvm::cl::init(false), llvm::cl::Hidden);
 
+static llvm::cl::opt
+CompileCommandsDir("compile-commands-dir",
+ llvm::cl::desc("Specify a path to look for compile_commands.json. If path is invalid, clangd will look in the current directory and parent paths of each source file.")); 
+
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
   llvm::raw_ostream  = llvm::outs();
   llvm::raw_ostream  = llvm::errs();
   JSONOutput Out(Outs, Logs);
 
+  // If --CompileCommandsDir arg was invoked, check value and override default path.
+  namespace path = llvm::sys::path;
+
+  if (!llvm::sys::path::is_absolute(CompileCommandsDir))
+  {
+Logs << "Path specified by --compile-commands-dir must be an absolute path. The argument will be ignored.\n";
+CompileCommandsDir = "";
+  }
+
+  if (!llvm::sys::fs::exists(CompileCommandsDir))
+  {
+Logs << "File does not exist. The argument will be ignored.\n";
+CompileCommandsDir = "";
+  }
+
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();
 
-  ClangdLSPServer LSPServer(Out, RunSynchronously);
+  ClangdLSPServer LSPServer(Out, RunSynchronously, CompileCommandsDir);
   LSPServer.run(std::cin);
 }
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -33,9 +33,9 @@
 public:
   virtual ~GlobalCompilationDatabase() = default;
 
-  virtual std::vector
+  virtual std::vector  
   getCompileCommands(PathRef File) = 0;
-
+  
   /// FIXME(ibiryukov): add facilities to track changes to compilation flags of
   /// existing targets.
 };
@@ -45,13 +45,16 @@
 class DirectoryBasedGlobalCompilationDatabase
 : public GlobalCompilationDatabase {
 public:
+  DirectoryBasedGlobalCompilationDatabase(Path NewCompileCommandsDir): CompileCommandsDir(NewCompileCommandsDir){}
   std::vector
   getCompileCommands(PathRef File) override;
 
   void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
+  tooling::CompilationDatabase *tryLoadDatabaseFromPath(PathRef File, std::string );
 
 private:
   tooling::CompilationDatabase *getCompilationDatabase(PathRef File);
+  Path CompileCommandsDir;  
 
   std::mutex Mutex;
   /// Caches compilation databases loaded from directories(keys are
Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -61,37 +61,47 @@
   ExtraFlagsForFile[File] = std::move(ExtraFlags);
 }
 
+tooling::CompilationDatabase * DirectoryBasedGlobalCompilationDatabase::tryLoadDatabaseFromPath(PathRef File, std::string )
+{
+  auto CachedIt = CompilationDatabases.find(File);
+  if (CachedIt != CompilationDatabases.end())
+return (CachedIt->second.get());
+  auto CDB = tooling::CompilationDatabase::loadFromDirectory(File, Error);
+  if (CDB && Error.empty())
+  {
+auto result = CDB.get();
+CompilationDatabases.insert(std::make_pair(File, std::move(CDB)));
+return result;
+  }
+  return nullptr;
+}
+
 tooling::CompilationDatabase *
 DirectoryBasedGlobalCompilationDatabase::getCompilationDatabase(PathRef File) {
   std::lock_guard Lock(Mutex);
-
+  
   namespace path = llvm::sys::path;
-
-  assert((path::is_absolute(File, path::Style::posix) ||
-  path::is_absolute(File, path::Style::windows)) &&
- "path must be absolute");
+  std::string Error;
+  if (!CompileCommandsDir.empty()) {
+File = CompileCommandsDir;
+File = path::parent_path(File);
+auto CDB = tryLoadDatabaseFromPath(File, Error);
+
+if (CDB && Error.empty())
+  return CDB;
+else
+  return nullptr;
+  }
 
   for (auto Path = path::parent_path(File); !Path.empty();
-   Path = path::parent_path(Path)) {
-
-auto CachedIt = 

[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:8592
+  bool BadR = !RType->isIntegerType() || RType->isSignedIntegerType() ||
+  RHS->isKnownToHaveBooleanValue();
+

Please extract a function which computes this for an Expr* and then call it as 
part of the conditions below, e.g.:

  if (op == BO_LT && isNonBooleanUnsignedValue(E->getLHS()) && IsZero(S, 
E->getRHS()))



Comment at: lib/Sema/SemaChecking.cpp:8879
+  if (IsComparisonConstant)
 return AnalyzeImpConvsInComparison(S, E);
   

Part of the purpose of checking for signed comparisons up here is to avoid 
unnecessarily computing ranges for the operands when we aren't going to use 
them.  That's still something we want to avoid.  I think you just need to call 
CheckTrivialUnsignedComparison in this fallback case, at least when the 
comparison is not constant.

You should also rename CheckTrivialUnsignedComparison to something like 
CheckTautologicalComparison.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565



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


[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: test/Sema/inline-asm-validate-amdgpu.cl:38
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// 
expected-error {{invalid output constraint '=v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1:2"(ci) : "v3:4"(ai), "v4:5"(bi) : 
);  // expected-error {{invalid output constraint '=v1:2' in asm}}
+

I don't understand. The backend parsed syntax is v[3:4]. Why should v3:4 be 
valid? Also in this example you are using a 64-bit input to a 32-bit operand


https://reviews.llvm.org/D37568



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


[PATCH] D36410: [OpenCL] Handle taking address of block captures

2017-09-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312728: [OpenCL] Handle taking an address of block captures. 
(authored by stulova).

Changed prior to commit:
  https://reviews.llvm.org/D36410?vs=110015=114197#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36410

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaOpenCL/invalid-block.cl


Index: cfe/trunk/test/SemaOpenCL/invalid-block.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl
@@ -81,3 +81,14 @@
   };
   return;
 }
+
+// Taking address of a capture is not allowed
+int g;
+kernel void f8(int a1) {
+  int a2;
+  void (^bl)(void) = ^(void) {
+ //expected-warning{{expression result unused}}
+ //expected-error{{taking address of a capture is not allowed}}
+ //expected-error{{taking address of a capture is not allowed}}
+  };
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -425,14 +425,6 @@
   assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type");
 
   if (Ty->isFunctionType()) {
-// If we are here, we are not calling a function but taking
-// its address (which is not allowed in OpenCL v1.0 s6.8.a.3).
-if (getLangOpts().OpenCL) {
-  if (Diagnose)
-Diag(E->getExprLoc(), diag::err_opencl_taking_function_address);
-  return ExprError();
-}
-
 if (auto *DRE = dyn_cast(E->IgnoreParenCasts()))
   if (auto *FD = dyn_cast(DRE->getDecl()))
 if (!checkAddressOfFunctionIsAvailable(FD, Diagnose, E->getExprLoc()))
@@ -10869,10 +10861,17 @@
   // Make sure to ignore parentheses in subsequent checks
   Expr *op = OrigOp.get()->IgnoreParens();
 
-  // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
-  if (LangOpts.OpenCL && op->getType()->isFunctionType()) {
-Diag(op->getExprLoc(), diag::err_opencl_taking_function_address);
-return QualType();
+  // In OpenCL captures for blocks called as lambda functions
+  // are located in the private address space. Blocks used in
+  // enqueue_kernel can be located in a different address space
+  // depending on a vendor implementation. Thus preventing
+  // taking an address of the capture to avoid invalid AS casts.
+  if (LangOpts.OpenCL) {
+auto* VarRef = dyn_cast(op);
+if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
+  Diag(op->getExprLoc(), diag::err_opencl_taking_address_capture);
+  return QualType();
+}
   }
 
   if (getLangOpts().C99) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7349,8 +7349,8 @@
 def err_opencl_function_pointer : Error<
   "pointers to functions are not allowed">;
 
-def err_opencl_taking_function_address : Error<
-  "taking address of function is not allowed">;
+def err_opencl_taking_address_capture : Error<
+  "taking address of a capture is not allowed">;
 
 def err_invalid_conversion_between_vector_and_scalar : Error<
   "invalid conversion between vector type %0 and scalar type %1">;


Index: cfe/trunk/test/SemaOpenCL/invalid-block.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl
@@ -81,3 +81,14 @@
   };
   return;
 }
+
+// Taking address of a capture is not allowed
+int g;
+kernel void f8(int a1) {
+  int a2;
+  void (^bl)(void) = ^(void) {
+ //expected-warning{{expression result unused}}
+ //expected-error{{taking address of a capture is not allowed}}
+ //expected-error{{taking address of a capture is not allowed}}
+  };
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -425,14 +425,6 @@
   assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type");
 
   if (Ty->isFunctionType()) {
-// If we are here, we are not calling a function but taking
-// its address (which is not allowed in OpenCL v1.0 s6.8.a.3).
-if (getLangOpts().OpenCL) {
-  if (Diagnose)
-Diag(E->getExprLoc(), diag::err_opencl_taking_function_address);
-  return ExprError();
-}
-
 if (auto *DRE = dyn_cast(E->IgnoreParenCasts()))
   if (auto *FD = dyn_cast(DRE->getDecl()))
 if (!checkAddressOfFunctionIsAvailable(FD, Diagnose, E->getExprLoc()))
@@ -10869,10 +10861,17 @@
   // Make sure to ignore parentheses in subsequent checks
   Expr *op = OrigOp.get()->IgnoreParens();
 
-  // OpenCL v1.0 s6.8.a.3: Pointers to functions are 

r312728 - [OpenCL] Handle taking an address of block captures.

2017-09-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Sep  7 10:00:33 2017
New Revision: 312728

URL: http://llvm.org/viewvc/llvm-project?rev=312728=rev
Log:
[OpenCL] Handle taking an address of block captures.

Block captures can have different physical locations
in memory segments depending on the use case (as a function
call or as a kernel enqueue) and in different vendor
implementations.

Therefore it's unclear how to add address space to capture
addresses uniformly. Currently it has been decided to disallow
taking addresses of captured variables until further
clarifications in the spec.

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaOpenCL/invalid-block.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=312728=312727=312728=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  7 10:00:33 
2017
@@ -7349,8 +7349,8 @@ def err_invalid_conversion_between_vecto
 def err_opencl_function_pointer : Error<
   "pointers to functions are not allowed">;
 
-def err_opencl_taking_function_address : Error<
-  "taking address of function is not allowed">;
+def err_opencl_taking_address_capture : Error<
+  "taking address of a capture is not allowed">;
 
 def err_invalid_conversion_between_vector_and_scalar : Error<
   "invalid conversion between vector type %0 and scalar type %1">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=312728=312727=312728=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep  7 10:00:33 2017
@@ -425,14 +425,6 @@ ExprResult Sema::DefaultFunctionArrayCon
   assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type");
 
   if (Ty->isFunctionType()) {
-// If we are here, we are not calling a function but taking
-// its address (which is not allowed in OpenCL v1.0 s6.8.a.3).
-if (getLangOpts().OpenCL) {
-  if (Diagnose)
-Diag(E->getExprLoc(), diag::err_opencl_taking_function_address);
-  return ExprError();
-}
-
 if (auto *DRE = dyn_cast(E->IgnoreParenCasts()))
   if (auto *FD = dyn_cast(DRE->getDecl()))
 if (!checkAddressOfFunctionIsAvailable(FD, Diagnose, E->getExprLoc()))
@@ -10869,10 +10861,17 @@ QualType Sema::CheckAddressOfOperand(Exp
   // Make sure to ignore parentheses in subsequent checks
   Expr *op = OrigOp.get()->IgnoreParens();
 
-  // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
-  if (LangOpts.OpenCL && op->getType()->isFunctionType()) {
-Diag(op->getExprLoc(), diag::err_opencl_taking_function_address);
-return QualType();
+  // In OpenCL captures for blocks called as lambda functions
+  // are located in the private address space. Blocks used in
+  // enqueue_kernel can be located in a different address space
+  // depending on a vendor implementation. Thus preventing
+  // taking an address of the capture to avoid invalid AS casts.
+  if (LangOpts.OpenCL) {
+auto* VarRef = dyn_cast(op);
+if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
+  Diag(op->getExprLoc(), diag::err_opencl_taking_address_capture);
+  return QualType();
+}
   }
 
   if (getLangOpts().C99) {

Modified: cfe/trunk/test/SemaOpenCL/invalid-block.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-block.cl?rev=312728=312727=312728=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl Thu Sep  7 10:00:33 2017
@@ -81,3 +81,14 @@ kernel void f7() {
   };
   return;
 }
+
+// Taking address of a capture is not allowed
+int g;
+kernel void f8(int a1) {
+  int a2;
+  void (^bl)(void) = ^(void) {
+ //expected-warning{{expression result unused}}
+ //expected-error{{taking address of a capture is not allowed}}
+ //expected-error{{taking address of a capture is not allowed}}
+  };
+}


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


[PATCH] D37562: [X86] Lower _mm[256|512]_[mask[z]]_avg_epu[8|16] intrinsics to native llvm IR

2017-09-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

You need to remove the bultins from include/clang/Basic/BuiltinsX86.def too.


https://reviews.llvm.org/D37562



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


[PATCH] D36354: [clang-tidy] Implement type-based check for `gsl::owner`

2017-09-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

ping


https://reviews.llvm.org/D36354



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


[PATCH] D36423: [libc++] Introsort based sorting function

2017-09-07 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

Ping!


https://reviews.llvm.org/D36423



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


[PATCH] D37548: [CUDA] When compilation fails, print the compilation mode.

2017-09-07 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

Nice.


https://reviews.llvm.org/D37548



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


[PATCH] D36410: [OpenCL] Handle taking address of block captures

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D36410#863426, @Anastasia wrote:

> In https://reviews.llvm.org/D36410#863409, @yaxunl wrote:
>
> > LGTM as a temporary measure until we have a solution for properly emitting 
> > blocks as enqueued kernel.
>
>
> Should I start discussion with Khronos on that? What would our preference be 
> - implicitly `generic` AS for capture addresses?


I had a discussion with Brian and we realized that captured variable in global 
address space is kind of unusual since that means each work item needs to have 
a different global pointer as the block context argument to the kernel, whereas 
usually when you set global pointer kernel argument for a kernel, different 
work items get the same global pointer. However, we cannot totally rule out an 
implementation of enqueue_kernel like that.

That said, I kind of think the address space of captured variable is 
implementation dependent, though normally it seems private address space makes 
more sense.

I do not object to open a discussion at khronos to clarify this.


https://reviews.llvm.org/D36410



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


[PATCH] D35533: [Basic] Update CMakeLists.txt to handle Repo with git

2017-09-07 Thread Don Hinton via Phabricator via cfe-commits
hintonda accepted this revision.
hintonda added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D35533



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


[bindings] add Cursor.linkage

2017-09-07 Thread Masud Rahman via cfe-commits
commit cc52d367ede0f3f306014d0418e18772e0c49dec
Author: Masud Rahman 
Date:   Thu Sep 7 11:39:19 2017 -0400

[bindings] add Cursor.linkage

Add Python bindings for the 'clang_getCursorLinkage', and tests to
validate the functionality.

diff --git a/bindings/python/clang/cindex.py
b/bindings/python/clang/cindex.py
index 4069ab8650..5713ab7f29 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1548,6 +1548,13 @@ class Cursor(Structure):

 return self._loc

+@property
+def linkage(self):
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
 @property
 def extent(self):
 """
@@ -2061,6 +2068,26 @@ RefQualifierKind.NONE = RefQualifierKind(0)
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)

+class LinkageKind(BaseEnumeration):
+"""
+"""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)
+LinkageKind.EXTERNAL = LinkageKind(4)
+
 class Type(Structure):
 """
 The type of an element in the abstract syntax tree.
diff --git a/bindings/python/tests/cindex/test_linkage.py
b/bindings/python/tests/cindex/test_linkage.py
new file mode 100644
index 00..392a0f156c
--- /dev/null
+++ b/bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,31 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, "no_linkage")
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, "internal")
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, "unique_external")
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, "external")
+assert external.linkage == LinkageKind.EXTERNAL
+
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix

2017-09-07 Thread Peter Szecsi via Phabricator via cfe-commits
szepet created this revision.
Herald added subscribers: baloghadamsoftware, whisperity, JDevlieghere.

There is a reported bug on the checker not handling the some APSInt values 
correctly: https://bugs.llvm.org/show_bug.cgi?id=34400

This patch fixes it, however, it shows a false positive. (Added to the test 
cases)
I am not sure if it's a checker or AST problem. The AST dump shows the 
following:

  -BinaryOperator 0x1195b98  'int' '|'
   |-ImplicitCastExpr 0x1195b68  'int' 
   | `-DeclRefExpr 0x1195b18  'enum j 
>::(anonymous at dude.cpp:15:3)' EnumConstant 0x1193b98 'ah' 'enum a, struct c, 0> 
>::(anonymous at dude.cpp:29:3)'
   `-ImplicitCastExpr 0x1195b80  'int' 
 `-DeclRefExpr 0x1195b40  'enum j 
>::(anonymous at dude.cpp:15:3)' EnumConstant 0x1195ad0 'ai' 'enum a, struct c, 0> 
>::(anonymous at dude.cpp:29:3)'

I am not sure if this is right since this belongs to the following code snippet 
(maybe I am just missing something):

  enum { ah = ad::m, ai = ae::m, l = ah | ai };

What do you think?


https://reviews.llvm.org/D37572

Files:
  clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
  test/clang-tidy/misc-suspicious-enum-usage.cpp


Index: test/clang-tidy/misc-suspicious-enum-usage.cpp
===
--- test/clang-tidy/misc-suspicious-enum-usage.cpp
+++ test/clang-tidy/misc-suspicious-enum-usage.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" --
+// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- 
-config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 
0}]}" -- -std=c++11
 
 enum Empty {
 };
@@ -54,7 +54,7 @@
   int emptytest = EmptyVal | B;
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types 
+  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
   if (I | Y)
 return 1;
   // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different 
enum types
@@ -88,3 +88,41 @@
 return 1;
   return 42;
 }
+
+// Bug #34400
+template 
+struct a;
+template 
+struct c;
+template 
+struct e;
+template 
+struct f;
+template 
+struct h {
+  typedef e i;
+};
+template 
+struct j {
+  enum { k = a::l,
+ m };
+};
+template 
+struct e : j {};
+template 
+struct r : h::i {};
+template 
+struct a> {
+  enum { l = q };
+};
+template 
+struct c : r> {};
+template 
+struct a> {
+  enum { ah = ad::m,
+ ai = ae::m,
+ l = ah | ai };
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: enum values are from different 
enum types
+};
+template 
+struct f : e, c, 0>> {};
Index: clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
===
--- clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
+++ clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
@@ -42,7 +42,8 @@
 const auto MinMaxVal = std::minmax_element(
 EnumDec->enumerator_begin(), EnumDec->enumerator_end(),
 [](const EnumConstantDecl *E1, const EnumConstantDecl *E2) {
-  return E1->getInitVal() < E2->getInitVal();
+  return llvm::APSInt::compareValues(E1->getInitVal(),
+ E2->getInitVal()) == -1;
 });
 MinVal = MinMaxVal.first->getInitVal();
 MaxVal = MinMaxVal.second->getInitVal();
@@ -57,7 +58,9 @@
 static bool hasDisjointValueRange(const EnumDecl *Enum1,
   const EnumDecl *Enum2) {
   ValueRange Range1(Enum1), Range2(Enum2);
-  return (Range1.MaxVal < Range2.MinVal) || (Range2.MaxVal < Range1.MinVal);
+  bool Less1 = llvm::APSInt::compareValues(Range1.MaxVal, Range2.MinVal) == -1;
+  bool Less2 = llvm::APSInt::compareValues(Range2.MaxVal, Range1.MinVal) == -1;
+  return Less1 || Less2;
 }
 
 static bool isNonPowerOf2NorNullLiteral(const EnumConstantDecl *EnumConst) {


Index: test/clang-tidy/misc-suspicious-enum-usage.cpp
===
--- test/clang-tidy/misc-suspicious-enum-usage.cpp
+++ test/clang-tidy/misc-suspicious-enum-usage.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- -config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 0}]}" --
+// RUN: %check_clang_tidy %s misc-suspicious-enum-usage %t -- -config="{CheckOptions: [{key: misc-suspicious-enum-usage.StrictMode, value: 0}]}" -- -std=c++11
 
 enum Empty {
 };
@@ -54,7 +54,7 @@
   int emptytest = EmptyVal | B;
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from 

[PATCH] D36410: [OpenCL] Handle taking address of block captures

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

In https://reviews.llvm.org/D36410#863409, @yaxunl wrote:

> LGTM as a temporary measure until we have a solution for properly emitting 
> blocks as enqueued kernel.


Should I start discussion with Khronos on that? What would our preference be - 
implicitly `generic` AS for capture addresses?


https://reviews.llvm.org/D36410



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


[PATCH] D37231: Add half load and store builtins

2017-09-07 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

Yes, sorry overlooked that. :) LGTM! Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D37231



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


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

2017-09-07 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: include/clang/AST/Type.h:332
 
+  bool getImplicitAddressSpaceFlag() const { return Mask & IMask; }
+  void setImplicitAddressSpaceFlag(bool Value) {

Could we add a bit of comment somewhere explaining why we added implicit AS 
flag please.



Comment at: lib/AST/Expr.cpp:3254
+// Only (void*)0 or equivalent are treated as nullptr. If pointee type
+// has non-default address space it is not treated as nullptr.
+bool PointeeHasDefaultAS = false;

Is this comment right wrt to named address spaces. So is `(private void*)0` not 
a `nullptr`?



Comment at: lib/AST/Expr.cpp:3257
+if (Ctx.getLangOpts().OpenCL)
+  PointeeHasDefaultAS =
+  (Ctx.getLangOpts().OpenCLVersion >= 200 &&

Can we now simplify this by checking implicit AS bit instead?



Comment at: lib/Sema/SemaType.cpp:6974
 
+  if (state.getSema().getLangOpts().OpenCL && !hasOpenCLAddressSpace &&
+  type.getAddressSpace() == LangAS::Default &&

I am not very convinced we need to do all this check really... I think since we 
have to live with this code further and maintain it let's try to simplify it a 
bit. This can also help us avoid redundant checks. Perhaps we could even move 
it out in a separate function?

How about some sort of hierarchical check structure like:

| |**CL version?** ||
|<2.0||>=2.0|
|`private`||**Type?**||
||pointer||non-pointer|
||`generic`||**Scope?**||
|||program||function|
|||`global`||**Qualifiers?**|
none||static/extern|
`private`||`global`|




Comment at: lib/Sema/SemaType.cpp:6994
+  // OpenCL v1.2 s6.5:
+  // The generic address space name for arguments to a function in a
+  // program, or local variables of a function is __private. All function

The generic address space -> The default address space


https://reviews.llvm.org/D35082



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


[PATCH] D36410: [OpenCL] Handle taking address of block captures

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM as a temporary measure until we have a solution for properly emitting 
blocks as enqueued kernel.


https://reviews.llvm.org/D36410



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


[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-09-07 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

Another ping.  Is it possible to approve this modification, or alternatively, 
let me know that it won't be approved indefinitely?  I understand that it's a 
controversial change. Thanks!


https://reviews.llvm.org/D34158



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


[PATCH] D31334: [clang-format] Add options for indenting preprocessor directives

2017-09-07 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius abandoned this revision.
curdeius added a comment.

Superseded by https://reviews.llvm.org/rL312125.


https://reviews.llvm.org/D31334



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


r312723 - [clang-format] Add support for C++17 structured bindings.

2017-09-07 Thread Marek Kurdej via cfe-commits
Author: mkurdej
Date: Thu Sep  7 07:28:32 2017
New Revision: 312723

URL: http://llvm.org/viewvc/llvm-project?rev=312723=rev
Log:
[clang-format] Add support for C++17 structured bindings.

Summary:
Before:
```
auto[a, b] = f();
```

After:
```
auto [a, b] = f();
```
or, if SpacesInSquareBrackets is true:
```
auto [ a, b ] = f();
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

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

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=312723=312722=312723=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Thu Sep  7 07:28:32 2017
@@ -84,6 +84,7 @@ namespace format {
   TYPE(RegexLiteral) \
   TYPE(SelectorName) \
   TYPE(StartOfName) \
+  TYPE(StructuredBindingLSquare) \
   TYPE(TemplateCloser) \
   TYPE(TemplateOpener) \
   TYPE(TemplateString) \

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=312723=312722=312723=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Sep  7 07:28:32 2017
@@ -310,6 +310,16 @@ private:
 return false;
   }
 
+  bool isCppStructuredBinding(const FormatToken *Tok) {
+if (!Style.isCpp() || !Tok->is(tok::l_square))
+  return false;
+do {
+  Tok = Tok->getPreviousNonComment();
+} while (Tok && Tok->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
+ tok::ampamp));
+return Tok && Tok->is(tok::kw_auto);
+  }
+
   bool parseSquare() {
 if (!CurrentToken)
   return false;
@@ -344,7 +354,9 @@ private:
 
 unsigned BindingIncrease = 1;
 if (Left->is(TT_Unknown)) {
-  if (StartsObjCMethodExpr) {
+  if (isCppStructuredBinding(Left)) {
+Left->Type = TT_StructuredBindingLSquare;
+  } else if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
   } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
  Contexts.back().ContextKind == tok::l_brace &&
@@ -2261,17 +2273,20 @@ bool TokenAnnotator::spaceRequiredBetwee
   if (Left.is(tok::l_square))
 return (Left.is(TT_ArrayInitializerLSquare) &&
 Style.SpacesInContainerLiterals && Right.isNot(tok::r_square)) ||
-   (Left.is(TT_ArraySubscriptLSquare) && Style.SpacesInSquareBrackets 
&&
-Right.isNot(tok::r_square));
+   (Left.isOneOf(TT_ArraySubscriptLSquare,
+ TT_StructuredBindingLSquare) &&
+Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
   if (Right.is(tok::r_square))
 return Right.MatchingParen &&
((Style.SpacesInContainerLiterals &&
  Right.MatchingParen->is(TT_ArrayInitializerLSquare)) ||
 (Style.SpacesInSquareBrackets &&
- Right.MatchingParen->is(TT_ArraySubscriptLSquare)));
+ Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
+  TT_StructuredBindingLSquare)));
   if (Right.is(tok::l_square) &&
   !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
- TT_DesignatedInitializerLSquare) &&
+ TT_DesignatedInitializerLSquare,
+ TT_StructuredBindingLSquare) &&
   !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
 return false;
   if (Left.is(tok::l_brace) && Right.is(tok::r_brace))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=312723=312722=312723=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Sep  7 07:28:32 2017
@@ -11452,6 +11452,31 @@ TEST_F(FormatTest, DoNotFormatLikelyXml)
 format(" ", getGoogleStyle()));
 }
 
+TEST_F(FormatTest, StructuredBindings) {
+  // Structured bindings is a C++17 feature.
+  // all modes, including C++11, C++14 and C++17
+  verifyFormat("auto [a, b] = f();");
+  EXPECT_EQ("auto [a, b] = f();", format("auto[a, b] = f();"));
+  EXPECT_EQ("const auto [a, b] = f();", format("const   auto[a, b] = f();"));
+  EXPECT_EQ("auto const [a, b] = f();", format("auto  const[a, b] = f();"));
+  EXPECT_EQ("auto const volatile [a, b] = f();",
+format("auto  const   volatile[a, b] = f();"));
+  EXPECT_EQ("auto [a, b, c] = f();", format("auto   [  a  ,  b,c   ] = f();"));
+  EXPECT_EQ("auto & [a, b, c] = f();",
+

[PATCH] D37568: [AMDGPU] Allow flexible register names in inline asm constraints

2017-09-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added subscribers: eraman, t-tye, tpr, dstuttard, nhaehnle, wdng, 
kzhuravl.

Currently AMDGPU inline asm only allow "v" and "s" as register names in 
constraints.

This patch allows the following register names in constraints: (n, m is 
unsigned integer, n < m)

v

s

{vn}

{sn}

{S} , wheere S is a special register name

{vn:m}

{sn:m}


https://reviews.llvm.org/D37568

Files:
  lib/Basic/Targets/AMDGPU.h
  test/CodeGenOpenCL/amdgcn-inline-asm.cl
  test/Sema/inline-asm-validate-amdgpu.cl

Index: test/Sema/inline-asm-validate-amdgpu.cl
===
--- test/Sema/inline-asm-validate-amdgpu.cl
+++ test/Sema/inline-asm-validate-amdgpu.cl
@@ -1,6 +1,5 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -x cl -triple amdgcn -fsyntax-only  %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -triple amdgcn -fsyntax-only -verify %s
 
 kernel void test () {
 
@@ -12,3 +11,33 @@
   // vgpr constraints
   __asm__ ("v_mov_b32 %0, %1" : "=v" (vgpr) : "v" (imm) : );
 }
+
+__kernel void
+ker(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : ""(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "="(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '=' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1a}"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}a"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={v1}a' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={exec}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "={exec}a"(ci) : "{v2}"(ai), "{v3}"(bi) : ); // expected-error {{invalid output constraint '={exec}a' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1:2}"(ci) : "{v3:4}"(ai), "{v4:5}"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "=v{1:2}"(ci) : "{v3:4}"(ai), "{v4:5}"(bi) : ); //expected-error {{invalid output constraint '=v{1:2}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1:2}a"(ci) : "{v3:4}"(ai), "{v4:5}"(bi) : ); //expected-error {{invalid output constraint '={v1:2}a' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "=v"(ci) : "v"(ai), "v"(bi) : );
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1"(ci) : "v2"(ai), "v3"(bi) : ); /// expected-error {{invalid output constraint '=v1' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "=v1:2"(ci) : "v3:4"(ai), "v4:5"(bi) : );  // expected-error {{invalid output constraint '=v1:2' in asm}}
+
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{a}"(ai), "{v3}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{a}"(bi) : ); // expected-error {{invalid input constraint '{a}' in asm}}
+c[i] = ci;
+}
Index: test/CodeGenOpenCL/amdgcn-inline-asm.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgcn-inline-asm.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn -O0 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @ker
+__kernel void
+ker(const __global float *a, const __global float *b, __global float *c, unsigned i)
+{
+float ai = a[i];
+float bi = b[i];
+float ci;
+// CHECK: call float asm "v_add_f32_e32 v1, v2, v3", "={v1},{v2},{v3}"(float %{{.*}}, float %{{.*}})
+__asm("v_add_f32_e32 v1, v2, v3" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+// CHECK: call float asm "v_add_f32_e32 $0, $1, $2", "={v1},{v2},{v3}"(float %{{.*}}, float %{{.*}})
+__asm("v_add_f32_e32 %0, %1, %2" : "={v1}"(ci) : "{v2}"(ai), "{v3}"(bi) : );
+c[i] = ci;
+}
Index: lib/Basic/Targets/AMDGPU.h
===
--- lib/Basic/Targets/AMDGPU.h
+++ lib/Basic/Targets/AMDGPU.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Compiler.h"
 
@@ -115,17 +116,70 @@
 return None;
   }
 
+  /// Accepted register names: (n, m is unsigned integer, n < m)
+  /// v
+  /// s
+  /// {vn}
+  /// {sn}
+  /// {S} , wheere S is a special register name
+  {vn:m}
+  /// {sn:m}
   bool validateAsmConstraint(const char *,
  TargetInfo::ConstraintInfo ) const override {
-switch (*Name) {
-default:
-  

[PATCH] D37513: [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-07 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.

Submitted as r312721. Thank you.


https://reviews.llvm.org/D37513



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


r312721 - [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-07 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Sep  7 06:45:41 2017
New Revision: 312721

URL: http://llvm.org/viewvc/llvm-project?rev=312721=rev
Log:
[clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

The current description of AllowAllParametersOfDeclarationOnNextLine in
the Clang-Format Style Options guide suggests that it is possible to
format function declaration, which fits in a single line (what is not
supported in current clang-format version). Also the example was not
reproducible and mades no sense.

Patch by Lucja Mazur, thank you!

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=312721=312720=312721=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Sep  7 06:45:41 2017
@@ -271,15 +271,22 @@ the configuration (without a prefix: ``A
 int b = 2; // comment  bint b = 2; // comment about b
 
 **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
-  Allow putting all parameters of a function declaration onto
+  If the function declaration doesn't fit on a line,
+  allow putting all parameters of a function declaration onto
   the next line even if ``BinPackParameters`` is ``false``.
 
   .. code-block:: c++
 
-true:   false:
-myFunction(foo, vs. myFunction(foo, bar, plop);
-   bar,
-   plop);
+true:
+void myFunction(
+int a, int b, int c, int d, int e);
+
+false:
+void myFunction(int a,
+int b,
+int c,
+int d,
+int e);
 
 **AllowShortBlocksOnASingleLine** (``bool``)
   Allows contracting simple braced statements to a single line.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=312721=312720=312721=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Sep  7 06:45:41 2017
@@ -151,13 +151,20 @@ struct FormatStyle {
   /// \endcode
   bool AlignTrailingComments;
 
-  /// \brief Allow putting all parameters of a function declaration onto
+  /// \brief If the function declaration doesn't fit on a line,
+  /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
   /// \code
-  ///   true:   false:
-  ///   myFunction(foo, vs. myFunction(foo, bar, plop);
-  ///  bar,
-  ///  plop);
+  ///   true:
+  ///   void myFunction(
+  ///   int a, int b, int c, int d, int e);
+  ///
+  ///   false:
+  ///   void myFunction(int a,
+  ///   int b,
+  ///   int c,
+  ///   int d,
+  ///   int e);
   /// \endcode
   bool AllowAllParametersOfDeclarationOnNextLine;
 


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


[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 114172.
lebedev.ri added a comment.

Added ReleaseNotes.rst note


Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-constant-compare.c

Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -6,6 +6,59 @@
 int main()
 {
 int a = value();
+
+if (a == 0xL)
+return 0;
+if (a != 0xL)
+return 0;
+if (a < 0xL)
+return 0;
+if (a <= 0xL)
+return 0;
+if (a > 0xL)
+return 0;
+if (a >= 0xL)
+return 0;
+
+if (0xL == a)
+return 0;
+if (0xL != a)
+return 0;
+if (0xL < a)
+return 0;
+if (0xL <= a)
+return 0;
+if (0xL > a)
+return 0;
+if (0xL >= a)
+return 0;
+
+if (a == 0xUL)
+return 0;
+if (a != 0xUL)
+return 0;
+if (a < 0xUL)
+return 0;
+if (a <= 0xUL)
+return 0;
+if (a > 0xUL)
+return 0;
+if (a >= 0xUL)
+return 0;
+
+if (0xUL == a)
+return 0;
+if (0xUL != a)
+return 0;
+if (0xUL < a)
+return 0;
+if (0xUL <= a)
+return 0;
+if (0xUL > a)
+return 0;
+if (0xUL >= a)
+return 0;
+
 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
 return 0;
 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
@@ -74,6 +127,7 @@
 return 0;
 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
 return 0;
+
 long l = value();
 if (l == 0x1234567812345678L)
 return 0;
@@ -106,34 +160,107 @@
 return 0;
 if (un != 0xL)
 return 0;
-if (un < 0xL)
+if (un < 0xL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
 return 0;
 if (un <= 0xL)
 return 0;
 if (un > 0xL)
 return 0;
-if (un >= 0xL)
+if (un >= 0xL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
 return 0;
 
 if (0xL == un)
 return 0;
 if (0xL != un)
 return 0;
 if (0xL < un)
 return 0;
-if (0xL <= un)
+if (0xL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
 return 0;
-if (0xL > un)
+if (0xL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
 return 0;
 if (0xL >= un)
 return 0;
-float fl = 0;
-if (fl == 0xL) // no warning
-  return 0;
 
-float dl = 0;
-if (dl == 0xL) // no warning
-  return 0;
+if (un == 0xUL)
+return 0;
+if (un != 0xUL)
+return 0;
+if (un < 0xUL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (un <= 0xUL)
+return 0;
+if (un > 0xUL)
+return 0;
+if (un >= 0xUL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+
+if (0xUL == un)
+return 0;
+if (0xUL != un)
+return 0;
+if (0xUL < un)
+return 0;
+if (0xUL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+return 0;
+if (0xUL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
+return 0;
+if (0xUL >= un)
+return 0;
+
+float fl = 0;
+if (fl == 0xL)
+return 0;
+if (fl != 0xL)
+return 0;
+if (fl < 0xL)
+return 0;
+if (fl <= 0xL)
+return 0;
+if (fl > 0xL)
+return 0;
+if (fl 

[PATCH] D37132: [clang-format] Add support for C++17 structured bindings.

2017-09-07 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. Sorry for the delay.


https://reviews.llvm.org/D37132



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


[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-07 Thread Cameron via Phabricator via cfe-commits
cameron314 added a comment.

> Maybe there's a third option option to remove the BOM from the buffer before 
> passing it to clang?
>  Could you elaborate on your use-case a little more? Is there no way to 
> consistently always pass buffers either with or without BOM?
>  Out of two options you mention discarding preamble on BOM changes seems like 
> an easy option that is both correct and won't make a difference in 
> performance since BOM rarely changes.
>  Looking at your use-case, it sounds like you'll only have 1 extra reparse of 
> preamble, which is probably fine.

In my particular use case, when the file is remapped by the IDE, there's never 
a BOM. But when it's not remapped, the real file may or may not have a BOM. 
Since the file goes back and forth between mapped and unmapped depending on 
whether it's saved, the BOM presence can change quite frequently, and we don't 
really have control over it (the BOM can change on disk too). This is a common 
use case for anyone integrating clang/libclang into an IDE; the rarity of UTF-8 
BOMs on platforms other than Windows probably obscured this until now.

I think since we can handle the changing BOM presence in the preamble 
gracefully, we should. I'll draft a patch that does the slicing correctly so 
that the offsets are always valid.

> Sure, it's not something clang supports, it's an edge-case when clang 
> receives "malformed" input. Does lexer only skip utf-8 BOM, but not other 
> versions of BOM?
>  But you're right, it's highly unlikely anything will break in that case.

Ah, I see. Yes, the lexer only skips a UTF-8 BOM, but I seem to recall seeing 
some code that detects BOMs in other encodings and emits an error (in the 
driver, possibly?).




Comment at: unittests/Frontend/PchPreambleTest.cpp:190
+
+  ASSERT_TRUE(ReparseAST(AST));
+  ASSERT_FALSE(AST->getDiagnostics().hasErrorOccurred());

ilya-biryukov wrote:
> cameron314 wrote:
> > ilya-biryukov wrote:
> > > We're not really testing that preamble was reused.
> > > Maybe return a flag from `ASTUnit::Reparse` to indicate if preamble was 
> > > reused and check it here?
> > We are; if it wasn't reused, the header would have been opened again and 
> > the last assert on `GetFileReadCount` below would fail.
> Missed that, thanks. Looks good.
> Maybe add a comment explicitly noting that?
Sure, will do.


https://reviews.llvm.org/D37491



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


[PATCH] D37474: [PCH] Allow VFS to be used for tests that generate PCH files

2017-09-07 Thread Cameron via Phabricator via cfe-commits
cameron314 added a comment.

Looking at the way remapped buffers are handled, I just remembered that they 
must exist on the file system (at the very least, in a directory that exists) 
or the remapping is not taken into account. So that pretty much rules out the 
other approach, I think.


https://reviews.llvm.org/D37474



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


[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value

2017-09-07 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: JDevlieghere.

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

**Problem:**

Clang-tidy check misc-unused-parameters omits parameter default value what 
results in its complete removal. Compilation errors might occur after 
clang-tidy fix.

**Patch description:**

Changed removal range. The range should end after parameter declarator, not 
after whole parameter declaration (which might contain a default value).


https://reviews.llvm.org/D37566

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused 
[misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,10 @@
 // CHECK-FIXES: staticFunctionC(2);
   staticFunctionD(1, 2, 3);
 // CHECK-FIXES: staticFunctionD(1, 3);
-  staticFunctionE();
+  staticFunctionE(1);
+// CHECK-FIXES: staticFunctionE();
+  staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();
 }
 
 /*
@@ -95,6 +104,9 @@
   static void f(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void f(int  /*i*/) {}
+  static void g(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void g(int  /*i*/ = 1) {}
 };
 
 namespace {
@@ -108,6 +120,9 @@
   void h(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void h(int  /*i*/) {}
+  void s(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void s(int  /*i*/ = 1) {}
 };
 
 void C::f(int i) {}
@@ -125,6 +140,7 @@
 // CHECK-FIXES: c.g();
 
   useFunction(::h);
+  useFunction(::s);
 }
 
 class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,7 +138,8 @@
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
+SourceRange RemovalRange(Param->getLocation(),
+ Param->DeclaratorDecl::getSourceRange().getEnd());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format 
will
 // clean this up afterwards.


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,10 @@
 // 

[PATCH] D37565: [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.

2017-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added a project: clang.

This is a first half(?) of a fix for the following bug:
https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)

GCC's -Wtype-limits does warn on comparison of unsigned value
with signed zero (as in, with 0), but clang only warns if the
zero is unsigned (i.e. 0U).

Also, be careful not to double-warn, or falsely warn on
comparison of signed/fp variable and signed 0.

Yes, all these testcases are needed.

Testing: $ ninja check-clang-sema check-clang-semacxx
Also, no new warnings for clang stage-2 build.


Repository:
  rL LLVM

https://reviews.llvm.org/D37565

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-constant-compare.c

Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -6,6 +6,59 @@
 int main()
 {
 int a = value();
+
+if (a == 0xL)
+return 0;
+if (a != 0xL)
+return 0;
+if (a < 0xL)
+return 0;
+if (a <= 0xL)
+return 0;
+if (a > 0xL)
+return 0;
+if (a >= 0xL)
+return 0;
+
+if (0xL == a)
+return 0;
+if (0xL != a)
+return 0;
+if (0xL < a)
+return 0;
+if (0xL <= a)
+return 0;
+if (0xL > a)
+return 0;
+if (0xL >= a)
+return 0;
+
+if (a == 0xUL)
+return 0;
+if (a != 0xUL)
+return 0;
+if (a < 0xUL)
+return 0;
+if (a <= 0xUL)
+return 0;
+if (a > 0xUL)
+return 0;
+if (a >= 0xUL)
+return 0;
+
+if (0xUL == a)
+return 0;
+if (0xUL != a)
+return 0;
+if (0xUL < a)
+return 0;
+if (0xUL <= a)
+return 0;
+if (0xUL > a)
+return 0;
+if (0xUL >= a)
+return 0;
+
 if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}}
 return 0;
 if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}}
@@ -74,6 +127,7 @@
 return 0;
 if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}}
 return 0;
+
 long l = value();
 if (l == 0x1234567812345678L)
 return 0;
@@ -106,34 +160,107 @@
 return 0;
 if (un != 0xL)
 return 0;
-if (un < 0xL)
+if (un < 0xL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
 return 0;
 if (un <= 0xL)
 return 0;
 if (un > 0xL)
 return 0;
-if (un >= 0xL)
+if (un >= 0xL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
 return 0;
 
 if (0xL == un)
 return 0;
 if (0xL != un)
 return 0;
 if (0xL < un)
 return 0;
-if (0xL <= un)
+if (0xL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
 return 0;
-if (0xL > un)
+if (0xL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
 return 0;
 if (0xL >= un)
 return 0;
-float fl = 0;
-if (fl == 0xL) // no warning
-  return 0;
 
-float dl = 0;
-if (dl == 0xL) // no warning
-  return 0;
+if (un == 0xUL)
+return 0;
+if (un != 0xUL)
+return 0;
+if (un < 0xUL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
+return 0;
+if (un <= 0xUL)
+return 0;
+if (un > 0xUL)
+return 0;
+if (un >= 0xUL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
+return 0;
+
+if (0xUL == un)
+return 0;
+if (0xUL != un)
+return 0;
+if (0xUL < un)
+return 0;
+if (0xUL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
+return 0;
+if (0xUL > un) // 

[PATCH] D37513: [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-07 Thread Lucja Mazur via Phabricator via cfe-commits
LuMa added a comment.

I cannot commit the patch myself.


https://reviews.llvm.org/D37513



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


[PATCH] D37513: [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-07 Thread Lucja Mazur via Phabricator via cfe-commits
LuMa updated this revision to Diff 114161.

https://reviews.llvm.org/D37513

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h


Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -151,13 +151,20 @@
   /// \endcode
   bool AlignTrailingComments;
 
-  /// \brief Allow putting all parameters of a function declaration onto
+  /// \brief If the function declaration doesn't fit on a line,
+  /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
   /// \code
-  ///   true:   false:
-  ///   myFunction(foo, vs. myFunction(foo, bar, plop);
-  ///  bar,
-  ///  plop);
+  ///   true:
+  ///   void myFunction(
+  ///   int a, int b, int c, int d, int e);
+  ///   
+  ///   false:
+  ///   void myFunction(int a,
+  ///   int b,
+  ///   int c,
+  ///   int d,
+  ///   int e);
   /// \endcode
   bool AllowAllParametersOfDeclarationOnNextLine;
 
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -271,15 +271,22 @@
 int b = 2; // comment  bint b = 2; // comment about b
 
 **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
-  Allow putting all parameters of a function declaration onto
+  If the function declaration doesn't fit on a line,
+  allow putting all parameters of a function declaration onto
   the next line even if ``BinPackParameters`` is ``false``.
 
   .. code-block:: c++
 
-true:   false:
-myFunction(foo, vs. myFunction(foo, bar, plop);
-   bar,
-   plop);
+true:
+void myFunction(
+int a, int b, int c, int d, int e);
+
+false:
+void myFunction(int a,
+int b,
+int c,
+int d,
+int e);
 
 **AllowShortBlocksOnASingleLine** (``bool``)
   Allows contracting simple braced statements to a single line.


Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -151,13 +151,20 @@
   /// \endcode
   bool AlignTrailingComments;
 
-  /// \brief Allow putting all parameters of a function declaration onto
+  /// \brief If the function declaration doesn't fit on a line,
+  /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
   /// \code
-  ///   true:   false:
-  ///   myFunction(foo, vs. myFunction(foo, bar, plop);
-  ///  bar,
-  ///  plop);
+  ///   true:
+  ///   void myFunction(
+  ///   int a, int b, int c, int d, int e);
+  ///   
+  ///   false:
+  ///   void myFunction(int a,
+  ///   int b,
+  ///   int c,
+  ///   int d,
+  ///   int e);
   /// \endcode
   bool AllowAllParametersOfDeclarationOnNextLine;
 
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -271,15 +271,22 @@
 int b = 2; // comment  bint b = 2; // comment about b
 
 **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
-  Allow putting all parameters of a function declaration onto
+  If the function declaration doesn't fit on a line,
+  allow putting all parameters of a function declaration onto
   the next line even if ``BinPackParameters`` is ``false``.
 
   .. code-block:: c++
 
-true:   false:
-myFunction(foo, vs. myFunction(foo, bar, plop);
-   bar,
-   plop);
+true:
+void myFunction(
+int a, int b, int c, int d, int e);
+
+false:
+void myFunction(int a,
+int b,
+int c,
+int d,
+int e);
 
 **AllowShortBlocksOnASingleLine** (``bool``)
   Allows contracting simple braced statements to a single line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28148: [Sema] Suppress warnings for C's zero initializer

2017-09-07 Thread S. Gilles via Phabricator via cfe-commits
sgilles added a comment.

Sure, if it still applies. I'm just a user and have no write access.  Looks 
like I patched this locally and then forgot all about it.


https://reviews.llvm.org/D28148



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


[PATCH] D35533: [Basic] Update CMakeLists.txt to handle Repo with git

2017-09-07 Thread MinSeong Kim via Phabricator via cfe-commits
minseong.kim updated this revision to Diff 114160.
minseong.kim marked 3 inline comments as done.
minseong.kim added a comment.

Re-uploading the patch, removing debug messages accidentally included in the 
patch.


https://reviews.llvm.org/D35533

Files:
  lib/Basic/CMakeLists.txt


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -4,39 +4,6 @@
   Support
   )
 
-# Figure out if we can track VC revisions.
-function(find_first_existing_file out_var)
-  foreach(file ${ARGN})
-if(EXISTS "${file}")
-  set(${out_var} "${file}" PARENT_SCOPE)
-  return()
-endif()
-  endforeach()
-endfunction()
-
-macro(find_first_existing_vc_file out_var path)
-  set(git_path "${path}/.git")
-
-  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
-  # is updated as modifications are made to the repository. In case the
-  # repository is a Git submodule, '.git' is a file that contains text that
-  # indicates where the repository's Git directory exists.
-  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
-FILE(READ "${git_path}" file_contents)
-if("${file_contents}" MATCHES "^gitdir: ([^\n]+)")
-  # '.git' is indeed a link to the submodule's Git directory.
-  # Use the path to that Git directory.
-  set(git_path "${path}/${CMAKE_MATCH_1}")
-endif()
-  endif()
-
-  find_first_existing_file(${out_var}
-"${git_path}/logs/HEAD"  # Git or Git submodule
-"${path}/.svn/wc.db" # SVN 1.7
-"${path}/.svn/entries"   # SVN 1.6
-)
-endmacro()
-
 find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
 find_first_existing_vc_file(clang_vc "${CLANG_SOURCE_DIR}")
 


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -4,39 +4,6 @@
   Support
   )
 
-# Figure out if we can track VC revisions.
-function(find_first_existing_file out_var)
-  foreach(file ${ARGN})
-if(EXISTS "${file}")
-  set(${out_var} "${file}" PARENT_SCOPE)
-  return()
-endif()
-  endforeach()
-endfunction()
-
-macro(find_first_existing_vc_file out_var path)
-  set(git_path "${path}/.git")
-
-  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
-  # is updated as modifications are made to the repository. In case the
-  # repository is a Git submodule, '.git' is a file that contains text that
-  # indicates where the repository's Git directory exists.
-  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
-FILE(READ "${git_path}" file_contents)
-if("${file_contents}" MATCHES "^gitdir: ([^\n]+)")
-  # '.git' is indeed a link to the submodule's Git directory.
-  # Use the path to that Git directory.
-  set(git_path "${path}/${CMAKE_MATCH_1}")
-endif()
-  endif()
-
-  find_first_existing_file(${out_var}
-"${git_path}/logs/HEAD"  # Git or Git submodule
-"${path}/.svn/wc.db" # SVN 1.7
-"${path}/.svn/entries"   # SVN 1.6
-)
-endmacro()
-
 find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
 find_first_existing_vc_file(clang_vc "${CLANG_SOURCE_DIR}")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r312717 - Add an usage example of BreakBeforeBraces

2017-09-07 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Thu Sep  7 05:09:14 2017
New Revision: 312717

URL: http://llvm.org/viewvc/llvm-project?rev=312717=rev
Log:
Add an usage example of BreakBeforeBraces

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=312717=312716=312717=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Sep  7 05:09:14 2017
@@ -533,6 +533,15 @@ the configuration (without a prefix: ``A
   If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
   each individual brace case should be handled. Otherwise, this is ignored.
 
+  .. code-block:: yaml
+
+# Example of usage:
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterEnum: true
+  AfterStruct: false
+  SplitEmptyFunction: false
+
   Nested configuration flags:
 
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=312717=312716=312717=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Sep  7 05:09:14 2017
@@ -746,6 +746,14 @@ struct FormatStyle {
   ///
   /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
   /// each individual brace case should be handled. Otherwise, this is ignored.
+  /// \code{.yaml}
+  ///   # Example of usage:
+  ///   BreakBeforeBraces: Custom
+  ///   BraceWrapping:
+  /// AfterEnum: true
+  /// AfterStruct: false
+  /// SplitEmptyFunction: false
+  /// \endcode
   BraceWrappingFlags BraceWrapping;
 
   /// \brief If ``true``, ternary operators will be placed after line breaks.


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


r312716 - Refresh the clang format options doc with the recent changes

2017-09-07 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Thu Sep  7 05:08:49 2017
New Revision: 312716

URL: http://llvm.org/viewvc/llvm-project?rev=312716=rev
Log:
Refresh the clang format options doc with the recent changes

Summary:
Looks like we are out of sync between the doc and the code.


Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=312716=312715=312716=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Sep  7 05:08:49 2017
@@ -679,7 +679,7 @@ the configuration (without a prefix: ``A
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
-  * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be 
put on a single line.
+  * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
 set, and the function could/should not be put on a single line (as per
@@ -691,6 +691,28 @@ the configuration (without a prefix: ``A
   {}  {
   }
 
+  * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct 
or union) body
+can be put on a single line. This option is used only if the opening
+brace of the record has already been wrapped, i.e. the `AfterClass`
+(for classes) brace wrapping mode is set.
+
+.. code-block:: c++
+
+  class Foo   vs.  class Foo
+  {}   {
+   }
+
+  * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put 
on a single line.
+This option is used only if the opening brace of the namespace has
+already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
+set.
+
+.. code-block:: c++
+
+  namespace Foo   vs.  namespace Foo
+  {}   {
+   }
+
 
 **BreakAfterJavaFieldAnnotations** (``bool``)
   Break after each annotation on a field in Java files.
@@ -1144,7 +1166,7 @@ the configuration (without a prefix: ``A
 IncludeCategories:
   - Regex:   '^"(llvm|llvm-c|clang|clang-c)/'
 Priority:2
-  - Regex:   '^(<|"(gtest|isl|json)/)'
+  - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
 Priority:3
   - Regex:   '.*'
 Priority:1
@@ -1180,7 +1202,7 @@ the configuration (without a prefix: ``A
  }  }
 
 **IndentPPDirectives** (``PPDirectiveIndentStyle``)
-  Indent preprocessor directives on conditionals.
+  The preprocessor directive indenting style to use.
 
   Possible values:
 
@@ -1189,22 +1211,24 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-  #if FOO
-  #if BAR
-  #include 
-  #endif
-  #endif
+   #if FOO
+   #if BAR
+   #include 
+   #endif
+   #endif
 
   * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
 Indents directives after the hash.
 
 .. code-block:: c++
 
-  #if FOO
-  #  if BAR
-  #include 
-  #  endif
-  #endif
+   #if FOO
+   #  if BAR
+   #include 
+   #  endif
+   #endif
+
+
 
 **IndentWidth** (``unsigned``)
   The number of columns to use for indentation.
@@ -1318,6 +1342,10 @@ the configuration (without a prefix: ``A
   * ``LK_TableGen`` (in configuration: ``TableGen``)
 Should be used for TableGen code.
 
+  * ``LK_TextProto`` (in configuration: ``TextProto``)
+Should be used for Protocol Buffer messages in text format
+(https://developers.google.com/protocol-buffers/).
+
 
 
 **MacroBlockBegin** (``std::string``)


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


  1   2   >