[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Does it really belong to Clang-tidy or Clang Analyzer is better place because 
of path-ensitivity?

Please rebase from trunk.

General note: CLang-tidy use //check// in terminology, not //checker//.




Comment at: docs/ReleaseNotes.rst:63
+
+  The checker aims to find loops where none of the
+  condition variables are updated in the body.

Just //Finds// instead of //The checker aims to find//. Please also align on 80 
symbols per line. Same in documentation.


https://reviews.llvm.org/D40937



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


[PATCH] D40671: [clang-tidy] Support specific checks for NOLINT directive

2017-12-06 Thread Anton via Phabricator via cfe-commits
xgsa added a comment.

So can this patch be submitted? Should I do something to make it happen?


https://reviews.llvm.org/D40671



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


[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added a comment.

Hi Eugen!
Good question, probably should have detailed it in the description.
This matcher based solution would not gain much benefit from the symbolic 
execution provided information. (I mean, it would mean a much different type of 
check on the states.) 
The main problems that the analyzer does not completely unroll the loops only 
the first steps and we always have information about the simulated path. 
However, detecting that some variables will surely not be modified requires a 
top level overview on the loop and the AST provides these informations. The one 
thing (that I can say right now) that can come handy is that we would able to 
detect more precisely the happened-before relation on the escape and the loop 
statements. Since the CFG can provide us fair enough information on this one, I 
do not think that this is enough reason to put this checker to the analyzer.

Other note: If somebody would came up with an approach which can benefit from 
the symbolic execution, these solutions could still live happily in the 
different tools eg. UseAfterMove (tidy) and MisusedMovedObjectChecker 
(analyzer).


https://reviews.llvm.org/D40937



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


[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D40937#947658, @szepet wrote:

> Other note: If somebody would came up with an approach which can benefit from 
> the symbolic execution, these solutions could still live happily in the 
> different tools eg. UseAfterMove (tidy) and MisusedMovedObjectChecker 
> (analyzer).


I'm more concerned with path sensitivity and reporting. From my point of view 
UseAfterMove also belongs to Analyzer realm.

Actually //bugprone// module may be better choice then //misc//.




Comment at: docs/ReleaseNotes.rst:63
+
+  The check finds loops where none of the condition variables are updated in 
the
+  body.

Please remove //The check//. See other checks release notes and documentation 
as style examples.

Please rebase from trunk, since I sorted Clang-tidy notes recently, so just 
prefer to avoid this task in future :-)


https://reviews.llvm.org/D40937



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


[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread JVApen via Phabricator via cfe-commits
JVApen added a comment.

How does this check deal with atomic members?

struct A {
 std:: atomic a;

void f() const { while (a); }
};


https://reviews.llvm.org/D40937



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


[PATCH] D40939: [analyzer] Avoid element regions of void type.

2017-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
Herald added subscribers: cfe-commits, rnkovacs.

Add an assertion that `ElementRegion`'s element type is not void.

Fix two violations of this rule that shown up on four of our existing test 
files.

I accidentally noticed that problem when i was looking at how 
`c++-allocator-inlining` mode handles `int *x = new int(5)` - apparently, it 
binds `5` to such broken region if a void pointer is returned by `operator 
new()`, which is a regression compared to the default mode. But this patch 
doesn't fix it (there were no tests for that).


Repository:
  rC Clang

https://reviews.llvm.org/D40939

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2169,7 +2169,14 @@
   for (auto *Node : CheckerPreStmt) {
 const LocationContext *LCtx = Node->getLocationContext();
 ProgramStateRef state = Node->getState();
-SVal V = state->getLValue(A->getType(),
+QualType T = A->getType();
+
+// One of the forbidden LValue types! We still need to have sensible
+// symbolic lvalues to represent this stuff.
+if (T->isVoidType())
+  T = getContext().CharTy;
+
+SVal V = state->getLValue(T,
   state->getSVal(Idx, LCtx),
   state->getSVal(Base, LCtx));
 Bldr.generateNode(A, Node, state->BindExpr(A, LCtx, V), nullptr,
Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -516,6 +516,10 @@
 assert(classof(this));
   }
 
+  static bool isValidTypeForRegion(QualType T) {
+return !T.isNull() && !T->isVoidType();
+  }
+
 public:
   virtual QualType getValueType() const = 0;
 
@@ -961,7 +965,10 @@
   CXXThisRegion(const PointerType *thisPointerTy,
 const StackArgumentsSpaceRegion *sReg)
   : TypedValueRegion(sReg, CXXThisRegionKind),
-ThisPointerTy(thisPointerTy) {}
+ThisPointerTy(thisPointerTy) {
+assert(isValidTypeForRegion(thisPointerTy->getPointeeType()) &&
+   "Invalid region type!");
+  }
 
   static void ProfileRegion(llvm::FoldingSetNodeID ,
 const PointerType *PT,
@@ -1075,6 +1082,7 @@
 assert((!Idx.getAs() ||
 Idx.castAs().getValue().isSigned()) &&
"The index must be signed");
+assert(isValidTypeForRegion(elementType) && "Invalid region type!");
   }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,


Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2169,7 +2169,14 @@
   for (auto *Node : CheckerPreStmt) {
 const LocationContext *LCtx = Node->getLocationContext();
 ProgramStateRef state = Node->getState();
-SVal V = state->getLValue(A->getType(),
+QualType T = A->getType();
+
+// One of the forbidden LValue types! We still need to have sensible
+// symbolic lvalues to represent this 

[PATCH] D40940: [ubsan] Use pass_object_size info in bounds checks

2017-12-06 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.
Herald added a reviewer: george.burgess.iv.

Teach UBSan's bounds check to opportunistically use pass_object_size
information to check array accesses.

rdar://33272922


https://reviews.llvm.org/D40940

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-pass-object-size.c


Index: test/CodeGen/ubsan-pass-object-size.c
===
--- /dev/null
+++ test/CodeGen/ubsan-pass-object-size.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-darwin10 
-fsanitize=array-bounds -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @foo(
+int foo(int *const p __attribute__((pass_object_size(0))), int n) {
+  int x = p[n];
+
+  // CHECK: [[SIZE_ALLOCA:%.*]] = alloca i64, align 8
+  // CHECK: store i64 %{{.*}}, i64* [[SIZE_ALLOCA]], align 8
+  // CHECK: [[LOAD_SIZE:%.*]] = load i64, i64* [[SIZE_ALLOCA]], align 8, 
!nosanitize
+  // CHECK-NEXT: [[SCALED_SIZE:%.*]] = udiv i64 [[LOAD_SIZE]], 4, !nosanitize
+  // CHECK-NEXT: [[SEXT_N:%.*]] = sext i32 %{{.*}} to i64, !nosanitize
+  // CHECK-NEXT: [[ICMP:%.*]] = icmp ult i64 [[SEXT_N]], [[SCALED_SIZE]], 
!nosanitize
+  // CHECK-NEXT: br i1 [[ICMP]], {{.*}} !nosanitize
+  // CHECK: __ubsan_handle_out_of_bounds
+
+  {
+int *p =  // Shadow the parameter.
+// CHECK-NOT: __ubsan_handle_out_of_bounds
+x = p[n];
+  }
+
+  // CHECK: ret i32
+  return x;
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -3932,6 +3932,10 @@
LValueBaseInfo *BaseInfo = nullptr,
TBAAAccessInfo *TBAAInfo = nullptr);
 
+  /// If \p E references a parameter with pass_object_size info, load the
+  /// object size and divide by the size of \p EltTy. Otherwise return null.
+  llvm::Value *LoadPassedObjectSize(const Expr *E, QualType EltTy);
+
   void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK);
 
 private:
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -814,6 +814,32 @@
   return false;
 }
 
+llvm::Value *CodeGenFunction::LoadPassedObjectSize(const Expr *E,
+   QualType EltTy) {
+  auto *DRE = dyn_cast(E->IgnoreImpCasts());
+  if (!DRE)
+return nullptr;
+
+  auto *PVD = dyn_cast(DRE->getDecl());
+  if (!PVD)
+return nullptr;
+
+  // Find the implicit size parameter.
+  auto SizeDeclIt = SizeArguments.find(PVD);
+  if (SizeDeclIt == SizeArguments.end())
+return nullptr;
+
+  ASTContext  = getContext();
+  const ImplicitParamDecl *IPD = SizeDeclIt->second;
+  assert(LocalDeclMap.count(IPD) && "Passed object size not loadable");
+  Address AddrOfSize = LocalDeclMap.find(IPD)->second;
+  llvm::Value *SizeInBytes = EmitLoadOfScalar(AddrOfSize, /*Volatile=*/false,
+  C.getSizeType(), 
E->getExprLoc());
+  llvm::Value *SizeOfElement = llvm::ConstantInt::get(
+  SizeInBytes->getType(), C.getTypeSizeInChars(EltTy).getQuantity());
+  return Builder.CreateUDiv(SizeInBytes, SizeOfElement);
+}
+
 /// If Base is known to point to the start of an array, return the length of
 /// that array. Return 0 if the length cannot be determined.
 static llvm::Value *getArrayIndexingBound(
@@ -835,9 +861,16 @@
 return CGF.Builder.getInt(CAT->getSize());
   else if (const auto *VAT = dyn_cast(AT))
 return CGF.getVLASize(VAT).first;
+  // Ignore pass_object_size here. It's not applicable on decayed pointers.
 }
   }
 
+  QualType EltTy{Base->getType()->getPointeeOrArrayElementType(), 0};
+  if (llvm::Value *POS = CGF.LoadPassedObjectSize(Base, EltTy)) {
+IndexedType = Base->getType();
+return POS;
+  }
+
   return nullptr;
 }
 


Index: test/CodeGen/ubsan-pass-object-size.c
===
--- /dev/null
+++ test/CodeGen/ubsan-pass-object-size.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-darwin10 -fsanitize=array-bounds -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @foo(
+int foo(int *const p __attribute__((pass_object_size(0))), int n) {
+  int x = p[n];
+
+  // CHECK: [[SIZE_ALLOCA:%.*]] = alloca i64, align 8
+  // CHECK: store i64 %{{.*}}, i64* [[SIZE_ALLOCA]], align 8
+  // CHECK: [[LOAD_SIZE:%.*]] = load i64, i64* [[SIZE_ALLOCA]], align 8, !nosanitize
+  // CHECK-NEXT: [[SCALED_SIZE:%.*]] = udiv i64 [[LOAD_SIZE]], 4, !nosanitize
+  // CHECK-NEXT: [[SEXT_N:%.*]] = sext i32 %{{.*}} to i64, !nosanitize
+  // CHECK-NEXT: [[ICMP:%.*]] = icmp ult i64 [[SEXT_N]], [[SCALED_SIZE]], !nosanitize
+  // CHECK-NEXT: br i1 [[ICMP]], {{.*}} !nosanitize
+  // CHECK: __ubsan_handle_out_of_bounds
+
+  {
+int *p =  // Shadow the parameter.
+// CHECK-NOT: 

[PATCH] D37057: [clang] Require address space to be specified when creating functions (4/4)

2017-12-06 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay updated this revision to Diff 125887.
dylanmckay added a comment.
Herald added a subscriber: cfe-commits.

- Remove the switch table stuff for a later patch
- Rebased on top of trunk


Repository:
  rC Clang

https://reviews.llvm.org/D37057

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCUDANV.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGGPUBuiltin.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -8974,7 +8974,7 @@
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
   auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
-   ());
+   CGF.CGM.getModule());
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);
   auto  = CGF.Builder;
@@ -9032,7 +9032,7 @@
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
   auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
-   ());
+   CGF.CGM.getModule());
   F->addFnAttr("enqueued-block");
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1928,7 +1928,7 @@
   llvm::FunctionType *ThunkTy = CGM.getTypes().GetFunctionType(FnInfo);
   llvm::Function *ThunkFn =
   llvm::Function::Create(ThunkTy, llvm::Function::ExternalLinkage,
- ThunkName.str(), ());
+ ThunkName.str(), CGM.getModule());
   assert(ThunkFn->getName() == ThunkName && "name was uniqued!");
 
   ThunkFn->setLinkage(MD->isExternallyVisible()
@@ -3856,7 +3856,7 @@
   const CXXRecordDecl *RD = CD->getParent();
   QualType RecordTy = getContext().getRecordType(RD);
   llvm::Function *ThunkFn = llvm::Function::Create(
-  ThunkTy, getLinkageForRTTI(RecordTy), ThunkName.str(), ());
+  ThunkTy, getLinkageForRTTI(RecordTy), ThunkName.str(), CGM.getModule());
   ThunkFn->setCallingConv(static_cast(
   FnInfo.getEffectiveCallingConvention()));
   if (ThunkFn->isWeakForLinker())
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2291,7 +2291,7 @@
   llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FI);
   llvm::Function *Wrapper =
   llvm::Function::Create(FnTy, getThreadLocalWrapperLinkage(VD, CGM),
- WrapperName.str(), ());
+ WrapperName.str(), CGM.getModule());
 
   CGM.SetLLVMFunctionAttributes(nullptr, FI, Wrapper);
 
@@ -2398,7 +2398,7 @@
   llvm::FunctionType *FnTy = llvm::FunctionType::get(CGM.VoidTy, false);
   Init = llvm::Function::Create(FnTy,
 llvm::GlobalVariable::ExternalWeakLinkage,
-InitFnName.str(), ());
+InitFnName.str(), CGM.getModule());
   const CGFunctionInfo  = CGM.getTypes().arrangeNullaryFunction();
   CGM.SetLLVMFunctionAttributes(nullptr, FI, cast(Init));
 }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2124,7 +2124,7 @@
 
   llvm::Function *F =
   llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
- Entry ? StringRef() : MangledName, ());
+ Entry ? StringRef() : MangledName, getModule());
 
   // If we already created a function with the same mangled name (but different
   // type) before, take its name and add it to the list of functions to be
Index: lib/CodeGen/CGStmtOpenMP.cpp
===
--- lib/CodeGen/CGStmtOpenMP.cpp
+++ lib/CodeGen/CGStmtOpenMP.cpp
@@ -381,7 +381,7 @@
 
   llvm::Function *F =
   llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage,
- FO.FunctionName, ());
+ FO.FunctionName, CGM.getModule());
   

[PATCH] D40806: CodeGen: Fix invalid bitcasts for memcpy

2017-12-06 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL32: CodeGen: Fix invalid bitcasts for memcpy (authored 
by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D40806?vs=125417=125863#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40806

Files:
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl

Index: cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
===
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown-amdgiz -S -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
+// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,R600 %s
 
 typedef __attribute__(( ext_vector_type(2) )) char char2;
 typedef __attribute__(( ext_vector_type(3) )) char char3;
@@ -309,7 +309,8 @@
 // CHECK: void @func_different_size_type_pair_arg(i64 %arg1.coerce0, i32 %arg1.coerce1)
 void func_different_size_type_pair_arg(different_size_type_pair arg1) { }
 
-// CHECK: void @func_flexible_array_arg(%struct.flexible_array* byval nocapture align 4 %arg)
+// AMDGCN: void @func_flexible_array_arg(%struct.flexible_array addrspace(5)* byval nocapture align 4 %arg)
+// R600: void @func_flexible_array_arg(%struct.flexible_array* byval nocapture align 4 %arg)
 void func_flexible_array_arg(flexible_array arg) { }
 
 // CHECK: define float @func_f32_ret()
@@ -404,14 +405,16 @@
   return s;
 }
 
-// CHECK: define void @func_ret_struct_arr32(%struct.struct_arr32* noalias nocapture sret %agg.result)
+// AMDGCN: define void @func_ret_struct_arr32(%struct.struct_arr32 addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define void @func_ret_struct_arr32(%struct.struct_arr32* noalias nocapture sret %agg.result)
 struct_arr32 func_ret_struct_arr32()
 {
   struct_arr32 s = { 0 };
   return s;
 }
 
-// CHECK: define void @func_ret_struct_arr33(%struct.struct_arr33* noalias nocapture sret %agg.result)
+// AMDGCN: define void @func_ret_struct_arr33(%struct.struct_arr33 addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define void @func_ret_struct_arr33(%struct.struct_arr33* noalias nocapture sret %agg.result)
 struct_arr33 func_ret_struct_arr33()
 {
   struct_arr33 s = { 0 };
@@ -440,7 +443,8 @@
   return s;
 }
 
-// CHECK: define void @func_flexible_array_ret(%struct.flexible_array* noalias nocapture sret %agg.result)
+// AMDGCN: define void @func_flexible_array_ret(%struct.flexible_array addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define void @func_flexible_array_ret(%struct.flexible_array* noalias nocapture sret %agg.result)
 flexible_array func_flexible_array_ret()
 {
   flexible_array s = { 0 };
@@ -450,11 +454,13 @@
 // CHECK: define void @func_reg_state_lo(<4 x i32> %arg0, <4 x i32> %arg1, <4 x i32> %arg2, i32 %arg3, i32 %s.coerce0, float %s.coerce1, i32 %s.coerce2)
 void func_reg_state_lo(int4 arg0, int4 arg1, int4 arg2, int arg3, struct_arg_t s) { }
 
-// CHECK: define void @func_reg_state_hi(<4 x i32> %arg0, <4 x i32> %arg1, <4 x i32> %arg2, i32 %arg3, i32 %arg4, %struct.struct_arg* byval nocapture align 4 %s)
+// AMDGCN: define void @func_reg_state_hi(<4 x i32> %arg0, <4 x i32> %arg1, <4 x i32> %arg2, i32 %arg3, i32 %arg4, %struct.struct_arg addrspace(5)* byval nocapture align 4 %s)
+// R600: define void @func_reg_state_hi(<4 x i32> %arg0, <4 x i32> %arg1, <4 x i32> %arg2, i32 %arg3, i32 %arg4, %struct.struct_arg* byval nocapture align 4 %s)
 void func_reg_state_hi(int4 arg0, int4 arg1, int4 arg2, int arg3, int arg4, struct_arg_t s) { }
 
 // XXX - Why don't the inner structs flatten?
-// CHECK: define void @func_reg_state_num_regs_nested_struct(<4 x i32> %arg0, i32 %arg1, i32 %arg2.coerce0, %struct.nested %arg2.coerce1, i32 %arg3.coerce0, %struct.nested %arg3.coerce1, %struct.num_regs_nested_struct* byval nocapture align 8 %arg4)
+// AMDGCN: define void @func_reg_state_num_regs_nested_struct(<4 x i32> %arg0, i32 %arg1, i32 %arg2.coerce0, %struct.nested %arg2.coerce1, i32 %arg3.coerce0, %struct.nested %arg3.coerce1, %struct.num_regs_nested_struct addrspace(5)* byval nocapture align 8 %arg4)
+// R600: define void @func_reg_state_num_regs_nested_struct(<4 x i32> %arg0, i32 %arg1, i32 %arg2.coerce0, %struct.nested %arg2.coerce1, i32 %arg3.coerce0, %struct.nested %arg3.coerce1, %struct.num_regs_nested_struct* byval nocapture align 8 %arg4)
 void func_reg_state_num_regs_nested_struct(int4 arg0, int arg1, num_regs_nested_struct arg2, num_regs_nested_struct arg3, num_regs_nested_struct arg4) { }
 
 // CHECK: define void 

r320000 - CodeGen: Fix invalid bitcasts for memcpy

2017-12-06 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Wed Dec  6 17:39:52 2017
New Revision: 32

URL: http://llvm.org/viewvc/llvm-project?rev=32=rev
Log:
CodeGen: Fix invalid bitcasts for memcpy

CreateCoercedLoad/CreateCoercedStore assumes pointer argument of
memcpy is in addr space 0, which is not correct and causes invalid
bitcasts for triple amdgcn---amdgiz.

It is fixed by using alloca addr space instead.

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

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

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=32=31=32=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Dec  6 17:39:52 2017
@@ -1234,8 +1234,8 @@ static llvm::Value *CreateCoercedLoad(Ad
 
   // Otherwise do coercion through memory. This is stupid, but simple.
   Address Tmp = CreateTempAllocaForCoercion(CGF, Ty, Src.getAlignment());
-  Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.Int8PtrTy);
-  Address SrcCasted = CGF.Builder.CreateBitCast(Src, CGF.Int8PtrTy);
+  Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
+  Address SrcCasted = CGF.Builder.CreateBitCast(Src, CGF.AllocaInt8PtrTy);
   CGF.Builder.CreateMemCpy(Casted, SrcCasted,
   llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize),
   false);
@@ -1316,8 +1316,8 @@ static void CreateCoercedStore(llvm::Val
 // to that information.
 Address Tmp = CreateTempAllocaForCoercion(CGF, SrcTy, Dst.getAlignment());
 CGF.Builder.CreateStore(Src, Tmp);
-Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.Int8PtrTy);
-Address DstCasted = CGF.Builder.CreateBitCast(Dst, CGF.Int8PtrTy);
+Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
+Address DstCasted = CGF.Builder.CreateBitCast(Dst, CGF.AllocaInt8PtrTy);
 CGF.Builder.CreateMemCpy(DstCasted, Casted,
 llvm::ConstantInt::get(CGF.IntPtrTy, DstSize),
 false);

Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl?rev=32=31=32=diff
==
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl Wed Dec  6 
17:39:52 2017
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
-// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown-amdgiz -S -emit-llvm -o - %s 
| FileCheck -check-prefixes=CHECK,AMDGCN %s
+// RUN: %clang_cc1 -triple r600-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK,R600 %s
 
 typedef __attribute__(( ext_vector_type(2) )) char char2;
 typedef __attribute__(( ext_vector_type(3) )) char char3;
@@ -309,7 +309,8 @@ void func_single_struct_element_struct_a
 // CHECK: void @func_different_size_type_pair_arg(i64 %arg1.coerce0, i32 
%arg1.coerce1)
 void func_different_size_type_pair_arg(different_size_type_pair arg1) { }
 
-// CHECK: void @func_flexible_array_arg(%struct.flexible_array* byval 
nocapture align 4 %arg)
+// AMDGCN: void @func_flexible_array_arg(%struct.flexible_array addrspace(5)* 
byval nocapture align 4 %arg)
+// R600: void @func_flexible_array_arg(%struct.flexible_array* byval nocapture 
align 4 %arg)
 void func_flexible_array_arg(flexible_array arg) { }
 
 // CHECK: define float @func_f32_ret()
@@ -404,14 +405,16 @@ struct_arr16 func_ret_struct_arr16()
   return s;
 }
 
-// CHECK: define void @func_ret_struct_arr32(%struct.struct_arr32* noalias 
nocapture sret %agg.result)
+// AMDGCN: define void @func_ret_struct_arr32(%struct.struct_arr32 
addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define void @func_ret_struct_arr32(%struct.struct_arr32* noalias 
nocapture sret %agg.result)
 struct_arr32 func_ret_struct_arr32()
 {
   struct_arr32 s = { 0 };
   return s;
 }
 
-// CHECK: define void @func_ret_struct_arr33(%struct.struct_arr33* noalias 
nocapture sret %agg.result)
+// AMDGCN: define void @func_ret_struct_arr33(%struct.struct_arr33 
addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define void @func_ret_struct_arr33(%struct.struct_arr33* noalias 
nocapture sret %agg.result)
 struct_arr33 func_ret_struct_arr33()
 {
   struct_arr33 s = { 0 };
@@ -440,7 +443,8 @@ different_size_type_pair func_different_
   return s;
 }
 
-// CHECK: define void @func_flexible_array_ret(%struct.flexible_array* noalias 
nocapture sret %agg.result)
+// AMDGCN: define void @func_flexible_array_ret(%struct.flexible_array 
addrspace(5)* noalias nocapture sret %agg.result)
+// R600: define 

[PATCH] D40936: Hardware-assisted AddressSanitizer (clang part).

2017-12-06 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc accepted this revision.
kcc added a comment.
This revision is now accepted and ready to land.

LGTM
please give at least Aleksey a chance to review as well.


https://reviews.llvm.org/D40936



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


[PATCH] D40806: CodeGen: Fix invalid bitcasts for memcpy

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



Comment at: cfe/trunk/lib/CodeGen/CGCall.cpp:1238
+  Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
+  Address SrcCasted = CGF.Builder.CreateBitCast(Src, CGF.AllocaInt8PtrTy);
   CGF.Builder.CreateMemCpy(Casted, SrcCasted,

There is a CreateElementBitCast method on CGBuilderTy that preserves the source 
address space; that seems like the obviously correct fix here instead of 
assuming any specific address space on either operand.



Comment at: cfe/trunk/lib/CodeGen/CGCall.cpp:1320
+Address Casted = CGF.Builder.CreateBitCast(Tmp, CGF.AllocaInt8PtrTy);
+Address DstCasted = CGF.Builder.CreateBitCast(Dst, CGF.AllocaInt8PtrTy);
 CGF.Builder.CreateMemCpy(DstCasted, Casted,

Same.


Repository:
  rL LLVM

https://reviews.llvm.org/D40806



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


[PATCH] D40938: update hwasan docs

2017-12-06 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc created this revision.
Herald added a subscriber: cfe-commits.

- use more readable name
- document the hwasan attribute


Repository:
  rC Clang

https://reviews.llvm.org/D40938

Files:
  docs/HardwareAssistedAddressSanitizerDesign.rst


Index: docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- docs/HardwareAssistedAddressSanitizerDesign.rst
+++ docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -1,9 +1,9 @@
-=
-HardwareAssistedAddressSanitizer Design Documentation
-=
+===
+Hardware-assisted AddressSanitizer Design Documentation
+===
 
 This page is a design document for
-**HardwareAssistedAddressSanitizer** (or HWASAN)
+**hardware-assisted AddressSanitizer** (or **HWASAN**)
 a tool similar to :doc:`AddressSanitizer`,
 but based on partial hardware assistance.
 
@@ -23,7 +23,7 @@
 
 AArch64 has the `Address Tagging`_, a hardware feature that allows
 software to use 8 most significant bits of a 64-bit pointer as
-a tag. HardwareAssistedAddressSanitizer uses `Address Tagging`_
+a tag. HWASAN uses `Address Tagging`_
 to implement a memory safety tool, similar to :doc:`AddressSanitizer`,
 but with smaller memory overhead and slightly different (mostly better)
 accuracy guarantees.
@@ -77,11 +77,26 @@
 
 Errors are generated by `__builtin_trap` and are handled by a signal handler.
 
+Attribute
+-
+
+HWASAN uses it's own LLVM IR Attribute `sanitize_hwaddress` and a matching
+C function attribute. An alternative would be to re-use ASAN's attribute
+`sanitize_address`. The reasons to use a separate attribute are:
+
+  * Users may need to disable ASAN but not HWASAN, or vise versa,
+because the tools have different trade-offs and compatibility issues.
+  * LLVM (ideally) does not use flags to decide which pass is being used,
+ASAN or HWASAN are being applied, based on the function attributes.
+
+This does mean that users of HWASAN may need to add the new attribute
+to the code that already uses the old attribute.
+
 
 Comparison with AddressSanitizer
 
 
-HardwareAssistedAddressSanitizer:
+HWASAN:
   * Is less portable than :doc:`AddressSanitizer`
 as it relies on hardware `Address Tagging`_ (AArch64).
 Address Tagging can be emulated with compiler instrumentation,
@@ -99,7 +114,7 @@
 or stack-use-after-return**.
 The detection is similarly probabilistic.
 
-The memory overhead of HardwareAssistedAddressSanitizer is expected to be much 
smaller
+The memory overhead of HWASAN is expected to be much smaller
 than that of AddressSanitizer:
 `1/N` extra memory for the shadow
 and some overhead due to `N`-aligning all objects.


Index: docs/HardwareAssistedAddressSanitizerDesign.rst
===
--- docs/HardwareAssistedAddressSanitizerDesign.rst
+++ docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -1,9 +1,9 @@
-=
-HardwareAssistedAddressSanitizer Design Documentation
-=
+===
+Hardware-assisted AddressSanitizer Design Documentation
+===
 
 This page is a design document for
-**HardwareAssistedAddressSanitizer** (or HWASAN)
+**hardware-assisted AddressSanitizer** (or **HWASAN**)
 a tool similar to :doc:`AddressSanitizer`,
 but based on partial hardware assistance.
 
@@ -23,7 +23,7 @@
 
 AArch64 has the `Address Tagging`_, a hardware feature that allows
 software to use 8 most significant bits of a 64-bit pointer as
-a tag. HardwareAssistedAddressSanitizer uses `Address Tagging`_
+a tag. HWASAN uses `Address Tagging`_
 to implement a memory safety tool, similar to :doc:`AddressSanitizer`,
 but with smaller memory overhead and slightly different (mostly better)
 accuracy guarantees.
@@ -77,11 +77,26 @@
 
 Errors are generated by `__builtin_trap` and are handled by a signal handler.
 
+Attribute
+-
+
+HWASAN uses it's own LLVM IR Attribute `sanitize_hwaddress` and a matching
+C function attribute. An alternative would be to re-use ASAN's attribute
+`sanitize_address`. The reasons to use a separate attribute are:
+
+  * Users may need to disable ASAN but not HWASAN, or vise versa,
+because the tools have different trade-offs and compatibility issues.
+  * LLVM (ideally) does not use flags to decide which pass is being used,
+ASAN or HWASAN are being applied, based on the function attributes.
+
+This does mean that users of HWASAN may need to add the new attribute
+to the code that already uses the old attribute.
+
 
 Comparison with AddressSanitizer
 
 

[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 125870.
szepet marked an inline comment as done.
szepet added a comment.

Updated the wording in the docs.


https://reviews.llvm.org/D40937

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/InfiniteLoopCheck.cpp
  clang-tidy/misc/InfiniteLoopCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-infinite-loop.rst
  test/clang-tidy/misc-infinite-loop.cpp

Index: test/clang-tidy/misc-infinite-loop.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-infinite-loop.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s misc-infinite-loop %t
+
+void simple_infinite_loop1() {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body [misc-infinite-loop]
+j++;
+  }
+
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body
+j++;
+  } while (i < 10);
+
+  for (i = 0; i < 10; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body
+  }
+}
+
+void simple_infinite_loop2() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body [misc-infinite-loop]
+j++;
+  }
+
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+j++;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+  }
+}
+
+void simple_not_infinite() {
+  int i = 0;
+  int Limit = 100;
+  while (i < Limit) { // Not an error since 'Limit' is updated
+Limit--;
+  }
+  do {
+Limit--;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit;Limit--) {
+  }
+}
+
+void escape_before1() {
+  int i = 0;
+  int Limit = 100;
+  int *p = 
+  while (i < Limit) { // Not an error, since p is alias of i.
+*++p;
+  }
+
+  do {
+*++p;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; *++p) {
+  }
+}
+
+void escape_before2() {
+  int i = 0;
+  int Limit = 100;
+  int *p = 
+  while (i < Limit) { // We do not warn since the var 'i' is escaped but it is
+  // an actual error, since the pointer 'p' is increased.
+*(p++);
+  }
+}
+
+void escape_after() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+  }
+  int *p = 
+}
+
+int glob;
+void glob_var(int ) {
+  int i = 0, Limit = 100;
+  while (x < Limit) { // Not an error since 'x' can be an alias of glob.
+glob++;
+  }
+}
+
+void glob_var2() {
+  int i = 0, Limit = 100;
+  while (glob < Limit) { // Since 'glob' is declared out of the function we do not warn.
+i++;
+  }
+}
Index: docs/clang-tidy/checks/misc-infinite-loop.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-infinite-loop.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-infinite-loop
+
+misc-infinite-loop
+==
+
+The check finds loops where none of the condition variables are updated in the
+body. This performs a very conservative check in order to avoid false positives
+and work only on integer types at the moment.
+
+Examples:
+
+.. code-block:: c++
+
+  void simple_infinite_loop() {
+int i = 0;
+int j = 0;
+int Limit = 10;
+while (i < Limit) { // Error, since none of the variables are updated.
+  j++;
+}
+  }
+
+  void escape_before() {
+int i = 0;
+int Limit = 100;
+int *p = 
+while (i < Limit) { // Not an error, since p is alias of i.
+  *++p;
+}
+  }
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -119,6 +119,7 @@
misc-definitions-in-headers
misc-forwarding-reference-overload
misc-incorrect-roundings
+   misc-infinite-loop
misc-lambda-function-name
misc-macro-parentheses
misc-macro-repeated-side-effects
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `misc-infinite-loop
+  `_ check
+
+  The check finds loops where none of the condition variables are updated in the
+  body.
+
 - The 'misc-move-constructor-init' check was renamed to `performance-move-constructor-init
   

r320008 - Test commit access

2017-12-06 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Wed Dec  6 22:27:58 2017
New Revision: 320008

URL: http://llvm.org/viewvc/llvm-project?rev=320008=rev
Log:
Test commit access

Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=320008=320007=320008=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Dec  6 22:27:58 2017
@@ -4295,7 +4295,7 @@ static TypeSourceInfo *GetFullTypeForDec
   << T << D.getSourceRange();
 D.setInvalidType(true);
   } else if (D.getName().getKind() ==
- UnqualifiedId::IK_DeductionGuideName) {
+ UnqualifiedId::IK_DeductionGuideName) {
 if (T != Context.DependentTy) {
   S.Diag(D.getDeclSpec().getLocStart(),
  diag::err_deduction_guide_with_complex_decl)


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


[PATCH] D40941: [ubsan] Use pass_object_size info in bounds checks (compiler-rt)

2017-12-06 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.
Herald added subscribers: dberris, kubamracek.

This is a test update for the clang change in https://reviews.llvm.org/D40940


https://reviews.llvm.org/D40941

Files:
  test/ubsan/TestCases/Misc/bounds.cpp


Index: test/ubsan/TestCases/Misc/bounds.cpp
===
--- test/ubsan/TestCases/Misc/bounds.cpp
+++ test/ubsan/TestCases/Misc/bounds.cpp
@@ -5,7 +5,23 @@
 // RUN: %run %t 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3
 // RUN: %run %t 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4
 
+int get_int(int *const p __attribute__((pass_object_size(0))), int i) {
+  // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of 
bounds for type 'int *'
+  return p[i];
+}
+
+int get_double(double *const p __attribute__((pass_object_size(0))), int i) {
+  // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of 
bounds for type 'double *'
+  return p[i];
+}
+
 int main(int argc, char **argv) {
+  int bar[2];
+  get_int(bar, argv[1][0] - '0');
+
+  double baz[2];
+  get_double(baz, argv[1][0] - '0');
+
   int arr[2][3][4] = {};
 
   return arr[argv[1][0] - '0'][argv[2][0] - '0'][argv[3][0] - '0'];


Index: test/ubsan/TestCases/Misc/bounds.cpp
===
--- test/ubsan/TestCases/Misc/bounds.cpp
+++ test/ubsan/TestCases/Misc/bounds.cpp
@@ -5,7 +5,23 @@
 // RUN: %run %t 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3
 // RUN: %run %t 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4
 
+int get_int(int *const p __attribute__((pass_object_size(0))), int i) {
+  // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of bounds for type 'int *'
+  return p[i];
+}
+
+int get_double(double *const p __attribute__((pass_object_size(0))), int i) {
+  // CHECK-A-2: bounds.cpp:[[@LINE+1]]:10: runtime error: index 2 out of bounds for type 'double *'
+  return p[i];
+}
+
 int main(int argc, char **argv) {
+  int bar[2];
+  get_int(bar, argv[1][0] - '0');
+
+  double baz[2];
+  get_double(baz, argv[1][0] - '0');
+
   int arr[2][3][4] = {};
 
   return arr[argv[1][0] - '0'][argv[2][0] - '0'][argv[3][0] - '0'];
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Peter Szecsi via Phabricator via cfe-commits
szepet created this revision.
Herald added subscribers: rnkovacs, baloghadamsoftware, whisperity, mgorny.

The checker aims to find loops where none of the condition variables are 
updated in the body. 
In this version it only works on integer types but the final aim is to make it 
work for objects as well. (via checking non-const method calls, etc)

Note: this kind of check is supported by clang warning as well 
(-Wfor-loop-analysis), however, it only works on for-loops and not investigate 
escape statements (modification via alias generates false positives e.g.  
`escape_before1()` test case).

Any suggestions on the checker are welcome!


https://reviews.llvm.org/D40937

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/InfiniteLoopCheck.cpp
  clang-tidy/misc/InfiniteLoopCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-infinite-loop.rst
  test/clang-tidy/misc-infinite-loop.cpp

Index: test/clang-tidy/misc-infinite-loop.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-infinite-loop.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s misc-infinite-loop %t
+
+void simple_infinite_loop1() {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body [misc-infinite-loop]
+j++;
+  }
+
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body
+j++;
+  } while (i < 10);
+
+  for (i = 0; i < 10; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: The condition variable (i) is not updated in the loop body
+  }
+}
+
+void simple_infinite_loop2() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body [misc-infinite-loop]
+j++;
+  }
+
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+j++;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+  }
+}
+
+void simple_not_infinite() {
+  int i = 0;
+  int Limit = 100;
+  while (i < Limit) { // Not an error since 'Limit' is updated
+Limit--;
+  }
+  do {
+Limit--;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit;Limit--) {
+  }
+}
+
+void escape_before1() {
+  int i = 0;
+  int Limit = 100;
+  int *p = 
+  while (i < Limit) { // Not an error, since p is alias of i.
+*++p;
+  }
+
+  do {
+*++p;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; *++p) {
+  }
+}
+
+void escape_before2() {
+  int i = 0;
+  int Limit = 100;
+  int *p = 
+  while (i < Limit) { // We do not warn since the var 'i' is escaped but it is
+  // an actual error, since the pointer 'p' is increased.
+*(p++);
+  }
+}
+
+void escape_after() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: None of the condition variables (i, Limit) are updated in the loop body
+  }
+  int *p = 
+}
+
+int glob;
+void glob_var(int ) {
+  int i = 0, Limit = 100;
+  while (x < Limit) { // Not an error since 'x' can be an alias of glob.
+glob++;
+  }
+}
+
+void glob_var2() {
+  int i = 0, Limit = 100;
+  while (glob < Limit) { // Since 'glob' is declared out of the function we do not warn.
+i++;
+  }
+}
Index: docs/clang-tidy/checks/misc-infinite-loop.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-infinite-loop.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - misc-infinite-loop
+
+misc-infinite-loop
+==
+
+The checker aims to find loops where none of the condition variables are
+updated in the body. This performs a very conservative check in order to
+avoid false positives and work only on integer types at the moment.
+
+Examples:
+
+.. code-block:: c++
+
+  void simple_infinite_loop() {
+int i = 0;
+int j = 0;
+int Limit = 10;
+while (i < Limit) { // Error, since none of the variables are updated.
+  j++;
+}
+  }
+
+  void escape_before() {
+int i = 0;
+int Limit = 100;
+int *p = 
+while (i < Limit) { // Not an error, since p is alias of i.
+  *++p;
+}
+  }
+  
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -119,6 +119,7 @@
misc-definitions-in-headers
misc-forwarding-reference-overload
misc-incorrect-roundings
+   misc-infinite-loop
misc-lambda-function-name
misc-macro-parentheses
misc-macro-repeated-side-effects
Index: 

[PATCH] D40939: [analyzer] Avoid element regions of void type.

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

> I accidentally noticed that problem

The actual problem was that `RegionStore` was unable to retrieve the binding to 
such `ElementRegion` (in case of this example, `5 S32b`). There may be more 
problems with such regions. But at the same time i believe that the very idea 
of a void `ElementRegion` is frightening enough to be fixed on its own.


Repository:
  rC Clang

https://reviews.llvm.org/D40939



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


[PATCH] D40929: Unblock Swift Calling Convention Mangling on Windows

2017-12-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added reviewers: rnk, majnemer.
rjmccall added a comment.

Reid, David, do you have a recommendation about the right way to support 
non-MS-supported CCs here?


Repository:
  rC Clang

https://reviews.llvm.org/D40929



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


[PATCH] D40937: [clang-tidy] Infinite loop checker

2017-12-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:94
+
+std::unique_ptr createSequence(Stmt *FunctionBody,
+ ASTContext ) {

Missing static?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:102
+  if (!TheCFG)
+return std::unique_ptr();
+

May be return {}?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:125
+
+  auto CondVarMatches =
+  match(findAll(declRefExpr(to(varDecl().bind("condvar", *Cond, 
ASTCtx);

const auto?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:130
+
+  for (auto  : CondVarMatches) {
+const VarDecl *CondVar = E.getNodeAs("condvar");

const auto?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:142
+// (excluding the init stmt).
+if (auto ForLoop = dyn_cast(LoopStmt)) {
+  if (ForLoop->getInc())

const auto?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:168
+*FunctionBody, ASTCtx);
+for (auto  : Match) {
+  if (Sequence->potentiallyAfter(LoopStmt, ES.getNodeAs("escStmt")))

const auto?



Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:176
+  std::string CondVarNames = "";
+  for (auto  : CondVarMatches) {
+CondVarNames += CVM.getNodeAs("condvar")->getNameAsString() + ", 
";

const auto?


https://reviews.llvm.org/D40937



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


[PATCH] D39284: Allow conditions to be decomposed with structured bindings

2017-12-06 Thread Zhihao Yuan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC320011: Allow conditions to be decomposed with structured 
bindings (authored by lichray).

Changed prior to commit:
  https://reviews.llvm.org/D39284?vs=125665=125892#toc

Repository:
  rC Clang

https://reviews.llvm.org/D39284

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/Parser/cxx1z-decomposition.cpp
  test/Parser/decomposed-condition.cpp
  test/SemaCXX/decomposed-condition.cpp

Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -414,6 +414,9 @@
   "C++ standards before C++17">, DefaultIgnore, InGroup;
 def ext_decomp_decl : ExtWarn<
   "decomposition declarations are a C++17 extension">, InGroup;
+def ext_decomp_decl_cond : ExtWarn<
+  "ISO C++17 does not permit structured binding declaration in a condition">,
+  InGroup>;
 def err_decomp_decl_spec : Error<
   "decomposition declaration cannot be declared "
   "%plural{1:'%1'|:with '%1' specifiers}0">;
Index: include/clang/Sema/DeclSpec.h
===
--- include/clang/Sema/DeclSpec.h
+++ include/clang/Sema/DeclSpec.h
@@ -1995,9 +1995,9 @@
 case BlockContext:
 case ForContext:
 case InitStmtContext:
+case ConditionContext:
   return true;
 
-case ConditionContext:
 case MemberContext:
 case PrototypeContext:
 case TemplateParamContext:
Index: test/Parser/decomposed-condition.cpp
===
--- test/Parser/decomposed-condition.cpp
+++ test/Parser/decomposed-condition.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -std=c++1z %s -verify
+
+struct Na {
+  bool flag;
+  float data;
+};
+
+struct Rst {
+  bool flag;
+  float data;
+  explicit operator bool() const {
+return flag;
+  }
+};
+
+Rst f();
+Na g();
+
+namespace CondInIf {
+void h() {
+  if (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  if (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInIf
+
+namespace CondInWhile {
+void h() {
+  while (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  while (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInWhile
+
+namespace CondInFor {
+void h() {
+  for (; auto [ok, d] = f();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  for (; auto [ok, d] = g();) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInFor
+
+struct IntegerLike {
+  bool flag;
+  float data;
+  operator int() const {
+return int(data);
+  }
+};
+
+namespace CondInSwitch {
+void h(IntegerLike x) {
+  switch (auto [ok, d] = x) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}}
+;
+  switch (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit structured binding declaration in a condition}} expected-error {{statement requires expression of integer type ('Na' invalid)}}
+;
+}
+} // namespace CondInSwitch
Index: test/Parser/cxx1z-decomposition.cpp
===
--- test/Parser/cxx1z-decomposition.cpp
+++ test/Parser/cxx1z-decomposition.cpp
@@ -32,13 +32,14 @@
   void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
-// A condition is not a simple-declaration.
-for (; auto [a, b, c] = S(); ) {} // expected-error {{not permitted in this context}}
-if (auto [a, b, c] = S()) {} // expected-error {{not permitted in this context}}
-if (int n; auto [a, b, c] = S()) {} // expected-error {{not permitted in this context}}
-switch (auto [a, b, c] = S()) {} // expected-error {{not permitted in this context}}
-switch (int n; auto [a, b, c] = S()) {} // expected-error {{not permitted in this context}}
-while (auto [a, b, c] = S()) {} // expected-error {{not permitted in this context}}
+// A condition is allowed as a Clang extension.
+// See commentary in test/Parser/decomposed-condition.cpp
+for (; auto [a, b, c] = S(); ) {} // 

r320011 - Allow conditions to be decomposed with structured bindings

2017-12-06 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Wed Dec  6 23:03:15 2017
New Revision: 320011

URL: http://llvm.org/viewvc/llvm-project?rev=320011=rev
Log:
Allow conditions to be decomposed with structured bindings

Summary:
This feature was discussed but not yet proposed.  It allows a structured 
binding to appear as a //condition//

if (auto [ok, val] = f(...))

So the user can save an extra //condition// if the statement can test the value 
to-be-decomposed instead.  Formally, it makes the value of the underlying 
object of the structured binding declaration also the value of a //condition// 
that is an initialized declaration.

Considering its logicality which is entirely evident from its trivial 
implementation, I think it might be acceptable to land it as an extension for 
now before I write the paper.

Reviewers: rsmith, faisalv, aaron.ballman

Reviewed By: rsmith

Subscribers: aaron.ballman, cfe-commits

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

Added:
cfe/trunk/test/Parser/decomposed-condition.cpp
cfe/trunk/test/SemaCXX/decomposed-condition.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/Parser/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=320011=320010=320011=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  6 23:03:15 
2017
@@ -414,6 +414,9 @@ def warn_cxx14_compat_decomp_decl : Warn
   "C++ standards before C++17">, DefaultIgnore, InGroup;
 def ext_decomp_decl : ExtWarn<
   "decomposition declarations are a C++17 extension">, InGroup;
+def ext_decomp_decl_cond : ExtWarn<
+  "ISO C++17 does not permit structured binding declaration in a condition">,
+  InGroup>;
 def err_decomp_decl_spec : Error<
   "decomposition declaration cannot be declared "
   "%plural{1:'%1'|:with '%1' specifiers}0">;

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=320011=320010=320011=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed Dec  6 23:03:15 2017
@@ -1995,9 +1995,9 @@ public:
 case BlockContext:
 case ForContext:
 case InitStmtContext:
+case ConditionContext:
   return true;
 
-case ConditionContext:
 case MemberContext:
 case PrototypeContext:
 case TemplateParamContext:

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=320011=320010=320011=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Dec  6 23:03:15 2017
@@ -1715,6 +1715,8 @@ Parser::ParseCXXTypeConstructExpression(
 /// type-specifier-seq declarator '=' assignment-expression
 /// [C++11] type-specifier-seq declarator '=' initializer-clause
 /// [C++11] type-specifier-seq declarator braced-init-list
+/// [Clang] type-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
+/// brace-or-equal-initializer
 /// [GNU]   type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
 /// '=' assignment-expression
 ///

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=320011=320010=320011=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Dec  6 23:03:15 2017
@@ -692,8 +692,9 @@ Sema::ActOnDecompositionDeclarator(Scope
   assert(D.isDecompositionDeclarator());
   const DecompositionDeclarator  = D.getDecompositionDeclarator();
 
-  // The syntax only allows a decomposition declarator as a simple-declaration
-  // or a for-range-declaration, but we parse it in more cases than that.
+  // The syntax only allows a decomposition declarator as a simple-declaration,
+  // a for-range-declaration, or a condition in Clang, but we parse it in more
+  // cases than that.
   if (!D.mayHaveDecompositionDeclarator()) {
 Diag(Decomp.getLSquareLoc(), diag::err_decomp_decl_context)
   << Decomp.getSourceRange();
@@ -708,9 +709,12 @@ Sema::ActOnDecompositionDeclarator(Scope
 return nullptr;
   }
 
-  Diag(Decomp.getLSquareLoc(), getLangOpts().CPlusPlus17
-   ? diag::warn_cxx14_compat_decomp_decl
-   : 

[PATCH] D39279: Stringizing raw string literals containing newline

2017-12-06 Thread Taewook Oh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319904: Stringizing raw string literals containing newline 
(authored by twoh).

Changed prior to commit:
  https://reviews.llvm.org/D39279?vs=125564=125745#toc

Repository:
  rC Clang

https://reviews.llvm.org/D39279

Files:
  include/clang/Lex/Lexer.h
  lib/Lex/Lexer.cpp
  test/Preprocessor/macro_raw_string.cpp
  unittests/Lex/LexerTest.cpp

Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -209,30 +209,39 @@
   return L;
 }
 
-/// Stringify - Convert the specified string into a C string, with surrounding
-/// ""'s, and with escaped \ and " characters.
+template  void StringifyImpl(T , char Quote) {
+  typename T::size_type i = 0, e = Str.size();
+  while (i < e) {
+if (Str[i] == '\\' || Str[i] == Quote) {
+  Str.insert(Str.begin() + i, '\\');
+  i += 2;
+  ++e;
+} else if (Str[i] == '\n' || Str[i] == '\r') {
+  // Replace '\r\n' and '\n\r' to '\\' followed by 'n'.
+  if ((i < e - 1) && (Str[i + 1] == '\n' || Str[i + 1] == '\r') &&
+  Str[i] != Str[i + 1]) {
+Str[i] = '\\';
+Str[i + 1] = 'n';
+  } else {
+// Replace '\n' and '\r' to '\\' followed by 'n'.
+Str[i] = '\\';
+Str.insert(Str.begin() + i + 1, 'n');
+++e;
+  }
+  i += 2;
+} else
+  ++i;
+  }
+}
+
 std::string Lexer::Stringify(StringRef Str, bool Charify) {
   std::string Result = Str;
   char Quote = Charify ? '\'' : '"';
-  for (unsigned i = 0, e = Result.size(); i != e; ++i) {
-if (Result[i] == '\\' || Result[i] == Quote) {
-  Result.insert(Result.begin()+i, '\\');
-  ++i; ++e;
-}
-  }
+  StringifyImpl(Result, Quote);
   return Result;
 }
 
-/// Stringify - Convert the specified string into a C string by escaping '\'
-/// and " characters.  This does not add surrounding ""'s to the string.
-void Lexer::Stringify(SmallVectorImpl ) {
-  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
-if (Str[i] == '\\' || Str[i] == '"') {
-  Str.insert(Str.begin()+i, '\\');
-  ++i; ++e;
-}
-  }
-}
+void Lexer::Stringify(SmallVectorImpl ) { StringifyImpl(Str, '"'); }
 
 //===--===//
 // Token Spelling
@@ -367,7 +376,7 @@
 /// to point to a constant buffer with the data already in it (avoiding a
 /// copy).  The caller is not allowed to modify the returned buffer pointer
 /// if an internal buffer is returned.
-unsigned Lexer::getSpelling(const Token , const char *, 
+unsigned Lexer::getSpelling(const Token , const char *,
 const SourceManager ,
 const LangOptions , bool *Invalid) {
   assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
@@ -592,17 +601,17 @@
   if (TheTok.getKind() == tok::eof) {
 break;
   }
-  
+
   // If we haven't hit the end of the preprocessor directive, skip this
   // token.
   if (!TheTok.isAtStartOfLine())
 continue;
-
+
   // We've passed the end of the preprocessor directive, and will look
   // at this token again below.
   InPreprocessorDirective = false;
 }
-
+
 // Keep track of the # of lines in the preamble.
 if (TheTok.isAtStartOfLine()) {
   unsigned TokOffset = TheTok.getLocation().getRawEncoding() - StartOffset;
@@ -619,13 +628,13 @@
 ActiveCommentLoc = TheTok.getLocation();
   continue;
 }
-
+
 if (TheTok.isAtStartOfLine() && TheTok.getKind() == tok::hash) {
-  // This is the start of a preprocessor directive. 
+  // This is the start of a preprocessor directive.
   Token HashTok = TheTok;
   InPreprocessorDirective = true;
   ActiveCommentLoc = SourceLocation();
-  
+
   // Figure out which directive this is. Since we're lexing raw tokens,
   // we don't have an identifier table available. Instead, just look at
   // the raw identifier to recognize and categorize preprocessor directives.
@@ -665,7 +674,7 @@
   break;
 }
   }
-  
+
   // We only end up here if we didn't recognize the preprocessor
   // directive or it was one that can't occur in the preamble at this
   // point. Roll back the current token to the location of the '#'.
@@ -678,7 +687,7 @@
 // the preamble.
 break;
   } while (true);
-  
+
   SourceLocation End;
   if (ActiveCommentLoc.isValid())
 End = ActiveCommentLoc; // don't truncate a decl comment.
@@ -700,13 +709,13 @@
   // trigraphs.
   bool Invalid = false;
   const char *TokPtr = SM.getCharacterData(TokStart, );
-  
+
   // If they request the first char of the token, we're trivially done.
   if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr)))
 return TokStart;
-  
+
   unsigned PhysOffset = 0;
-  
+
   // The usual case is that 

r319904 - Stringizing raw string literals containing newline

2017-12-06 Thread Taewook Oh via cfe-commits
Author: twoh
Date: Wed Dec  6 09:00:53 2017
New Revision: 319904

URL: http://llvm.org/viewvc/llvm-project?rev=319904=rev
Log:
Stringizing raw string literals containing newline

Summary: This patch implements 4.3 of 
http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4220.pdf. If a raw string 
contains a newline character, replace each newline character with the \n escape 
code. Without this patch, included test case (macro_raw_string.cpp) results 
compilation failure.

Reviewers: rsmith, doug.gregor, jkorous-apple

Reviewed By: jkorous-apple

Subscribers: jkorous-apple, vsapsai, cfe-commits

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

Added:
cfe/trunk/test/Preprocessor/macro_raw_string.cpp
Modified:
cfe/trunk/include/clang/Lex/Lexer.h
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=319904=319903=319904=diff
==
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Dec  6 09:00:53 2017
@@ -70,7 +70,7 @@ class Lexer : public PreprocessorLexer {
   SourceLocation FileLoc;// Location for start of file.
   LangOptions LangOpts;  // LangOpts enabled by this language (cache).
   bool Is_PragmaLexer;   // True if lexer for _Pragma handling.
-  
+
   
//======//
   // Context-specific lexing flags set by the preprocessor.
   //
@@ -241,17 +241,16 @@ public:
 
   /// \brief Return the current location in the buffer.
   const char *getBufferLocation() const { return BufferPtr; }
-  
-  /// Stringify - Convert the specified string into a C string by escaping '\'
-  /// and " characters.  This does not add surrounding ""'s to the string.
+
+  /// Stringify - Convert the specified string into a C string by i) escaping
+  /// '\\' and " characters and ii) replacing newline character(s) with "\\n".
   /// If Charify is true, this escapes the ' character instead of ".
   static std::string Stringify(StringRef Str, bool Charify = false);
 
-  /// Stringify - Convert the specified string into a C string by escaping '\'
-  /// and " characters.  This does not add surrounding ""'s to the string.
+  /// Stringify - Convert the specified string into a C string by i) escaping
+  /// '\\' and " characters and ii) replacing newline character(s) with "\\n".
   static void Stringify(SmallVectorImpl );
 
-  
   /// getSpelling - This method is used to get the spelling of a token into a
   /// preallocated buffer, instead of as an std::string.  The caller is 
required
   /// to allocate enough space for the token, which is guaranteed to be at 
least
@@ -262,11 +261,11 @@ public:
   /// to point to a constant buffer with the data already in it (avoiding a
   /// copy).  The caller is not allowed to modify the returned buffer pointer
   /// if an internal buffer is returned.
-  static unsigned getSpelling(const Token , const char *, 
+  static unsigned getSpelling(const Token , const char *,
   const SourceManager ,
   const LangOptions ,
   bool *Invalid = nullptr);
-  
+
   /// getSpelling() - Return the 'spelling' of the Tok token.  The spelling of 
a
   /// token is the characters used to represent the token in the source file
   /// after trigraph expansion and escaped-newline folding.  In particular, 
this
@@ -274,7 +273,7 @@ public:
   /// UCNs, etc.
   static std::string getSpelling(const Token ,
  const SourceManager ,
- const LangOptions , 
+ const LangOptions ,
  bool *Invalid = nullptr);
 
   /// getSpelling - This method is used to get the spelling of the
@@ -290,7 +289,7 @@ public:
const SourceManager ,
const LangOptions ,
bool *invalid = nullptr);
-  
+
   /// MeasureTokenLength - Relex the token at the specified location and return
   /// its length in bytes in the input file.  If the token needs cleaning (e.g.
   /// includes a trigraph or an escaped newline) then this count includes bytes
@@ -312,7 +311,7 @@ public:
   static SourceLocation GetBeginningOfToken(SourceLocation Loc,
 const SourceManager ,
 const LangOptions );
-  
+
   /// AdvanceToTokenCharacter - If the current SourceLocation specifies a
   /// location at the start of a token, return a new location that specifies a
   /// character within the token.  This handles trigraphs and escaped newlines.
@@ -320,7 +319,7 @@ public:
 unsigned 

[PATCH] D40909: [clang-format] Reorganize raw string delimiters

2017-12-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

Repository:
  rC Clang

https://reviews.llvm.org/D40909

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestRawStrings.cpp

Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -9,6 +9,8 @@
 
 #include "clang/Format/Format.h"
 
+#include 
+
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
@@ -19,6 +21,12 @@
 
 #define DEBUG_TYPE "format-test"
 
+#define DBG(A) \
+  DEBUG({  \
+llvm::dbgs() << __LINE__ << ":" << __func__ << ":" << #A << " = " << A \
+ << "\n";  \
+  });
+
 using clang::tooling::ReplacementTest;
 using clang::tooling::toReplacements;
 
@@ -65,23 +73,40 @@
   FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) {
 FormatStyle Style = getLLVMStyle();
 Style.ColumnLimit = ColumnLimit;
-Style.RawStringFormats = {{/*Delimiter=*/"pb",
-   /*Kind=*/FormatStyle::LK_TextProto,
-   /*BasedOnStyle=*/"google"}};
+Style.AdditionalLanguageStyles[FormatStyle::LK_TextProto] =
+std::make_shared(
+getGoogleStyle(FormatStyle::LK_TextProto));
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_TextProto,
+   /*Delimiters=*/{"pb"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
 return Style;
   }
 
-  FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
+  FormatStyle getRawStringLLVMCppStyleBasedOn(std::string Name) {
 FormatStyle Style = getLLVMStyle();
-Style.RawStringFormats = {{/*Delimiter=*/"cpp",
-   /*Kind=*/FormatStyle::LK_Cpp, BasedOnStyle}};
+FormatStyle BasedOnStyle = getLLVMStyle();
+getPredefinedStyle(Name, FormatStyle::LK_Cpp, );
+Style.AdditionalLanguageStyles[FormatStyle::LK_Cpp] =
+std::make_shared(BasedOnStyle);
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
+   /*Delimiters=*/{"cpp"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
+DBG(BasedOnStyle.PointerAlignment);
 return Style;
   }
 
-  FormatStyle getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle) {
+  FormatStyle getRawStringGoogleCppStyleBasedOn(std::string Name) {
 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
-Style.RawStringFormats = {{/*Delimiter=*/"cpp",
-   /*Kind=*/FormatStyle::LK_Cpp, BasedOnStyle}};
+FormatStyle BasedOnStyle = getLLVMStyle();
+getPredefinedStyle(Name, FormatStyle::LK_Cpp, );
+Style.AdditionalLanguageStyles[FormatStyle::LK_Cpp] =
+std::make_shared(BasedOnStyle);
+Style.RawStringFormats = {{/*Language=*/FormatStyle::LK_Cpp,
+   /*Delimiters=*/{"cpp"},
+   /*EnclosingFunctionNames=*/{},
+   /*CanonicalDelimiter=*/""}};
 return Style;
   }
 
@@ -96,17 +121,19 @@
   // llvm style puts '*' on the right.
   // google style puts '*' on the left.
 
-  // Use the llvm style if the raw string style has no BasedOnStyle.
-  expect_eq(R"test(int *i = R"cpp(int *p = nullptr;)cpp")test",
-format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
-   getRawStringLLVMCppStyleBasedOn("")));
-
-  // Use the google style if the raw string style has BasedOnStyle=google.
+  // Use llvm style outside and the google style inside if the raw string style
+  // is based on google.
   expect_eq(R"test(int *i = R"cpp(int* p = nullptr;)cpp")test",
 format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
getRawStringLLVMCppStyleBasedOn("google")));
 
-  // Use the llvm style if the raw string style has no BasedOnStyle=llvm.
+  // Use llvm style if the raw string style has no BasedOnStyle.
+  expect_eq(R"test(int *i = R"cpp(int *p = nullptr;)cpp")test",
+format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",
+   getRawStringLLVMCppStyleBasedOn("")));
+
+  // Use google style outside and the llvm style inside if the raw string style
+  // is based on llvm.
   expect_eq(R"test(int* i = R"cpp(int *p = nullptr;)cpp")test",
 format(R"test(int * i = R"cpp(int * p = nullptr;)cpp")test",

[PATCH] D40562: [Sema] Ignore decls in namespaces when global decls are not wanted.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D40562#942521, @arphaman wrote:

> In https://reviews.llvm.org/D40562#941753, @ilya-biryukov wrote:
>
> > In https://reviews.llvm.org/D40562#941570, @arphaman wrote:
> >
> > > I'm not actually 100% sure, but I would imagine that this one of the 
> > > reasons, yes. It would be nice to improve the cache to have things like 
> > > namespace-level `Decl`, although how will lookup work in that case? Btw, 
> > > do you think the cache can be reused in clangd as well?
> >
> >
> > As Eric mentioned, we are planning to have project-global completion for 
> > namespace-level Decls (to have completion items not #included in the 
> > current file and add the #include directive properly).  So the cache is 
> > probably not that useful to clangd long-term.
>
>
> Interesting, thanks! Will this be something that clients of clangd can 
> opt-out from? Or at least configure certain aspects of the behaviour?


Absolutely!


Repository:
  rC Clang

https://reviews.llvm.org/D40562



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


[PATCH] D40567: Always show template parameters in IR type names

2017-12-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 125761.
sepavloff added a comment.

Updated patch

- old type names are generated always if --ir-type-names is not specified,
- added new value of --ir-type-names, none, to suppress type names,
- value of --ir-type-names is stored in module properties.


Repository:
  rC Clang

https://reviews.llvm.org/D40567

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCXX/template-types.cpp

Index: test/CodeGenCXX/template-types.cpp
===
--- /dev/null
+++ test/CodeGenCXX/template-types.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=none -o - | FileCheck %s --check-prefix=CHECK-NONE
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=terse -o - | FileCheck %s --check-prefix=CHECK-TERSE
+// RUN: %clang_cc1 %s -S -emit-llvm --ir-type-names=full -o - | FileCheck %s --check-prefix=CHECK-FULL
+
+struct Empty {};
+template struct ABC {
+  T v;
+};
+struct Opaque;
+template class OpaqueClass;
+
+ABC var_1;
+ABC var_2;
+ABC var_3;
+ABC *var_4;
+OpaqueClass *var_5;
+OpaqueClass *var_6;
+OpaqueClass *var_7;
+OpaqueClass *var_8;
+
+
+//-- without option '--ir-type-names'
+
+// CHECK: %struct.ABC = type { i32 }
+// CHECK: %struct.ABC.0 = type { %struct.ABC.1 }
+// CHECK: %struct.ABC.1 = type { i16 }
+// CHECK: %struct.ABC.2 = type { %struct.Empty }
+// CHECK: %struct.Empty = type { i8 }
+// CHECK: %class.OpaqueClass = type opaque
+// CHECK: %class.OpaqueClass.4 = type opaque
+// CHECK: %class.OpaqueClass.5 = type opaque
+// CHECK: %class.OpaqueClass.6 = type opaque
+
+// CHECK: @var_1 = global %struct.ABC zeroinitializer
+// CHECK: @var_2 = global %struct.ABC.0 zeroinitializer
+// CHECK: @var_3 = global %struct.ABC.2 zeroinitializer
+// CHECK: @var_4 = global %struct.ABC.3* null
+// CHECK: @var_5 = global %class.OpaqueClass* null
+// CHECK: @var_6 = global %class.OpaqueClass.4* null
+// CHECK: @var_7 = global %class.OpaqueClass.5* null
+// CHECK: @var_8 = global %class.OpaqueClass.6* null
+
+// CHECK-NOT: !{{[0-9]+}} = !{{{.*}} !"type_names"
+
+
+//-- with option '--ir-type-names=none'
+
+// CHECK-NONE: %0 = type { i32 }
+// CHECK-NONE: %1 = type { %2 }
+// CHECK-NONE: %2 = type { i16 }
+// CHECK-NONE: %3 = type { %4 }
+// CHECK-NONE: %4 = type { i8 }
+// CHECK-NONE: %5 = type opaque
+// CHECK-NONE: %6 = type opaque
+// CHECK-NONE: %7 = type opaque
+// CHECK-NONE: %8 = type opaque
+// CHECK-NONE: %9 = type opaque
+
+// CHECK-NONE: @var_1 = global %0 zeroinitializer
+// CHECK-NONE: @var_2 = global %1 zeroinitializer
+// CHECK-NONE: @var_3 = global %3 zeroinitializer
+// CHECK-NONE: @var_4 = global %5* null
+// CHECK-NONE: @var_5 = global %6* null
+// CHECK-NONE: @var_6 = global %7* null
+// CHECK-NONE: @var_7 = global %8* null
+// CHECK-NONE: @var_8 = global %9* null
+
+// CHECK-NONE: !{{[0-9]+}} = !{{{.*}} !"type_names", i32 1}
+
+
+//-- with option '--ir-type-names=terse'
+
+// CHECK-TERSE: %struct.ABC = type { i32 }
+// CHECK-TERSE: %struct.ABC.0 = type { %struct.ABC.1 }
+// CHECK-TERSE: %struct.ABC.1 = type { i16 }
+// CHECK-TERSE: %struct.ABC.2 = type { %struct.Empty }
+// CHECK-TERSE: %struct.Empty = type { i8 }
+// CHECK-TERSE: %class.OpaqueClass = type opaque
+// CHECK-TERSE: %class.OpaqueClass.4 = type opaque
+// CHECK-TERSE: %class.OpaqueClass.5 = type opaque
+// CHECK-TERSE: %class.OpaqueClass.6 = type opaque
+
+// CHECK-TERSE: @var_1 = global %struct.ABC zeroinitializer
+// CHECK-TERSE: @var_2 = global %struct.ABC.0 zeroinitializer
+// CHECK-TERSE: @var_3 = global %struct.ABC.2 zeroinitializer
+// CHECK-TERSE: @var_4 = global %struct.ABC.3* null
+// CHECK-TERSE: @var_5 = global %class.OpaqueClass* null
+// CHECK-TERSE: @var_6 = global %class.OpaqueClass.4* null
+// CHECK-TERSE: @var_7 = global %class.OpaqueClass.5* null
+// CHECK-TERSE: @var_8 = global %class.OpaqueClass.6* null
+
+// CHECK-TERSE: !{{[0-9]+}} = !{{{.*}} !"type_names", i32 2}
+
+
+//-- with option '--ir-type-names=full'
+
+// CHECK-FULL: %"struct.ABC" = type { i32 }
+// CHECK-FULL: %"struct.ABC" = type { %"struct.ABC" }
+// CHECK-FULL: %"struct.ABC" = type { i16 }
+// CHECK-FULL: %"struct.ABC" = type { %struct.Empty }
+// CHECK-FULL: %struct.Empty = type { i8 }
+// CHECK-FULL: %"struct.ABC" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+// CHECK-FULL: %"class.OpaqueClass" = type opaque
+
+// CHECK-FULL: @var_1 = global %"struct.ABC" zeroinitializer
+// CHECK-FULL: @var_2 = global %"struct.ABC" zeroinitializer
+// CHECK-FULL: @var_3 = global %"struct.ABC" 

Re: [PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread David Blaikie via cfe-commits
Thanks!

On Wed, Dec 6, 2017 at 2:12 AM Sven van Haastregt via Phabricator <
revi...@reviews.llvm.org> wrote:

> This revision was automatically updated to reflect the committed changes.
> Closed by commit rC319883: [OpenCL] Fix layering violation by
> getOpenCLTypeAddrSpace (authored by svenvh).
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D40838
>
> Files:
>   include/clang/AST/ASTContext.h
>   include/clang/Basic/TargetInfo.h
>   lib/AST/ASTContext.cpp
>   lib/Basic/TargetInfo.cpp
>   lib/Basic/Targets/AMDGPU.h
>   lib/CodeGen/CGOpenCLRuntime.cpp
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Herald added a subscriber: cfe-commits.

The adjustment is calculated with CreatePtrDiff() which returns
the difference in (base) elements. This is passed to CreateGEP()
so make sure that the GEP base has the correct pointer type:
It needs to be a pointer to the base type, not a pointer to a
constant sized array.


Repository:
  rC Clang

https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 

[PATCH] D39284: Allow conditions to be decomposed with structured bindings

2017-12-06 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

Can someone commit this please?  One more patch then I'll go get a commit bit.


Repository:
  rC Clang

https://reviews.llvm.org/D39284



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


LLVM buildmaster will be updated and restarted tonight

2017-12-06 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7 PM Pacific time.

Thanks

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


[PATCH] D40897: [clangd] Introduce a "Symbol" class.

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

In https://reviews.llvm.org/D40897#946708, @malaperle wrote:

> Hi! Have you looked into https://reviews.llvm.org/D40548 ? Maybe we need to 
> coordinate the two a bit.


Hi Marc! Thanks for the input!

Yeah, Eric and I are working closely on a prototype of global code completion. 
We have implemented the initial version (see github 
),
 and the prototype works well for LLVM project (even with a simple 
implementation), so we plan to split the patch, improve the code, and 
contribute it back to clangd repo incrementally.

For the prototype, we will load all symbols (without occurrences) into the 
memory, and build an in-memory index. From our experiment, the dataset of LLVM 
project in YAML format is ~120MB (~38,000 symbols), which is acceptable in 
clangd.

Our rough plan would be

1. Define the Symbol structure.
2. Design the interfaces of SymbolIndex, ASTIndex.
3. Combine 1) and 2) together to make global code completion work (we'd use 
YAML dataset for LLVM project, note that this is not a final solution, it would 
be hidden in an `--experimental` flag).
4. Switch to use the dataset from index-while-building when it is ready.




Comment at: clangd/Symbol.h:37
+// The class presents a C++ symbol, e.g. class, function.
+struct Symbol {
+  // The symbol identifier, using USR.

malaperle wrote:
> I think it would be nice to have methods as an interface to get this data 
> instead of storing them directly. So that an index-on-disk could go fetch the 
> data. Especially the occurrences which can take a lot of memory (I'm working 
> on a branch that does that). But perhaps defining that interface is not 
> within the scope of this patch and could be better discussed in D40548 ?
I agree. We can't load all the symbol occurrences into the memory since they 
are too large. We need to design interface for the symbol occurrences. 

We could discuss the interface here, but CodeCompletion is the main thing which 
this patch focuses on. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

Better to use `SharedAddresses[N].first.getAddress().getType()`


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 125768.
Hahnfeld marked 3 inline comments as done.
Hahnfeld added a comment.

Get type from `Address`.


https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1029,9 +1029,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint 

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 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


https://reviews.llvm.org/D40911



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319931: Fix PR35542: Correct adjusting of private reduction 
variable (authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D40911?vs=125768=125770#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40911

Files:
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
  cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Index: cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
+++ cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
===
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = 

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319931: Fix PR35542: Correct adjusting of private reduction 
variable (authored by Hahnfeld).

Repository:
  rC Clang

https://reviews.llvm.org/D40911

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/for_reduction_codegen.cpp
  test/OpenMP/for_reduction_codegen_UDR.cpp

Index: test/OpenMP/for_reduction_codegen_UDR.cpp
===
--- test/OpenMP/for_reduction_codegen_UDR.cpp
+++ test/OpenMP/for_reduction_codegen_UDR.cpp
@@ -735,7 +735,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VVAR2_PRIV:%.+]] = getelementptr [5 x [[S_FLOAT_TY]]], [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VVAR2_PRIV_PTR:%.+]] = bitcast [5 x [[S_FLOAT_TY]]]* [[VVAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VVAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VVAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: ret void
 
 // CHECK: define internal void [[MAIN_MICROTASK5]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [4 x [[S_FLOAT_TY]]]* dereferenceable(48) %{{.+}})
@@ -761,8 +762,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_FLOAT_TY]]* getelementptr ([[S_FLOAT_TY]], [[S_FLOAT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [2 x [[S_FLOAT_TY]]], [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], i64 [[OFFSET]]
-// CHECK: [[VAR3_PRIV:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
+// CHECK: [[VAR3_PRIV_PTR:%.+]] = bitcast [2 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[PSEUDO_VAR3_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR3_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[VAR3_PRIV:%.+]] = bitcast [[S_FLOAT_TY]]* [[PSEUDO_VAR3_PRIV]] to [4 x [[S_FLOAT_TY]]]*
 
 // CHECK: store [4 x [[S_FLOAT_TY]]]* [[VAR3_PRIV]], [4 x [[S_FLOAT_TY]]]** %
 
@@ -985,8 +987,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_INT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint ([[S_INT_TY]]* getelementptr ([[S_INT_TY]], [[S_INT_TY]]* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [40 x [[S_INT_TY]]], [40 x [[S_INT_TY]]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [40 x [[S_INT_TY]]]* [[ARR_PRIV]] to [[S_INT_TY]]*
+// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [[S_INT_TY]], [[S_INT_TY]]* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
+// CHECK: [[ARR_PRIV:%.+]] = bitcast [[S_INT_TY]]* [[PSEUDO_ARR_PRIV]] to [42 x [[S_INT_TY]]]*
 
 // CHECK: ret void
 
Index: test/OpenMP/for_reduction_codegen.cpp
===
--- test/OpenMP/for_reduction_codegen.cpp
+++ test/OpenMP/for_reduction_codegen.cpp
@@ -944,8 +944,8 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 [[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* [[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* [[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ 

r319931 - Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Wed Dec  6 11:15:28 2017
New Revision: 319931

URL: http://llvm.org/viewvc/llvm-project?rev=319931=rev
Log:
Fix PR35542: Correct adjusting of private reduction variable

The adjustment is calculated with CreatePtrDiff() which returns
the difference in (base) elements. This is passed to CreateGEP()
so make sure that the GEP base has the correct pointer type:
It needs to be a pointer to the base type, not a pointer to a
constant sized array.

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

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=319931=319930=319931=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Dec  6 11:15:28 2017
@@ -1104,11 +1104,14 @@ Address ReductionCodeGen::adjustPrivateA
 OriginalBaseLValue);
 llvm::Value *Adjustment = CGF.Builder.CreatePtrDiff(
 BaseLValue.getPointer(), SharedAddresses[N].first.getPointer());
-llvm::Value *Ptr =
-CGF.Builder.CreateGEP(PrivateAddr.getPointer(), Adjustment);
+llvm::Value *PrivatePointer =
+CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getAddress().getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);
 return castToBase(CGF, OrigVD->getType(),
   SharedAddresses[N].first.getType(),
-  OriginalBaseLValue.getPointer()->getType(),
+  OriginalBaseLValue.getAddress().getType(),
   OriginalBaseLValue.getAlignment(), Ptr);
   }
   BaseDecls.emplace_back(

Modified: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_reduction_codegen.cpp?rev=319931=319930=319931=diff
==
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp Wed Dec  6 11:15:28 2017
@@ -944,8 +944,8 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint i32* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (i32* 
getelementptr (i32, i32* null, i32 1) to i64)
-// CHECK: [[PSEUDO_ARR_PRIV:%.+]] = getelementptr [1 x [2 x i32]], [1 x [2 x 
i32]]* [[ARR_PRIV]], i64 [[OFFSET]]
-// CHECK: [[ARR_PRIV:%.+]] = bitcast [1 x [2 x i32]]* [[PSEUDO_ARR_PRIV]] to 
i32*
+// CHECK: [[ARR_PRIV_PTR:%.+]] = bitcast [1 x [2 x i32]]* [[ARR_PRIV]] to i32*
+// CHECK: [[ARR_PRIV:%.+]] = getelementptr i32, i32* [[ARR_PRIV_PTR]], i64 
[[OFFSET]]
 
 // CHECK: ret void
 
@@ -1000,9 +1000,9 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* 
getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, 
[1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* 
[[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1029,9 +1029,9 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = ptrtoint [[S_FLOAT_TY]]* [[LOW]] to i64
 // CHECK: [[OFFSET_BYTES:%.+]] = sub i64 [[START]], [[LOW_BOUND]]
 // CHECK: [[OFFSET:%.+]] = sdiv exact i64 [[OFFSET_BYTES]], ptrtoint (float* 
getelementptr (float, float* null, i32 1) to i64)
-// CHECK: [[PSEUDO_VAR2_PRIV:%.+]] = getelementptr [1 x [6 x [[S_FLOAT_TY, 
[1 x [6 x [[S_FLOAT_TY* [[VAR2_PRIV]], i64 [[OFFSET]]
+// CHECK: [[VAR2_PRIV_PTR:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[VAR2_PRIV]] to [[S_FLOAT_TY]]*
+// CHECK: [[VAR2_PRIV:%.+]] = getelementptr [[S_FLOAT_TY]], [[S_FLOAT_TY]]* 
[[VAR2_PRIV_PTR]], i64 [[OFFSET]]
 // CHECK: store [[S_FLOAT_TY]]** [[REF:.+]], [[S_FLOAT_TY]]*** %
-// CHECK: [[VAR2_PRIV:%.+]] = bitcast [1 x [6 x [[S_FLOAT_TY* 
[[PSEUDO_VAR2_PRIV]] to [[S_FLOAT_TY]]*
 // CHECK: store [[S_FLOAT_TY]]* [[VAR2_PRIV]], [[S_FLOAT_TY]]** [[REF]]
 // CHECK: ret void
 
@@ -1080,7 +1080,8 @@ int main() {
 // CHECK: [[LOW_BOUND:%.+]] = 

[PATCH] D40562: [Sema] Ignore decls in namespaces when global decls are not wanted.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 125777.
ioeric added a comment.

- Add a new code-completion option IncludeNamespaceLevelDecls. For now, I only 
restrict this option work for qualified id completion to reduce the impact.


Repository:
  rC Clang

https://reviews.llvm.org/D40562

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/CodeCompleteOptions.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/ignore-ns-level-decls.cpp

Index: test/CodeCompletion/ignore-ns-level-decls.cpp
===
--- /dev/null
+++ test/CodeCompletion/ignore-ns-level-decls.cpp
@@ -0,0 +1,21 @@
+namespace ns {
+  struct bar {
+  };
+
+  struct baz {
+  };
+
+  int func(int a, bar b, baz c);
+}
+
+void test() {
+  ns::
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 %s -o - | FileCheck %s --check-prefix=CHECK-1
+// CHECK-1-DAG: COMPLETION: bar : bar
+// CHECK-1-DAG: COMPLETION: baz : baz
+// CHECK-1-DAG: COMPLETION: func : [#int#]func(<#int a#>, <#bar b#>, <#baz c#>)
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:7 -no-code-completion-ns-level-decls %s -o - | FileCheck %s --check-prefix=CHECK-EMPTY
+// CHECK-EMPTY-NOT: COMPLETION: bar : bar
+// CHECK-EMPTY: {{^}}{{$}}
+}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4635,16 +4635,18 @@
   // qualified-id completions.
   if (!EnteringContext)
 MaybeAddOverrideCalls(*this, Ctx, Results);
-  Results.ExitScope();  
-  
-  CodeCompletionDeclConsumer Consumer(Results, CurContext);
-  LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
- /*IncludeGlobalScope=*/true,
- /*IncludeDependentBases=*/true);
+  Results.ExitScope();
 
-  HandleCodeCompleteResults(this, CodeCompleter, 
-Results.getCompletionContext(),
-Results.data(),Results.size());
+  if (CodeCompleter->includeNamespaceLevelDecls() ||
+  (!Ctx->isNamespace() && !Ctx->isTranslationUnit())) {
+CodeCompletionDeclConsumer Consumer(Results, CurContext);
+LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
+   /*IncludeGlobalScope=*/true,
+   /*IncludeDependentBases=*/true);
+  }
+
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
 }
 
 void Sema::CodeCompleteUsing(Scope *S) {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1378,6 +1378,8 @@
 = Args.hasArg(OPT_code_completion_patterns);
   Opts.CodeCompleteOpts.IncludeGlobals
 = !Args.hasArg(OPT_no_code_completion_globals);
+  Opts.CodeCompleteOpts.IncludeNamespaceLevelDecls
+= !Args.hasArg(OPT_no_code_completion_ns_level_decls);
   Opts.CodeCompleteOpts.IncludeBriefComments
 = Args.hasArg(OPT_code_completion_brief_comments);
 
Index: include/clang/Sema/CodeCompleteOptions.h
===
--- include/clang/Sema/CodeCompleteOptions.h
+++ include/clang/Sema/CodeCompleteOptions.h
@@ -24,15 +24,20 @@
   /// Show top-level decls in code completion results.
   unsigned IncludeGlobals : 1;
 
+  /// Show decls in namespace (including the global namespace) in code
+  /// completion results. If this is 0, `IncludeGlobals` will be ignored.
+  ///
+  /// Currently, this only works when completing qualified IDs (i.e.
+  /// `Sema::CodeCompleteQualifiedId`).
+  /// FIXME: consider supporting more completion cases with this option.
+  unsigned IncludeNamespaceLevelDecls : 1;
+
   /// Show brief documentation comments in code completion results.
   unsigned IncludeBriefComments : 1;
 
-  CodeCompleteOptions() :
-  IncludeMacros(0),
-  IncludeCodePatterns(0),
-  IncludeGlobals(1),
-  IncludeBriefComments(0)
-  { }
+  CodeCompleteOptions()
+  : IncludeMacros(0), IncludeCodePatterns(0), IncludeGlobals(1),
+IncludeNamespaceLevelDecls(1), IncludeBriefComments(0) {}
 };
 
 } // namespace clang
Index: include/clang/Sema/CodeCompleteConsumer.h
===
--- include/clang/Sema/CodeCompleteConsumer.h
+++ include/clang/Sema/CodeCompleteConsumer.h
@@ -902,8 +902,13 @@
   }
 
   /// \brief Whether to include global (top-level) declaration results.
-  bool includeGlobals() const {
-return CodeCompleteOpts.IncludeGlobals;
+  bool includeGlobals() const { return CodeCompleteOpts.IncludeGlobals; }
+
+  /// \brief Whether to include declarations in namespace contexts (including
+  /// the global namespace). If this is false, `includeGlobals()` will be
+  /// 

Re: r319875 - Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.

2017-12-06 Thread Hans Wennborg via cfe-commits
This made Clang start warning about unsigned vs enum compares on Windows.

$ echo 'enum E { foo }; bool f(unsigned a, E b) { return a == b; }' |
bin/clang -Wsign-compare -c -x c++ - -target i686-pc-win32
:1:52: warning: comparison of integers of different signs:
'unsigned int' and 'E' [-Wsign-compare]
enum E { foo }; bool f(unsigned a, E b) { return a == b; }
 ~ ^  ~

That's probably intentional and I think we can fix the ones that came
up, just wanted to let you know.


On Tue, Dec 5, 2017 at 7:00 PM, Richard Smith via cfe-commits
 wrote:
>
> Author: rsmith
> Date: Tue Dec  5 19:00:51 2017
> New Revision: 319875
>
> URL: http://llvm.org/viewvc/llvm-project?rev=319875=rev
> Log:
> Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.
>
> An enumeration with a fixed underlying type can have any value in its
> underlying type, not just those spanned by the values of its enumerators.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=319875=319874=319875=diff
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec  5 19:00:51 2017
> @@ -8260,11 +8260,12 @@ struct IntRange {
>  } else if (const EnumType *ET = dyn_cast(T)) {
>// For enum types in C++, use the known bit width of the enumerators.
>EnumDecl *Enum = ET->getDecl();
> -  // In C++11, enums without definitions can have an explicitly specified
> -  // underlying type.  Use this type to compute the range.
> -  if (!Enum->isCompleteDefinition())
> +  // In C++11, enums can have a fixed underlying type. Use this type to
> +  // compute the range.
> +  if (Enum->isFixed()) {
>  return IntRange(C.getIntWidth(QualType(T, 0)),
>  !ET->isSignedIntegerOrEnumerationType());
> +  }
>
>unsigned NumPositive = Enum->getNumPositiveBits();
>unsigned NumNegative = Enum->getNumNegativeBits();
>
> Modified: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp?rev=319875=319874=319875=diff
> ==
> --- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp (original)
> +++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp Tue Dec  
> 5 19:00:51 2017
> @@ -2,11 +2,11 @@
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED 
> -verify %s
>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only 
> -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
>
> -// Okay, this is where it gets complicated.
> -// Then default enum sigdness is target-specific.
> -// On windows, it is signed by default. We do not want to warn in that case.
> -
>  int main() {
> +  // On Windows, all enumerations have a fixed underlying type, which is 
> 'int'
> +  // if not otherwise specified, so A is identical to C on Windows. 
> Otherwise,
> +  // we follow the C++ rules, which say that the only valid values of A are 0
> +  // and 1.
>enum A { A_foo = 0, A_bar, };
>enum A a;
>
> @@ -87,21 +87,23 @@ int main() {
>
>if (c < 0)
>  return 0;
> -  if (0 >= c) // expected-warning {{comparison 0 >= 'enum C' is always true}}
> +  if (0 >= c)
>  return 0;
> -  if (c > 0) // expected-warning {{comparison 'enum C' > 0 is always false}}
> +  if (c > 0)
>  return 0;
>if (0 <= c)
>  return 0;
> -  if (c <= 0) // expected-warning {{comparison 'enum C' <= 0 is always true}}
> +  if (c <= 0)
>  return 0;
>if (0 > c)
>  return 0;
>if (c >= 0)
>  return 0;
> -  if (0 < c) // expected-warning {{0 < 'enum C' is always false}}
> +  if (0 < c)
>  return 0;
>
> +  // FIXME: These diagnostics are terrible. The issue here is that the signed
> +  // enumeration value was promoted to an unsigned type.
>if (c < 0U) // expected-warning {{comparison of unsigned enum expression < 
> 0 is always false}}
>  return 0;
>if (0U >= c)
> @@ -121,21 +123,23 @@ int main() {
>  #elif defined(SIGNED)
>if (a < 0)
>  return 0;
> -  if (0 >= a) // expected-warning {{comparison 0 >= 'enum A' is always true}}
> +  if (0 >= a)
>  return 0;
> -  if (a > 0) // expected-warning {{comparison 'enum A' > 0 is always false}}
> +  if (a > 0)
>  return 0;
>if (0 <= a)
>  return 0;
> -  if (a <= 0) // expected-warning {{comparison 'enum A' <= 0 is always true}}
> +  if (a <= 0)
>  return 0;
>if (0 > a)
>  return 0;
>if (a >= 0)
>  return 0;
> -  if (0 < a) 

[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

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



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

ABataev wrote:
> Better to use `SharedAddresses[N].first.getAddress().getType()`
Ok, was copied from below call to `castToBase()`. Should I adjust it there as 
well?


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


[PATCH] D40911: [OpenMP] Fix PR35542: Correct adjusting of private reduction variable

2017-12-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1110
+PrivateAddr.getPointer(),
+SharedAddresses[N].first.getPointer()->getType());
+llvm::Value *Ptr = CGF.Builder.CreateGEP(PrivatePointer, Adjustment);

Hahnfeld wrote:
> ABataev wrote:
> > Better to use `SharedAddresses[N].first.getAddress().getType()`
> Ok, was copied from below call to `castToBase()`. Should I adjust it there as 
> well?
Yes, please


Repository:
  rC Clang

https://reviews.llvm.org/D40911



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


r319942 - Delete special-case "out-of-range" handling for bools, and just use the normal

2017-12-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Dec  6 11:23:19 2017
New Revision: 319942

URL: http://llvm.org/viewvc/llvm-project?rev=319942=rev
Log:
Delete special-case "out-of-range" handling for bools, and just use the normal
codepath plus the new "minimum / maximum value of type" diagnostic to get the
same effect.

Move the warning for an in-range but tautological comparison of a constant (0
or 1) against a bool out of -Wtautological-constant-out-of-range-compare into
the more-appropriate -Wtautological-constant-compare.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=319942=319941=319942=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  6 11:23:19 
2017
@@ -5952,6 +5952,8 @@ def warn_out_of_range_compare : Warning<
   "comparison of %select{constant %0|true|false}1 with " 
   "%select{expression of type %2|boolean expression}3 is always "
   "%select{false|true}4">, InGroup;
+def warn_tautological_bool_compare : Warning,
+  InGroup;
 def warn_comparison_of_mixed_enum_types : Warning<
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=319942=319941=319942=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Dec  6 11:23:19 2017
@@ -8650,15 +8650,8 @@ static bool IsEnumConstOrFromMacro(Sema
   return false;
 }
 
-static bool isNonBooleanIntegerValue(Expr *E) {
-  return !E->isKnownToHaveBooleanValue() && E->getType()->isIntegerType();
-}
-
-static bool isNonBooleanUnsignedValue(Expr *E) {
-  // We are checking that the expression is not known to have boolean value,
-  // is an integer type; and is either unsigned after implicit casts,
-  // or was unsigned before implicit casts.
-  return isNonBooleanIntegerValue(E) &&
+static bool isKnownToHaveUnsignedValue(Expr *E) {
+  return E->getType()->isIntegerType() &&
  (!E->getType()->isSignedIntegerType() ||
   !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
 }
@@ -8684,7 +8677,7 @@ static llvm::Optional IsTypeL
   if (IsEnumConstOrFromMacro(S, Constant))
 return llvm::Optional();
 
-  if (isNonBooleanUnsignedValue(Other) && Value == 0)
+  if (isKnownToHaveUnsignedValue(Other) && Value == 0)
 return LimitType::Min;
 
   // TODO: Investigate using GetExprRange() to get tighter bounds
@@ -8694,20 +8687,20 @@ static llvm::Optional IsTypeL
 OtherT = AT->getValueType();
 
   IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  if (Other->isKnownToHaveBooleanValue())
+OtherRange = IntRange::forBoolType();
 
   // Special-case for C++ for enum with one enumerator with value of 0.
   if (OtherRange.Width == 0)
 return Value == 0 ? LimitType::Both : llvm::Optional();
 
   if (llvm::APSInt::isSameValue(
-  llvm::APSInt::getMaxValue(OtherRange.Width,
-OtherT->isUnsignedIntegerType()),
+  llvm::APSInt::getMaxValue(OtherRange.Width, OtherRange.NonNegative),
   Value))
 return LimitType::Max;
 
   if (llvm::APSInt::isSameValue(
-  llvm::APSInt::getMinValue(OtherRange.Width,
-OtherT->isUnsignedIntegerType()),
+  llvm::APSInt::getMinValue(OtherRange.Width, OtherRange.NonNegative),
   Value))
 return LimitType::Min;
 
@@ -8726,6 +8719,20 @@ static bool HasEnumType(Expr *E) {
   return E->getType()->isEnumeralType();
 }
 
+static int classifyConstantValue(Expr *Constant) {
+  // The values of this enumeration are used in the diagnostics
+  // diag::warn_out_of_range_compare and diag::warn_tautological_bool_compare.
+  enum ConstantValueKind {
+Miscellaneous = 0,
+LiteralTrue,
+LiteralFalse
+  };
+  if (auto *BL = dyn_cast(Constant))
+return BL->getValue() ? ConstantValueKind::LiteralTrue
+  : ConstantValueKind::LiteralFalse;
+  return ConstantValueKind::Miscellaneous;
+}
+
 static bool CheckTautologicalComparison(Sema , BinaryOperator *E,
 Expr *Constant, Expr *Other,
 const llvm::APSInt ,
@@ -8738,11 +8745,12 @@ static bool CheckTautologicalComparison(
   BinaryOperatorKind Op = E->getOpcode();
 
   QualType OType = Other->IgnoreParenImpCasts()->getType();
+  if (!OType->isIntegerType())
+return false;
 
-  llvm::Optional ValueType; // Which limit (min/max) is the 
constant?
-
-  if 

[PATCH] D40864: [Darwin] Add a new -mstack-probe option and enable by default

2017-12-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/BackendUtil.cpp:442
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
+  Options.EnableStackProbe = CodeGenOpts.StackProbe;
 

aemerson wrote:
> ahatanak wrote:
> > Is there a reason you can't use function attributes 
> > "probe-stack"="___chkstk_darwin" and "stack-probe-size"=4096 instead of 
> > setting a TargetOptions flag here? If you intend to use stack probing with 
> > LTO, I think you need function attributes. Also, it looks like that would 
> > simplify the changes made to X86 backend.
> I don't think there's any reason not to. Is it worth specifying the probe 
> size itself given that it'll be a known fixed value? It could be misleading 
> to give a probe size which only has a single valid value for Darwin.
If 4096B is the only valid size for Darwin and the default size is 4096B in the 
backend, you can just add attribute "probe-stack"="___chkstk_darwin" to the 
function.  The backend can check the existence of the attribute and decide 
whether to enable stack-probing.


Repository:
  rC Clang

https://reviews.llvm.org/D40864



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


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

This enables us to use information in Preprocessor when handling symbol
occurrences.


Repository:
  rC Clang

https://reviews.llvm.org/D40884

Files:
  include/clang/Index/IndexDataConsumer.h
  include/clang/Index/IndexingAction.h
  lib/Index/IndexingAction.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -342,7 +342,7 @@
   CXTranslationUnit getCXTU() const { return CXTU; }
 
   void setASTContext(ASTContext );
-  void setPreprocessor(std::shared_ptr PP);
+  void setPreprocessor(std::shared_ptr PP) override;
 
   bool shouldSuppressRefs() const {
 return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -8,10 +8,11 @@
 //===--===//
 
 #include "clang/Index/IndexingAction.h"
-#include "clang/Index/IndexDataConsumer.h"
 #include "IndexingContext.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/MultiplexConsumer.h"
+#include "clang/Index/IndexDataConsumer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 
@@ -42,16 +43,18 @@
 namespace {
 
 class IndexASTConsumer : public ASTConsumer {
+  std::shared_ptr PP;
   IndexingContext 
 
 public:
-  IndexASTConsumer(IndexingContext )
-: IndexCtx(IndexCtx) {}
+  IndexASTConsumer(std::shared_ptr PP, IndexingContext )
+  : PP(std::move(PP)), IndexCtx(IndexCtx) {}
 
 protected:
   void Initialize(ASTContext ) override {
 IndexCtx.setASTContext(Context);
 IndexCtx.getDataConsumer().initialize(Context);
+IndexCtx.getDataConsumer().setPreprocessor(PP);
   }
 
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
@@ -80,8 +83,10 @@
 : DataConsumer(std::move(dataConsumer)),
   IndexCtx(Opts, *DataConsumer) {}
 
-  std::unique_ptr createIndexASTConsumer() {
-return llvm::make_unique(IndexCtx);
+  std::unique_ptr
+  createIndexASTConsumer(CompilerInstance ) {
+return llvm::make_unique(CI.getPreprocessorPtr(),
+   IndexCtx);
   }
 
   void finish() {
@@ -98,7 +103,7 @@
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override {
-return createIndexASTConsumer();
+return createIndexASTConsumer(CI);
   }
 
   void EndSourceFileAction() override {
@@ -142,7 +147,7 @@
 
   std::vector Consumers;
   Consumers.push_back(std::move(OtherConsumer));
-  Consumers.push_back(createIndexASTConsumer());
+  Consumers.push_back(createIndexASTConsumer(CI));
   return llvm::make_unique(std::move(Consumers));
 }
 
@@ -173,6 +178,7 @@
   IndexingContext IndexCtx(Opts, *DataConsumer);
   IndexCtx.setASTContext(Unit.getASTContext());
   DataConsumer->initialize(Unit.getASTContext());
+  DataConsumer->setPreprocessor(Unit.getPreprocessorPtr());
   indexTranslationUnit(Unit, IndexCtx);
   DataConsumer->finish();
 }
@@ -198,7 +204,7 @@
   IndexCtx.setASTContext(Ctx);
   DataConsumer->initialize(Ctx);
 
-  for (const Decl *D :Reader.getModuleFileLevelDecls(Mod)) {
+  for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) {
 IndexCtx.indexTopLevelDecl(D);
   }
   DataConsumer->finish();
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include 
 
Index: include/clang/Index/IndexDataConsumer.h
===
--- include/clang/Index/IndexDataConsumer.h
+++ include/clang/Index/IndexDataConsumer.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_INDEX_INDEXDATACONSUMER_H
 
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Lex/Preprocessor.h"
 
 namespace clang {
   class ASTContext;
@@ -36,6 +37,8 @@
 
   virtual void initialize(ASTContext ) {}
 
+  virtual void setPreprocessor(std::shared_ptr PP) {}
+
   /// \returns true to continue indexing, or false to abort.
   virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
ArrayRef Relations,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40643: [libclang] Add function to get the buffer for a file

2017-12-06 Thread Erik Verbruggen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319881: [libclang] Add function to get the buffer for a file 
(authored by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D40643?vs=124904=125677#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40643

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CIndex.cpp


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4162,6 +4162,27 @@
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -4162,6 +4162,27 @@
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319881 - [libclang] Add function to get the buffer for a file

2017-12-06 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Dec  6 01:02:52 2017
New Revision: 319881

URL: http://llvm.org/viewvc/llvm-project?rev=319881=rev
Log:
[libclang] Add function to get the buffer for a file

This can be used by clients in conjunction with an offset returned by
e.g. clang_getFileLocation. Now those clients do not need to also
open/read the file.

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

Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=319881=319880=319881=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Dec  6 01:02:52 2017
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 43
+#define CINDEX_VERSION_MINOR 44
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -404,6 +404,21 @@ CINDEX_LINKAGE CXFile clang_getFile(CXTr
 const char *file_name);
 
 /**
+ * \brief Retrieve the buffer associated with the given file.
+ *
+ * \param tu the translation unit
+ *
+ * \param file the file for which to retrieve the buffer.
+ *
+ * \param size [out] if non-NULL, will be set to the size of the buffer.
+ *
+ * \returns a pointer to the buffer in memory that holds the contents of
+ * \p file, or a NULL pointer when the file is not loaded.
+ */
+CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
+ CXFile file, size_t *size);
+
+/**
  * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  * or they are both NULL.
  */

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=319881=319880=319881=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Dec  6 01:02:52 2017
@@ -4162,6 +4162,27 @@ CXFile clang_getFile(CXTranslationUnit T
   return const_cast(FMgr.getFile(file_name));
 }
 
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+  size_t *size) {
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return nullptr;
+  }
+
+  const SourceManager  = cxtu::getASTUnit(TU)->getSourceManager();
+  FileID fid = SM.translateFile(static_cast(file));
+  bool Invalid = true;
+  llvm::MemoryBuffer *buf = SM.getBuffer(fid, );
+  if (Invalid) {
+if (size)
+  *size = 0;
+return nullptr;
+  }
+  if (size)
+*size = buf->getBufferSize();
+  return buf->getBufferStart();
+}
+
 unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
 CXFile file) {
   if (isNotUsableTU(TU)) {


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


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: include/clang/Index/IndexingAction.h:14
 #include "clang/Basic/LLVM.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"

Is this header being used in this file?


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D40884#946630, @ioeric wrote:

> In https://reviews.llvm.org/D40884#946506, @malaperle wrote:
>
> > You can get the preprocessor from the ASTContext, no?
>
>
> I don't think `ASTContext` contains preprocessor information.


My bad, it was the SourceManager I had in mind. Ignore me!


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D40903: [Sanitizers] Basic Solaris sanitizer support (PR 33274)

2017-12-06 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a project: Sanitizers.
Herald added subscribers: fedor.sergeev, jyknight.

This patch (on top of https://reviews.llvm.org/D35755) provides the clang side 
necessary
to enable the Solaris port of the sanitizers implemented by 
https://reviews.llvm.org/D40898,
https://reviews.llvm.org/D40899, and https://reviews.llvm.org/D40900).

A few features of note:

- While compiler-rt cmake/base-config-ix.cmake (COMPILER_RT_OS_DIR) places the 
runtime libs in a tolower(CMAKE_SYSTEM_NAME) directory, clang defaults to the 
OS part of the target triplet (solaris2.11 in the case at hand).  The patch 
makes them agree on compiler-rt's idea.

- While Solaris ld accepts a considerable number of GNU ld options for 
compatibility, it only does so for the double-dash forms.  clang unfortunately 
is inconsistent here and sometimes uses the double-dash form, sometimes the 
single-dash one that confuses the hell out of Solaris ld.  I've changed the 
affected places to use the double-dash form that should always work.

- As described in https://reviews.llvm.org/D40899, Solaris ld doesn't create 
the __start___sancov_guards/__stop___sancov_guards labels gld/gold/lld do, so 
I'm including additional runtime libs into the link that provide them.

- One test uses -fstack-protector, but unlike other systems libssp hasn't been 
folded into Solaris libc, but needs to be linked with separately.

- For now, only 32-bit x86 asan is enabled on Solaris.  64-bit x86 should 
follow, but sparc (which requires additional compiler-rt changes not yet 
submitted) fails miserably due to a llvmsparc backend limitation:

fatal error: error in backend: Function 
"_ZN7testing8internal16BoolFromGTestEnvEPKcb": over-aligned dynamic alloca not 
supported.

  However, inside the gcc tree, Solaris/sparc asan works almost as well as x86.


Repository:
  rC Clang

https://reviews.llvm.org/D40903

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Solaris.cpp
  lib/Driver/ToolChains/Solaris.h

Index: lib/Driver/ToolChains/Solaris.h
===
--- lib/Driver/ToolChains/Solaris.h
+++ lib/Driver/ToolChains/Solaris.h
@@ -65,6 +65,7 @@
   addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
+  SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
 protected:
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -92,24 +92,48 @@
 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
+  // Provide __start___sancov_guards.  Solaris ld doesn't automatically create
+  // __start_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_begin", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_e, options::OPT_r});
 
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (getToolChain().ShouldLinkCXXStdlib(Args))
   getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+if (Args.hasArg(options::OPT_fstack_protector) ||
+Args.hasArg(options::OPT_fstack_protector_strong) ||
+Args.hasArg(options::OPT_fstack_protector_all)) {
+  // Explicitly link ssp libraries, not folded into Solaris libc.
+  CmdArgs.push_back("-lssp_nonshared");
+  CmdArgs.push_back("-lssp");
+}
 CmdArgs.push_back("-lgcc_s");
 CmdArgs.push_back("-lc");
 if (!Args.hasArg(options::OPT_shared)) {
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+if (NeedsSanitizerDeps)
+  linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
   }
 
+  // Provide __stop___sancov_guards.  Solaris ld doesn't automatically create
+  // __stop_SECNAME labels.
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back(
+  getToolChain().getCompilerRTArgString(Args, "sancov_end", false));
+  CmdArgs.push_back("--no-whole-archive");
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 CmdArgs.push_back(
 Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
@@ -165,6 +189,17 @@
   addPathIfExists(D, D.SysRoot + "/usr/lib" + LibSuffix, Paths);
 }
 
+SanitizerMask Solaris::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  

[PATCH] D40813: [clang-tidy] Adding Fuchsia checker for virtual inheritance

2017-12-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/fuchsia-virtual-inheritance.cpp:30
+class D : public B, public C {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: virtual inheritance is disallowed 
[fuchsia-virtual-inheritance]
+  // CHECK-NEXT: class C : public B, public C {

I don't think that this should be diagnosed -- it will be confusing to the user 
to see this claimed as virtual inheritance when there's no virtual inheritance 
at this level.



Comment at: test/clang-tidy/fuchsia-virtual-inheritance.cpp:34-36
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]
+  // CHECK-NEXT:  D(int value) : A(value), B(), C() {}
+  // CHECK-MESSAGES: [[@LINE-3]]:33: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]

I'm also not certain this should be diagnosed either. It's technically correct 
because it's calling the base class constructors here, but at the same time, it 
seems very low-value and likely to cause the user to do something really bad, 
like silence the warning by not calling the base class constructors.


https://reviews.llvm.org/D40813



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


[PATCH] D40871: [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319908: [CUDA] Added overloads for '[unsigned] long' 
variants of shfl builtins. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40871?vs=125648=125756#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40871

Files:
  lib/Headers/__clang_cuda_intrinsics.h


Index: lib/Headers/__clang_cuda_intrinsics.h
===
--- lib/Headers/__clang_cuda_intrinsics.h
+++ lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


Index: lib/Headers/__clang_cuda_intrinsics.h
===
--- lib/Headers/__clang_cuda_intrinsics.h
+++ lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( \
 __mask, static_cast(__val), __offset, __width));   \
   }\
+  inline __device__ long __FnName(unsigned int __mask, long __val, \
+  int __offset, int __width = warpSize) {  \
+_Static_assert(sizeof(long) == sizeof(long long) ||\
+   sizeof(long) == sizeof(int));   \
+if (sizeof(long) == sizeof(long long)) {   \
+  return static_cast(::__FnName( \
+  __mask, static_cast(__val), __offset, __width));  \
+} else if (sizeof(long) == sizeof(int)) {  \
+  return static_cast(\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); \
+}  \
+  }\
+  inline __device__ unsigned long __FnName(unsigned int __mask,\
+   unsigned long __val, int __offset,  \
+   int __width = warpSize) {   \
+return static_cast( \
+::__FnName(__mask, static_cast(__val), __offset, __width));  \
+  }\
   inline __device__ double __FnName(unsigned int __mask, double __val, \
 int __offset, int __width = warpSize) {\
 long long __tmp;   \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40871: [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319908: [CUDA] Added overloads for '[unsigned] long' 
variants of shfl builtins. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40871?vs=125648=125755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40871

Files:
  cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -135,6 +135,24 @@
 return static_cast(::__FnName( \
 __mask, static_cast(__val), __offset, __width));   \
   }\
+  inline __device__ long __FnName(unsigned int __mask, long __val, \
+  int __offset, int __width = warpSize) {  \
+_Static_assert(sizeof(long) == sizeof(long long) ||\
+   sizeof(long) == sizeof(int));   \
+if (sizeof(long) == sizeof(long long)) {   \
+  return static_cast(::__FnName( \
+  __mask, static_cast(__val), __offset, __width));  \
+} else if (sizeof(long) == sizeof(int)) {  \
+  return static_cast(\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); \
+}  \
+  }\
+  inline __device__ unsigned long __FnName(unsigned int __mask,\
+   unsigned long __val, int __offset,  \
+   int __width = warpSize) {   \
+return static_cast( \
+::__FnName(__mask, static_cast(__val), __offset, __width));  \
+  }\
   inline __device__ double __FnName(unsigned int __mask, double __val, \
 int __offset, int __width = warpSize) {\
 long long __tmp;   \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r319908 - [CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

2017-12-06 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Dec  6 09:40:35 2017
New Revision: 319908

URL: http://llvm.org/viewvc/llvm-project?rev=319908=rev
Log:
[CUDA] Added overloads for '[unsigned] long' variants of shfl builtins.

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

Modified:
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=319908=319907=319908=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Wed Dec  6 09:40:35 2017
@@ -135,6 +135,24 @@ __MAKE_SHUFFLES(__shfl_xor, __nvvm_shfl_
 return static_cast(::__FnName( 
\
 __mask, static_cast(__val), __offset, __width));   
\
   }
\
+  inline __device__ long __FnName(unsigned int __mask, long __val, 
\
+  int __offset, int __width = warpSize) {  
\
+_Static_assert(sizeof(long) == sizeof(long long) ||
\
+   sizeof(long) == sizeof(int));   
\
+if (sizeof(long) == sizeof(long long)) {   
\
+  return static_cast(::__FnName( 
\
+  __mask, static_cast(__val), __offset, __width));  
\
+} else if (sizeof(long) == sizeof(int)) {  
\
+  return static_cast(
\
+  ::__FnName(__mask, static_cast(__val), __offset, __width)); 
\
+}  
\
+  }
\
+  inline __device__ unsigned long __FnName(unsigned int __mask,
\
+   unsigned long __val, int __offset,  
\
+   int __width = warpSize) {   
\
+return static_cast( 
\
+::__FnName(__mask, static_cast(__val), __offset, __width));  
\
+  }
\
   inline __device__ double __FnName(unsigned int __mask, double __val, 
\
 int __offset, int __width = warpSize) {
\
 long long __tmp;   
\


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


r319909 - [NVPTX, CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in clang.

2017-12-06 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Dec  6 09:50:05 2017
New Revision: 319909

URL: http://llvm.org/viewvc/llvm-project?rev=319909=rev
Log:
[NVPTX,CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in 
clang.


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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def?rev=319909=319908=319909=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def Wed Dec  6 09:50:05 2017
@@ -371,6 +371,9 @@ BUILTIN(__nvvm_bitcast_i2f, "fi", "")
 BUILTIN(__nvvm_bitcast_ll2d, "dLLi", "")
 BUILTIN(__nvvm_bitcast_d2ll, "LLid", "")
 
+// FNS
+TARGET_BUILTIN(__nvvm_fns, "UiUiUii", "n", "ptx60")
+
 // Sync
 
 BUILTIN(__syncthreads, "v", "")

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=319909=319908=319909=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Wed Dec  6 09:50:05 2017
@@ -206,6 +206,10 @@ inline __device__ unsigned int __ballot_
 
 inline __device__ unsigned int __activemask() { return __nvvm_vote_ballot(1); }
 
+inline __device__ unsigned int __fns(unsigned mask, unsigned base, int offset) 
{
+  return __nvvm_fns(mask, base, offset);
+}
+
 #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
 
 // Define __match* builtins CUDA-9 headers expect to see.


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


[PATCH] D40884: [Index] Add setPreprocessor member to IndexDataConsumer.

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

In https://reviews.llvm.org/D40884#946506, @malaperle wrote:

> You can get the preprocessor from the ASTContext, no?


I don't think `ASTContext` contains preprocessor information.


Repository:
  rC Clang

https://reviews.llvm.org/D40884



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


[PATCH] D40901: Refactor lazy loading of template specializations. NFC

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

Fix preexisting comment typo.


https://reviews.llvm.org/D40901

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp

Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -182,15 +182,30 @@
   return Common;
 }
 
+void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
+  // Grab the most recent declaration to ensure we've loaded any lazy
+  // redeclarations of this template.
+  //
+  // FIXME: Avoid walking the entire redeclaration chain here.
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
+  if (CommonBasePtr->LazySpecializations) {
+ASTContext  = getASTContext();
+uint32_t *Specs = CommonBasePtr->LazySpecializations;
+CommonBasePtr->LazySpecializations = nullptr;
+for (uint32_t I = 0, N = *Specs++; I != N; ++I)
+  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
+  }
+}
+
 template
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector , ArrayRef Args,
 void *) {
   using SETraits = SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID,Args, getASTContext());
+  EntryType::Profile(ID, Args, getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -251,18 +266,7 @@
 }
 
 void FunctionTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -330,18 +334,7 @@
 }
 
 void ClassTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -941,21 +934,8 @@
  DeclarationName(), nullptr, nullptr);
 }
 
-// TODO: Unify across class, function and variable templates?
-//   May require moving this and Common to RedeclarableTemplateDecl.
 void VarTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -800,6 +800,8 @@
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
+  void loadLazySpecializationsImpl() const;
+
   template  typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector ,
  ArrayRef Args, void *);
@@ -818,6 +820,13 @@
 /// was explicitly specialized.
 llvm::PointerIntPair
   InstantiatedFromMember;
+
+/// \brief If non-null, points to an array of specializations (including
+/// partial specializations) known only by their external declaration IDs.
+///
+/// The first value in the array is the number of specializations/partial
+/// specializations that follow.
+uint32_t *LazySpecializations = nullptr;
   };
 
   /// \brief Pointer to the common data shared by all declarations of this
@@ -985,13 +994,6 @@
 /// require the use of this information.
 TemplateArgument *InjectedArgs = 

[PATCH] D39812: [Driver, CodeGen] pass through and apply -fassociative-math

2017-12-06 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Ping * 3.


https://reviews.llvm.org/D39812



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


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

2017-12-06 Thread Zoltán Gera via Phabricator via cfe-commits
gerazo added a comment.

The code modifications are coming soon (after doing some extensive testing) for 
the scan-build part.




Comment at: tools/scan-build-py/libscanbuild/analyze.py:223
+ctu_config = get_ctu_config(args)
+if ctu_config.collect:
+shutil.rmtree(ctu_config.dir, ignore_errors=True)

danielmarjamaki wrote:
> danielmarjamaki wrote:
> > not a big deal but I would use early exits in this function
> with "not a big deal" I mean; feel free to ignore my comment if you want to 
> have it this way.
I've checked it through. The only place for an early exit now would be before 
the else. The 1st and 2nd ifs are in fact non-orthogonal.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:145
+mangled_ast_pairs.append((mangled_name, ast_files.pop()))
+
+return mangled_ast_pairs

george.karpenkov wrote:
> Overall, instead of creating a dictionary with multiple elements, and then 
> converting to a list, it's much simper to only add an element to 
> `mangled_to_asts` when it is not already mapped to something (probably 
> logging a message otherwise), and then just return `mangled_to_asts.items()`
The reason for the previous is that we need to count the occurence number 
ofdifferent mappings only let those pass through which don't have multiple 
variations.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:189
+# Remove all temporary files
+shutil.rmtree(fnmap_dir, ignore_errors=True)
+

gerazo wrote:
> george.karpenkov wrote:
> > Having an analysis tool remove files is scary, what if (maybe not in this 
> > revision, but in a future iteration) a bug is introduced, and the tool 
> > removes user code instead?
> > Why not just create a temporary directory with `tempfile.mkdtemp`, put all 
> > temporary files there, and then simply iterate through them?
> > Then you would be able to get rid of the constant `CPU_TEMP_FNMAP_FOLDER` 
> > entirely, and OS would be responsible for cleanup.
> Yes, you are right. We are essentially using a temp dir. Because of the size 
> we first had to put it next to the project (not on tmp drive for instance) 
> and for debugging purposes we gave a name to it. Still it can be done with 
> mkdtemp as well.
Finally, I came to the conclusion that mkdtemp would not be better than the 
current solution. In order to find our created dir by other threads, we need a 
designated name. Suffixing it by generated name would further complicate things 
as we need not to allow multiple concurrent runs here. The current solution is 
more robust from this point of view.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:241
+run_analyzer_parallel(args)
+shutil.rmtree(ctu_config.dir, ignore_errors=True)
+else:

george.karpenkov wrote:
> Same as the comment above about removing folders. Also it seems like there 
> should be a way to remove redundancy in `if collect / remove tree` block 
> repeated twice.
Th previous call for data removal happens because the user asked for a collect 
run, so we clean data to do a recollection. This second one happens because the 
user asked for a full recollection and anaylsis run all in one. So here we 
destroy the temp data for user's convenience. This happens after, not before 
like previously. The default behavior is to do this when the user uses the tool 
the easy way (collect and analyze all in one) and we intentionally keep 
collection data if the user only asks for a collect or an analyze run. So with 
this, the user can use a collect run's results for multiple analyze runs. This 
is written in the command line help. I will definitely put comments here to 
explain.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:296
+'command': [execution.cmd[0], '-c'] + compilation.flags,
+'ctu': json.loads(os.getenv('ANALYZE_BUILD_CTU'))
 }

george.karpenkov wrote:
> Again, is it possible to avoid JSON-over-environment-variables?
There is an other thing against changing this. Currently the interface here 
using env variables is used by intercept-build, analyze-build and scan-build 
tool as well. In order to drop json, we need to change those tools too. It 
would be a separate patch definitely.



Comment at: tools/scan-build-py/libscanbuild/analyze.py:561
+except OSError:
+pass
+ast_command = [opts['clang'], '-emit-ast']

gerazo wrote:
> george.karpenkov wrote:
> > `try/except/pass` is almost always bad.
> > When can the error occur? Why are we ignoring it?
> I think this code is redundant with the if above.
Here the folders are created on demand. Because these are created parallel by 
multiple processes, there is small chance that an other process already created 
the folder between the isdir check and the makedirs 

[PATCH] D40901: Refactor lazy loading of template specializations. NFC

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

Unify the loading of lazy template specializations across class, function

  and variable templates.


Repository:
  rL LLVM

https://reviews.llvm.org/D40901

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp

Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -182,15 +182,30 @@
   return Common;
 }
 
+void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
+  // Grab the most recent declaration to ensure we've loaded any lazy
+  // redeclarations of this template.
+  //
+  // FIXME: Avoid walking the entire redeclaration chain here.
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
+  if (CommonBasePtr->LazySpecializations) {
+ASTContext  = getASTContext();
+uint32_t *Specs = CommonBasePtr->LazySpecializations;
+CommonBasePtr->LazySpecializations = nullptr;
+for (uint32_t I = 0, N = *Specs++; I != N; ++I)
+  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
+  }
+}
+
 template
 typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType *
 RedeclarableTemplateDecl::findSpecializationImpl(
 llvm::FoldingSetVector , ArrayRef Args,
 void *) {
   using SETraits = SpecEntryTraits;
 
   llvm::FoldingSetNodeID ID;
-  EntryType::Profile(ID,Args, getASTContext());
+  EntryType::Profile(ID, Args, getASTContext());
   EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
   return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
 }
@@ -251,18 +266,7 @@
 }
 
 void FunctionTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -330,18 +334,7 @@
 }
 
 void ClassTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
@@ -941,21 +934,8 @@
  DeclarationName(), nullptr, nullptr);
 }
 
-// TODO: Unify across class, function and variable templates?
-//   May require moving this and Common to RedeclarableTemplateDecl.
 void VarTemplateDecl::LoadLazySpecializations() const {
-  // Grab the most recent declaration to ensure we've loaded any lazy
-  // redeclarations of this template.
-  //
-  // FIXME: Avoid walking the entire redeclaration chain here.
-  Common *CommonPtr = getMostRecentDecl()->getCommonPtr();
-  if (CommonPtr->LazySpecializations) {
-ASTContext  = getASTContext();
-uint32_t *Specs = CommonPtr->LazySpecializations;
-CommonPtr->LazySpecializations = nullptr;
-for (uint32_t I = 0, N = *Specs++; I != N; ++I)
-  (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
-  }
+  loadLazySpecializationsImpl();
 }
 
 llvm::FoldingSetVector &
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -800,6 +800,8 @@
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
+  void loadLazySpecializationsImpl() const;
+
   template  typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector ,
  ArrayRef Args, void *);
@@ -818,6 +820,13 @@
 /// was explicitly specialized.
 llvm::PointerIntPair
   InstantiatedFromMember;
+
+/// \brief If non-null, points to an array of specializations (including
+/// partial specializations) known only by their external declaration IDs.
+///
+/// The first value in the array is the number of of specializations/
+/// partial specializations that follow.
+uint32_t *LazySpecializations = nullptr;
   };
 
   /// \brief Pointer to the common data shared by all declarations of this
@@ -985,13 +994,6 @@
 /// require the use of 

[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sam Parker via Phabricator via cfe-commits
samparker accepted this revision.
samparker added a comment.
This revision is now accepted and ready to land.

Great, LGTM, many thanks for doing this!


https://reviews.llvm.org/D40888



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


[PATCH] D40895: Ignore pointers to incomplete types when diagnosing misaligned addresses

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

LGTM, thank you!


https://reviews.llvm.org/D40895



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


[PATCH] D40872: [NVPTX, CUDA] Added llvm.nvvm.fns intrinsic and matching __nvvm_fns builtin in clang.

2017-12-06 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319909: [NVPTX,CUDA] Added llvm.nvvm.fns intrinsic and 
matching __nvvm_fns builtin in… (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D40872?vs=125649=125757#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40872

Files:
  cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
  cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
  llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
  llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/trunk/test/CodeGen/NVPTX/fns.ll

Index: llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
@@ -682,6 +682,11 @@
   def int_nvvm_bitcast_d2ll : GCCBuiltin<"__nvvm_bitcast_d2ll">,
   Intrinsic<[llvm_i64_ty], [llvm_double_ty], [IntrNoMem]>;
 
+// FNS
+
+  def int_nvvm_fns : GCCBuiltin<"__nvvm_fns">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
+[IntrNoMem]>;
 
 // Atomics not available as llvm intrinsics.
   def int_nvvm_atomic_load_add_f32 : Intrinsic<[llvm_float_ty],
Index: llvm/trunk/test/CodeGen/NVPTX/fns.ll
===
--- llvm/trunk/test/CodeGen/NVPTX/fns.ll
+++ llvm/trunk/test/CodeGen/NVPTX/fns.ll
@@ -0,0 +1,36 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_30 -mattr=+ptx60 | FileCheck %s
+
+declare i32 @llvm.nvvm.fns(i32, i32, i32)
+
+; CHECK-LABEL: .func{{.*}}fns
+define i32 @fns(i32 %mask, i32 %base, i32 %offset) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [fns_param_0];
+  ; CHECK: ld.param.u32 	[[BASE:%r[0-9]+]], [fns_param_1];
+  ; CHECK: ld.param.u32 	[[OFFSET:%r[0-9]+]], [fns_param_2];
+
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], [[BASE]], [[OFFSET]];
+  %r0 = call i32 @llvm.nvvm.fns(i32 %mask, i32 %base, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], [[BASE]], 0;
+  %r1 = call i32 @llvm.nvvm.fns(i32 %mask, i32 %base, i32 0);
+  %r01 = add i32 %r0, %r1;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], 1, [[OFFSET]];
+  %r2 = call i32 @llvm.nvvm.fns(i32 %mask, i32 1, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, [[MASK]], 1, 0;
+  %r3 = call i32 @llvm.nvvm.fns(i32 %mask, i32 1, i32 0);
+  %r23 = add i32 %r2, %r3;
+  %r0123 = add i32 %r01, %r23;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, [[BASE]], [[OFFSET]];
+  %r4 = call i32 @llvm.nvvm.fns(i32 2, i32 %base, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, [[BASE]], 0;
+  %r5 = call i32 @llvm.nvvm.fns(i32 2, i32 %base, i32 0);
+  %r45 = add i32 %r4, %r5;
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, 1, [[OFFSET]];
+  %r6 = call i32 @llvm.nvvm.fns(i32 2, i32 1, i32 %offset);
+  ; CHECK:  fns.b32 	{{%r[0-9]+}}, 2, 1, 0;
+  %r7 = call i32 @llvm.nvvm.fns(i32 2, i32 1, i32 0);
+  %r67 = add i32 %r6, %r7;
+  %r4567 = add i32 %r45, %r67;
+  %r = add i32 %r0123, %r4567;
+  ret i32 %r;
+}
+
Index: llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -979,6 +979,33 @@
 def INT_NVVM_BITCAST_D2LL : F_MATH_1<"mov.b64 \t$dst, $src0;", Int64Regs,
   Float64Regs, int_nvvm_bitcast_d2ll>;
 
+//
+// FNS
+//
+
+class INT_FNS_MBO
+  : NVPTXInst<(outs Int32Regs:$dst), ins,
+   "fns.b32 \t$dst, $mask, $base, $offset;",
+   [(set Int32Regs:$dst, Operands )]>,
+Requires<[hasPTX60, hasSM30]>;
+
+def INT_FNS_rrr : INT_FNS_MBO<(ins Int32Regs:$mask, Int32Regs:$base, Int32Regs:$offset),
+ (int_nvvm_fns Int32Regs:$mask, Int32Regs:$base, Int32Regs:$offset)>;
+def INT_FNS_rri : INT_FNS_MBO<(ins Int32Regs:$mask, Int32Regs:$base,i32imm:$offset),
+ (int_nvvm_fns Int32Regs:$mask, Int32Regs:$base,   imm:$offset)>;
+def INT_FNS_rir : INT_FNS_MBO<(ins Int32Regs:$mask,i32imm:$base, Int32Regs:$offset),
+ (int_nvvm_fns Int32Regs:$mask,   imm:$base, Int32Regs:$offset)>;
+def INT_FNS_rii : INT_FNS_MBO<(ins Int32Regs:$mask,i32imm:$base,i32imm:$offset),
+ (int_nvvm_fns Int32Regs:$mask,   imm:$base,   imm:$offset)>;
+def INT_FNS_irr : INT_FNS_MBO<(insi32imm:$mask, Int32Regs:$base, Int32Regs:$offset),
+ (int_nvvm_fns   imm:$mask, Int32Regs:$base, Int32Regs:$offset)>;
+def INT_FNS_iri : INT_FNS_MBO<(insi32imm:$mask, Int32Regs:$base,i32imm:$offset),
+ (int_nvvm_fns   imm:$mask, Int32Regs:$base,   imm:$offset)>;
+def INT_FNS_iir : INT_FNS_MBO<(insi32imm:$mask,i32imm:$base, Int32Regs:$offset),
+ (int_nvvm_fns   imm:$mask,   imm:$base, Int32Regs:$offset)>;
+def INT_FNS_iii : INT_FNS_MBO<(insi32imm:$mask,i32imm:$base,i32imm:$offset),
+ (int_nvvm_fns   

[PATCH] D40806: CodeGen: Fix invalid bitcasts for memcpy

2017-12-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D40806



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


[PATCH] D40486: [clangd] Implemented logging using Context

2017-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Mostly nits - throughout there's going to be lots of judgement calls about 
where to propagate context and where not.
No need to get all those "exactly right", but trying to get a feel for what 
these answers are likely to be.

Most of the interesting stuff is around the logger itself of course :-)




Comment at: clangd/ClangdServer.cpp:31
 
-class FulfillPromiseGuard {
+class FulfillContextPromiseGuard {
 public:

Up to you, but I like the old name better - this class is local so it's OK to 
be a bit opinionated.



Comment at: clangd/ClangdServer.cpp:36
 
-  ~FulfillPromiseGuard() { Promise.set_value(); }
+  ~FulfillContextPromiseGuard() { Promise.set_value(std::move(Ctx)); }
 

Yikes, I can see how we got here, but we really don't get to move out of 
something we received an lvalue-reference to...

I think a safer idiom here is turning a whole lambda into a destructor:

   auto Fulfil = MakeDestructor([&]{
  DonePromise.set_value(std::move(Ctx));
   });

I'm not sure if LLVM has a shared utility for this, I've seen it in other 
codebases. Either way we could just define it here.

(Or we could copy the context to avoid the awkwardness)



Comment at: clangd/ClangdServer.cpp:220
 
-  // Note that std::future from this cleanup action is ignored.
-  scheduleCancelRebuild(std::move(Recreated.RemovedFile));
+  // Note that std::future from this cleanup action.
+  // FIXME(ibiryukov): We use a global context here, should not fork the action

You dropped the end of this comment



Comment at: clangd/ClangdServer.cpp:221
+  // Note that std::future from this cleanup action.
+  // FIXME(ibiryukov): We use a global context here, should not fork the action
+  // instead.

I don't quite understand what this is saying should be better. Is it saying we 
do these two things together instead of running them in parallel?

And why not clone the context instead?



Comment at: clangd/ClangdUnit.cpp:436
+  RebuildInProgress(false), PCHs(std::move(PCHs)) {
+  log(emptyCtx(), "Opened file " + FileName + " with command [" +
+  this->Command.Directory + "] " +

why are we dropping the context here?
It's important that in general we don't store the ctx in the object and blindly 
reuse it, but passing it into the constructor for use *in* the constructor 
seems fine.

Reading on... OK, it saves a *lot* of plumbing to avoid attributing this one 
API call. I still don't totally understand how the CppFile API/lifetime works, 
so up to you.



Comment at: clangd/ClangdUnit.cpp:533
+That](std::string NewContents,
+  Context ) mutable // 'mutable' to
+// allow changing

nit: this wrapping has become *really* weird over time - can we change the 
comment to `/* allow changing OldPreamble */` to try to fix it?



Comment at: clangd/ClangdUnit.h:257
 
+/// Get signature help at a specified \p Pos in \p FileName.
+SignatureHelp

I think this is a bad merge - signatureHelp has moved to CodeComplete.h



Comment at: clangd/GlobalCompilationDatabase.h:37
   virtual llvm::Optional
   getCompileCommand(PathRef File) const = 0;
 

Do we want Ctx in this interface?
It's an extension point, and the ability for embedders to track calls flowing 
between their API calls and their extension points is one of the reasons we 
have ctx...



Comment at: clangd/JSONRPCDispatcher.cpp:22
 
+namespace {
+static Key TracerKey;

Maybe we don't need the Key suffix, as it's in the type... we should spend our 
verbosity elsewhere



Comment at: clangd/JSONRPCDispatcher.cpp:23
+namespace {
+static Key TracerKey;
+static Key IDKey;

RequestTracer?



Comment at: clangd/JSONRPCDispatcher.cpp:24
+static Key TracerKey;
+static Key IDKey;
+static Key OutKey;

RequestID



Comment at: clangd/JSONRPCDispatcher.cpp:48
+void JSONOutput::logImpl(Context , const Twine ) {
+  // FIXME(ibiryukov): get rid of trace::log here.
   trace::log(Message);

why?



Comment at: clangd/JSONRPCDispatcher.h:29
 /// them.
 class JSONOutput : public Logger {
 public:

does this class need to be public? Is it staying around for the long haul?



Comment at: clangd/JSONRPCDispatcher.h:39
   /// Write a line to the logging stream.
-  void log(const Twine ) override;
+  void logImpl(Context , const Twine ) override;
 

Is this temporary?



Comment at: clangd/Logger.cpp:16
+namespace {
+class EmptyLogger : public Logger {
+public:

[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-06 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Hi! Have you looked into https://reviews.llvm.org/D40548 ? Maybe we need to 
coordinate the two a bit.




Comment at: clangd/Symbol.h:37
+// The class presents a C++ symbol, e.g. class, function.
+struct Symbol {
+  // The symbol identifier, using USR.

I think it would be nice to have methods as an interface to get this data 
instead of storing them directly. So that an index-on-disk could go fetch the 
data. Especially the occurrences which can take a lot of memory (I'm working on 
a branch that does that). But perhaps defining that interface is not within the 
scope of this patch and could be better discussed in D40548 ?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2017-12-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 125779.
erichkeane marked 3 inline comments as done.
erichkeane added a comment.

Fix all rsmith's and craig's fixes, AFAIK.


https://reviews.llvm.org/D40819

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/X86Target.def
  include/clang/Sema/Overload.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/attr-target-mv-func-ptrs.c
  test/CodeGen/attr-target-mv-va-args.c
  test/CodeGen/attr-target-mv.c
  test/CodeGenCXX/attr-target-mv-constexpr.cpp
  test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  test/CodeGenCXX/attr-target-mv-func-ptrs.cpp
  test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  test/CodeGenCXX/attr-target-mv-overloads.cpp
  test/Sema/attr-target-mv.c
  test/SemaCXX/attr-target-mv.cpp

Index: test/SemaCXX/attr-target-mv.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-mv.cpp
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("sse4.2"))) no_default(void);
+void __attribute__((target("arch=sandybridge")))  no_default(void);
+
+void use1(void){
+  // expected-note@-4 {{candidate ignored: non-default multiversion function cannot be called directly}}
+  // expected-note@-4 {{candidate ignored: non-default multiversion function cannot be called directly}}
+  // expected-error@+1 {{no matching function for call to 'no_default'}}
+  no_default();
+}
+constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
+constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
+//expected-error@+1 {{multiversion function declaration has a different constexpr specification}}
+int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
+constexpr int __attribute__((target("default"))) foo(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different constexpr specification}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
+int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
+int __attribute__((target("default"))) foo2(void) { return 2; }
+
+static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar(void);
+//expected-error@+1 {{multiversion function declaration has a different storage class}}
+int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
+static int __attribute__((target("default"))) bar(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different storage class}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+static int __attribute__((target("arch=sandybridge"))) bar2(void);
+int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
+int __attribute__((target("default"))) bar2(void) { return 2; }
+
+
+inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
+inline int __attribute__((target("arch=sandybridge"))) baz(void);
+//expected-error@+1 {{multiversion function declaration has a different inline specification}}
+int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
+inline int __attribute__((target("default"))) baz(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different inline specification}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+inline int __attribute__((target("arch=sandybridge"))) baz2(void);
+int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
+int __attribute__((target("default"))) baz2(void) { return 2; }
+
+float __attribute__((target("sse4.2"))) bock(void) { return 0; }
+//expected-error@+2 {{multiversion function declaration has a different return type}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+int __attribute__((target("arch=sandybridge"))) bock(void);
+//expected-error@+2 {{multiversion function declaration has a different return type}}
+//expected-note@+1 {{function multiversion caused by this declaration}}
+int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
+//expected-error@+2 {{multiversion function declaration has a different 

[clang-tools-extra] r319948 - [CMake] Use PRIVATE in target_link_libraries for fuzzers.

2017-12-06 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Wed Dec  6 11:52:40 2017
New Revision: 319948

URL: http://llvm.org/viewvc/llvm-project?rev=319948=rev
Log:
[CMake] Use PRIVATE in target_link_libraries for fuzzers.

Several fuzzers were missed by r319840.

Modified:
clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt?rev=319948=319947=319948=diff
==
--- clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 
2017
@@ -12,6 +12,7 @@ add_clang_executable(clangd-fuzzer
   )
 
 target_link_libraries(clangd-fuzzer
+  PRIVATE
   clangBasic
   clangDaemon
   clangFormat


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


r319948 - [CMake] Use PRIVATE in target_link_libraries for fuzzers.

2017-12-06 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Wed Dec  6 11:52:40 2017
New Revision: 319948

URL: http://llvm.org/viewvc/llvm-project?rev=319948=rev
Log:
[CMake] Use PRIVATE in target_link_libraries for fuzzers.

Several fuzzers were missed by r319840.

Modified:
cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt

Modified: cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt?rev=319948=319947=319948=diff
==
--- cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-format/fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 2017
@@ -10,6 +10,7 @@ add_clang_executable(clang-format-fuzzer
   )
 
 target_link_libraries(clang-format-fuzzer
+  PRIVATE
   ${CLANG_FORMAT_LIB_DEPS}
   ${LLVM_LIB_FUZZING_ENGINE}
   )

Modified: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/CMakeLists.txt?rev=319948=319947=319948=diff
==
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt Wed Dec  6 11:52:40 2017
@@ -48,6 +48,7 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 )
 
   target_link_libraries(clang-proto-fuzzer
+PRIVATE
 ${ProtobufMutator_LIBRARIES}
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}

Modified: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt?rev=319948=319947=319948=diff
==
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt Wed Dec  6 
11:52:40 2017
@@ -11,4 +11,4 @@ add_clang_library(clangProtoToCXX proto_
   )
 
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
-target_link_libraries(clang-proto-to-cxx clangProtoToCXX)
+target_link_libraries(clang-proto-to-cxx PRIVATE clangProtoToCXX)


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


[PATCH] D40567: Always show template parameters in IR type names

2017-12-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D40567#943747, @sepavloff wrote:

> Although code generation (in LTO compilation) might be unaffected by this 
> distortions, other applications of IR linking suffer from it. It does not 
> allow to implement some checks, validation techniques and optimizations.


Any system trying to use IR type names to deduce information about source-level 
types is simply wrong. We simply don't provide the sort of guarantees you seem 
to be looking for here. We don't even guarantee to consistently use the same IR 
type for the same source type within a single translation unit. IR type names 
exist only for the benefit of humans reading the IR.


Repository:
  rC Clang

https://reviews.llvm.org/D40567



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2017-12-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 14 inline comments as done.
erichkeane added a comment.

Incoming patch!




Comment at: include/clang/Basic/Attr.td:1809
   bool DuplicateArchitecture = false;
+  bool operator ==(const ParsedTargetAttr ) {
+return DuplicateArchitecture == Other.DuplicateArchitecture &&

rsmith wrote:
> Our normal convention is to not put a space before `==` here.
Clang format seems to keep adding it interestingly enough.  Perhaps because it 
is a .td file?  Will remove.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:9317-9318
+def err_target_required_in_redecl :
+  Error<"function declaration is missing 'target' attribute in a "
+"multiversioned function">;
+def note_multiversioning_caused_here :

rsmith wrote:
> There's some weird indentation hereabouts. Our normal convention is to put 
> the `Error<` on the `def` line, and start the diagnostic text as a 
> 2-space-indented string literal on the next line.
Thanks!  Clang-format really makes a mess of these too...



Comment at: lib/CodeGen/CodeGenModule.cpp:2144
+if (getContext().hasSameType(CurFD->getType(), FD->getType())) {
+  StringRef MangledName = getMangledName(CurFD);
+  llvm::Constant *Func = GetGlobalValue(MangledName);

rsmith wrote:
> You should skip functions you've already seen somewhere around here; we don't 
> need to handle the same function multiple times.
Will the lookup call give me duplicates?  I need to check each at least once 
through this so that I can put them into "Options" so that I can emit them 
during the resolver.  

Otherwise, I'm not terribly sure what you mean.



Comment at: lib/Sema/SemaDecl.cpp:9326-9328
+static bool CheckMultiVersionAdditionalRules(Sema , const FunctionDecl 
*OldFD,
+ const FunctionDecl *NewFD,
+ bool CausesMV) {

rsmith wrote:
> rsmith wrote:
> > Would it be possible to factor out the checks in `MergeFunctionDecl` that 
> > you're using here and reuse them directly?
> Maybe also check that the language linkage matches (`extern "C"` and `extern 
> "C++"` could imply different calling conventions, even though they don't on 
> any of our current targets).
I'd thought about that, but I'm being WAAY more strict, so I didn't see a good 
way to factor them out without making things pretty complicated.  Suggestions 
welcome :)



Comment at: lib/Sema/SemaDecl.cpp:9383-9384
+
+QualType OldReturnType = OldType->getReturnType();
+QualType NewReturnType = NewType->getReturnType();
+if (OldReturnType != NewReturnType) {

rsmith wrote:
> This won't do the right thing for C++14 deduced return types. I'm not 
> completely sure what the right thing is, though -- clearly we need to deduce 
> the same return type in all versions of the function, but it's less clear 
> whether we should also require the return-type-as-written to match across 
> versions (as is required across redeclarations). Example:
> 
> ```
> VERSION_FOO auto f() { return 0; } // declared return type is `auto`, actual 
> return type is `int`
> VERSION_BAR auto f(); // will fail the current check, because the return type 
> `auto` doesn't match the prior return type `int`
> VERSION_BAR auto f() { return 0.0; } // should reject this because we deduced 
> a different return type than on the VERSION_FOO version?
> ```
> 
> Perhaps the simplest thing would be to simply disallow deduced return types 
> for multiversioned functions entirely for now?
I think disallowing 'auto' return for now is a good idea. This next patch is 
using isUndeducedType, which I think is sufficient, but if there is a better 
function I'm missing, please let me know.


https://reviews.llvm.org/D40819



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


r319950 - [clang] Use PRIVATE in target_link_libraries

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 12:05:42 2017
New Revision: 319950

URL: http://llvm.org/viewvc/llvm-project?rev=319950=rev
Log:
[clang] Use PRIVATE in target_link_libraries

I'd missed this one in r319840 because I hadn't been configuring with an
order file before.

Modified:
cfe/trunk/tools/driver/CMakeLists.txt

Modified: cfe/trunk/tools/driver/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/CMakeLists.txt?rev=319950=319949=319950=diff
==
--- cfe/trunk/tools/driver/CMakeLists.txt (original)
+++ cfe/trunk/tools/driver/CMakeLists.txt Wed Dec  6 12:05:42 2017
@@ -123,7 +123,7 @@ if(CLANG_ORDER_FILE AND (LD64_EXECUTABLE
   if("${ORDER_FILE}" STREQUAL "\n")
 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS 
${CLANG_ORDER_FILE})
   elseif(LINKER_ORDER_FILE_WORKS)
-target_link_libraries(clang ${LINKER_ORDER_FILE_OPTION})
+target_link_libraries(clang PRIVATE ${LINKER_ORDER_FILE_OPTION})
 set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
   endif()
 endif()


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


[PATCH] D40548: [clangd] Prototyping index support and naive index-based global code completion. WIP

2017-12-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Hi Marc, the patch is not ready for review yet. I am still cleaning up the 
prototype and will let you know when it's ready for review.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40548



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


[PATCH] D40680: [libc++] Create install-stripped targets

2017-12-06 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319959: [libc++] Create install-stripped targets (authored 
by smeenai).

Repository:
  rL LLVM

https://reviews.llvm.org/D40680

Files:
  libcxx/trunk/include/CMakeLists.txt
  libcxx/trunk/lib/CMakeLists.txt


Index: libcxx/trunk/include/CMakeLists.txt
===
--- libcxx/trunk/include/CMakeLists.txt
+++ libcxx/trunk/include/CMakeLists.txt
@@ -58,6 +58,8 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
Index: libcxx/trunk/lib/CMakeLists.txt
===
--- libcxx/trunk/lib/CMakeLists.txt
+++ libcxx/trunk/lib/CMakeLists.txt
@@ -389,5 +389,13 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()


Index: libcxx/trunk/include/CMakeLists.txt
===
--- libcxx/trunk/include/CMakeLists.txt
+++ libcxx/trunk/include/CMakeLists.txt
@@ -58,6 +58,8 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
Index: libcxx/trunk/lib/CMakeLists.txt
===
--- libcxx/trunk/lib/CMakeLists.txt
+++ libcxx/trunk/lib/CMakeLists.txt
@@ -389,5 +389,13 @@
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r319959 - [libc++] Create install-stripped targets

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 13:03:42 2017
New Revision: 319959

URL: http://llvm.org/viewvc/llvm-project?rev=319959=rev
Log:
[libc++] Create install-stripped targets

LLVM is gaining install-*-stripped targets to perform stripped installs,
and in order for this to be useful for install-distribution, all
potential distribution components should have stripped installation
targets. LLVM has a function to create these install targets, but since
we can't use LLVM CMake functions in libc++, let's do it manually.

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

Modified:
libcxx/trunk/include/CMakeLists.txt
libcxx/trunk/lib/CMakeLists.txt

Modified: libcxx/trunk/include/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/CMakeLists.txt?rev=319959=319958=319959=diff
==
--- libcxx/trunk/include/CMakeLists.txt (original)
+++ libcxx/trunk/include/CMakeLists.txt Wed Dec  6 13:03:42 2017
@@ -58,6 +58,8 @@ if (LIBCXX_INSTALL_HEADERS)
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+# Stripping is a no-op for headers
+add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
 
 add_custom_target(libcxx-headers)
 add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=319959=319958=319959=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Wed Dec  6 13:03:42 2017
@@ -389,5 +389,13 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND (L
   COMMAND "${CMAKE_COMMAND}"
   -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-cxx-stripped
+  DEPENDS ${lib_install_target}
+  ${experimental_lib_install_target}
+  ${header_install_target}
+  COMMAND "${CMAKE_COMMAND}"
+  -DCMAKE_INSTALL_COMPONENT=cxx
+  -DCMAKE_INSTALL_DO_STRIP=1
+  -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
 add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()


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


[PATCH] D37813: clang-format: better handle namespace macros

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

In https://reviews.llvm.org/D37813#945125, @Typz wrote:

> I don't think this is really relevant for this tool: if someone changes the 
> implementation of the macro, then *they* must indeed if it should not be 
> formatted like a namespace (and keep the clang-format configuration 
> unchanged), or if it should now be formatted like a class (and thus make 
> changes to clang-format configuration). Here we are not defining what the 
> macro does, but how clang-format should indent it : in most case I don't 
> think the indentation format should actually depend on the way it is 
> implemented...


Ok, that's probably where our different opinions come from - I would want a 
macro to be formatted to reflect how it's implemented, because otherwise I'm 
going to be surprised when I look at the implementation, and I consider 
surprises to be something to avoid in programming in general, where possible.

That said, I'm also then a bit confused by your tests - they seem to currently 
format a mixture of namespace and class formatting, and combine the indentation 
of a class-scope with namespace end comments.


https://reviews.llvm.org/D37813



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


[PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319883: [OpenCL] Fix layering violation by 
getOpenCLTypeAddrSpace (authored by svenvh).

Repository:
  rC Clang

https://reviews.llvm.org/D40838

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/AMDGPU.h
  lib/CodeGen/CGOpenCLRuntime.cpp

Index: include/clang/AST/ASTContext.h
===
--- include/clang/AST/ASTContext.h
+++ include/clang/AST/ASTContext.h
@@ -1224,6 +1224,12 @@
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -46,7 +46,6 @@
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1826,7 +1826,8 @@
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.
Index: lib/Basic/Targets/AMDGPU.h
===
--- lib/Basic/Targets/AMDGPU.h
+++ lib/Basic/Targets/AMDGPU.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
 #define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
 
-#include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/StringSet.h"
@@ -258,24 +257,18 @@
 }
   }
 
-  LangAS getOpenCLTypeAddrSpace(const Type *T) const override {
-auto BT = dyn_cast(T);
-
-if (!BT)
-  return TargetInfo::getOpenCLTypeAddrSpace(T);
-
-switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
-  case BuiltinType::Id:\
-return LangAS::opencl_constant;
-#include "clang/Basic/OpenCLImageTypes.def"
-case BuiltinType::OCLClkEvent:
-case BuiltinType::OCLQueue:
-case BuiltinType::OCLReserveID:
+  LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
+switch (TK) {
+case OCLTK_Image:
+  return LangAS::opencl_constant;
+
+case OCLTK_ClkEvent:
+case 

r319883 - [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Wed Dec  6 02:11:28 2017
New Revision: 319883

URL: http://llvm.org/viewvc/llvm-project?rev=319883=rev
Log:
[OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

Commit 7ac28eb0a5 / r310911 ("[OpenCL] Allow targets to select address
space per type", 2017-08-15) made Basic depend on AST, introducing a
circular dependency.  Break this dependency by adding the
OpenCLTypeKind enum in Basic and map from AST types to this enum in
ASTContext.

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets/AMDGPU.h
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=319883=319882=319883=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Dec  6 02:11:28 2017
@@ -1224,6 +1224,12 @@ public:
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=319883=319882=319883=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Dec  6 02:11:28 2017
@@ -46,7 +46,6 @@ class MacroBuilder;
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@ public:
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=319883=319882=319883=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Dec  6 02:11:28 2017
@@ -1826,7 +1826,8 @@ TypeInfo ASTContext::getTypeInfoImpl(con
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@ QualType ASTContext::getBlockDescriptorE
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
+  case BuiltinType::Id:
\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 

[PATCH] D40838: [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace

2017-12-06 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL319883: [OpenCL] Fix layering violation by 
getOpenCLTypeAddrSpace (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D40838?vs=125554=125682#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40838

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets/AMDGPU.h
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp

Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1224,6 +1224,12 @@
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;
 
+  /// Map an AST Type to an OpenCLTypeKind enum value.
+  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+  /// Get address space for OpenCL type.
+  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -46,7 +46,6 @@
 class QualType;
 class SourceLocation;
 class SourceManager;
-class Type;
 
 namespace Builtin { struct Info; }
 
@@ -1057,8 +1056,19 @@
   return getTargetOpts().SupportedOpenCLOptions;
   }
 
+  enum OpenCLTypeKind {
+OCLTK_Default,
+OCLTK_ClkEvent,
+OCLTK_Event,
+OCLTK_Image,
+OCLTK_Pipe,
+OCLTK_Queue,
+OCLTK_ReserveID,
+OCLTK_Sampler,
+  };
+
   /// \brief Get address space for OpenCL type.
-  virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
 
   /// \returns Target specific vtbl ptr address space.
   virtual unsigned getVtblPtrAddressSpace() const {
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -1826,7 +1826,8 @@
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
 case BuiltinType::Id:
 #include "clang/Basic/OpenCLImageTypes.def"
-  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+  AS = getTargetAddressSpace(
+  Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -5720,6 +5721,46 @@
   return getTagDeclType(BlockDescriptorExtendedType);
 }
 
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+  auto BT = dyn_cast(T);
+
+  if (!BT) {
+if (isa(T))
+  return TargetInfo::OCLTK_Pipe;
+
+return TargetInfo::OCLTK_Default;
+  }
+
+  switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
+return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+  case BuiltinType::OCLClkEvent:
+return TargetInfo::OCLTK_ClkEvent;
+
+  case BuiltinType::OCLEvent:
+return TargetInfo::OCLTK_Event;
+
+  case BuiltinType::OCLQueue:
+return TargetInfo::OCLTK_Queue;
+
+  case BuiltinType::OCLReserveID:
+return TargetInfo::OCLTK_ReserveID;
+
+  case BuiltinType::OCLSampler:
+return TargetInfo::OCLTK_Sampler;
+
+  default:
+return TargetInfo::OCLTK_Default;
+  }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+  return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
 /// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
 /// requires copy/dispose. Note that this must match the logic
 /// in buildByrefHelpers.
Index: cfe/trunk/lib/Basic/TargetInfo.cpp
===
--- cfe/trunk/lib/Basic/TargetInfo.cpp
+++ cfe/trunk/lib/Basic/TargetInfo.cpp
@@ -12,7 +12,6 @@
 //===--===//
 
 #include "clang/Basic/TargetInfo.h"
-#include "clang/AST/Type.h"
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/LangOptions.h"
@@ -357,23 +356,13 @@
   return true;
 }
 
-LangAS TargetInfo::getOpenCLTypeAddrSpace(const Type *T) const {
-  auto BT = dyn_cast(T);
-
-  if (!BT) {
-if (isa(T))
-  return LangAS::opencl_global;
-
-return LangAS::Default;
-  }
-
-  switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
-  case BuiltinType::Id:\
+LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) 

[PATCH] D40489: [clangd] Changed tracing interfaces

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125696.
ilya-biryukov added a comment.
Herald added a subscriber: klimek.

- Update the patch to accomodate changes from tracing and Context patches.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40489

Files:
  clangd/Trace.cpp
  clangd/Trace.h

Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -28,12 +28,21 @@
 namespace trace {
 
 /// A consumer of trace events. The events are produced by Spans and trace::log.
+/// Calls to begin_event and end_event with the same name are always properly
+/// nested by using a RAII object (Span).
+/// Implmentations of this interface must be thread-safe.
 class EventTracer {
 public:
   virtual ~EventTracer() = default;
-  /// Consume a trace event.
-  virtual void event(const ContextData , llvm::StringRef Phase,
- json::obj &) = 0;
+
+  /// Called when event with \p Name starts.
+  virtual void begin_event(const ContextData , llvm::StringRef Name) = 0;
+  /// Called when event with \p Name ends.
+  virtual void end_event(const ContextData , llvm::StringRef Name,
+ json::obj &) = 0;
+  /// Called for instant events.
+  virtual void instant_event(const ContextData , llvm::StringRef Name,
+ json::obj &) = 0;
 };
 
 /// Sets up a global EventTracer that consumes events produced by Span and
@@ -67,15 +76,16 @@
 /// SomeJSONExpr is evaluated and copied only if actually needed.
 class Span {
 public:
-  Span(Context , std::string Name);
+  Span(Context , llvm::StringRef Name);
   ~Span();
 
   /// Returns mutable span metadata if this span is interested.
   /// Prefer to use SPAN_ATTACH rather than accessing this directly.
   json::obj *args() { return Args.get(); }
 
 private:
   const ContextData 
+  std::string Name;
   std::unique_ptr Args;
 };
 
Index: clangd/Trace.cpp
===
--- clangd/Trace.cpp
+++ clangd/Trace.cpp
@@ -44,10 +44,23 @@
 Out.flush();
   }
 
+  void begin_event(const ContextData , llvm::StringRef Name) override {
+jsonEvent("B", json::obj{{"name", Name}});
+  }
+
+  void end_event(const ContextData , llvm::StringRef Name,
+ json::obj &) override {
+jsonEvent("E", json::obj{{"args", std::move(Args)}});
+  }
+
+  void instant_event(const ContextData , llvm::StringRef Name,
+ json::obj &) override {
+jsonEvent("i", json::obj{{"name", Name}, {"args", std::move(Args)}});
+  }
+
   // Record an event on the current thread. ph, pid, tid, ts are set.
   // Contents must be a list of the other JSON key/values.
-  void event(const ContextData , StringRef Phase,
- json::obj &) override {
+  void jsonEvent(StringRef Phase, json::obj &) {
 uint64_t TID = get_threadid();
 std::lock_guard Lock(Mu);
 // If we haven't already, emit metadata describing this thread.
@@ -109,27 +122,21 @@
 void log(Context , const Twine ) {
   if (!T)
 return;
-  T->event(*Ctx, "i",
-   json::obj{
-   {"name", "Log"},
-   {"args", json::obj{{"Message", Message.str()}}},
-   });
+  T->instant_event(*Ctx, "Log", json::obj{{"Message", Message.str()}});
 }
 
-Span::Span(Context , std::string Name) : Ctx(*Ctx) {
+Span::Span(Context , llvm::StringRef Name) : Ctx(*Ctx), Name(Name) {
   if (!T)
 return;
-  T->event(this->Ctx, "B", json::obj{{"name", std::move(Name)}});
+  T->begin_event(this->Ctx, this->Name);
   Args = llvm::make_unique();
 }
 
 Span::~Span() {
   if (!T)
 return;
-  if (!Args)
-Args = llvm::make_unique();
-  T->event(Ctx, "E",
-   Args ? json::obj{{"args", std::move(*Args)}} : json::obj{});
+  assert(Args && "Args can't be null at this point");
+  T->end_event(Ctx, Name, std::move(*Args));
 }
 
 } // namespace trace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40488: [clangd] Implemented tracing using Context

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125690.
ilya-biryukov added a comment.
Herald added a subscriber: klimek.

- Updated tracing to use the new Context implementation.
- Restored global tracer.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40488

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Context.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
@@ -74,10 +75,11 @@
   std::string JSON;
   {
 raw_string_ostream OS(JSON);
-auto Session = trace::Session::create(OS);
+auto JSONTracer = trace::createJSONTracer(OS);
+trace::TracingSession Session(*JSONTracer);
 {
-  trace::Span S("A");
-  trace::log("B");
+  trace::Span S(emptyCtx(), "A");
+  trace::log(emptyCtx(), "B");
 }
   }
 
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -115,19 +115,25 @@
<< EC.message();
 }
   }
+
+  // Setup tracing facilities.
   llvm::Optional TraceStream;
-  std::unique_ptr TraceSession;
+  std::unique_ptr Tracer;
   if (!TraceFile.empty()) {
 std::error_code EC;
 TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
 if (EC) {
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
+  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
 }
   }
 
+  llvm::Optional TracingSession;
+  if (Tracer)
+TracingSession.emplace(*Tracer);
+
   llvm::raw_ostream  = llvm::outs();
   llvm::raw_ostream  = llvm::errs();
   JSONOutput Out(Outs, Logs,
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -8,60 +8,74 @@
 //===--===//
 //
 // Supports writing performance traces describing clangd's behavior.
-// Traces are written in the Trace Event format supported by chrome's trace
-// viewer (chrome://tracing).
+// Traces are consumed by implementations of the EventTracer interface.
 //
-// The format is documented here:
-// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
 //
 // All APIs are no-ops unless a Session is active (created by ClangdMain).
 //
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "Context.h"
 #include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace trace {
 
-// A session directs the output of trace events. Only one Session can exist.
-// It should be created before clangd threads are spawned, and destroyed after
-// they exit.
-// TODO: we may want to add pluggable support for other tracing backends.
-class Session {
+/// A consumer of trace events. The events are produced by Spans and trace::log.
+class EventTracer {
 public:
-  // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream ,
- bool Pretty = false);
-  ~Session();
+  virtual ~EventTracer() = default;
+  /// Consume a trace event.
+  virtual void event(const ContextData , llvm::StringRef Phase,
+ json::obj &) = 0;
+};
 
-private:
-  Session() = default;
+/// Sets up a global EventTracer that consumes events produced by Span and
+/// trace::log. Only one TracingSession can be active at a time and it should be
+/// set up before calling any clangd-specific functions.
+class TracingSession {
+public:
+  TracingSession(EventTracer );
+  ~TracingSession();
 };
 
-// Records a single instant event, associated with the current thread.
-void log(const llvm::Twine );
+/// Create an instance of EventTracer that produces an output in the Trace Event
+/// format supported by Chrome's trace viewer (chrome://tracing).
+///
+/// The format is documented here:
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+///
+/// The implementation supports concurrent calls and can be used as a global
+/// tracer (i.e., can be put into a global Context).
+std::unique_ptr createJSONTracer(llvm::raw_ostream ,
+  bool Pretty = false);
 
-// Records an event whose duration is the lifetime 

[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125814.
Nebiroth added a comment.

Fixed re-added include


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "TestFS.h"
@@ -620,7 +619,7 @@
 AddDocument(FileIndex);
 
   Position Pos{LineDist(RandGen), ColumnDist(RandGen)};
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  Server.findDefinitions(FilePaths[FileIndex], Pos);
 };
 
 std::vector> AsyncRequests = {
@@ -749,6 +748,58 @@
   EXPECT_FALSE(PathResult.hasValue());
 }
 
+TEST_F(ClangdVFSTest, CheckDefinitionIncludes) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+  #include "foo.h"
+  #include "invalid.h"
+  int b = a;
+  )cpp";
+  FS.Files[FooCpp] = SourceContents;
+  auto FooH = getVirtualTestFilePath("foo.h");
+  const auto HeaderContents = "int a;";
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = HeaderContents;
+
+  Server.addDocument(FooH, HeaderContents);
+  Server.addDocument(FooCpp, SourceContents);
+
+  Position P = Position{1, 11};
+
+  std::vector Locations = Server.findDefinitions(FooCpp, P).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+  std::string s("file:///");
+  std::string check = Locations[0].uri.uri;
+  check = check.erase(0, s.size());
+  check = check.substr(0, check.size() - 1);
+  ASSERT_EQ(check, FooH);
+  ASSERT_EQ(Locations[0].range.start.line, 0);
+  ASSERT_EQ(Locations[0].range.start.character, 0);
+  ASSERT_EQ(Locations[0].range.end.line, 0);
+  ASSERT_EQ(Locations[0].range.end.character, 0);
+
+  // Test ctrl-clicking on the #include part on the statement
+  Position P3 = Position{1, 3};
+
+  Locations = Server.findDefinitions(FooCpp, P3).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+
+  // Test invalid include
+  Position P2 = Position{2, 11};
+
+  Locations = Server.findDefinitions(FooCpp, P2).get().Value;
+  EXPECT_TRUE(Locations.empty());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -108,6 +108,14 @@
 bool fromJSON(const json::Expr &, Range &);
 json::Expr toJSON(const Range &);
 
+class RangeHash {
+public:
+  std::size_t operator()(const Range ) const {
+return ((R.start.line & 0x18) << 3) | ((R.start.character & 0x18) << 1) |
+   ((R.end.line & 0x18) >> 1) | ((R.end.character & 0x18) >> 3);
+  }
+};
+
 struct Location {
   /// The text document's URI.
   URI uri;
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 class raw_ostream;
@@ -59,6 +60,15 @@
   std::vector Diags;
 };
 
+class IncludeReferenceMap {
+  llvm::Optional findIncludeTargetAtLoc(Location Loc);
+
+public:
+  std::unordered_map IncludeLocationMap;
+  std::vector> DataVector;
+  std::vector RangeVector;
+};
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -69,7 +79,8 @@
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
-IntrusiveRefCntPtr VFS, clangd::Logger );
+IntrusiveRefCntPtr VFS, clangd::Logger ,
+IncludeReferenceMap IRM);
 
   ParsedAST(ParsedAST &);
   ParsedAST =(ParsedAST &);
@@ -89,12 +100,14 @@
 
   const std::vector () const;
 
+  IncludeReferenceMap takeIRM() { return IRM; };
+
 private:
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action,
 std::vector TopLevelDecls,
-std::vector Diags);
+std::vector Diags, IncludeReferenceMap IRM);
 
 private:
   void ensurePreambleDeclsDeserialized();
@@ -114,6 +127,8 @@
   std::vector Diags;
   std::vector TopLevelDecls;
   bool PreambleDeclsDeserialized;
+  std::vector PendingTopLevelDecls;
+  IncludeReferenceMap IRM;
 };
 
 // Provides thread-safe access to ParsedAST.
@@ -256,14 

[PATCH] D40398: Remove ValueDependent assertions on ICE checks.

2017-12-06 Thread Matt Davis via Phabricator via cfe-commits
mattd added a comment.

ping


https://reviews.llvm.org/D40398



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


[PATCH] D40818: [libcxxabi] Pass LIBCXXABI_SYSROOT and LIBCXXABI_GCC_TOOLCHAIN to lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D40818



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


r319983 - [clang] Add PRIVATE to target_link_libraries

2017-12-06 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Wed Dec  6 15:02:00 2017
New Revision: 319983

URL: http://llvm.org/viewvc/llvm-project?rev=319983=rev
Log:
[clang] Add PRIVATE to target_link_libraries

Another follow-up to r319840. I'd done a test configure with
LLVM_BUILD_STATIC, so I'm not sure why this didn't show up in that.

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

Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=319983=319982=319983=diff
==
--- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
+++ cfe/trunk/tools/c-index-test/CMakeLists.txt Wed Dec  6 15:02:00 2017
@@ -16,6 +16,7 @@ endif()
 
 if (LLVM_BUILD_STATIC)
   target_link_libraries(c-index-test
+PRIVATE
 libclang_static
 clangCodeGen
 clangIndex


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


[PATCH] D39375: [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125815.
Nebiroth added a comment.

Reverted formatting changes to ASTUnit


Repository:
  rC Clang

https://reviews.llvm.org/D39375

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -239,7 +239,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine , IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps, bool 
StoreInMemory,
-PreambleCallbacks ) {
+PreambleCallbacks , std::unique_ptr PPCallbacks) {
   assert(VFS && "VFS is null");
 
   if (!Bounds.Size)
@@ -351,6 +351,7 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  Clang->getPreprocessor().addPPCallbacks(std::move(PPCallbacks));
   Act->Execute();
 
   // Run the callbacks.
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1293,7 +1293,7 @@
 
 llvm::ErrorOr NewPreamble = 
PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
-PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
+PCHContainerOps, /*StoreInMemory=*/false, Callbacks, nullptr);
 if (NewPreamble) {
   Preamble = std::move(*NewPreamble);
   PreambleRebuildCounter = 1;
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -81,7 +81,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine , IntrusiveRefCntPtr 
VFS,
 std::shared_ptr PCHContainerOps,
-bool StoreInMemory, PreambleCallbacks );
+bool StoreInMemory, PreambleCallbacks , 
std::unique_ptr PPCallbacks);
 
   PrecompiledPreamble(PrecompiledPreamble &&) = default;
   PrecompiledPreamble =(PrecompiledPreamble &&) = default;


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -239,7 +239,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine , IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps, bool StoreInMemory,
-PreambleCallbacks ) {
+PreambleCallbacks , std::unique_ptr PPCallbacks) {
   assert(VFS && "VFS is null");
 
   if (!Bounds.Size)
@@ -351,6 +351,7 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  Clang->getPreprocessor().addPPCallbacks(std::move(PPCallbacks));
   Act->Execute();
 
   // Run the callbacks.
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1293,7 +1293,7 @@
 
 llvm::ErrorOr NewPreamble = PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
-PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
+PCHContainerOps, /*StoreInMemory=*/false, Callbacks, nullptr);
 if (NewPreamble) {
   Preamble = std::move(*NewPreamble);
   PreambleRebuildCounter = 1;
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -81,7 +81,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine , IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps,
-bool StoreInMemory, PreambleCallbacks );
+bool StoreInMemory, PreambleCallbacks , std::unique_ptr PPCallbacks);
 
   PrecompiledPreamble(PrecompiledPreamble &&) = default;
   PrecompiledPreamble =(PrecompiledPreamble &&) = default;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38110: [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.

2017-12-06 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.

LGTM if @sdardis is good with it


https://reviews.llvm.org/D38110



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


[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-06 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 125813.
Nebiroth added a comment.
Herald added a subscriber: klimek.

Using PPCallbacks interface to find non-preamble includes
Created inner class to store vectors in to find locations
Refactored methods to remove some unnecessary parameters
Refactored Unit tests
Merge with most recent master branch + clang


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/Protocol.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "TestFS.h"
@@ -620,7 +619,7 @@
 AddDocument(FileIndex);
 
   Position Pos{LineDist(RandGen), ColumnDist(RandGen)};
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  Server.findDefinitions(FilePaths[FileIndex], Pos);
 };
 
 std::vector> AsyncRequests = {
@@ -749,6 +748,58 @@
   EXPECT_FALSE(PathResult.hasValue());
 }
 
+TEST_F(ClangdVFSTest, CheckDefinitionIncludes) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+  #include "foo.h"
+  #include "invalid.h"
+  int b = a;
+  )cpp";
+  FS.Files[FooCpp] = SourceContents;
+  auto FooH = getVirtualTestFilePath("foo.h");
+  const auto HeaderContents = "int a;";
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = HeaderContents;
+
+  Server.addDocument(FooH, HeaderContents);
+  Server.addDocument(FooCpp, SourceContents);
+
+  Position P = Position{1, 11};
+
+  std::vector Locations = Server.findDefinitions(FooCpp, P).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+  std::string s("file:///");
+  std::string check = Locations[0].uri.uri;
+  check = check.erase(0, s.size());
+  check = check.substr(0, check.size() - 1);
+  ASSERT_EQ(check, FooH);
+  ASSERT_EQ(Locations[0].range.start.line, 0);
+  ASSERT_EQ(Locations[0].range.start.character, 0);
+  ASSERT_EQ(Locations[0].range.end.line, 0);
+  ASSERT_EQ(Locations[0].range.end.character, 0);
+
+  // Test ctrl-clicking on the #include part on the statement
+  Position P3 = Position{1, 3};
+
+  Locations = Server.findDefinitions(FooCpp, P3).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+
+  // Test invalid include
+  Position P2 = Position{2, 11};
+
+  Locations = Server.findDefinitions(FooCpp, P2).get().Value;
+  EXPECT_TRUE(Locations.empty());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -108,6 +108,14 @@
 bool fromJSON(const json::Expr &, Range &);
 json::Expr toJSON(const Range &);
 
+class RangeHash {
+public:
+  std::size_t operator()(const Range ) const {
+return ((R.start.line & 0x18) << 3) | ((R.start.character & 0x18) << 1) |
+   ((R.end.line & 0x18) >> 1) | ((R.end.character & 0x18) >> 3);
+  }
+};
+
 struct Location {
   /// The text document's URI.
   URI uri;
Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -9,6 +9,7 @@
 
 #include "GlobalCompilationDatabase.h"
 #include "Logger.h"
+#include "ProtocolHandlers.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 class raw_ostream;
@@ -59,6 +60,15 @@
   std::vector Diags;
 };
 
+class IncludeReferenceMap {
+  llvm::Optional findIncludeTargetAtLoc(Location Loc);
+
+public:
+  std::unordered_map IncludeLocationMap;
+  std::vector> DataVector;
+  std::vector RangeVector;
+};
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -69,7 +79,8 @@
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
-IntrusiveRefCntPtr VFS, clangd::Logger );
+IntrusiveRefCntPtr VFS, clangd::Logger ,
+IncludeReferenceMap 

[PATCH] D40637: [CMake] Support runtimes and monorepo layouts when looking for libc++

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D40637



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


[PATCH] D40815: [libcxxabi] Use the correct variable name for target triple in lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D40815



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


[PATCH] D40814: [libcxx] Use the correct variable name for target triple in lit

2017-12-06 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXX libc++

https://reviews.llvm.org/D40814



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


[PATCH] D33467: Fix LLVM build errors if necent build of GCC 7 is used

2017-12-06 Thread Guilherme Amadio via Phabricator via cfe-commits
amadio added a comment.

The problems fixed here also happen when compiling with Clang-5.0 and C++17 
enabled. What happens is that the assignment to `ProfileFileName` needs a 
conversion of `PGOTestProfileFile` from the `opt` type to `std::string`, but 
the compiler is trying to use a deleted constructor of `opt` instead:

  include/llvm/Support/CommandLine.h:1296:3: note: declared here
 opt(const opt &) = delete;

An alternative way of fixing this, which I have used in ROOT is to write 
`ProfileFileName = StringRef(PGOTestProfileFile);` to help the compiler 
understand what is going on.


Repository:
  rL LLVM

https://reviews.llvm.org/D33467



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


[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.
Herald added subscribers: kristof.beyls, javed.absar, aemerson.

  This is a follow up of r302131, in which we forgot to add SemaChecking
  tests. Adding these tests revealed two problems which have been fixed:
  - added missing intrinsic __qdbl,
  - properly range checking ssat16 and usat16.


https://reviews.llvm.org/D40888

Files:
  include/clang/Basic/BuiltinsARM.def
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins-arm.c

Index: test/Sema/builtins-arm.c
===
--- test/Sema/builtins-arm.c
+++ test/Sema/builtins-arm.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple armv7 -target-abi apcs-gnu \
 // RUN:   -fsyntax-only -verify %s
 
+#include 
+
 void f(void *a, void *b) {
   __clear_cache(); // expected-error {{too few arguments to function call, expected 2, have 0}} // expected-note {{'__clear_cache' is a builtin with type 'void (void *, void *)}}
   __clear_cache(a); // expected-error {{too few arguments to function call, expected 2, have 1}}
@@ -136,3 +138,185 @@
   __builtin_arm_mrrc2(15, a, 0); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}}
   __builtin_arm_mrrc2(15, 0, a); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}}
 }
+
+void test_9_3_multiplications(int a, int b) {
+  int r;
+  r = __builtin_arm_smulbb(a, b);
+  r = __builtin_arm_smulbb(1, -9);
+
+  r = __builtin_arm_smulbt(a, b);
+  r = __builtin_arm_smulbt(0, b);
+
+  r = __builtin_arm_smultb(a, b);
+  r = __builtin_arm_smultb(5, b);
+
+  r = __builtin_arm_smultt(a, b);
+  r = __builtin_arm_smultt(a, -1);
+
+  r = __builtin_arm_smulwb(a, b);
+  r = __builtin_arm_smulwb(1, 2);
+
+  r = __builtin_arm_smulwt(a, b);
+  r = __builtin_arm_smulwt(-1, -2);
+  r = __builtin_arm_smulwt(-1.0f, -2);
+}
+
+void test_9_4_1_width_specified_saturation(int a, int b) {
+  unsigned u;
+  int s;
+
+  s = __builtin_arm_ssat(8, 2);
+  s = __builtin_arm_ssat(a, 1);
+  s = __builtin_arm_ssat(a, 32);
+  s = __builtin_arm_ssat(a, 0);   // expected-error {{argument should be a value from 1 to 32}}
+  s = __builtin_arm_ssat(a, 33);  // expected-error {{argument should be a value from 1 to 32}}
+  s = __builtin_arm_ssat(a, b);   // expected-error {{argument to '__builtin_arm_ssat' must be a constant integer}}
+
+  u = __builtin_arm_usat(8, 2);
+  u = __builtin_arm_usat(a, 0);
+  u = __builtin_arm_usat(a, 31);
+  u = __builtin_arm_usat(a, 32);  // expected-error {{argument should be a value from 0 to 31}}
+  u = __builtin_arm_usat(a, b);   // expected-error {{argument to '__builtin_arm_usat' must be a constant integer}}
+}
+
+void test_9_4_2_saturating_addition_subtraction(int a, int b) {
+  int s;
+  s = __builtin_arm_qadd(a, b);
+  s = __builtin_arm_qadd(-1, 0);
+
+  s = __builtin_arm_qsub(a, b);
+  s = __builtin_arm_qsub(0, -1);
+
+  s = __builtin_arm_qdbl(a);
+}
+
+void test_9_4_3_accumulating_multiplications(int a, int b, int c) {
+  int s;
+
+  s = __builtin_arm_smlabb(a, b, c);
+  s = __builtin_arm_smlabb(1, b, c);
+  s = __builtin_arm_smlabb(a, 2, c);
+  s = __builtin_arm_smlabb(a, b, -3);
+
+  s = __builtin_arm_smlabt(a, b, c);
+  s = __builtin_arm_smlabt(1, b, c);
+  s = __builtin_arm_smlabt(a, 2, c);
+  s = __builtin_arm_smlabt(a, b, -3);
+
+  s = __builtin_arm_smlatb(a, b, c);
+  s = __builtin_arm_smlatt(1, b, c);
+  s = __builtin_arm_smlawb(a, 2, c);
+  s = __builtin_arm_smlawt(a, b, -3);
+}
+
+void test_9_5_4_parallel_16bit_saturation(int16x2_t a) {
+  unsigned u;
+  int s;
+
+  s = __builtin_arm_ssat16(a, 1);
+  s = __builtin_arm_ssat16(a, 16);
+  s = __builtin_arm_ssat16(a, 0);  // expected-error {{argument should be a value from 1 to 16}}
+  s = __builtin_arm_ssat16(a, 17); // expected-error {{argument should be a value from 1 to 16}}
+
+  u = __builtin_arm_usat16(a, 0);
+  u = __builtin_arm_usat16(a, 15);
+  u = __builtin_arm_usat16(a, 16); // expected-error {{argument should be a value from 0 to 15}}
+}
+
+void test_9_5_5_packing_and_unpacking(int16x2_t a, int8x4_t b, uint16x2_t c, uint8x4_t d) {
+  int16x2_t x;
+  uint16x2_t y;
+
+  x = __builtin_arm_sxtab16(a, b);
+  x = __builtin_arm_sxtab16(1, -1);
+  x = __builtin_arm_sxtb16(b);
+  x = __builtin_arm_sxtb16(-b);
+
+  y = __builtin_arm_uxtab16(c, d);
+  y = __builtin_arm_uxtab16(-1, -2);
+  y = __builtin_arm_uxtb16(d);
+  y = __builtin_arm_uxtb16(-1);
+}
+
+uint8x4_t
+test_9_5_6_parallel_selection(uint8x4_t a, uint8x4_t b) {
+  return __builtin_arm_sel(a, b);
+}
+
+void test_9_5_7_parallel_8bit_addition_substraction(int8x4_t a, int8x4_t b,
+uint8x4_t c, uint8x4_t d) {
+  int8x4_t s;
+  uint8x4_t u;
+
+  s = __builtin_arm_qadd8(a, b);
+  s = __builtin_arm_qsub8(a, b);
+  s = __builtin_arm_sadd8(a, b);
+  s = __builtin_arm_shadd8(a, b);
+  s = __builtin_arm_shsub8(a, b);
+  s = __builtin_arm_ssub8(a, b);
+
+  u = __builtin_arm_uadd8(c, d);
+  u = __builtin_arm_uhadd8(c, d);
+  u = 

[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125712.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Removed unused helpers from Context.h
- Use assert instead of llvm_unreachable in getExisiting(Key<>)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485

Files:
  clangd/CMakeLists.txt
  clangd/Context.cpp
  clangd/Context.h
  clangd/TypedValueMap.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/ContextTests.cpp

Index: unittests/clangd/ContextTests.cpp
===
--- /dev/null
+++ unittests/clangd/ContextTests.cpp
@@ -0,0 +1,71 @@
+//===-- ContextTests.cpp - Context tests *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Context.h"
+
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+TEST(TypedValueMapTests, Simple) {
+  Key IntParam;
+  Key ExtraIntParam;
+
+  clangd::TypedValueMap Ctx;
+
+  ASSERT_TRUE(Ctx.emplace(IntParam, 10));
+  ASSERT_TRUE(Ctx.emplace(ExtraIntParam, 20));
+
+  EXPECT_EQ(*Ctx.get(IntParam), 10);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+
+  ASSERT_FALSE(Ctx.emplace(IntParam, 30));
+
+  ASSERT_TRUE(Ctx.remove(IntParam));
+  EXPECT_EQ(Ctx.get(IntParam), nullptr);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+
+  ASSERT_TRUE(Ctx.emplace(IntParam, 30));
+  EXPECT_EQ(*Ctx.get(IntParam), 30);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+}
+
+TEST(TypedValueMapTests, MoveOps) {
+  Key Param;
+
+  clangd::TypedValueMap Ctx;
+  Ctx.emplace(Param, llvm::make_unique(10));
+  EXPECT_EQ(**Ctx.get(Param), 10);
+
+  clangd::TypedValueMap NewCtx = std::move(Ctx);
+  EXPECT_EQ(**NewCtx.get(Param), 10);
+}
+
+TEST(ContextTests, Builders) {
+  Key ParentParam;
+  Key ParentAndChildParam;
+  Key ChildParam;
+
+  Context ParentCtx =
+  buildCtx().add(ParentParam, 10).add(ParentAndChildParam, 20);
+  Context ChildCtx =
+  ParentCtx.derive().add(ParentAndChildParam, 30).add(ChildParam, 40);
+
+  EXPECT_EQ(*ParentCtx->get(ParentParam), 10);
+  EXPECT_EQ(*ParentCtx->get(ParentAndChildParam), 20);
+  EXPECT_EQ(ParentCtx->get(ChildParam), nullptr);
+
+  EXPECT_EQ(*ChildCtx->get(ParentParam), 10);
+  EXPECT_EQ(*ChildCtx->get(ParentAndChildParam), 30);
+  EXPECT_EQ(*ChildCtx->get(ChildParam), 40);
+}
+
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -11,6 +11,7 @@
 add_extra_unittest(ClangdTests
   ClangdTests.cpp
   CodeCompleteTests.cpp
+  ContextTests.cpp
   FuzzyMatchTests.cpp
   JSONExprTests.cpp
   TestFS.cpp
Index: clangd/TypedValueMap.h
===
--- /dev/null
+++ clangd/TypedValueMap.h
@@ -0,0 +1,95 @@
+//===--- TypedValueMap.h - Type-safe heterogenous key-value map -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Type-safe heterogenous map.
+//
+//===--===//
+
+#include "llvm/ADT/DenseMap.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// Used as identity for map values. Non-movable and non-copyable. Address of
+/// this object is used internally to as keys in a map.
+template  class Key {
+public:
+  static_assert(!std::is_reference::value,
+"Reference arguments to Key<> are not allowed");
+
+  Key() = default;
+
+  Key(Key const &) = delete;
+  Key =(Key const &) = delete;
+  Key(Key &&) = delete;
+  Key =(Key &&) = delete;
+};
+
+/// A type-safe map from Key to T.
+class TypedValueMap {
+public:
+  TypedValueMap() = default;
+  TypedValueMap(const TypedValueMap &) = delete;
+  TypedValueMap(TypedValueMap &&) = default;
+
+  template  Type *get(Key ) const {
+auto It = Map.find();
+if (It == Map.end())
+  return nullptr;
+return static_cast(It->second->getValuePtr());
+  }
+
+  template 
+  bool emplace(Key , Args &&... As) {
+bool Added =
+Map.try_emplace(,
+llvm::make_unique<
+TypedAnyStorage::type>>(
+std::forward(As)...))
+.second;
+return Added;
+  }
+
+  template  bool remove(Key ) {
+auto It = Map.find();
+if (It == Map.end())
+  return false;
+
+Map.erase(It);
+return true;
+  }
+
+private:
+  class AnyStorage {
+  public:
+virtual ~AnyStorage() = default;
+

[PATCH] D40488: [clangd] Implemented tracing using Context

2017-12-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 125713.
ilya-biryukov added a comment.

- Use getExistingKey instead of getPtr in JSONRPCDispatcher.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40488

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Context.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
@@ -74,10 +75,11 @@
   std::string JSON;
   {
 raw_string_ostream OS(JSON);
-auto Session = trace::Session::create(OS);
+auto JSONTracer = trace::createJSONTracer(OS);
+trace::TracingSession Session(*JSONTracer);
 {
-  trace::Span S("A");
-  trace::log("B");
+  trace::Span S(emptyCtx(), "A");
+  trace::log(emptyCtx(), "B");
 }
   }
 
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -115,19 +115,25 @@
<< EC.message();
 }
   }
+
+  // Setup tracing facilities.
   llvm::Optional TraceStream;
-  std::unique_ptr TraceSession;
+  std::unique_ptr Tracer;
   if (!TraceFile.empty()) {
 std::error_code EC;
 TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
 if (EC) {
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
+  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
 }
   }
 
+  llvm::Optional TracingSession;
+  if (Tracer)
+TracingSession.emplace(*Tracer);
+
   llvm::raw_ostream  = llvm::outs();
   llvm::raw_ostream  = llvm::errs();
   JSONOutput Out(Outs, Logs,
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -8,60 +8,74 @@
 //===--===//
 //
 // Supports writing performance traces describing clangd's behavior.
-// Traces are written in the Trace Event format supported by chrome's trace
-// viewer (chrome://tracing).
+// Traces are consumed by implementations of the EventTracer interface.
 //
-// The format is documented here:
-// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
 //
 // All APIs are no-ops unless a Session is active (created by ClangdMain).
 //
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "Context.h"
 #include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace trace {
 
-// A session directs the output of trace events. Only one Session can exist.
-// It should be created before clangd threads are spawned, and destroyed after
-// they exit.
-// TODO: we may want to add pluggable support for other tracing backends.
-class Session {
+/// A consumer of trace events. The events are produced by Spans and trace::log.
+class EventTracer {
 public:
-  // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream ,
- bool Pretty = false);
-  ~Session();
+  virtual ~EventTracer() = default;
+  /// Consume a trace event.
+  virtual void event(const ContextData , llvm::StringRef Phase,
+ json::obj &) = 0;
+};
 
-private:
-  Session() = default;
+/// Sets up a global EventTracer that consumes events produced by Span and
+/// trace::log. Only one TracingSession can be active at a time and it should be
+/// set up before calling any clangd-specific functions.
+class TracingSession {
+public:
+  TracingSession(EventTracer );
+  ~TracingSession();
 };
 
-// Records a single instant event, associated with the current thread.
-void log(const llvm::Twine );
+/// Create an instance of EventTracer that produces an output in the Trace Event
+/// format supported by Chrome's trace viewer (chrome://tracing).
+///
+/// The format is documented here:
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+///
+/// The implementation supports concurrent calls and can be used as a global
+/// tracer (i.e., can be put into a global Context).
+std::unique_ptr createJSONTracer(llvm::raw_ostream ,
+  bool Pretty = false);
 
-// Records an event whose duration is the lifetime of the Span object.
-//
-// Arbitrary JSON metadata can 

[PATCH] D40888: [ARM] ACLE parallel arithmetic and DSP style multiplications

2017-12-06 Thread Sam Parker via Phabricator via cfe-commits
samparker added a comment.

Thanks for looking into this!




Comment at: include/clang/Basic/BuiltinsARM.def:39
 BUILTIN(__builtin_arm_qsub, "iii", "nc")
+BUILTIN(__builtin_arm_qdbl, "ii", "nc")
 BUILTIN(__builtin_arm_ssat, "iiUi", "nc")

Do we now need a codegen tests for this one?



Comment at: test/Sema/builtins-arm.c:161
+  r = __builtin_arm_smulwt(-1, -2);
+  r = __builtin_arm_smulwt(-1.0f, -2);
+}

Interesting that this doesn't give an error?



Comment at: test/Sema/builtins-arm.c:236
+  y = __builtin_arm_uxtab16(c, d);
+  y = __builtin_arm_uxtab16(-1, -2);
+  y = __builtin_arm_uxtb16(d);

Can / should we warn the user when using signed arguments? Looks like I missed 
the unsigned qualifiers in the original patch.


https://reviews.llvm.org/D40888



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


[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2017-12-06 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

In https://reviews.llvm.org/D20124#943592, @cameron314 wrote:

> Here's the final patch that fixes `clang_getSkippedRegions` with regions in 
> the preamble (as well as serializing the skipped regions in the PCH file).


Works fine for me, thanks! Test from the bug report is fixed by this one.

You should probably add "Fixes PR34971." to the summary.

@erikjv @ilya-biryukov - please review as you know the details here :)


https://reviews.llvm.org/D20124



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


r319986 - [Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2017-12-06 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Dec  6 15:18:41 2017
New Revision: 319986

URL: http://llvm.org/viewvc/llvm-project?rev=319986=rev
Log:
[Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other 
minor fixes (NFC).

Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=319986=319985=319986=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Dec  6 15:18:41 2017
@@ -1,4 +1,4 @@
-//===--- HeaderSearch.h - Resolve Header File Locations -*- C++ 
-*-===//
+//===- HeaderSearch.h - Resolve Header File Locations ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -14,25 +14,37 @@
 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
 #define LLVM_CLANG_LEX_HEADERSEARCH_H
 
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
 
 namespace clang {
-  
-class DiagnosticsEngine;  
+
+class DiagnosticsEngine;
+class DirectoryEntry;
 class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
+class HeaderMap;
 class HeaderSearchOptions;
 class IdentifierInfo;
+class LangOptions;
+class Module;
 class Preprocessor;
+class TargetInfo;
 
 /// \brief The preprocessor keeps track of this information for each
 /// file that is \#included.
@@ -76,14 +88,14 @@ struct HeaderFileInfo {
   unsigned IsValid : 1;
   
   /// \brief The number of times the file has been included already.
-  unsigned short NumIncludes;
+  unsigned short NumIncludes = 0;
 
   /// \brief The ID number of the controlling macro.
   ///
   /// This ID number will be non-zero when there is a controlling
   /// macro whose IdentifierInfo may not yet have been loaded from
   /// external storage.
-  unsigned ControllingMacroID;
+  unsigned ControllingMacroID = 0;
 
   /// If this file has a \#ifndef XXX (or equivalent) guard that
   /// protects the entire contents of the file, this is the identifier
@@ -93,17 +105,16 @@ struct HeaderFileInfo {
   /// the controlling macro of this header, since
   /// getControllingMacro() is able to load a controlling macro from
   /// external storage.
-  const IdentifierInfo *ControllingMacro;
+  const IdentifierInfo *ControllingMacro = nullptr;
 
   /// \brief If this header came from a framework include, this is the name
   /// of the framework.
   StringRef Framework;
   
   HeaderFileInfo()
-: isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), 
-  External(false), isModuleHeader(false), isCompilingModuleHeader(false),
-  Resolved(false), IndexHeaderMapHeader(false), IsValid(0),
-  NumIncludes(0), ControllingMacroID(0), ControllingMacro(nullptr)  {}
+  : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), 
+External(false), isModuleHeader(false), isCompilingModuleHeader(false),
+Resolved(false), IndexHeaderMapHeader(false), IsValid(false)  {}
 
   /// \brief Retrieve the controlling macro for this header file, if
   /// any.
@@ -135,6 +146,8 @@ public:
 /// \brief Encapsulates the information needed to find the file referenced
 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
 class HeaderSearch {
+  friend class DirectoryLookup;
+
   /// This structure is used to record entries in our framework cache.
   struct FrameworkCacheEntry {
 /// The directory entry which should be used for the cached framework.
@@ -151,6 +164,7 @@ class HeaderSearch {
 
   DiagnosticsEngine 
   FileManager 
+
   /// \#include search path information.  Requests for \#include "x" search the
   /// directory of the \#including file first, then each directory in 
SearchDirs
   /// consecutively. Requests for  search the current dir first, then each
@@ -158,9 +172,9 @@ class HeaderSearch {
   /// NoCurDirSearch is true, then the check for the file in the current
   /// directory is suppressed.
   std::vector SearchDirs;
-  unsigned AngledDirIdx;
-  unsigned SystemDirIdx;
-  bool NoCurDirSearch;
+  unsigned AngledDirIdx = 0;
+  unsigned SystemDirIdx = 0;
+  bool NoCurDirSearch = false;
 
   /// \brief \#include prefixes for which 

[PATCH] D40380: Remove old concepts parsing code

2017-12-06 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC319992: Remove old concepts parsing code (authored by 
hubert.reinterpretcast).

Changed prior to commit:
  https://reviews.llvm.org/D40380?vs=124032=125844#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40380

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaTemplate.cpp
  test/CXX/concepts-ts/dcl.dcl/lit.cfg.py
  test/Parser/cxx-concept-declaration.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3464,11 +3464,6 @@
   isInvalid = DS.SetConstexprSpec(Loc, PrevSpec, DiagID);
   break;
 
-// concept
-case tok::kw_concept:
-  isInvalid = DS.SetConceptSpec(Loc, PrevSpec, DiagID);
-  break;
-
 // type-specifier
 case tok::kw_short:
   isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec,
@@ -4825,9 +4820,6 @@
   case tok::annot_decltype:
   case tok::kw_constexpr:
 
-// C++ Concepts TS - concept
-  case tok::kw_concept:
-
 // C11 _Atomic
   case tok::kw__Atomic:
 return true;
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1299,11 +1299,9 @@
 //   'friend'
 //   'typedef'
 //   'constexpr'
-//   'concept'
   case tok::kw_friend:
   case tok::kw_typedef:
   case tok::kw_constexpr:
-  case tok::kw_concept:
 // storage-class-specifier
   case tok::kw_register:
   case tok::kw_static:
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -8342,8 +8342,7 @@
   // We leave 'friend' and 'virtual' to be rejected in the normal way.
   if (DS.hasTypeSpecifier() || DS.getTypeQualifiers() ||
   DS.getStorageClassSpecLoc().isValid() || DS.isInlineSpecified() ||
-  DS.isNoreturnSpecified() || DS.isConstexprSpecified() ||
-  DS.isConceptSpecified()) {
+  DS.isNoreturnSpecified() || DS.isConstexprSpecified()) {
 BadSpecifierDiagnoser Diagnoser(
 *this, D.getIdentifierLoc(),
 diag::err_deduction_guide_invalid_specifier);
@@ -8356,9 +8355,7 @@
 Diagnoser.check(DS.getInlineSpecLoc(), "inline");
 Diagnoser.check(DS.getNoreturnSpecLoc(), "_Noreturn");
 Diagnoser.check(DS.getConstexprSpecLoc(), "constexpr");
-Diagnoser.check(DS.getConceptSpecLoc(), "concept");
 DS.ClearConstexprSpec();
-DS.ClearConceptSpec();
 
 Diagnoser.check(DS.getConstSpecLoc(), "const");
 Diagnoser.check(DS.getRestrictSpecLoc(), "__restrict");
Index: lib/Sema/DeclSpec.cpp
===
--- lib/Sema/DeclSpec.cpp
+++ lib/Sema/DeclSpec.cpp
@@ -969,18 +969,6 @@
   return false;
 }
 
-bool DeclSpec::SetConceptSpec(SourceLocation Loc, const char *,
-  unsigned ) {
-  if (Concept_specified) {
-DiagID = diag::ext_duplicate_declspec;
-PrevSpec = "concept";
-return true;
-  }
-  Concept_specified = true;
-  ConceptLoc = Loc;
-  return false;
-}
-
 void DeclSpec::SaveWrittenBuiltinSpecs() {
   writtenBS.Sign = getTypeSpecSign();
   writtenBS.Width = getTypeSpecWidth();
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -8037,15 +8037,6 @@
   // Ignore access information;  it doesn't figure into redeclaration checking.
   FunctionDecl *Specialization = cast(*Result);
 
-  // C++ Concepts TS [dcl.spec.concept]p7: A program shall not declare [...]
-  // an explicit specialization (14.8.3) [...] of a concept definition.
-  if (Specialization->getPrimaryTemplate()->isConcept()) {
-Diag(FD->getLocation(), diag::err_concept_specialized)
-<< 0 /*function*/ << 1 /*explicitly specialized*/;
-Diag(Specialization->getLocation(), diag::note_previous_declaration);
-return true;
-  }
-
   FunctionTemplateSpecializationInfo *SpecInfo
 = Specialization->getTemplateSpecializationInfo();
   assert(SpecInfo && "Function template specialization info missing?");
@@ -8932,15 +8923,6 @@
 Diag(D.getDeclSpec().getConstexprSpecLoc(),
  diag::err_explicit_instantiation_constexpr);
 
-  // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
-  // applied only to the definition of a function template or variable template,
-  // declared in namespace scope.
-  if (D.getDeclSpec().isConceptSpecified()) {
-Diag(D.getDeclSpec().getConceptSpecLoc(),
- diag::err_concept_specified_specialization) << 0;
-return true;
-  }
-
   // A deduction guide is not on the list of entities 

r319992 - Remove old concepts parsing code

2017-12-06 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Wed Dec  6 16:34:20 2017
New Revision: 319992

URL: http://llvm.org/viewvc/llvm-project?rev=319992=rev
Log:
Remove old concepts parsing code

Summary:
This is so we can implement concepts per P0734R0. Relevant failing test
cases are disabled.

Reviewers: hubert.reinterpretcast, rsmith, saar.raz, nwilson

Reviewed By: saar.raz

Subscribers: cfe-commits

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

Patch by Changyu Li!

Added:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py
Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/Parser/cxx-concept-declaration.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=319992=319991=319992=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Wed Dec  6 16:34:20 2017
@@ -405,7 +405,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -418,7 +418,7 @@ protected:
   TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params, NamedDecl *Decl)
-  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl, false),
+  : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl),
 TemplateParams(CTDI) {
 this->setTemplateParameters(Params);
   }
@@ -450,7 +450,7 @@ public:
   }
 
   /// Get the underlying, templated declaration.
-  NamedDecl *getTemplatedDecl() const { return TemplatedDecl.getPointer(); }
+  NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -461,21 +461,11 @@ public:
 
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   TemplatedDecl.getPointer()->getSourceRange().getEnd());
+   TemplatedDecl->getSourceRange().getEnd());
   }
 
-  /// Whether this is a (C++ Concepts TS) function or variable concept.
-  bool isConcept() const { return TemplatedDecl.getInt(); }
-  void setConcept() { TemplatedDecl.setInt(true); }
-
 protected:
-  /// \brief The named declaration from which this template was instantiated.
-  /// (or null).
-  ///
-  /// The boolean value will be true to indicate that this template
-  /// (function or variable) is a concept.
-  llvm::PointerIntPair TemplatedDecl;
-
+  NamedDecl *TemplatedDecl;
   /// \brief The template parameter list and optional requires-clause
   /// associated with this declaration; alternatively, a
   /// \c ConstrainedTemplateDeclInfo if the associated constraints of the
@@ -504,9 +494,9 @@ public:
   /// \brief Initialize the underlying templated declaration and
   /// template parameters.
   void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) {
-assert(!TemplatedDecl.getPointer() && "TemplatedDecl already set!");
+assert(!TemplatedDecl && "TemplatedDecl already set!");
 assert(!TemplateParams && "TemplateParams already set!");
-TemplatedDecl.setPointer(templatedDecl);
+TemplatedDecl = templatedDecl;
 TemplateParams = templateParams;
   }
 };
@@ -1028,7 +1018,7 @@ public:
 
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// Returns whether this template declaration defines the primary
@@ -2120,7 +2110,7 @@ public:
 
   /// \brief Get the underlying class declarations of the template.
   CXXRecordDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
   /// \brief Returns whether this template declaration defines the primary
@@ -2367,7 +2357,7 @@ public:
 
   /// Get the underlying function declaration of the template.
   TypeAliasDecl *getTemplatedDecl() const {
-return static_cast(TemplatedDecl.getPointer());
+return static_cast(TemplatedDecl);
   }
 
 
@@ -2934,7 +2924,7 @@ public:
 
   /// \brief Get the underlying variable declarations of the 

  1   2   >