[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-16 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In the following patch I have modified Include categories by adding a new field 
"sortInlcudes" which defines the priority of the sort. And priority field will 
now only be used for grouping.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



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


[PATCH] D64799: [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU

2019-07-16 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/test/SemaObjC/typo-correction-subscript.m:1
 // RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only 
-Wno-objc-root-class %s -verify -disable-free
 

I think you can even remove `-disable-free` in this test. It was there to avoid 
the assertion in `~Sema` (see D60848).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64799/new/

https://reviews.llvm.org/D64799



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


[PATCH] D64843: hwasan: Initialize the pass only once.

2019-07-16 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
pcc added a reviewer: eugenis.
Herald added subscribers: cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

This will let us instrument globals during initialization. This required
making the new PM pass a module pass, which should still provide access to
analyses via the ModuleAnalysisManager.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64843

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/test/Instrumentation/HWAddressSanitizer/basic.ll

Index: llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
===
--- llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
+++ llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
@@ -6,10 +6,10 @@
 ; RUN: opt < %s -hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
 
 ; Ensure than hwasan runs with the new PM pass
-; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-DYNAMIC-SHADOW
-; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-DYNAMIC-SHADOW
-; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
-; RUN: opt < %s -passes='function(hwasan)' -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
+; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-DYNAMIC-SHADOW
+; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-with-ifunc=1 -hwasan-with-tls=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-DYNAMIC-SHADOW
+; RUN: opt < %s -passes=hwasan -hwasan-recover=0 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT,ABORT-ZERO-BASED-SHADOW
+; RUN: opt < %s -passes=hwasan -hwasan-recover=1 -hwasan-mapping-offset=0 -S | FileCheck %s --check-prefixes=CHECK,RECOVER,RECOVER-ZERO-BASED-SHADOW
 
 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @hwasan.module_ctor, i8* bitcast (void ()* @hwasan.module_ctor to i8*) }]
 
Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -277,12 +277,22 @@
 
   StringRef getPassName() const override { return "HWAddressSanitizer"; }
 
+  bool doInitialization(Module ) override {
+HWASan = llvm::make_unique(M, CompileKernel, Recover);
+return true;
+  }
+
   bool runOnFunction(Function ) override {
-HWAddressSanitizer HWASan(*F.getParent(), CompileKernel, Recover);
-return HWASan.sanitizeFunction(F);
+return HWASan->sanitizeFunction(F);
+  }
+
+  bool doFinalization(Module ) override {
+HWASan.reset();
+return false;
   }
 
 private:
+  std::unique_ptr HWASan;
   bool CompileKernel;
   bool Recover;
 };
@@ -309,10 +319,13 @@
 HWAddressSanitizerPass::HWAddressSanitizerPass(bool CompileKernel, bool Recover)
 : CompileKernel(CompileKernel), Recover(Recover) {}
 
-PreservedAnalyses HWAddressSanitizerPass::run(Function ,
-  FunctionAnalysisManager ) {
-  HWAddressSanitizer HWASan(*F.getParent(), CompileKernel, Recover);
-  if (HWASan.sanitizeFunction(F))
+PreservedAnalyses HWAddressSanitizerPass::run(Module ,
+  ModuleAnalysisManager ) {
+  HWAddressSanitizer HWASan(M, CompileKernel, Recover);
+  bool Modified = false;
+  for (Function  : M)
+Modified |= HWASan.sanitizeFunction(F);
+  if (Modified)
 return PreservedAnalyses::none();
   return PreservedAnalyses::all();
 }
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -55,6 +55,8 @@
 MODULE_PASS("globalopt", GlobalOptPass())
 MODULE_PASS("globalsplit", GlobalSplitPass())
 MODULE_PASS("hotcoldsplit", HotColdSplittingPass())
+MODULE_PASS("hwasan", HWAddressSanitizerPass(false, false))
+MODULE_PASS("khwasan", HWAddressSanitizerPass(true, true))
 MODULE_PASS("inferattrs", InferFunctionAttrsPass())
 MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
 MODULE_PASS("instrorderfile", InstrOrderFilePass())
@@ -240,8 +242,6 @@
 FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
 FUNCTION_PASS("asan", 

[PATCH] D64842: [OPENMP] Fix crash in LoopCounterRefChecker when MemberExpr is not Var or Field

2019-07-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64842/new/

https://reviews.llvm.org/D64842



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


[PATCH] D64842: [OPENMP] Fix crash in LoopCounterRefChecker when MemberExpr is not Var or Field

2019-07-16 Thread Mike Rice via Phabricator via cfe-commits
mikerice created this revision.
mikerice added reviewers: ABataev, cfe-commits.
Herald added a subscriber: guansong.

checkDecl is only valid for VarDecls or FieldDecls, since getCanonicalDecl 
expects only these.  Prevent other Decl kinds (such as CXXMethodDecls and 
EnumConstantDecls) from entering and asserting.


https://reviews.llvm.org/D64842

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/for_loop_messages.cpp


Index: clang/test/OpenMP/for_loop_messages.cpp
===
--- clang/test/OpenMP/for_loop_messages.cpp
+++ clang/test/OpenMP/for_loop_messages.cpp
@@ -626,6 +626,8 @@
 class TC {
   int ii, iii, kk;
 public:
+  enum { myconstant = 42 };
+  int ub();
   int dotest_lt(IT begin, IT end) {
 #pragma omp parallel
 // expected-error@+3 3 {{the loop initializer expression depends on the 
current loop control variable}}
@@ -634,6 +636,12 @@
   for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
 ;
 
+// Check that member function calls and enum constants in the condition is
+// handled.
+#pragma omp for
+  for (ii = 0; ii < ub() + this->myconstant; ii += 1) // expected-no-error
+;
+
 #pragma omp parallel
 // expected-error@+4 2 {{expected loop invariant expression or ' * 
ii + ' kind of expression}}
 // expected-error@+3 {{expected loop invariant expression or ' * 
TC::ii + ' kind of expression}}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4992,7 +4992,8 @@
   bool VisitMemberExpr(const MemberExpr *E) {
 if (isa(E->getBase()->IgnoreParens())) {
   const ValueDecl *VD = E->getMemberDecl();
-  return checkDecl(E, VD);
+  if (isa(VD) || isa(VD))
+return checkDecl(E, VD);
 }
 return false;
   }


Index: clang/test/OpenMP/for_loop_messages.cpp
===
--- clang/test/OpenMP/for_loop_messages.cpp
+++ clang/test/OpenMP/for_loop_messages.cpp
@@ -626,6 +626,8 @@
 class TC {
   int ii, iii, kk;
 public:
+  enum { myconstant = 42 };
+  int ub();
   int dotest_lt(IT begin, IT end) {
 #pragma omp parallel
 // expected-error@+3 3 {{the loop initializer expression depends on the current loop control variable}}
@@ -634,6 +636,12 @@
   for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
 ;
 
+// Check that member function calls and enum constants in the condition is
+// handled.
+#pragma omp for
+  for (ii = 0; ii < ub() + this->myconstant; ii += 1) // expected-no-error
+;
+
 #pragma omp parallel
 // expected-error@+4 2 {{expected loop invariant expression or ' * ii + ' kind of expression}}
 // expected-error@+3 {{expected loop invariant expression or ' * TC::ii + ' kind of expression}}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -4992,7 +4992,8 @@
   bool VisitMemberExpr(const MemberExpr *E) {
 if (isa(E->getBase()->IgnoreParens())) {
   const ValueDecl *VD = E->getMemberDecl();
-  return checkDecl(E, VD);
+  if (isa(VD) || isa(VD))
+return checkDecl(E, VD);
 }
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum added a comment.

In D64537#1588699 , @dschuff wrote:

> I had a reply that got eaten here, so I'm going to keep trolling you on your 
> CL since we don't have a design doc for this.
>  The `offset` field of a data segment initializer can be a `global.get` on an 
> imported global.  
> (https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions).
>  Since each thread is separately instantiated with separate JS, we could have 
> a global import like `__tls_base` which has a different value in each thread. 
> Then we wouldn't need to manually call the init code anywhere. Would there be 
> other advantages or disadvantages for that?


I already answered this one:

In D64537#1586614 , @quantum wrote:

> In D64537#1586556 , @dschuff wrote:
>
> > The `offset` field of a segment can be a constant expression 
> > 
> >  which can be a `global.get` of an imported global. So we could have an 
> > imported global `__tls_base` which is different for each thread, and have 
> > an active segment with that as its segment offset?
>
>
> I didn't know that it could have been a constant expression. I don't think 
> this would have worked very well on the main thread though, since we need to 
> run `malloc` before we can compute `__tls_base`. I think this requires the 
> global to be mutable, if only because we need to be able to initialize it on 
> the main thread.


The problem I found with the import approach is that the main thread cannot use 
`global.get` of an imported global to get the location of TLS, mainly because 
it needs to be `malloc`'d. To use `malloc`, the main thread needs to be 
initialized. This will result in a circular dependency.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



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


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

I had a reply that got eaten here, so I'm going to keep trolling you on your CL 
since we don't have a design doc for this.
The `offset` field of a data segment initializer can be a `global.get` on an 
imported global.  
(https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions).
 Since each thread is separately instantiated with separate JS, we could have a 
global import like `__tls_base` which has a different value in each thread. 
Then we wouldn't need to manually call the init code anywhere. Would there be 
other advantages or disadvantages for that?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:104
+
+  if (isNullStmtWithAttributes()) {
+MaybeParseGNUAttributes(Attrs);

If we're going to generally support statement attributes, it should be possible 
to apply them to non-null statements.  (Even if there aren't any valid 
attributes right now, that's likely to change in the future.)  Or is that not 
possible to implement for some reason?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838



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


[PATCH] D64828: AMDGPU: Add some missing builtins

2019-07-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r366286


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64828/new/

https://reviews.llvm.org/D64828



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


r366286 - AMDGPU: Add some missing builtins

2019-07-16 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Tue Jul 16 17:01:03 2019
New Revision: 366286

URL: http://llvm.org/viewvc/llvm-project?rev=366286=rev
Log:
AMDGPU: Add some missing builtins

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

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=366286=366285=366286=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Tue Jul 16 17:01:03 2019
@@ -108,6 +108,16 @@ BUILTIN(__builtin_amdgcn_ds_fminf, "ff*3
 BUILTIN(__builtin_amdgcn_ds_fmaxf, "ff*3fIiIiIb", "n")
 BUILTIN(__builtin_amdgcn_ds_append, "ii*3", "n")
 BUILTIN(__builtin_amdgcn_ds_consume, "ii*3", "n")
+BUILTIN(__builtin_amdgcn_alignbit, "UiUiUiUi", "nc")
+BUILTIN(__builtin_amdgcn_alignbyte, "UiUiUiUi", "nc")
+BUILTIN(__builtin_amdgcn_ubfe, "UiUiUiUi", "nc")
+BUILTIN(__builtin_amdgcn_sbfe, "UiUiUiUi", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pkrtz, "E2hff", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pknorm_i16, "E2sff", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pknorm_u16, "E2Usff", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pk_i16, "E2sii", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pk_u16, "E2UsUiUi", "nc")
+BUILTIN(__builtin_amdgcn_cvt_pk_u8_f32, "UifUiUi", "nc")
 
 
//===--===//
 // CI+ only builtins.
@@ -163,6 +173,13 @@ TARGET_BUILTIN(__builtin_amdgcn_sdot8, "
 TARGET_BUILTIN(__builtin_amdgcn_udot8, "UiUiUiUiIb", "nc", "dot2-insts")
 
 
//===--===//
+// GFX10+ only builtins.
+//===--===//
+TARGET_BUILTIN(__builtin_amdgcn_permlane16, "UiUiUiUiUiIbIb", "nc", 
"gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_permlanex16, "UiUiUiUiUiIbIb", "nc", 
"gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mov_dpp8, "UiUiIUi", "nc", "gfx10-insts")
+
+//===--===//
 // Special builtins.
 
//===--===//
 BUILTIN(__builtin_amdgcn_read_exec, "LUi", "nc")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=366286=366285=366286=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Jul 16 17:01:03 2019
@@ -12679,6 +12679,8 @@ Value *CodeGenFunction::EmitAMDGPUBuilti
 
   case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
 return emitBinaryBuiltin(*this, E, Intrinsic::amdgcn_ds_swizzle);
+  case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
+return emitBinaryBuiltin(*this, E, Intrinsic::amdgcn_mov_dpp8);
   case AMDGPU::BI__builtin_amdgcn_mov_dpp:
   case AMDGPU::BI__builtin_amdgcn_update_dpp: {
 llvm::SmallVector Args;
@@ -12744,6 +12746,10 @@ Value *CodeGenFunction::EmitAMDGPUBuilti
 return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_fract);
   case AMDGPU::BI__builtin_amdgcn_lerp:
 return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_lerp);
+  case AMDGPU::BI__builtin_amdgcn_ubfe:
+return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_ubfe);
+  case AMDGPU::BI__builtin_amdgcn_sbfe:
+return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_sbfe);
   case AMDGPU::BI__builtin_amdgcn_uicmp:
   case AMDGPU::BI__builtin_amdgcn_uicmpl:
   case AMDGPU::BI__builtin_amdgcn_sicmp:

Added: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl?rev=366286=auto
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl Tue Jul 16 17:01:03 
2019
@@ -0,0 +1,24 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1010 -S 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1011 -S 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1012 -S 
-emit-llvm -o - %s | FileCheck %s
+
+typedef unsigned int uint;
+
+// CHECK-LABEL: @test_permlane16(
+// CHECK: call i32 @llvm.amdgcn.permlane16(i32 %a, i32 %b, i32 %c, i32 %d, i1 
true, i1 true)
+void test_permlane16(global uint* out, uint a, uint b, uint c, uint d) {
+  *out = 

[PATCH] D41412: [libcxx] implement concat() and split()

2019-07-16 Thread Tim Shen via Phabricator via cfe-commits
timshen added a comment.

In D41412#1586966 , @grosser wrote:

> Hi @timshen,
>
> I am very interested in these patches. Any chance you can take up the 
> upstreaming process again?


I'm glad to spend time upstreaming these patches. Now we just need a libc++ 
maintainer to take on the reviews. I'll try to contact mclow, but I'm not sure 
how exactly to reach Marshall.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D41412/new/

https://reviews.llvm.org/D41412



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:2146
+bool Parser::isNullStmtWithAttributes() {
+  RevertingTentativeParsingAction PA(*this);
+  return TryParseNullStmtWithAttributes() == TPResult::True;

Is this “cheap” in terms of compile time?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Thanks, I think this is fine solution for now.

Probably not ideal (@aaron.ballman mentioned the ideal solution - rewrite the 
parser),  but “suboptimal” parser should not stop any progress in this area.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838



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


r366284 - Fix OpenCLCXX test on 32-bit Windows where thiscall is present

2019-07-16 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul 16 16:44:33 2019
New Revision: 366284

URL: http://llvm.org/viewvc/llvm-project?rev=366284=rev
Log:
Fix OpenCLCXX test on 32-bit Windows where thiscall is present

Modified:
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=366284=366283=366284=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Tue Jul 16 16:44:33 
2019
@@ -30,8 +30,8 @@ struct c2 {
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &) __generic'
-//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &) __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
 return *this;
@@ -41,8 +41,8 @@ struct x1 {
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *) __generic'
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *) __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} 
__generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *){{( 
__attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
   }
@@ -57,9 +57,9 @@ void bar(__global x1 *xx, __global
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
   x3(const x3 );
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 ) {}


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


r366282 - Fix darwin-ld.c if dsymutil.exe exists on PATH

2019-07-16 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jul 16 16:38:05 2019
New Revision: 366282

URL: http://llvm.org/viewvc/llvm-project?rev=366282=rev
Log:
Fix darwin-ld.c if dsymutil.exe exists on PATH

Modified:
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/test/Driver/darwin-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=366282=366281=366282=diff
==
--- cfe/trunk/test/Driver/darwin-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-ld.c Tue Jul 16 16:38:05 2019
@@ -5,9 +5,9 @@
 
 // Make sure we run dsymutil on source input files.
 // RUN: %clang -target i386-apple-darwin9 -### -g %s -o BAR 2> %t.log
-// RUN: grep '".*dsymutil" "-o" "BAR.dSYM" "BAR"' %t.log
+// RUN: grep '".*dsymutil\(.exe\)\?" "-o" "BAR.dSYM" "BAR"' %t.log
 // RUN: %clang -target i386-apple-darwin9 -### -g -filelist FOO %s -o BAR 2> 
%t.log
-// RUN: grep '".*dsymutil" "-o" "BAR.dSYM" "BAR"' %t.log
+// RUN: grep '".*dsymutil\(.exe\)\?" "-o" "BAR.dSYM" "BAR"' %t.log
 
 // Check linker changes that came with new linkedit format.
 // RUN: touch %t.o


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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-16 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 210218.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695

Files:
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp

Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,18 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  break;
+}
+else{
+  Ret = 0;
+}
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -452,7 +452,8 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
-IO.mapOptional("BitFieldDeclarationsOnePerLine", Style.BitFieldDeclarationsOnePerLine);
+IO.mapOptional("BitFieldDeclarationsOnePerLine",
+   Style.BitFieldDeclarationsOnePerLine);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
@@ -609,8 +610,8 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
-false, false, true,  true,  true};
+false, false, false, false, false, false,
+false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -688,8 +689,8 @@
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
   LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
- false, false, false, false, false,
- false, false, true,  true,  true};
+ false, false, false, false, false, false,
+ false, true,  true,  true};
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
@@ -1023,6 +1024,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 1, 0},
+  {"^", 1, 1},
+  {"^", 9, 11},
+  {"^\"\w.*\.h\"$", 10, 12}};
+  NetBSDStyle.SortIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1081,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1774,8 +1810,9 @@
 static void sortCppIncludes(const FormatStyle ,
 const SmallVectorImpl ,
 

[PATCH] D64828: AMDGPU: Add some missing builtins

2019-07-16 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec accepted this revision.
rampitec added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64828/new/

https://reviews.llvm.org/D64828



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:2131
+  ParseGNUAttributes(attrs, nullptr, nullptr);
+  if (attrs.size() <= 0) {
+return TPResult::False;

Negative size() ?

Did you mean “== 0”? Not sure if “empty()”  exists there..



Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:1280
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();
 // Skip empty cases.

Make it unconditional (see my patch)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838



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


[PATCH] D64828: AMDGPU: Add some missing builtins

2019-07-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 210216.
arsenm added a comment.

Drop one and fix missing test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64828/new/

https://reviews.llvm.org/D64828

Files:
  include/clang/Basic/BuiltinsAMDGPU.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl
  test/CodeGenOpenCL/builtins-amdgcn.cl
  test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
  test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl

Index: test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl
===
--- /dev/null
+++ test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl
@@ -0,0 +1,15 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu tahiti -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu hawaii -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu fiji -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx900 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx908 -verify -S -o - %s
+
+typedef unsigned int uint;
+
+
+void test(global uint* out, uint a, uint b, uint c, uint d) {
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, 1, 1); // expected-error {{'__builtin_amdgcn_permlane16' needs target feature gfx10-insts}}
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, 1, 1);  // expected-error {{'__builtin_amdgcn_permlanex16' needs target feature gfx10-insts}}
+  *out = __builtin_amdgcn_mov_dpp8(a, 1);  // expected-error {{'__builtin_amdgcn_mov_dpp8' needs target feature gfx10-insts}}
+}
Index: test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
===
--- /dev/null
+++ test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -verify -S -o - %s
+
+typedef unsigned int uint;
+
+
+void test_permlane16(global uint* out, uint a, uint b, uint c, uint d, uint e) {
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, e, 1); // expected-error{{argument to '__builtin_amdgcn_permlane16' must be a constant integer}}
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, 1, e); // expected-error{{argument to '__builtin_amdgcn_permlane16' must be a constant integer}}
+}
+
+void test_permlanex16(global uint* out, uint a, uint b, uint c, uint d, uint e) {
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, e, 1); // expected-error{{argument to '__builtin_amdgcn_permlanex16' must be a constant integer}}
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, 1, e); // expected-error{{argument to '__builtin_amdgcn_permlanex16' must be a constant integer}}
+}
+
+void test_mov_dpp8(global uint* out, uint a, uint b) {
+  *out = __builtin_amdgcn_mov_dpp8(a, b); // expected-error{{argument to '__builtin_amdgcn_mov_dpp8' must be a constant integer}}
+}
Index: test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn.cl
+++ test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -5,6 +5,10 @@
 
 typedef unsigned long ulong;
 typedef unsigned int uint;
+typedef unsigned short ushort;
+typedef half __attribute__((ext_vector_type(2))) half2;
+typedef short __attribute__((ext_vector_type(2))) short2;
+typedef ushort __attribute__((ext_vector_type(2))) ushort2;
 
 // CHECK-LABEL: @test_div_scale_f64
 // CHECK: call { double, i1 } @llvm.amdgcn.div.scale.f64(double %a, double %b, i1 true)
@@ -590,6 +594,66 @@
   *out = __builtin_amdgcn_mbcnt_hi(src0, src1);
 }
 
+// CHECK-LABEL: @test_alignbit(
+// CHECK: tail call i32 @llvm.amdgcn.alignbit(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_alignbit(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_alignbit(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_alignbyte(
+// CHECK: tail call i32 @llvm.amdgcn.alignbyte(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_alignbyte(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_alignbyte(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_ubfe(
+// CHECK: tail call i32 @llvm.amdgcn.ubfe.i32(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_ubfe(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_ubfe(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_sbfe(
+// CHECK: tail call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_sbfe(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_sbfe(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_cvt_pkrtz(
+// CHECK: tail call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %src0, float %src1)
+kernel void test_cvt_pkrtz(global half2* out, float src0, float src1) {
+  *out = __builtin_amdgcn_cvt_pkrtz(src0, src1);
+}
+
+// CHECK-LABEL: @test_cvt_pknorm_i16(
+// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pknorm.i16(float %src0, float %src1)
+kernel void test_cvt_pknorm_i16(global short2* out, float src0, float 

[PATCH] D64274: [analyzer] VirtualCallChecker overhaul.

2019-07-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D64274#1584974 , 
@baloghadamsoftware wrote:

> Hmm, I still fail to understand the problem with the current `VirtualCall` 
> checker. Is it unstable? Does it report many false positives?


Yeah, pretty much. It's basically defined to find non-bugs and so far i've seen 
no indication that a lot of them are actually bugs, but it's rather the 
opposite, and it's rather noisy. It defines a good practice to follow ("if you 
truly want to call a virtual function and you understand that no virtual 
dispatch will happen, add an explicit qualifier"), but i feel uncomfy to force 
this recommendation upon people by default. That's still a good check but 
that's not a kind of thing that people ask for when they're using the analyzer. 
Btw, this check could probably benefit from a fixit hint (which adds the 
missing qualifier).

When the function is pure virtual, it's an immediate UB, so it's something we 
can always warn about.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64274/new/

https://reviews.llvm.org/D64274



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry added a comment.

Revival of https://reviews.llvm.org/D63260 and https://reviews.llvm.org/D63299.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838



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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry updated this revision to Diff 210215.
Nathan-Huckleberry added a comment.

- Fixed formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64838/new/

https://reviews.llvm.org/D64838

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Sema/fallthrough-attr.c
  clang/test/SemaCXX/switch-implicit-fallthrough.cpp

Index: clang/test/SemaCXX/switch-implicit-fallthrough.cpp
===
--- clang/test/SemaCXX/switch-implicit-fallthrough.cpp
+++ clang/test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -329,3 +329,15 @@
   }
   return n;
 }
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+__attribute__((fallthrough));
+  case 1:
+n++;
+break;
+  }
+  return n;
+}
Index: clang/test/Sema/fallthrough-attr.c
===
--- /dev/null
+++ clang/test/Sema/fallthrough-attr.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -std=gnu89 -verify -Wimplicit-fallthrough %s
+
+int foo(int x) {
+  int a = 0;
+
+  switch (x) {
+  case 0:
+a++;
+  case 1:
+// expected-warning@-1{{unannotated fall-through between switch labels}}
+//expected-note@-2{{insert 'break;' to avoid fall-through}}
+a--;
+  case 2:
+// expected-warning@-1{{unannotated fall-through between switch labels}}
+// expected-note@-2{{insert 'break;' to avoid fall-through}}
+break;
+  default:
+a = 1;
+  }
+
+  return 0;
+}
+
+int bar(int x) {
+  int a = 0;
+
+  switch (x) {
+  case 0:
+a++;
+__attribute__((fallthrough));
+  case 1:
+a--;
+__attribute__((fallthrough));
+  case 2:
+break;
+  default:
+a = 1;
+  }
+
+  return 0;
+}
+
+__attribute__((fallthrough)); // expected-warning {{declaration does not declare anything}}
+void baz(int x) {
+  __attribute__((fallthrough)); // expected-error {{fallthrough annotation is outside switch statement}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1215,7 +1215,7 @@
 tok::r_square, tok::r_square
   };
 
-  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17;
+  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17 && !PP.getLangOpts().C2x;
 
   StringRef MacroName;
   if (PreferClangAttr)
@@ -1224,24 +1224,19 @@
 MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens);
   if (MacroName.empty() && !PreferClangAttr)
 MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens);
-  if (MacroName.empty())
-MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]";
+  if (MacroName.empty()) {
+if (!PreferClangAttr)
+  MacroName = "[[fallthrough]]";
+else if (PP.getLangOpts().CPlusPlus)
+  MacroName = "[[clang::fallthrough]]";
+else
+  MacroName = "__attribute__((fallthrough))";
+  }
   return MacroName;
 }
 
 static void DiagnoseSwitchLabelsFallthrough(Sema , AnalysisDeclContext ,
 bool PerFunction) {
-  // Only perform this analysis when using [[]] attributes. There is no good
-  // workflow for this warning when not using C++11. There is no good way to
-  // silence the warning (no attribute is available) unless we are using
-  // [[]] attributes. One could use pragmas to silence the warning, but as a
-  // general solution that is gross and not in the spirit of this warning.
-  //
-  // NOTE: This an intermediate solution. There are on-going discussions on
-  // how to properly support this warning outside of C++11 with an annotation.
-  if (!AC.getASTContext().getLangOpts().DoubleSquareBracketAttributes)
-return;
-
   FallthroughMapper FM(S);
   FM.TraverseStmt(AC.getBody());
 
@@ -1281,7 +1276,7 @@
   SourceLocation L = Label->getBeginLoc();
   if (L.isMacroID())
 continue;
-  if (S.getLangOpts().CPlusPlus11) {
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();
 // Skip empty cases.
 while (B->empty() && !Term && B->succ_size() == 1) {
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -2121,3 +2121,28 @@
 return TPResult::Ambiguous;
   return TPResult::False;
 }
+
+Parser::TPResult Parser::TryParseNullStmtWithAttributes() {
+  if (Tok.isNot(tok::kw___attribute)) {
+return TPResult::False;
+  }
+  ParsedAttributesWithRange attrs(AttrFactory);
+  ParseGNUAttributes(attrs, nullptr, nullptr);
+  if (attrs.size() <= 0) {
+return TPResult::False;
+  }
+  for (auto  : 

[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-16 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed extraneous matches of non-NullStmt


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64838

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Sema/fallthrough-attr.c
  clang/test/SemaCXX/switch-implicit-fallthrough.cpp

Index: clang/test/SemaCXX/switch-implicit-fallthrough.cpp
===
--- clang/test/SemaCXX/switch-implicit-fallthrough.cpp
+++ clang/test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -329,3 +329,15 @@
   }
   return n;
 }
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+__attribute__ ((fallthrough));
+  case 1:
+n++;
+break;
+  }
+  return n;
+}
Index: clang/test/Sema/fallthrough-attr.c
===
--- /dev/null
+++ clang/test/Sema/fallthrough-attr.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -std=gnu89 -verify -Wimplicit-fallthrough %s
+
+int foo(int x)
+{
+int a = 0;
+
+switch (x) {
+case 0:
+  a++;
+case 1:
+  // expected-warning@-1{{unannotated fall-through between switch labels}}
+  //expected-note@-2{{insert 'break;' to avoid fall-through}}
+  a--;
+case 2:
+  // expected-warning@-1{{unannotated fall-through between switch labels}}
+  // expected-note@-2{{insert 'break;' to avoid fall-through}}
+break;
+default:
+a = 1;
+}
+
+return 0;
+}
+
+int bar(int x)
+{
+int a = 0;
+
+switch (x) {
+case 0:
+  a++;
+  __attribute__ ((fallthrough));
+case 1:
+  a--;
+  __attribute__ ((fallthrough));
+case 2:
+break;
+default:
+a = 1;
+}
+
+return 0;
+}
+
+__attribute__ ((fallthrough)); // expected-warning {{declaration does not declare anything}}
+void baz(int x) {
+  __attribute__ ((fallthrough)); // expected-error {{fallthrough annotation is outside switch statement}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1215,7 +1215,7 @@
 tok::r_square, tok::r_square
   };
 
-  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17;
+  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17 && !PP.getLangOpts().C2x;
 
   StringRef MacroName;
   if (PreferClangAttr)
@@ -1224,24 +1224,19 @@
 MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens);
   if (MacroName.empty() && !PreferClangAttr)
 MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens);
-  if (MacroName.empty())
-MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]";
+  if (MacroName.empty()) {
+if (!PreferClangAttr)
+  MacroName = "[[fallthrough]]";
+else if (PP.getLangOpts().CPlusPlus)
+  MacroName = "[[clang::fallthrough]]";
+else
+  MacroName = "__attribute__((fallthrough))";
+  }
   return MacroName;
 }
 
 static void DiagnoseSwitchLabelsFallthrough(Sema , AnalysisDeclContext ,
 bool PerFunction) {
-  // Only perform this analysis when using [[]] attributes. There is no good
-  // workflow for this warning when not using C++11. There is no good way to
-  // silence the warning (no attribute is available) unless we are using
-  // [[]] attributes. One could use pragmas to silence the warning, but as a
-  // general solution that is gross and not in the spirit of this warning.
-  //
-  // NOTE: This an intermediate solution. There are on-going discussions on
-  // how to properly support this warning outside of C++11 with an annotation.
-  if (!AC.getASTContext().getLangOpts().DoubleSquareBracketAttributes)
-return;
-
   FallthroughMapper FM(S);
   FM.TraverseStmt(AC.getBody());
 
@@ -1281,7 +1276,7 @@
   SourceLocation L = Label->getBeginLoc();
   if (L.isMacroID())
 continue;
-  if (S.getLangOpts().CPlusPlus11) {
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();
 // Skip empty cases.
 while (B->empty() && !Term && B->succ_size() == 1) {
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -2121,3 +2121,28 @@
 return TPResult::Ambiguous;
   return TPResult::False;
 }
+
+Parser::TPResult Parser::TryParseNullStmtWithAttributes() {
+  if(Tok.isNot(tok::kw___attribute)) {
+return TPResult::False;
+  

[PATCH] D64799: [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU

2019-07-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'm in favor of this as is. We should loop in and get confirmation from @rsmith 
though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64799/new/

https://reviews.llvm.org/D64799



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


r366276 - Fix a typo in target features

2019-07-16 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Jul 16 15:32:17 2019
New Revision: 366276

URL: http://llvm.org/viewvc/llvm-project?rev=366276=rev
Log:
Fix a typo in target features

There was a slight typo in r364352 that ended up causing our backend to
complain on some x86 Android builds. This CL fixes that.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/X86.cpp
cfe/trunk/test/Driver/clang-translation.c

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/X86.cpp?rev=366276=366275=366276=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/X86.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/X86.cpp Tue Jul 16 15:32:17 2019
@@ -135,7 +135,7 @@ void x86::getX86TargetFeatures(const Dri
 if (ArchType == llvm::Triple::x86_64) {
   Features.push_back("+sse4.2");
   Features.push_back("+popcnt");
-  Features.push_back("+mcx16");
+  Features.push_back("+cx16");
 } else
   Features.push_back("+ssse3");
   }

Modified: cfe/trunk/test/Driver/clang-translation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-translation.c?rev=366276=366275=366276=diff
==
--- cfe/trunk/test/Driver/clang-translation.c (original)
+++ cfe/trunk/test/Driver/clang-translation.c Tue Jul 16 15:32:17 2019
@@ -318,7 +318,7 @@
 // ANDROID-X86_64: "-target-cpu" "x86-64"
 // ANDROID-X86_64: "-target-feature" "+sse4.2"
 // ANDROID-X86_64: "-target-feature" "+popcnt"
-// ANDROID-X86_64: "-target-feature" "+mcx16"
+// ANDROID-X86_64: "-target-feature" "+cx16"
 
 // RUN: %clang -target mips-linux-gnu -### -S %s 2>&1 | \
 // RUN: FileCheck -check-prefix=MIPS %s


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


[PATCH] D64491: [Driver] Enable __cxa_atexit on Solaris

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

lgtm


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64491/new/

https://reviews.llvm.org/D64491



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


[PATCH] D64828: AMDGPU: Add some missing builtins

2019-07-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: rampitec, yaxunl, kzhuravl, b-sumner.
Herald added subscribers: t-tye, tpr, dstuttard, nhaehnle, wdng, jvesely.

https://reviews.llvm.org/D64828

Files:
  include/clang/Basic/BuiltinsAMDGPU.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl
  test/CodeGenOpenCL/builtins-amdgcn.cl
  test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
  test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl

Index: test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl
===
--- /dev/null
+++ test/SemaOpenCL/builtins-amdgcn-error-gfx10.cl
@@ -0,0 +1,15 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu tahiti -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu hawaii -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu fiji -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx900 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx908 -verify -S -o - %s
+
+typedef unsigned int uint;
+
+
+void test(global uint* out, uint a, uint b, uint c, uint d) {
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, 1, 1); // expected-error {{'__builtin_amdgcn_permlane16' needs target feature gfx10-insts}}
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, 1, 1);  // expected-error {{'__builtin_amdgcn_permlanex16' needs target feature gfx10-insts}}
+  *out = __builtin_amdgcn_s_get_waveid_in_workgroup(); // expected-error {{'__builtin_amdgcn_s_get_waveid_in_workgroup' needs target feature gfx10-insts}}
+}
Index: test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
===
--- /dev/null
+++ test/SemaOpenCL/builtins-amdgcn-error-gfx10-param.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -verify -S -o - %s
+
+typedef unsigned int uint;
+
+
+void test_permlane16(global uint* out, uint a, uint b, uint c, uint d, uint e) {
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, e, 1); // expected-error{{argument to '__builtin_amdgcn_permlane16' must be a constant integer}}
+  *out = __builtin_amdgcn_permlane16(a, b, c, d, 1, e); // expected-error{{argument to '__builtin_amdgcn_permlane16' must be a constant integer}}
+}
+
+void test_permlanex16(global uint* out, uint a, uint b, uint c, uint d, uint e) {
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, e, 1); // expected-error{{argument to '__builtin_amdgcn_permlanex16' must be a constant integer}}
+  *out = __builtin_amdgcn_permlanex16(a, b, c, d, 1, e); // expected-error{{argument to '__builtin_amdgcn_permlanex16' must be a constant integer}}
+}
+
+void test_mov_dpp8(global uint* out, uint a, uint b) {
+  *out = __builtin_amdgcn_mov_dpp8(a, b); // expected-error{{argument to '__builtin_amdgcn_mov_dpp8' must be a constant integer}}
+}
Index: test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn.cl
+++ test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -5,6 +5,10 @@
 
 typedef unsigned long ulong;
 typedef unsigned int uint;
+typedef unsigned short ushort;
+typedef half __attribute__((ext_vector_type(2))) half2;
+typedef short __attribute__((ext_vector_type(2))) short2;
+typedef ushort __attribute__((ext_vector_type(2))) ushort2;
 
 // CHECK-LABEL: @test_div_scale_f64
 // CHECK: call { double, i1 } @llvm.amdgcn.div.scale.f64(double %a, double %b, i1 true)
@@ -590,6 +594,66 @@
   *out = __builtin_amdgcn_mbcnt_hi(src0, src1);
 }
 
+// CHECK-LABEL: @test_alignbit(
+// CHECK: tail call i32 @llvm.amdgcn.alignbit(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_alignbit(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_alignbit(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_alignbyte(
+// CHECK: tail call i32 @llvm.amdgcn.alignbyte(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_alignbyte(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_alignbyte(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_ubfe(
+// CHECK: tail call i32 @llvm.amdgcn.ubfe.i32(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_ubfe(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_ubfe(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_sbfe(
+// CHECK: tail call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 %src2)
+kernel void test_sbfe(global uint* out, uint src0, uint src1, uint src2) {
+  *out = __builtin_amdgcn_sbfe(src0, src1, src2);
+}
+
+// CHECK-LABEL: @test_cvt_pkrtz(
+// CHECK: tail call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %src0, float %src1)
+kernel void test_cvt_pkrtz(global half2* out, float src0, float src1) {
+  *out = __builtin_amdgcn_cvt_pkrtz(src0, src1);
+}
+
+// CHECK-LABEL: @test_cvt_pknorm_i16(
+// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pknorm.i16(float %src0, float %src1)
+kernel void test_cvt_pknorm_i16(global 

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum updated this revision to Diff 210188.
quantum added a comment.

Disable atomics when TLS is stripped


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  lld/test/wasm/data-segments.ll
  lld/test/wasm/tls.ll
  lld/wasm/Driver.cpp
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/include/llvm/MC/MCSectionWasm.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/target-features-tls.ll
  llvm/test/CodeGen/WebAssembly/tls.ll

Index: llvm/test/CodeGen/WebAssembly/tls.ll
===
--- llvm/test/CodeGen/WebAssembly/tls.ll
+++ llvm/test/CodeGen/WebAssembly/tls.ll
@@ -1,17 +1,82 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefix=SINGLE %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; SINGLE-LABEL: address_of_tls:
+; CHECK-LABEL: address_of_tls:
+; CHECK-NEXT: .functype  address_of_tls () -> (i32)
 define i32 @address_of_tls() {
-  ; SINGLE: i32.const $push0=, tls
-  ; SINGLE-NEXT: return $pop0
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
   ret i32 ptrtoint(i32* @tls to i32)
 }
 
-; SINGLE: .type	tls,@object
-; SINGLE-NEXT: .section	.bss.tls,"",@
-; SINGLE-NEXT: .p2align 2
-; SINGLE-NEXT: tls:
-; SINGLE-NEXT: .int32 0
-@tls = internal thread_local global i32 0
+; CHECK-LABEL: ptr_to_tls:
+; CHECK-NEXT: .functype ptr_to_tls () -> (i32)
+define i32* @ptr_to_tls() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
+  ret i32* @tls
+}
+
+; CHECK-LABEL: tls_load:
+; CHECK-NEXT: .functype tls_load () -> (i32)
+define i32 @tls_load() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.load 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.load tls
+  ; NO-TLS-NEXT: return
+  %tmp = load i32, i32* @tls, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: tls_store:
+; CHECK-NEXT: .functype tls_store (i32) -> ()
+define void @tls_store(i32 %x) {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.store 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.store tls
+  ; NO-TLS-NEXT: return
+  store i32 %x, i32* @tls, align 4
+  ret void
+}
+
+; CHECK-LABEL: tls_size:
+; CHECK-NEXT: .functype tls_size () -> (i32)
+define i32 @tls_size() {
+; CHECK-NEXT: global.get __tls_size
+; CHECK-NEXT: return
+  %1 = call i32 @llvm.wasm.tls.size.i32()
+  ret i32 %1
+}
+
+; CHECK: .type tls,@object
+; TLS-NEXT: .section .tbss.tls,"",@
+; NO-TLS-NEXT: .section .bss.tls,"",@
+; CHECK-NEXT: .p2align 2
+; CHECK-NEXT: tls:
+; CHECK-NEXT: .int32 0
+@tls = internal thread_local(localexec) global i32 0
+
+declare i32 @llvm.wasm.tls.size.i32()
Index: llvm/test/CodeGen/WebAssembly/target-features-tls.ll
===
--- llvm/test/CodeGen/WebAssembly/target-features-tls.ll
+++ llvm/test/CodeGen/WebAssembly/target-features-tls.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mattr=-atomics | FileCheck %s --check-prefixes CHECK,NO-ATOMICS
-; RUN: llc < %s -mattr=+atomics | FileCheck %s --check-prefixes CHECK,ATOMICS
+; RUN: llc < %s -mattr=-bulk-memory | FileCheck %s --check-prefixes NO-BULK-MEM
+; RUN: llc < %s -mattr=+bulk-memory | FileCheck %s --check-prefixes BULK-MEM
 
 ; Test that the target features section contains -atomics or +atomics
 ; for modules that have thread local storage in their source.
@@ -9,18 +9,18 @@
 
 @foo = internal thread_local global i32 0
 
-; CHECK-LABEL: .custom_section.target_features,"",@
+; -bulk-memory
+; NO-BULK-MEM-LABEL: 

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.

Nice work!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



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


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366272: [WebAssembly] Implement thread-local storage 
(local-exec model) (authored by quantum, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64537?vs=210188=210191#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537

Files:
  cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-wasm.c
  lld/trunk/test/wasm/data-segments.ll
  lld/trunk/test/wasm/tls.ll
  lld/trunk/wasm/Driver.cpp
  lld/trunk/wasm/Symbols.cpp
  lld/trunk/wasm/Symbols.h
  lld/trunk/wasm/Writer.cpp
  llvm/trunk/include/llvm/BinaryFormat/Wasm.h
  llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/trunk/include/llvm/MC/MCSectionWasm.h
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/trunk/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/trunk/test/CodeGen/WebAssembly/target-features-tls.ll
  llvm/trunk/test/CodeGen/WebAssembly/tls.ll

Index: lld/trunk/wasm/Symbols.h
===
--- lld/trunk/wasm/Symbols.h
+++ lld/trunk/wasm/Symbols.h
@@ -426,6 +426,15 @@
   // linear memory.
   static GlobalSymbol *stackPointer;
 
+  // __tls_base
+  // Global that holds the address of the base of the current thread's
+  // TLS block.
+  static GlobalSymbol *tlsBase;
+
+  // __tls_size
+  // Symbol whose value is the size of the TLS block.
+  static GlobalSymbol *tlsSize;
+
   // __data_end
   // Symbol marking the end of the data and bss.
   static DefinedData *dataEnd;
@@ -448,6 +457,10 @@
   // Function that applies relocations to data segment post-instantiation.
   static DefinedFunction *applyRelocs;
 
+  // __wasm_init_tls
+  // Function that allocates thread-local storage and initializes it.
+  static DefinedFunction *initTLS;
+
   // __dso_handle
   // Symbol used in calls to __cxa_atexit to determine current DLL
   static DefinedData *dsoHandle;
Index: lld/trunk/wasm/Driver.cpp
===
--- lld/trunk/wasm/Driver.cpp
+++ lld/trunk/wasm/Driver.cpp
@@ -454,6 +454,7 @@
 // Create ABI-defined synthetic symbols
 static void createSyntheticSymbols() {
   static WasmSignature nullSignature = {{}, {}};
+  static WasmSignature i32ArgSignature = {{}, {ValType::I32}};
   static llvm::wasm::WasmGlobalType globalTypeI32 = {WASM_TYPE_I32, false};
   static llvm::wasm::WasmGlobalType mutableGlobalTypeI32 = {WASM_TYPE_I32,
 true};
@@ -516,6 +517,30 @@
 WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base");
   }
 
+  if (config->sharedMemory && !config->shared) {
+llvm::wasm::WasmGlobal tlsBaseGlobal;
+tlsBaseGlobal.Type = {WASM_TYPE_I32, true};
+tlsBaseGlobal.InitExpr.Value.Int32 = 0;
+tlsBaseGlobal.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
+tlsBaseGlobal.SymbolName = "__tls_base";
+WasmSym::tlsBase =
+symtab->addSyntheticGlobal("__tls_base", WASM_SYMBOL_VISIBILITY_HIDDEN,
+   make(tlsBaseGlobal, nullptr));
+
+llvm::wasm::WasmGlobal tlsSizeGlobal;
+tlsSizeGlobal.Type = {WASM_TYPE_I32, false};
+tlsSizeGlobal.InitExpr.Value.Int32 = 0;
+tlsSizeGlobal.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
+tlsSizeGlobal.SymbolName = "__tls_size";
+WasmSym::tlsSize =
+symtab->addSyntheticGlobal("__tls_size", WASM_SYMBOL_VISIBILITY_HIDDEN,
+   make(tlsSizeGlobal, nullptr));
+
+WasmSym::initTLS = symtab->addSyntheticFunction(
+"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
+make(i32ArgSignature, "__wasm_init_tls"));
+  }
+
   WasmSym::dsoHandle = symtab->addSyntheticDataSymbol(
   "__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN);
 }
Index: lld/trunk/wasm/Symbols.cpp
===
--- lld/trunk/wasm/Symbols.cpp
+++ lld/trunk/wasm/Symbols.cpp
@@ -27,11 +27,14 @@
 DefinedFunction *WasmSym::callCtors;
 DefinedFunction *WasmSym::initMemory;
 DefinedFunction *WasmSym::applyRelocs;
+DefinedFunction *WasmSym::initTLS;
 DefinedData *WasmSym::dsoHandle;
 DefinedData *WasmSym::dataEnd;
 DefinedData *WasmSym::globalBase;
 DefinedData *WasmSym::heapBase;
 GlobalSymbol *WasmSym::stackPointer;
+GlobalSymbol *WasmSym::tlsBase;
+GlobalSymbol *WasmSym::tlsSize;
 UndefinedGlobal *WasmSym::tableBase;
 UndefinedGlobal *WasmSym::memoryBase;
 
@@ -200,8 +203,14 @@
 
 uint32_t DefinedData::getVirtualAddress() const {
   LLVM_DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n");
-  if (segment)
+  if (segment) {
+// For thread local data, the symbol location is relative to the start of
+// 

r366272 - [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via cfe-commits
Author: quantum
Date: Tue Jul 16 15:00:45 2019
New Revision: 366272

URL: http://llvm.org/viewvc/llvm-project?rev=366272=rev
Log:
[WebAssembly] Implement thread-local storage (local-exec model)

Summary:
Thread local variables are placed inside a `.tdata` segment. Their symbols are
offsets from the start of the segment. The address of a thread local variable
is computed as `__tls_base` + the offset from the start of the segment.

`.tdata` segment is a passive segment and `memory.init` is used once per thread
to initialize the thread local storage.

`__tls_base` is a wasm global. Since each thread has its own wasm instance,
it is effectively thread local. Currently, `__tls_base` must be initialized
at thread startup, and so cannot be used with dynamic libraries.

`__tls_base` is to be initialized with a new linker-synthesized function,
`__wasm_init_tls`, which takes as an argument a block of memory to use as the
storage for thread locals. It then initializes the block of memory and sets
`__tls_base`. As `__wasm_init_tls` will handle the memory initialization,
the memory does not have to be zeroed.

To help allocating memory for thread-local storage, a new compiler intrinsic
is introduced: `__builtin_wasm_tls_size()`. This instrinsic function returns
the size of the thread-local storage for the current function.

The expected usage is to run something like the following upon thread startup:

__wasm_init_tls(malloc(__builtin_wasm_tls_size()));

Reviewers: tlively, aheejin, kripken, sbc100

Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, cfe-commits, 
llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=366272=366271=366272=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Tue Jul 16 15:00:45 
2019
@@ -29,6 +29,9 @@ BUILTIN(__builtin_wasm_memory_grow, "zIi
 TARGET_BUILTIN(__builtin_wasm_memory_init, "vIUiIUiv*UiUi", "", "bulk-memory")
 TARGET_BUILTIN(__builtin_wasm_data_drop, "vIUi", "", "bulk-memory")
 
+// Thread-local storage
+TARGET_BUILTIN(__builtin_wasm_tls_size, "z", "nc", "bulk-memory")
+
 // Floating point min/max
 BUILTIN(__builtin_wasm_min_f32, "fff", "nc")
 BUILTIN(__builtin_wasm_max_f32, "fff", "nc")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=366272=366271=366272=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Jul 16 15:00:45 2019
@@ -13913,6 +13913,11 @@ Value *CodeGenFunction::EmitWebAssemblyB
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_data_drop);
 return Builder.CreateCall(Callee, {Arg});
   }
+  case WebAssembly::BI__builtin_wasm_tls_size: {
+llvm::Type *ResultType = ConvertType(E->getType());
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_tls_size, ResultType);
+return Builder.CreateCall(Callee);
+  }
   case WebAssembly::BI__builtin_wasm_throw: {
 Value *Tag = EmitScalarExpr(E->getArg(0));
 Value *Obj = EmitScalarExpr(E->getArg(1));

Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=366272=366271=366272=diff
==
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Tue Jul 16 15:00:45 2019
@@ -38,6 +38,12 @@ void data_drop() {
   // WEBASSEMBLY64: call void @llvm.wasm.data.drop(i32 3)
 }
 
+__SIZE_TYPE__ tls_size() {
+  return __builtin_wasm_tls_size();
+  // WEBASSEMBLY32: call i32 @llvm.wasm.tls.size.i32()
+  // WEBASSEMBLY64: call i64 @llvm.wasm.tls.size.i64()
+}
+
 void throw(void *obj) {
   return __builtin_wasm_throw(0, obj);
   // WEBASSEMBLY32: call void @llvm.wasm.throw(i32 0, i8* %{{.*}})


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


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum updated this revision to Diff 210187.
quantum added a comment.

Remove extra braces


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  lld/test/wasm/data-segments.ll
  lld/test/wasm/tls.ll
  lld/wasm/Driver.cpp
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/include/llvm/MC/MCSectionWasm.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/target-features-tls.ll
  llvm/test/CodeGen/WebAssembly/tls.ll

Index: llvm/test/CodeGen/WebAssembly/tls.ll
===
--- llvm/test/CodeGen/WebAssembly/tls.ll
+++ llvm/test/CodeGen/WebAssembly/tls.ll
@@ -1,17 +1,82 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefix=SINGLE %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; SINGLE-LABEL: address_of_tls:
+; CHECK-LABEL: address_of_tls:
+; CHECK-NEXT: .functype  address_of_tls () -> (i32)
 define i32 @address_of_tls() {
-  ; SINGLE: i32.const $push0=, tls
-  ; SINGLE-NEXT: return $pop0
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
   ret i32 ptrtoint(i32* @tls to i32)
 }
 
-; SINGLE: .type	tls,@object
-; SINGLE-NEXT: .section	.bss.tls,"",@
-; SINGLE-NEXT: .p2align 2
-; SINGLE-NEXT: tls:
-; SINGLE-NEXT: .int32 0
-@tls = internal thread_local global i32 0
+; CHECK-LABEL: ptr_to_tls:
+; CHECK-NEXT: .functype ptr_to_tls () -> (i32)
+define i32* @ptr_to_tls() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
+  ret i32* @tls
+}
+
+; CHECK-LABEL: tls_load:
+; CHECK-NEXT: .functype tls_load () -> (i32)
+define i32 @tls_load() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.load 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.load tls
+  ; NO-TLS-NEXT: return
+  %tmp = load i32, i32* @tls, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: tls_store:
+; CHECK-NEXT: .functype tls_store (i32) -> ()
+define void @tls_store(i32 %x) {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.store 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.store tls
+  ; NO-TLS-NEXT: return
+  store i32 %x, i32* @tls, align 4
+  ret void
+}
+
+; CHECK-LABEL: tls_size:
+; CHECK-NEXT: .functype tls_size () -> (i32)
+define i32 @tls_size() {
+; CHECK-NEXT: global.get __tls_size
+; CHECK-NEXT: return
+  %1 = call i32 @llvm.wasm.tls.size.i32()
+  ret i32 %1
+}
+
+; CHECK: .type tls,@object
+; TLS-NEXT: .section .tbss.tls,"",@
+; NO-TLS-NEXT: .section .bss.tls,"",@
+; CHECK-NEXT: .p2align 2
+; CHECK-NEXT: tls:
+; CHECK-NEXT: .int32 0
+@tls = internal thread_local(localexec) global i32 0
+
+declare i32 @llvm.wasm.tls.size.i32()
Index: llvm/test/CodeGen/WebAssembly/target-features-tls.ll
===
--- llvm/test/CodeGen/WebAssembly/target-features-tls.ll
+++ llvm/test/CodeGen/WebAssembly/target-features-tls.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mattr=-atomics | FileCheck %s --check-prefixes CHECK,NO-ATOMICS
-; RUN: llc < %s -mattr=+atomics | FileCheck %s --check-prefixes CHECK,ATOMICS
+; RUN: llc < %s -mattr=-bulk-memory | FileCheck %s --check-prefixes NO-BULK-MEM
+; RUN: llc < %s -mattr=+bulk-memory | FileCheck %s --check-prefixes BULK-MEM
 
 ; Test that the target features section contains -atomics or +atomics
 ; for modules that have thread local storage in their source.
@@ -9,18 +9,18 @@
 
 @foo = internal thread_local global i32 0
 
-; CHECK-LABEL: .custom_section.target_features,"",@
+; -bulk-memory
+; NO-BULK-MEM-LABEL: 

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum updated this revision to Diff 210184.
quantum added a comment.

Removed the trailing `.`. I would add a test to make sure things work without 
`-fdata-sections`, but `this->Options.DataSections = true;` is hard-coded in 
`WebAssemblyTargetMachine.cpp`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  lld/test/wasm/data-segments.ll
  lld/test/wasm/tls.ll
  lld/wasm/Driver.cpp
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/include/llvm/MC/MCSectionWasm.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/target-features-tls.ll
  llvm/test/CodeGen/WebAssembly/tls.ll

Index: llvm/test/CodeGen/WebAssembly/tls.ll
===
--- llvm/test/CodeGen/WebAssembly/tls.ll
+++ llvm/test/CodeGen/WebAssembly/tls.ll
@@ -1,17 +1,82 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefix=SINGLE %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; SINGLE-LABEL: address_of_tls:
+; CHECK-LABEL: address_of_tls:
+; CHECK-NEXT: .functype  address_of_tls () -> (i32)
 define i32 @address_of_tls() {
-  ; SINGLE: i32.const $push0=, tls
-  ; SINGLE-NEXT: return $pop0
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
   ret i32 ptrtoint(i32* @tls to i32)
 }
 
-; SINGLE: .type	tls,@object
-; SINGLE-NEXT: .section	.bss.tls,"",@
-; SINGLE-NEXT: .p2align 2
-; SINGLE-NEXT: tls:
-; SINGLE-NEXT: .int32 0
-@tls = internal thread_local global i32 0
+; CHECK-LABEL: ptr_to_tls:
+; CHECK-NEXT: .functype ptr_to_tls () -> (i32)
+define i32* @ptr_to_tls() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
+  ret i32* @tls
+}
+
+; CHECK-LABEL: tls_load:
+; CHECK-NEXT: .functype tls_load () -> (i32)
+define i32 @tls_load() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.load 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.load tls
+  ; NO-TLS-NEXT: return
+  %tmp = load i32, i32* @tls, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: tls_store:
+; CHECK-NEXT: .functype tls_store (i32) -> ()
+define void @tls_store(i32 %x) {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.store 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.store tls
+  ; NO-TLS-NEXT: return
+  store i32 %x, i32* @tls, align 4
+  ret void
+}
+
+; CHECK-LABEL: tls_size:
+; CHECK-NEXT: .functype tls_size () -> (i32)
+define i32 @tls_size() {
+; CHECK-NEXT: global.get __tls_size
+; CHECK-NEXT: return
+  %1 = call i32 @llvm.wasm.tls.size.i32()
+  ret i32 %1
+}
+
+; CHECK: .type tls,@object
+; TLS-NEXT: .section .tbss.tls,"",@
+; NO-TLS-NEXT: .section .bss.tls,"",@
+; CHECK-NEXT: .p2align 2
+; CHECK-NEXT: tls:
+; CHECK-NEXT: .int32 0
+@tls = internal thread_local(localexec) global i32 0
+
+declare i32 @llvm.wasm.tls.size.i32()
Index: llvm/test/CodeGen/WebAssembly/target-features-tls.ll
===
--- llvm/test/CodeGen/WebAssembly/target-features-tls.ll
+++ llvm/test/CodeGen/WebAssembly/target-features-tls.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mattr=-atomics | FileCheck %s --check-prefixes CHECK,NO-ATOMICS
-; RUN: llc < %s -mattr=+atomics | FileCheck %s --check-prefixes CHECK,ATOMICS
+; RUN: llc < %s -mattr=-bulk-memory | FileCheck %s --check-prefixes NO-BULK-MEM
+; RUN: llc < %s -mattr=+bulk-memory | FileCheck %s --check-prefixes BULK-MEM
 
 ; Test that the target features section contains -atomics or +atomics
 ; for modules that have thread local storage in their source.
@@ -9,18 +9,18 

[PATCH] D64632: [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier

2019-07-16 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

Submitted as r366267. Thanks!




Comment at: clang/lib/Format/TokenAnnotator.cpp:389
   bool isCpp11AttributeSpecifier(const FormatToken ) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;

aaron.ballman wrote:
> Clang has a feature flag to enable support for double-square bracket 
> attributes in more than just C++ mode, and this is enabled by default in C2x 
> mode. This check for `isCpp()` makes me suspect we may be doing the wrong 
> thing here.
Good point. I filed https://bugs.llvm.org/show_bug.cgi?id=42645 to revisit this.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64632/new/

https://reviews.llvm.org/D64632



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


[PATCH] D64632: [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier

2019-07-16 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366267: [clang-format] Dont detect call to ObjC class 
method as C++11 attribute… (authored by benhamilton, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64632?vs=209777=210182#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64632/new/

https://reviews.llvm.org/D64632

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -388,6 +388,10 @@
   bool isCpp11AttributeSpecifier(const FormatToken ) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+// The first square bracket is part of an ObjC array literal
+if (Tok.Previous && Tok.Previous->is(tok::at)) {
+  return false;
+}
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -400,7 +404,7 @@
 while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
   // ObjC message send. We assume nobody will use : in a C++11 attribute
   // specifier parameter, although this is technically valid:
-  // [[foo(:)]]
+  // [[foo(:)]].
   if (AttrTok->is(tok::colon) ||
   AttrTok->startsSequence(tok::identifier, tok::identifier) ||
   AttrTok->startsSequence(tok::r_paren, tok::identifier))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -7027,6 +7027,12 @@
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
 
+  // Make sure that we do not mistake Objective-C method inside array literals
+  // as attributes, even if those method names are also keywords.
+  verifyFormat("@[ [foo bar] ];");
+  verifyFormat("@[ [NSArray class] ];");
+  verifyFormat("@[ [foo enum] ];");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -388,6 +388,10 @@
   bool isCpp11AttributeSpecifier(const FormatToken ) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+// The first square bracket is part of an ObjC array literal
+if (Tok.Previous && Tok.Previous->is(tok::at)) {
+  return false;
+}
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -400,7 +404,7 @@
 while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
   // ObjC message send. We assume nobody will use : in a C++11 attribute
   // specifier parameter, although this is technically valid:
-  // [[foo(:)]]
+  // [[foo(:)]].
   if (AttrTok->is(tok::colon) ||
   AttrTok->startsSequence(tok::identifier, tok::identifier) ||
   AttrTok->startsSequence(tok::r_paren, tok::identifier))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -7027,6 +7027,12 @@
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
 
+  // Make sure that we do not mistake Objective-C method inside array literals
+  // as attributes, even if those method names are also keywords.
+  verifyFormat("@[ [foo bar] ];");
+  verifyFormat("@[ [NSArray class] ];");
+  verifyFormat("@[ [foo enum] ];");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-07-16 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane marked an inline comment as done.
jpakkane added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:21
+  Finder->addMatcher(
+  varDecl(unless(hasInitializer(anything(.bind("vardecl"), this);
+}

alexfh wrote:
> jpakkane wrote:
> > alexfh wrote:
> > > I believe, this should skip matches within template instantiations. 
> > > Consider this code:
> > > ```
> > > template
> > > void f(T) { T t; }
> > > void g() {
> > > f(0);
> > > f(0.0);
> > > }
> > > ```
> > > 
> > > What will the fix  be?
> > I tested with the following function:
> > 
> > 
> > ```
> > template
> > void template_test_function() {
> >   T t;
> >   int uninitialized;
> > }
> > ```
> > 
> > Currently it warns on the "uninitialized" variable regardless of whether 
> > the template is instantiated or not. If you call it with an int type, it 
> > will warn about variable t being uninitialized. If you call it with a, say, 
> > struct type, there is no warnings. Is this a reasonable approach?
> And what happens, if there are multiple instantiations of the same template, 
> each of them requiring a different fix? Can you try the check with my example 
> above (and maybe also add `f("");`inside `g()`). I believe, the check will 
> produce multiple warnings with conflicting fixes (and each of them will be 
> wrong, btw).
Interestingly it does warn about it, but only once, even if you have two 
different template specializations.

I tried to suppress this warning when the type being instantiated is a template 
argument type but no matter what I tried I could not get this to work. Is there 
a way to get this information from the MatchedDecl object or does one need to 
do something more complicated like going up the AST until a function definition 
is found and checking if it is a template specialization (presumably with 
TemplatedKind)? Any help would be appreciated.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64671/new/

https://reviews.llvm.org/D64671



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


r366267 - [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier

2019-07-16 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Tue Jul 16 14:29:40 2019
New Revision: 366267

URL: http://llvm.org/viewvc/llvm-project?rev=366267=rev
Log:
[clang-format] Don't detect call to ObjC class method as C++11 attribute 
specifier

Summary:
Previously, clang-format detected something like the following as a C++11 
attribute specifier.

  @[[NSArray class]]

instead of an array with an Objective-C method call inside. In general, when 
the attribute specifier checking runs, if it sees 2 identifiers in a row, it 
decides that the square brackets represent an Objective-C method call. However, 
here, `class` is tokenized as a keyword instead of an identifier, so this check 
fails.

To fix this, the attribute specifier first checks whether the first square 
bracket has an "@" before it. If it does, then that square bracket is not the 
start of a attribute specifier because it is an Objective-C array literal. (The 
assumption is that @[[.*]] is not valid C/C++.)

Contributed by rkgibson2.

Reviewers: benhamilton

Reviewed By: benhamilton

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=366267=366266=366267=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul 16 14:29:40 2019
@@ -388,6 +388,10 @@ private:
   bool isCpp11AttributeSpecifier(const FormatToken ) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+// The first square bracket is part of an ObjC array literal
+if (Tok.Previous && Tok.Previous->is(tok::at)) {
+  return false;
+}
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -400,7 +404,7 @@ private:
 while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
   // ObjC message send. We assume nobody will use : in a C++11 attribute
   // specifier parameter, although this is technically valid:
-  // [[foo(:)]]
+  // [[foo(:)]].
   if (AttrTok->is(tok::colon) ||
   AttrTok->startsSequence(tok::identifier, tok::identifier) ||
   AttrTok->startsSequence(tok::r_paren, tok::identifier))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=366267=366266=366267=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 16 14:29:40 2019
@@ -7027,6 +7027,12 @@ TEST_F(FormatTest, UnderstandsSquareAttr
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
 
+  // Make sure that we do not mistake Objective-C method inside array literals
+  // as attributes, even if those method names are also keywords.
+  verifyFormat("@[ [foo bar] ];");
+  verifyFormat("@[ [NSArray class] ];");
+  verifyFormat("@[ [foo enum] ];");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;


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


[PATCH] D64820: Avoids an assertion failure when an invalid conversion declaration is used

2019-07-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added a reviewer: rsmith.
Mordante added a project: clang.

When using a user-defined conversion function template with a deduced return 
type the compiler gives a set of warnings:

  bug.cc:252:44: error: cannot specify any part of a return type in the 
declaration of a conversion function; use an alias template to declare a 
conversion to 'auto (Ts &&...) const'
template  operator auto()(Ts &&... xs) const;
 ^~~
  bug.cc:252:29: error: conversion function cannot convert to a function type
template  operator auto()(Ts &&... xs) const;
  ^
  error: pointer to function type cannot have 'const' qualifier

after which it triggers an assertion failure. It seems the last error is 
incorrect and doesn't have any location information. This patch stops the 
compilation after the second warning.

Fixes bug 31422.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64820

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/conversion_function_to_function.cpp


Index: clang/test/Sema/conversion_function_to_function.cpp
===
--- /dev/null
+++ clang/test/Sema/conversion_function_to_function.cpp
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++14 %s 2>&1 | FileCheck %s
+
+struct S {
+  template  operator auto()(Ts &&... xs) const;
+};
+
+// CHECK: error: cannot specify any part of a return type in the declaration 
of a conversion function; use an alias template to declare a conversion to 
'auto (Ts &&...) const'
+// CHECK: error: conversion function cannot convert to a function type
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8066,6 +8066,9 @@
 }
 
 SemaRef.CheckConversionDeclarator(D, R, SC);
+if (D.isInvalidType())
+  return nullptr;
+
 IsVirtualOkay = true;
 return CXXConversionDecl::Create(
 SemaRef.Context, cast(DC), D.getBeginLoc(), NameInfo, R,


Index: clang/test/Sema/conversion_function_to_function.cpp
===
--- /dev/null
+++ clang/test/Sema/conversion_function_to_function.cpp
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++14 %s 2>&1 | FileCheck %s
+
+struct S {
+  template  operator auto()(Ts &&... xs) const;
+};
+
+// CHECK: error: cannot specify any part of a return type in the declaration of a conversion function; use an alias template to declare a conversion to 'auto (Ts &&...) const'
+// CHECK: error: conversion function cannot convert to a function type
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8066,6 +8066,9 @@
 }
 
 SemaRef.CheckConversionDeclarator(D, R, SC);
+if (D.isInvalidType())
+  return nullptr;
+
 IsVirtualOkay = true;
 return CXXConversionDecl::Create(
 SemaRef.Context, cast(DC), D.getBeginLoc(), NameInfo, R,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61749: [clang-tidy] initial version of readability-convert-member-functions-to-static

2019-07-16 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366265: [clang-tidy] initial version of 
readability-convert-member-functions-to-static (authored by mgehre, committed 
by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61749?vs=209360=210176#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61749/new/

https://reviews.llvm.org/D61749

Files:
  clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
  
clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
  
clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
  clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-convert-member-functions-to-static.rst
  
clang-tools-extra/trunk/test/clang-tidy/readability-convert-member-functions-to-static.cpp

Index: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "BracesAroundStatementsCheck.h"
 #include "ConstReturnTypeCheck.h"
 #include "ContainerSizeEmptyCheck.h"
+#include "ConvertMemberFunctionsToStatic.h"
 #include "DeleteNullPointerCheck.h"
 #include "DeletedDefaultCheck.h"
 #include "ElseAfterReturnCheck.h"
@@ -57,6 +58,8 @@
 "readability-const-return-type");
 CheckFactories.registerCheck(
 "readability-container-size-empty");
+CheckFactories.registerCheck(
+"readability-convert-member-functions-to-static");
 CheckFactories.registerCheck(
 "readability-delete-null-pointer");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -0,0 +1,172 @@
+//===--- ConvertMemberFunctionsToStatic.cpp - clang-tidy --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ConvertMemberFunctionsToStatic.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/SourceLocation.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
+
+AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
+  return Node.isOverloadedOperator();
+}
+
+AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
+  return Node.hasAnyDependentBases();
+}
+
+AST_MATCHER(CXXMethodDecl, isTemplate) {
+  return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
+}
+
+AST_MATCHER(CXXMethodDecl, isDependentContext) {
+  return Node.isDependentContext();
+}
+
+AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
+  const ASTContext  = Finder->getASTContext();
+  return clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(
+ Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+ Ctxt.getSourceManager(), Ctxt.getLangOpts())
+  .isInvalid();
+}
+
+AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
+}
+
+AST_MATCHER(CXXMethodDecl, usesThis) {
+  class FindUsageOfThis : public RecursiveASTVisitor {
+  public:
+bool Used = false;
+
+bool VisitCXXThisExpr(const CXXThisExpr *E) {
+  Used = true;
+  return false; // Stop traversal.
+}
+  } UsageOfThis;
+
+  // TraverseStmt does not modify its argument.
+  UsageOfThis.TraverseStmt(const_cast(Node.getBody()));
+
+  return UsageOfThis.Used;
+}
+
+void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxMethodDecl(
+  isDefinition(), isUserProvided(),
+  unless(anyOf(
+  isExpansionInSystemHeader(), isVirtual(), isStatic(),
+  hasTrivialBody(), isOverloadedOperator(), cxxConstructorDecl(),
+  cxxDestructorDecl(), 

[PATCH] D61749: [clang-tidy] initial version of readability-convert-member-functions-to-static

2019-07-16 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Thank you for the review, Aaron!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61749/new/

https://reviews.llvm.org/D61749



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


[clang-tools-extra] r366265 - [clang-tidy] initial version of readability-convert-member-functions-to-static

2019-07-16 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Tue Jul 16 14:19:00 2019
New Revision: 366265

URL: http://llvm.org/viewvc/llvm-project?rev=366265=rev
Log:
[clang-tidy] initial version of readability-convert-member-functions-to-static

Summary:
Finds non-static member functions that can be made ``static``.

I have run this check (repeatedly) over llvm-project. It made 1708 member 
functions
``static``. Out of those, I had to exclude 22 via ``NOLINT`` because their 
address
was taken and stored in a variable of pointer-to-member type (e.g. passed to
llvm::StringSwitch).
It also made 243 member functions ``const``. (This is currently very 
conservative
to have no false-positives and can hopefully be extended in the future.)

You can find the results here: 
https://github.com/mgehre/llvm-project/commits/static_const_eval

Reviewers: alexfh, aaron.ballman

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

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

Added:

clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp

clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-convert-member-functions-to-static.rst

clang-tools-extra/trunk/test/clang-tidy/readability-convert-member-functions-to-static.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=366265=366264=366265=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Tue Jul 16 
14:19:00 2019
@@ -5,6 +5,7 @@ add_clang_library(clangTidyReadabilityMo
   BracesAroundStatementsCheck.cpp
   ConstReturnTypeCheck.cpp
   ContainerSizeEmptyCheck.cpp
+  ConvertMemberFunctionsToStatic.cpp
   DeleteNullPointerCheck.cpp
   DeletedDefaultCheck.cpp
   ElseAfterReturnCheck.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp?rev=366265=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
 (added)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
 Tue Jul 16 14:19:00 2019
@@ -0,0 +1,172 @@
+//===--- ConvertMemberFunctionsToStatic.cpp - clang-tidy 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ConvertMemberFunctionsToStatic.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/SourceLocation.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
+
+AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
+  return Node.isOverloadedOperator();
+}
+
+AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
+  return Node.hasAnyDependentBases();
+}
+
+AST_MATCHER(CXXMethodDecl, isTemplate) {
+  return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
+}
+
+AST_MATCHER(CXXMethodDecl, isDependentContext) {
+  return Node.isDependentContext();
+}
+
+AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
+  const ASTContext  = Finder->getASTContext();
+  return clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(
+ Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+ Ctxt.getSourceManager(), Ctxt.getLangOpts())
+  .isInvalid();
+}
+
+AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
+}
+
+AST_MATCHER(CXXMethodDecl, usesThis) {
+  class FindUsageOfThis : public RecursiveASTVisitor {
+  public:
+bool Used = false;
+
+bool VisitCXXThisExpr(const CXXThisExpr *E) {
+  Used = true;
+  return false; // Stop traversal.
+}
+  } UsageOfThis;
+
+  // TraverseStmt does not modify its argument.
+  

Re: r366123 - ARM MTE stack sanitizer.

2019-07-16 Thread Evgenii Stepanov via cfe-commits
I could not reproduce this on Linux nor on Mac.
I wonder if triggering a clean build would help? I don't see a way to
do that though.

On Tue, Jul 16, 2019 at 10:50 AM Evgenii Stepanov
 wrote:
>
> Hi,
>
> thanks for letting me know! Is this reproducible on Linux? It is
> possible to extract a reproducer from the bot?
>
> On Mon, Jul 15, 2019 at 9:30 PM Amara Emerson  wrote:
> >
> > Hi Evgeniy,
> >
> > This commit looks like it broke the lldb bot: 
> > http://green.lab.llvm.org/green/job/lldb-cmake/31011/
> >
> > Can you take a look?
> >
> > Amara
> >
> > On Jul 15, 2019, at 1:02 PM, Evgeniy Stepanov via cfe-commits 
> >  wrote:
> >
> > Author: eugenis
> > Date: Mon Jul 15 13:02:23 2019
> > New Revision: 366123
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=366123=rev
> > Log:
> > ARM MTE stack sanitizer.
> >
> > Add "memtag" sanitizer that detects and mitigates stack memory issues
> > using armv8.5 Memory Tagging Extension.
> >
> > It is similar in principle to HWASan, which is a software implementation
> > of the same idea, but there are enough differencies to warrant a new
> > sanitizer type IMHO. It is also expected to have very different
> > performance properties.
> >
> > The new sanitizer does not have a runtime library (it may grow one
> > later, along with a "debugging" mode). Similar to SafeStack and
> > StackProtector, the instrumentation pass (in a follow up change) will be
> > inserted in all cases, but will only affect functions marked with the
> > new sanitize_memtag attribute.
> >
> > Reviewers: pcc, hctim, vitalybuka, ostannard
> >
> > Subscribers: srhines, mehdi_amini, javed.absar, kristof.beyls, hiraditya, 
> > cryptoad, steven_wu, dexonsmith, cfe-commits, llvm-commits
> >
> > Tags: #clang, #llvm
> >
> > Differential Revision: https://reviews.llvm.org/D64169
> >
> > Added:
> >cfe/trunk/test/CodeGen/memtag-attr.cpp
> >cfe/trunk/test/Lexer/has_feature_memtag_sanitizer.cpp
> > Modified:
> >cfe/trunk/include/clang/Basic/Features.def
> >cfe/trunk/include/clang/Basic/Sanitizers.def
> >cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> >cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
> >cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> >cfe/trunk/lib/CodeGen/SanitizerMetadata.cpp
> >cfe/trunk/lib/Driver/SanitizerArgs.cpp
> >cfe/trunk/lib/Driver/ToolChains/Linux.cpp
> >cfe/trunk/test/Driver/fsanitize.c
> >cfe/trunk/test/SemaCXX/attr-no-sanitize.cpp
> >
> > Modified: cfe/trunk/include/clang/Basic/Features.def
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=366123=366122=366123=diff
> > ==
> > --- cfe/trunk/include/clang/Basic/Features.def (original)
> > +++ cfe/trunk/include/clang/Basic/Features.def Mon Jul 15 13:02:23 2019
> > @@ -42,6 +42,7 @@ FEATURE(address_sanitizer,
> > FEATURE(hwaddress_sanitizer,
> > LangOpts.Sanitize.hasOneOf(SanitizerKind::HWAddress |
> >SanitizerKind::KernelHWAddress))
> > +FEATURE(memtag_sanitizer, LangOpts.Sanitize.has(SanitizerKind::MemTag))
> > FEATURE(xray_instrument, LangOpts.XRayInstrument)
> > FEATURE(undefined_behavior_sanitizer,
> > LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
> >
> > Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=366123=366122=366123=diff
> > ==
> > --- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
> > +++ cfe/trunk/include/clang/Basic/Sanitizers.def Mon Jul 15 13:02:23 2019
> > @@ -55,6 +55,9 @@ SANITIZER("hwaddress", HWAddress)
> > // Kernel Hardware-assisted AddressSanitizer (KHWASan)
> > SANITIZER("kernel-hwaddress", KernelHWAddress)
> >
> > +// A variant of AddressSanitizer using AArch64 MTE extension.
> > +SANITIZER("memtag", MemTag)
> > +
> > // MemorySanitizer
> > SANITIZER("memory", Memory)
> >
> >
> > Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=366123=366122=366123=diff
> > ==
> > --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
> > +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 15 13:02:23 2019
> > @@ -369,6 +369,10 @@ llvm::Function *CodeGenModule::CreateGlo
> >   !isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc))
> > Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
> >
> > +  if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) &&
> > +  !isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc))
> > +Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
> > +
> >   if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
> >   !isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc))
> > 

[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 accepted this revision.
sbc100 added inline comments.
This revision is now accepted and ready to land.



Comment at: lld/wasm/Writer.cpp:400
+  StringRef name = segment->getName();
+  if (name.startswith(".tdata.") || name.startswith(".tbss."))
+tlsUsed = true;

Right now we always compiler with -fdata-sections, but if we didn't then object 
files might have just one ".tdata" sections.   Perhaps drop the final "."?  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:27
+static const char GlobalArgumentMemAccess[] = {
+// grep  -P -o "(?<=FUNCTION_INFO: ).*"  | sort -u >
+// ../llvm-project/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpData.h

glider wrote:
> vitalybuka wrote:
> > glider wrote:
> > > Ditto.
> > These files should be empty. Raw diff 
> > https://reviews.llvm.org/file/data/o6sk6gw2gqs4u4pmodrn/PHID-FILE-s6c6nsofxnqekkcvzdzs/D61879.diff
> >  already contains them. 
> > It's ThinLTO replacement experiments. They don't improve results enough, so 
> > I didn't bother to create real ThinLTO stuff. Anyway it is not needed for 
> > full LTO.
> > 
> ```
> $ ninja -j64 check-clang
> ...
> /usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:20:32:
>  error: zero-size array ‘llvm::GUIDS_LOOKUP’
>  static const GlobalValue::GUID GUIDS_LOOKUP[] = {
> ^~~~
> /usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:26:19:
>  error: zero-size array ‘llvm::GlobalArgumentMemAccess’
>  static const char GlobalArgumentMemAccess[] = {
>^~~
> ```
> Am I doing something wrong? Looks like empty files aren't enough.
> I've fixed the problem by putting "0" into each file, but it's strange it 
> works differently for us.
You must be using LLVM_ENABLE_WERROR?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61879/new/

https://reviews.llvm.org/D61879



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


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Guanzhong Chen via Phabricator via cfe-commits
quantum updated this revision to Diff 210166.
quantum added a comment.

More fine-grainted stripping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  lld/test/wasm/data-segments.ll
  lld/test/wasm/tls.ll
  lld/wasm/Driver.cpp
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/include/llvm/MC/MCSectionWasm.h
  llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/target-features-tls.ll
  llvm/test/CodeGen/WebAssembly/tls.ll

Index: llvm/test/CodeGen/WebAssembly/tls.ll
===
--- llvm/test/CodeGen/WebAssembly/tls.ll
+++ llvm/test/CodeGen/WebAssembly/tls.ll
@@ -1,17 +1,82 @@
-; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefix=SINGLE %s
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
+; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; SINGLE-LABEL: address_of_tls:
+; CHECK-LABEL: address_of_tls:
+; CHECK-NEXT: .functype  address_of_tls () -> (i32)
 define i32 @address_of_tls() {
-  ; SINGLE: i32.const $push0=, tls
-  ; SINGLE-NEXT: return $pop0
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
   ret i32 ptrtoint(i32* @tls to i32)
 }
 
-; SINGLE: .type	tls,@object
-; SINGLE-NEXT: .section	.bss.tls,"",@
-; SINGLE-NEXT: .p2align 2
-; SINGLE-NEXT: tls:
-; SINGLE-NEXT: .int32 0
-@tls = internal thread_local global i32 0
+; CHECK-LABEL: ptr_to_tls:
+; CHECK-NEXT: .functype ptr_to_tls () -> (i32)
+define i32* @ptr_to_tls() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const tls
+  ; NO-TLS-NEXT: return
+  ret i32* @tls
+}
+
+; CHECK-LABEL: tls_load:
+; CHECK-NEXT: .functype tls_load () -> (i32)
+define i32 @tls_load() {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.load 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.load tls
+  ; NO-TLS-NEXT: return
+  %tmp = load i32, i32* @tls, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: tls_store:
+; CHECK-NEXT: .functype tls_store (i32) -> ()
+define void @tls_store(i32 %x) {
+  ; TLS-DAG: global.get __tls_base
+  ; TLS-DAG: i32.const tls
+  ; TLS-NEXT: i32.add
+  ; TLS-NEXT: i32.store 0
+  ; TLS-NEXT: return
+
+  ; NO-TLS-NEXT: i32.const 0
+  ; NO-TLS-NEXT: i32.store tls
+  ; NO-TLS-NEXT: return
+  store i32 %x, i32* @tls, align 4
+  ret void
+}
+
+; CHECK-LABEL: tls_size:
+; CHECK-NEXT: .functype tls_size () -> (i32)
+define i32 @tls_size() {
+; CHECK-NEXT: global.get __tls_size
+; CHECK-NEXT: return
+  %1 = call i32 @llvm.wasm.tls.size.i32()
+  ret i32 %1
+}
+
+; CHECK: .type tls,@object
+; TLS-NEXT: .section .tbss.tls,"",@
+; NO-TLS-NEXT: .section .bss.tls,"",@
+; CHECK-NEXT: .p2align 2
+; CHECK-NEXT: tls:
+; CHECK-NEXT: .int32 0
+@tls = internal thread_local(localexec) global i32 0
+
+declare i32 @llvm.wasm.tls.size.i32()
Index: llvm/test/CodeGen/WebAssembly/target-features-tls.ll
===
--- llvm/test/CodeGen/WebAssembly/target-features-tls.ll
+++ llvm/test/CodeGen/WebAssembly/target-features-tls.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mattr=-atomics | FileCheck %s --check-prefixes CHECK,NO-ATOMICS
-; RUN: llc < %s -mattr=+atomics | FileCheck %s --check-prefixes CHECK,ATOMICS
+; RUN: llc < %s -mattr=-bulk-memory | FileCheck %s --check-prefixes NO-BULK-MEM
+; RUN: llc < %s -mattr=+bulk-memory | FileCheck %s --check-prefixes BULK-MEM
 
 ; Test that the target features section contains -atomics or +atomics
 ; for modules that have thread local storage in their source.
@@ -9,18 +9,18 @@
 
 @foo = internal thread_local global i32 0
 
-; CHECK-LABEL: .custom_section.target_features,"",@
+; -bulk-memory
+; NO-BULK-MEM-LABEL: 

[PATCH] D64780: Disallow most calling convention attributes on PS4.

2019-07-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Some suggestions, you don't have to take all of them.




Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2961
+def error_cconv_unsupported : Error<
+  "%0 calling convention not supported %select{"
+  // Use CallingConventionIgnoredReason Enum to specify these.

This duplication merely to say "not supported" instead of "ignored" seems 
unfortunate. We could reasonable change "ignored" to "unsupported" and then you 
could use the warn_cconv_ignored.Text accessor to share the text.



Comment at: include/clang/Basic/TargetInfo.h:1271
 CCCR_Ignore,
+CCCR_Error,
   };

I feel like perhaps a cleaner way of implementing this would be to have the 
driver pass down -Werror=unknown-calling-conv (sp) on PS4. That would also 
allow users to tell clang to ignore their CC annotations by disabling the 
warning, which could be useful when porting a codebase widely annotated with 
__stdcall, for example.



Comment at: lib/Basic/Targets/X86.h:646-647
   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+if (getTriple().isPS4()) 
+   return (CC == CC_C) ? CCCR_OK : CCCR_Error;
 switch (CC) {

For better separation of concerns, I would suggest putting this in 
PS4OSTargetInfo::checkCallingConvention, so that the main x64 code doesn't have 
to consider that OS-specific concern.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64780/new/

https://reviews.llvm.org/D64780



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


[PATCH] D64380: Add 'require_designated_init' and 'required' attribute to clang

2019-07-16 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman planned changes to this revision.
emmettneyman added a comment.

Changes planned:

- Move diagnostics into a diagnostic group.
- Add behavior and test cases for private members of structs/classes.
- Investigate behavior of GCC `designated_init` attribute


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64380/new/

https://reviews.llvm.org/D64380



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


[PATCH] D64482: [Driver] Define _FILE_OFFSET_BITS=64 on Solaris

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

> To avoid a similar inconsistence with host compilers that don't predefine 
> _FILE_OFFSET_BITS=64
>  (e.g. clang < 9, gcc < 9), this needs a compantion patch to be submitted 
> shortly.

I'm curious, what's the plan for that? I suppose the user can always take 
things into their own hands with -D and -U.

In any case, if you want to match newer GCCs, I'm for that. lgtm


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64482/new/

https://reviews.llvm.org/D64482



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


[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)

2019-07-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

LGTM apart from one last comment




Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:193
+
+if (!Features[WebAssembly::FeatureBulkMemory])
   Stripped |= stripThreadLocals(M);

quantum wrote:
> tlively wrote:
> > I just realized that if we have atomics but not bulk memory and TLS is 
> > stripped, then we will be in the awkward situation of both using atomics 
> > and disallowing atomics because the module is not thread safe. I think the 
> > best solution would be to go back and forcibly strip both atomics and TLS 
> > if either of them would be stripped.
> Done.
We can be more fine grained than this. We should strip atomics or TLS only if 
the relevant feature is missing or the other one is stripped. It is possible to 
have thread-locals and bulk memory but not have any atomics to strip.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64537/new/

https://reviews.llvm.org/D64537



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


[PATCH] D63508: make -frewrite-includes also rewrite conditions in #if/#elif

2019-07-16 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added inline comments.



Comment at: clang/test/Frontend/rewrite-includes-conditions.c:17
+line4
+#elif value2 < value2
+line5

rsmith wrote:
> Did you mean for this to be `value1 < value2` rather than `value2 < value2`?
Yes, not that it'd matter in practice. I'll fix that in the next iteration of 
the patch.




Comment at: clang/test/Frontend/rewrite-includes-conditions.c:54-67
+// CHECK: #if 0 /* disabled by -frewrite-includes */
+// CHECK-NEXT: #if value1 == value2
+// CHECK-NEXT: #endif
+// CHECK-NEXT: #endif /* disabled by -frewrite-includes */
+// CHECK-NEXT: #if 0 /* evaluated by -frewrite-includes */
+// CHECK-NEXT: # 14 "{{.*}}rewrite-includes-conditions.c"
+

rsmith wrote:
> I find this output pretty hard to read -- it's hard to tell what's an 
> original `#if` / `#endif` that's been effectively commented out, and what's 
> an added `#if` / `#endif` that's doing the commenting.
> 
> What do you think about modifying the original line so it's no longer 
> recognized as a preprocessing directive? For instance, instead of:
> 
> ```
> #if 0 /* disabled by -frewrite-includes */
> #if value1 == value2
> #endif
> #endif /* disabled by -frewrite-includes */
> #if 0 /* evaluated by -frewrite-includes */
> # 14 "{{.*}}rewrite-includes-conditions.c"
> line3
> #if 0 /* disabled by -frewrite-includes */
> #if 0
> #elif value1 > value2
> #endif
> #endif /* disabled by -frewrite-includes */
> #elif 0 /* evaluated by -frewrite-includes */
> # 16 "{{.*}}rewrite-includes-conditions.c"
> line4
> #if 0 /* disabled by -frewrite-includes */
> #if 0
> #elif value1 < value2
> #endif
> #endif /* disabled by -frewrite-includes */
> #elif 1 /* evaluated by -frewrite-includes */
> # 18 "{{.*}}rewrite-includes-conditions.c"
> line5
> [...]
> ```
> 
> you might produce
> 
> ```
> #if 0 /* rewritten by -frewrite-includes */
> !#if value1 == value2
> #endif
> #if 0 /* evaluated by -frewrite-includes */
> # 14 "{{.*}}rewrite-includes-conditions.c"
> line3
> #if 0 /* rewritten by -frewrite-includes */
> !#elif value1 > value2
> #endif
> #elif 0 /* evaluated by -frewrite-includes */
> # 16 "{{.*}}rewrite-includes-conditions.c"
> line4
> #if 0 /* rewritten by -frewrite-includes */
> !#elif value1 < value2
> #endif
> #elif 1 /* evaluated by -frewrite-includes */
> # 18 "{{.*}}rewrite-includes-conditions.c"
> line5
> [...]
> ```
> 
> (or whatever transformation you like that prevents recognition of a 
> `#if`/`#elif` within the `#if 0` block).
> 
> Also, maybe we could move the quoted directives inside their respective `#if` 
> / `#elif` block, and only comment them out if the block was entered:
> 
> ```
> #if 0 /* evaluated by -frewrite-includes */
> was: #if value1 == value2
> # 14 "{{.*}}rewrite-includes-conditions.c"
> line3
> #elif 0 /* evaluated by -frewrite-includes */
> was: #elif value1 > value2
> # 16 "{{.*}}rewrite-includes-conditions.c"
> line4
> #elif 1 /* evaluated by -frewrite-includes */
> #if 0
> was: #elif value1 < value2
> #endif
> # 18 "{{.*}}rewrite-includes-conditions.c"
> line5
> [...]
> ```
I think that's a matter of taste/opinion. I find your proposal visually harder 
to read, because although it saves one line, it also is incorrect syntax, it 
visually breaks if-endif nesting and is inconsistent with how 
-frewrite-includes does other rewriting. Moreover I think this will be so 
rarely examined by a human that it doesn't really matter. So unless you insist 
I'd prefer to keep it as it is.

BTW, the other related review I linked above, is it enough to mention it here, 
or should I do something more about it? I'm not sure how to pick reviewers if 
there's not an obvious one.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63508/new/

https://reviews.llvm.org/D63508



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


[PATCH] D64518: [LibTooling] Relax Transformer to allow rewriting macro expansions

2019-07-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 210148.
ymandel added a comment.

tweaks in response to comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64518/new/

https://reviews.llvm.org/D64518

Files:
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -137,7 +137,7 @@
   TransformerTest() { appendToHeader(KHeaderContents); }
 };
 
-// Given string s, change strlen($s.c_str()) to $s.size().
+// Given string s, change strlen($s.c_str()) to REPLACED.
 static RewriteRule ruleStrlenSize() {
   StringRef StringExpr = "strexpr";
   auto StringType = namedDecl(hasAnyName("::basic_string", "::string"));
@@ -163,17 +163,6 @@
   testRule(ruleStrlenSize(), Input, Input);
 }
 
-// Tests that expressions in macro arguments are rewritten (when applicable).
-TEST_F(TransformerTest, StrlenSizeMacro) {
-  std::string Input = R"cc(
-#define ID(e) e
-int f(string s) { return ID(strlen(s.c_str())); })cc";
-  std::string Expected = R"cc(
-#define ID(e) e
-int f(string s) { return ID(REPLACED); })cc";
-  testRule(ruleStrlenSize(), Input, Expected);
-}
-
 // Tests replacing an expression.
 TEST_F(TransformerTest, Flag) {
   StringRef Flag = "flag";
@@ -619,23 +608,114 @@
   EXPECT_EQ(ErrorCount, 0);
 }
 
-TEST_F(TransformerTest, NoTransformationInMacro) {
+// Transformation of macro source text when the change encompasses the entirety
+// of the expanded text.
+TEST_F(TransformerTest, SimpleMacro) {
+  std::string Input = R"cc(
+#define ZERO 0
+int f(string s) { return ZERO; }
+  )cc";
+  std::string Expected = R"cc(
+#define ZERO 0
+int f(string s) { return 999; }
+  )cc";
+
+  StringRef zero = "zero";
+  RewriteRule R = makeRule(integerLiteral(equals(0)).bind(zero),
+   change(node(zero), text("999")));
+  testRule(R, Input, Expected);
+}
+
+// Transformation of macro source text when the change encompasses the entirety
+// of the expanded text, for the case of function-style macros.
+TEST_F(TransformerTest, FunctionMacro) {
   std::string Input = R"cc(
 #define MACRO(str) strlen((str).c_str())
-int f(string s) { return MACRO(s); })cc";
-  testRule(ruleStrlenSize(), Input, Input);
+int f(string s) { return MACRO(s); }
+  )cc";
+  std::string Expected = R"cc(
+#define MACRO(str) strlen((str).c_str())
+int f(string s) { return REPLACED; }
+  )cc";
+
+  testRule(ruleStrlenSize(), Input, Expected);
+}
+
+// Tests that expressions in macro arguments can be rewritten.
+TEST_F(TransformerTest, MacroArg) {
+  std::string Input = R"cc(
+#define PLUS(e) e + 1
+int f(string s) { return PLUS(strlen(s.c_str())); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS(e) e + 1
+int f(string s) { return PLUS(REPLACED); }
+  )cc";
+
+  testRule(ruleStrlenSize(), Input, Expected);
 }
 
-// This test handles the corner case where a macro called within another macro
-// expands to matching code, but the matched code is an argument to the nested
-// macro.  A simple check of isMacroArgExpansion() vs. isMacroBodyExpansion()
-// will get this wrong, and transform the code. This test verifies that no such
-// transformation occurs.
-TEST_F(TransformerTest, NoTransformationInNestedMacro) {
+// Tests that expressions in macro arguments can be rewritten, even when the
+// macro call occurs inside another macro's definition.
+TEST_F(TransformerTest, MacroArgInMacroDef) {
   std::string Input = R"cc(
 #define NESTED(e) e
 #define MACRO(str) NESTED(strlen((str).c_str()))
-int f(string s) { return MACRO(s); })cc";
+int f(string s) { return MACRO(s); }
+  )cc";
+  std::string Expected = R"cc(
+#define NESTED(e) e
+#define MACRO(str) NESTED(strlen((str).c_str()))
+int f(string s) { return REPLACED; }
+  )cc";
+
+  testRule(ruleStrlenSize(), Input, Expected);
+}
+
+// Tests the corner case of the identity macro, specifically that it is
+// discarded in the rewrite rather than preserved (like PLUS is preserved in the
+// previous test).  This behavior is of dubious value (and marked with a FIXME
+// in the code), but we test it to verify (and demonstrate) how this case is
+// handled.
+TEST_F(TransformerTest, IdentityMacro) {
+  std::string Input = R"cc(
+#define ID(e) e
+int f(string s) { return ID(strlen(s.c_str())); }
+  )cc";
+  std::string Expected = R"cc(
+#define ID(e) e
+int f(string s) { return REPLACED; }
+  )cc";
+
+  testRule(ruleStrlenSize(), Input, Expected);
+}
+
+// No rewrite is applied when the changed text does not encompass the entirety
+// of the expanded text. That is, the edit would have to be applied to the
+// macro's definition to succeed and editing the expansion point would not
+// suffice.
+TEST_F(TransformerTest, NoPartialRewriteOMacroExpansion) 

[PATCH] D64518: [LibTooling] Relax Transformer to allow rewriting macro expansions

2019-07-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 2 inline comments as done.
ymandel added a comment.

In D64518#1585917 , @ilya-biryukov 
wrote:

> This clearly increases the utility of the library, but also seems to add 
> corner cases that the library won't handle (see the comment about unittests 
> for an example).
>  WDYT about those? Are they important, should we support producing warnings 
> in those cases to let the users know things might get broken?


That's a really good question.  The code explicitly chooses to treat these 
failures like "this didn't match" rather than "this matched and now there's an 
error".  That reflects the split that some users will want to know while others 
will want the system to always skip such matches, just like it skips 
non-matching expressions.

This seems like a good candidate for configuration -- the user could then 
choose which mode to run in.  But, I'm also open to just reporting these 
conditions as errors.  It's already in a context that returns Expected, so its 
no trouble; it's just a matter of choosing what we think is "correct".




Comment at: clang/lib/Tooling/Refactoring/Transformer.cpp:76
+static llvm::Optional
+makeValidRange(CharSourceRange Range, const MatchResult ) {
+  const SourceManager  = *Result.SourceManager;

ilya-biryukov wrote:
> Could we add unit tests for this particular function?
> 
> Interesting cases (`[[` and `]]` mark the start and end of a range):
> ```
> #define FOO(a) a+a;
> #define BAR 10+
> 
> // change part of a macro argument
> int a = FOO([[10]] + 10);
> 
> // change the whole macro expansion
> int b = [[FOO(10+10)]];
> 
> // Try to change 10 inside 'BAR', but not '+'.
> // Should this fail? Should we give a warning?
> int c = BAR 3; 
> 
> // Try changing the lhs (10) of a binary expr, but not rhs.
> // Is that allowed? Should we give a warning?
> int d = FOO(10);
> ```
Sure. What do you think of exposing this function in 
clang/include/clang/Tooling/Refactoring/SourceCode.h and testing it from there?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64518/new/

https://reviews.llvm.org/D64518



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


[PATCH] D64780: Disallow most calling convention attributes on PS4.

2019-07-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'm fine with the idea of targets making unsupported CCs hard errors.




Comment at: test/Sema/no_callconv.cpp:44
+void __attribute__((sysv_abi)) funcI() {}
+void __attribute__((cdecl)) funcC() {}

Please include a newline at the end of this file.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64780/new/

https://reviews.llvm.org/D64780



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


[PATCH] D64804: [OpenCL][Sema] Minor refactoring and constraint checking

2019-07-16 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.

Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64804/new/

https://reviews.llvm.org/D64804



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


[PATCH] D64644: Fixes an assertion failure while instantiation a template with an incomplete typo corrected type

2019-07-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 210146.
Mordante added a comment.

Remove the includes from the test.
Changed the `std::is_constructible` to `is_same` since the latter is easier to 
mock.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64644/new/

https://reviews.llvm.org/D64644

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp


Index: 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,60 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | 
FileCheck %s
+
+// Test case to test the error in https://bugs.llvm.org/show_bug.cgi?id=35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+template  class allocator;
+
+template  struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template  struct enable_if {};
+template  struct enable_if { typedef Tp type; };
+
+template  struct integral_constant {
+  static constexpr const Tp value = v;
+  typedef Tp value_type;
+  typedef integral_constant type;
+
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
+};
+
+template  constexpr const Tp integral_constant::value;
+
+using true_type = integral_constant;
+using false_type = integral_constant;
+
+template  struct is_same : public false_type {};
+template  struct is_same : public true_type {};
+
+template  struct single {
+  typedef T first_type;
+
+  T first;
+
+  struct CheckArgs {
+template  static constexpr bool enable_implicit() {
+  return is_same::value;
+}
+  };
+
+  template (),
+   bool>::type = false>
+  single(U1 &);
+};
+
+using SetKeyType = String;
+single v;
+
+// CHECK: error: unknown type name 'String'; did you mean 'string'?
+// CHECK: fatal error: too many errors emitted, stopping now [-ferror-limit=]
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -718,9 +718,14 @@
 SourceLocation TemplateKWLoc,
 const DeclarationNameInfo ,
 const TemplateArgumentListInfo *TemplateArgs) {
+  // DependentScopeDeclRefExpr::Create requires a valid QualifierLoc
+  // See https://bugs.llvm.org/show_bug.cgi?id=35682
+  NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
+  if (!QualifierLoc)
+return ExprError();
+
   return DependentScopeDeclRefExpr::Create(
-  Context, SS.getWithLocInContext(Context), TemplateKWLoc, NameInfo,
-  TemplateArgs);
+  Context, std::move(QualifierLoc), TemplateKWLoc, NameInfo, TemplateArgs);
 }
 
 


Index: clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,60 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | FileCheck %s
+
+// Test case to test the error in https://bugs.llvm.org/show_bug.cgi?id=35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+template  class allocator;
+
+template  struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template  struct enable_if {};
+template  struct enable_if { typedef Tp type; };
+
+template  struct integral_constant {
+  static constexpr const Tp value = v;
+  typedef Tp value_type;
+  typedef integral_constant type;
+
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
+};
+
+template  constexpr const Tp integral_constant::value;
+
+using true_type = integral_constant;
+using false_type = integral_constant;
+
+template  struct is_same : public false_type {};
+template  struct is_same : public true_type {};
+
+template  struct single {
+  typedef T first_type;
+
+  T first;
+
+  struct CheckArgs {
+template  static constexpr bool enable_implicit() {
+  return 

[PATCH] D64736: [clang-tidy] New bugprone-infinite-loop check for detecting obvious infinite loops

2019-07-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added reviewers: JonasToth, gribozavr.
lebedev.ri added a comment.

Thanks.
Are there any tests missing for `volatile`, atomics?
I'm not really current on clang-tidy state of affairs, so i'm gonna leave most 
of the review for others..




Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:21
+static internal::Matcher loopEndingStmt() {
+  return stmt(anyOf(breakStmt(), returnStmt(), gotoStmt(), cxxThrowExpr()));
+}

What about function calls marked `noreturn`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64736/new/

https://reviews.llvm.org/D64736



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


Re: r366076 - fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic

2019-07-16 Thread Yonghong Song via cfe-commits


On 7/16/19 11:03 AM, Nick Desaulniers wrote:
> On Tue, Jul 16, 2019 at 11:02 AM Nick Desaulniers
>  wrote:
>>
>> On Mon, Jul 15, 2019 at 5:13 PM Eric Christopher  wrote:
>>>
>>> I'm going to cheat and make Nick do it :)
>>
>> I suspect that Eric still compiles LLVM by specifying all object files
>> in order on the command line and doesn't want to talk about it on
>> cfe-commits. :) Though, even I'm behind the times as I think the cool
>> kids are using "gn" these days?  I'm so out of touch.
>>
>>> On Mon, Jul 15, 2019 at 5:12 PM Yonghong Song  wrote:
 I just tried the following cmake (removing -DLLVM_ENABLE_ASSERTIONS=ON 
 which is used in my previous build)

 cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
  -DCMAKE_C_COMPILER=/llvm8/bin/clang \
  -DCMAKE_CXX_COMPILER=/llvm8/bin/clang++ \
  -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..

 and cannot reproduce the issue. If you could send me the cmake
 command line which caused failure in your environment. That will
 be great!
>>
>> I did:
>> $ cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
>> -DCMAKE_C_COMPILER=
>> -DCMAKE_CXX_COMPILER=
>> -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_PROJECTS="clang;lld"
>> -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86"
>>
>> I sometimes add:
>> -DLLVM_ENABLE_ASSERTIONS=ON
>> which hopefully gets cleared when rerunning cmake, but I wouldn't bet
>> my life on that. (Looks like it's OFF in my CMakeCache.txt, so I guess
>> I could've taken that bet).
> 
> Forgot to mention that jdoerfert also mentioned on IRC yesterday that
> -DLLVM_ENABLE_ASSERTIONS=ON can influence Clang's codegen of LLVM IR.

Thanks, Nick. Will give your cmake a try and keep in mind that
testing both LLVM_ENABLE_ASSERTIONS ON/OFF for clang changes.

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


[PATCH] D48680: Add missing visibility annotation for __base

2019-07-16 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

In D48680#1587967 , @ldionne wrote:

> @pcc In your reproducer, what is `~/l3/ra-cmake/bin/clang++`?


That's just clang built from trunk at the time that I posted my comment.

> Are you able to reproduce without `-fuse-ld=lld`? I'm trying to reproduce 
> locally but I can't.

On which platform? On Linux lld (or gold) is needed in order to use LTO which 
is a requirement for CFI.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48680/new/

https://reviews.llvm.org/D48680



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


Re: r366076 - fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic

2019-07-16 Thread Nick Desaulniers via cfe-commits
On Tue, Jul 16, 2019 at 11:02 AM Nick Desaulniers
 wrote:
>
> On Mon, Jul 15, 2019 at 5:13 PM Eric Christopher  wrote:
> >
> > I'm going to cheat and make Nick do it :)
>
> I suspect that Eric still compiles LLVM by specifying all object files
> in order on the command line and doesn't want to talk about it on
> cfe-commits. :) Though, even I'm behind the times as I think the cool
> kids are using "gn" these days?  I'm so out of touch.
>
> > On Mon, Jul 15, 2019 at 5:12 PM Yonghong Song  wrote:
> > > I just tried the following cmake (removing -DLLVM_ENABLE_ASSERTIONS=ON 
> > > which is used in my previous build)
> > >
> > > cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
> > > -DCMAKE_C_COMPILER=/llvm8/bin/clang \
> > > -DCMAKE_CXX_COMPILER=/llvm8/bin/clang++ \
> > > -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
> > > -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..
> > >
> > > and cannot reproduce the issue. If you could send me the cmake
> > > command line which caused failure in your environment. That will
> > > be great!
>
> I did:
> $ cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
> -DCMAKE_C_COMPILER=
> -DCMAKE_CXX_COMPILER=
> -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_PROJECTS="clang;lld"
> -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86"
>
> I sometimes add:
> -DLLVM_ENABLE_ASSERTIONS=ON
> which hopefully gets cleared when rerunning cmake, but I wouldn't bet
> my life on that. (Looks like it's OFF in my CMakeCache.txt, so I guess
> I could've taken that bet).

Forgot to mention that jdoerfert also mentioned on IRC yesterday that
-DLLVM_ENABLE_ASSERTIONS=ON can influence Clang's codegen of LLVM IR.
-- 
Thanks,
~Nick Desaulniers
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r366076 - fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic

2019-07-16 Thread Nick Desaulniers via cfe-commits
On Mon, Jul 15, 2019 at 5:13 PM Eric Christopher  wrote:
>
> I'm going to cheat and make Nick do it :)

I suspect that Eric still compiles LLVM by specifying all object files
in order on the command line and doesn't want to talk about it on
cfe-commits. :) Though, even I'm behind the times as I think the cool
kids are using "gn" these days?  I'm so out of touch.

> On Mon, Jul 15, 2019 at 5:12 PM Yonghong Song  wrote:
> > I just tried the following cmake (removing -DLLVM_ENABLE_ASSERTIONS=ON 
> > which is used in my previous build)
> >
> > cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
> > -DCMAKE_C_COMPILER=/llvm8/bin/clang \
> > -DCMAKE_CXX_COMPILER=/llvm8/bin/clang++ \
> > -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
> > -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..
> >
> > and cannot reproduce the issue. If you could send me the cmake
> > command line which caused failure in your environment. That will
> > be great!

I did:
$ cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
-DCMAKE_C_COMPILER=
-DCMAKE_CXX_COMPILER=
-DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_PROJECTS="clang;lld"
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86"

I sometimes add:
-DLLVM_ENABLE_ASSERTIONS=ON
which hopefully gets cleared when rerunning cmake, but I wouldn't bet
my life on that. (Looks like it's OFF in my CMakeCache.txt, so I guess
I could've taken that bet).

-- 
Thanks,
~Nick Desaulniers
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64811: Warn when NumParams overflows

2019-07-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: rsmith, rjmccall.
Mordante added a project: clang.

Before when the overflow occurred an assertion was triggered. Now check whether 
the maximum has been reached and warn properly.

This patch fixes bug 33162 which is marked as 'duplicate' of bug 19607. The 
original part of bug 19607 is fixed by D63975 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64811

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/function_parameter_overflow.cpp
  clang/test/Parser/lambda_function_parameter_overflow.cpp
  clang/test/Parser/parameter_overflow.h

Index: clang/test/Parser/parameter_overflow.h
===
--- /dev/null
+++ clang/test/Parser/parameter_overflow.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#define I10 int, int, int, int, int, int, int, int, int, int
+#define I50 I10, I10, I10, I10, I10
+#define I500 I50, I50, I50, I50, I50, I50, I50, I50, I50, I50
+#define I5000 I500, I500, I500, I500, I500, I500, I500, I500, I500, I500
+#define I6 I5000, I5000, I5000, I5000, I5000, I5000, I5000, I5000, I5000, I5000, I5000, I5000
+
+#define  I65535 I6, I5000, I500, I10, I10, I10, int, int, int, int, int
Index: clang/test/Parser/lambda_function_parameter_overflow.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda_function_parameter_overflow.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: not %clang_cc1 %s -fsyntax-only -DFAIL 2>&1 | FileCheck %s
+
+#include "parameter_overflow.h"
+
+auto foo = [](I65535
+#ifdef FAIL
+, int
+#endif
+){};
+// CHECK: fatal error: number of function parameters exceeded maximum of 65535
Index: clang/test/Parser/function_parameter_overflow.cpp
===
--- /dev/null
+++ clang/test/Parser/function_parameter_overflow.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: not %clang_cc1 %s -fsyntax-only -DFAIL 2>&1 | FileCheck %s
+
+#include "parameter_overflow.h"
+
+void foo(I65535
+#ifdef FAIL
+, int
+#endif
+);
+// CHECK: fatal error: number of function parameters exceeded maximum of 65535
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1265,6 +1265,14 @@
 
   ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc);
 
+  // If the parameters could not be parsed stop processing. Proceeding is
+  // not an issue when the maximum scope depth is exceeded. But when the
+  // maximum number of parameters is exceeded the processing will still hit
+  // the assertion in FunctionProtoType's constructor.
+  // See https://bugs.llvm.org/show_bug.cgi?id=19607
+  if (Tok.is(tok::eof))
+return ExprError();
+
   // For a generic lambda, each 'auto' within the parameter declaration
   // clause creates a template type parameter, so increment the depth.
   // If we've parsed any explicit template parameters, then the depth will
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -6668,6 +6668,15 @@
 
 // If the next token is a comma, consume it and keep reading arguments.
   } while (TryConsumeToken(tok::comma));
+
+  // Avoid exceeding the maximum function parameters
+  // See https://bugs.llvm.org/show_bug.cgi?id=19607
+  if (ParamInfo.size() > Type::getMaxNumParams()) {
+Diag(ParamInfo[Type::getMaxNumParams() - 1].IdentLoc,
+ diag::err_number_of_function_parameters_exceeded)
+<< Type::getMaxNumParams();
+cutOffParsing();
+  }
 }
 
 /// [C90]   direct-declarator '[' constant-expression[opt] ']'
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -326,6 +326,8 @@
 def err_argument_required_after_attribute : Error<
   "argument required after attribute">;
 def err_missing_param : Error<"expected parameter declarator">;
+def err_number_of_function_parameters_exceeded : Error<
+  "number of function parameters exceeded maximum of %0">, DefaultFatal;
 def err_missing_comma_before_ellipsis : Error<
   "C requires a comma prior to the ellipsis in a variadic function type">;
 def err_unexpected_typedef_ident : Error<
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1520,6 +1520,8 @@
 unsigned Kind : 8;
   };
 
+  enum { 

[PATCH] D48680: Add missing visibility annotation for __base

2019-07-16 Thread Louis Dionne via Phabricator via cfe-commits
ldionne requested changes to this revision.
ldionne added a comment.
This revision now requires changes to proceed.
Herald added a subscriber: dexonsmith.

@pcc In your reproducer, what is `~/l3/ra-cmake/bin/clang++`? Are you able to 
reproduce without `-fuse-ld=lld`? I'm trying to reproduce locally but I can't.

I know this is a small change, but I'd like to understand why it's needed since 
I suspect it may uncover other places where visibility is wrong -- if the 
problem is really on libc++'s side.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48680/new/

https://reviews.llvm.org/D48680



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


[PATCH] D48680: Add missing visibility annotation for __base

2019-07-16 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

I think it would be up to the libc++ maintainers to approve the patch.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48680/new/

https://reviews.llvm.org/D48680



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


[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

2019-07-16 Thread Steve Canon via Phabricator via cfe-commits
scanon accepted this revision.
scanon added a comment.
This revision is now accepted and ready to land.

LGTM. Please get at least one additional reviewer's approval before merging, as 
this is a corner of clang that I don't work on often.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64666/new/

https://reviews.llvm.org/D64666



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


Re: r366123 - ARM MTE stack sanitizer.

2019-07-16 Thread Evgenii Stepanov via cfe-commits
Hi,

thanks for letting me know! Is this reproducible on Linux? It is
possible to extract a reproducer from the bot?

On Mon, Jul 15, 2019 at 9:30 PM Amara Emerson  wrote:
>
> Hi Evgeniy,
>
> This commit looks like it broke the lldb bot: 
> http://green.lab.llvm.org/green/job/lldb-cmake/31011/
>
> Can you take a look?
>
> Amara
>
> On Jul 15, 2019, at 1:02 PM, Evgeniy Stepanov via cfe-commits 
>  wrote:
>
> Author: eugenis
> Date: Mon Jul 15 13:02:23 2019
> New Revision: 366123
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366123=rev
> Log:
> ARM MTE stack sanitizer.
>
> Add "memtag" sanitizer that detects and mitigates stack memory issues
> using armv8.5 Memory Tagging Extension.
>
> It is similar in principle to HWASan, which is a software implementation
> of the same idea, but there are enough differencies to warrant a new
> sanitizer type IMHO. It is also expected to have very different
> performance properties.
>
> The new sanitizer does not have a runtime library (it may grow one
> later, along with a "debugging" mode). Similar to SafeStack and
> StackProtector, the instrumentation pass (in a follow up change) will be
> inserted in all cases, but will only affect functions marked with the
> new sanitize_memtag attribute.
>
> Reviewers: pcc, hctim, vitalybuka, ostannard
>
> Subscribers: srhines, mehdi_amini, javed.absar, kristof.beyls, hiraditya, 
> cryptoad, steven_wu, dexonsmith, cfe-commits, llvm-commits
>
> Tags: #clang, #llvm
>
> Differential Revision: https://reviews.llvm.org/D64169
>
> Added:
>cfe/trunk/test/CodeGen/memtag-attr.cpp
>cfe/trunk/test/Lexer/has_feature_memtag_sanitizer.cpp
> Modified:
>cfe/trunk/include/clang/Basic/Features.def
>cfe/trunk/include/clang/Basic/Sanitizers.def
>cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>cfe/trunk/lib/CodeGen/SanitizerMetadata.cpp
>cfe/trunk/lib/Driver/SanitizerArgs.cpp
>cfe/trunk/lib/Driver/ToolChains/Linux.cpp
>cfe/trunk/test/Driver/fsanitize.c
>cfe/trunk/test/SemaCXX/attr-no-sanitize.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Features.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=366123=366122=366123=diff
> ==
> --- cfe/trunk/include/clang/Basic/Features.def (original)
> +++ cfe/trunk/include/clang/Basic/Features.def Mon Jul 15 13:02:23 2019
> @@ -42,6 +42,7 @@ FEATURE(address_sanitizer,
> FEATURE(hwaddress_sanitizer,
> LangOpts.Sanitize.hasOneOf(SanitizerKind::HWAddress |
>SanitizerKind::KernelHWAddress))
> +FEATURE(memtag_sanitizer, LangOpts.Sanitize.has(SanitizerKind::MemTag))
> FEATURE(xray_instrument, LangOpts.XRayInstrument)
> FEATURE(undefined_behavior_sanitizer,
> LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
>
> Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=366123=366122=366123=diff
> ==
> --- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
> +++ cfe/trunk/include/clang/Basic/Sanitizers.def Mon Jul 15 13:02:23 2019
> @@ -55,6 +55,9 @@ SANITIZER("hwaddress", HWAddress)
> // Kernel Hardware-assisted AddressSanitizer (KHWASan)
> SANITIZER("kernel-hwaddress", KernelHWAddress)
>
> +// A variant of AddressSanitizer using AArch64 MTE extension.
> +SANITIZER("memtag", MemTag)
> +
> // MemorySanitizer
> SANITIZER("memory", Memory)
>
>
> Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=366123=366122=366123=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 15 13:02:23 2019
> @@ -369,6 +369,10 @@ llvm::Function *CodeGenModule::CreateGlo
>   !isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc))
> Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
>
> +  if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) &&
> +  !isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc))
> +Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
> +
>   if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
>   !isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc))
> Fn->addFnAttr(llvm::Attribute::SanitizeThread);
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=366123=366122=366123=diff
> ==
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Jul 15 13:02:23 2019
> @@ -696,6 +696,8 @@ void 

[PATCH] D48680: Add missing visibility annotation for __base

2019-07-16 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@pcc can you please submit this patch if there are no objections?


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48680/new/

https://reviews.llvm.org/D48680



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


[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGClass.cpp:2016
   CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*for vbase*/ false,
-/*Delegating=*/false, addr);
+/*Delegating=*/false, addr, type);
 }

mantognini wrote:
> rjmccall wrote:
> > mantognini wrote:
> > > This is the only place where the new parameter has an interesting value. 
> > > In the ~10 other calls to `EmitCXXDestructorCall` overloads, the default 
> > > value of this new parameter is used instead.
> > Arguments that are potentially required for correctness — as opposed to 
> > just enabling some optimization — should generally not have defaults.  I 
> > think you should remove these defaults and require a sensible type to be 
> > passed down in all cases.
> I've addressed that. I had to add some extra parameter/attributes here and 
> there. Please let me know if anything is can be improved.
Thanks, other than the FIXMEs and the object/pointer mismatches this all looks 
right; very nicely done.



Comment at: clang/lib/CodeGen/CGClass.cpp:496
+  // destroyed should have the expected type.
+  QualType ThisTy = D->getThisType();
   Address Addr =

I think the rule we want is that the type passed here is the (qualified) object 
type, but `getThisType()` will return a pointer type.  Consider adding a 
`getThisObjectType()` method to `CXXMethodDecl` which does that computation 
(and then make `getThisType()` just wrap that in a `PointerType`).



Comment at: clang/lib/CodeGen/CGClass.cpp:1447
+if (HaveInsertPoint()) {
+  // FIXME: Determine the type of the object being destroyed.
+  QualType ThisTy;

mantognini wrote:
> I'm not familiar enough with CXXCtorType and such, and would welcome some 
> help for these two FIXMEs.
`Dtor->getThisObjectType()` should be right in both of these cases.



Comment at: clang/lib/CodeGen/CGClass.cpp:2376
+  // Therefore, "this" should have the expected type.
+  QualType ThisTy = Dtor->getThisType();
   CGF.EmitCXXDestructorCall(Dtor, Type, /*ForVirtualBase=*/false,

Same thing about `getThisObjectType()`.



Comment at: clang/lib/CodeGen/CGExprCXX.cpp:103
+  // we ensure a cast is added where necessary.
+  if (ThisTy.isNull()) {
+#ifndef NDEBUG

mantognini wrote:
> Despite no longer having a default parameter, not all call site can provide a 
> meaningful value ATM. That is why this check is still required.
Is that resolved with fixing the FIXME?

Please assert that `ThisTy->getAsCXXRecordDecl() == Dtor->getParent()` to guard 
against that pointer/object mixup.



Comment at: clang/lib/CodeGen/CGExprCXX.cpp:374
   EmitCXXDestructorCall(GD, Callee, This.getPointer(),
+/*ThisTy=*/QualType(),
 /*ImplicitParam=*/nullptr,

`ThisTy` here can be either `Base->getType()` or 
`Base->getType()->getPointeeType()` depending on whether this is an arrow 
access.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1758
+  // This is suboptimal for correctness purposes. Instead, CE should probably
+  // always be defined.
+  QualType ThisTy;

It looks like the only places that pass down a null CE are the two 
implementations in `emitVirtualObjectDelete`, which both have a 
`CXXDeleteExpr`.  You could just have this method take an 
`llvm::PointerUnion` or something, and then 
someone else could take advantage of that for better source locations on the 
virtual call eventually.



Comment at: clang/lib/CodeGen/MicrosoftCXXABI.cpp:1928
+  if (CE)
+ThisTy = CE->getImplicitObjectArgument()->getType();
+

Same point as in the ItaniumCXXABI implementation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64569/new/

https://reviews.llvm.org/D64569



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


[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

2019-07-16 Thread Ziang Wan via Phabricator via cfe-commits
ziangwan marked an inline comment as done.
ziangwan added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:11429
+  S.Context.getFloatTypeSemantics(QualType(TargetBT, 0)));
+TargetFloatValue.convertFromAPInt(SourceInt,
+  SourceBT->isSignedInteger(), llvm::APFloat::rmNearestTiesToEven);

scanon wrote:
> Why don't we just check that the result of the first conversion is opOK? I 
> don't think doing a round-trip check is required here.
I have changed the code to check the status of the first conversion only. 
Please review it again.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64666/new/

https://reviews.llvm.org/D64666



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


[PATCH] D64089: [Driver] Introduce -stdlib++-isystem

2019-07-16 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1307
+  HasStdlibxxIsystem ? TC.AddClangCXXStdlibIsystemArgs(Args, CmdArgs)
+ : TC.AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
+});

So, before, we would populate `-stdlib=XXX` here unconditionally for `cc1`.

After the patch, we do _not_ populate `-stdlib=XXX` and instead we pass 
`-internal-isystem` to `cc1` with the contents of `-stdlib++-isystem` whenever 
that option is provided, otherwise we fall back to the previous behaviour.

Did I get that right? If so, could we investigate getting rid of 
`AddClangCXXStdlibIncludeArgs` altogether? I don't think it is needed anymore 
since my refactor of the driver for Darwin.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64089/new/

https://reviews.llvm.org/D64089



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


Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

2019-07-16 Thread Shoaib Meenai via cfe-commits
Makes sense, thanks. Seems like INTERFACE is the way to go then.

From:  on behalf of Chris Bieneman 
Date: Tuesday, July 16, 2019 at 10:32 AM
To: Shoaib Meenai 
Cc: Alex Bradbury , cfe-commits 
Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

I get that CMake does something different for PRIVATE, but the way we use CMake 
in LLVM we really can't make a private distinction reasonable. Because we don't 
sub-divide our headers per library, we don't support per-dependency include 
paths in LLVM or Clang's libraries.

This behavior also assumes you are using `target_include_directories` to assign 
PRIVATE | PUBLIC | INTERFACE to include directories, which we don't generally 
do in LLVM (a quick grep showed one place in LLVM code excluding our google 
benchmark drop). We do generally use `include_directories` which always treats 
things as PRIVATE, so they don't cascade to dependencies.

-Chris


On Jul 12, 2019, at 7:16 PM, Shoaib Meenai 
mailto:smee...@fb.com>> wrote:

I struggled for a while thinking why PRIVATE might be useful in a 
target_link_libraries call for a shared library, and then I found 
https://cmake.org/pipermail/cmake/2016-May/063400.html.
 The relevant bit is:

If you were paying careful attention, you would have noticed that when A
links in B as PRIVATE, the include directories of B never propagate to
something linking to A, but if A is a static library, then the *linking* of
B behaves as though the relationship was PUBLIC. This
PRIVATE-becomes-PUBLIC behaviour for static libraries only applies to the
*linking*, not to the other dependencies (compiler options/flags and
include search paths).

So PRIVATE/INTERFACE/PUBLIC doesn’t make any difference as far as the actual 
linking goes, but it does affect propagation of other options, and I think it’s 
valid to want to have a PRIVATE dependency for a static library.

From: mailto:cbiene...@apple.com>> on behalf of Chris 
Bieneman mailto:be...@apple.com>>
Date: Friday, July 12, 2019 at 9:08 AM
To: Shoaib Meenai mailto:smee...@fb.com>>
Cc: Alex Bradbury mailto:a...@lowrisc.org>>, cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

Ah! I see what is going on here. This is kinda a silliness of CMake. `PRIVATE` 
linkage for a static archive is silly, and shouldn't be possible. All link 
dependencies for static archives are really `INTERFACE` dependencies, and it 
looks like CMake is doing something kinda silly instead of producing a 
reasonable error or warning like it probably should do.

For context, `PRIVATE` linkage in the context of that change would mean 
DirectoryWalker links something, but things that link DirectoryWalker don't. 
That just isn't possible with static archives, so they become interface 
dependencies (and CMake seems to insert a generator expression to make that 
work).

In `llvm_add_library` we always use `PRIVATE` linkage for shared libraries, and 
`INTERFACE` for static, which does the right thing.

Unless there is a better reason than a new patch coming in, I think the right 
fix is to revert this back and expect the new patch to correct its linkage 
behavior.

-Chris



On Jul 12, 2019, at 8:53 AM, Shoaib Meenai 
mailto:smee...@fb.com>> wrote:

See 
https://reviews.llvm.org/D58418#1577670.
 More generally it would appear for any static library with a PRIVATE 
dependency though.

I guess an alternative would be to use the LINK_LIBRARIES property (which 
should be free of generator expressions, I believe) to propagate dependencies 
instead of INTERFACE_LINK_LIBRARIES, and just assume that no one is gonna set 
an INTERFACE dependency on a static library. (Supporting PRIVATE dependencies 
on a static library definitely seems more valuable than supporting INTERFACE 
dependencies.)

From: mailto:cbiene...@apple.com>> on behalf of Chris 
Bieneman mailto:be...@apple.com>>
Date: Friday, July 12, 2019 at 8:49 AM
To: Shoaib Meenai mailto:smee...@fb.com>>
Cc: Alex Bradbury mailto:a...@lowrisc.org>>, cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

One of the benefits of the object library approach for generating the clang 
dylib is that it was compatible with BUILD_SHARED_LIBS. We had lots of issues 
with libLLVM where people using BUILD_SHARED_LIBS would make changes that broke 
it, so I was trying to make the clang dylib in a way that it could always be 
enabled.

Do we know where the 

Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

2019-07-16 Thread Chris Bieneman via cfe-commits
I get that CMake does something different for PRIVATE, but the way we use CMake 
in LLVM we really can't make a private distinction reasonable. Because we don't 
sub-divide our headers per library, we don't support per-dependency include 
paths in LLVM or Clang's libraries.

This behavior also assumes you are using `target_include_directories` to assign 
PRIVATE | PUBLIC | INTERFACE to include directories, which we don't generally 
do in LLVM (a quick grep showed one place in LLVM code excluding our google 
benchmark drop). We do generally use `include_directories` which always treats 
things as PRIVATE, so they don't cascade to dependencies.

-Chris

> On Jul 12, 2019, at 7:16 PM, Shoaib Meenai  wrote:
> 
> I struggled for a while thinking why PRIVATE might be useful in a 
> target_link_libraries call for a shared library, and then I found 
> https://cmake.org/pipermail/cmake/2016-May/063400.html 
> . The relevant bit is:
>  
> If you were paying careful attention, you would have noticed that when A
> links in B as PRIVATE, the include directories of B never propagate to
> something linking to A, but if A is a static library, then the *linking* of
> B behaves as though the relationship was PUBLIC. This
> PRIVATE-becomes-PUBLIC behaviour for static libraries only applies to the
> *linking*, not to the other dependencies (compiler options/flags and
> include search paths).
>  
> So PRIVATE/INTERFACE/PUBLIC doesn’t make any difference as far as the actual 
> linking goes, but it does affect propagation of other options, and I think 
> it’s valid to want to have a PRIVATE dependency for a static library.
>  
> From:  on behalf of Chris Bieneman 
> Date: Friday, July 12, 2019 at 9:08 AM
> To: Shoaib Meenai 
> Cc: Alex Bradbury , cfe-commits 
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> Ah! I see what is going on here. This is kinda a silliness of CMake. 
> `PRIVATE` linkage for a static archive is silly, and shouldn't be possible. 
> All link dependencies for static archives are really `INTERFACE` 
> dependencies, and it looks like CMake is doing something kinda silly instead 
> of producing a reasonable error or warning like it probably should do.
>  
> For context, `PRIVATE` linkage in the context of that change would mean 
> DirectoryWalker links something, but things that link DirectoryWalker don't. 
> That just isn't possible with static archives, so they become interface 
> dependencies (and CMake seems to insert a generator expression to make that 
> work).
>  
> In `llvm_add_library` we always use `PRIVATE` linkage for shared libraries, 
> and `INTERFACE` for static, which does the right thing.
>  
> Unless there is a better reason than a new patch coming in, I think the right 
> fix is to revert this back and expect the new patch to correct its linkage 
> behavior.
>  
> -Chris
> 
> 
> On Jul 12, 2019, at 8:53 AM, Shoaib Meenai  > wrote:
>  
> See https://reviews.llvm.org/D58418#1577670 
> .
>  More generally it would appear for any static library with a PRIVATE 
> dependency though.
>  
> I guess an alternative would be to use the LINK_LIBRARIES property (which 
> should be free of generator expressions, I believe) to propagate dependencies 
> instead of INTERFACE_LINK_LIBRARIES, and just assume that no one is gonna set 
> an INTERFACE dependency on a static library. (Supporting PRIVATE dependencies 
> on a static library definitely seems more valuable than supporting INTERFACE 
> dependencies.)
>  
> From: mailto:cbiene...@apple.com>> on behalf of Chris 
> Bieneman mailto:be...@apple.com>>
> Date: Friday, July 12, 2019 at 8:49 AM
> To: Shoaib Meenai mailto:smee...@fb.com>>
> Cc: Alex Bradbury mailto:a...@lowrisc.org>>, cfe-commits 
> mailto:cfe-commits@lists.llvm.org>>
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> One of the benefits of the object library approach for generating the clang 
> dylib is that it was compatible with BUILD_SHARED_LIBS. We had lots of issues 
> with libLLVM where people using BUILD_SHARED_LIBS would make changes that 
> broke it, so I was trying to make the clang dylib in a way that it could 
> always be enabled.
>  
> Do we know where the nested generator expression was coming from?
>  
> -Chris
> 
> 
> 
> On Jul 12, 2019, at 8:32 AM, Shoaib Meenai  > wrote:
>  
> Oops, sorry about the breakage.
>  
> Chris, aren't BUILD_SHARED_LIBS and the combined Clang dylib incompatible? 
> Should we disable building the latter if the former is set?
>  
> From: Alex Bradbury mailto:a...@lowrisc.org>>
> Date: Friday, July 12, 2019 at 2:02 AM
> To: Shoaib Meenai 

[PATCH] D62584: [OpenCL][PR42033] Deducing addr space with template parameter types

2019-07-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Minor comment then LGTM




Comment at: lib/Sema/SemaType.cpp:7418
+  // Expect for pointer or reference types because the addr space in
+  // template argument can only belong to a pointee.
+  (T->isDependentType() && !T->isPointerType() && !T->isReferenceType()) ||

"Except"


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62584/new/

https://reviews.llvm.org/D62584



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


r366231 - fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic

2019-07-16 Thread Yonghong Song via cfe-commits
Author: yhs
Date: Tue Jul 16 10:24:33 2019
New Revision: 366231

URL: http://llvm.org/viewvc/llvm-project?rev=366231=rev
Log:
fix unnamed fiefield issue and add tests for __builtin_preserve_access_index 
intrinsic

The original commit is r366076. It is temporarily reverted (r366155)
due to test failure. This resubmit makes test more robust by accepting
regex instead of hardcoded names/references in several places.

This is a followup patch for https://reviews.llvm.org/D61809.
Handle unnamed bitfield properly and add more test cases.

Fixed the unnamed bitfield issue. The unnamed bitfield is ignored
by debug info, so we need to ignore such a struct/union member
when we try to get the member index in the debug info.

D61809 contains two test cases but not enough as it does
not checking generated IRs in the fine grain level, and also
it does not have semantics checking tests.
This patch added unit tests for both code gen and semantics checking for
the new intrinsic.

Signed-off-by: Yonghong Song 

Added:
cfe/trunk/test/CodeGen/builtin-preserve-access-index.c
cfe/trunk/test/Sema/builtin-preserve-access-index.c
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=366231=366230=366231=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Jul 16 10:24:33 2019
@@ -3892,6 +3892,23 @@ LValue CodeGenFunction::EmitLValueForLam
   return EmitLValueForField(LambdaLV, Field);
 }
 
+/// Get the field index in the debug info. The debug info structure/union
+/// will ignore the unnamed bitfields.
+unsigned CodeGenFunction::getDebugInfoFIndex(const RecordDecl *Rec,
+ unsigned FieldIndex) {
+  unsigned I = 0, Skipped = 0;
+
+  for (auto F : Rec->getDefinition()->fields()) {
+if (I == FieldIndex)
+  break;
+if (F->isUnnamedBitfield())
+  Skipped++;
+I++;
+  }
+
+  return FieldIndex - Skipped;
+}
+
 /// Get the address of a zero-sized field within a record. The resulting
 /// address doesn't necessarily have the right type.
 static Address emitAddrOfZeroSizeField(CodeGenFunction , Address Base,
@@ -3931,7 +3948,7 @@ static Address emitPreserveStructAccess(
   CGF.CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
 
   return CGF.Builder.CreatePreserveStructAccessIndex(
-  base, idx, field->getFieldIndex(), DbgInfo);
+  base, idx, CGF.getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo);
 }
 
 static bool hasAnyVptr(const QualType Type, const ASTContext ) {
@@ -4048,7 +4065,7 @@ LValue CodeGenFunction::EmitLValueForFie
   getContext().getRecordType(rec), rec->getLocation());
   addr = Address(
   Builder.CreatePreserveUnionAccessIndex(
-  addr.getPointer(), field->getFieldIndex(), DbgInfo),
+  addr.getPointer(), getDebugInfoFIndex(rec, 
field->getFieldIndex()), DbgInfo),
   addr.getAlignment());
 }
   } else {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=366231=366230=366231=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Jul 16 10:24:33 2019
@@ -2652,6 +2652,9 @@ public:
   /// Converts Location to a DebugLoc, if debug information is enabled.
   llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
 
+  /// Get the record field index as represented in debug info.
+  unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex);
+
 
   
//======//
   //Declaration Emission

Added: cfe/trunk/test/CodeGen/builtin-preserve-access-index.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-preserve-access-index.c?rev=366231=auto
==
--- cfe/trunk/test/CodeGen/builtin-preserve-access-index.c (added)
+++ cfe/trunk/test/CodeGen/builtin-preserve-access-index.c Tue Jul 16 10:24:33 
2019
@@ -0,0 +1,177 @@
+// RUN: %clang -target x86_64 -emit-llvm -S -g %s -o - | FileCheck %s
+
+#define _(x) (__builtin_preserve_access_index(x))
+
+const void *unit1(const void *arg) {
+  return _(arg);
+}
+// CHECK: define dso_local i8* @unit1
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: llvm.preserve.struct.access.index
+// CHECK-NOT: llvm.preserve.union.access.index
+
+const void *unit2(void) {
+  return _((const void *)0xULL);
+}
+// CHECK: define dso_local i8* @unit2
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: 

[PATCH] D64644: Fixes an assertion failure while instantiation a template with an incomplete typo corrected type

2019-07-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp:9-10
+
+#include 
+#include 
+

Please don't pull in any external headers - just mock what you need.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64644/new/

https://reviews.llvm.org/D64644



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


[PATCH] D64644: Fixes an assertion failure while instantiation a template with an incomplete typo corrected type

2019-07-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 210128.
Mordante marked an inline comment as done.
Mordante retitled this revision from "Fixes a clang frontend assertion failure 
(bug 35682)" to "Fixes an assertion failure while instantiation a template with 
an incomplete typo corrected type".
Mordante edited the summary of this revision.
Mordante added a comment.

Fixes @lebedev.ri's remark and adds the requested test.
While working on the test I discovered the initial assumption in bug 35682 was 
incorrect. Updated the title and summary accordingly.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64644/new/

https://reviews.llvm.org/D64644

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp


Index: 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,47 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | 
FileCheck %s
+
+// Test case to test the error in https://bugs.llvm.org/show_bug.cgi?id=35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+#include 
+#include 
+
+template 
+class allocator;
+
+template 
+struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template 
+struct single {
+  typedef T first_type;
+
+  T first;
+
+  struct CheckArgs {
+template 
+static constexpr bool enable_implicit() {
+  return std::is_constructible::value;
+}
+  };
+
+  template (),
+bool>::type = false>
+  single(U1 &) : first(std::forward(u1)) {}
+};
+
+using SetKeyType = String;
+single v;
+
+// CHECK: error: unknown type name 'String'; did you mean 'string'?
+// CHECK: fatal error: too many errors emitted, stopping now [-ferror-limit=]
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -718,9 +718,14 @@
 SourceLocation TemplateKWLoc,
 const DeclarationNameInfo ,
 const TemplateArgumentListInfo *TemplateArgs) {
+  // DependentScopeDeclRefExpr::Create requires a valid QualifierLoc
+  // See https://bugs.llvm.org/show_bug.cgi?id=35682
+  NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
+  if (!QualifierLoc)
+return ExprError();
+
   return DependentScopeDeclRefExpr::Create(
-  Context, SS.getWithLocInContext(Context), TemplateKWLoc, NameInfo,
-  TemplateArgs);
+  Context, std::move(QualifierLoc), TemplateKWLoc, NameInfo, TemplateArgs);
 }
 
 


Index: clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,47 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | FileCheck %s
+
+// Test case to test the error in https://bugs.llvm.org/show_bug.cgi?id=35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+#include 
+#include 
+
+template 
+class allocator;
+
+template 
+struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template 
+struct single {
+  typedef T first_type;
+
+  T first;
+
+  struct CheckArgs {
+template 
+static constexpr bool enable_implicit() {
+  return std::is_constructible::value;
+}
+  };
+
+  template (),
+bool>::type = false>
+  single(U1 &) : first(std::forward(u1)) {}
+};
+
+using SetKeyType = String;
+single v;
+
+// CHECK: error: unknown type name 'String'; did you mean 'string'?
+// CHECK: fatal error: too many errors emitted, stopping now [-ferror-limit=]
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -718,9 +718,14 @@
 SourceLocation TemplateKWLoc,
 const DeclarationNameInfo ,
 

[PATCH] D63648: [Preprocessor] Honor absolute paths in diagnostics

2019-07-16 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

Ping!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63648/new/

https://reviews.llvm.org/D63648



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


[PATCH] D64804: [OpenCL][Sema] Minor refactoring and constraint checking

2019-07-16 Thread Marco Antognini via Phabricator via cfe-commits
mantognini added reviewers: Anastasia, rjmccall.
mantognini added a comment.

This should address the minor refactoring requesting in D64083 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64804/new/

https://reviews.llvm.org/D64804



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


[PATCH] D64804: [OpenCL][Sema] Minor refactoring and constraint checking

2019-07-16 Thread Marco Antognini via Phabricator via cfe-commits
mantognini created this revision.
Herald added subscribers: cfe-commits, Anastasia, yaxunl.
Herald added a project: clang.

Simplify code a bit and add assertion to address post-landing comments
from D64083 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64804

Files:
  clang/lib/Sema/SemaExprCXX.cpp


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4216,17 +4216,12 @@
 break;
 
   case ICK_Block_Pointer_Conversion: {
-QualType LHSType = Context.getCanonicalType(ToType).getUnqualifiedType();
-QualType RHSType = Context.getCanonicalType(FromType).getUnqualifiedType();
-
-// Assumptions based on Sema::IsBlockPointerConversion.
-assert(isa(LHSType) && "BlockPointerType expected");
-assert(isa(RHSType) && "BlockPointerType expected");
-
 LangAS AddrSpaceL =
-LHSType->getAs()->getPointeeType().getAddressSpace();
+ToType->castAs()->getPointeeType().getAddressSpace();
 LangAS AddrSpaceR =
-RHSType->getAs()->getPointeeType().getAddressSpace();
+
FromType->castAs()->getPointeeType().getAddressSpace();
+assert(Qualifiers::isAddressSpaceSupersetOf(AddrSpaceL, AddrSpaceR) &&
+   "Invalid cast");
 CastKind Kind =
 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
 From = ImpCastExprToType(From, ToType.getUnqualifiedType(), Kind,


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4216,17 +4216,12 @@
 break;
 
   case ICK_Block_Pointer_Conversion: {
-QualType LHSType = Context.getCanonicalType(ToType).getUnqualifiedType();
-QualType RHSType = Context.getCanonicalType(FromType).getUnqualifiedType();
-
-// Assumptions based on Sema::IsBlockPointerConversion.
-assert(isa(LHSType) && "BlockPointerType expected");
-assert(isa(RHSType) && "BlockPointerType expected");
-
 LangAS AddrSpaceL =
-LHSType->getAs()->getPointeeType().getAddressSpace();
+ToType->castAs()->getPointeeType().getAddressSpace();
 LangAS AddrSpaceR =
-RHSType->getAs()->getPointeeType().getAddressSpace();
+FromType->castAs()->getPointeeType().getAddressSpace();
+assert(Qualifiers::isAddressSpaceSupersetOf(AddrSpaceL, AddrSpaceR) &&
+   "Invalid cast");
 CastKind Kind =
 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
 From = ImpCastExprToType(From, ToType.getUnqualifiedType(), Kind,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

2019-07-16 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

In D61634#1586047 , @tejohnson wrote:

> Checking in to see where we are on this issue. I haven't had any time to work 
> on 4 but hopefully can start on that soon. But it needs the first part done 
> to be effective.


Thx for the heads up @tejohnson.
The patch is missing a bit of documentation but it shouldn't be too far from 
complete:

- it adds a clang function attribute, e.g. 
`__attribute__((no_builtin("memcpy")))`
- instructs clang to compose individual IR attributes from the clang attribute 
above, e.g. `no-builtin-memcpy`, `no-builtin-memset`, `no-builtin-sqrt`...
- adds a specific builtin to clang for the memcpy case `__builtin_memcpy_inline`
- adds an LLVM IR intrinsic `int_memcpy_inline`
- adds an LLVM Instruction `MemCpyInlineInst`
- instructs LLVM to forward the `no-builtin-memcpy` IR attribute from the 
function declaration to the actual memcpy calls inside the function's body 
(same for `memset` and `memmove`)
- adds code to turn the `MemCpyInlineInst` into code, using `DAG.getMemcpy` 
with `always_inline` set.

Left to do:

- finish implementing memset / memmove
- check attributes and reject the one that are not implemented
- add documentation

There's too many things going on in this patch and it may worth splitting it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61634/new/

https://reviews.llvm.org/D61634



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


[PATCH] D64801: [analyzer] Add CTU user docs

2019-07-16 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: dkrupp, a_sidorin, Szelethus, NoQ.
Herald added subscribers: cfe-commits, Charusso, gamesh411, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64801

Files:
  clang/docs/analyzer/user-docs.rst
  clang/docs/analyzer/user-docs/CrossTranslationUnit.rst

Index: clang/docs/analyzer/user-docs/CrossTranslationUnit.rst
===
--- /dev/null
+++ clang/docs/analyzer/user-docs/CrossTranslationUnit.rst
@@ -0,0 +1,147 @@
+=
+Cross Translation Unit (CTU) Analysis
+=
+
+Normally, static analysis works in the boundary of one translation unit (TU).
+However, with additional steps and configuration we can enable the analysis to inline the definition of a function from another TU.
+
+.. contents::
+   :local:
+
+Manual CTU Analysis
+---
+
+Let's consider these source files in our minimal example:
+
+.. code-block:: cpp
+
+  // main.cpp
+  int foo();
+
+  int main() {
+return 3 / foo();
+  }
+
+.. code-block:: cpp
+
+  // foo.cpp
+  int foo() {
+return 0;
+  }
+
+And a compilation database:
+
+.. code-block:: bash
+
+  [
+{
+  "directory": "/path/to/your/project",
+  "command": "clang++ -c foo.cpp -o foo.o",
+  "file": "foo.cpp"
+},
+{
+  "directory": "/path/to/your/project",
+  "command": "clang++ -c main.cpp -o main.o",
+  "file": "main.cpp"
+}
+  ]
+
+We'd like to analyze `main.cpp` and discover the division by zero bug.
+In order to be able to inline the definition of `foo` from `foo.cpp` first we have to generate the `AST` (or `PCH`) file of `foo.cpp`:
+
+.. code-block:: bash
+
+  $ pwd $ /path/to/your/project
+  $ clang++ -emit-ast -o foo.cpp.ast foo.cpp
+  $ # Check that the .ast file is generated:
+  $ ls
+  compile_commands.json  foo.cpp.ast  foo.cpp  main.cpp
+  $
+
+The next step is to create a CTU index file which holds the `USR` name and location of external definitions in the source files:
+
+.. code-block:: bash
+
+  $ clang-extdef-mapping -p . foo.cpp
+  c:@F@foo# /path/to/your/project/foo.cpp
+  $ clang-extdef-mapping -p . foo.cpp > externalDefMap.txt
+
+We have to modify `externalDefMap.txt` to contain the name of the `.ast` files instead of the source files:
+
+.. code-block:: bash
+
+  $ sed -i -e "s/.cpp/.cpp.ast/g" externalDefMap.txt
+
+We still have to further modify the `externalDefMap.txt` file to contain relative paths:
+
+.. code-block:: bash
+
+  $ sed -i -e "s|$(pwd)/||g" externalDefMap.txt
+
+Now everything is available for the CTU analysis.
+We have to feed Clang with CTU specific extra arguments:
+
+.. code-block:: bash
+
+  $ pwd
+  /path/to/your/project
+  $ clang++ --analyze -Xclang -analyzer-config -Xclang experimental-enable-naive-ctu-analysis=true -Xclang -analyzer-config -Xclang ctu-dir=. -Xclang -analyzer-output=plist-multi-file main.cpp
+  main.cpp:5:12: warning: Division by zero
+return 3 / foo();
+   ~~^~~
+  1 warning generated.
+  $ # The plist file with the result is generated.
+  $ ls
+  compile_commands.json  externalDefMap.txt  foo.ast  foo.cpp  foo.cpp.ast  main.cpp  main.plist
+  $
+
+This manual procedure is boring and error-prone, so sooner or later we'd like to have a script which automates this for us.
+
+Automated CTU Analysis with CodeChecker
+---
+The `CodeChecker `_ project fully supports automated CTU analysis with Clang.
+Once we have set up the `PATH` environment variable and we activated the python `venv` then it is all it takes:
+
+.. code-block:: bash
+
+  $ CodeChecker analyze --ctu compile_commands.json -o reports
+  [INFO 2019-07-16 17:21] - Pre-analysis started.
+  [INFO 2019-07-16 17:21] - Collecting data for ctu analysis.
+  [INFO 2019-07-16 17:21] - [1/2] foo.cpp
+  [INFO 2019-07-16 17:21] - [2/2] main.cpp
+  [INFO 2019-07-16 17:21] - Pre-analysis finished.
+  [INFO 2019-07-16 17:21] - Starting static analysis ...
+  [INFO 2019-07-16 17:21] - [1/2] clangsa analyzed foo.cpp successfully.
+  [INFO 2019-07-16 17:21] - [2/2] clangsa analyzed main.cpp successfully.
+  [INFO 2019-07-16 17:21] -  Summary 
+  [INFO 2019-07-16 17:21] - Successfully analyzed
+  [INFO 2019-07-16 17:21] -   clangsa: 2
+  [INFO 2019-07-16 17:21] - Total analyzed compilation commands: 2
+  [INFO 2019-07-16 17:21] - =
+  [INFO 2019-07-16 17:21] - Analysis finished.
+  [INFO 2019-07-16 17:21] - To view results in the terminal use the "CodeChecker parse" command.
+  [INFO 2019-07-16 17:21] - To store results use the "CodeChecker store" command.
+  [INFO 2019-07-16 17:21] - See --help and the user guide for further options about parsing and storing the reports.

[PATCH] D64799: [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU

2019-07-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 210105.
ilya-biryukov added a comment.

Fix a typo (xD)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64799/new/

https://reviews.llvm.org/D64799

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/SemaObjC/typo-correction-subscript.m


Index: clang/test/SemaObjC/typo-correction-subscript.m
===
--- clang/test/SemaObjC/typo-correction-subscript.m
+++ clang/test/SemaObjC/typo-correction-subscript.m
@@ -9,6 +9,7 @@
 - (void)rdar47403222:(Dictionary *)opts {
   [self undeclaredMethod:undeclaredArg];
   // expected-error@-1{{no visible @interface for 'Test' declares the selector 
'undeclaredMethod:'}}
+  // expected-error@-2{{use of undeclared identifier 'undeclaredArg}}
   opts[(__bridge id)undeclaredKey] = 0;
   // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -37,6 +37,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "clang/Sema/TypoCorrection.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/TimeProfiler.h"
@@ -376,8 +377,6 @@
   // Detach from the PP callback handler which outlives Sema since it's owned
   // by the preprocessor.
   SemaPPCallbackHandler->reset();
-
-  assert(DelayedTypos.empty() && "Uncorrected typos!");
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
@@ -910,6 +909,15 @@
   assert(LateParsedInstantiations.empty() &&
  "end of TU template instantiation should not create more "
  "late-parsed templates");
+
+  // Report diagnostics for uncorrected delayed typos. Ideally all of them
+  // should have been corrected by that time, but it is very hard to cover all
+  // cases in practice.
+  for (const auto  : DelayedTypos) {
+// We pass an empty TypoCorrection to indicate no correction was performed.
+Typo.second.DiagHandler(TypoCorrection());
+  }
+  DelayedTypos.clear();
 }
 
 /// ActOnEndOfTranslationUnit - This is called at the very end of the


Index: clang/test/SemaObjC/typo-correction-subscript.m
===
--- clang/test/SemaObjC/typo-correction-subscript.m
+++ clang/test/SemaObjC/typo-correction-subscript.m
@@ -9,6 +9,7 @@
 - (void)rdar47403222:(Dictionary *)opts {
   [self undeclaredMethod:undeclaredArg];
   // expected-error@-1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}}
+  // expected-error@-2{{use of undeclared identifier 'undeclaredArg}}
   opts[(__bridge id)undeclaredKey] = 0;
   // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -37,6 +37,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "clang/Sema/TypoCorrection.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/TimeProfiler.h"
@@ -376,8 +377,6 @@
   // Detach from the PP callback handler which outlives Sema since it's owned
   // by the preprocessor.
   SemaPPCallbackHandler->reset();
-
-  assert(DelayedTypos.empty() && "Uncorrected typos!");
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
@@ -910,6 +909,15 @@
   assert(LateParsedInstantiations.empty() &&
  "end of TU template instantiation should not create more "
  "late-parsed templates");
+
+  // Report diagnostics for uncorrected delayed typos. Ideally all of them
+  // should have been corrected by that time, but it is very hard to cover all
+  // cases in practice.
+  for (const auto  : DelayedTypos) {
+// We pass an empty TypoCorrection to indicate no correction was performed.
+Typo.second.DiagHandler(TypoCorrection());
+  }
+  DelayedTypos.clear();
 }
 
 /// ActOnEndOfTranslationUnit - This is called at the very end of the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64418: [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-07-16 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 210101.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64418/new/

https://reviews.llvm.org/D64418

Files:
  docs/LanguageExtensions.rst
  docs/UsersManual.rst

Index: docs/UsersManual.rst
===
--- docs/UsersManual.rst
+++ docs/UsersManual.rst
@@ -2397,7 +2397,8 @@
 This will produce a generic test.bc file that can be used in vendor toolchains
 to perform machine code generation.
 
-Clang currently supports OpenCL C language standards up to v2.0.
+Clang currently supports OpenCL C language standards up to v2.0. Starting from Clang9
+C++ mode is available for OpenCL (see :ref:`C++ for OpenCL `).
 
 OpenCL Specific Options
 ---
@@ -2756,6 +2757,45 @@
   enqueue query functions from `section 6.13.17.5
   `_.
 
+.. _opencl_cpp:
+
+C++ for OpenCL
+--
+
+Starting from Clang9 kernel code can contain C++17 features: classes, templates,
+function overloading, type deduction, etc. Please note that this is not an
+implementation of `OpenCL C++
+`_ and
+there is no plan to support it in clang in any new releases in the near future.
+
+There are only a few restrictions on allowed C++ features. For detailed information
+please refer to documentation on Extensions (:doc:`LanguageExtensions`).
+
+Since C++ features are to be used on top of OpenCL C functionality, all existing
+restrictions from OpenCL C v2.0 will inherently apply. All OpenCL C builtin types
+and function libraries are supported and can be used in the new mode.
+
+To enable the new mode pass the following command line option when compiling ``.cl``
+file ``-cl-std=c++`` or ``-std=c++``.
+
+   .. code-block:: c++
+
+ template T add( T x, T y )
+ {
+   return x + y;
+ }
+
+ __kernel void test( __global float* a, __global float* b)
+ {
+   auto index = get_global_id(0);
+   a[index] = add(b[index], b[index+1]);
+ }
+
+
+   .. code-block:: console
+
+ clang -cl-std=c++ test.cl
+
 .. _target_features:
 
 Target-Specific Features and Limitations
Index: docs/LanguageExtensions.rst
===
--- docs/LanguageExtensions.rst
+++ docs/LanguageExtensions.rst
@@ -1516,6 +1516,269 @@
 Query the presence of this new mangling with
 ``__has_feature(objc_protocol_qualifier_mangling)``.
 
+
+OpenCL Features
+===
+
+C++ for OpenCL
+--
+
+This functionality is built on top of OpenCL C v2.0 and C++17. Regular C++
+features can be used in OpenCL kernel code. All functionality from OpenCL C
+is inherited. This section describes minor differences to OpenCL C and any
+limitations related to C++ support as well as interactions between OpenCL and
+C++ features that are not documented elsewhere.
+
+Restrictions to C++17
+^
+
+The following features are not supported:
+
+- Virtual functions
+- ``dynamic_cast`` operator
+- Non-placement ``new``/``delete`` operators
+- Standard C++ libraries. Currently there is no solution for alternative C++
+  libraries provided. Future release will feature library support.
+
+
+Interplay of OpenCL and C++ features
+
+
+Address space behavior
+""
+
+Address spaces are part of the type qualifiers; many rules are just inherited
+from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
+extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
+behavior in C++ is not documented formally yet, Clang extends existing concept
+from C and OpenCL. For example conversion rules are extended from qualification
+conversion but the compatibility is determined using sets and overlapping from
+Embedded C (ISO/IEC JTC1 SC22 WG14 N1021 s3.1.3). For OpenCL it means that
+implicit conversions are allowed from named to ``__generic`` but not vice versa
+(OpenCL C v2.0 s6.5.5) except for ``__constant`` address space. Most of the
+rules are built on top of this behavior.
+
+**Casts**
+
+C style cast will follow OpenCL C v2.0 rules (s6.5.5). All cast operators will
+permit implicit conversion to ``__generic``. However converting from named
+address spaces to ``__generic`` can only be done using ``addrspace_cast``. Note
+that conversions between ``__constant`` and any other is still disallowed.
+
+.. _opencl_cpp_addrsp_deduction:
+
+**Deduction**
+
+Address spaces are not deduced for:
+
+- non-pointer/non-reference template parameters or any dependent types except
+  for template specializations.
+- non-pointer/non-reference class members except for static data members that are
+  deduced to ``__global`` address space.
+- non-pointer/non-reference alias declarations.
+- ``decltype`` expression.
+
+.. code-block:: c++
+
+  template 
+  void foo() {
+T m; // 

[PATCH] D64765: [OPENMP]Add support for analysis of firstprivate variables.

2019-07-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 210100.
ABataev added a comment.

Rebase


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64765/new/

https://reviews.llvm.org/D64765

Files:
  include/clang/AST/OpenMPClause.h
  test/Analysis/cfg-openmp.cpp
  test/OpenMP/distribute_parallel_for_firstprivate_messages.cpp
  test/OpenMP/distribute_parallel_for_simd_firstprivate_messages.cpp
  test/OpenMP/parallel_firstprivate_messages.cpp
  test/OpenMP/parallel_for_firstprivate_messages.cpp
  test/OpenMP/parallel_for_simd_firstprivate_messages.cpp
  test/OpenMP/parallel_sections_firstprivate_messages.cpp
  test/OpenMP/target_firstprivate_messages.cpp
  test/OpenMP/target_parallel_firstprivate_messages.cpp
  test/OpenMP/target_parallel_for_firstprivate_messages.cpp
  test/OpenMP/target_parallel_for_simd_firstprivate_messages.cpp
  test/OpenMP/target_simd_firstprivate_messages.cpp
  test/OpenMP/target_teams_distribute_firstprivate_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_firstprivate_messages.cpp
  
test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_messages.cpp
  test/OpenMP/target_teams_distribute_simd_firstprivate_messages.cpp
  test/OpenMP/target_teams_firstprivate_messages.cpp
  test/OpenMP/task_firstprivate_messages.cpp
  test/OpenMP/taskloop_firstprivate_messages.cpp
  test/OpenMP/taskloop_simd_firstprivate_messages.cpp
  test/OpenMP/teams_distribute_firstprivate_messages.cpp
  test/OpenMP/teams_distribute_parallel_for_firstprivate_messages.cpp
  test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_messages.cpp
  test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
  test/OpenMP/teams_firstprivate_messages.cpp

Index: test/OpenMP/teams_firstprivate_messages.cpp
===
--- test/OpenMP/teams_firstprivate_messages.cpp
+++ test/OpenMP/teams_firstprivate_messages.cpp
@@ -10,6 +10,14 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp target
+#pragma omp teams firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
===
--- test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
+++ test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
@@ -10,6 +10,14 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp target
+#pragma omp teams distribute simd firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_messages.cpp
===
--- test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_messages.cpp
@@ -10,6 +10,14 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp target
+#pragma omp teams distribute parallel for simd firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/teams_distribute_parallel_for_firstprivate_messages.cpp
===
--- test/OpenMP/teams_distribute_parallel_for_firstprivate_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_firstprivate_messages.cpp
@@ -10,6 +10,14 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp target
+#pragma omp teams distribute parallel for firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/teams_distribute_firstprivate_messages.cpp
===
--- test/OpenMP/teams_distribute_firstprivate_messages.cpp
+++ test/OpenMP/teams_distribute_firstprivate_messages.cpp
@@ -10,6 +10,14 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp 

[PATCH] D64799: [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU

2019-07-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: rnk, sammccall.
Herald added a subscriber: kadircet.
Herald added a project: clang.

Instead of asserting all typos are corrected in the sema destructor.

The sema destructor is not run in the common case of running the compiler
with the -disable-free cc1 flag (which is the default in the driver).

Having this assertion led to crashes in libclang and clangd, which are not
reproducible when running the compiler.

Asserting at the end of the TU could be an option, but finding all
missing typo correction cases is hard and having worse diagnostics instead
of a failing assertion is a better trade-off.

For more discussion on this, see:
https://lists.llvm.org/pipermail/cfe-dev/2019-July/062872.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64799

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/SemaObjC/typo-correction-subscript.m


Index: clang/test/SemaObjC/typo-correction-subscript.m
===
--- clang/test/SemaObjC/typo-correction-subscript.m
+++ clang/test/SemaObjC/typo-correction-subscript.m
@@ -9,6 +9,7 @@
 - (void)rdar47403222:(Dictionary *)opts {
   [self undeclaredMethod:undeclaredArg];
   // expected-error@-1{{no visible @interface for 'Test' declares the selector 
'undeclaredMethod:'}}
+  // expected-error@-2{{use of undeclared identifier 'undeclaredArg}}
   opts[(__bridge id)undeclaredKey] = 0;
   // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -37,6 +37,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "clang/Sema/TypoCorrection.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/TimeProfiler.h"
@@ -376,8 +377,6 @@
   // Detach from the PP callback handler which outlives Sema since it's owned
   // by the preprocessor.
   SemaPPCallbackHandler->reset();
-
-  assert(DelayedTypos.empty() && "Uncorrected typos!");
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
@@ -910,6 +909,15 @@
   assert(LateParsedInstantiations.empty() &&
  "end of TU template instantiation should not create more "
  "late-parsed templates");
+
+  // Report diagnostics for uncorrected delayed typos. Ideally all of them
+  // should have been corrected by that point, but it is very hard to cover all
+  // cases in practice.
+  for (const auto  : DelayedTypos) {
+// We pass an empty TypoCorrection to indicate no correction was performed.
+Typo.second.DiagHandler(TypoCorrection());
+  }
+  DelayedTypos.clear();
 }
 
 /// ActOnEndOfTranslationUnit - This is called at the very end of the


Index: clang/test/SemaObjC/typo-correction-subscript.m
===
--- clang/test/SemaObjC/typo-correction-subscript.m
+++ clang/test/SemaObjC/typo-correction-subscript.m
@@ -9,6 +9,7 @@
 - (void)rdar47403222:(Dictionary *)opts {
   [self undeclaredMethod:undeclaredArg];
   // expected-error@-1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}}
+  // expected-error@-2{{use of undeclared identifier 'undeclaredArg}}
   opts[(__bridge id)undeclaredKey] = 0;
   // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -37,6 +37,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "clang/Sema/TypoCorrection.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/TimeProfiler.h"
@@ -376,8 +377,6 @@
   // Detach from the PP callback handler which outlives Sema since it's owned
   // by the preprocessor.
   SemaPPCallbackHandler->reset();
-
-  assert(DelayedTypos.empty() && "Uncorrected typos!");
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
@@ -910,6 +909,15 @@
   assert(LateParsedInstantiations.empty() &&
  "end of TU template instantiation should not create more "
  "late-parsed templates");
+
+  // Report diagnostics for uncorrected delayed typos. Ideally all of them
+  // should have been corrected by that point, but it is very hard to cover all
+  // cases in practice.
+  for (const auto  : DelayedTypos) {
+// We pass an empty TypoCorrection to indicate no correction was performed.
+Typo.second.DiagHandler(TypoCorrection());
+  }
+  DelayedTypos.clear();
 }
 
 /// ActOnEndOfTranslationUnit - This is called at the very end of the
___
cfe-commits mailing list

[PATCH] D64791: [OpenCL] Fix sampler initialization for C++ mode

2019-07-16 Thread Neil Hickey via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366212: [OpenCL] Fixing sampler initialisations for C++ 
mode. (authored by neil.hickey, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64791?vs=210061=210096#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64791/new/

https://reviews.llvm.org/D64791

Files:
  cfe/trunk/lib/Sema/SemaInit.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/test/CodeGenOpenCL/sampler.cl

Index: cfe/trunk/test/CodeGenOpenCL/sampler.cl
===
--- cfe/trunk/test/CodeGenOpenCL/sampler.cl
+++ cfe/trunk/test/CodeGenOpenCL/sampler.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=c++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s
 //
 // This test covers 5 cases of sampler initialzation:
 //   1. function argument passing
@@ -29,7 +30,7 @@
 int get_sampler_initializer(void);
 
 void fnc4smp(sampler_t s) {}
-// CHECK: define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %
+// CHECK: define spir_func void [[FUNCNAME:@.*fnc4smp.*]](%opencl.sampler_t addrspace(2)* %
 
 kernel void foo(sampler_t smp_par) {
   // CHECK-LABEL: define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* %smp_par)
@@ -45,32 +46,32 @@
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   // Case 1b
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   // Case 1a/2a
   fnc4smp(glb_smp);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   // Case 1a/2c
   fnc4smp(glb_smp_const);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   // Case 1c
   fnc4smp(smp_par);
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_par_ptr]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   fnc4smp(5);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
   fnc4smp(const_smp);
@@ -78,12 +79,12 @@
   // CHECK: store %opencl.sampler_t addrspace(2)* [[CONST_SAMP]], %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR:%[a-zA-Z0-9]+]]
   fnc4smp(const_smp);
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   constant sampler_t constant_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
   fnc4smp(constant_smp);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]])
 
   // TODO: enable sampler initialization with non-constant integer.
   //const sampler_t const_smp_func_init = get_sampler_initializer();
Index: cfe/trunk/lib/Sema/SemaOverload.cpp
===
--- 

r366212 - [OpenCL] Fixing sampler initialisations for C++ mode.

2019-07-16 Thread Neil Hickey via cfe-commits
Author: neil.hickey
Date: Tue Jul 16 07:57:32 2019
New Revision: 366212

URL: http://llvm.org/viewvc/llvm-project?rev=366212=rev
Log:
[OpenCL] Fixing sampler initialisations for C++ mode.

Allow conversions between integer and sampler type.

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

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenOpenCL/sampler.cl

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=366212=366211=366212=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jul 16 07:57:32 2019
@@ -5640,6 +5640,9 @@ void InitializationSequence::InitializeF
   bool allowObjCWritebackConversion = S.getLangOpts().ObjCAutoRefCount &&
  Entity.isParameterKind();
 
+  if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
+return;
+
   // We're at the end of the line for C: it's either a write-back conversion
   // or it's a C assignment. There's no need to check anything else.
   if (!S.getLangOpts().CPlusPlus) {
@@ -5649,9 +5652,6 @@ void InitializationSequence::InitializeF
   return;
 }
 
-if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
-  return;
-
 if (TryOCLZeroOpaqueTypeInitialization(S, *this, DestType, Initializer))
   return;
 

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=366212=366211=366212=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Jul 16 07:57:32 2019
@@ -1851,6 +1851,10 @@ static bool IsStandardConversion(Sema 
  (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) {
 SCS.Second = ICK_Zero_Queue_Conversion;
 FromType = ToType;
+  } else if (ToType->isSamplerT() &&
+ From->isIntegerConstantExpr(S.getASTContext())) {
+SCS.Second = ICK_Compatible_Conversion;
+FromType = ToType;
   } else {
 // No second conversion required.
 SCS.Second = ICK_Identity;

Modified: cfe/trunk/test/CodeGenOpenCL/sampler.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/sampler.cl?rev=366212=366211=366212=diff
==
--- cfe/trunk/test/CodeGenOpenCL/sampler.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/sampler.cl Tue Jul 16 07:57:32 2019
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | 
FileCheck %s
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown -o 
- -O0 | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=c++ -emit-llvm -triple spir-unknown-unknown -o - 
-O0 | FileCheck %s
 //
 // This test covers 5 cases of sampler initialzation:
 //   1. function argument passing
@@ -29,7 +30,7 @@ const sampler_t glb_smp_const = CLK_ADDR
 int get_sampler_initializer(void);
 
 void fnc4smp(sampler_t s) {}
-// CHECK: define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %
+// CHECK: define spir_func void [[FUNCNAME:@.*fnc4smp.*]](%opencl.sampler_t 
addrspace(2)* %
 
 kernel void foo(sampler_t smp_par) {
   // CHECK-LABEL: define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* 
%smp_par)
@@ -45,32 +46,32 @@ kernel void foo(sampler_t smp_par) {
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, 
%opencl.sampler_t addrspace(2)** [[smp_ptr]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   // Case 1b
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
   // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, 
%opencl.sampler_t addrspace(2)** [[smp_ptr]]
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   // Case 1a/2a
   fnc4smp(glb_smp);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   // Case 1a/2c
   fnc4smp(glb_smp_const);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
-  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+  // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t 

[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

2019-07-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

the code looks clearer now!




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:609
 FixItsMap.erase(File);
+std::lock_guard HLock(HighlightingsMutex);
+FileToPrevHighlightings.erase(File);

nit: I would create a new `{}` block merely for the hightlightings.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1110
 PathRef File, std::vector Highlightings) {
+  llvm::ArrayRef Prev;
+  {

this seems unsafe, we get a reference of the map value, we might access it 
without the mutex being guarded. 

```
std::vector Old;
{
std::lock_guard Lock(HighlightingsMutex);
Old = std::move(FileToHighlightings[File]);
}
```



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1124
+std::lock_guard Lock(HighlightingsMutex);
+FileToPrevHighlightings[File] = Highlightings;
+  }

`FileToPrevHighlightings[File] = std::move(Highlightings);`



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:140
+  std::mutex HighlightingsMutex;
+  llvm::StringMap> FileToPrevHighlightings;
 

nit: I'd drop `Prev`.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:229
+// Get the highlights for \c Line where the first entry for \c Line is
+// immediately preceded by \c OldLine
+ArrayRef takeLine(ArrayRef AllTokens,

nit: I'm not sure I understand the comment.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:233
+ int Line) {
+  return ArrayRef(OldLine.end(), AllTokens.end())
+  .take_while([Line](const HighlightingToken ) {

nit: this implies that OldLine and AllTokens must ref to the same container, 
could you refine the `OldLine` as a start `Iterator`? 



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:255
+  // ArrayRefs to the current line in the highlights.
+  ArrayRef NewLine(Highlightings.data(),
+  Highlightings.data()),

IIUC, we are initializing an empty ArrayRef, if so, how about using 
`NewLine(Highlightings.data(), /*length*/0)`? `NewLine(Highlightings.data(), 
Highlightings.data())` is a bit weird, it took me a while to understand the 
purpose.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:257
+  Highlightings.data()),
+  OldLine = {PrevHighlightings.data(), PrevHighlightings.data()};
+  // ArrayRefs to the new and old highlighting vectors.

nit: split it into a new statement.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:259
+  // ArrayRefs to the new and old highlighting vectors.
+  ArrayRef Current = {Highlightings},
+  Prev = {PrevHighlightings};

we don't change Current and Prev below, how about re-using `Highlightings` and 
`PrevHighlightings`?



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:71
+/// in \c Highlightings an empty line is added. Returns the resulting
+/// HighlightingTokens grouped by their line number. Assumes the highlightings
+/// are sorted by the tokens' ranges.

I believe `Assumes the highlightings are sorted by the tokens' ranges.` is a 
requirement for this function?

If so, mark it more explicitly in the comment, like 

```
///
/// REQUIRED: OldHighlightings and NewHighlightings are sorted.
```



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:74
+std::vector
+diffHighlightings(ArrayRef Highlightings,
+  ArrayRef PrevHighlightings);

nit: I'd use name the parameters symmetrically, `NewHighlightings` and 
`OldHighlightings`.



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:32
 
-void checkHighlightings(llvm::StringRef Code) {
+std::tuple,
+   std::vector>

we don't need `ParsedAST`  now I think.



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:265
+TEST(SemanticHighlighting, HighlightingDiffer) {
+  std::vector<
+  std::pair, std::pair>>

this is a complicated structure, could you add some comments describing the 
test strategy here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64475/new/

https://reviews.llvm.org/D64475



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


r366211 - [OPENMP]Add support for analysis of if clauses.

2019-07-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jul 16 07:51:46 2019
New Revision: 366211

URL: http://llvm.org/viewvc/llvm-project?rev=366211=rev
Log:
[OPENMP]Add support for analysis of if clauses.

Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: clang

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

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/test/Analysis/cfg-openmp.cpp
cfe/trunk/test/OpenMP/cancel_if_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_if_messages.cpp
cfe/trunk/test/OpenMP/target_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_enter_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_exit_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
cfe/trunk/test/OpenMP/target_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_if_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_if_messages.cpp
cfe/trunk/test/OpenMP/target_update_if_messages.cpp
cfe/trunk/test/OpenMP/task_if_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_if_messages.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=366211=366210=366211=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Tue Jul 16 07:51:46 2019
@@ -501,11 +501,10 @@ public:
 return const_child_range(,  + 1);
   }
 
-  child_range used_children() {
-return child_range(child_iterator(), child_iterator());
-  }
+  child_range used_children();
   const_child_range used_children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
   }
 
   static bool classof(const OMPClause *T) {

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=366211=366210=366211=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Tue Jul 16 07:51:46 2019
@@ -209,6 +209,25 @@ const OMPClauseWithPostUpdate *OMPClause
   return nullptr;
 }
 
+/// Gets the address of the original, non-captured, expression used in the
+/// clause as the preinitializer.
+static Stmt **getAddrOfExprAsWritten(Stmt *S) {
+  if (!S)
+return nullptr;
+  if (auto *DS = dyn_cast(S)) {
+assert(DS->isSingleDecl() && "Only single expression must be captured.");
+if (auto *OED = dyn_cast(DS->getSingleDecl()))
+  return OED->getInitAddress();
+  }
+  return nullptr;
+}
+
+OMPClause::child_range OMPIfClause::used_children() {
+  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
+return child_range(C, C + 1);
+  return child_range(,  + 1);
+}
+
 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext , Expr *Num,
unsigned NumLoops,
SourceLocation StartLoc,

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=366211=366210=366211=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Jul 16 07:51:46 2019
@@ -4746,8 +4746,9 @@ CFGBlock *CFGBuilder::VisitOMPExecutable
 
   // Reverse the elements to process them in natural order. Iterators are not
   // bidirectional, so we need to create temp vector.
-  for (Stmt *S : llvm::reverse(llvm::to_vector<8>(
-   OMPExecutableDirective::used_clauses_children(D->clauses() {
+  SmallVector Used(
+  

[PATCH] D64775: [Format/ObjC] Avoid breaking between unary operators and ObjC method invocations

2019-07-16 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton marked an inline comment as done.
benhamilton added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2427-2428
 return 50;
 
+  if (Left.is(TT_UnaryOperator) && Right.is(TT_ObjCMethodExpr))
+return 60;

sammccall wrote:
> This looks a little suspicious only because it's so specific.
> 
> It seems like you'd *always* want a harsh penalty for breaking between a 
> unary operator and its operand. @klimek does this look right, should we drop 
> the `ObcJMethodExpr` requirement or is this case handled elsewhere?
I tried changing it to just `if (Left.is(TT_UnaryOperator))` and all the tests 
passed. I'll go for the gusto and assume this is fine.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64775/new/

https://reviews.llvm.org/D64775



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


[PATCH] D64775: [Format/ObjC] Avoid breaking between unary operators and ObjC method invocations

2019-07-16 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 210095.
benhamilton marked an inline comment as done.
benhamilton added a comment.

- Rebase.
- Change to just avoid breaking when the left-hand side is a unary operator


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64775/new/

https://reviews.llvm.org/D64775

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -886,6 +886,18 @@
" bb:42\n"
" cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "![foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "+[foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "-[foo bar]) {\n"
+   "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,8 @@
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
+  if (Left.is(TT_UnaryOperator))
+return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -886,6 +886,18 @@
" bb:42\n"
" cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "![foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "+[foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "-[foo bar]) {\n"
+   "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,8 @@
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
+  if (Left.is(TT_UnaryOperator))
+return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59555: [analyzer] Add yaml parser to GenericTaintChecker

2019-07-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Starting to look real good!




Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:807
+  "",
+  Released>,
+  ]>,

We mark options that are not yet ready for used with `InAlpha`, rather then 
`Released`. I think it would be more fitting in this case!

Mind that if you'd like to list this option after that, you'd have to use
```lang=bash
clang -cc1 -analyzer-checker-option-help-alpha
```



Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:58
+
+  /// The ``TaintConfiguration`` is used to parse configuration file.
+  struct TaintConfiguration {

Just simply `Used to parse the configuration file`.
https://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments



Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:302-303
+  Result.push_back(InvalidArgIndex);
+  llvm::errs() << "Invalid arg number for propagation rules: " << Arg
+   << '\n';
+} else

Do we emit an error for this case?



Comment at: lib/StaticAnalyzer/Checkers/Yaml.h:1
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "llvm/ADT/APInt.h"

Header blurb (licence stuff etc)!



Comment at: test/Analysis/taint-generic.c:1-2
-// RUN: %clang_analyze_cc1  
-analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 
-Wno-format-security -verify %s
-// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT 
-analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 
-Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  
-analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 
-analyzer-config 
alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 -Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT 
-analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 
-analyzer-config 
alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 -Wno-format-security -verify %s
 

Could you please use line breaks here? I know it isn't your making, but if 
we're touching it anyways :^)

```
// RUN: %clang_analyze_cc1 -Wno-format-security -verify %s \
// RUN:   -DFILE_IS_STRUCT \
// RUN:   -analyzer-checker=alpha.security.taint \
// RUN:   -analyzer-checker=core \
// RUN:   -analyzer-checker=alpha.security.ArrayBoundV2 \
// RUN:   -analyzer-config \
// RUN: 
alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
```

And also a testcase for an incorrect checker option:
```

// RUN: not %clang_analyze_cc1 -verify %s \
// RUN:   -analyzer-checker=alpha.security.taint \
// RUN:   -analyzer-config \
// RUN: alpha.security.taint.TaintPropagation:Config=justguessit \
// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FILE

// CHECK-INVALID-FILE: (frontend): invalid input for checker option
// CHECK-INVALID-FILE-SAME:
'alpha.security.taint.TaintPropagation:Config',
// CHECK-INVALID-FILE-SAME:that expects a valid yaml file
```
something like that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59555/new/

https://reviews.llvm.org/D59555



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


[PATCH] D61466: [Rewrite][NFC] Add FIXMEs and tests for RemoveLineIfEmpty bug

2019-07-16 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Ping.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61466/new/

https://reviews.llvm.org/D61466



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-16 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added inline comments.



Comment at: llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:27
+static const char GlobalArgumentMemAccess[] = {
+// grep  -P -o "(?<=FUNCTION_INFO: ).*"  | sort -u >
+// ../llvm-project/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpData.h

vitalybuka wrote:
> glider wrote:
> > Ditto.
> These files should be empty. Raw diff 
> https://reviews.llvm.org/file/data/o6sk6gw2gqs4u4pmodrn/PHID-FILE-s6c6nsofxnqekkcvzdzs/D61879.diff
>  already contains them. 
> It's ThinLTO replacement experiments. They don't improve results enough, so I 
> didn't bother to create real ThinLTO stuff. Anyway it is not needed for full 
> LTO.
> 
```
$ ninja -j64 check-clang
...
/usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:20:32:
 error: zero-size array ‘llvm::GUIDS_LOOKUP’
 static const GlobalValue::GUID GUIDS_LOOKUP[] = {
^~~~
/usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:26:19:
 error: zero-size array ‘llvm::GlobalArgumentMemAccess’
 static const char GlobalArgumentMemAccess[] = {
   ^~~
```
Am I doing something wrong? Looks like empty files aren't enough.
I've fixed the problem by putting "0" into each file, but it's strange it works 
differently for us.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61879/new/

https://reviews.llvm.org/D61879



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


[PATCH] D64554: [CrossTU] Add a function to retrieve original source location.

2019-07-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: include/clang/AST/ASTImporter.h:317
+std::shared_ptr SharedState = nullptr,
+ASTUnit *Unit = nullptr);
 

martong wrote:
> balazske wrote:
> > balazske wrote:
> > > martong wrote:
> > > > What if we provided an additional constructor where we take over the 
> > > > ASTUnits instead of the ASTContexts?
> > > > Then we would not need to pass the FileManagers neither.
> > > > ```
> > > > ASTImporter(ASTUnit , 
> > > > ASTUnit ,
> > > > bool MinimalImport,
> > > > std::shared_ptr SharedState = 
> > > > nullptr,
> > > > ```
> > > Is the `SharedState==nullptr` case only for LLDB? If yes then it is 
> > > possible to have a "LLDB" constructor when no shared state and no ASTUnit 
> > > is needed. And another for CTU case when a From and To ASTUnit is 
> > > specified and a shared state (theoretically minimal can be true in any 
> > > case but probably only true for LLDB?).
> > It is not trivial to make and use this new kind of constructor (with 
> > ToUnit), there is no ToUnit in the CrossTU context. Is it OK to have the 
> > original constructor, or one with `FromUnit` (but `ToContext` and 
> > `ToFileManager`)?
> > Is the SharedState==nullptr case only for LLDB?
> Yes.
> 
> > Is it OK to have the original constructor, or one with FromUnit (but 
> > ToContext and ToFileManager)?
> 
> I think it is OK to have a new ctor with FromUnit (but ToContext and 
> ToFileManager). Because ASTUnit is just a utility class for loading an 
> ASTContext from an AST file. So, one of the "to" or the "from" context could 
> be initialized by an ASTUnit.
> 
> In the future the API of the ASTImporter could be extended with such a ctor 
> which takes two ASTUnits, also we could add the counterpart ctor where we 
> have ToUnit, FromContext and FromFileManager as params.
Note that if we have a ctor which takes FromUnit as a param then we won't need 
the assertions which check whether the Unit provides the same context or not.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64554/new/

https://reviews.llvm.org/D64554



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


[PATCH] D64554: [CrossTU] Add a function to retrieve original source location.

2019-07-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: include/clang/AST/ASTImporter.h:317
+std::shared_ptr SharedState = nullptr,
+ASTUnit *Unit = nullptr);
 

balazske wrote:
> balazske wrote:
> > martong wrote:
> > > What if we provided an additional constructor where we take over the 
> > > ASTUnits instead of the ASTContexts?
> > > Then we would not need to pass the FileManagers neither.
> > > ```
> > > ASTImporter(ASTUnit , 
> > > ASTUnit ,
> > > bool MinimalImport,
> > > std::shared_ptr SharedState = 
> > > nullptr,
> > > ```
> > Is the `SharedState==nullptr` case only for LLDB? If yes then it is 
> > possible to have a "LLDB" constructor when no shared state and no ASTUnit 
> > is needed. And another for CTU case when a From and To ASTUnit is specified 
> > and a shared state (theoretically minimal can be true in any case but 
> > probably only true for LLDB?).
> It is not trivial to make and use this new kind of constructor (with ToUnit), 
> there is no ToUnit in the CrossTU context. Is it OK to have the original 
> constructor, or one with `FromUnit` (but `ToContext` and `ToFileManager`)?
> Is the SharedState==nullptr case only for LLDB?
Yes.

> Is it OK to have the original constructor, or one with FromUnit (but 
> ToContext and ToFileManager)?

I think it is OK to have a new ctor with FromUnit (but ToContext and 
ToFileManager). Because ASTUnit is just a utility class for loading an 
ASTContext from an AST file. So, one of the "to" or the "from" context could be 
initialized by an ASTUnit.

In the future the API of the ASTImporter could be extended with such a ctor 
which takes two ASTUnits, also we could add the counterpart ctor where we have 
ToUnit, FromContext and FromFileManager as params.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64554/new/

https://reviews.llvm.org/D64554



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


[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-16 Thread Marco Antognini via Phabricator via cfe-commits
mantognini marked 10 inline comments as done.
mantognini added a comment.

Mind the fact that I've rebased the changes onto a more recent master version. 
If you look at the diff of v1 against v2 you might see some unrelated changes.

Let me know if there's anything else that I need to change.




Comment at: clang/lib/CodeGen/CGClass.cpp:2016
   CGF.EmitCXXDestructorCall(dtor, Dtor_Complete, /*for vbase*/ false,
-/*Delegating=*/false, addr);
+/*Delegating=*/false, addr, type);
 }

rjmccall wrote:
> mantognini wrote:
> > This is the only place where the new parameter has an interesting value. In 
> > the ~10 other calls to `EmitCXXDestructorCall` overloads, the default value 
> > of this new parameter is used instead.
> Arguments that are potentially required for correctness — as opposed to just 
> enabling some optimization — should generally not have defaults.  I think you 
> should remove these defaults and require a sensible type to be passed down in 
> all cases.
I've addressed that. I had to add some extra parameter/attributes here and 
there. Please let me know if anything is can be improved.



Comment at: clang/lib/CodeGen/CGClass.cpp:1447
+if (HaveInsertPoint()) {
+  // FIXME: Determine the type of the object being destroyed.
+  QualType ThisTy;

I'm not familiar enough with CXXCtorType and such, and would welcome some help 
for these two FIXMEs.



Comment at: clang/lib/CodeGen/CGExprCXX.cpp:103
+  // we ensure a cast is added where necessary.
+  if (ThisTy.isNull()) {
+#ifndef NDEBUG

Despite no longer having a default parameter, not all call site can provide a 
meaningful value ATM. That is why this check is still required.



Comment at: clang/lib/CodeGen/CGExprCXX.cpp:96
+llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE,
+QualType ThisTy) {
+  const CXXMethodDecl *DtorDecl = cast(Dtor.getDecl());

mantognini wrote:
> This new parameter is required in order to call `performAddrSpaceCast`.
Now that it's no longer a default parameter. I've group ThisTy with This.



Comment at: clang/lib/CodeGen/CGExprCXX.cpp:117-118
+  llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy);
+  This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS,
+   NewType);
+}

rjmccall wrote:
> Anastasia wrote:
> > mantognini wrote:
> > > This is effectively the fix for the third point mentioned in the 
> > > description.
> > > 
> > > Alternatively, `This = Builder.CreatePointerBitCastOrAddrSpaceCast(This, 
> > > NewType);` seems to work equally well and does not require the extra new 
> > > parameter.
> > Yes, I agree just using `CreatePointerBitCastOrAddrSpaceCast` would be 
> > easier.
> > 
> > As far as I remember (@rjmccall can correct me if I am wrong) 
> > `performAddrSpaceCast` was added to workaround the fact that `nullptr` 
> > constant might not be value 0 for some address spaces. However, considering 
> > that it's not the first place where some big change has to be done in 
> > CodeGen to be able to use the new API I am wondering if it's worth looking 
> > at moving this logic to LLVM lowering phases that can map `nullptr` 
> > constant into some arbitrary value. I think the challenge is to find where 
> > LLVM assumes that `nullptr` is always 0. That might not be an easy task.
> > 
> > PS, I am not suggesting to do it for this patch but just an idea to 
> > investigate in the future. 
> I continue to think that it makes sense to set Clang up to be able to handle 
> language-level address spaces that don't exist at the level of LLVM IR.

Alright, I've kept it.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8428-8439
+bool DiagOccured = false;
 FTI.MethodQualifiers->forEachQualifier(
 [&](DeclSpec::TQ TypeQual, StringRef QualName, SourceLocation SL) {
+  // This diagnostic should be emitted on any qualifier except an addr
+  // space qualifier. However, forEachQualifier currently doesn't visit
+  // addr space qualifiers, so there's no way to write this condition
+  // right now; we just diagnose on everything.

rjmccall wrote:
> mantognini wrote:
> > This is the fix for the first point in the description.
> Can we unify this with the similar check we do elsewhere?
Done.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8197
+  const DeclaratorChunk::FunctionTypeInfo  = D.getFunctionTypeInfo();
+  if (FTI.hasMethodTypeQualifiers() && !D.isInvalidType()) {
+bool DiagOccured = false;

I've refactored that bit out of the two mentioned functions. Mind the fact that 
it now always check `!D.isInvalidType()`. I think it makes sense, but let me 
know if that's not the case.



[PATCH] D64754: [clangd] Added highlighting for the targets in typedefs.

2019-07-16 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366207: [clangd] Added highlighting for the targets in 
typedefs and using. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64754?vs=210053=210084#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64754/new/

https://reviews.llvm.org/D64754

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -93,6 +93,12 @@
 return true;
   }
 
+  bool VisitTypedefNameDecl(TypedefNameDecl *TD) {
+if(const auto *TSI = TD->getTypeSourceInfo())
+  addTypeLoc(TD->getLocation(), TSI->getTypeLoc());
+return true;
+  }
+
   bool VisitTypeLoc(TypeLoc ) {
 // This check is for not getting two entries when there are anonymous
 // structs. It also makes us not highlight certain namespace qualifiers
@@ -101,9 +107,7 @@
 if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
   return true;
 
-if (const Type *TP = TL.getTypePtr())
-  if (const TagDecl *TD = TP->getAsTagDecl())
-addToken(TL.getBeginLoc(), TD);
+addTypeLoc(TL.getBeginLoc(), TL);
 return true;
   }
 
@@ -118,6 +122,12 @@
   }
 
 private:
+  void addTypeLoc(SourceLocation Loc, const TypeLoc ) {
+if (const Type *TP = TL.getTypePtr())
+  if (const TagDecl *TD = TP->getAsTagDecl())
+addToken(Loc, TD);
+  }
+
   void addToken(SourceLocation Loc, const NamedDecl *D) {
 if (D->getDeclName().isIdentifier() && D->getName().empty())
   // Don't add symbols that don't have any length.
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -90,7 +90,7 @@
 typename T::A* $Field[[D]];
   };
   $Namespace[[abc]]::$Class[[A]] $Variable[[AA]];
-  typedef $Namespace[[abc]]::$Class[[A]] AAA;
+  typedef $Namespace[[abc]]::$Class[[A]] $Class[[AAA]];
   struct $Class[[B]] {
 $Class[[B]]();
 ~$Class[[B]]();
@@ -173,6 +173,19 @@
   }
   int $Variable[[B]];
   $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
+)cpp",
+R"cpp(
+  namespace $Namespace[[a]] {
+struct $Class[[A]] {};
+  }
+  typedef $Namespace[[a]]::$Class[[A]] $Class[[B]];
+  using $Class[[BB]] = $Namespace[[a]]::$Class[[A]];
+  enum class $Enum[[E]] {};
+  typedef $Enum[[E]] $Enum[[C]];
+  typedef $Enum[[C]] $Enum[[CC]];
+  using $Enum[[CD]] = $Enum[[CC]];
+  $Enum[[CC]] $Function[[f]]($Class[[B]]);
+  $Enum[[CD]] $Function[[f]]($Class[[BB]]);
 )cpp"};
   for (const auto  : TestCases) {
 checkHighlightings(TestCase);


Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -93,6 +93,12 @@
 return true;
   }
 
+  bool VisitTypedefNameDecl(TypedefNameDecl *TD) {
+if(const auto *TSI = TD->getTypeSourceInfo())
+  addTypeLoc(TD->getLocation(), TSI->getTypeLoc());
+return true;
+  }
+
   bool VisitTypeLoc(TypeLoc ) {
 // This check is for not getting two entries when there are anonymous
 // structs. It also makes us not highlight certain namespace qualifiers
@@ -101,9 +107,7 @@
 if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
   return true;
 
-if (const Type *TP = TL.getTypePtr())
-  if (const TagDecl *TD = TP->getAsTagDecl())
-addToken(TL.getBeginLoc(), TD);
+addTypeLoc(TL.getBeginLoc(), TL);
 return true;
   }
 
@@ -118,6 +122,12 @@
   }
 
 private:
+  void addTypeLoc(SourceLocation Loc, const TypeLoc ) {
+if (const Type *TP = TL.getTypePtr())
+  if (const TagDecl *TD = TP->getAsTagDecl())
+addToken(Loc, TD);
+  }
+
   void addToken(SourceLocation Loc, const NamedDecl *D) {
 if (D->getDeclName().isIdentifier() && D->getName().empty())
   // Don't add symbols that don't have any length.
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -90,7 +90,7 @@
 typename T::A* $Field[[D]];
 

[clang-tools-extra] r366207 - [clangd] Added highlighting for the targets in typedefs and using.

2019-07-16 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Tue Jul 16 06:23:12 2019
New Revision: 366207

URL: http://llvm.org/viewvc/llvm-project?rev=366207=rev
Log:
[clangd] Added highlighting for the targets in typedefs and using.

Summary:
In `typedef int A` the `A` was not highlighted previously.

This patch gives `A` the same kind of highlighting that the underlying type has 
(class/enum) (which in this example is no special highlighting because builtins 
are not handled yet)
Will add highlightings for built ins in another patch.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366207=366206=366207=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Tue Jul 16 06:23:12 
2019
@@ -93,6 +93,12 @@ public:
 return true;
   }
 
+  bool VisitTypedefNameDecl(TypedefNameDecl *TD) {
+if(const auto *TSI = TD->getTypeSourceInfo())
+  addTypeLoc(TD->getLocation(), TSI->getTypeLoc());
+return true;
+  }
+
   bool VisitTypeLoc(TypeLoc ) {
 // This check is for not getting two entries when there are anonymous
 // structs. It also makes us not highlight certain namespace qualifiers
@@ -101,9 +107,7 @@ public:
 if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
   return true;
 
-if (const Type *TP = TL.getTypePtr())
-  if (const TagDecl *TD = TP->getAsTagDecl())
-addToken(TL.getBeginLoc(), TD);
+addTypeLoc(TL.getBeginLoc(), TL);
 return true;
   }
 
@@ -118,6 +122,12 @@ public:
   }
 
 private:
+  void addTypeLoc(SourceLocation Loc, const TypeLoc ) {
+if (const Type *TP = TL.getTypePtr())
+  if (const TagDecl *TD = TP->getAsTagDecl())
+addToken(Loc, TD);
+  }
+
   void addToken(SourceLocation Loc, const NamedDecl *D) {
 if (D->getDeclName().isIdentifier() && D->getName().empty())
   // Don't add symbols that don't have any length.

Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366207=366206=366207=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Tue 
Jul 16 06:23:12 2019
@@ -90,7 +90,7 @@ TEST(SemanticHighlighting, GetsCorrectTo
 typename T::A* $Field[[D]];
   };
   $Namespace[[abc]]::$Class[[A]] $Variable[[AA]];
-  typedef $Namespace[[abc]]::$Class[[A]] AAA;
+  typedef $Namespace[[abc]]::$Class[[A]] $Class[[AAA]];
   struct $Class[[B]] {
 $Class[[B]]();
 ~$Class[[B]]();
@@ -173,6 +173,19 @@ TEST(SemanticHighlighting, GetsCorrectTo
   }
   int $Variable[[B]];
   $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
+)cpp",
+R"cpp(
+  namespace $Namespace[[a]] {
+struct $Class[[A]] {};
+  }
+  typedef $Namespace[[a]]::$Class[[A]] $Class[[B]];
+  using $Class[[BB]] = $Namespace[[a]]::$Class[[A]];
+  enum class $Enum[[E]] {};
+  typedef $Enum[[E]] $Enum[[C]];
+  typedef $Enum[[C]] $Enum[[CC]];
+  using $Enum[[CD]] = $Enum[[CC]];
+  $Enum[[CC]] $Function[[f]]($Class[[B]]);
+  $Enum[[CD]] $Function[[f]]($Class[[BB]]);
 )cpp"};
   for (const auto  : TestCases) {
 checkHighlightings(TestCase);


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


[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-16 Thread Marco Antognini via Phabricator via cfe-commits
mantognini updated this revision to Diff 210080.
mantognini added a comment.

- Refactored common bits from CheckConstructorDeclarator and 
CheckDestructorDeclarator.
- Added as many "ThisTy" parameter I could.
- Addressed issue with identifier format in tests (%N to %var.ascast).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64569/new/

https://reviews.llvm.org/D64569

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
  clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl

Index: clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
+
+// This test ensures the proper address spaces and address space cast are used
+// for constructors, member functions and destructors.
+// See also atexit.cl and global_init.cl for other specific tests.
+
+// CHECK: %struct.MyType = type { i32 }
+struct MyType {
+  MyType(int i) : i(i) {}
+  MyType(int i) __constant : i(i) {}
+  ~MyType() {}
+  ~MyType() __constant {}
+  int bar() { return i + 2; }
+  int bar() __constant { return i + 1; }
+  int i;
+};
+
+// CHECK: @const1 = addrspace(2) global %struct.MyType zeroinitializer
+__constant MyType const1 = 1;
+// CHECK: @const2 = addrspace(2) global %struct.MyType zeroinitializer
+__constant MyType const2(2);
+// CHECK: @glob = addrspace(1) global %struct.MyType zeroinitializer
+MyType glob(1);
+
+// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
+// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
+// CHECK: call void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*), i32 1)
+
+// CHECK-LABEL: define spir_kernel void @fooGlobal()
+kernel void fooGlobal() {
+  // CHECK: call i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*))
+  glob.bar();
+  // CHECK: call i32 @_ZNU3AS26MyType3barEv(%struct.MyType addrspace(2)* @const1)
+  const1.bar();
+  // CHECK: call void @_ZNU3AS26MyTypeD1Ev(%struct.MyType addrspace(2)* @const1)
+  const1.~MyType();
+}
+
+// CHECK-LABEL: define spir_kernel void @fooLocal()
+kernel void fooLocal() {
+  // CHECK: [[VAR:%.*]] = alloca %struct.MyType
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* [[REG]], i32 3)
+  MyType myLocal(3);
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* [[REG]])
+  myLocal.bar();
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call void @_ZNU3AS46MyTypeD1Ev(%struct.MyType addrspace(4)* [[REG]])
+}
+
+// Ensure all members are defined for all the required address spaces.
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* %this, i32 %i)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* %this, i32 %i)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS26MyTypeD1Ev(%struct.MyType addrspace(2)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS46MyTypeD1Ev(%struct.MyType addrspace(4)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr i32 @_ZNU3AS26MyType3barEv(%struct.MyType addrspace(2)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* %this)
Index: clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
-
-struct MyType {
-  MyType(int i) : i(i) {}
-  MyType(int i) __constant : i(i) {}
-  int i;
-};
-
-//CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
-__constant MyType const1 = 1;
-//CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
-__constant MyType const2(2);
-//CHECK: call void 

[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

2019-07-16 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 210079.
jvikstrom added a comment.

Moved highlighting state to LSP layer. Removed class holding state. Addressed 
comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64475/new/

https://reviews.llvm.org/D64475

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -29,7 +29,9 @@
   return Tokens;
 }
 
-void checkHighlightings(llvm::StringRef Code) {
+std::tuple,
+   std::vector>
+getHighlightingsAnnotated(llvm::StringRef Code) {
   Annotations Test(Code);
   auto AST = TestTU::withCode(Test.code()).build();
   static const std::map KindToString{
@@ -49,9 +51,41 @@
   }
 
   auto ActualTokens = getSemanticHighlightings(AST);
+  return {std::move(AST), ActualTokens, ExpectedTokens};
+}
+
+void checkHighlightings(llvm::StringRef Code) {
+  std::vector ActualTokens;
+  std::vector ExpectedTokens;
+  std::tie(std::ignore, ActualTokens, ExpectedTokens) =
+  getHighlightingsAnnotated(Code);
   EXPECT_THAT(ActualTokens, testing::UnorderedElementsAreArray(ExpectedTokens));
 }
 
+void checkDiffedHighlights(const std::vector ,
+   const std::vector ,
+   std::vector ) {
+  std::map> ExpectedLines;
+  for (const HighlightingToken  : ExpectedTokens)
+ExpectedLines[Token.R.start.line].push_back(Token);
+  std::vector ExpectedLinePairHighlighting;
+  for (int Line : EmptyLines)
+ExpectedLinePairHighlighting.push_back({Line, {}});
+  for (auto  : ExpectedLines) {
+llvm::sort(LineTokens.second);
+ExpectedLinePairHighlighting.push_back(
+{LineTokens.first, LineTokens.second});
+  }
+
+  // The UnorderedElementsAreArray only checks that the top level vector
+  // is unordered. The vectors in the pair must be in the correct order.
+  for (unsigned I = 0, End = ActualDiffed.size(); I < End; ++I)
+llvm::sort(ActualDiffed[I].Tokens);
+
+  EXPECT_THAT(ActualDiffed,
+  testing::UnorderedElementsAreArray(ExpectedLinePairHighlighting));
+}
+
 TEST(SemanticHighlighting, GetsCorrectTokens) {
   const char *TestCases[] = {
 R"cpp(
@@ -211,21 +245,103 @@
 return Pos;
   };
 
-  std::vector Tokens{
-  {HighlightingKind::Variable,
-Range{CreatePosition(3, 8), CreatePosition(3, 12)}},
-  {HighlightingKind::Function,
-Range{CreatePosition(3, 4), CreatePosition(3, 7)}},
-  {HighlightingKind::Variable,
-Range{CreatePosition(1, 1), CreatePosition(1, 5)}}};
+  std::vector Tokens{
+  {3,
+   {{HighlightingKind::Variable,
+ Range{CreatePosition(3, 8), CreatePosition(3, 12)}},
+{HighlightingKind::Function,
+ Range{CreatePosition(3, 4), CreatePosition(3, 7),
+  {1,
+   {{HighlightingKind::Variable,
+ Range{CreatePosition(1, 1), CreatePosition(1, 5)};
   std::vector ActualResults =
   toSemanticHighlightingInformation(Tokens);
   std::vector ExpectedResults = {
-  {1, "AQAEAAA="},
-  {3, "CAAEAAAEAAMAAQ=="}};
+  {3, "CAAEAAAEAAMAAQ=="}, {1, "AQAEAAA="}};
   EXPECT_EQ(ActualResults, ExpectedResults);
 }
 
+TEST(SemanticHighlighting, HighlightingDiffer) {
+  std::vector<
+  std::pair, std::pair>>
+  TestCases{{{},
+ {
+ R"cpp(
+int $Variable[[A]]
+double $Variable[[B]];
+struct $Class[[C]] {};
+  )cpp",
+ R"cpp(
+int A;
+double B;
+struct C {};
+  )cpp"}},
+{{5},
+ {
+ R"cpp(
+  struct $Class[[Alpha]] {
+double SomeVariable = 9483.301;
+  };
+  struct $Class[[Beta]] {};
+  int $Variable[[A]] = 121;
+  $Class[[Alpha]] $Variable[[Var]];
+  )cpp",
+ R"cpp(
+  struct Alpha {
+double SomeVariable = 9483.301;
+  };
+  struct Beta   {}; // Some comment
+  intA = 121;
+  $Class[[Beta]] $Variable[[Var]];
+  )cpp"}},
+{{},
+ {
+ R"cpp(
+  int $Variable[[A]] = 121; int $Variable[[B]];
+)cpp",
+ R"cpp(
+  intA = 121; int $Variable[[B]];
+)cpp"}},
+{{},
+ {
+ R"cpp(
+  int$Variable[[A]];
+  

  1   2   >