[PATCH] D70440: [Driver] Use VFS to check if sanitizer blacklists exist

2019-11-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Do we need to add a dep on Frontend to DriverTests here? That's a heavy 
dependency (it pulls in Sema etc). If it is needed, maybe the test is in the 
wrong binary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70440



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


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 230601.
awpandey marked 3 inline comments as done.
awpandey added a comment.

This revision includes

1. Added check for return type it is attached to the exact node we're expecting 
it to.
2. Removed unnecessary strings and checks.


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

https://reviews.llvm.org/D70524

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-auto-return.cpp
  llvm/test/DebugInfo/X86/debug-info-auto-return.ll

Index: llvm/test/DebugInfo/X86/debug-info-auto-return.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-auto-return.ll
@@ -0,0 +1,171 @@
+;RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+
+; C++ source to regenerate:
+
+;class myClass {
+;int low, high;
+;
+;  public:
+;  myClass(int a, int b) {
+;low = a;
+;high = b;
+;  }
+;auto findMax();
+;};
+;
+;auto myClass::findMax() {
+;if (low > high)
+;return 1;
+;  else
+;return 1;
+;}
+;int main() {
+;myClass f(3, 5);
+;  return 0;
+;}
+
+; CHECK: .debug_info contents:
+
+; CHECK:  DW_TAG_subprogram [7] *
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (0007) string = "_ZN7myClass7findMaxEv")
+; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} "auto"
+; CHECK-NEXT: DW_AT_declaration {{.*}} (true)
+
+; CHECK: DW_TAG_unspecified_type
+; CHECK-NEXT:  DW_AT_name [DW_FORM_strx1] {{.*}} "auto"
+
+; ModuleID = 'debug-info-auto-return.cpp'
+source_filename = "debug-info-auto-return.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%class.myClass = type { i32, i32 }
+
+$_ZN7myClassC2Eii = comdat any
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @_ZN7myClass7findMaxEv(%class.myClass* %this) #0 align 2 !dbg !7 {
+entry:
+  %retval = alloca i32, align 4
+  %this.addr = alloca %class.myClass*, align 8
+  store %class.myClass* %this, %class.myClass** %this.addr, align 8
+  call void @llvm.dbg.declare(metadata %class.myClass** %this.addr, metadata !22, metadata !DIExpression()), !dbg !24
+  %this1 = load %class.myClass*, %class.myClass** %this.addr, align 8
+  %low = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 0, !dbg !25
+  %0 = load i32, i32* %low, align 4, !dbg !25
+  %high = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 1, !dbg !27
+  %1 = load i32, i32* %high, align 4, !dbg !27
+  %cmp = icmp sgt i32 %0, %1, !dbg !28
+  br i1 %cmp, label %if.then, label %if.else, !dbg !29
+
+if.then:  ; preds = %entry
+  store i32 1, i32* %retval, align 4, !dbg !30
+  br label %return, !dbg !30
+
+if.else:  ; preds = %entry
+  store i32 1, i32* %retval, align 4, !dbg !31
+  br label %return, !dbg !31
+
+return:   ; preds = %if.else, %if.then
+  %2 = load i32, i32* %retval, align 4, !dbg !32
+  ret i32 %2, !dbg !32
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline norecurse optnone uwtable
+define dso_local i32 @main() #2 !dbg !33 {
+entry:
+  %retval = alloca i32, align 4
+  %f = alloca %class.myClass, align 4
+  store i32 0, i32* %retval, align 4
+  call void @llvm.dbg.declare(metadata %class.myClass* %f, metadata !36, metadata !DIExpression()), !dbg !37
+  call void @_ZN7myClassC2Eii(%class.myClass* %f, i32 3, i32 5), !dbg !37
+  ret i32 0, !dbg !38
+}
+
+; Function Attrs: noinline nounwind optnone uwtable
+define linkonce_odr dso_local void @_ZN7myClassC2Eii(%class.myClass* %this, i32 %a, i32 %b) unnamed_addr #0 comdat align 2 !dbg !39 {
+entry:
+  %this.addr = alloca %class.myClass*, align 8
+  %a.addr = alloca i32, align 4
+  %b.addr = alloca i32, align 4
+  store %class.myClass* %this, %class.myClass** %this.addr, align 8
+  call void @llvm.dbg.declare(metadata %class.myClass** %this.addr, metadata !40, metadata !DIExpression()), !dbg !41
+  store i32 %a, i32* %a.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !42, metadata !DIExpression()), !dbg !43
+  store i32 %b, i32* %b.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !44, metadata !DIExpression()), !dbg !45
+  %this1 = load %class.myClass*, %class.myClass** %this.addr, align 8
+  %0 = load i32, i32* %a.addr, align 4, !dbg !46
+  %low = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 0, !dbg !48
+  store i32 %0, i32* %low, align 4, !dbg !49
+  %1 = load i32, i32* %b.addr, align 4, !dbg !50
+  %high = getelementptr inbounds %class.myClass, %class.myClass* %this1, i32 0, i32 1, !dbg !51
+  st

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey marked 2 inline comments as done.
awpandey added a comment.

Thanks @aprantl  for your suggestions. I have revised by patch based on that.


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

https://reviews.llvm.org/D70524



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


[PATCH] D70588: Don't report "main" as missing a prototype in freestanding mode

2019-11-22 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added a reviewer: efriedma.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A user may want to use freestanding mode with the standard "main" entry
point. It's not useful to warn about a missing prototype as it's not
typical to have a prototype for "main".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70588

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/no-warn-missing-prototype.c


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- /dev/null
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes-x c -ffreestanding 
-verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding 
-verify %s
+// expected-no-diagnostics
+int main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@
 return false;
 
   // Don't warn about 'main'.
-  if (FD->isMain())
-return false;
+  if (isa(FD->getDeclContext()->getRedeclContext()))
+if (IdentifierInfo *II = FD->getIdentifier())
+  if (II->isStr("main"))
+return false;
 
   // Don't warn about inline functions.
   if (FD->isInlined())


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- /dev/null
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes-x c -ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding -verify %s
+// expected-no-diagnostics
+int main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@
 return false;
 
   // Don't warn about 'main'.
-  if (FD->isMain())
-return false;
+  if (isa(FD->getDeclContext()->getRedeclContext()))
+if (IdentifierInfo *II = FD->getIdentifier())
+  if (II->isStr("main"))
+return false;
 
   // Don't warn about inline functions.
   if (FD->isInlined())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70445: [clangd] Show lambda signature for lambda autocompletions

2019-11-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Great, thanks for fixing this!




Comment at: clang/test/CodeCompletion/lambdas.cpp:66
+  auto my_lambda = [&](int a, double &b) { return 1.f; };
+  my_
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:66:5 %s -o - | 
FileCheck -check-prefix=CHECK-9 %s

nit: often preferable to make the examples valid syntax (and set code 
completion point to interrupt it, to avoid different tests interfering with 
each other.

(Here the my_ prefix isn't needed - plain completion on an empty line will 
yield the result you want)



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

https://reviews.llvm.org/D70445



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


[PATCH] D67149: Fix argument order for BugType instation for

2019-11-22 Thread Henry Wong via Phabricator via cfe-commits
MTC added a comment.

Good catch, the fix is reasonable to me. However, I'm no longer wok on the 
analyzer now, maybe you can add @NoQ  Or some other active reviewers to review 
the code.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67149



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


[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

2019-11-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60231 tests passed, 0 failed and 732 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70569



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


[PATCH] D70445: [clangd] Show lambda signature for lambda autocompletions

2019-11-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 230619.
kbobyrev added a comment.

Get rid of incomplete identifiers in test code.


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

https://reviews.llvm.org/D70445

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/function-templates.cpp
  clang/test/CodeCompletion/lambdas.cpp

Index: clang/test/CodeCompletion/lambdas.cpp
===
--- clang/test/CodeCompletion/lambdas.cpp
+++ clang/test/CodeCompletion/lambdas.cpp
@@ -60,3 +60,15 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:57:24 %s -o - | FileCheck -check-prefix=CHECK-8 %s
   // CHECK-8-NOT: COMPLETION: Pattern : [<#=
 }
+
+void test6() {
+  auto my_lambda = [&](int a, double &b) { return 1.f; };
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:65:58 %s -o - | FileCheck -check-prefix=CHECK-9 %s
+  // CHECK-9: [#float#]my_lambda(<#int a#>, <#double &b#>)[# const#]
+}
+
+void test7() {
+  auto generic_lambda = [&](auto a, const auto &b) { return a + b; };
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:71:70 %s -o - | FileCheck -check-prefix=CHECK-10 %s
+  // CHECK-10: [#auto#]generic_lambda(<#auto a#>, <#const auto &b#>)[# const#]
+}
Index: clang/test/CodeCompletion/function-templates.cpp
===
--- clang/test/CodeCompletion/function-templates.cpp
+++ clang/test/CodeCompletion/function-templates.cpp
@@ -1,7 +1,7 @@
 namespace std {
   template
   void sort(RandomAccessIterator first, RandomAccessIterator last);
-  
+
   template
   X* dyn_cast(Y *Val);
 }
@@ -11,13 +11,17 @@
   template T &getAs();
 };
 
+template 
+V doSomething(T t, const U &u, V *v) { return V(); }
+
 void f() {
   std::sort(1, 2);
   Foo().getAs();
-  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:15:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:18:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
   // CHECK-CC1: dyn_cast<<#class X#>>(<#Y *Val#>)
   // CHECK-CC1: sort(<#RandomAccessIterator first#>, <#RandomAccessIterator last#>
-  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:16:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2: getAs<<#typename T#>>()
-)
-  
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: [#V#]doSomething(<#T t#>, <#const U &u#>, <#V *v#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3315,6 +3315,18 @@
   return Result.TakeString();
 }
 
+// FIXME: Right now this works well with lambdas. Add support for other functor
+// types like std::function.
+static const NamedDecl *extractFunctorCallOperator(const NamedDecl *ND) {
+  const auto *VD = dyn_cast(ND);
+  if (!VD)
+return nullptr;
+  const auto *RecordDecl = VD->getType()->getAsCXXRecordDecl();
+  if (!RecordDecl || !RecordDecl->isLambda())
+return nullptr;
+  return RecordDecl->getLambdaCallOperator();
+}
+
 CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
 Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
 bool IncludeBriefComments, const CodeCompletionContext &CCContext,
@@ -3339,9 +3351,8 @@
   for (const auto *I : ND->specific_attrs())
 Result.AddAnnotation(Result.getAllocator().CopyString(I->getAnnotation()));
 
-  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
-
-  if (const auto *Function = dyn_cast(ND)) {
+  auto AddFunctionTypeAndResult = [&](const FunctionDecl *Function) {
+AddResultTypeChunk(Ctx, Policy, Function, CCContext.getBaseType(), Result);
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
Ctx, Policy);
 AddTypedNameChunk(Ctx, Policy, ND, Result);
@@ -3349,9 +3360,21 @@
 AddFunctionParameterChunks(PP, Policy, Function, Result);
 Result.AddChunk(CodeCompletionString::CK_RightParen);
 AddFunctionTypeQualsToCompletionString(Result, Function);
+  };
+
+  if (const auto *Function = dyn_cast(ND)) {
+AddFunctionTypeAndResult(Function);
+return Result.TakeString();
+  }
+
+  if (const auto *CallOperator =
+  dyn_cast_or_null(extractFunctorCallOperator(ND))) {
+AddFunctionTypeAndResult(CallOperator);
 return Result.TakeString();
   }
 
+  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
+
   if (const FunctionTemplateDecl *FunTmpl =
   dyn_cast(ND)) {
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
@@ -3417,6 +3440,7 @@
 Resu

[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:95
 
+// Constructs an expression that idiomatically represents a value, taking into
+// account whether `ExprId` is a pointer or already a value.

Three slashes, please.



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:96
+// Constructs an expression that idiomatically represents a value, taking into
+// account whether `ExprId` is a pointer or already a value.
+Stencil asValue(llvm::StringRef ExprId);

Need more explanation to cover the cases when the expression is a pointer to a 
pointer (do we deref once or twice?), or a smart pointer (do we take care of 
that at all?)

WDYT about calling it `maybeDeref()` or `derefIfPointer()`?



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:99
+
+// Constructs an expression that idiomatically represents a pointer, taking 
into
+// account whether `ExprId` is a value or already a pointer.

Three slashes, please.



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:101
+// account whether `ExprId` is a value or already a pointer.
+Stencil asPointer(llvm::StringRef ExprId);
+

Similarly, `maybeAddressOf()`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554



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


[PATCH] D68388: [PR41008][OpenCL] Add OpenCL C compatibility mode to C++ for OpenCL

2019-11-22 Thread Kévin Petit via Phabricator via cfe-commits
kpet updated this revision to Diff 230620.
kpet retitled this revision from "[PR41008][OpenCL] Support restrict keyword in 
C++ mode" to "[PR41008][OpenCL] Add OpenCL C compatibility mode to C++ for  
OpenCL".
kpet edited the summary of this revision.
kpet added a comment.

As discussed offline, let's only enable `restrict` under a compatibility flag. 
PTAL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68388

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenOpenCLCXX/compat-clc-kernel-arg-info.cl

Index: clang/test/CodeGenOpenCLCXX/compat-clc-kernel-arg-info.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/compat-clc-kernel-arg-info.cl
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 %s -cl-std=clc++ -clcxx-clc-compatibility -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++ -clcxx-clc-compatibility -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
+
+kernel void foo(global int * globalintp, global int * restrict globalintrestrictp,
+global const int * globalconstintp,
+global const int * restrict globalconstintrestrictp,
+constant int * constantintp, constant int * restrict constantintrestrictp,
+global const volatile int * globalconstvolatileintp,
+global const volatile int * restrict globalconstvolatileintrestrictp,
+global volatile int * globalvolatileintp,
+global volatile int * restrict globalvolatileintrestrictp,
+local int * localintp, local int * restrict localintrestrictp,
+local const int * localconstintp,
+local const int * restrict localconstintrestrictp,
+local const volatile int * localconstvolatileintp,
+local const volatile int * restrict localconstvolatileintrestrictp,
+local volatile int * localvolatileintp,
+local volatile int * restrict localvolatileintrestrictp,
+int X, const int constint, const volatile int constvolatileint,
+volatile int volatileint) {
+  *globalintrestrictp = constint + volatileint;
+}
+// CHECK: define spir_kernel void @foo{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[MD11:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD12:[0-9]+]]
+// CHECK: !kernel_arg_type ![[MD13:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD13]]
+// CHECK: !kernel_arg_type_qual ![[MD14:[0-9]+]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[MD15:[0-9]+]]
+
+kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3, read_write image1d_t img4) {
+}
+// CHECK: define spir_kernel void @foo2{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[MD21:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD22:[0-9]+]]
+// CHECK: !kernel_arg_type ![[MD23:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD23]]
+// CHECK: !kernel_arg_type_qual ![[MD24:[0-9]+]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[MD25:[0-9]+]]
+
+kernel void foo3(__global half * X) {
+}
+// CHECK: define spir_kernel void @foo3{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[MD31:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD32:[0-9]+]]
+// CHECK: !kernel_arg_type ![[MD33:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD33]]
+// CHECK: !kernel_arg_type_qual ![[MD34:[0-9]+]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[MD35:[0-9]+]]
+
+typedef unsigned int myunsignedint;
+kernel void foo4(__global unsigned int * X, __global myunsignedint * Y) {
+}
+// CHECK: define spir_kernel void @foo4{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD42:[0-9]+]]
+// CHECK: !kernel_arg_type ![[MD43:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD44:[0-9]+]]
+// CHECK: !kernel_arg_type_qual ![[MD45:[0-9]+]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]]
+
+typedef image1d_t myImage;
+kernel void foo5(myImage img1, write_only image1d_t img2) {
+}
+// CHECK: define spir_kernel void @foo5{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD51:[0-9]+]]
+// CHECK: !kernel_arg_type ![[MD52:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD53:[0-9]+]]
+// CHECK: !kernel_arg_type_qual ![[MD45]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
+
+typedef char char16 __attribute__((ext_vector_type(16)));
+__kernel void foo6(__global char16 arg[]) {}
+// CHECK: !kernel_arg_typ

[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang Tidy's script

2019-11-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

> This patch introduces a way to apply the fix-its by the Analyzer:

I'm not sure this option is very useful... I don't know of anyone who uses the 
same option in Clang or ClangTidy. The only way I know people apply fixits is 
with the help of IDEs. I am also skeptical that people want to apply *all* 
fixits. Usually people want to pick a few specific ones, or all fixits of a 
certain kind; but not everything.

What workflow are you thinking of for this option?


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

https://reviews.llvm.org/D69746



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


[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

btw forgot to add a comment, it might be worth mentioning in change description 
that, this works in its current state because we don't allow extractions inside 
lambda expressions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70569



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


[PATCH] D69022: [coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves

2019-11-22 Thread JunMa via Phabricator via cfe-commits
junparser added a comment.

In D69022#1756138 , @modocache wrote:

> LGTM, thanks! Please let me know if you'd like me to commit this change.


commit it please, thanks!


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

https://reviews.llvm.org/D69022



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


[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet marked an inline comment as done.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:173
+bool alwaysReturns(const ExtractionZone &EZ) {
+  const Stmt *Last = EZ.Parent->Children.back()->ASTNode.get();
+  // Unwrap enclosing (unconditional) compound statement.

`EZ.getLastRootStmt()` instead of `EZ.Parent->Children.back()`



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:175
+  // Unwrap enclosing (unconditional) compound statement.
+  while (const auto *CS = llvm::dyn_cast(Last))
+if (CS->body_empty())

nit: braces



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:180
+  Last = CS->body_back();
+  return llvm::isa(Last);
+}

what if there's a goto in the selection :P 



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:611
+  // (Others are possible if there are conversions, but this seems clearest).
+  if (CapturedInfo.HasReturnStmt) {
+// If the return is conditional, neither replacing the code with

nit: early exits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70569



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


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Sorry wrote comments but forgot to hit submit :(




Comment at: clang/include/clang/Tooling/CompilationDatabase.h:229
+/// \return true if all @files were expanded successfully or there were none.
+bool expandResponseFiles(tooling::CompileCommand &Cmd,
+ llvm::cl::TokenizerCallback Tokenizer);

instead of exposing this functionality and handling them in Fixed and JSON 
compilation databases separately,  I was rather talking about creating a new 
type of compilation database.

as `inferTargetAndDriverMode` or `inferMissingCompileCommands` functions does. 
which will take an `Inner`/`Base` compilation database, and in its 
`getCompileCommands` method will try to expand any rsp files.

does that make sense?

Also please implement it in a new file. (but still put the declaration into 
this header)


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

https://reviews.llvm.org/D70222



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


[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

2019-11-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 2 inline comments as done.
sammccall added a comment.

(Thanks! Will address comments, just wanted to ask for a clarification)




Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:180
+  Last = CS->body_back();
+  return llvm::isa(Last);
+}

kadircet wrote:
> what if there's a goto in the selection :P 
If the goto target is in the selection, that's fine. Otherwise it's broken 
control flow like break/continue. It doesn't seem to be detected yet indeed.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:611
+  // (Others are possible if there are conversions, but this seems clearest).
+  if (CapturedInfo.HasReturnStmt) {
+// If the return is conditional, neither replacing the code with

kadircet wrote:
> nit: early exits
I'm not sure what this comment means, can you elaborate?
(I do mean "sometimes returns and sometimes doesn't". Early-exits aren't a 
problem, e.g. `if (x) return 1; return 2;` can be extracted.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70569



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


[PATCH] D70157: Align branches within 32-Byte boundary

2019-11-22 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

In D70157#1755927 , @jyknight wrote:

> An alternative would be to simply emit NOPs before branches as needed. That 
> would be substantially simpler, since it would only require special handling 
> for a branch or a fused-branch. I assume things were done this 
> substantially-more-complex way in order to reduce performance cost of 
> inserting NOP instructions? Are there numbers for how much better it is to 
> use segment prefixes, vs a separate nop instruction? It seems a little bit 
> surprising to me that it would be that important, but I don't know...
>
> I'll note that the method here has the semantic issue of making it 
> effectively impossible to ever evaluate an expression like ".if . - symbol == 
> 24" (assuming we're emitting instructions), since every instruction can now 
> change size. I suspect that will make it impossible to turn this on by 
> default without breaking a lot of assembly code. Previously, only certain 
> instructions, like branches or arithmetic ops with constant arguments of 
> unknown value, could change size.


Thanks for your remind! Now, if `-malign-branch-prefix-size=0` is used, the 
method will only insert `BranchPadding` or `FusedJccPadding` before branches as 
needed, and insert `BranchPrefix` before the instruction which is macro fusible 
but not macro fused. In this condition, the operation is as simple as inserting 
nop only. Since more performance can be recovered by inserting prefixes than 
inserting nops,  I believe I should support prefix padding.


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

https://reviews.llvm.org/D70157



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


[PATCH] D68362: [libunwind][RISCV] Add 64-bit RISC-V support

2019-11-22 Thread Hafiz Abid Qadeer via Phabricator via cfe-commits
abidh added inline comments.



Comment at: libunwind/src/Registers.hpp:3765
+inline void Registers_riscv::setFloatRegister(int regNum, double value) {
+#ifdef __riscv_flen == 64
+  assert(validFloatRegister(regNum));

I am building these changes and get the following warning.
warning: extra tokens at end of #ifdef directive [-Wextra-tokens]

You probably meant #if here.



Comment at: libunwind/src/UnwindRegistersRestore.S:1042
+DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
+#if __riscv_flen == 64
+  fldf0, (8 * 32 + 8 * 0)(a0)

This line generates the following warning when compiled without 'd' extension.

warning: '__riscv_flen' is not defined, evaluates to 0 [-Wundef]

Probably better to make it something like
#if defined(__riscv_flen) && __riscv_flen == 64



Comment at: libunwind/src/UnwindRegistersSave.S:1020
+
+#if __riscv_flen == 64
+  fsdf0, (8 * 32 + 8 * 0)(a0)

Similar problem here as described above.


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

https://reviews.llvm.org/D68362



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


[PATCH] D70485: [ARM,MVE] Add intrinsics to deal with predicates.

2019-11-22 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 230627.
simon_tatham edited the summary of this revision.
simon_tatham added a comment.

Revised again to fix test failures. But I've also split off the rework of 
`int_arm_vctp` into a separate patch D70592 , 
to make it clearer what's going on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70485

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/test/CodeGen/arm-mve-intrinsics/predicates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/predicates.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/predicates.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/predicates.ll
@@ -0,0 +1,219 @@
+; RUN: opt -instcombine %s | llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - | FileCheck %s
+
+declare <16 x i1> @llvm.arm.mve.vctp8(i32)
+declare <8 x i1> @llvm.arm.mve.vctp16(i32)
+declare <4 x i1> @llvm.arm.mve.vctp32(i32)
+declare <4 x i1> @llvm.arm.mve.vctp64(i32)
+
+declare i32 @llvm.arm.mve.pred.v2i.v4i1(<4 x i1>)
+declare i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1>)
+declare i32 @llvm.arm.mve.pred.v2i.v16i1(<16 x i1>)
+
+declare <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32)
+declare <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32)
+declare <16 x i1> @llvm.arm.mve.pred.i2v.v16i1(i32)
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp8q(i32 %a) {
+; CHECK-LABEL: test_vctp8q:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vctp.8 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <16 x i1> @llvm.arm.mve.vctp8(i32 %a)
+  %1 = call i32 @llvm.arm.mve.pred.v2i.v16i1(<16 x i1> %0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp8q_m(i32 %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vctp8q_m:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vctpt.8 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = call <16 x i1> @llvm.arm.mve.pred.i2v.v16i1(i32 %0)
+  %2 = call <16 x i1> @llvm.arm.mve.vctp8(i32 %a)
+  %3 = and <16 x i1> %1, %2
+  %4 = call i32 @llvm.arm.mve.pred.v2i.v16i1(<16 x i1> %3)
+  %5 = trunc i32 %4 to i16
+  ret i16 %5
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp16q(i32 %a) {
+; CHECK-LABEL: test_vctp16q:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vctp.16 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <8 x i1> @llvm.arm.mve.vctp16(i32 %a)
+  %1 = call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1> %0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp16q_m(i32 %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vctp16q_m:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vctpt.16 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 %0)
+  %2 = call <8 x i1> @llvm.arm.mve.vctp16(i32 %a)
+  %3 = and <8 x i1> %1, %2
+  %4 = call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1> %3)
+  %5 = trunc i32 %4 to i16
+  ret i16 %5
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp32q(i32 %a) {
+; CHECK-LABEL: test_vctp32q:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vctp.32 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <4 x i1> @llvm.arm.mve.vctp32(i32 %a)
+  %1 = call i32 @llvm.arm.mve.pred.v2i.v4i1(<4 x i1> %0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp32q_m(i32 %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vctp32q_m:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vctpt.32 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 %0)
+  %2 = call <4 x i1> @llvm.arm.mve.vctp32(i32 %a)
+  %3 = and <4 x i1> %1, %2
+  %4 = call i32 @llvm.arm.mve.pred.v2i.v4i1(<4 x i1> %3)
+  %5 = trunc i32 %4 to i16
+  ret i16 %5
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp64q(i32 %a) {
+; CHECK-LABEL: test_vctp64q:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vctp.64 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <4 x i1> @llvm.arm.mve.vctp64(i32 %a)
+  %1 = call i32 @llvm.arm.mve.pred.v2i.v4i1(<4 x i1> %0)
+  %2 = trunc i32 %1 to i16
+  ret i16 %2
+}
+
+define arm_aapcs_vfpcc zeroext i16 @test_vctp64q_m(i32 %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vctp64q_m:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vctpt.64 r0
+; CHECK-NEXT:vmrs r0, p0
+; CHECK-NEXT:  

[clang-tools-extra] 7f0dcf6 - [clangd] Show lambda signature for lambda autocompletions

2019-11-22 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2019-11-22T12:48:06+01:00
New Revision: 7f0dcf665dd22be296805bc7a1c71a36243c4e09

URL: 
https://github.com/llvm/llvm-project/commit/7f0dcf665dd22be296805bc7a1c71a36243c4e09
DIFF: 
https://github.com/llvm/llvm-project/commit/7f0dcf665dd22be296805bc7a1c71a36243c4e09.diff

LOG: [clangd] Show lambda signature for lambda autocompletions

The original bug report can be found
[here](https://github.com/clangd/clangd/issues/85)

Given the following code:

```c++
void function() {
  auto Lambda = [](int a, double &b) {return 1.f;};
  La^
}
```

Triggering the completion at `^` would show `(lambda)` before this patch
and would show signature `(int a, double &b) const`, build a snippet etc
with this patch.

Reviewers: sammccall

Reviewed by: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/function-templates.cpp
clang/test/CodeCompletion/lambdas.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 6757a8c686a7..cb6d61150319 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2465,6 +2465,26 @@ TEST(CompletionTest, NoCompletionsForNewNames) {
   EXPECT_THAT(Results.Completions, UnorderedElementsAre());
 }
 
+TEST(CompletionTest, Lambda) {
+  clangd::CodeCompleteOptions Opts = {};
+
+  auto Results = completions(R"cpp(
+void function() {
+  auto Lambda = [](int a, const double &b) {return 1.f;};
+  Lam^
+}
+  )cpp",
+ {}, Opts);
+
+  ASSERT_EQ(Results.Completions.size(), 1u);
+  const auto &A = Results.Completions.front();
+  EXPECT_EQ(A.Name, "Lambda");
+  EXPECT_EQ(A.Signature, "(int a, const double &b) const");
+  EXPECT_EQ(A.Kind, CompletionItemKind::Variable);
+  EXPECT_EQ(A.ReturnType, "float");
+  EXPECT_EQ(A.SnippetSuffix, "(${1:int a}, ${2:const double &b})");
+}
+
 TEST(CompletionTest, ObjectiveCMethodNoArguments) {
   auto Results = completions(R"objc(
   @interface Foo

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 81eed4330cdc..e75aca4d81e5 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -3315,6 +3315,18 @@ 
CodeCompletionResult::createCodeCompletionStringForOverride(
   return Result.TakeString();
 }
 
+// FIXME: Right now this works well with lambdas. Add support for other functor
+// types like std::function.
+static const NamedDecl *extractFunctorCallOperator(const NamedDecl *ND) {
+  const auto *VD = dyn_cast(ND);
+  if (!VD)
+return nullptr;
+  const auto *RecordDecl = VD->getType()->getAsCXXRecordDecl();
+  if (!RecordDecl || !RecordDecl->isLambda())
+return nullptr;
+  return RecordDecl->getLambdaCallOperator();
+}
+
 CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
 Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
 bool IncludeBriefComments, const CodeCompletionContext &CCContext,
@@ -3339,9 +3351,8 @@ CodeCompletionString 
*CodeCompletionResult::createCodeCompletionStringForDecl(
   for (const auto *I : ND->specific_attrs())
 Result.AddAnnotation(Result.getAllocator().CopyString(I->getAnnotation()));
 
-  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
-
-  if (const auto *Function = dyn_cast(ND)) {
+  auto AddFunctionTypeAndResult = [&](const FunctionDecl *Function) {
+AddResultTypeChunk(Ctx, Policy, Function, CCContext.getBaseType(), Result);
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
Ctx, Policy);
 AddTypedNameChunk(Ctx, Policy, ND, Result);
@@ -3349,9 +3360,21 @@ CodeCompletionString 
*CodeCompletionResult::createCodeCompletionStringForDecl(
 AddFunctionParameterChunks(PP, Policy, Function, Result);
 Result.AddChunk(CodeCompletionString::CK_RightParen);
 AddFunctionTypeQualsToCompletionString(Result, Function);
+  };
+
+  if (const auto *Function = dyn_cast(ND)) {
+AddFunctionTypeAndResult(Function);
+return Result.TakeString();
+  }
+
+  if (const auto *CallOperator =
+  dyn_cast_or_null(extractFunctorCallOperator(ND))) {
+AddFunctionTypeAndResult(CallOperator);
 return Result.TakeString();
   }
 
+  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
+
   if (const FunctionTemplateDecl *FunTmpl =
   dyn_cast(ND)) {
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
@@ -3417,6 +3440,7 @@ CodeCompletionString 
*CodeCompletionResult::createCodeCompletionStringForDecl(
 Result.AddChunk(CodeCompletionString::CK_RightAngle);
   

[PATCH] D70180: [AArch64][SVE] Implement floating-point conversion intrinsics

2019-11-22 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: efriedma.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70180



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


[PATCH] D70594: [clangd] Implement range patching heuristics for cross-file rename.

2019-11-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, arphaman, mgrang, jkorous, 
MaskRay.
Herald added a project: clang.

The heuristic is simple, only for cases we are confident.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70594

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "index/Ref.h"
 #include "refactor/Rename.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gmock/gmock.h"
@@ -665,6 +666,111 @@
 expectedResult(Code, expectedResult(T, "abc")));
 }
 
+TEST(CrossFileRenameTests, RangePatching) {
+  struct {
+llvm::StringRef LatestCode;
+llvm::StringRef IndexCode;
+RangeMatcher::MatchType ExpectedMatch;
+  } Tests [] = {
+{
+  // Equal
+  R"([[foo]])",
+  R"([[foo]])",
+  RangeMatcher::MatchType::Subset,
+},
+{
+  // proper subset
+  R"([[foo]] [[foo]])",
+  R"([[foo]])",
+  RangeMatcher::MatchType::Subset,
+},
+{
+  // same line, near-miss column.
+  R"([[foo]] [[foo]])",
+  R"(  [[foo]] [[foo]])",
+  RangeMatcher::MatchType::NearMiss,
+},
+{
+  // same line, near-miss column.
+  R"([[foo]] [[foo]])",
+  R"([[foo]]   [[foo]])",
+  RangeMatcher::MatchType::NearMiss,
+},
+{
+  // same column, near-miss line
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+
+[[foo]] [[foo]]
+  )",
+  RangeMatcher::MatchType::NearMiss,
+},
+
+
+{
+  // same line, but column diff > near-miss threshold
+  R"([[foo]])",
+  R"(   [[foo]])",
+  RangeMatcher::MatchType::NoMatch,
+},
+{
+  // same column, but line diff > near-miss threshold
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+
+
+
+[[foo]] [[foo]]
+  )",
+  RangeMatcher::MatchType::NoMatch,
+},
+{
+  // two lines with different number of elements are not near-miss.
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+[[foo]]
+[[foo]]
+  )",
+  RangeMatcher::MatchType::NoMatch,
+}
+  };
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  RangeMatcher Matcher(LangOpts);
+
+  for (const auto &T : Tests) {
+auto IndexOccurrences = Annotations(T.IndexCode).ranges();
+auto Candidates = Annotations(T.LatestCode).ranges();
+EXPECT_EQ(T.ExpectedMatch,
+  RangeMatcher::match(IndexOccurrences, Candidates))
+<< T.LatestCode << ":" << T.IndexCode;
+
+
+auto AuthoritativeResult = Matcher.getBest(Annotations(T.LatestCode).code(),
+   "foo", IndexOccurrences);
+switch (T.ExpectedMatch) {
+case RangeMatcher::MatchType::NoMatch:
+  EXPECT_EQ(llvm::None, AuthoritativeResult);
+  break;
+case RangeMatcher::MatchType::Subset:
+  ASSERT_TRUE(AuthoritativeResult);
+  EXPECT_EQ(IndexOccurrences, *AuthoritativeResult);
+  break;
+case RangeMatcher::MatchType::NearMiss:
+  ASSERT_TRUE(AuthoritativeResult);
+
+  EXPECT_EQ(Candidates, *AuthoritativeResult);
+  break;
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -54,6 +54,49 @@
  std::vector Occurrences,
  llvm::StringRef NewName);
 
+/// Check whether the index results are good enough to perform the cross-file
+/// rename.
+///
+/// Index may be stale at the point of renaming, this class is designed to
+/// mitigate the issue of staleness index that may hurt the quality of rename
+/// results.
+///
+/// Techniques:
+///   - lex the latest file content (from dirty buffer/disk) to find all rename
+/// candidates, this yields a superset candidates
+///   - apply range patching heuristics to generate "authoritative" rename
+/// candidates. Scenarios that we are confident:
+///  (a) index returns a subset of candidates
+///- fully equal, we are sure the index is up-to-date
+///- proper subset, index is correct in most cases? there may be false
+///  positives (e.g. candidates got appended), but rename is still safe
+///  (b) index returns non-candidate results
+///- check whether they are near-miss (same line/column)
+class

[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:611
+  // (Others are possible if there are conversions, but this seems clearest).
+  if (CapturedInfo.HasReturnStmt) {
+// If the return is conditional, neither replacing the code with

sammccall wrote:
> kadircet wrote:
> > nit: early exits
> I'm not sure what this comment means, can you elaborate?
> (I do mean "sometimes returns and sometimes doesn't". Early-exits aren't a 
> problem, e.g. `if (x) return 1; return 2;` can be extracted.)
ah sorry, i was trying to imply usage of early exits in the code, i.e:

```
ExtractedFunc.ReturnType = EnclosingFunc.getParentASTContext().VoidTy;
if not HasReturnStmt
  return true;
if not AlwaysReturn
  return false;
.
.
.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70569



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


[PATCH] D70253: [AArch64][SVE2] Implement remaining SVE2 floating-point intrinsics

2019-11-22 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsAArch64.td:898
+ llvm_i32_ty],
+[IntrNoMem]>;
+

I'd expect the `llvm_i32_ty` to be an immediate for these instructions, right? 
If so you'll need to add `ImmArg`  to the list of properties.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70253



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


[PATCH] D70445: [clangd] Show lambda signature for lambda autocompletions

2019-11-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f0dcf665dd2: [clangd] Show lambda signature for lambda 
autocompletions (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70445

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/function-templates.cpp
  clang/test/CodeCompletion/lambdas.cpp

Index: clang/test/CodeCompletion/lambdas.cpp
===
--- clang/test/CodeCompletion/lambdas.cpp
+++ clang/test/CodeCompletion/lambdas.cpp
@@ -60,3 +60,15 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:57:24 %s -o - | FileCheck -check-prefix=CHECK-8 %s
   // CHECK-8-NOT: COMPLETION: Pattern : [<#=
 }
+
+void test6() {
+  auto my_lambda = [&](int a, double &b) { return 1.f; };
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:65:58 %s -o - | FileCheck -check-prefix=CHECK-9 %s
+  // CHECK-9: [#float#]my_lambda(<#int a#>, <#double &b#>)[# const#]
+}
+
+void test7() {
+  auto generic_lambda = [&](auto a, const auto &b) { return a + b; };
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:71:70 %s -o - | FileCheck -check-prefix=CHECK-10 %s
+  // CHECK-10: [#auto#]generic_lambda(<#auto a#>, <#const auto &b#>)[# const#]
+}
Index: clang/test/CodeCompletion/function-templates.cpp
===
--- clang/test/CodeCompletion/function-templates.cpp
+++ clang/test/CodeCompletion/function-templates.cpp
@@ -1,7 +1,7 @@
 namespace std {
   template
   void sort(RandomAccessIterator first, RandomAccessIterator last);
-  
+
   template
   X* dyn_cast(Y *Val);
 }
@@ -11,13 +11,17 @@
   template T &getAs();
 };
 
+template 
+V doSomething(T t, const U &u, V *v) { return V(); }
+
 void f() {
   std::sort(1, 2);
   Foo().getAs();
-  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:15:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:18:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
   // CHECK-CC1: dyn_cast<<#class X#>>(<#Y *Val#>)
   // CHECK-CC1: sort(<#RandomAccessIterator first#>, <#RandomAccessIterator last#>
-  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:16:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2: getAs<<#typename T#>>()
-)
-  
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: [#V#]doSomething(<#T t#>, <#const U &u#>, <#V *v#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3315,6 +3315,18 @@
   return Result.TakeString();
 }
 
+// FIXME: Right now this works well with lambdas. Add support for other functor
+// types like std::function.
+static const NamedDecl *extractFunctorCallOperator(const NamedDecl *ND) {
+  const auto *VD = dyn_cast(ND);
+  if (!VD)
+return nullptr;
+  const auto *RecordDecl = VD->getType()->getAsCXXRecordDecl();
+  if (!RecordDecl || !RecordDecl->isLambda())
+return nullptr;
+  return RecordDecl->getLambdaCallOperator();
+}
+
 CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
 Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
 bool IncludeBriefComments, const CodeCompletionContext &CCContext,
@@ -3339,9 +3351,8 @@
   for (const auto *I : ND->specific_attrs())
 Result.AddAnnotation(Result.getAllocator().CopyString(I->getAnnotation()));
 
-  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
-
-  if (const auto *Function = dyn_cast(ND)) {
+  auto AddFunctionTypeAndResult = [&](const FunctionDecl *Function) {
+AddResultTypeChunk(Ctx, Policy, Function, CCContext.getBaseType(), Result);
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
Ctx, Policy);
 AddTypedNameChunk(Ctx, Policy, ND, Result);
@@ -3349,9 +3360,21 @@
 AddFunctionParameterChunks(PP, Policy, Function, Result);
 Result.AddChunk(CodeCompletionString::CK_RightParen);
 AddFunctionTypeQualsToCompletionString(Result, Function);
+  };
+
+  if (const auto *Function = dyn_cast(ND)) {
+AddFunctionTypeAndResult(Function);
+return Result.TakeString();
+  }
+
+  if (const auto *CallOperator =
+  dyn_cast_or_null(extractFunctorCallOperator(ND))) {
+AddFunctionTypeAndResult(CallOperator);
 return Result.TakeString();
   }
 
+  AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result);
+
   if (const FunctionTemplateDecl *FunTmpl =
   dyn_cast(ND)) {

[PATCH] D70594: [clangd] Implement range patching heuristics for cross-file rename.

2019-11-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: FAILURE - Could not check out parent git hash 
"6171238cb7e9e8616d21ce09d463e945ce0a9fb8". It was not found in the repository. 
Did you configure the "Parent Revision" in Phabricator properly? Trying to 
apply the patch to the master branch instead...

ERROR: arc patch failed with error code 1. Check build log for details.
Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70594



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


[PATCH] D69223: WDocumentation: Implement the \anchor.

2019-11-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Thank you for the contribution and sorry for the review delay!




Comment at: clang/bindings/xml/comment-xml-schema.rng:583
+  
+
+

Since the name of the anchor is not a part of the document text, it should be 
an attribute on the anchor tag (not a part of the text).



Comment at: clang/lib/Index/CommentToXML.cpp:302
+assert(C->getNumArgs() == 1);
+Result << "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

I guess we should emit an empty "" instead.



Comment at: clang/lib/Index/CommentToXML.cpp:303
+Result << "";

I don't think escaping is needed. IDs have a strict syntax: 
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id



Comment at: clang/lib/Index/CommentToXML.cpp:304
+appendToResultWithHTMLEscaping(Arg0);
+Result << "\"/>";
+return;

https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5



Comment at: clang/test/Index/Inputs/CommentXML/valid-function-02.xml:12
 .
+hhh
   

I'd suggest to add a separate test file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69223



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


[PATCH] D70437: [AArch64][SVE] Implement shift intrinsics

2019-11-22 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.
Herald added a reviewer: efriedma.

Two small comments, but overall looks good!




Comment at: llvm/include/llvm/IR/IntrinsicsAArch64.td:835
+ LLVMMatchType<0>,
+ llvm_i32_ty],
+[IntrNoMem]>;

If this is an immediate, please add `ImmArg` to the list of properties.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:671
   setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
+  setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i8, Custom);
+  setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i16, Custom);

Given that we need this for some SVE instructions, perhaps enclose it in `if 
(Subtarget->isSVE())` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70437



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


[PATCH] D70494: [clangd] Fix diagnostic location for macro expansions

2019-11-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:121
   const SourceManager &SM = Info.getSourceManager();
+  const SourceLocation &DiagLoc = SM.getFileLoc(Info.getLocation());
   SourceLocation IncludeInMainFile;

should we use getExpansionLoc? getFileLoc returns a spelling location if it 
comes from a macro argument, but I think it doesn't matter.



Comment at: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:944
 
 TEST(IgnoreDiags, FromNonWrittenSources) {
   Annotations Main(R"cpp(

this doesn't belong to IgnoreDiags any more, I think, should be 
`DiagsInHeaders`, the same to the newly-added test.



Comment at: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:978
+  #define X foo
+  X;)cpp");
+  TestTU TU = TestTU::withCode(Main.code());

could you add one more test case where foo is spelled at macro argument? I 
believe it was broken as well before this patch.

```
#define X(arg) arg
X(foo);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70494



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


[PATCH] D68388: [PR41008][OpenCL] Add OpenCL C compatibility mode to C++ for OpenCL

2019-11-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

I think we should use `-fpermissive` rather than adding similar flag to Clang. 
At the end we might end up with other cases where we need similar mechanism it 
doesn't make sense to add a flag for each case.

Also I am not sure that what you are doing here is really enabling OpenCL C 
compatibility mode that would imply to me that `restrict` is expected to behave 
in C++ mode as it was in C but is it really the case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68388



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


[PATCH] D70494: [clangd] Fix diagnostic location for macro expansions

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 5 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:121
   const SourceManager &SM = Info.getSourceManager();
+  const SourceLocation &DiagLoc = SM.getFileLoc(Info.getLocation());
   SourceLocation IncludeInMainFile;

hokein wrote:
> should we use getExpansionLoc? getFileLoc returns a spelling location if it 
> comes from a macro argument, but I think it doesn't matter.
right



Comment at: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:944
 
 TEST(IgnoreDiags, FromNonWrittenSources) {
   Annotations Main(R"cpp(

hokein wrote:
> this doesn't belong to IgnoreDiags any more, I think, should be 
> `DiagsInHeaders`, the same to the newly-added test.
ah thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70494



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


[PATCH] D70494: [clangd] Fix diagnostic location for macro expansions

2019-11-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 230636.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70494

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -941,7 +941,7 @@
   WithNote(Diag(Header.range(), "error occurred here");
 }
 
-TEST(IgnoreDiags, FromNonWrittenSources) {
+TEST(DiagsInHeaders, FromNonWrittenSources) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
 void foo() {})cpp");
@@ -951,7 +951,11 @@
   TestTU TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles = {{"a.h", Header.code()}};
   TU.ExtraArgs = {"-DFOO=NOOO"};
-  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Main.range(),
+   "in included file: use of undeclared identifier 
'NOOO'"),
+  WithNote(Diag(Header.range(), "error occurred here");
 }
 
 TEST(IgnoreDiags, FromNonWrittenInclude) {
@@ -963,6 +967,40 @@
   EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
 }
 
+TEST(DiagsInHeaders, ErrorFromMacroExpansion) {
+  Annotations Main(R"cpp(
+  void bar() {
+int fo;
+#include [["a.h"]]
+  })cpp");
+  Annotations Header(R"cpp(
+  #define X foo
+  X;)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(
+  Diag(Main.range(), "in included file: use of undeclared "
+ "identifier 'foo'; did you mean 'fo'?")));
+}
+
+TEST(DiagsInHeaders, ErrorFromMacroArgument) {
+  Annotations Main(R"cpp(
+  void bar() {
+int fo;
+#include [["a.h"]]
+  })cpp");
+  Annotations Header(R"cpp(
+  #define X(arg) arg
+  X(foo);)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(
+  Diag(Main.range(), "in included file: use of undeclared "
+ "identifier 'foo'; did you mean 'fo'?")));
+}
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -117,8 +117,8 @@
   if (D.Severity < DiagnosticsEngine::Level::Error)
 return false;
 
-  const SourceLocation &DiagLoc = Info.getLocation();
   const SourceManager &SM = Info.getSourceManager();
+  const SourceLocation &DiagLoc = SM.getExpansionLoc(Info.getLocation());
   SourceLocation IncludeInMainFile;
   auto GetIncludeLoc = [&SM](SourceLocation SLoc) {
 return SM.getIncludeLoc(SM.getFileID(SLoc));


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -941,7 +941,7 @@
   WithNote(Diag(Header.range(), "error occurred here");
 }
 
-TEST(IgnoreDiags, FromNonWrittenSources) {
+TEST(DiagsInHeaders, FromNonWrittenSources) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
 void foo() {})cpp");
@@ -951,7 +951,11 @@
   TestTU TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles = {{"a.h", Header.code()}};
   TU.ExtraArgs = {"-DFOO=NOOO"};
-  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Main.range(),
+   "in included file: use of undeclared identifier 'NOOO'"),
+  WithNote(Diag(Header.range(), "error occurred here");
 }
 
 TEST(IgnoreDiags, FromNonWrittenInclude) {
@@ -963,6 +967,40 @@
   EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
 }
 
+TEST(DiagsInHeaders, ErrorFromMacroExpansion) {
+  Annotations Main(R"cpp(
+  void bar() {
+int fo;
+#include [["a.h"]]
+  })cpp");
+  Annotations Header(R"cpp(
+  #define X foo
+  X;)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  UnorderedElementsAre(
+  Diag(Main.range(), "in included file: use of undeclared "
+ "identifier 'foo'; did you

[PATCH] D70596: [analyzer][docs] NFC: Extend documentation for MallocOverflow checker

2019-11-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: Szelethus, NoQ, krememek.
Herald added subscribers: cfe-commits, Charusso, donat.nagy, dexonsmith, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun, whisperity.
Herald added a project: clang.

Adds and example for `MallocOverflow` checker how to suppress the warning via 
checking the upper bound of the allocation size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70596

Files:
  clang/docs/analyzer/checkers.rst


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1974,6 +1974,12 @@
void *p = malloc(n * sizeof(int)); // warn
  }
 
+ void test2(int n) {
+   if (n > 100) // gives an upper-bound
+ return;
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1974,6 +1974,12 @@
void *p = malloc(n * sizeof(int)); // warn
  }
 
+ void test2(int n) {
+   if (n > 100) // gives an upper-bound
+ return;
+   void *p = malloc(n * sizeof(int)); // no warning
+ }
+
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70494: [clangd] Fix diagnostic location for macro expansions

2019-11-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60220 tests passed, 0 failed and 732 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70494



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


[PATCH] D68388: [PR41008][OpenCL] Add OpenCL C compatibility mode to C++ for OpenCL

2019-11-22 Thread Kévin Petit via Phabricator via cfe-commits
kpet added a comment.

Thanks for the feedback.

> I think we should use -fpermissive rather than adding similar flag to Clang.

Could you point me at a use of `-fpermissive` for a similar case? Also it seems 
`-fpermissive` is not mentioned in the Clang manual or the help text. Am I 
missing something?

> At the end we might end up with other cases where we need similar mechanism 
> it doesn't make sense to add a flag for each case.

Completely agree and that was one of the reasons I decided to add a generic 
flag like this. I felt that compatibility with existing OpenCL C source was an 
important enough use-case to warrant adding a flag for it especially since, as 
you say, we expect such a flag could be useful to control several bits of 
behaviour.

> Also I am not sure that what you are doing here is really enabling OpenCL C 
> compatibility mode that would imply to me that restrict is expected to behave 
> in C++ mode as it was in C but is it really the case?

Isn't restrict mainly an optimisation feature? That's certainly my reading of 
6.7.3-7 in the C99 spec:

> The intended use of the restrict qualifier (like the register storage class) 
> is to promote
> optimization, and deleting all instances of the qualifier from all 
> preprocessing translation
> units composing a conforming program does not change its meaning (i.e., 
> observable
> behavior).

The main goal here is to be able to consume existing OpenCL C source without 
modifications. I thought that enabling existing behaviour for 
`restrict`/`__restrict` that may result in additional optimisations was more 
useful than just discarding `restrict`, which would be a valid way of achieving 
compatibility. Is there something specific that worries you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68388



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


[PATCH] D68388: [PR41008][OpenCL] Add OpenCL C compatibility mode to C++ for OpenCL

2019-11-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D68388#1756701 , @kpet wrote:

> Thanks for the feedback.
>
> > I think we should use -fpermissive rather than adding similar flag to Clang.
>
> Could you point me at a use of `-fpermissive` for a similar case? Also it 
> seems `-fpermissive` is not mentioned in the Clang manual or the help text. 
> Am I missing something?




  bin/clang -fpermissive test.cl

Clang already has the flag added. So you can just start using it I presume. 
Feel free to document it.

> 
> 
>> At the end we might end up with other cases where we need similar mechanism 
>> it doesn't make sense to add a flag for each case.
> 
> Completely agree and that was one of the reasons I decided to add a generic 
> flag like this. I felt that compatibility with existing OpenCL C source was 
> an important enough use-case to warrant adding a flag for it especially 
> since, as you say, we expect such a flag could be useful to control several 
> bits of behaviour.
> 
>> Also I am not sure that what you are doing here is really enabling OpenCL C 
>> compatibility mode that would imply to me that restrict is expected to 
>> behave in C++ mode as it was in C but is it really the case?
> 
> Isn't restrict mainly an optimisation feature? That's certainly my reading of 
> 6.7.3-7 in the C99 spec:
> 
>> The intended use of the restrict qualifier (like the register storage class) 
>> is to promote
>> optimization, and deleting all instances of the qualifier from all 
>> preprocessing translation
>> units composing a conforming program does not change its meaning (i.e., 
>> observable
>> behavior).
> 
> The main goal here is to be able to consume existing OpenCL C source without 
> modifications. I thought that enabling existing behaviour for 
> `restrict`/`__restrict` that may result in additional optimisations was more 
> useful than just discarding `restrict`, which would be a valid way of 
> achieving compatibility. Is there something specific that worries you?

C++ deviates from C so restrict in C++ might not be restrict in C. Can we 
confidently say we will support restrict exactly like OpenCL C does i.e. C99?

In other words I believe it is much safe to say that we support `restrict` in 
adhoc way that deviates C++ for OpenCL documentation without implying 
developers should refer to OpenCL C and C99 spec to get how it works. We can 
also use this mechanism for any behavior that deviates the documentation rather 
than adding a flag for each (i.e. we might want to deviate in something that 
doesn't come from OpenCL C at all).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68388



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


[PATCH] D69825: [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation

2019-11-22 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added a comment.

Thanks for this change. I applied this patch (prior to splitting out 
https://reviews.llvm.org/D70568) and it built and worked okay (I only see one 
clang-cl in process explorer).

I don't see anything like same performance improvement however. I did my own 
assessment of build times. I built 2 x stage 1 toolchains using clang 9.0.0 
with and without this patch (applied to 
1b9ef3bbb595206b0097b7adec2c1b69eae6fab4 
). Then I 
used each of those to build LLVM (no clang or lld) again.

CMake settings:

  # Build stage 1 (same with and without patch)
  cmake -G Ninja -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" 
-DCMAKE_LINKER="C:/Program Files/LLVM/bin/lld-link.exe" 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang;lld 
-DLLVM_TARGETS_TO_BUILD=X86 -DCLANG_ENABLE_STATIC_ANALYZER=OFF 
-DCLANG_ENABLE_ARCMT=OFF ../llvm
  
  # Build stage 2 without patch
  cmake -G Ninja 
-DCMAKE_C_COMPILER="/build_stage1_no_patch/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="/build_stage1_no_patch/bin/clang-cl.exe"
 -DCMAKE_LINKER="/build_stage1_no_patch/bin/lld-link.exe" 
-DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 ../llvm
  
  # Build stage 2 with patch
  cmake -G Ninja 
-DCMAKE_C_COMPILER="/build_stage1_patch/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="/build_stage1_patch/bin/clang-cl.exe" 
-DCMAKE_LINKER="/build_stage1_patch/bin/lld-link.exe" 
-DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 ../llvm

These both built the patched code.

I got a ~1.5% performance improvement, reducing "ninja all" from 571.5s to 
562.5s seconds on a 6 core machine (average over three 3 builds on a quiet 
machine), times below. For reference I am using winver 1803 and have CFG 
enabled.

Assuming that `time_saved ≈ (process_invocation_overhead * compiler_jobs) / 
parallel_build_jobs`
or (rearranging) `process_invocation_overhead ≈ (time_saved * 
parallel_build_jobs) / compiler_jobs`
(I know this is not perfectly true as build jobs will tail off towards the end 
of a build, but I think is okay for a ballpark estimate.)

I saved 9 seconds, over 1720 compiler jobs (from `ninja -v -n all | grep -c 
clang-cl`), with 14 parallel build jobs which gives the process invocation 
overhead of about 73ms which is in the range you mentioned above (30-100ms). 
Therefore I think that this is in the right ballpark.

I can't see how this would get 20% (from the table) or 30% improvement (from 
the first graph). In `abba_test.ps1` you include running tests (due to 
`check-all`) so it is possible that you are saving time on a very large number 
of clang driver invocations on very small files. This is helpful for LLVM 
developers but I don't think it's representative of other builds. 
Alternatively, is the process overhead higher on your machine(s) for some 
reason (e.g. security software).

To be clear, I'm not against this patch going in, and I can confirm that it is 
a performance improvement so good to have. I just can't see where the claimed 
20-30% saving on build time comes from.

Time data for 3 builds (seconds)
No patch (571.349, 575.353, 567.638)
With Patch (560.870, 563.110, 563.368)


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

https://reviews.llvm.org/D69825



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


[PATCH] D70071: [ConstExprPreter] Removed the flag forcing the use of the interpreter

2019-11-22 Thread Nandor Licker via Phabricator via cfe-commits
nand added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70071



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


[PATCH] D70588: Don't report "main" as missing a prototype in freestanding mode

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70588



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


[PATCH] D69840: [Basic] Make SourceLocation usable as key in hash maps, NFCI

2019-11-22 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

ping^2


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

https://reviews.llvm.org/D69840



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


[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 5 inline comments as done.
ymandel added a comment.

Thanks for the review!




Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:96
+// Constructs an expression that idiomatically represents a value, taking into
+// account whether `ExprId` is a pointer or already a value.
+Stencil asValue(llvm::StringRef ExprId);

gribozavr2 wrote:
> Need more explanation to cover the cases when the expression is a pointer to 
> a pointer (do we deref once or twice?), or a smart pointer (do we take care 
> of that at all?)
> 
> WDYT about calling it `maybeDeref()` or `derefIfPointer()`?
I went with maybe... Given that, I didn't elaborate on pointer-to-pointer case 
because it never claims to result in a value. WDYT?

also, I kind of like derefIfPointer better, but addressOfIfValue just seemed to 
clunky. So, went w/ maybe...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554



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


[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 230647.
ymandel added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554

Files:
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -233,6 +233,46 @@
   testExpr(Id, "int *x; *x;", addressOf(Id), "x");
 }
 
+TEST_F(StencilTest, MaybeDerefValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeDerefPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeDeref(Id), "*x");
+}
+
+TEST_F(StencilTest, MaybeDerefBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x + 1;", maybeDeref(Id), "*(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeDerefAddressExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; &x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeAddressOf(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", addressOf(Id), "&x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x + 1;", maybeAddressOf(Id), "&(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeAddressOfDerefExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; *x;", addressOf(Id), "x");
+}
+
 TEST_F(StencilTest, AccessOpValue) {
   StringRef Snippet = R"cc(
 S x;
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -59,7 +59,9 @@
 enum class UnaryNodeOperator {
   Parens,
   Deref,
-  Address,
+  MaybeDeref,
+  AddressOf,
+  MaybeAddressOf,
 };
 
 // Generic container for stencil operations with a (single) node-id argument.
@@ -121,9 +123,15 @@
   case UnaryNodeOperator::Deref:
 OpName = "deref";
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+OpName = "maybeDeref";
+break;
+  case UnaryNodeOperator::AddressOf:
 OpName = "addressOf";
 break;
+  case UnaryNodeOperator::MaybeAddressOf:
+OpName = "maybeAddressOf";
+break;
   }
   return (OpName + "(\"" + Data.Id + "\")").str();
 }
@@ -191,7 +199,21 @@
   case UnaryNodeOperator::Deref:
 Source = tooling::buildDereference(*E, *Match.Context);
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+if (!E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
+Source = tooling::buildDereference(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::AddressOf:
+Source = tooling::buildAddressOf(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::MaybeAddressOf:
+if (E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
 Source = tooling::buildAddressOf(*E, *Match.Context);
 break;
   }
@@ -300,9 +322,19 @@
   UnaryNodeOperator::Deref, ExprId);
 }
 
+Stencil transformer::maybeDeref(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeDeref, ExprId);
+}
+
 Stencil transformer::addressOf(llvm::StringRef ExprId) {
   return std::make_shared>(
-  UnaryNodeOperator::Address, ExprId);
+  UnaryNodeOperator::AddressOf, ExprId);
+}
+
+Stencil transformer::maybeAddressOf(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeAddressOf, ExprId);
 }
 
 Stencil transformer::access(StringRef BaseId, Stencil Member) {
Index: clang/include/clang/Tooling/Transformer/Stencil.h
===
--- clang/include/clang/Tooling/Transformer/Stencil.h
+++ clang/include/clang/Tooling/Transformer/Stencil.h
@@ -87,11 +87,24 @@
 /// \p ExprId is wrapped in parentheses, if needed.
 Stencil deref(llvm::StringRef ExprId);
 
+/// If \p ExprId is of pointer type, constructs an idiomatic dereferencing of
+/// the expression bound to \p ExprId, including wrapping it in parentheses, if
+/// needed. Otherwise, generates the original expression source.
+/// FIXME: Identify smart-pointers as pointer types.
+Stencil maybeDeref(llvm::StringRef ExprId);
+
 /// Constructs an expression that idiomatically takes the address of the
 /// expression bound to \p ExprId. \p ExprId is wrapped in parentheses, if
 /// needed.
 Stencil addressOf(llvm::StringRef ExprId);
 
+/// If \p ExprId is not a pointer type, constructs an expression that
+/// idiomatically takes the address of the express

[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 230646.
ymandel added a comment.

renamed combinators; reordered cases to pair x and maybeX.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554

Files:
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -233,6 +233,46 @@
   testExpr(Id, "int *x; *x;", addressOf(Id), "x");
 }
 
+TEST_F(StencilTest, MaybeDerefValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeDerefPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeDeref(Id), "*x");
+}
+
+TEST_F(StencilTest, MaybeDerefBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x + 1;", maybeDeref(Id), "*(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeDerefAddressExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; &x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeAddressOf(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", addressOf(Id), "&x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x + 1;", maybeAddressOf(Id), "&(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeAddressOfDerefExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; *x;", addressOf(Id), "x");
+}
+
 TEST_F(StencilTest, AccessOpValue) {
   StringRef Snippet = R"cc(
 S x;
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -59,7 +59,9 @@
 enum class UnaryNodeOperator {
   Parens,
   Deref,
-  Address,
+  MaybeDeref,
+  AddressOf,
+  MaybeAddressOf,
 };
 
 // Generic container for stencil operations with a (single) node-id argument.
@@ -121,9 +123,15 @@
   case UnaryNodeOperator::Deref:
 OpName = "deref";
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+OpName = "maybeDeref";
+break;
+  case UnaryNodeOperator::AddressOf:
 OpName = "addressOf";
 break;
+  case UnaryNodeOperator::MaybeAddressOf:
+OpName = "maybeAddressOf";
+break;
   }
   return (OpName + "(\"" + Data.Id + "\")").str();
 }
@@ -191,7 +199,21 @@
   case UnaryNodeOperator::Deref:
 Source = tooling::buildDereference(*E, *Match.Context);
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+if (!E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
+Source = tooling::buildDereference(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::AddressOf:
+Source = tooling::buildAddressOf(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::MaybeAddressOf:
+if (E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
 Source = tooling::buildAddressOf(*E, *Match.Context);
 break;
   }
@@ -300,9 +322,19 @@
   UnaryNodeOperator::Deref, ExprId);
 }
 
+Stencil transformer::maybeDeref(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeDeref, ExprId);
+}
+
 Stencil transformer::addressOf(llvm::StringRef ExprId) {
   return std::make_shared>(
-  UnaryNodeOperator::Address, ExprId);
+  UnaryNodeOperator::AddressOf, ExprId);
+}
+
+Stencil transformer::maybeAddressOf(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeAddressOf, ExprId);
 }
 
 Stencil transformer::access(StringRef BaseId, Stencil Member) {
Index: clang/include/clang/Tooling/Transformer/Stencil.h
===
--- clang/include/clang/Tooling/Transformer/Stencil.h
+++ clang/include/clang/Tooling/Transformer/Stencil.h
@@ -87,11 +87,24 @@
 /// \p ExprId is wrapped in parentheses, if needed.
 Stencil deref(llvm::StringRef ExprId);
 
+/// If \p ExprId is of pointer type, constructs an idiomatic dereferencing of
+/// the expression bound to \p ExprId, including wrapping it in parentheses, if
+/// needed. Otherwise, generates the original expression source.
+/// FIXME: Identify smart points as pointer types.
+Stencil maybeDeref(llvm::StringRef ExprId);
+
 /// Constructs an expression that idiomatically takes the address of the
 /// expression bound to \p ExprId. \p ExprId is wrapped in parentheses, if
 /// needed.
 Stencil addressOf(llvm::StringRef ExprId);
 
+/// If \p ExprId is not a pointer type, constructs an expression that
+//

[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:90
 
+/// If \p ExprId is of pointer type, constructs an idiomatic dereferencing of
+/// the expression bound to \p ExprId, including wrapping it in parentheses, if

"If the expression \p ExprId has pointer type ..."



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:101
 
+/// If \p ExprId is not a pointer type, constructs an expression that
+/// idiomatically takes the address of the expression bound to \p ExprId,

"If the expression \p ExprId is not a pointer, ..."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554



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


[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 marked an inline comment as done.
gribozavr2 added inline comments.



Comment at: clang/include/clang/Tooling/Transformer/Stencil.h:96
+// Constructs an expression that idiomatically represents a value, taking into
+// account whether `ExprId` is a pointer or already a value.
+Stencil asValue(llvm::StringRef ExprId);

ymandel wrote:
> gribozavr2 wrote:
> > Need more explanation to cover the cases when the expression is a pointer 
> > to a pointer (do we deref once or twice?), or a smart pointer (do we take 
> > care of that at all?)
> > 
> > WDYT about calling it `maybeDeref()` or `derefIfPointer()`?
> I went with maybe... Given that, I didn't elaborate on pointer-to-pointer 
> case because it never claims to result in a value. WDYT?
> 
> also, I kind of like derefIfPointer better, but addressOfIfValue just seemed 
> to clunky. So, went w/ maybe...
> Given that, I didn't elaborate on pointer-to-pointer case because it never 
> claims to result in a value. WDYT?

I think it is clear what happens with pointers to pointers given the current 
doc comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554



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


[PATCH] D69282: [RFC] Add a VCS conflict marker format printing on tooling::ReplacementError

2019-11-22 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added a reviewer: ioeric.
jdemeule added a comment.

Kindly ping reviewers and adding Eric as you were interested last year about 
that.


Repository:
  rC Clang

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

https://reviews.llvm.org/D69282



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


[PATCH] D69475: [clang] Provide better fix-it on exception spec error

2019-11-22 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added a comment.

Kindly ping reviewer.


Repository:
  rC Clang

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

https://reviews.llvm.org/D69475



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


[PATCH] D70485: [ARM,MVE] Add intrinsics to deal with predicates.

2019-11-22 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.

Thanks. I'm still happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70485



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


[clang] 26fa9e3 - Add support to find out resource dir and add it as compilation args

2019-11-22 Thread Kousik Kumar via cfe-commits

Author: Kousik Kumar
Date: 2019-11-22T07:43:54-08:00
New Revision: 26fa9e31f58a7ff693f3a5d8c2eb1b6a5a13b133

URL: 
https://github.com/llvm/llvm-project/commit/26fa9e31f58a7ff693f3a5d8c2eb1b6a5a13b133
DIFF: 
https://github.com/llvm/llvm-project/commit/26fa9e31f58a7ff693f3a5d8c2eb1b6a5a13b133.diff

LOG: Add support to find out resource dir and add it as compilation args

Summary:
If -resource-dir is not specified as part of the compilation command, then by 
default
clang-scan-deps picks up a directory relative to its own path as 
resource-directory.
This is probably not the right behavior - since resource directory should be 
picked relative
to the path of the clang-compiler in the compilation command.
This patch adds support for it along with a cache to store the resource-dir 
paths based on
compiler paths.

Notes:
1. "-resource-dir" is a behavior that's specific to clang, gcc does not have 
that flag. That's why if I'm not able to find a resource-dir, I quietly ignore 
it.
2. Should I also use the mtime of the compiler in the cache? I think its not 
strictly necessary since we assume the filesystem is immutable.
3. From my testing, this does not regress performance.
4. Will try to get this tested on Windows.

But basically the problem that this patch is trying to solve is, clients might 
not always want to specify
"-resource-dir" in their compile commands, so scan-deps must auto-infer it 
correctly.

Reviewers: arphaman, Bigcheese, jkorous, dexonsmith, klimek

Reviewed By: Bigcheese

Subscribers: MaskRay, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index bd463cbdeee9..1294e6682841 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -13,6 +13,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
@@ -39,6 +40,64 @@ class SharedStream {
   raw_ostream &OS;
 };
 
+class ResourceDirectoryCache {
+public:
+  /// findResourceDir finds the resource directory relative to the clang
+  /// compiler being used in Args, by running it with "-print-resource-dir"
+  /// option and cache the results for reuse. \returns resource directory path
+  /// associated with the given invocation command or empty string if the
+  /// compiler path is NOT an absolute path.
+  StringRef findResourceDir(const tooling::CommandLineArguments &Args) {
+if (Args.size() < 1)
+  return "";
+
+const std::string &ClangBinaryPath = Args[0];
+if (!llvm::sys::path::is_absolute(ClangBinaryPath))
+  return "";
+
+const std::string &ClangBinaryName =
+llvm::sys::path::filename(ClangBinaryPath);
+
+std::unique_lock LockGuard(CacheLock);
+const auto &CachedResourceDir = Cache.find(ClangBinaryPath);
+if (CachedResourceDir != Cache.end())
+  return CachedResourceDir->second;
+
+std::vector PrintResourceDirArgs{ClangBinaryName,
+"-print-resource-dir"};
+llvm::SmallString<64> OutputFile, ErrorFile;
+llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
+   "" /*no-suffix*/, OutputFile);
+llvm::sys::fs::createTemporaryFile("print-resource-dir-error",
+   "" /*no-suffix*/, ErrorFile);
+llvm::FileRemover OutputRemover(OutputFile.c_str());
+llvm::FileRemover ErrorRemover(ErrorFile.c_str());
+llvm::Optional Redirects[] = {
+{""}, // Stdin
+StringRef(OutputFile),
+StringRef(ErrorFile),
+};
+if (const int RC = llvm::sys::ExecuteAndWait(
+ClangBinaryPath, PrintResourceDirArgs, {}, Redirects)) {
+  auto ErrorBuf = llvm::MemoryBuffer::getFile(ErrorFile.c_str());
+  llvm::errs() << ErrorBuf.get()->getBuffer();
+  return "";
+}
+
+auto OutputBuf = llvm::MemoryBuffer::getFile(OutputFile.c_str());
+if (!OutputBuf)
+  return "";
+StringRef Output = OutputBuf.get()->getBuffer().rtrim('\n');
+
+Cache[ClangBinaryPath] = Output.str();
+return Cache[ClangBinaryPath];
+  }
+
+private:
+  std::map Cache;
+  std::mutex CacheLock;
+};
+
 llvm::cl::opt Help("h", llvm::cl::desc("Alias for -help"),
  llvm::cl::Hidden);
 
@@ -169,12 +228,15 @@ int main(int argc, const char **argv) {
   auto AdjustingCompilations =
   std::make_unique(
   std::move(Compilations));
+  ResourceDirectoryCache ResourceDirCache;
   AdjustingCompilations-

[PATCH] D69122: Add support to find out resource dir and add it as compilation args

2019-11-22 Thread Kousik Kumar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26fa9e31f58a: Add support to find out resource dir and add 
it as compilation args (authored by kousikk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69122

Files:
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -13,6 +13,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
@@ -39,6 +40,64 @@
   raw_ostream &OS;
 };
 
+class ResourceDirectoryCache {
+public:
+  /// findResourceDir finds the resource directory relative to the clang
+  /// compiler being used in Args, by running it with "-print-resource-dir"
+  /// option and cache the results for reuse. \returns resource directory path
+  /// associated with the given invocation command or empty string if the
+  /// compiler path is NOT an absolute path.
+  StringRef findResourceDir(const tooling::CommandLineArguments &Args) {
+if (Args.size() < 1)
+  return "";
+
+const std::string &ClangBinaryPath = Args[0];
+if (!llvm::sys::path::is_absolute(ClangBinaryPath))
+  return "";
+
+const std::string &ClangBinaryName =
+llvm::sys::path::filename(ClangBinaryPath);
+
+std::unique_lock LockGuard(CacheLock);
+const auto &CachedResourceDir = Cache.find(ClangBinaryPath);
+if (CachedResourceDir != Cache.end())
+  return CachedResourceDir->second;
+
+std::vector PrintResourceDirArgs{ClangBinaryName,
+"-print-resource-dir"};
+llvm::SmallString<64> OutputFile, ErrorFile;
+llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
+   "" /*no-suffix*/, OutputFile);
+llvm::sys::fs::createTemporaryFile("print-resource-dir-error",
+   "" /*no-suffix*/, ErrorFile);
+llvm::FileRemover OutputRemover(OutputFile.c_str());
+llvm::FileRemover ErrorRemover(ErrorFile.c_str());
+llvm::Optional Redirects[] = {
+{""}, // Stdin
+StringRef(OutputFile),
+StringRef(ErrorFile),
+};
+if (const int RC = llvm::sys::ExecuteAndWait(
+ClangBinaryPath, PrintResourceDirArgs, {}, Redirects)) {
+  auto ErrorBuf = llvm::MemoryBuffer::getFile(ErrorFile.c_str());
+  llvm::errs() << ErrorBuf.get()->getBuffer();
+  return "";
+}
+
+auto OutputBuf = llvm::MemoryBuffer::getFile(OutputFile.c_str());
+if (!OutputBuf)
+  return "";
+StringRef Output = OutputBuf.get()->getBuffer().rtrim('\n');
+
+Cache[ClangBinaryPath] = Output.str();
+return Cache[ClangBinaryPath];
+  }
+
+private:
+  std::map Cache;
+  std::mutex CacheLock;
+};
+
 llvm::cl::opt Help("h", llvm::cl::desc("Alias for -help"),
  llvm::cl::Hidden);
 
@@ -169,12 +228,15 @@
   auto AdjustingCompilations =
   std::make_unique(
   std::move(Compilations));
+  ResourceDirectoryCache ResourceDirCache;
   AdjustingCompilations->appendArgumentsAdjuster(
-  [](const tooling::CommandLineArguments &Args, StringRef FileName) {
+  [&ResourceDirCache](const tooling::CommandLineArguments &Args,
+  StringRef FileName) {
 std::string LastO = "";
 bool HasMT = false;
 bool HasMQ = false;
 bool HasMD = false;
+bool HasResourceDir = false;
 // We need to find the last -o value.
 if (!Args.empty()) {
   std::size_t Idx = Args.size() - 1;
@@ -188,6 +250,8 @@
 HasMQ = true;
   if (Args[Idx] == "-MD")
 HasMD = true;
+  if (Args[Idx] == "-resource-dir")
+HasResourceDir = true;
 }
 --Idx;
   }
@@ -215,6 +279,15 @@
 AdjustedArgs.push_back("-Xclang");
 AdjustedArgs.push_back("-sys-header-deps");
 AdjustedArgs.push_back("-Wno-error");
+
+if (!HasResourceDir) {
+  StringRef ResourceDir =
+  ResourceDirCache.findResourceDir(Args);
+  if (!ResourceDir.empty()) {
+AdjustedArgs.push_back("-resource-dir");
+AdjustedArgs.push_back(ResourceDir);
+  }
+}
 return AdjustedArgs;
   });
   AdjustingCompilations->appendArgumentsAdjuster(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62574: Initial draft of target-configurable address spaces.

2019-11-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan marked 2 inline comments as done.
ebevhan added a comment.

Sorry for the very late response on this. Hope it's not completely off your 
radar.




Comment at: include/clang/AST/ASTContext.h:2598
+  /// Returns true if address space A overlaps with B.
+  bool isAddressSpaceOverlapping(LangAS A, LangAS B) const {
+// A overlaps with B if either is a superset of the other.

Anastasia wrote:
> ebevhan wrote:
> > Anastasia wrote:
> > > ebevhan wrote:
> > > > Anastasia wrote:
> > > > > Is there any advantage of keeping superset&subset concept? Amd if 
> > > > > yes, how do we position the new functionality with explicit cast?
> > > > > 
> > > > > I think I am missing a bit conceptual view... because I think we 
> > > > > originally discussed to switch to implicit/explicit conversion model. 
> > > > > Perhaps there is no reason to do it but I would just like to 
> > > > > understand why? 
> > > > Yes, I know the original discussion was regarding the implicit/explicit 
> > > > model, but I came to realize during the implementation that all that 
> > > > was needed to get the superspace model to work generically with the 
> > > > current behavior was an override on the explicit conversion.
> > > > 
> > > > The implicit/explicit model also has the drawback that it's a bit too 
> > > > expressive. You can express semantics that just don't really make 
> > > > sense, like permitting implicit conversion but not explicit conversion. 
> > > > The superspace model doesn't let you do that, and the additions I've 
> > > > made here still don't: If implicit conversion is allowed, explicit 
> > > > conversion must also be allowed. It just becomes possible to allow 
> > > > explicit conversion for ASes that don't overlap.
> > > > 
> > > > Since the superspace model is what OpenCL and Embedded-C use in their 
> > > > specification, it's probably better to use that anyway.
> > > > The implicit/explicit model also has the drawback that it's a bit too 
> > > > expressive. You can express semantics that just don't really make 
> > > > sense, like permitting implicit conversion but not explicit conversion. 
> > > > The superspace model doesn't let you do that, and the additions I've 
> > > > made here still don't: If implicit conversion is allowed, explicit 
> > > > conversion must also be allowed. It just becomes possible to allow 
> > > > explicit conversion for ASes that don't overlap.
> > > 
> > > Ok, I think we could define the new model something like - explicit 
> > > conversions are automatically allowed for all implicit conversions... 
> > > targets won't have to specify those but only extra comversions that are 
> > > not allowed implicitly. 
> > > 
> > > Just to understand in the current patch when are we supposed to use 
> > > `isAddressSpaceOverlapping` and when 
> > > `isExplicitAddrSpaceConversionLegal`. Can't we just always use 
> > > `isExplicitAddrSpaceConversionLegal`?
> > > 
> > > > 
> > > > Since the superspace model is what OpenCL and Embedded-C use in their 
> > > > specification, it's probably better to use that anyway.
> > > 
> > > I agree the advantage of following spec is really huge. However, Clang is 
> > > already broken for Emdedded C isn't it? Because it allows any explicit 
> > > conversions?
> > > 
> > > As for OpenCL it might be reasonable to provide new documentation if 
> > > needed as soon as the new rules don't invalidate all behavior.
> > > 
> > > 
> > > Ok, I think we could define the new model something like - explicit 
> > > conversions are automatically allowed for all implicit conversions... 
> > > targets won't have to specify those but only extra comversions that are 
> > > not allowed implicitly.
> > 
> > Yes, this is how it's defined. Converting explicitly between two ASes where 
> > either one is a superset of the other is always legal.
> > 
> > > Just to understand in the current patch when are we supposed to use 
> > > isAddressSpaceOverlapping and when isExplicitAddrSpaceConversionLegal. 
> > > Can't we just always use isExplicitAddrSpaceConversionLegal?
> > 
> > I guess the distinction between `isAddressSpaceOverlapping` and 
> > `isExplicitAddrSpaceConversionLegal` is pretty subtle. You would want the 
> > former when you need to know if **implicit conversion A->B or B->A** is 
> > permitted, and the latter when you need to know if **explicit conversion 
> > A->B** is permitted.
> > 
> > Though in most cases, I think the latter is probably the most common.
> > 
> > > I agree the advantage of following spec is really huge. However, Clang is 
> > > already broken for Emdedded C isn't it? Because it allows any explicit 
> > > conversions?
> > 
> > No, the current behavior of permitting all explicit conversions is 
> > according to spec: "A non-null pointer into an address space A can be cast 
> > to a pointer into another address space B, but such a cast is undefined if 
> > the source pointer does not point to a location in B." The addi

[clang] 6f7c876 - [OPENMP]Fix behaviour of defaultmap for OpenMP 4.5.

2019-11-22 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2019-11-22T11:26:09-05:00
New Revision: 6f7c8760a5c01edaa8e9c8e48940e1b8a7aa4128

URL: 
https://github.com/llvm/llvm-project/commit/6f7c8760a5c01edaa8e9c8e48940e1b8a7aa4128
DIFF: 
https://github.com/llvm/llvm-project/commit/6f7c8760a5c01edaa8e9c8e48940e1b8a7aa4128.diff

LOG: [OPENMP]Fix behaviour of defaultmap for OpenMP 4.5.

In OpenMP 4.5 pointers also must be considered as scalar types and
defaultmap(tofrom:scalar) clause must affect mapping of the pointers
too.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_map_codegen.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 45cac595004f..53840d400164 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -1763,7 +1763,12 @@ void Sema::checkOpenMPDeviceExpr(const Expr *E) {
 }
 
 static OpenMPDefaultmapClauseKind
-getVariableCategoryFromDecl(const ValueDecl *VD) {
+getVariableCategoryFromDecl(const LangOptions &LO, const ValueDecl *VD) {
+  if (LO.OpenMP <= 45) {
+if (VD->getType().getNonReferenceType()->isScalarType())
+  return OMPC_DEFAULTMAP_scalar;
+return OMPC_DEFAULTMAP_aggregate;
+  }
   if (VD->getType().getNonReferenceType()->isAnyPointerType())
 return OMPC_DEFAULTMAP_pointer;
   if (VD->getType().getNonReferenceType()->isScalarType())
@@ -1894,8 +1899,8 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, 
unsigned Level,
   (DSAStack->isForceCaptureByReferenceInTargetExecutable() &&
!Ty->isAnyPointerType()) ||
   !Ty->isScalarType() ||
-  DSAStack->isDefaultmapCapturedByRef(Level,
-  getVariableCategoryFromDecl(D)) 
||
+  DSAStack->isDefaultmapCapturedByRef(
+  Level, getVariableCategoryFromDecl(LangOpts, D)) ||
   DSAStack->hasExplicitDSA(
   D, [](OpenMPClauseKind K) { return K == OMPC_reduction; }, 
Level);
 }
@@ -2112,8 +2117,8 @@ void Sema::setOpenMPCaptureKind(FieldDecl *FD, const 
ValueDecl *D,
 if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective,
NewLevel)) {
   OMPC = OMPC_map;
-  if (DSAStack->mustBeFirstprivateAtLevel(NewLevel,
-  getVariableCategoryFromDecl(D)))
+  if (DSAStack->mustBeFirstprivateAtLevel(
+  NewLevel, getVariableCategoryFromDecl(LangOpts, D)))
 OMPC = OMPC_firstprivate;
   break;
 }
@@ -2944,7 +2949,8 @@ class DSAAttrChecker final : public 
StmtVisitor {
   // data-haring attribute clause (including a data-sharing attribute
   // clause on a combined construct where target. is one of the
   // constituent constructs), or an is_device_ptr clause.
-  OpenMPDefaultmapClauseKind ClauseKind = getVariableCategoryFromDecl(VD);
+  OpenMPDefaultmapClauseKind ClauseKind =
+  getVariableCategoryFromDecl(SemaRef.getLangOpts(), VD);
   if (SemaRef.getLangOpts().OpenMP >= 50) {
 bool IsModifierNone = Stack->getDefaultmapModifier(ClauseKind) ==
   OMPC_DEFAULTMAP_MODIFIER_none;

diff  --git a/clang/test/OpenMP/target_map_codegen.cpp 
b/clang/test/OpenMP/target_map_codegen.cpp
index 0a8198a90417..cd1b5e49174e 100644
--- a/clang/test/OpenMP/target_map_codegen.cpp
+++ b/clang/test/OpenMP/target_map_codegen.cpp
@@ -656,15 +656,15 @@ void implicit_maps_pointer (){
 
 // CK11-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_double_complex{{.*}}_l678.region_id = 
weak constant i8 0
 
-// CK11-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i64] [i64 16]
+// CK11-DAG: [[SIZES:@.+]] = {{.+}}constant [2 x i64] [i64 16, i64 {{8|4}}]
 // Map types: OMP_MAP_TO  | OMP_MAP_FROM | OMP_MAP_TARGET_PARAM | 
OMP_MAP_IMPLICIT = 547
-// CK11-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 547]
+// CK11-DAG: [[TYPES:@.+]] = {{.+}}constant [2 x i64] [i64 547, i64 547]
 
 // CK11-LABEL: implicit_maps_double_complex{{.*}}(
-void implicit_maps_double_complex (int a){
+void implicit_maps_double_complex (int a, int *b){
   double _Complex dc = (double)a;
 
-  // CK11-DAG: call i32 @__tgt_target(i64 {{.+}}, i8* {{.+}}, i32 1, i8** 
[[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[SIZES]]{{.+}}, 
{{.+}}[[TYPES]]{{.+}})
+  // CK11-DAG: call i32 @__tgt_target(i64 {{.+}}, i8* {{.+}}, i32 2, i8** 
[[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[SIZES]]{{.+}}, 
{{.+}}[[TYPES]]{{.+}})
   // CK11-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BPS:%[^,]+]], i32 0, 
i32 0
   // CK11-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, 
i32 0
   // CK11-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0
@@ -674,14 +674,14 @@ void implicit_maps_double_complex (int a){
   // CK11-DAG: store { double, double }* [[PTR:%[^,]+]], { double, double }** 
[[CBP1]]
   // CK11-

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2925
+return C.getQualifiedType(T.getTypePtr(), Quals);
+  }
 case Type::DeducedTemplateSpecialization: {

You need to mark this `LLVM_FALLTHROUGH` now or you'll get a warning.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:3104
   case Type::Auto:
+if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
+  return CreateType(cast(Ty));

LLVM coding style doesn't put single statements into `{}`



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:3106
+  return CreateType(cast(Ty));
+}
   case Type::Attributed:

same here



Comment at: clang/test/CodeGenCXX/debug-info-auto-return.cpp:7
+
+// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: !18
+// CHECK: !18 =  !DISubroutineType(types: !19)

Please don't hardcode the MDNode numbers, they will inevitably change over 
time. Instead use variables:
```
type: ![[SUBROUTINE_TYPE:[0-9]+]]`
// CHECK: ![[SUBROUTINE_TYPE]] =  !DISubroutineType(types: ![[ARGS:[0-9]+)
```
etc


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

https://reviews.llvm.org/D70524



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


[clang] 0b3d1d1 - [coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves

2019-11-22 Thread Brian Gesiak via cfe-commits

Author: Brian Gesiak
Date: 2019-11-22T11:39:13-05:00
New Revision: 0b3d1d1348da78c8b12e89f138577b0a8ffd4b2f

URL: 
https://github.com/llvm/llvm-project/commit/0b3d1d1348da78c8b12e89f138577b0a8ffd4b2f
DIFF: 
https://github.com/llvm/llvm-project/commit/0b3d1d1348da78c8b12e89f138577b0a8ffd4b2f.diff

LOG: [coroutines] Remove assert on CoroutineParameterMoves in 
Sema::buildCoroutineParameterMoves

Summary:
The assertion of CoroutineParameterMoves happens when build coroutine function 
with arguments  multiple time while fails to build promise type.

Fix: use return false instead.

Test Plan: check-clang

Reviewers: modocache, GorNishanov, rjmccall

Reviewed By: modocache

Subscribers: rjmccall, EricWF, cfe-commits

Tags: #clang

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

Patch by junparser (JunMa)!

Added: 


Modified: 
clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutines.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 7c125e999d00..271c4a10f3e4 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1527,8 +1527,8 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
   auto *FD = cast(CurContext);
 
   auto *ScopeInfo = getCurFunction();
-  assert(ScopeInfo->CoroutineParameterMoves.empty() &&
- "Should not build parameter moves twice");
+  if (!ScopeInfo->CoroutineParameterMoves.empty())
+return false;
 
   for (auto *PD : FD->parameters()) {
 if (PD->getType()->isDependentType())

diff  --git a/clang/test/SemaCXX/coroutines.cpp 
b/clang/test/SemaCXX/coroutines.cpp
index c8de7b017859..677c6e6ff8d2 100644
--- a/clang/test/SemaCXX/coroutines.cpp
+++ b/clang/test/SemaCXX/coroutines.cpp
@@ -87,6 +87,11 @@ int no_promise_type() { // expected-error {{this function 
cannot be a coroutine:
   co_await a;
 }
 
+int no_promise_type_multiple_awaits(int) { // expected-error {{this function 
cannot be a coroutine: 'std::experimental::coroutine_traits' has no 
member named 'promise_type'}}
+  co_await a;
+  co_await a;
+}
+
 template <>
 struct std::experimental::coroutine_traits { typedef int 
promise_type; };
 double bad_promise_type(double) { // expected-error {{this function cannot be 
a coroutine: 'experimental::coroutine_traits::promise_type' 
(aka 'int') is not a class}}



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


[PATCH] D69022: [coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves

2019-11-22 Thread Brian Gesiak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b3d1d1348da: [coroutines] Remove assert on 
CoroutineParameterMoves in Sema… (authored by modocache).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69022

Files:
  clang/lib/Sema/SemaCoroutine.cpp
  clang/test/SemaCXX/coroutines.cpp


Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -87,6 +87,11 @@
   co_await a;
 }
 
+int no_promise_type_multiple_awaits(int) { // expected-error {{this function 
cannot be a coroutine: 'std::experimental::coroutine_traits' has no 
member named 'promise_type'}}
+  co_await a;
+  co_await a;
+}
+
 template <>
 struct std::experimental::coroutine_traits { typedef int 
promise_type; };
 double bad_promise_type(double) { // expected-error {{this function cannot be 
a coroutine: 'experimental::coroutine_traits::promise_type' 
(aka 'int') is not a class}}
Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -1527,8 +1527,8 @@
   auto *FD = cast(CurContext);
 
   auto *ScopeInfo = getCurFunction();
-  assert(ScopeInfo->CoroutineParameterMoves.empty() &&
- "Should not build parameter moves twice");
+  if (!ScopeInfo->CoroutineParameterMoves.empty())
+return false;
 
   for (auto *PD : FD->parameters()) {
 if (PD->getType()->isDependentType())


Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -87,6 +87,11 @@
   co_await a;
 }
 
+int no_promise_type_multiple_awaits(int) { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits' has no member named 'promise_type'}}
+  co_await a;
+  co_await a;
+}
+
 template <>
 struct std::experimental::coroutine_traits { typedef int promise_type; };
 double bad_promise_type(double) { // expected-error {{this function cannot be a coroutine: 'experimental::coroutine_traits::promise_type' (aka 'int') is not a class}}
Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -1527,8 +1527,8 @@
   auto *FD = cast(CurContext);
 
   auto *ScopeInfo = getCurFunction();
-  assert(ScopeInfo->CoroutineParameterMoves.empty() &&
- "Should not build parameter moves twice");
+  if (!ScopeInfo->CoroutineParameterMoves.empty())
+return false;
 
   for (auto *PD : FD->parameters()) {
 if (PD->getType()->isDependentType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69022: [coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves

2019-11-22 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added a comment.

Thanks again for the patch @junparser! And sorry the review took so long!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69022



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


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:30
+; CHECK:  DW_TAG_subprogram [7] *
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (0007) string 
= "_ZN7myClass7findMaxEv")
+; CHECK: DW_AT_type [DW_FORM_ref4] {{.*}} "auto"

No need to over-specify this (form/index etc) as those details can change over 
time and aren't relevant to the test.  Sufficient to check
`DW_AT_linkage_name {{.*}} "_ZN7myClass7findMaxEv"`



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

https://reviews.llvm.org/D70524



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


[PATCH] D70368: [clang-tidy] Rewrite modernize-avoid-bind check

2019-11-22 Thread Zachary Turner via Phabricator via cfe-commits
zturner updated this revision to Diff 230661.
zturner added a comment.

Addressed suggestions from @Eugene.Zelenko


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

https://reviews.llvm.org/D70368

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize-avoid-bind.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind-permissive-parameter-list.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
@@ -8,75 +8,62 @@
 template 
 bind_rt bind(Fp &&, Arguments &&...);
 }
+
+template 
+T ref(T &t);
 }
 
-int add(int x, int y) { return x + y; }
+namespace boost {
+template 
+class bind_rt {};
 
-void f() {
-  auto clj = std::bind(add, 2, 2);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
-  // CHECK-FIXES: auto clj = [] { return add(2, 2); };
-}
+template 
+bind_rt bind(const Fp &, Arguments...);
 
-void g() {
-  int x = 2;
-  int y = 2;
-  auto clj = std::bind(add, x, y);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // CHECK-FIXES: auto clj = [=] { return add(x, y); };
+template 
+struct reference_wrapper {
+  explicit reference_wrapper(T &t) {}
+};
+
+template 
+reference_wrapper const ref(T &t) {
+  return reference_wrapper(t);
 }
 
-struct placeholder {};
-placeholder _1;
-placeholder _2;
+} // namespace boost
 
-void h() {
-  int x = 2;
-  auto clj = std::bind(add, x, _1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // CHECK-FIXES: auto clj = [=](auto && arg1) { return add(x, arg1); };
-}
+namespace C {
+int add(int x, int y) { return x + y; }
+} // namespace C
 
-struct A;
-struct B;
-bool ABTest(const A &, const B &);
+struct Foo {
+  static int add(int x, int y) { return x + y; }
+};
 
-void i() {
-  auto BATest = std::bind(ABTest, _2, _1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer a lambda to std::bind
-  // CHECK-FIXES: auto BATest = [](auto && arg1, auto && arg2) { return ABTest(arg2, arg1); };
-}
+struct D {
+  D() = default;
+  void operator()(int x, int y) const {}
 
-void j() {
-  auto clj = std::bind(add, 2, 2, 2);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // No fix is applied for argument mismatches.
-  // CHECK-FIXES: auto clj = std::bind(add, 2, 2, 2);
-}
+  void MemberFunction(int x) {}
 
-void k() {
-  auto clj = std::bind(add, _1, _1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // No fix is applied for reused placeholders.
-  // CHECK-FIXES: auto clj = std::bind(add, _1, _1);
-}
+  static D *create();
+};
 
-void m() {
-  auto clj = std::bind(add, 1, add(2, 5));
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // No fix is applied for nested calls.
-  // CHECK-FIXES: auto clj = std::bind(add, 1, add(2, 5));
-}
+struct F {
+  F(int x) {}
+  ~F() {}
 
-namespace C {
-  int add(int x, int y){ return x + y; }
-}
+  int get() { return 42; }
+};
 
-void n() {
-  auto clj = std::bind(C::add, 1, 1);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
-  // CHECK-FIXES: auto clj = [] { return C::add(1, 1); };
-}
+void UseF(F);
+
+struct placeholder {};
+placeholder _1;
+placeholder _2;
+
+int add(int x, int y) { return x + y; }
+int addThree(int x, int y, int z) { return x + y + z; }
 
 // Let's fake a minimal std::function-like facility.
 namespace std {
@@ -114,10 +101,213 @@
   void Reset(std::function);
 };
 
-void test(Thing *t) {
+int GlobalVariable = 42;
+
+struct TestCaptureByValueStruct {
+  int MemberVariable;
+  static int StaticMemberVariable;
+  F MemberStruct;
+
+  void testCaptureByValue(int Param, F f) {
+int x = 3;
+int y = 4;
+auto AAA = std::bind(add, x, y);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind [modernize-avoid-bind]
+// CHECK-FIXES: auto AAA = [x, y] { return add(x, y); };
+
+// When the captured variable is repeated, it should only appear in the capture list once.
+auto BBB = std::bind(add, x, x);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind [modernize-avoid-bind]
+// CHECK-FIXES: auto BBB = [x] { return add(x, x); };
+
+int LocalVariable;
+// Global variables shouldn't be captured at all, and members should be captured through this.
+auto CCC = std::bind(add, MemberVariable, GlobalVariable);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind [modernize-avoid-bind]
+// CHECK-

[clang] 5459a90 - [OPENMP]Simplify processing of context selectors, NFC.

2019-11-22 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2019-11-22T11:53:06-05:00
New Revision: 5459a905c23c03fad68e80b2dff23ca1ca3b7c7c

URL: 
https://github.com/llvm/llvm-project/commit/5459a905c23c03fad68e80b2dff23ca1ca3b7c7c
DIFF: 
https://github.com/llvm/llvm-project/commit/5459a905c23c03fad68e80b2dff23ca1ca3b7c7c.diff

LOG: [OPENMP]Simplify processing of context selectors, NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c2d895b4ea4a..f80249483c7a 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11138,33 +11138,22 @@ bool checkContext(
 bool matchesContext(CodeGenModule &CGM,
 const CompleteOMPContextSelectorData &ContextData) {
   for (const OMPContextSelectorData &Data : ContextData) {
-switch (Data.CtxSet) {
-case OMP_CTX_SET_implementation:
-  switch (Data.Ctx) {
-  case OMP_CTX_vendor:
-if (!checkContext(Data))
-  return false;
-break;
-  case OMP_CTX_kind:
-  case OMP_CTX_unknown:
-llvm_unreachable(
-"Unexpected context selector kind in implementation set.");
-  }
+switch (Data.Ctx) {
+case OMP_CTX_vendor:
+  assert(Data.CtxSet == OMP_CTX_SET_implementation &&
+ "Expected implementation context selector set.");
+  if (!checkContext(Data))
+return false;
   break;
-case OMP_CTX_SET_device:
-  switch (Data.Ctx) {
-  case OMP_CTX_kind:
-if (!checkContext(
-Data, CGM))
-  return false;
-break;
-  case OMP_CTX_vendor:
-  case OMP_CTX_unknown:
-llvm_unreachable("Unexpected context selector kind in device set.");
-  }
+case OMP_CTX_kind:
+  assert(Data.CtxSet == OMP_CTX_SET_device &&
+ "Expected device context selector set.");
+  if (!checkContext(Data,
+   
CGM))
+return false;
   break;
-case OMP_CTX_SET_unknown:
-  llvm_unreachable("Unexpected context selector set kind.");
+case OMP_CTX_unknown:
+  llvm_unreachable("Unknown context selector kind.");
 }
   }
   return true;
@@ -11184,32 +11173,21 @@ translateAttrToContextSelectorData(ASTContext &C,
 Data.back().Ctx = Ctx;
 const Expr *Score = *std::next(A->scores_begin(), I);
 Data.back().Score = Score->EvaluateKnownConstInt(C);
-switch (CtxSet) {
-case OMP_CTX_SET_implementation:
-  switch (Ctx) {
-  case OMP_CTX_vendor:
-Data.back().Names =
-llvm::makeArrayRef(A->implVendors_begin(), A->implVendors_end());
-break;
-  case OMP_CTX_kind:
-  case OMP_CTX_unknown:
-llvm_unreachable(
-"Unexpected context selector kind in implementation set.");
-  }
+switch (Ctx) {
+case OMP_CTX_vendor:
+  assert(CtxSet == OMP_CTX_SET_implementation &&
+ "Expected implementation context selector set.");
+  Data.back().Names =
+  llvm::makeArrayRef(A->implVendors_begin(), A->implVendors_end());
   break;
-case OMP_CTX_SET_device:
-  switch (Ctx) {
-  case OMP_CTX_kind:
-Data.back().Names =
-llvm::makeArrayRef(A->deviceKinds_begin(), A->deviceKinds_end());
-break;
-  case OMP_CTX_vendor:
-  case OMP_CTX_unknown:
-llvm_unreachable("Unexpected context selector kind in device set.");
-  }
+case OMP_CTX_kind:
+  assert(CtxSet == OMP_CTX_SET_device &&
+ "Expected device context selector set.");
+  Data.back().Names =
+  llvm::makeArrayRef(A->deviceKinds_begin(), A->deviceKinds_end());
   break;
-case OMP_CTX_SET_unknown:
-  llvm_unreachable("Unexpected context selector set kind.");
+case OMP_CTX_unknown:
+  llvm_unreachable("Unknown context selector kind.");
 }
   }
   return Data;

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 53840d400164..59178fb671fb 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5404,29 +5404,19 @@ void Sema::ActOnOpenMPDeclareVariantDirective(
   else
 Score = ActOnIntegerConstant(SourceLocation(), 0).get();
 }
-switch (CtxSet) {
-case OMP_CTX_SET_implementation:
-  switch (Ctx) {
-  case OMP_CTX_vendor:
-ImplVendors.append(D.Names.begin(), D.Names.end());
-break;
-  case OMP_CTX_kind:
-  case OMP_CTX_unknown:
-llvm_unreachable("Unexpected context selector kind.");
-  }
+switch (Ctx) {
+case OMP_CTX_vendor:
+  assert(CtxSet == OMP_CTX_SET_implementation &&
+ "Expected implementation context selector set.");
+  ImplVendors.append(D.Names.begin(), D.Nam

[PATCH] D70368: [clang-tidy] Rewrite modernize-avoid-bind check

2019-11-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:194
+  The check now supports supports diagnosing and fixing arbitrary callables 
instead of
+  only simple free functions. The ``PermissiveParameterList`` option has also 
been
+  added to address situations where the existing fix-it logic would sometimes 
generate

Please use single back-tics for options.



Comment at: clang-tools-extra/docs/clang-tidy/checks/modernize-avoid-bind.rst:50
+  If the option is set to non-zero, the check will append ``auto&&...`` to the 
end
+  of every placeholder parameter list.  Without this, it is possible for a 
fixit
+  to perform an incorrect transformation in the case where the result of the 
``bind``

Double space here and in other places are still not fixed. Same for fixit.


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

https://reviews.llvm.org/D70368



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


[PATCH] D70470: [analyzer] Add FuchsiaHandleCheck to catch handle leaks, use after frees and double frees

2019-11-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 230668.
xazax.hun added a comment.

- Fix member operator modeling.
- Added new lines to the end of files.
- Added documentation.
- Minor typo fixes in tests.


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

https://reviews.llvm.org/D70470

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
  clang/test/Analysis/fuchsia_handle.cpp

Index: clang/test/Analysis/fuchsia_handle.cpp
===
--- /dev/null
+++ clang/test/Analysis/fuchsia_handle.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,fuchsia.HandleChecker -verify %s
+
+typedef __typeof__(sizeof(int)) size_t;
+typedef int zx_status_t;
+typedef __typeof__(sizeof(int)) zx_handle_t;
+typedef unsigned int uint32_t;
+#define NULL ((void *)0)
+
+#if defined(__clang__)
+#define ZX_HANDLE_ACQUIRE  __attribute__((acquire_handle))
+#define ZX_HANDLE_RELEASE  __attribute__((release_handle))
+#define ZX_HANDLE_USE  __attribute__((use_handle))
+#else
+#define ZX_HANDLE_ACQUIRE
+#define ZX_HANDLE_RELEASE
+#define ZX_HANDLE_USE
+#endif
+
+zx_status_t zx_channel_create(
+uint32_t options,
+ZX_HANDLE_ACQUIRE zx_handle_t* out0,
+zx_handle_t* out1 ZX_HANDLE_ACQUIRE);
+
+zx_status_t zx_handle_close(
+zx_handle_t handle ZX_HANDLE_RELEASE);
+
+void escape1(zx_handle_t *in);
+void escape2(zx_handle_t in);
+
+void use1(const zx_handle_t *in ZX_HANDLE_USE);
+void use2(zx_handle_t in ZX_HANDLE_USE);
+
+// To test if argument indexes are OK for operator calls.
+struct MyType {
+  ZX_HANDLE_ACQUIRE
+  zx_handle_t operator+(zx_handle_t replace ZX_HANDLE_RELEASE);
+};
+
+void checkNoLeak01() {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  zx_handle_close(sa);
+  zx_handle_close(sb);
+}
+
+void checkNoLeak02() {
+  zx_handle_t ay[2];
+  zx_channel_create(0, &ay[0], &ay[1]);
+  zx_handle_close(ay[0]);
+  zx_handle_close(ay[1]);
+}
+
+void checkNoLeak03() {
+  zx_handle_t ay[2];
+  zx_channel_create(0, &ay[0], &ay[1]);
+  for (int i = 0; i < 2; i++)
+zx_handle_close(ay[i]);
+}
+
+zx_handle_t checkNoLeak04() {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  zx_handle_close(sa);
+  return sb; // no warning
+}
+
+zx_handle_t checkNoLeak05(zx_handle_t *out1) {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  *out1 = sa;
+  return sb; // no warning
+}
+
+void checkNoLeak06() {
+  zx_handle_t sa, sb;
+  if (zx_channel_create(0, &sa, &sb))
+return;
+  zx_handle_close(sa);
+  zx_handle_close(sb);
+} 
+
+void checkNoLeak07(int tag) {
+  zx_handle_t sa, sb;
+  if (zx_channel_create(0, &sa, &sb))
+return;
+  escape1(&sa);
+  escape2(sb);
+}
+
+void checkLeak01(int tag) {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  use1(&sa);
+  if (tag)
+zx_handle_close(sa);
+  use2(sb); // expected-warning {{Potential leak of handle}}
+  zx_handle_close(sb);
+}
+
+void checkDoubleRelease01(int tag) {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  if (tag)
+zx_handle_close(sa);
+  zx_handle_close(sa); // expected-warning {{Releasing a previously released handle}}
+  zx_handle_close(sb);
+}
+
+void checkUseAfterFree01(int tag) {
+  zx_handle_t sa, sb;
+  zx_channel_create(0, &sa, &sb);
+  if (tag) {
+zx_handle_close(sa);
+use1(&sa); // expected-warning {{Using a previously released handle}}
+  }
+  zx_handle_close(sb);
+  use2(sb); // expected-warning {{Using a previously released handle}}
+}
+
+void checkMemberOperatorIndices() {
+  zx_handle_t sa, sb, sc;
+  zx_channel_create(0, &sa, &sb);
+  zx_handle_close(sb);
+  MyType t;
+  sc = t + sa;
+  zx_handle_close(sc);
+}
Index: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
===
--- /dev/null
+++ clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -0,0 +1,457 @@
+//=== FuchsiaHandleChecker.cpp - Find handle leaks/double closes -*- C++ -*--=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This checker checks if the handle of Fuchsia is properly used according to
+// following rules.
+//   - If a handle is acquired, it should be released before execution
+//ends.
+//   - If a handle is released, it should not be released again.
+//   - If a handle is released, it should not be used for other purposes
+//such as I/O.
+//
+// In this checker, each tracked handle is associated with a state. When the
+

[PATCH] D70572: [Serialization] #pragma clang transform

2019-11-22 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 230670.
Meinersbur added a comment.

- Remove some leftovers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70572

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/transform-interleave.cpp
  clang/test/PCH/transform-unroll.cpp
  clang/test/PCH/transform-unrollandjam.cpp
  clang/test/PCH/transform-vectorize.cpp

Index: clang/test/PCH/transform-vectorize.cpp
===
--- /dev/null
+++ clang/test/PCH/transform-vectorize.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -emit-pch -o %t.pch %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -include-pch %t.pch %s -ast-dump-all -o - | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+
+void vectorize_heuristic(int n) {
+#pragma clang transform vectorize
+  for (int i = 0; i < n; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported vectorize_heuristic
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: ForStmt
+
+
+void vectorize_width(int n) {
+#pragma clang transform vectorize width(4)
+  for (int i = 0; i < n; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported vectorize_width
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: WidthClause
+// CHECK-NEXT:   IntegerLiteral {{.*}} 'int' 4
+// CHECK-NEXT: ForStmt
+
+#endif /* HEADER */
Index: clang/test/PCH/transform-unrollandjam.cpp
===
--- /dev/null
+++ clang/test/PCH/transform-unrollandjam.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -emit-pch -o %t.pch %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -include-pch %t.pch %s -ast-dump-all -o - | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+
+void  unrollandjam_heuristic(int n) {
+#pragma clang transform unrollandjam
+  for (int i = 0; i < n; i+=1)
+for (int j = 0; j < n; j+=1)
+  ;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unrollandjam_heuristic
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: ForStmt
+
+
+void unrollandjam_partial(int n) {
+#pragma clang transform unrollandjam partial(4)
+  for (int i = 0; i < n; i+=1)
+for (int j = 0; j < n; j+=1)
+  ;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unrollandjam_partial
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: PartialClause
+// CHECK-NEXT:   IntegerLiteral {{.*}} 'int' 4
+// CHECK-NEXT: ForStmt
+
+#endif /* HEADER */
Index: clang/test/PCH/transform-unroll.cpp
===
--- /dev/null
+++ clang/test/PCH/transform-unroll.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -emit-pch -o %t.pch %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexperimental-transform-pragma -include-pch %t.pch %s -ast-dump-all -o - | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+
+void  unroll_heuristic(int n) {
+#pragma clang transform unroll
+  for (int i = 0; i < 4; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unroll_heuristic
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: ForStmt
+
+
+void unroll_full(int n) {
+#pragma clang transform unroll full
+  for (int i = 0; i < 4; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unroll_full
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: FullClause
+// CHECK-NEXT: ForStmt
+
+
+void unroll_partial(int n) {
+#pragma clang transform unroll partial(4)
+  for (int i = 0; i < n; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unroll_partial
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: PartialClause
+// CHECK-NEXT:   IntegerLiteral {{.*}} 'int' 4
+// CHECK-NEXT: ForStmt
+
+
+template
+void unroll_template_function(int n) {
+#pragma clang transform unroll partial(FACTOR)
+  for (int i = 0; i < n; i+=1)
+;
+}
+// CHECK-LABEL: FunctionDecl {{.*}} imported unroll_template_function
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: PartialClause
+// CHECK-NEXT:   DeclRefExpr {{.*}} 'FACTOR' 'int'
+// CHECK-NEXT: ForStmt
+
+
+template void unroll_template_function<5>(int);
+// CHECK-LABEL: FunctionDecl {{.*}} imported unroll_template_function
+// CHECK: TransformExecutableDirective
+// CHECK-NEXT: PartialClause
+// CHECK-NEXT:   SubstNonTypeTemplateParmExpr
+// CHECK-NEXT:   IntegerLiteral {{.*}} 'int' 5
+// CHECK-NEXT: ForStmt
+
+
+template
+struct Unroll {
+  void unroll_template_method(in

[PATCH] D70551: [clang-offload-wrapper] Add data layout to the wrapper bitcode

2019-11-22 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev added a comment.

Ok, it is possible to do it like you suggested, but I think that teaching 
wrapper tool to set data layout without external help is more preferable. There 
is a certain difference between opt and wrapper tool – opt works on the 
existing .bc that is provided in command line and data-layout option just gives 
user an optional way to override input’s data layout while wrapper tool creates 
output .bc from scratch. With your proposal, data-layout would become sort of 
mandatory option for the wrapper tool which is not very convenient. I believe 
wrapper tool should be able to set it without external help, and we can always 
add an option to override data layout (similar to opt) if there would be a need 
for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70551



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


[PATCH] D69180: [Format] Add format check for coroutine keywords with negative numbers

2019-11-22 Thread Jonathan Thomas via Phabricator via cfe-commits
jonathoma added a comment.

@modocache Feel free to commit from my end! Thanks again :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69180



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


[PATCH] D70551: [clang-offload-wrapper] Add data layout to the wrapper bitcode

2019-11-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D70551#1756997 , @sdmitriev wrote:

> Ok, it is possible to do it like you suggested, but I think that teaching 
> wrapper tool to set data layout without external help is more preferable. 
> There is a certain difference between opt and wrapper tool – opt works on the 
> existing .bc that is provided in command line and data-layout option just 
> gives user an optional way to override input’s data layout while wrapper tool 
> creates output .bc from scratch. With your proposal, data-layout would become 
> sort of mandatory option for the wrapper tool which is not very convenient. I 
> believe wrapper tool should be able to set it without external help, and we 
> can always add an option to override data layout (similar to opt) if there 
> would be a need for that.


Why it is not convenient? Plus, when you're trying to build the data layout 
yourself, you end up with the default one for the given target rather than rely 
on the one specified by the user when the driver was invoked. So, I think, it 
would be better to get the data layout from the driver rather than use the 
default one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70551



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


[clang] 01e8dd2 - [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2019-11-22T12:36:40-05:00
New Revision: 01e8dd2e7a852794a60e50f356f171f893503598

URL: 
https://github.com/llvm/llvm-project/commit/01e8dd2e7a852794a60e50f356f171f893503598
DIFF: 
https://github.com/llvm/llvm-project/commit/01e8dd2e7a852794a60e50f356f171f893503598.diff

LOG: [libTooling] Add stencil combinators for nodes that may be pointers or 
values.

Summary:
Adds combinators `maybeDeref` and `maybeAddressOf` to provide a uniform way to 
handle
nodes which may be bound to either a pointer or a value (most often in the
context of member expressions). Such polymorphism is already supported by
`access`; these combinators extend it to more general uses.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/Stencil.h
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/Tooling/StencilTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index dd65e68b7e8a..0363b689dc5b 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -87,11 +87,24 @@ Stencil expression(llvm::StringRef Id);
 /// \p ExprId is wrapped in parentheses, if needed.
 Stencil deref(llvm::StringRef ExprId);
 
+/// If \p ExprId is of pointer type, constructs an idiomatic dereferencing of
+/// the expression bound to \p ExprId, including wrapping it in parentheses, if
+/// needed. Otherwise, generates the original expression source.
+/// FIXME: Identify smart-pointers as pointer types.
+Stencil maybeDeref(llvm::StringRef ExprId);
+
 /// Constructs an expression that idiomatically takes the address of the
 /// expression bound to \p ExprId. \p ExprId is wrapped in parentheses, if
 /// needed.
 Stencil addressOf(llvm::StringRef ExprId);
 
+/// If \p ExprId is not a pointer type, constructs an expression that
+/// idiomatically takes the address of the expression bound to \p ExprId,
+/// including wrapping \p ExprId in parentheses, if needed. Otherwise, 
generates
+/// the original expression source.
+/// FIXME: Identify smart-pointers as pointer types.
+Stencil maybeAddressOf(llvm::StringRef ExprId);
+
 /// Constructs a `MemberExpr` that accesses the named member (\p Member) of the
 /// object bound to \p BaseId. The access is constructed idiomatically: if \p
 /// BaseId is bound to `e` and \p Member identifies member `m`, then returns

diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index 486e18b341f7..8710e3cdf60f 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -59,7 +59,9 @@ struct DebugPrintNodeData {
 enum class UnaryNodeOperator {
   Parens,
   Deref,
-  Address,
+  MaybeDeref,
+  AddressOf,
+  MaybeAddressOf,
 };
 
 // Generic container for stencil operations with a (single) node-id argument.
@@ -121,9 +123,15 @@ std::string toStringData(const UnaryOperationData &Data) {
   case UnaryNodeOperator::Deref:
 OpName = "deref";
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+OpName = "maybeDeref";
+break;
+  case UnaryNodeOperator::AddressOf:
 OpName = "addressOf";
 break;
+  case UnaryNodeOperator::MaybeAddressOf:
+OpName = "maybeAddressOf";
+break;
   }
   return (OpName + "(\"" + Data.Id + "\")").str();
 }
@@ -191,7 +199,21 @@ Error evalData(const UnaryOperationData &Data,
   case UnaryNodeOperator::Deref:
 Source = tooling::buildDereference(*E, *Match.Context);
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+if (!E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
+Source = tooling::buildDereference(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::AddressOf:
+Source = tooling::buildAddressOf(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::MaybeAddressOf:
+if (E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
 Source = tooling::buildAddressOf(*E, *Match.Context);
 break;
   }
@@ -300,9 +322,19 @@ Stencil transformer::deref(llvm::StringRef ExprId) {
   UnaryNodeOperator::Deref, ExprId);
 }
 
+Stencil transformer::maybeDeref(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeDeref, ExprId);
+}
+
 Stencil transformer::addressOf(llvm::StringRef ExprId) {
   return std::make_shared>(
-  UnaryNodeOperator::Address, ExprId);
+  UnaryNodeOperator::AddressOf, ExprId);
+}
+
+Stencil transformer::maybeAddressOf(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  Una

[PATCH] D70554: [libTooling] Add stencil combinators for nodes that may be pointers or values.

2019-11-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
ymandel marked an inline comment as done.
Closed by commit rG01e8dd2e7a85: [libTooling] Add stencil combinators for nodes 
that may be pointers or values. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70554

Files:
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -233,6 +233,46 @@
   testExpr(Id, "int *x; *x;", addressOf(Id), "x");
 }
 
+TEST_F(StencilTest, MaybeDerefValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeDerefPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeDeref(Id), "*x");
+}
+
+TEST_F(StencilTest, MaybeDerefBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x + 1;", maybeDeref(Id), "*(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeDerefAddressExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; &x;", maybeDeref(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfPointer) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; x;", maybeAddressOf(Id), "x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfValue) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x;", addressOf(Id), "&x");
+}
+
+TEST_F(StencilTest, MaybeAddressOfBinOp) {
+  StringRef Id = "id";
+  testExpr(Id, "int x; x + 1;", maybeAddressOf(Id), "&(x + 1)");
+}
+
+TEST_F(StencilTest, MaybeAddressOfDerefExpr) {
+  StringRef Id = "id";
+  testExpr(Id, "int *x; *x;", addressOf(Id), "x");
+}
+
 TEST_F(StencilTest, AccessOpValue) {
   StringRef Snippet = R"cc(
 S x;
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -59,7 +59,9 @@
 enum class UnaryNodeOperator {
   Parens,
   Deref,
-  Address,
+  MaybeDeref,
+  AddressOf,
+  MaybeAddressOf,
 };
 
 // Generic container for stencil operations with a (single) node-id argument.
@@ -121,9 +123,15 @@
   case UnaryNodeOperator::Deref:
 OpName = "deref";
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+OpName = "maybeDeref";
+break;
+  case UnaryNodeOperator::AddressOf:
 OpName = "addressOf";
 break;
+  case UnaryNodeOperator::MaybeAddressOf:
+OpName = "maybeAddressOf";
+break;
   }
   return (OpName + "(\"" + Data.Id + "\")").str();
 }
@@ -191,7 +199,21 @@
   case UnaryNodeOperator::Deref:
 Source = tooling::buildDereference(*E, *Match.Context);
 break;
-  case UnaryNodeOperator::Address:
+  case UnaryNodeOperator::MaybeDeref:
+if (!E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
+Source = tooling::buildDereference(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::AddressOf:
+Source = tooling::buildAddressOf(*E, *Match.Context);
+break;
+  case UnaryNodeOperator::MaybeAddressOf:
+if (E->getType()->isAnyPointerType()) {
+  *Result += tooling::getText(*E, *Match.Context);
+  return Error::success();
+}
 Source = tooling::buildAddressOf(*E, *Match.Context);
 break;
   }
@@ -300,9 +322,19 @@
   UnaryNodeOperator::Deref, ExprId);
 }
 
+Stencil transformer::maybeDeref(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeDeref, ExprId);
+}
+
 Stencil transformer::addressOf(llvm::StringRef ExprId) {
   return std::make_shared>(
-  UnaryNodeOperator::Address, ExprId);
+  UnaryNodeOperator::AddressOf, ExprId);
+}
+
+Stencil transformer::maybeAddressOf(llvm::StringRef ExprId) {
+  return std::make_shared>(
+  UnaryNodeOperator::MaybeAddressOf, ExprId);
 }
 
 Stencil transformer::access(StringRef BaseId, Stencil Member) {
Index: clang/include/clang/Tooling/Transformer/Stencil.h
===
--- clang/include/clang/Tooling/Transformer/Stencil.h
+++ clang/include/clang/Tooling/Transformer/Stencil.h
@@ -87,11 +87,24 @@
 /// \p ExprId is wrapped in parentheses, if needed.
 Stencil deref(llvm::StringRef ExprId);
 
+/// If \p ExprId is of pointer type, constructs an idiomatic dereferencing of
+/// the expression bound to \p ExprId, including wrapping it in parentheses, if
+/// needed. Otherwise, generates the original expression source.
+/// FIXME: Identify smart-pointers as pointer types.
+Stencil maybeDeref(llvm::StringRef ExprId);
+
 /// Constructs an expression that idiomatically takes the address of the
 /// expression bound to \p ExprId. \p ExprId is wrapped in parentheses, if
 /// needed

[PATCH] D70603: Change while to do-while

2019-11-22 Thread Seija Kijin via Phabricator via cfe-commits
pi1024e created this revision.
pi1024e added a project: LLVM.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
pi1024e added a reviewer: llvm.org.
pi1024e edited reviewers, added: modocache, sammccall, Quuxplusone; removed: 
llvm.org.

The assert statement says that the location must be a macroID, which is true. 
However, the while statements checks for that again, which is unnecessary, and 
gives warnings for returning a potentially non-initialized variable. For this 
reason, I suggest changing the while to a do-while loop while keeping the 
assert where it is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70603

Files:
  clang/lib/Analysis/ReachableCode.cpp


Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -138,10 +138,10 @@
 static SourceLocation getTopMostMacro(SourceLocation Loc, SourceManager &SM) {
   assert(Loc.isMacroID());
   SourceLocation Last;
-  while (Loc.isMacroID()) {
+  do {
 Last = Loc;
 Loc = SM.getImmediateMacroCallerLoc(Loc);
-  }
+  } while (Loc.isMacroID());
   return Last;
 }
 


Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -138,10 +138,10 @@
 static SourceLocation getTopMostMacro(SourceLocation Loc, SourceManager &SM) {
   assert(Loc.isMacroID());
   SourceLocation Last;
-  while (Loc.isMacroID()) {
+  do {
 Last = Loc;
 Loc = SM.getImmediateMacroCallerLoc(Loc);
-  }
+  } while (Loc.isMacroID());
   return Last;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-11-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 230678.
steveire added a comment.

Rebase and update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61837

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1595,6 +1595,91 @@
   notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr();
 }
 
+TEST(Traversal, traverseMatcher) {
+
+  StringRef VarDeclCode = R"cpp(
+void foo()
+{
+  int i = 3.0;
+}
+)cpp";
+
+  auto Matcher = varDecl(hasInitializer(floatLiteral()));
+
+  EXPECT_TRUE(
+  notMatches(VarDeclCode, traverse(ast_type_traits::TK_AsIs, Matcher)));
+  EXPECT_TRUE(
+  matches(VarDeclCode,
+  traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+   Matcher)));
+}
+
+TEST(Traversal, traverseMatcherNesting) {
+
+  StringRef Code = R"cpp(
+float bar(int i)
+{
+  return i;
+}
+
+void foo()
+{
+  bar(bar(3.0));
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+   callExpr(has(callExpr(traverse(
+   ast_type_traits::TK_AsIs,
+   callExpr(has(implicitCastExpr(has(floatLiteral(;
+}
+
+TEST(Traversal, traverseMatcherThroughImplicit) {
+  StringRef Code = R"cpp(
+struct S {
+  S(int x);
+};
+
+void constructImplicit() {
+  int a = 8;
+  S s(a);
+}
+  )cpp";
+
+  auto Matcher = traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+  implicitCastExpr());
+
+  // Verfiy that it does not segfault
+  EXPECT_FALSE(matches(Code, Matcher));
+}
+
+TEST(Traversal, traverseMatcherThroughMemoization) {
+
+  StringRef Code = R"cpp(
+void foo()
+{
+  int i = 3.0;
+}
+  )cpp";
+
+  auto Matcher = varDecl(hasInitializer(floatLiteral()));
+
+  // Matchers such as hasDescendant memoize their result regarding AST
+  // nodes. In the matcher below, the first use of hasDescendant(Matcher)
+  // fails, and the use of it inside the traverse() matcher should pass
+  // causing the overall matcher to be a true match.
+  // This test verifies that the first false result is not re-used, which
+  // would cause the overall matcher to be incorrectly false.
+
+  EXPECT_TRUE(matches(
+  Code, functionDecl(anyOf(
+hasDescendant(Matcher),
+traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+ functionDecl(hasDescendant(Matcher)));
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImpCasts matches when implicit casts are
   // present and its inner matcher alone does not match.
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -189,6 +189,14 @@
   llvm_unreachable("Invalid Op value.");
 }
 
+DynTypedMatcher DynTypedMatcher::constructRestrictedWrapper(
+const DynTypedMatcher &InnerMatcher,
+ast_type_traits::ASTNodeKind RestrictKind) {
+  DynTypedMatcher Copy = InnerMatcher;
+  Copy.RestrictKind = RestrictKind;
+  return Copy;
+}
+
 DynTypedMatcher DynTypedMatcher::trueMatcher(
 ast_type_traits::ASTNodeKind NodeKind) {
   return DynTypedMatcher(NodeKind, NodeKind, &*TrueMatcherInstance);
@@ -211,8 +219,13 @@
 bool DynTypedMatcher::matches(const ast_type_traits::DynTypedNode &DynNode,
   ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
-  if (RestrictKind.isBaseOf(DynNode.getNodeKind()) &&
-  Implementation->dynMatches(DynNode, Finder, Builder)) {
+  TraversalKindScope raii(Finder->getASTContext(),
+  Implementation->TraversalKind());
+
+  auto N = Finder->getASTContext().traverseIgnored(DynNode);
+
+  if (RestrictKind.isBaseOf(N.getNodeKind()) &&
+  Implementation->dynMatches(N, Finder, Builder)) {
 return true;
   }
   // Delete all bindings when a matcher does not match.
@@ -225,8 +238,13 @@
 bool DynTypedMatcher::matchesNoKindCheck(
 const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder,
 BoundNodesTreeBuilder *Builder) const {
-  assert(RestrictKind.isBaseOf(DynNode.getNodeKind()));
-  if (Implementation->dynMatches(DynNode, Finder, Builder)) {
+  T

[PATCH] D70551: [clang-offload-wrapper] Add data layout to the wrapper bitcode

2019-11-22 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev added a comment.

I would agree with you if data layout was indeed available in the driver, but 
unfortunately driver does not have access to any existing TargetInfo instance 
(or maybe I just have not found it). So, I have to create TargetInfo and build 
data layout even for the case when driver passes it to the wrapper tool. I 
guess that would also be a default data layout, so it would not differ much 
from what I have already done in this patch. BTW, I will probably upload an 
alternative patch where I have implemented your suggestion, just to compare))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70551



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


[PATCH] D70551: [clang-offload-wrapper] Add data layout to the wrapper bitcode

2019-11-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D70551#1757065 , @sdmitriev wrote:

> I would agree with you if data layout was indeed available in the driver, but 
> unfortunately driver does not have access to any existing TargetInfo instance 
> (or maybe I just have not found it). So, I have to create TargetInfo and 
> build data layout even for the case when driver passes it to the wrapper 
> tool. I guess that would also be a default data layout, so it would not 
> differ much from what I have already done in this patch. BTW, I will probably 
> upload an alternative patch where I have implemented your suggestion, just to 
> compare))


Of course, this is not a good solution. I was hoping that TargetInfo is 
available in driver. Otherwise, it would be good somehow to read the target 
data from the .bc file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70551



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


[PATCH] D70603: Change while to do-while

2019-11-22 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Missing a test; please upload all patches with full context (`-U9`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70603



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


[PATCH] D70605: [OpenCL] Fix address space for implicit conversion (PR43145)

2019-11-22 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, rjmccall.
Herald added a subscriber: yaxunl.

Clang was creating a `DerivedToBase` `ImplicitCastExpr` that was also
casting between address spaces as part of the second step in the
standard conversion sequence.  Defer the address space conversion to
the third step in the sequence instead, such that we get a separate
`ImplicitCastExpr` for the address space conversion.


https://reviews.llvm.org/D70605

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -69,3 +69,12 @@
   // CHECK: bitcast i8 addrspace(4)* %add.ptr1 to %class.B2 addrspace(4)*
   // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv
 }
+
+// Implicit conversion of derived to base.
+
+void functionWithBaseArg(class B2 *b) {}
+
+void pr43145_4() {
+  Derived d;
+  functionWithBaseArg(&d);
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4095,9 +4095,21 @@
 << From->getSourceRange();
 }
 
+// Defer address space conversion to the third conversion.
+QualType FromPteeType = From->getType()->getPointeeType();
+QualType ToPteeType = ToType->getPointeeType();
+QualType NewToType = ToType;
+if (!FromPteeType.isNull() && !ToPteeType.isNull() &&
+FromPteeType.getAddressSpace() != ToPteeType.getAddressSpace()) {
+  NewToType = Context.removeAddrSpaceQualType(ToPteeType);
+  NewToType = Context.getAddrSpaceQualType(NewToType,
+   FromPteeType.getAddressSpace());
+  NewToType = Context.getPointerType(NewToType);
+}
+
 CastKind Kind;
 CXXCastPath BasePath;
-if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle))
+if (CheckPointerConversion(From, NewToType, Kind, BasePath, CStyle))
   return ExprError();
 
 // Make sure we extend blocks if necessary.
@@ -4108,8 +4120,8 @@
   From = E.get();
 }
 if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
-  CheckObjCConversion(SourceRange(), ToType, From, CCK);
-From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK)
+  CheckObjCConversion(SourceRange(), NewToType, From, CCK);
+From = ImpCastExprToType(From, NewToType, Kind, VK_RValue, &BasePath, CCK)
  .get();
 break;
   }


Index: clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -69,3 +69,12 @@
   // CHECK: bitcast i8 addrspace(4)* %add.ptr1 to %class.B2 addrspace(4)*
   // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv
 }
+
+// Implicit conversion of derived to base.
+
+void functionWithBaseArg(class B2 *b) {}
+
+void pr43145_4() {
+  Derived d;
+  functionWithBaseArg(&d);
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4095,9 +4095,21 @@
 << From->getSourceRange();
 }
 
+// Defer address space conversion to the third conversion.
+QualType FromPteeType = From->getType()->getPointeeType();
+QualType ToPteeType = ToType->getPointeeType();
+QualType NewToType = ToType;
+if (!FromPteeType.isNull() && !ToPteeType.isNull() &&
+FromPteeType.getAddressSpace() != ToPteeType.getAddressSpace()) {
+  NewToType = Context.removeAddrSpaceQualType(ToPteeType);
+  NewToType = Context.getAddrSpaceQualType(NewToType,
+   FromPteeType.getAddressSpace());
+  NewToType = Context.getPointerType(NewToType);
+}
+
 CastKind Kind;
 CXXCastPath BasePath;
-if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle))
+if (CheckPointerConversion(From, NewToType, Kind, BasePath, CStyle))
   return ExprError();
 
 // Make sure we extend blocks if necessary.
@@ -4108,8 +4120,8 @@
   From = E.get();
 }
 if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
-  CheckObjCConversion(SourceRange(), ToType, From, CCK);
-From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK)
+  CheckObjCConversion(SourceRange(), NewToType, From, CCK);
+From = ImpCastExprToType(From, NewToType, Kind, VK_RValue, &BasePath, CCK)
  .get();
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70603: Change while to do-while

2019-11-22 Thread Seija Kijin via Phabricator via cfe-commits
pi1024e added a comment.

What do you mean? I test compiled this and there are no errors after running 
the test benchmark. Was I supposed to do something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70603



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


[PATCH] D70603: Change while to do-while

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

This is fine as NFC/NFCI patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70603



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


[PATCH] D70551: [clang-offload-wrapper] Add data layout to the wrapper bitcode

2019-11-22 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev added a comment.

Wrapper tool is invoked at link phase, therefore there just could be no .bc 
files available to read data layout from. Ok, looks like there is no good 
solution for the data layout problem, so I will drop the idea of passing 
wrapper .bc directly to the linker when LTO is enabled (at least for now:). I 
will abandon this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70551



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


[PATCH] D70537: [clang] CGDebugInfo asserts `!DT.isNull()` when compiling with debug symbols

2019-11-22 Thread Vedant Kumar via Phabricator via cfe-commits
vsk requested changes to this revision.
vsk added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1437
+if (isa(V))
+  continue;
+

I see that we don't attempt to handle `VarTemplateSpecializationDecl` when 
emitting CodeView. But it looks like we generally do handle these when emitting 
DWARF. I think the problem you're trying to address has more to do with clang 
not being able to describe globals with undeduced types in debug info.

E.g. if I replace `auto` with `int` in your test case, I get 
(https://godbolt.org/z/gRpRws):

```
!17 = distinct !DIGlobalVariable(name: "value", linkageName: 
"_ZN6TypeId5valueIJiEEE", scope: !2, file: !8, line: 7, type: !14, isLocal: 
false, isDefinition: true, declaration: !13, templateParams: !18)
!18 = !{!19}
!19 = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: 
"Args", value: !20)
```

Could you limit the scope of this patch to just ignore 
VarTemplateSpecializationDecl's with undeduced types? I think there's an 
example of how to do this in `CGDebugInfo::EmitUsingDecl`, you could factor 
that out and reuse it here.

Please also add a test case for the `s/auto/int/` example, to make sure that 
doesn't regress.


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

https://reviews.llvm.org/D70537



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


[clang-tools-extra] e1e7b6f - [clang-include-fixer] Suppress cmd prompt from Vim on Windows

2019-11-22 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2019-11-22T11:28:42-08:00
New Revision: e1e7b6f381a9a5640605fdc4a3e78eb01f8fc8b9

URL: 
https://github.com/llvm/llvm-project/commit/e1e7b6f381a9a5640605fdc4a3e78eb01f8fc8b9
DIFF: 
https://github.com/llvm/llvm-project/commit/e1e7b6f381a9a5640605fdc4a3e78eb01f8fc8b9.diff

LOG: [clang-include-fixer] Suppress cmd prompt from Vim on Windows

Copied from the clang-format.py editor integration.

Reviewers: bkramer

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

Added: 


Modified: 
clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py

Removed: 




diff  --git a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py 
b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
index 4c38f71ef76a..df05101e4fd8 100644
--- a/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
+++ b/clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
@@ -85,9 +85,16 @@ def GetUserSelection(message, headers, 
maximum_suggested_headers):
 
 
 def execute(command, text):
+  # Avoid flashing a cmd prompt on Windows.
+  startupinfo = None
+  if sys.platform.startswith('win32'):
+startupinfo = subprocess.STARTUPINFO()
+startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+startupinfo.wShowWindow = subprocess.SW_HIDE
+
   p = subprocess.Popen(command,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-   stdin=subprocess.PIPE)
+   stdin=subprocess.PIPE, startupinfo=startupinfo)
   return p.communicate(input=text)
 
 



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


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: llvm/test/DebugInfo/X86/debug-info-auto-return.ll:1
+;RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+

I don't think the FORMs are relevant for this test, so we can do without the 
`-v`


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

https://reviews.llvm.org/D70524



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


[PATCH] D70368: [clang-tidy] Rewrite modernize-avoid-bind check

2019-11-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mark addressed comments as done.


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

https://reviews.llvm.org/D70368



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


[PATCH] D70518: [clang-include-fixer] Suppress cmd prompt from Vim on Windows

2019-11-22 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe1e7b6f381a9: [clang-include-fixer] Suppress cmd prompt from 
Vim on Windows (authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70518

Files:
  clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py


Index: clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
===
--- clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
+++ clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
@@ -85,9 +85,16 @@
 
 
 def execute(command, text):
+  # Avoid flashing a cmd prompt on Windows.
+  startupinfo = None
+  if sys.platform.startswith('win32'):
+startupinfo = subprocess.STARTUPINFO()
+startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+startupinfo.wShowWindow = subprocess.SW_HIDE
+
   p = subprocess.Popen(command,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-   stdin=subprocess.PIPE)
+   stdin=subprocess.PIPE, startupinfo=startupinfo)
   return p.communicate(input=text)
 
 


Index: clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
===
--- clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
+++ clang-tools-extra/clang-include-fixer/tool/clang-include-fixer.py
@@ -85,9 +85,16 @@
 
 
 def execute(command, text):
+  # Avoid flashing a cmd prompt on Windows.
+  startupinfo = None
+  if sys.platform.startswith('win32'):
+startupinfo = subprocess.STARTUPINFO()
+startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+startupinfo.wShowWindow = subprocess.SW_HIDE
+
   p = subprocess.Popen(command,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-   stdin=subprocess.PIPE)
+   stdin=subprocess.PIPE, startupinfo=startupinfo)
   return p.communicate(input=text)
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Generally if you're not touching LLVM code, I would suggest not adding an LLVM 
test - unless this is new or surprising usage of existing LLVM functionality 
(or the functionality was otherwise undertested in LLVM previously). But I'm 
guessing that's not the case here?


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

https://reviews.llvm.org/D70524



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


[PATCH] D70111: [DWARF5]Addition of alignment field in the typedef for dwarf5

2019-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D70111#1754702 , @awpandey wrote:

> I am considering this
>
> - Will commit this without C bindings
> - will give separate patch for C bindings and release notes (if necessary).
> - will give another patch for Go bindings and release notes (if necessary).


I'm not sure I follow - are you asking a question? Proposing a path forward 
you're planning to take (or this patch already represents)?

I'd reiterate my previous request:

Please update the go bindings and include a release note that this API is 
changing & why. (include that in this patch review & then it can be reviewed & 
all committed together to keep the whole source tree in a working state, 
because committing the change while either removing the C API or updating it 
without updating the Go bindings would break the Go bindings, which isn't good)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70111



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


[PATCH] D69620: Add AIX assembler support

2019-11-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:37
+
+  // Specify the mode in which the as command operates.
+  if (IsArch32Bit) {

Refer to the other comment regarding confusion of "as" with the English word.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:47
+  // displayed. Otherwise, undefined symbols are flagged with error messages.
+  CmdArgs.push_back("-u");
+

There is no FIXME here indicating the plan to remove this in the future when 
the assembly generation from the compiler no longer needs this.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:49
+
+  // Acccept any mixture of instructions.
+  CmdArgs.push_back("-many");

Minor nit: Typo: s/Acccept/Accept/;



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:50
+  // Acccept any mixture of instructions.
+  CmdArgs.push_back("-many");
+

A comment should indicate that this behaviour matches that of GCC on Power for 
AIX and Linux for both the user-provided assembler source case and the 
compiler-produced assembler source case. The behaviour for XL with 
user-provided assemble source is different.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:61
+
+  // Specify assembler input file(s).
+  for (const auto &II : Inputs)

The AIX assembler does not accept more than one input file. If the intent is to 
let the assembler produce the error message, then I think we should at least 
have a comment to acknowledge the situation.



Comment at: clang/test/Driver/aix-as.c:1
+// General tests that as invocations on AIX targets are sane. Note that we
+// only test assembler functionalities in this suite.

Minor nit: To avoid confusion with the English word, use
```
`as`
```
or
```
as(1)
```



Comment at: clang/test/Driver/aix-as.c:31
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32-PTHREAD %s
+// CHECK-AS32-PTHREAD-NOT: warning:

I am not getting how this block is related to "pthread".



Comment at: clang/test/Driver/aix-as.c:40
+
+// Check powerpc-ibm-aix7.1.0.0, 64-bit. -Wa,, option.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \

s/powerpc/powerpc64/;



Comment at: clang/test/Driver/aix-as.c:44
+// RUN: -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS64-PTHREAD %s
+// CHECK-AS64-PTHREAD-NOT: warning:

Same comment re: "pthread".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620



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


[PATCH] D70411: [analyzer] CERT: StrChecker: 31.c

2019-11-22 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Now I have simplified the checker so we do not need any ASCII-art, I believe. 
Do we have any better logic than the current implementation to catch when the 
string is read?


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

https://reviews.llvm.org/D70411



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


[PATCH] D70411: [analyzer] CERT: StrChecker: 31.c

2019-11-22 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 230702.
Charusso marked an inline comment as done.
Charusso retitled this revision from "[analyzer][WIP] CERT: StrChecker: 31.c" 
to "[analyzer] CERT: StrChecker: 31.c".
Charusso added a comment.

- Remove the report storing map so we do not traverse backwards on the bug-path.
- Use `NoteTags` instead of reports on problematic function calls.
- Emit a report only if a not null-terminated string is read.
- Store whether the string is null-terminated.


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

https://reviews.llvm.org/D70411

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSizeInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/lib/StaticAnalyzer/Checkers/AllocationState.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
  clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/cert/str31-c-fp-suppression.cpp
  clang/test/Analysis/cert/str31-c-notes.cpp
  clang/test/Analysis/cert/str31-c.cpp

Index: clang/test/Analysis/cert/str31-c.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str31-c.cpp
@@ -0,0 +1,205 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,security.cert.str.31.c \
+// RUN:  -verify %s
+
+// See the examples on the page of STR31:
+// https://wiki.sei.cmu.edu/confluence/display/c/STR31-C.+Guarantee+that+storage+for+strings+has+sufficient+space+for+character+data+and+the+null+terminator
+
+#include "../Inputs/system-header-simulator.h"
+
+#define EOF -1
+typedef __SIZE_TYPE__ size_t;
+
+void free(void *memblock);
+void *malloc(size_t size);
+
+void do_something(char *buffer);
+
+namespace test_gets_bad {
+#define BUFFER_SIZE 1024
+
+void func(void) {
+  char buf[BUFFER_SIZE];
+  if (gets(buf)) {
+do_something(buf);
+// expected-warning@-1 {{'buf' is not null-terminated}}
+  }
+}
+} // namespace test_gets_bad
+
+namespace test_gets_good {
+enum { BUFFERSIZE = 32 };
+
+void func(void) {
+  char buff[BUFFERSIZE];
+
+  if (fgets(buff, sizeof(buff), stdin)) {
+do_something(buff);
+  }
+}
+} // namespace test_gets_good
+
+namespace test_sprintf_bad {
+void func(const char *name) {
+  char buf[128];
+  sprintf(buf, "%s.txt", name);
+
+  do_something(buf);
+  // expected-warning@-1 {{'buf' is not null-terminated}}
+}
+} // namespace test_sprintf_bad
+
+namespace test_sprintf_good {
+void func(const char *name) {
+  char buff[128];
+  snprintf(buff, sizeof(buff), "%s.txt", name);
+
+  do_something(buff);
+}
+} // namespace test_sprintf_good
+
+namespace test_fscanf_bad {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buf[BUF_LENGTH];
+  if (fscanf(stdin, "%s", buf)) {
+do_something(buf);
+// expected-warning@-1 {{'buf' is not null-terminated}}
+  }
+}
+} // namespace test_fscanf_bad
+
+namespace test_fscanf_good {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buff[BUF_LENGTH];
+  if (fscanf(stdin, "%1023s", buff)) {
+do_something(buff);
+  }
+}
+} // namespace test_fscanf_good
+
+namespace test_strcpy_bad {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char prog_name[128];
+  strcpy(prog_name, name);
+
+  do_something(prog_name);
+  // expected-warning@-1 {{'prog_name' is not null-terminated}}
+
+  return 0;
+}
+
+void func(void) {
+  char buff[256];
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+strcpy(buff, editor);
+
+do_something(buff);
+// expected-warning@-1 {{'buff' is not null-terminated}}
+  }
+}
+} // namespace test_strcpy_bad
+
+namespace test_strcpy_good {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char *prog_name2 = (char *)malloc(strlen(name) + 1);
+  if (prog_name2 != NULL) {
+strcpy(prog_name2, name);
+  }
+
+  do_something(prog_name2);
+
+  free(prog_name2);
+  return 0;
+}
+
+void func(void) {
+  char *buff2;
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+size_t len = strlen(editor) + 1;
+buff2 = (char *)malloc(len);
+if (buff2 != NULL) {
+  strcpy(buff2, editor);
+}
+
+do_something(buff2);
+free(buff2);
+  }
+}
+} // namespace test_strcpy_good
+
+//===--===//
+// The following is from the rule's page which we do not handle yet.
+//===--===//
+
+namespace test_loop_index_bad {
+void copy(size_t n, char src[n], char dest[n]) {
+  size_t i;
+
+  for (i = 0; src[i] && (i < n); ++i) {
+dest[i] = src[i];

[PATCH] D70342: [Diagnostics] Put "deprecated copy" warnings into -Wdeprecated-copy

2019-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good to me - can handle anything else from @rsmith in post-commit review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70342



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


[PATCH] D70342: [Diagnostics] Put "deprecated copy" warnings into -Wdeprecated-copy

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

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70342



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


[PATCH] D70613: Add method to ignore invisible AST nodes

2019-11-22 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70613

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1680,6 +1680,149 @@
  functionDecl(hasDescendant(Matcher)));
 }
 
+TEST(Traversal, traverseInvisible) {
+
+  StringRef Code = R"cpp(
+
+struct A
+{
+};
+
+struct B
+{
+  B(int);
+  B(A const& a);
+  B();
+};
+
+struct C
+{
+  operator B();
+};
+
+B func1() {
+  return 42;
+}
+
+B func2() {
+  return B{42};
+}
+
+B func3() {
+  return B(42);
+}
+
+B func4() {
+  return B();
+}
+
+B func5() {
+  return B{};
+}
+
+B func6() {
+  return C();
+}
+
+B func7() {
+  return A();
+}
+
+B func8() {
+  return C{};
+}
+
+B func9() {
+  return A{};
+}
+
+B func10() {
+  A a;
+  return a;
+}
+
+B func11() {
+  B b;
+  return b;
+}
+
+B func12() {
+  C c;
+  return c;
+}
+
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func1"))),
+hasReturnValue(integerLiteral(equals(42)));
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(ast_type_traits::TK_IgnoreInvisible,
+   returnStmt(forFunction(functionDecl(hasName("func2"))),
+  hasReturnValue(cxxTemporaryObjectExpr(
+  hasArgument(0, integerLiteral(equals(42);
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func3"))),
+hasReturnValue(
+cxxFunctionalCastExpr(hasSourceExpression(
+integerLiteral(equals(42);
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func4"))),
+hasReturnValue(cxxTemporaryObjectExpr());
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func5"))),
+hasReturnValue(cxxTemporaryObjectExpr());
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func6"))),
+hasReturnValue(cxxTemporaryObjectExpr());
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func7"))),
+hasReturnValue(cxxTemporaryObjectExpr());
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func8"))),
+hasReturnValue(cxxFunctionalCastExpr(
+hasSourceExpression(initListExpr(;
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func9"))),
+hasReturnValue(cxxFunctionalCastExpr(
+hasSourceExpression(initListExpr(;
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func10"))),
+hasReturnValue(
+declRefExpr(to(varDecl(hasName("a");
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func11"))),
+hasReturnValue(
+declRefExpr(to(varDecl(hasName("b");
+
+  EXPECT_TRUE(matches(
+  Code, traverse(ast_type_traits::TK_IgnoreInvisible,
+ returnStmt(forFunction(functionDecl(hasName("func12"))),
+hasReturnValue(
+declRefExpr(to(varDecl(hasName("c");
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImp

[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2019-11-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

In D70524#1757237 , @dblaikie wrote:

> Generally if you're not touching LLVM code, I would suggest not adding an 
> LLVM test - unless this is new or surprising usage of existing LLVM 
> functionality (or the functionality was otherwise undertested in LLVM 
> previously). But I'm guessing that's not the case here?


The rephrase the question David is asking: Do we already have an LLVM test for 
a named unspecified type?


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

https://reviews.llvm.org/D70524



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


[PATCH] D67149: Fix argument order for BugType instation for

2019-11-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Ah, the good old "stringly typed" APIs.

Would you like to write a LIT test for the fix, say by `FileCheck`ing the Plist 
output? (i could write one for you if it's not your cup of tea)


Repository:
  rC Clang

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

https://reviews.llvm.org/D67149



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


[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang Tidy's script

2019-11-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D69746#1756448 , @gribozavr2 wrote:

> > This patch introduces a way to apply the fix-its by the Analyzer:
>
> I'm not sure this option is very useful... I don't know of anyone who uses 
> the same option in Clang or ClangTidy. The only way I know people apply 
> fixits is with the help of IDEs. I am also skeptical that people want to 
> apply *all* fixits. Usually people want to pick a few specific ones, or all 
> fixits of a certain kind; but not everything.
>
> What workflow are you thinking of for this option?


For now this is definitely for testing purposes only. This patch doesn't expose 
the option in any of the interfaces that are intended for actual users to use 
(`-analyzer-config` is not one of them).

I don't have any immediate plans on exposing this option to users. That said, 
the user can always apply fixits of a specific checker by only running that 
checker (or by only enabling fixits of this checker).


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

https://reviews.llvm.org/D69746



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


[PATCH] D70467: [Distro] Bypass distro detection on non-Linux hosts

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

In D70467#1755364 , @aganea wrote:

> Actually, I'm not sure the `DetectDistro()` does what it intends to do when 
> cross-compiling: if I compile on Ubuntu and I forcibly specify `-target 
> x86_64-linux` on the cmd-line, should it detect which Linux distro I'm on? In 
> the case of `CudaInstallationDetector()` it seems it should use the host 
> triple, whereas in the case `clang/lib/Driver/ToolChains/Linux.cpp:Linux()` 
> it adds flags for building the target, so it should take the target triple 
> maybe. Should we pass a triple to `DetectDistro`?


It does seem wrong to use DetectDistro when the user passes a target triple. 
DetectDistro inherently detects something about that host, and it seems we 
don't have a way to pass that information explicitly on the command line. So, 
cross-compiling from one distro to another might somehow do the wrong thing 
depending on what distro detection does.

In D70467#1755337 , @aganea wrote:

> In D70467#1752611 , @rnk wrote:
>
> > Hm, I guess it does happen. I think that condition should be restructured 
> > to only do all that BSD, PS4, Android, Gentoo etc logic if the format is 
> > ELF, if COFF, then always default to -faddrsig.
>
>
> We're cross-compiling all our target platforms on Windows. It seems this 
> patch would be still valid in that case:
>
>   > clang -target x86_64-linux a.cpp
>   
>
> Would still call `DetectDistro()`, and unless I'm missing something, we 
> wouldn't want it to lookup `C:\etc\lsb-release` even if it's there? Or people 
> are really doing that to target a specific distro when compiling from 
> Windows? It doesn't make sense from my POV.
>  The same argument applies to CUDA: the code in 
> `clang/lib/Driver/ToolChains/Cuda.cpp:CudaInstallationDetector()` says 
> "HostTriple" but it's actually the Target triple -- you can try my cmd-line 
> above, it hits the Distro detect.
>  Unless you specify a non-real FS, I wouldn't want `DetectDistro` to return 
> anything else than `Distro::UnknownDistro` when running on a non-Linux OS.
>  Would you have a different opinion or something I don't see?


True, that makes sense to me.

lgtm




Comment at: clang/lib/Driver/Distro.cpp:29
+  // If the host is not running Linux, and we're backed by a real file system,
+  // no need to check the distro.
+  IntrusiveRefCntPtr RealFS =

I think it's worth adding more to this comment. This is the case where someone 
is cross-compiling from BSD or Windows to Linux, and it would be meaningless to 
try to figure out the "distro" of the non-Linux host.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:514
 
-  const Distro Distro(getDriver().getVFS());
+  const Distro Distro(getDriver().getVFS(), Triple);
 

So many duplicate detections. =/


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

https://reviews.llvm.org/D70467



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


[clang] e0f22fe - [RISCV] Use compiler-rt if no GCC installation detected

2019-11-22 Thread Edward Jones via cfe-commits

Author: Edward Jones
Date: 2019-11-22T20:05:29Z
New Revision: e0f22fe04a5c9eb244ff0533549743b7deb03b99

URL: 
https://github.com/llvm/llvm-project/commit/e0f22fe04a5c9eb244ff0533549743b7deb03b99
DIFF: 
https://github.com/llvm/llvm-project/commit/e0f22fe04a5c9eb244ff0533549743b7deb03b99.diff

LOG: [RISCV] Use compiler-rt if no GCC installation detected

If a GCC installation is not detected, then this attempts to
use compiler-rt and the compiler-rt crtbegin/crtend
implementations as a fallback.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.h
clang/test/Driver/riscv32-toolchain-extra.c
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain-extra.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index bd63873e3c6c..25d912428b5f 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -61,6 +61,16 @@ Tool *RISCVToolChain::buildLinker() const {
   return new tools::RISCV::Linker(*this);
 }
 
+ToolChain::RuntimeLibType RISCVToolChain::GetDefaultRuntimeLibType() const {
+  return GCCInstallation.isValid() ?
+ToolChain::RLT_Libgcc : ToolChain::RLT_CompilerRT;
+}
+
+ToolChain::UnwindLibType
+RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
+  return ToolChain::UNW_None;
+}
+
 void RISCVToolChain::addClangTargetOptions(
 const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
@@ -138,9 +148,22 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   bool WantCRTs =
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
 
+  const char *crtbegin, *crtend;
+  auto RuntimeLib = ToolChain.GetRuntimeLibType(Args);
+  if (RuntimeLib == ToolChain::RLT_Libgcc) {
+crtbegin = "crtbegin.o";
+crtend = "crtend.o";
+  } else {
+assert (RuntimeLib == ToolChain::RLT_CompilerRT);
+crtbegin = ToolChain.getCompilerRTArgString(Args, "crtbegin",
+ToolChain::FT_Object);
+crtend = ToolChain.getCompilerRTArgString(Args, "crtend",
+  ToolChain::FT_Object);
+  }
+
   if (WantCRTs) {
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
   }
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
@@ -161,11 +184,11 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("-lc");
 CmdArgs.push_back("-lgloss");
 CmdArgs.push_back("--end-group");
-CmdArgs.push_back("-lgcc");
+AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
   }
 
   if (WantCRTs)
-CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());

diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index b2b56b066efd..bb7f64849bcb 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -25,6 +25,9 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args,
  Action::OffloadKind) const override;
+  RuntimeLibType GetDefaultRuntimeLibType() const override;
+  UnwindLibType
+  GetUnwindLibType(const llvm::opt::ArgList &Args) const override;
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;

diff  --git a/clang/test/Driver/riscv32-toolchain-extra.c 
b/clang/test/Driver/riscv32-toolchain-extra.c
index 613667213ac8..d07d0f199ae2 100644
--- a/clang/test/Driver/riscv32-toolchain-extra.c
+++ b/clang/test/Driver/riscv32-toolchain-extra.c
@@ -19,15 +19,15 @@
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld 
%T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf 
%T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
 // RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
-// RUN:-target riscv32-unknown-elf 2>&1 \
+// RUN:-target riscv32-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 
-// 

[clang] 0c7a1c0 - [OPENMP] [DOCS] correct status for use_device_addr clause

2019-11-22 Thread Kelvin Li via cfe-commits

Author: Kelvin Li
Date: 2019-11-22T15:32:40-05:00
New Revision: 0c7a1c0cfc2a4e5b8b7f3920b2797c12963b8384

URL: 
https://github.com/llvm/llvm-project/commit/0c7a1c0cfc2a4e5b8b7f3920b2797c12963b8384
DIFF: 
https://github.com/llvm/llvm-project/commit/0c7a1c0cfc2a4e5b8b7f3920b2797c12963b8384.diff

LOG: [OPENMP] [DOCS] correct status for use_device_addr clause

The status of the use_device_addr clause feature is changed from 'done' to 
'worked on`.

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

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index aafadcfa0058..ee80f1afb9e6 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -205,7 +205,7 @@ implementation.
 
+--+--+--+---+
 | device extension | mapping lambda expression 
   | :good:`done` | D51107  
  |
 
+--+--+--+---+
-| device extension | clause: use_device_addr for target data   
   | :good:`done` | 
  |
+| device extension | clause: use_device_addr for target data   
   | :part:`worked on`| 
  |
 
+--+--+--+---+
 | device extension | map(replicate) or map(local) when requires 
unified_shared_me | :part:`worked on`| D55719,D55892
 |
 
+--+--+--+---+



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


[PATCH] D68407: [RISCV] Use compiler-rt if no GCC installation detected

2019-11-22 Thread Edward Jones via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0f22fe04a5c: [RISCV] Use compiler-rt if no GCC installation 
detected (authored by edward-jones).

Changed prior to commit:
  https://reviews.llvm.org/D68407?vs=229284&id=230708#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68407

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.h
  clang/test/Driver/riscv32-toolchain-extra.c
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain-extra.c
  clang/test/Driver/riscv64-toolchain.c

Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -3,8 +3,11 @@
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "riscv64"
 
+// In the below tests, --rtlib=platform is used so that the driver ignores
+// the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib
+
 // RUN: %clang %s -### -no-canonical-prefixes \
-// RUN:   -target riscv64-unknown-elf \
+// RUN:   -target riscv64-unknown-elf --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-BAREMETAL-LP64 %s
@@ -20,7 +23,7 @@
 // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes \
-// RUN:   -target riscv64-unknown-elf \
+// RUN:   -target riscv64-unknown-elf --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-BAREMETAL-NOSYSROOT-LP64 %s
@@ -35,7 +38,7 @@
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clangxx %s -### -no-canonical-prefixes \
-// RUN:   -target riscv64-unknown-elf -stdlib=libstdc++ \
+// RUN:   -target riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
 // RUN:   --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \
 // RUN:   | FileCheck -check-prefix=CXX-RV64-BAREMETAL-LP64 %s
@@ -52,7 +55,7 @@
 // CXX-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clangxx %s -### -no-canonical-prefixes \
-// RUN:   -target riscv64-unknown-elf -stdlib=libstdc++ \
+// RUN:   -target riscv64-unknown-elf -stdlib=libstdc++ --rtlib=platform \
 // RUN:   --sysroot= \
 // RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree 2>&1 \
 // RUN:   | FileCheck -check-prefix=CXX-RV64-BAREMETAL-NOSYSROOT-LP64 %s
@@ -68,7 +71,7 @@
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-linux-gnu -mabi=lp64 \
+// RUN:   -target riscv64-unknown-linux-gnu --rtlib=platform -mabi=lp64 \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-LINUX-MULTI-LP64 %s
@@ -84,7 +87,7 @@
 // C-RV64-LINUX-MULTI-LP64: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-linux-gnu -march=rv64imafd \
+// RUN:   -target riscv64-unknown-linux-gnu --rtlib=platform -march=rv64imafd \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-LINUX-MULTI-LP64D %s
@@ -100,7 +103,8 @@
 // C-RV64-LINUX-MULTI-LP64D: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64d"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-elf --sysroot= -march=rv64imac -mabi=lp64\
+// RUN:   -target riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imac -mabi=lp64\
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64IMAC-BAREMETAL-MULTI-LP64 %s
 
@@ -115,7 +119,8 @@
 // C-RV64IMAC-BAREMETAL-MULTI-LP64: "{{.*}}/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64{{/|}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-elf --sysroot= -march=rv64imafdc -mabi=lp64d \
+// RUN:   -target riscv64-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv64imafdc -mabi=lp64d \
 

[PATCH] D70608: [OPENMP] [DOCS] correct status for use_device_addr clause

2019-11-22 Thread Kelvin Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c7a1c0cfc2a: [OPENMP] [DOCS] correct status for 
use_device_addr clause (authored by kkwli0).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70608

Files:
  clang/docs/OpenMPSupport.rst


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -205,7 +205,7 @@
 
+--+--+--+---+
 | device extension | mapping lambda expression 
   | :good:`done` | D51107  
  |
 
+--+--+--+---+
-| device extension | clause: use_device_addr for target data   
   | :good:`done` | 
  |
+| device extension | clause: use_device_addr for target data   
   | :part:`worked on`| 
  |
 
+--+--+--+---+
 | device extension | map(replicate) or map(local) when requires 
unified_shared_me | :part:`worked on`| D55719,D55892
 |
 
+--+--+--+---+


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -205,7 +205,7 @@
 +--+--+--+---+
 | device extension | mapping lambda expression| :good:`done` | D51107|
 +--+--+--+---+
-| device extension | clause: use_device_addr for target data  | :good:`done` |   |
+| device extension | clause: use_device_addr for target data  | :part:`worked on`|   |
 +--+--+--+---+
 | device extension | map(replicate) or map(local) when requires unified_shared_me | :part:`worked on`| D55719,D55892 |
 +--+--+--+---+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70071: [ConstExprPreter] Removed the flag forcing the use of the interpreter

2019-11-22 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese accepted this revision.
Bigcheese added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70071



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


[clang] 9180f8a - Don't report "main" as missing a prototype in freestanding mode

2019-11-22 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2019-11-22T12:35:43-08:00
New Revision: 9180f8a57436da0ce91d9d4885702a10f89571bc

URL: 
https://github.com/llvm/llvm-project/commit/9180f8a57436da0ce91d9d4885702a10f89571bc
DIFF: 
https://github.com/llvm/llvm-project/commit/9180f8a57436da0ce91d9d4885702a10f89571bc.diff

LOG: Don't report "main" as missing a prototype in freestanding mode

Summary:
A user may want to use freestanding mode with the standard "main" entry
point. It's not useful to warn about a missing prototype as it's not
typical to have a prototype for "main".

Reviewers: efriedma, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

Added: 
clang/test/Sema/no-warn-missing-prototype.c

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6d857e832c4b..47c05d5d2eaa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
 return false;
 
   // Don't warn about 'main'.
-  if (FD->isMain())
-return false;
+  if (isa(FD->getDeclContext()->getRedeclContext()))
+if (IdentifierInfo *II = FD->getIdentifier())
+  if (II->isStr("main"))
+return false;
 
   // Don't warn about inline functions.
   if (FD->isInlined())

diff  --git a/clang/test/Sema/no-warn-missing-prototype.c 
b/clang/test/Sema/no-warn-missing-prototype.c
new file mode 100644
index ..2361677a5f73
--- /dev/null
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes-x c -ffreestanding 
-verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding 
-verify %s
+// expected-no-diagnostics
+int main() {
+  return 0;
+}



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


[PATCH] D70588: Don't report "main" as missing a prototype in freestanding mode

2019-11-22 Thread Bill Wendling via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9180f8a57436: Don't report "main" as missing 
a prototype in freestanding mode (authored by void).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70588

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/no-warn-missing-prototype.c


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- /dev/null
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes-x c -ffreestanding 
-verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding 
-verify %s
+// expected-no-diagnostics
+int main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@
 return false;
 
   // Don't warn about 'main'.
-  if (FD->isMain())
-return false;
+  if (isa(FD->getDeclContext()->getRedeclContext()))
+if (IdentifierInfo *II = FD->getIdentifier())
+  if (II->isStr("main"))
+return false;
 
   // Don't warn about inline functions.
   if (FD->isInlined())


Index: clang/test/Sema/no-warn-missing-prototype.c
===
--- /dev/null
+++ clang/test/Sema/no-warn-missing-prototype.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes-x c -ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding -verify %s
+// expected-no-diagnostics
+int main() {
+  return 0;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13319,8 +13319,10 @@
 return false;
 
   // Don't warn about 'main'.
-  if (FD->isMain())
-return false;
+  if (isa(FD->getDeclContext()->getRedeclContext()))
+if (IdentifierInfo *II = FD->getIdentifier())
+  if (II->isStr("main"))
+return false;
 
   // Don't warn about inline functions.
   if (FD->isInlined())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >