[PATCH] D76772: [AMDGPU] Add __builtin_amdgcn_workgroup_size_x/y/z

2020-03-27 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG369e26ca9e0d: [AMDGPU] Add 
__builtin_amdgcn_workgroup_size_x/y/z (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76772

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Index: clang/test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -527,6 +527,24 @@
 	}
 }
 
+// CHECK-LABEL: @test_get_workgroup_size(
+// CHECK: call align 4 dereferenceable(64) i8 addrspace(4)* @llvm.amdgcn.dispatch.ptr()
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 4
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 4, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 6
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 2, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 8
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 4, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+void test_get_workgroup_size(int d, global int *out)
+{
+	switch (d) {
+	case 0: *out = __builtin_amdgcn_workgroup_size_x(); break;
+	case 1: *out = __builtin_amdgcn_workgroup_size_y(); break;
+	case 2: *out = __builtin_amdgcn_workgroup_size_z(); break;
+	default: *out = 0;
+	}
+}
+
 // CHECK-LABEL: @test_fmed3_f32
 // CHECK: call float @llvm.amdgcn.fmed3.f32(
 void test_fmed3_f32(global float* out, float a, float b, float c)
@@ -698,6 +716,7 @@
 }
 
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
+// CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
 // CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly }
 // CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }
 // CHECK-DAG: ![[$EXEC]] = !{!"exec"}
Index: clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa \
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK-LABEL: test_get_workgroup_size
+// CHECK: call align 4 dereferenceable(64) i8 addrspace(4)* @llvm.amdgcn.dispatch.ptr()
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i32 4
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 2, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i32 6
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 2, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i32 8
+// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 2, !range [[$WS_RANGE:![0-9]*]], !invariant.load
+__device__ void test_get_workgroup_size(int d, int *out)
+{
+  switch (d) {
+  case 0: *out = __builtin_amdgcn_workgroup_size_x(); break;
+  case 1: *out = __builtin_amdgcn_workgroup_size_y(); break;
+  case 2: *out = __builtin_amdgcn_workgroup_size_z(); break;
+  default: *out = 0;
+  }
+}
+
+// CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13407,6 +13407,48 @@
   }
 }
 
+namespace {
+// If \p E is not null pointer, insert address space cast to match return
+// type of \p E if necessary.
+Value *EmitAMDGPUDispatchPtr(CodeGenFunction ,
+ const CallExpr *E = nullptr) {
+  auto *F = CGF.CGM.getIntrinsic(Intrinsic::amdgcn_dispatch_ptr);
+  auto *Call = CGF.Builder.CreateCall(F);
+  Call->addAttribute(
+  AttributeList::ReturnIndex,
+  Attribute::getWithDereferenceableBytes(Call->getContext(), 64));
+  Call->addAttribute(AttributeList::ReturnIndex,
+ Attribute::getWithAlignment(Call->getContext(), Align(4)));
+  if (!E)
+return Call;
+  QualType BuiltinRetType = E->getType();
+  auto *RetTy = cast(CGF.ConvertType(BuiltinRetType));
+  if (RetTy == Call->getType())
+return Call;
+  return CGF.Builder.CreateAddrSpaceCast(Call, RetTy);
+}
+
+// \p Index is 0, 1, and 2 for x, y, and z dimension, respectively.
+Value *EmitAMDGPUWorkGroupSize(CodeGenFunction , unsigned Index) {
+  const unsigned XOffset = 4;
+  auto *DP = EmitAMDGPUDispatchPtr(CGF);
+  // Indexing the HSA kernel_dispatch_packet struct.
+  auto *Offset = llvm::ConstantInt::get(CGF.Int32Ty, XOffset + Index * 2);
+  

[PATCH] D70366: Add new 'flatten' LLVM attribute to fix clang's 'flatten' function attribute

2020-03-27 Thread LevitatingLion via Phabricator via cfe-commits
LevitatingLion added a comment.

Thanks for the ping. I hadn't looked at this since, but I'll update the patch 
this weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70366



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


[clang] 369e26c - [AMDGPU] Add __builtin_amdgcn_workgroup_size_x/y/z

2020-03-27 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-03-28T01:03:20-04:00
New Revision: 369e26ca9e0d9ceb87c70d26e9f13e793ee1ab40

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

LOG: [AMDGPU] Add __builtin_amdgcn_workgroup_size_x/y/z

The main purpose of introducing these builtins is to add a range
metadata [1, 1025) on the work group size loaded from dispatch
ptr, which cannot be done by source code.

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

Added: 
clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a9143ad8292c..e5b256c07a49 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -33,6 +33,10 @@ BUILTIN(__builtin_amdgcn_workitem_id_x, "Ui", "nc")
 BUILTIN(__builtin_amdgcn_workitem_id_y, "Ui", "nc")
 BUILTIN(__builtin_amdgcn_workitem_id_z, "Ui", "nc")
 
+BUILTIN(__builtin_amdgcn_workgroup_size_x, "Ui", "nc")
+BUILTIN(__builtin_amdgcn_workgroup_size_y, "Ui", "nc")
+BUILTIN(__builtin_amdgcn_workgroup_size_z, "Ui", "nc")
+
 BUILTIN(__builtin_amdgcn_mbcnt_hi, "UiUiUi", "nc")
 BUILTIN(__builtin_amdgcn_mbcnt_lo, "UiUiUi", "nc")
 

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 81760ec82838..5edfa0e4e0c7 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -212,6 +212,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
 
   unsigned ARMCDECoprocMask : 8;
 
+  unsigned MaxOpenCLWorkGroupSize;
+
   // TargetInfo Constructor.  Default initializes all fields.
   TargetInfo(const llvm::Triple );
 
@@ -663,6 +665,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// types for the given target.
   unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
 
+  unsigned getMaxOpenCLWorkGroupSize() const { return MaxOpenCLWorkGroupSize; }
+
   /// Return the alignment (in bits) of the thrown exception object. This is
   /// only meaningful for targets that allocate C++ exceptions in a system
   /// runtime, such as those using the Itanium C++ ABI.

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 2330339bedfb..2f1e044bb106 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -133,6 +133,8 @@ TargetInfo::TargetInfo(const llvm::Triple ) : 
TargetOpts(), Triple(T) {
   // Default to an unknown platform name.
   PlatformName = "unknown";
   PlatformMinVersion = VersionTuple();
+
+  MaxOpenCLWorkGroupSize = 1024;
 }
 
 // Out of line virtual dtor for TargetInfo.

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 754d95d1ab81..880fe0e271f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13407,6 +13407,48 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
+namespace {
+// If \p E is not null pointer, insert address space cast to match return
+// type of \p E if necessary.
+Value *EmitAMDGPUDispatchPtr(CodeGenFunction ,
+ const CallExpr *E = nullptr) {
+  auto *F = CGF.CGM.getIntrinsic(Intrinsic::amdgcn_dispatch_ptr);
+  auto *Call = CGF.Builder.CreateCall(F);
+  Call->addAttribute(
+  AttributeList::ReturnIndex,
+  Attribute::getWithDereferenceableBytes(Call->getContext(), 64));
+  Call->addAttribute(AttributeList::ReturnIndex,
+ Attribute::getWithAlignment(Call->getContext(), 
Align(4)));
+  if (!E)
+return Call;
+  QualType BuiltinRetType = E->getType();
+  auto *RetTy = cast(CGF.ConvertType(BuiltinRetType));
+  if (RetTy == Call->getType())
+return Call;
+  return CGF.Builder.CreateAddrSpaceCast(Call, RetTy);
+}
+
+// \p Index is 0, 1, and 2 for x, y, and z dimension, respectively.
+Value *EmitAMDGPUWorkGroupSize(CodeGenFunction , unsigned Index) {
+  const unsigned XOffset = 4;
+  auto *DP = EmitAMDGPUDispatchPtr(CGF);
+  // Indexing the HSA kernel_dispatch_packet struct.
+  auto *Offset = llvm::ConstantInt::get(CGF.Int32Ty, XOffset + Index * 2);
+  auto *GEP = CGF.Builder.CreateGEP(DP, Offset);
+  auto *DstTy =
+  CGF.Int16Ty->getPointerTo(GEP->getType()->getPointerAddressSpace());
+  auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy);
+  auto *LD = CGF.Builder.CreateLoad(Address(Cast, CharUnits::fromQuantity(2)));
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  llvm::MDNode *RNode = MDHelper.createRange(APInt(16, 1),
+  

[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253289.
oontvoo added a comment.

cleanup logging


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/dummy_pragma_once.h
  clang/test/Modules/Inputs/dummy_textual_header.h
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/import-pragma-once.c

Index: clang/test/Modules/import-pragma-once.c
===
--- /dev/null
+++ clang/test/Modules/import-pragma-once.c
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c %s
+#include "dummy_pragma_once.h"
+#include "dummy_textual_header.h"
+
+void *p = 
+void *q = 
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -282,6 +282,11 @@
   header "dummy.h"
 }
 
+module dummy_pragma_once {
+  header "dummy_pragma_once.h"
+  textual header "dummy_textual_header.h"
+}
+
 module builtin {
   header "builtin.h"
   explicit module sub {
Index: clang/test/Modules/Inputs/dummy_textual_header.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_textual_header.h
@@ -0,0 +1,2 @@
+#pragma once
+int y = 6;
Index: clang/test/Modules/Inputs/dummy_pragma_once.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_pragma_once.h
@@ -0,0 +1,3 @@
+#include "dummy_textual_header.h"
+
+int x = 5;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1621,7 +1621,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1678,6 +1678,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1705,7 +1708,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1783,8 +1786,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1801,8 +1803,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2636,6 +2643,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1947462 , @hliao wrote:

> In D76365#1947103 , @tra wrote:
>
> > In D76365#1946938 , @hliao wrote:
> >
> > > The new revision is accepted, right? Just want to confirm as it seems you 
> > > accept it before I posted the new change.
> >
> >
> > The approval was for the old version. I didn't undo it when I reopened the 
> > review. The diff looks OK, though the last variant still leaves open the 
> > question of what's the meaning of these attributes and what are the 
> > restrictions on their use.
> >
> > So what's the reasonable thing to do if I write something like this:
> >
> >   __attribute__((device_builtin_surface_type)) int foo; // Ignore? Warn? 
> > Error? Do something sensible?
> >
>
>
> For such case, NVCC reports the following error:
>
>   kernel.cu(3): error: attribute "device_builtin_surface_type" does not apply 
> here
>  
>   1 error detected in the compilation of "kernel.cpp1.ii"
>
>
> That error is generated after `nvcc --keep -g -c kernel.cu` from this sample 
> code (`kernel.cu`)
>
>   #include 
>  
>   __attribute__((device_builtin_surface_type)) int foo;
>  
>   int f() {
> return foo;
>   }
>
>
> I changed that sample code a little bit to this one
>
>   #include 
>  
>   #if 1
>   typedef __attribute__((device_builtin_surface_type)) int dev_texsurf_int_t;
>   dev_texsurf_int_t foo;
>   #else
>   __attribute__((device_builtin_surface_type)) int foo;
>   #endif
>  
>   int f() {
> return foo;
>   }
>
>
> It triggers a crash in NVCC with the same compilation command line.
>
> We may enhance clang to report an error instead of a warning only so far.


I tried one more sample, it triggers NVCC crash as well.

  struct __attribute__((device_builtin_surface_type)) ref {
int x;
  } R;
  
  int f() { return R.x; }

For this case, clang reports error due to the same checks added in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[clang] 499b2a8 - PR45294: Fix handling of assumed template names looked up in the lexical

2020-03-27 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-27T21:07:06-07:00
New Revision: 499b2a8d63ca9b319ce3aae462029f37ce7d96dd

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

LOG: PR45294: Fix handling of assumed template names looked up in the lexical
scope.

There are a few contexts in which we assume a name is a template name;
if such a context is one where we should perform an unqualified lookup,
and lookup finds nothing, we would form a dependent template name even
if the name is not dependent. This happens in particular for the lookup
of a pseudo-destructor.

In passing, rename ActOnDependentTemplateName to just ActOnTemplateName
given that we apply it for non-dependent template names too.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/Parser/cxx-decl.cpp
clang/test/SemaCXX/literal-operators.cpp
clang/test/SemaCXX/pseudo-destructors.cpp
clang/test/SemaTemplate/nested-name-spec-template.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d2aa2902bb2a..b48f92f38939 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4919,6 +4919,9 @@ def err_template_kw_refers_to_non_template : Error<
   "%0 following the 'template' keyword does not refer to a template">;
 def note_template_kw_refers_to_non_template : Note<
   "declared as a non-template here">;
+def err_template_kw_refers_to_dependent_non_template : Error<
+  "%0%select{| following the 'template' keyword}1 "
+  "cannot refer to a dependent template">;
 def err_template_kw_refers_to_class_template : Error<
   "'%0%1' instantiated to a class template, not a function template">;
 def note_referenced_class_template : Note<

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 985bcf689d21..761fad9456be 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1773,6 +1773,12 @@ Parser::ParseCXXPseudoDestructor(Expr *Base, 
SourceLocation OpLoc,
 
   // If there is a '<', the second type name is a template-id. Parse
   // it as such.
+  //
+  // FIXME: This is not a context in which a '<' is assumed to start a template
+  // argument list. This affects examples such as
+  //   void f(auto *p) { p->~X(); }
+  // ... but there's no ambiguity, and nowhere to write 'template' in such an
+  // example, so we accept it anyway.
   if (Tok.is(tok::less) &&
   ParseUnqualifiedIdTemplateId(
   SS, ObjectType, Base && Base->containsErrors(), SourceLocation(),

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 47b5de320ebf..a33e40b8768d 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1878,11 +1878,7 @@ bool Parser::TryAnnotateTypeOrScopeToken() {
  Tok.getLocation());
 } else if (Tok.is(tok::annot_template_id)) {
   TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
-  if (TemplateId->isInvalid())
-return true;
-  if (TemplateId->Kind != TNK_Type_template &&
-  TemplateId->Kind != TNK_Dependent_template_name &&
-  TemplateId->Kind != TNK_Undeclared_template) {
+  if (!TemplateId->mightBeType()) {
 Diag(Tok, diag::err_typename_refers_to_non_type_template)
   << Tok.getAnnotationRange();
 return true;
@@ -1891,14 +1887,13 @@ bool Parser::TryAnnotateTypeOrScopeToken() {
   ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
  TemplateId->NumArgs);
 
-  Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
- TemplateId->TemplateKWLoc,
- TemplateId->Template,
- TemplateId->Name,
- TemplateId->TemplateNameLoc,
- TemplateId->LAngleLoc,
- TemplateArgsPtr,
- TemplateId->RAngleLoc);
+  Ty = TemplateId->isInvalid()
+   ? TypeError()
+   : Actions.ActOnTypenameType(
+ getCurScope(), TypenameLoc, SS, TemplateId->TemplateKWLoc,
+ TemplateId->Template, TemplateId->Name,
+ TemplateId->TemplateNameLoc, TemplateId->LAngleLoc,
+ TemplateArgsPtr, TemplateId->RAngleLoc);
 } else {
   Diag(Tok, diag::err_expected_type_name_after_typename)
 << SS.getRange();

diff  --git 

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1947103 , @tra wrote:

> In D76365#1946938 , @hliao wrote:
>
> > The new revision is accepted, right? Just want to confirm as it seems you 
> > accept it before I posted the new change.
>
>
> The approval was for the old version. I didn't undo it when I reopened the 
> review. The diff looks OK, though the last variant still leaves open the 
> question of what's the meaning of these attributes and what are the 
> restrictions on their use.
>
> So what's the reasonable thing to do if I write something like this:
>
>   __attribute__((device_builtin_surface_type)) int foo; // Ignore? Warn? 
> Error? Do something sensible?
>


For such case, NVCC reports the following error:

  kernel.cu(3): error: attribute "device_builtin_surface_type" does not apply 
here
  
  1 error detected in the compilation of "kernel.cpp1.ii"

That error is generated after `nvcc --keep -g -c kernel.cu` from this sample 
code (`kernel.cu`)

  #include 
  
  __attribute__((device_builtin_surface_type)) int foo;
  
  int f() {
return foo;
  }

I changed that sample code a little bit to this one

  #include 
  
  #if 1
  typedef __attribute__((device_builtin_surface_type)) int dev_texsurf_int_t;
  dev_texsurf_int_t foo;
  #else
  __attribute__((device_builtin_surface_type)) int foo;
  #endif
  
  int f() {
return foo;
  }

It triggers a crash in NVCC with the same compilation command line.

We may enhance clang to report an error instead of a warning only so far.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[clang] 88c7ffa - Form invalid template-id annotations when parsing a construct that is

2020-03-27 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-27T20:27:42-07:00
New Revision: 88c7ffaf947642b0cb2d13e5d1a4a54fc633d014

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

LOG: Form invalid template-id annotations when parsing a construct that is
required to be a template-id but names an undeclared identifier.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/invalid-template-specifier.cpp
clang/test/SemaObjCXX/parameterized_classes_subst.mm
clang/test/SemaTemplate/dependent-base-classes.cpp
clang/test/SemaTemplate/nested-name-spec-template.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6025175e7177..b4b2611481db 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7226,7 +7226,7 @@ class Sema final {
const DeclarationNameInfo ,
const TemplateArgumentListInfo *TemplateArgs);
 
-  TemplateNameKind ActOnDependentTemplateName(
+  TemplateNameKind ActOnTemplateName(
   Scope *S, CXXScopeSpec , SourceLocation TemplateKWLoc,
   const UnqualifiedId , ParsedType ObjectType, bool EnteringContext,
   TemplateTy , bool AllowInjectedClassName = false);

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 1f0d37154328..985bcf689d21 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -316,13 +316,11 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
   // Commit to parsing the template-id.
   TPA.Commit();
   TemplateTy Template;
-  if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName(
-  getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
-  EnteringContext, Template, /*AllowInjectedClassName*/ true)) {
-if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
-TemplateName, false))
-  return true;
-  } else
+  TemplateNameKind TNK = Actions.ActOnTemplateName(
+  getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
+  EnteringContext, Template, /*AllowInjectedClassName*/ true);
+  if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
+  TemplateName, false))
 return true;
 
   continue;
@@ -528,16 +526,13 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
   << FixItHint::CreateInsertion(Tok.getLocation(), "template ");
 }
 
-if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName(
-getCurScope(), SS, Tok.getLocation(), TemplateName, ObjectType,
-EnteringContext, Template, /*AllowInjectedClassName*/ true)) {
-  // Consume the identifier.
-  ConsumeToken();
-  if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
-  TemplateName, false))
-return true;
-}
-else
+SourceLocation TemplateNameLoc = ConsumeToken();
+
+TemplateNameKind TNK = Actions.ActOnTemplateName(
+getCurScope(), SS, TemplateNameLoc, TemplateName, ObjectType,
+EnteringContext, Template, /*AllowInjectedClassName*/ true);
+if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
+TemplateName, false))
   return true;
 
 continue;
@@ -2307,9 +2302,9 @@ bool Parser::ParseUnqualifiedIdTemplateId(
 if (AssumeTemplateId) {
   // We defer the injected-class-name checks until we've found whether
   // this template-id is used to form a nested-name-specifier or not.
-  TNK = Actions.ActOnDependentTemplateName(
-  getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
-  Template, /*AllowInjectedClassName*/ true);
+  TNK = Actions.ActOnTemplateName(getCurScope(), SS, TemplateKWLoc, Id,
+  ObjectType, EnteringContext, Template,
+  /*AllowInjectedClassName*/ true);
 } else {
   bool MemberOfUnknownSpecialization;
   TNK = Actions.isTemplateName(getCurScope(), SS,
@@ -2346,7 +2341,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(
   << Name
   << FixItHint::CreateInsertion(Id.StartLocation, "template ");
 }
-TNK = Actions.ActOnDependentTemplateName(
+TNK = Actions.ActOnTemplateName(
 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
   

[PATCH] D76887: AMDGPU: Make HIPToolChain a subclass of ROCMToolChain

2020-03-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/HIP.cpp:271
  const ToolChain , const ArgList )
-: ToolChain(D, Triple, Args), HostTC(HostTC) {
+: ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
   // Lookup binaries into the driver directory, this is used to

I did not see ROCMToolChain in clang trunk. Is it in another patch?


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

https://reviews.llvm.org/D76887



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


[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-27 Thread Digger via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 253281.
DiggerLin added a comment.

clang reformat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCXCOFFStreamer.cpp
  llvm/lib/MC/XCOFFObjectWriter.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll

Index: llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
===
--- llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
+++ llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
@@ -15,6 +15,7 @@
 ;CHECK-NEXT: .globl  foo_ptr
 ;CHECK-NEXT: .align  2
 ;CHECK-NEXT: foo_ptr:
+;CHECK-NEXT: .extern foo[DS]
 ;CHECK-NEXT: .long   foo[DS]
 ;CHECK-NEXT: .globl  bar_ptr1
 ;CHECK-NEXT: .align  2
@@ -25,6 +26,7 @@
 ;CHECK64-NEXT: .globl  foo_ptr
 ;CHECK64-NEXT: .align  3
 ;CHECK64-NEXT:foo_ptr:
+;CHECK64-NEXT:  .extern foo[DS]
 ;CHECK64-NEXT: .llong  foo[DS]
 ;CHECK64-NEXT: .globl  bar_ptr1
 ;CHECK64-NEXT: .align  3
Index: llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
@@ -0,0 +1,628 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT32 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT64 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec -filetype=obj -o %t.o < %s
+; RUN: llvm-readobj  --symbols %t.o | FileCheck --check-prefix=CHECKSYM %s
+
+@bar_p = global i32 (...)* @bar_ref, align 4
+@foo_weak_p = global void (...)* bitcast (void ()* @foo_ref_weak to void (...)*), align 4
+@foo_ext_weak_p = global void (...)* bitcast (void ()* @foo_ext_weak to void (...)*), align 4
+@b = weak global i32 0, align 4
+@b_e = external global i32, align 4
+
+define weak void @foo_weak() #0 {
+entry:
+  ret void
+}
+
+define weak void @foo_ref_weak() #0 {
+entry:
+  ret void
+}
+
+define void @foo() #0 {
+entry:
+  ret void
+}
+
+declare i32 @bar_ref(...) #1
+
+declare extern_weak void @foo_ext_weak() #1
+
+define i32 @main() #0 {
+entry:
+  %call = call i32 @bar_extern(i32* @b)
+  call void @foo()
+  %0 = load i32 (...)*, i32 (...)** @bar_p, align 4
+  %callee.knr.cast = bitcast i32 (...)* %0 to i32 (i32*)*
+  %call1 = call i32 %callee.knr.cast(i32* @b_e)
+  %1 = load void (...)*, void (...)** @foo_weak_p, align 4
+  %callee.knr.cast2 = bitcast void (...)* %1 to void ()*
+  call void %callee.knr.cast2()
+  %2 = load void (...)*, void (...)** @foo_ext_weak_p, align 4
+  %callee.knr.cast3 = bitcast void (...)* %2 to void ()*
+  call void %callee.knr.cast3()
+  call void @foo_weak()
+  ret i32 0
+}
+
+declare i32 @bar_extern(i32*) #1
+
+; COMMON:  	.weak	foo_weak[DS]# -- Begin function foo_weak
+; COMMON-NEXT:	.weak	.foo_weak
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect foo_weak[DS]
+; BIT32-NEXT:	.long	.foo_weak   # @foo_weak
+; BIT32-NEXT:	.long	TOC[TC0]
+; BIT32-NEXT:	.long	0
+; BIT64-NEXT:	.llong	.foo_weak   # @foo_weak
+; BIT64-NEXT:	.llong	TOC[TC0]
+; BIT64-NEXT:	.llong	0
+; COMMON-NEXT:	.csect .text[PR]
+; COMMON-NEXT:.foo_weak:
+
+; COMMON:	.weak	foo_ref_weak[DS]# -- Begin function foo_ref_weak
+; COMMON-NEXT:	.weak	.foo_ref_weak
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect foo_ref_weak[DS]
+; BIT32-NEXT:	.long	.foo_ref_weak   # @foo_ref_weak
+; BIT32-NEXT:	.long	TOC[TC0]
+; BIT32-NEXT:	.long	0
+; BIT64-NEXT:	.llong	.foo_ref_weak   # @foo_ref_weak
+; BIT64-NEXT:	.llong	TOC[TC0]
+; BIT64-NEXT:	.llong	0
+; COMMON-NEXT:	.csect .text[PR]
+; COMMON-NEXT:.foo_ref_weak:
+
+; COMMON:  	.globl	foo[DS] # -- Begin function foo
+; COMMON-NEXT:	.globl	.foo
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect foo[DS]
+; BIT32-NEXT:	.long	.foo# @foo
+; BIT32-NEXT:	.long	TOC[TC0]
+; BIT32-NEXT:	.long	0
+; BIT64-NEXT:	.llong	.foo# @foo
+; BIT64-NEXT:	.llong	TOC[TC0]
+; BIT64-NEXT:	.llong	0
+; COMMON-NEXT:	.csect .text[PR]
+; COMMON-NEXT:.foo:
+
+; COMMON:  	.globl	main[DS]# -- Begin function main
+; COMMON-NEXT:	.globl	.main
+; COMMON-NEXT:	.align	4
+; COMMON-NEXT:	.csect main[DS]
+; BIT32-NEXT:	.long	.main 

[PATCH] D76959: [WebAssembly] Import wasm_simd128.h from Emscripten

2020-03-27 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added inline comments.



Comment at: clang/lib/Headers/wasm_simd128.h:10
+
+#pragma once
+

tlively wrote:
> sunfish wrote:
> > Do you know why other clang headers, such as `lib/Headers/xmmintrin.h`, 
> > don't use `#pragma once`?
> No, I don't know. According to 
> https://github.com/emscripten-core/emscripten/pull/9299#discussion_r316893349 
> `#pragma once` is the convention in Emscripten's header files, but I don't 
> know what the trade offs are. @sbc100 do you have a better answer for this?
I think you should follow the local conventions.   For whatever reason `#pramga 
once` never really seems to take off (emscripten is the only project I know of 
that uses it).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76959



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


[clang] 0c42539 - Improve error recovery from missing '>' in template argument list.

2020-03-27 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-27T18:59:01-07:00
New Revision: 0c42539df3d4c697fa3bf6fc88e94b127d334a57

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

LOG: Improve error recovery from missing '>' in template argument list.

Produce the conventional "to match this '<'" note, so that the user
knows why we expected a '>', and properly handle '>>' in C++11 onwards.

Added: 


Modified: 
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/ParsedTemplate.h
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p3.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/Parser/cxx-member-initializers.cpp
clang/test/Parser/cxx-template-argument.cpp
clang/test/Parser/cxx-template-decl.cpp
clang/test/Parser/objc-error-qualified-implementation.m
clang/test/SemaCXX/decltype.cpp
clang/test/SemaCXX/implicit-exception-spec.cpp
clang/test/SemaCXX/injected-class-name-crash.cpp
clang/test/SemaObjC/crash-on-type-args-protocols.m
clang/test/SemaTemplate/ms-delayed-default-template-args.cpp

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6ebceee006e6..333c96e8cd27 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3160,7 +3160,8 @@ class Parser : public CodeCompletionHandler {
   // C++ 14.3: Template arguments [temp.arg]
   typedef SmallVector TemplateArgList;
 
-  bool ParseGreaterThanInTemplateList(SourceLocation ,
+  bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
+  SourceLocation ,
   bool ConsumeLastToken,
   bool ObjCGenericList);
   bool ParseTemplateIdAfterTemplateName(bool ConsumeLastToken,

diff  --git a/clang/include/clang/Sema/ParsedTemplate.h 
b/clang/include/clang/Sema/ParsedTemplate.h
index dd77cbf3b9fe..f0245b93c7eb 100644
--- a/clang/include/clang/Sema/ParsedTemplate.h
+++ b/clang/include/clang/Sema/ParsedTemplate.h
@@ -186,7 +186,7 @@ namespace clang {
 unsigned NumArgs;
 
 /// Whether an error was encountered in the template arguments.
-/// If so, NumArgs and the trailing argumentst are best-effort.
+/// If so, NumArgs and the trailing arguments are best-effort.
 bool ArgsInvalid;
 
 /// Retrieves a pointer to the template arguments

diff  --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 1c6163151386..f0a2a482f063 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -523,10 +523,9 @@ ObjCTypeParamList 
*Parser::parseObjCTypeParamListOrProtocolRefs(
 SkipUntil(tok::greater, tok::at, StopBeforeMatch);
 if (Tok.is(tok::greater))
   ConsumeToken();
-  } else if (ParseGreaterThanInTemplateList(rAngleLoc,
+  } else if (ParseGreaterThanInTemplateList(lAngleLoc, rAngleLoc,
 /*ConsumeLastToken=*/true,
 /*ObjCGenericList=*/true)) {
-Diag(lAngleLoc, diag::note_matching) << "'<'";
 SkipUntil({tok::greater, tok::greaterequal, tok::at, tok::minus,
tok::minus, tok::plus, tok::colon, tok::l_paren, tok::l_brace,
tok::comma, tok::semi },
@@ -1551,7 +1550,7 @@ ParseObjCProtocolReferences(SmallVectorImpl 
,
   }
 
   // Consume the '>'.
-  if (ParseGreaterThanInTemplateList(EndLoc, consumeLastToken,
+  if (ParseGreaterThanInTemplateList(LAngleLoc, EndLoc, consumeLastToken,
  /*ObjCGenericList=*/false))
 return true;
 
@@ -1649,7 +1648,7 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers(
   if (allSingleIdentifiers) {
 // Parse the closing '>'.
 SourceLocation rAngleLoc;
-(void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken,
+(void)ParseGreaterThanInTemplateList(lAngleLoc, rAngleLoc, 
consumeLastToken,
  /*ObjCGenericList=*/true);
 
 // Let Sema figure out what we parsed.
@@ -1755,7 +1754,7 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers(
 
   // Parse the closing '>'.
   SourceLocation rAngleLoc;
-  (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken,
+  (void)ParseGreaterThanInTemplateList(lAngleLoc, rAngleLoc, consumeLastToken,
/*ObjCGenericList=*/true);
 
   if (invalid) {

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 9b49a27b731e..518167321f18 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1031,7 +1031,8 @@ void 
Parser::DiagnoseMisplacedEllipsisInDeclarator(SourceLocation 

[PATCH] D68049: Propeller: Clang options for basic block sections

2020-03-27 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram updated this revision to Diff 253271.
tmsriram marked 5 inline comments as done.
tmsriram added a reviewer: eli.friedman.
tmsriram added a comment.

Clang options for Basic Block Sections enabled in D68063 
 and D73674 

1. -fbasicblock-sections = { "all" | "" | "labels" | "none" }
2. -funique-bb-section-names

Added more tests.  Rebased and checked that it applies cleanly on trunk.


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

https://reviews.llvm.org/D68049

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/basicblock-sections.c
  clang/test/CodeGen/basicblock-sections.funcnames
  clang/test/Driver/fbasicblock-sections.c
  clang/test/Driver/funique-bb-section-names.c

Index: clang/test/Driver/fbasicblock-sections.c
===
--- /dev/null
+++ clang/test/Driver/fbasicblock-sections.c
@@ -0,0 +1,9 @@
+// RUN: %clang -### -fbasicblock-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### -fbasicblock-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-ALL %s
+// RUN: %clang -### -fbasicblock-sections=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### -fbasicblock-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
+//
+// CHECK-OPT-NONE: "-fbasicblock-sections=none"
+// CHECK-OPT-ALL: "-fbasicblock-sections=all"
+// CHECK-OPT-LIST: -fbasicblock-sections={{[^ ]*}}fbasicblock-sections.c
+// CHECK-OPT-LABELS: "-fbasicblock-sections=labels"
Index: clang/test/Driver/funique-bb-section-names.c
===
--- /dev/null
+++ clang/test/Driver/funique-bb-section-names.c
@@ -0,0 +1,4 @@
+// RUN: %clang -### -funique-bb-section-names %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
+// RUN: %clang -### -funique-bb-section-names -fno-unique-bb-section-names %s -S 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
+// CHECK-OPT: "-funique-bb-section-names"
+// CHECK-NOOPT-NOT: "-funique-bb-section-names"
Index: clang/test/CodeGen/basicblock-sections.funcnames
===
--- /dev/null
+++ clang/test/CodeGen/basicblock-sections.funcnames
@@ -0,0 +1 @@
+!world
Index: clang/test/CodeGen/basicblock-sections.c
===
--- /dev/null
+++ clang/test/CodeGen/basicblock-sections.c
@@ -0,0 +1,47 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -o - < %s | FileCheck %s --check-prefix=PLAIN
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasicblock-sections=all -fbasicblock-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN
+
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasicblock-sections=labels -o - < %s | FileCheck %s --check-prefix=BB_LABELS
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasicblock-sections=all -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasicblock-sections=%S/basicblock-sections.funcnames -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasicblock-sections=all -funique-bb-section-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+
+int world(int a) {
+  if (a > 10)
+return 10;
+  else if (a > 5)
+return 5;
+  else
+return 0;
+}
+
+int another(int a) {
+  if (a > 10)
+return 20;
+  return 0;
+}
+
+// PLAIN-NOT: section
+// PLAIN: world
+//
+// BB_LABELS-NOT: section
+// BB_LABELS: world
+// BB_LABELS-LABEL: a.BB.world
+// BB_LABELS-LABEL: aa.BB.world
+// BB_LABEL-LABEL: a.BB.another
+//
+// BB_WORLD: .section .text.world,"ax",@progbits
+// BB_WORLD: world
+// BB_WORLD: .section .text.world,"ax",@progbits,unique
+// BB_WORLD: a.BB.world
+// BB_WORLD: .section .text.another,"ax",@progbits
+// BB_ALL: .section .text.another,"ax",@progbits,unique
+// BB_ALL: a.BB.another
+// BB_LIST-NOT: .section .text.another,"ax",@progbits,unique
+// BB_LIST: another
+// BB_LIST-NOT: a.BB.another
+//
+// UNIQUE: .section .text.world.a.BB.world
+// UNIQUE: .section .text.another.a.BB.another
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -953,11 +953,24 @@
   Opts.TrapFuncName = std::string(Args.getLastArgValue(OPT_ftrap_function_EQ));
   Opts.UseInitArray = !Args.hasArg(OPT_fno_use_init_array);
 
-  Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
+  Opts.BBSections =
+  

[PATCH] D76916: [Darwin] Respect -fno-unroll-loops during LTO.

2020-03-27 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a subscriber: Florian.
dexonsmith added a comment.

@fhahn, please revert, this isn't how we usually pass options in LTO.

If this is something we expect developers to use, it should be specifiable on a 
per-TU basis.  The way we do this is by specifying it during compilation, 
attaching string-based function attributes, and checking that attribute at the 
beginning of the "unroll loop" pass to see whether to skip it for that function.




Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:546-551
+  // Forward -fno-unroll-loops to the linker in LTO.
+  if (Args.hasArg(options::OPT_fno_unroll_loops)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-lto-no-unroll-loops"));
+  }
+

I don't understand why we need driver support for this... is this something we 
expect users to do?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76916



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


[PATCH] D76959: [WebAssembly] Import wasm_simd128.h from Emscripten

2020-03-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively marked 2 inline comments as done.
tlively added inline comments.



Comment at: clang/lib/Headers/wasm_simd128.h:10
+
+#pragma once
+

sunfish wrote:
> Do you know why other clang headers, such as `lib/Headers/xmmintrin.h`, don't 
> use `#pragma once`?
No, I don't know. According to 
https://github.com/emscripten-core/emscripten/pull/9299#discussion_r316893349 
`#pragma once` is the convention in Emscripten's header files, but I don't know 
what the trade offs are. @sbc100 do you have a better answer for this?



Comment at: clang/lib/Headers/wasm_simd128.h:42
+
+// v128 wasm_v128_load(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load(const void *__mem) {

sunfish wrote:
> This comment (and similar throughout the file) don't seem to be adding any 
> new information.
I agree. These have been around since the beginning of the file and we just 
kept adding them for consistency and never did anything else with them. I'll 
remove them now, but in the future (once the proposal is standardized?) we 
should put actual doc comments in their place, like xmmintrin.h has.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76959



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


[PATCH] D76959: [WebAssembly] Import wasm_simd128.h from Emscripten

2020-03-27 Thread Dan Gohman via Phabricator via cfe-commits
sunfish added a comment.

Very cool, thanks for putting this together!




Comment at: clang/lib/Headers/wasm_simd128.h:10
+
+#pragma once
+

Do you know why other clang headers, such as `lib/Headers/xmmintrin.h`, don't 
use `#pragma once`?



Comment at: clang/lib/Headers/wasm_simd128.h:30
+typedef long long __i64x2 __attribute__((__vector_size__(16), 
__aligned__(16)));
+typedef unsigned long long __u64x2
+__attribute__((__vector_size__(16), __aligned__(16)));

Since this file is already including , instead of `char`, `unsigned 
char`, `short`, `unsigned short`, etc., can these use `int8_t`, `uint8_t`, 
`int16_t`, `uint16_t`, and so on, for clarity? Also, this would avoid any 
possible behavior change under `-funsigned-char`.



Comment at: clang/lib/Headers/wasm_simd128.h:40
+#define __REQUIRE_CONSTANT(e)  
\
+  _Static_assert(__builtin_constant_p(e), "Expected constant")
+

In clang's xmmintrin.h, helper macros like these `__DEFAULT_FN_ATTRS` and 
`__REQUIRE_CONSTANT` are `#undef`ed at the end of the file.



Comment at: clang/lib/Headers/wasm_simd128.h:42
+
+// v128 wasm_v128_load(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load(const void *__mem) {

This comment (and similar throughout the file) don't seem to be adding any new 
information.



Comment at: clang/lib/Headers/wasm_simd128.h:87
+  struct __wasm_v64x2_load_splat_struct {
+long long __v;
+  } __attribute__((__packed__, __may_alias__));

Similar to above, these can use the fixed-size type names like `int64_t`.



Comment at: clang/lib/Headers/wasm_simd128.h:179
+int8_t c7, int8_t c8, int8_t c9, int8_t c10, int8_t c11, int8_t c12,
+int8_t c13, int8_t c14, int8_t c15) {
+  return (v128_t)(__i8x16){c0, c1, c2,  c3,  c4,  c5,  c6,  c7,

`c0`, `c1`, etc. aren't reserved identifiers, so the convention in other clang 
headers is to prefix them with `__`.



Comment at: clang/lib/Headers/wasm_simd128.h:293
+// v128_t wasm_i8x16_splat(int8_t a)
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_splat(int8_t a) {
+  return (v128_t)(__i8x16){a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a};

`a`, `b`, etc. also aren't reserved identifiers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76959



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


[clang] b3f6e3d - Improve recovery from invalid template-ids.

2020-03-27 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-27T17:11:04-07:00
New Revision: b3f6e3d6d64d77a9c840b8407b7e3c49b62b46dd

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

LOG: Improve recovery from invalid template-ids.

Instead of bailing out of parsing when we encounter an invalid
template-name or template arguments in a template-id, produce an
annotation token describing the invalid construct.

This avoids duplicate errors and generally allows us to recover better.
In principle we should be able to extend this to store some kinds of
invalid template-id in the AST for tooling use, but that isn't handled
as part of this change.

Added: 


Modified: 
clang/include/clang/Sema/Ownership.h
clang/include/clang/Sema/ParsedTemplate.h
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/DeclSpec.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/p3.cpp
clang/test/Parser/cxx-ambig-init-templ.cpp
clang/test/Parser/cxx-class.cpp
clang/test/Parser/cxx-member-initializers.cpp
clang/test/Parser/cxx-template-decl.cpp
clang/test/Parser/eof2.cpp
clang/test/Parser/recovery.cpp
clang/test/SemaCXX/PR20705.cpp
clang/test/SemaCXX/PR9459.cpp
clang/test/SemaCXX/builtins.cpp
clang/test/SemaCXX/implicit-exception-spec.cpp
clang/test/SemaCXX/injected-class-name-crash.cpp
clang/test/SemaCXX/invalid-member-expr.cpp
clang/test/SemaTemplate/ms-delayed-default-template-args.cpp
clang/test/SemaTemplate/temp_arg.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Ownership.h 
b/clang/include/clang/Sema/Ownership.h
index 4de3397d51b4..7c7b1d35c9fd 100644
--- a/clang/include/clang/Sema/Ownership.h
+++ b/clang/include/clang/Sema/Ownership.h
@@ -278,6 +278,7 @@ namespace clang {
 
   inline ExprResult ExprError() { return ExprResult(true); }
   inline StmtResult StmtError() { return StmtResult(true); }
+  inline TypeResult TypeError() { return TypeResult(true); }
 
   inline ExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); }
   inline StmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); }

diff  --git a/clang/include/clang/Sema/ParsedTemplate.h 
b/clang/include/clang/Sema/ParsedTemplate.h
index 82d00494b0d6..dd77cbf3b9fe 100644
--- a/clang/include/clang/Sema/ParsedTemplate.h
+++ b/clang/include/clang/Sema/ParsedTemplate.h
@@ -169,7 +169,9 @@ namespace clang {
 /// template-name.
 ParsedTemplateTy Template;
 
-/// The kind of template that Template refers to.
+/// The kind of template that Template refers to. If this is
+/// TNK_Non_template, an error was encountered and diagnosed
+/// when parsing or looking up the template name.
 TemplateNameKind Kind;
 
 /// The location of the '<' before the template argument
@@ -183,6 +185,10 @@ namespace clang {
 /// NumArgs - The number of template arguments.
 unsigned NumArgs;
 
+/// Whether an error was encountered in the template arguments.
+/// If so, NumArgs and the trailing argumentst are best-effort.
+bool ArgsInvalid;
+
 /// Retrieves a pointer to the template arguments
 ParsedTemplateArgument *getTemplateArgs() {
   return getTrailingObjects();
@@ -195,13 +201,13 @@ namespace clang {
IdentifierInfo *Name, OverloadedOperatorKind OperatorKind,
ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind,
SourceLocation LAngleLoc, SourceLocation RAngleLoc,
-   ArrayRef TemplateArgs,
+   ArrayRef TemplateArgs, bool ArgsInvalid,
SmallVectorImpl ) {
   TemplateIdAnnotation *TemplateId = new (llvm::safe_malloc(
   totalSizeToAlloc(TemplateArgs.size(
   TemplateIdAnnotation(TemplateKWLoc, TemplateNameLoc, Name,
OperatorKind, OpaqueTemplateName, TemplateKind,
-   LAngleLoc, RAngleLoc, TemplateArgs);
+   LAngleLoc, RAngleLoc, TemplateArgs, 
ArgsInvalid);
   CleanupList.push_back(TemplateId);
   return TemplateId;
 }
@@ -213,6 +219,20 @@ namespace clang {
   this->~TemplateIdAnnotation();
   free(this);
 }
+
+/// Determine whether this might be a type template.
+bool mightBeType() const {
+  return Kind == TNK_Non_template ||
+ Kind == TNK_Type_template ||
+ Kind == TNK_Dependent_template_name ||
+ Kind == TNK_Undeclared_template;
+}
+
+bool hasInvalidName() const { return Kind == 

Re: [clang] 857bf5d - [FIX] Do not copy an llvm::function_ref if it has to be reused

2020-03-27 Thread Arthur O'Dwyer via cfe-commits
On Fri, Mar 27, 2020 at 8:16 PM Arthur O'Dwyer 
wrote:

> Richard: Okay, filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94376 !
>
> David: You are correct, the bug in function_ref appeared only when
> constructing from `const function_ref&&`. When I said that the constructor
> template suppressed the copy constructor, I was wrong. The implicitly
> generated copy constructor is still there, and it's the best match for
> `const function_ref&` but not for `const function_ref&&`.  The bug would
> also appear with construction from `volatile function_ref&`, but, let's not
> go there. :)
>
> IMHO (YMMV), it would be worth *additionally* adding a complex but
> "realistic" test case that depends on the GCC bug, as opposed to your own
> test's simple but "unrealistic" cast to `const function_ref&&`. Here's a
> test case that I believe would have dereferenced null on GCC but would have
> worked fine on Clang—
>
> TEST(FunctionRefTest, BadCopyGCCBug) {
>
>   auto A = [] { return 1; };
>
>   function_ref W = A;
>
>   auto LW = [=]() {  // captures a data member 'const function_ref W'
>
>
...and naturally I put the comment on the wrong line. :P
The const-qualified capture happens on the *following* line.


> return [=]() {
>
>   return W();
>
> };
>
>   }();
>
>   auto LX = std::move(LW);  // calls function_ref's 'const&&' constructor
>
>   W = nullptr;
>
>   ASSERT_EQ(LX(), 1);
>
> }
>

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


Re: [clang] 857bf5d - [FIX] Do not copy an llvm::function_ref if it has to be reused

2020-03-27 Thread Arthur O'Dwyer via cfe-commits
Richard: Okay, filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94376 !

David: You are correct, the bug in function_ref appeared only when
constructing from `const function_ref&&`. When I said that the constructor
template suppressed the copy constructor, I was wrong. The implicitly
generated copy constructor is still there, and it's the best match for
`const function_ref&` but not for `const function_ref&&`.  The bug would
also appear with construction from `volatile function_ref&`, but, let's not
go there. :)

IMHO (YMMV), it would be worth *additionally* adding a complex but
"realistic" test case that depends on the GCC bug, as opposed to your own
test's simple but "unrealistic" cast to `const function_ref&&`. Here's a
test case that I believe would have dereferenced null on GCC but would have
worked fine on Clang—

TEST(FunctionRefTest, BadCopyGCCBug) {

  auto A = [] { return 1; };

  function_ref W = A;

  auto LW = [=]() {  // captures a data member 'const function_ref W'

return [=]() {

  return W();

};

  }();

  auto LX = std::move(LW);  // calls function_ref's 'const&&' constructor

  W = nullptr;

  ASSERT_EQ(LX(), 1);

}

–Arthur


On Fri, Mar 27, 2020 at 7:48 PM Richard Smith  wrote:

> On Thu, 26 Mar 2020 at 21:50, Arthur O'Dwyer via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> [...]
>> Argh! That is insanely sneaky, and it is quite probable IMHO that this is
>> a core-language bug in GCC, because GCC behaves differently from EDG and
>> Clang here.
>> https://godbolt.org/z/oCvLpv
>> On GCC, when you have a lambda nested within a lambda, and you
>> capture-by-copy a variable which was captured-by-copy using [=] or [i] (but
>> not C++14 init-capture [i=i]), then your data member for that capture will
>> have type `const I`, not just `I`.
>> On Clang and EDG, [=], [i], and [i=i] all behave equivalently, and
>> capture a data member with type `I`.
>>
>> I don't see anything about this on
>> https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=lambda%20capture%20const
>> — Richard, you might be best able to describe the issue correctly ;) but if
>> you want me to file it, I will.  (Might be a corollary of bug 86697
>> .)
>>
>
> Oh wow, so this would only fail with a combination of libstdc++ (which
> makes a copy of the lambda and destroy the original before copying the
> lambda) and GCC (which has a bug in how it determines the type of a nested
> capture)? Fascinating! :)
>
> [expr.prim.lambda.capture]p10 is the relevant rule: "The type of such a
> data member is the referenced type if the entity is a reference to an
> object, an lvalue reference to the referenced function type if the entity
> is a reference to a function, or the type of the corresponding captured
> entity otherwise."
>
> Regardless of whether you think the captured entity is the original
> variable or the member of the outer closure type, the type of that entity
> is not const-qualified. So the inner capture should not have a
> const-qualified type.
>
> Given that you identified the GCC capture bug, I think you should do the
> honors :)
>
>
>> Regardless, llvm::function_ref's SFINAE should still be fixed. This is a
>> bug in llvm::function_ref, exposed by a bug in GCC. (Or vice versa.)
>>
>
> Yup.
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast marked 3 inline comments as done.
PaulkaToast added a comment.

In D76818#1943781 , @njames93 wrote:

> If you want to make it a general check, you should consider making the 
> default module options set the correct namespace
> RequiredNamespace


Changed the check a bit so I'm not sure if pulling it out is still something 
desired, if so what module do you recommend this should live under?




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp:6
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: CXXRecord is not defined in a 
namespace, please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};

njames93 wrote:
> Small nit : Not a fan of the diagnostic saying `CXX Record`. Maybe a pain but 
> `getDeclKindName` isn't the best to expose to users. 
Removed getDeclKindName as recommended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818



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


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 253250.
PaulkaToast added a comment.

Updated to handle nested namespaces, exclude C linkages functions,  and made 
check language specific. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Please wrap implentation in '__llvm_libc' namespace.
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Please wrap implentation in '__llvm_libc' namespace.
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Please wrap implentation in '__llvm_libc' namespace.
+
+namespace namespaceG {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace.
+namespace namespaceH {
+class ClassB;
+} // namespace namespaceH
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace namespaceG
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+// Namespaces within __llvim_libc namespace allowed.
+namespace namespaceI {
+class ClassB;
+} // namespace namespaceI
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+extern "C" void extern_funcJ() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks all llvm-libc implementation is within the correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+// Namespaces within __llvm_libc namespace are allowed.
+namespace inner{
+int localVar = 0;
+}
+// Functions with C linkage are allowed.
+extern "C" void str_fuzz(){}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: outer most namespace is not correct.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+Options
+---
+
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The default
+is `__llvm_libc`.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-implementation-in-namespace
+  ` check.
+
+  Checks all llvm-libc implementation is within the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
Index: 

[PATCH] D76959: [WebAssembly] Import wasm_simd128.h from Emscripten

2020-03-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, sunfish.
Herald added subscribers: cfe-commits, jgravelle-google, sbc100, mgorny, 
dschuff.
Herald added a project: clang.
tlively updated this revision to Diff 253249.
tlively added a comment.

- Update license to match xmmintrin.h format


As the WebAssembly SIMD proposal nears stabilization, there is desire
to use it with toolchains other than Emscripten. Moving the intrinsics
header to clang will make it available to WASI toolchains as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76959

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/wasm_simd128.h

Index: clang/lib/Headers/wasm_simd128.h
===
--- /dev/null
+++ clang/lib/Headers/wasm_simd128.h
@@ -0,0 +1,1240 @@
+/*=== wasm_simd128.h - WebAssembly portable SIMD intrinsics ===
+ *
+ * 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
+ *
+ *===---===
+ */
+
+#pragma once
+
+#include 
+#include 
+
+// User-facing type
+typedef int32_t v128_t __attribute__((__vector_size__(16), __aligned__(16)));
+
+// Internal types determined by clang builtin definitions
+typedef int32_t __v128_u __attribute__((__vector_size__(16), __aligned__(1)));
+typedef char __i8x16 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned char __u8x16
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef short __i16x8 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned short __u16x8
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef int __i32x4 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned int __u32x4
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef long long __i64x2 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned long long __u64x2
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef float __f32x4 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef double __f64x2 __attribute__((__vector_size__(16), __aligned__(16)));
+
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __nodebug__, __target__("simd128"),\
+ __min_vector_width__(128)))
+
+#define __REQUIRE_CONSTANT(e)  \
+  _Static_assert(__builtin_constant_p(e), "Expected constant")
+
+// v128 wasm_v128_load(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load(const void *__mem) {
+  // UB-free unaligned access copied from xmmintrin.h
+  struct __wasm_v128_load_struct {
+__v128_u __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((const struct __wasm_v128_load_struct *)__mem)->__v;
+}
+
+#ifdef __wasm_unimplemented_simd128__
+
+// v128_t wasm_v8x16_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v8x16_load_splat(const void *__mem) {
+  struct __wasm_v8x16_load_splat_struct {
+char __v;
+  } __attribute__((__packed__, __may_alias__));
+  char v = ((const struct __wasm_v8x16_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i8x16){v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v};
+}
+
+// v128_t wasm_v16x8_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v16x8_load_splat(const void *__mem) {
+  struct __wasm_v16x8_load_splat_struct {
+short __v;
+  } __attribute__((__packed__, __may_alias__));
+  short v = ((const struct __wasm_v16x8_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i16x8){v, v, v, v, v, v, v, v};
+}
+
+// v128_t wasm_v32x4_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v32x4_load_splat(const void *__mem) {
+  struct __wasm_v32x4_load_splat_struct {
+int __v;
+  } __attribute__((__packed__, __may_alias__));
+  int v = ((const struct __wasm_v32x4_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i32x4){v, v, v, v};
+}
+
+// v128_t wasm_v64x2_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v64x2_load_splat(const void *__mem) {
+  struct __wasm_v64x2_load_splat_struct {
+long long __v;
+  } __attribute__((__packed__, __may_alias__));
+  long long v = ((const struct __wasm_v64x2_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i64x2){v, v};
+}
+
+// v128_t wasm_i16x8_load_8x8(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_i16x8_load_8x8(const void *__mem) {
+  typedef signed char __i8x8
+  __attribute__((__vector_size__(8), __aligned__(8)));
+  struct __wasm_i16x8_load_8x8_struct {
+__i8x8 __v;
+  } __attribute__((__packed__, __may_alias__));
+  __i8x8 v = ((const struct __wasm_i16x8_load_8x8_struct *)__mem)->__v;
+  return (v128_t) 

[PATCH] D76943: [clang analysis] Make mutex guard detection more reliable.

2020-03-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma updated this revision to Diff 253253.
efriedma added a comment.

Add support for conversion operators.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76943

Files:
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5648,6 +5648,19 @@
 auto ptr = get();
 return ptr->f();
   }
+  void use_constructor() {
+auto ptr = ReadLockedPtr(nullptr);
+ptr->f();
+auto ptr2 = ReadLockedPtr{nullptr};
+ptr2->f();
+auto ptr3 = (ReadLockedPtr{nullptr});
+ptr3->f();
+  }
+  struct Convertible { Convertible(); operator ReadLockedPtr(); };
+  void use_conversion() {
+ReadLockedPtr ptr = Convertible();
+ptr->f();
+  }
 }
 
 namespace PR38640 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,14 @@
 
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
-E = EWC->getSubExpr();
-  if (auto *ICE = dyn_cast(E))
-if (ICE->getCastKind() == CK_NoOp)
-  E = ICE->getSubExpr();
+E = EWC->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion ||
+CE->getCastKind() == CK_UserDefinedConversion)
+  E = CE->getSubExpr()->IgnoreParens();
   if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr();
+E = BTE->getSubExpr()->IgnoreParens();
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5648,6 +5648,19 @@
 auto ptr = get();
 return ptr->f();
   }
+  void use_constructor() {
+auto ptr = ReadLockedPtr(nullptr);
+ptr->f();
+auto ptr2 = ReadLockedPtr{nullptr};
+ptr2->f();
+auto ptr3 = (ReadLockedPtr{nullptr});
+ptr3->f();
+  }
+  struct Convertible { Convertible(); operator ReadLockedPtr(); };
+  void use_conversion() {
+ReadLockedPtr ptr = Convertible();
+ptr->f();
+  }
 }
 
 namespace PR38640 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,14 @@
 
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
-E = EWC->getSubExpr();
-  if (auto *ICE = dyn_cast(E))
-if (ICE->getCastKind() == CK_NoOp)
-  E = ICE->getSubExpr();
+E = EWC->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion ||
+CE->getCastKind() == CK_UserDefinedConversion)
+  E = CE->getSubExpr()->IgnoreParens();
   if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr();
+E = BTE->getSubExpr()->IgnoreParens();
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76959: [WebAssembly] Import wasm_simd128.h from Emscripten

2020-03-27 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 253249.
tlively added a comment.

- Update license to match xmmintrin.h format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76959

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/wasm_simd128.h

Index: clang/lib/Headers/wasm_simd128.h
===
--- /dev/null
+++ clang/lib/Headers/wasm_simd128.h
@@ -0,0 +1,1240 @@
+/*=== wasm_simd128.h - WebAssembly portable SIMD intrinsics ===
+ *
+ * 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
+ *
+ *===---===
+ */
+
+#pragma once
+
+#include 
+#include 
+
+// User-facing type
+typedef int32_t v128_t __attribute__((__vector_size__(16), __aligned__(16)));
+
+// Internal types determined by clang builtin definitions
+typedef int32_t __v128_u __attribute__((__vector_size__(16), __aligned__(1)));
+typedef char __i8x16 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned char __u8x16
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef short __i16x8 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned short __u16x8
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef int __i32x4 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned int __u32x4
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef long long __i64x2 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef unsigned long long __u64x2
+__attribute__((__vector_size__(16), __aligned__(16)));
+typedef float __f32x4 __attribute__((__vector_size__(16), __aligned__(16)));
+typedef double __f64x2 __attribute__((__vector_size__(16), __aligned__(16)));
+
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __nodebug__, __target__("simd128"),\
+ __min_vector_width__(128)))
+
+#define __REQUIRE_CONSTANT(e)  \
+  _Static_assert(__builtin_constant_p(e), "Expected constant")
+
+// v128 wasm_v128_load(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load(const void *__mem) {
+  // UB-free unaligned access copied from xmmintrin.h
+  struct __wasm_v128_load_struct {
+__v128_u __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((const struct __wasm_v128_load_struct *)__mem)->__v;
+}
+
+#ifdef __wasm_unimplemented_simd128__
+
+// v128_t wasm_v8x16_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v8x16_load_splat(const void *__mem) {
+  struct __wasm_v8x16_load_splat_struct {
+char __v;
+  } __attribute__((__packed__, __may_alias__));
+  char v = ((const struct __wasm_v8x16_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i8x16){v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v};
+}
+
+// v128_t wasm_v16x8_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v16x8_load_splat(const void *__mem) {
+  struct __wasm_v16x8_load_splat_struct {
+short __v;
+  } __attribute__((__packed__, __may_alias__));
+  short v = ((const struct __wasm_v16x8_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i16x8){v, v, v, v, v, v, v, v};
+}
+
+// v128_t wasm_v32x4_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v32x4_load_splat(const void *__mem) {
+  struct __wasm_v32x4_load_splat_struct {
+int __v;
+  } __attribute__((__packed__, __may_alias__));
+  int v = ((const struct __wasm_v32x4_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i32x4){v, v, v, v};
+}
+
+// v128_t wasm_v64x2_load_splat(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_v64x2_load_splat(const void *__mem) {
+  struct __wasm_v64x2_load_splat_struct {
+long long __v;
+  } __attribute__((__packed__, __may_alias__));
+  long long v = ((const struct __wasm_v64x2_load_splat_struct *)__mem)->__v;
+  return (v128_t)(__i64x2){v, v};
+}
+
+// v128_t wasm_i16x8_load_8x8(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_i16x8_load_8x8(const void *__mem) {
+  typedef signed char __i8x8
+  __attribute__((__vector_size__(8), __aligned__(8)));
+  struct __wasm_i16x8_load_8x8_struct {
+__i8x8 __v;
+  } __attribute__((__packed__, __may_alias__));
+  __i8x8 v = ((const struct __wasm_i16x8_load_8x8_struct *)__mem)->__v;
+  return (v128_t) __builtin_convertvector(v, __i16x8);
+}
+
+// v128_t wasm_i16x8_load_8x8(void* mem)
+static __inline__ v128_t __DEFAULT_FN_ATTRS
+wasm_u16x8_load_8x8(const void *__mem) {
+  typedef unsigned char __u8x8
+  __attribute__((__vector_size__(8), __aligned__(8)));
+  struct __wasm_u16x8_load_8x8_struct {
+__u8x8 __v;
+  } 

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1947103 , @tra wrote:

> In D76365#1946938 , @hliao wrote:
>
> > The new revision is accepted, right? Just want to confirm as it seems you 
> > accept it before I posted the new change.
>
>
> The approval was for the old version. I didn't undo it when I reopened the 
> review. The diff looks OK, though the last variant still leaves open the 
> question of what's the meaning of these attributes and what are the 
> restrictions on their use.
>
> So what's the reasonable thing to do if I write something like this:
>
>   __attribute__((device_builtin_surface_type)) int foo; // Ignore? Warn? 
> Error? Do something sensible?
>


I remembered that triggers NVCC internal errors or errors. I will check that 
this night.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


Re: [clang] 857bf5d - [FIX] Do not copy an llvm::function_ref if it has to be reused

2020-03-27 Thread Richard Smith via cfe-commits
On Fri, 27 Mar 2020 at 16:35, David Blaikie via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, Mar 26, 2020 at 8:49 PM Richard Smith 
> wrote:
>
>> On Thu, 26 Mar 2020 at 17:07, David Blaikie via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> On Thu, Mar 26, 2020 at 3:12 PM Arthur O'Dwyer <
>>> arthur.j.odw...@gmail.com> wrote:
>>>
 I'm not sure, but I do see that the call stack contains a call to

 bool llvm::function_ref>>> bool)>::callback_fn 
 const>(long, clang::Expr*&, bool)

 Notice that this is function_ref::callback_fn instantiated with
 T=function_ref itself; i.e., we do have a function_ref to a function_ref.
 This is the thing I was saying can happen (in my "lamb/sheep" example) but
 which I thought should never happen in this codepath.
 Here's function_ref's copy constructor:


   template 

   function_ref(Callable &,


 std::enable_if_t,

   function_ref>::value> * =
 nullptr)

   : callback(callback_fn>>> std::remove_reference::type>),

 callable(reinterpret_cast()) {}


 I believe that it should be using std::remove_cvref_t, not
 std::remove_reference_t, so as not to conflict with the compiler's
 implicitly generated copy constructor.

 Thoughts?

>>>
>>> Yep, looks like you're on to something here - I still don't understand
>>> why calling that function rather than the real trivial copy ctor would be
>>> problematic,
>>>
>>
>> OK, so: we're calling the wrong constructor for the inner capture due to
>> the implicit 'const' that's added because the outer lambda is not mutable
>> (and the fix suggested by Arthur is the right one: we should be using
>> remove_cvref_t here not remove_reference_t -- or rather
>> std::remove_cv_t>, since we don't require
>> C++20 yet). And this means that copying a function_ref from a *const*
>> function_ref gives you a new function_ref that refers to the old one, not a
>> new function_ref that refers to the same function the old one did. In
>> particular, this happens when copying a lambda that captures a function_ref
>> by value.
>>
>
> I was only able to hit this with a const rvalue reference - is that
> expected, or did I overcomplicate my test case in some way?
>

No, my analysis was incomplete, sorry. For a const function_ref&, we call
the implicit copy constructor rather than the constructor template. const
function_ref&& breaks because it isn't an exact match for an implicit
copy/move constructor.


> (this: "const function_ref a; function_ref b = a;" didn't hit the
> converting ctor, it ran the copy ctor as desired. I had to "function_ref
> b = static_cast &&>(a);" to tickle it)
>
> Committed the fix/test in cbce88dd3a9ea7161da3c57749cf03873dc7ea79 - open
> to suggestions on simplification of the test case if there is some. Oh, I
> might've named the new test case a bit poorly... didn't go back and edit
> that after it got more baked.
>
>
>>
>> The next part of the puzzle is that llvm::any_of takes its callback by
>> value and passes it by value to std::any_of. And inside any_of, in
>> libstdc++, the predicate is passed through __pred_iter (
>> https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/predefined_ops.h#L323)
>> before being used. That results in building a function_ref referring to
>> part of the function parameter in __pred_iter, whose lifetime ends before
>> we call it.
>>
>> With libc++, the predicate is not copied around inside any_of, which is
>> why this was only failing on some buildbots.
>>
>> but I managed to reproduce this locally with GCC 7.5 (seems to be an
>>> issue with the 7 series - the buildbot used 7.3) & if I capture by value in
>>> both outer and inner lambdas it reproduces, but if I mark the outer lambda
>>> as mutable it succeeds (because this would remove the const & not trip over
>>> the SFINAE issue you pointed out)...
>>>
>>> Investigation continues.
>>>
>>> - Dave
>>>
>>>
 –Arthur



 On Thu, Mar 26, 2020 at 5:08 PM David Blaikie 
 wrote:

> Hey Richard - could you help try to diagnose what's happening here?
>
> I reverted this patch in:
> https://github.com/llvm/llvm-project/commit/0d0b90105f92f6cd9cc7004d565834f4429183fb
> But that did actually cause buildbot failures, such as these ones:
> http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/24491
>   eg:
> http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/24491/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Adeclare_variant_mixed_codegen.cpp
> I "fixed" these failures blind by reapplying part of this original
> commit (the lambda capture by reference rather than by value):
> https://github.com/llvm/llvm-project/commit/2ec59a0a40f4ec02e6b2dbe5f12261959c191aa9
>
> I've stared at this a fair bit and can't spot 

Re: [clang] 857bf5d - [FIX] Do not copy an llvm::function_ref if it has to be reused

2020-03-27 Thread Richard Smith via cfe-commits
On Thu, 26 Mar 2020 at 21:50, Arthur O'Dwyer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, Mar 26, 2020 at 11:49 PM Richard Smith 
> wrote:
>
>> On Thu, 26 Mar 2020 at 17:07, David Blaikie via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> On Thu, Mar 26, 2020 at 3:12 PM Arthur O'Dwyer <
>>> arthur.j.odw...@gmail.com> wrote:
>>>
 I'm not sure, but I do see that the call stack contains a call to

 bool llvm::function_ref>>> bool)>::callback_fn 
 const>(long, clang::Expr*&, bool)

 Notice that this is function_ref::callback_fn instantiated with
 T=function_ref itself; i.e., we do have a function_ref to a function_ref.
 This is the thing I was saying can happen (in my "lamb/sheep" example) but
 which I thought should never happen in this codepath.
 Here's function_ref's copy constructor:


   template 

   function_ref(Callable &,


 std::enable_if_t,

   function_ref>::value> * =
 nullptr)

   : callback(callback_fn>>> std::remove_reference::type>),

 callable(reinterpret_cast()) {}


 I believe that it should be using std::remove_cvref_t, not
 std::remove_reference_t, so as not to conflict with the compiler's
 implicitly generated copy constructor.

 Thoughts? [...]

>>>
>> OK, so: we're calling the wrong constructor for the inner capture due to
>> the implicit 'const' that's added because the outer lambda is not mutable
>> (and the fix suggested by Arthur is the right one: we should be using
>> remove_cvref_t here not remove_reference_t -- or rather
>> std::remove_cv_t>, since we don't require
>> C++20 yet). And this means that copying a function_ref from a *const*
>> function_ref gives you a new function_ref that refers to the old one, not a
>> new function_ref that refers to the same function the old one did.
>>
>
> Argh! That is insanely sneaky, and it is quite probable IMHO that this is
> a core-language bug in GCC, because GCC behaves differently from EDG and
> Clang here.
> https://godbolt.org/z/oCvLpv
> On GCC, when you have a lambda nested within a lambda, and you
> capture-by-copy a variable which was captured-by-copy using [=] or [i] (but
> not C++14 init-capture [i=i]), then your data member for that capture will
> have type `const I`, not just `I`.
> On Clang and EDG, [=], [i], and [i=i] all behave equivalently, and capture
> a data member with type `I`.
>
> I don't see anything about this on
> https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=lambda%20capture%20const
> — Richard, you might be best able to describe the issue correctly ;) but if
> you want me to file it, I will.  (Might be a corollary of bug 86697
> .)
>

Oh wow, so this would only fail with a combination of libstdc++ (which
makes a copy of the lambda and destroy the original before copying the
lambda) and GCC (which has a bug in how it determines the type of a nested
capture)? Fascinating! :)

[expr.prim.lambda.capture]p10 is the relevant rule: "The type of such a
data member is the referenced type if the entity is a reference to an
object, an lvalue reference to the referenced function type if the entity
is a reference to a function, or the type of the corresponding captured
entity otherwise."

Regardless of whether you think the captured entity is the original
variable or the member of the outer closure type, the type of that entity
is not const-qualified. So the inner capture should not have a
const-qualified type.

Given that you identified the GCC capture bug, I think you should do the
honors :)


> Regardless, llvm::function_ref's SFINAE should still be fixed. This is a
> bug in llvm::function_ref, exposed by a bug in GCC. (Or vice versa.)
>

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


Re: [clang] 2ec59a0 - Buildbot debugging of 0d0b90105f92f6cd9cc7004d565834f4429183fb (lambda/function_ref lifetime issues)

2020-03-27 Thread David Blaikie via cfe-commits
Underlying function_ref fix made in
https://github.com/llvm/llvm-project/commit/cbce88dd3a9ea7161da3c57749cf03873dc7ea79
But
I'm still happy to leave this code in as-is, though function_ref is small
enough to be cheap to copy, I think it's simpler to write
local/non-escaping lambdas with "[&]" for simplicity/clarity.

On Sun, Mar 22, 2020 at 10:44 PM David Blaikie via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: David Blaikie
> Date: 2020-03-22T22:43:44-07:00
> New Revision: 2ec59a0a40f4ec02e6b2dbe5f12261959c191aa9
>
> URL:
> https://github.com/llvm/llvm-project/commit/2ec59a0a40f4ec02e6b2dbe5f12261959c191aa9
> DIFF:
> https://github.com/llvm/llvm-project/commit/2ec59a0a40f4ec02e6b2dbe5f12261959c191aa9.diff
>
> LOG: Buildbot debugging of 0d0b90105f92f6cd9cc7004d565834f4429183fb
> (lambda/function_ref lifetime issues)
>
> This is failing on several buildbots with some inexplicable (to me,
> right now) crashes. Let's see if this change is adequate to unblock the
> buildbots & further understanding can be gained later.
>
> Added:
>
>
> Modified:
> clang/include/clang/AST/OpenMPClause.h
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/AST/OpenMPClause.h
> b/clang/include/clang/AST/OpenMPClause.h
> index 548328d36a79..a781797c2d56 100644
> --- a/clang/include/clang/AST/OpenMPClause.h
> +++ b/clang/include/clang/AST/OpenMPClause.h
> @@ -7061,9 +7061,9 @@ struct OMPTraitInfo {
>
>bool anyScoreOrCondition(
>llvm::function_ref Cond) {
> -return llvm::any_of(Sets, [Cond](OMPTraitInfo::OMPTraitSet ) {
> +return llvm::any_of(Sets, [&](OMPTraitInfo::OMPTraitSet ) {
>return llvm::any_of(
> -  Set.Selectors, [Cond](OMPTraitInfo::OMPTraitSelector )
> {
> +  Set.Selectors, [&](OMPTraitInfo::OMPTraitSelector ) {
>  return Cond(Selector.ScoreOrCondition,
>  /* IsScore */ Selector.Kind !=
>  llvm::omp::TraitSelector::user_condition);
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] 857bf5d - [FIX] Do not copy an llvm::function_ref if it has to be reused

2020-03-27 Thread David Blaikie via cfe-commits
On Thu, Mar 26, 2020 at 8:49 PM Richard Smith  wrote:

> On Thu, 26 Mar 2020 at 17:07, David Blaikie via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> On Thu, Mar 26, 2020 at 3:12 PM Arthur O'Dwyer 
>> wrote:
>>
>>> I'm not sure, but I do see that the call stack contains a call to
>>>
>>> bool llvm::function_ref>> bool)>::callback_fn 
>>> const>(long, clang::Expr*&, bool)
>>>
>>> Notice that this is function_ref::callback_fn instantiated with
>>> T=function_ref itself; i.e., we do have a function_ref to a function_ref.
>>> This is the thing I was saying can happen (in my "lamb/sheep" example) but
>>> which I thought should never happen in this codepath.
>>> Here's function_ref's copy constructor:
>>>
>>>
>>>   template 
>>>
>>>   function_ref(Callable &,
>>>
>>>
>>> std::enable_if_t,
>>>
>>>   function_ref>::value> * =
>>> nullptr)
>>>
>>>   : callback(callback_fn>> std::remove_reference::type>),
>>>
>>> callable(reinterpret_cast()) {}
>>>
>>>
>>> I believe that it should be using std::remove_cvref_t, not
>>> std::remove_reference_t, so as not to conflict with the compiler's
>>> implicitly generated copy constructor.
>>>
>>> Thoughts?
>>>
>>
>> Yep, looks like you're on to something here - I still don't understand
>> why calling that function rather than the real trivial copy ctor would be
>> problematic,
>>
>
> OK, so: we're calling the wrong constructor for the inner capture due to
> the implicit 'const' that's added because the outer lambda is not mutable
> (and the fix suggested by Arthur is the right one: we should be using
> remove_cvref_t here not remove_reference_t -- or rather
> std::remove_cv_t>, since we don't require
> C++20 yet). And this means that copying a function_ref from a *const*
> function_ref gives you a new function_ref that refers to the old one, not a
> new function_ref that refers to the same function the old one did. In
> particular, this happens when copying a lambda that captures a function_ref
> by value.
>

I was only able to hit this with a const rvalue reference - is that
expected, or did I overcomplicate my test case in some way? (this: "const
function_ref a; function_ref b = a;" didn't hit the converting ctor,
it ran the copy ctor as desired. I had to "function_ref b =
static_cast &&>(a);" to tickle it)

Committed the fix/test in cbce88dd3a9ea7161da3c57749cf03873dc7ea79 - open
to suggestions on simplification of the test case if there is some. Oh, I
might've named the new test case a bit poorly... didn't go back and edit
that after it got more baked.


>
> The next part of the puzzle is that llvm::any_of takes its callback by
> value and passes it by value to std::any_of. And inside any_of, in
> libstdc++, the predicate is passed through __pred_iter (
> https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/predefined_ops.h#L323)
> before being used. That results in building a function_ref referring to
> part of the function parameter in __pred_iter, whose lifetime ends before
> we call it.
>
> With libc++, the predicate is not copied around inside any_of, which is
> why this was only failing on some buildbots.
>
> but I managed to reproduce this locally with GCC 7.5 (seems to be an issue
>> with the 7 series - the buildbot used 7.3) & if I capture by value in both
>> outer and inner lambdas it reproduces, but if I mark the outer lambda as
>> mutable it succeeds (because this would remove the const & not trip over
>> the SFINAE issue you pointed out)...
>>
>> Investigation continues.
>>
>> - Dave
>>
>>
>>> –Arthur
>>>
>>>
>>>
>>> On Thu, Mar 26, 2020 at 5:08 PM David Blaikie 
>>> wrote:
>>>
 Hey Richard - could you help try to diagnose what's happening here?

 I reverted this patch in:
 https://github.com/llvm/llvm-project/commit/0d0b90105f92f6cd9cc7004d565834f4429183fb
 But that did actually cause buildbot failures, such as these ones:
 http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/24491
   eg:
 http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/24491/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Adeclare_variant_mixed_codegen.cpp
 I "fixed" these failures blind by reapplying part of this original
 commit (the lambda capture by reference rather than by value):
 https://github.com/llvm/llvm-project/commit/2ec59a0a40f4ec02e6b2dbe5f12261959c191aa9

 I've stared at this a fair bit and can't spot any undefined behavior,
 but I guess it's probably in there somewhere - and I'm worried that this
 fix is blind, not fully justified & might be hiding some latent issues.

 The full buildbot example failure quoted here in case it times out/gets
 deleted on the buildbot itself:

  TEST 'Clang ::
 OpenMP/declare_variant_mixed_codegen.cpp' FAILED 
 Script:
 --
 : 'RUN: at line 1';
 

[PATCH] D76943: [clang analysis] Make mutex guard detection more reliable.

2020-03-27 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added subscribers: aaron.ballman, aaronpuchert.
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2144-2145
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion)
+  E = CE->getSubExpr()->IgnoreParens();

rsmith wrote:
> Should we also skip over `CK_UserDefinedConversion` here (for conversion 
> functions that return mutex locks, I suppose)?
Seems reasonable, there could be a CXXMemberCallExpr to an annotated function 
below that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76943



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


[PATCH] D76939: [AST] Add a Dependence bitmask to use for calculations with multiple node types.

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGd68c09ac8795: [AST] Add a Dependence bitmask to use for 
calculations with multiple node types. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D76939?vs=253169=253246#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76939

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/lib/AST/ComputeDependence.cpp

Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -370,7 +370,8 @@
   auto Deps = ExprDependence::None;
 
   if (auto *NNS = E->getQualifier())
-Deps |= toExprDependence(NNS->getDependence());
+Deps |= toExprDependence(NNS->getDependence() &
+ ~NestedNameSpecifierDependence::Dependent);
 
   if (auto *FirstArg = E->getTemplateArgs()) {
 unsigned NumArgs = E->getNumTemplateArgs();
@@ -590,7 +591,8 @@
 D |= turnTypeToValueDependence(
 toExprDependence(ST->getType()->getDependence()));
   if (auto *Q = E->getQualifier())
-D |= toExprDependence(Q->getDependence());
+D |= toExprDependence(Q->getDependence() &
+  ~NestedNameSpecifierDependence::Dependent);
   return D;
 }
 
@@ -616,7 +618,8 @@
 Deps |= ExprDependence::UnexpandedPack;
   Deps |= getDependenceInExpr(E->getNameInfo());
   if (auto *Q = E->getQualifier())
-Deps |= toExprDependence(Q->getDependence());
+Deps |= toExprDependence(Q->getDependence() &
+ ~NestedNameSpecifierDependence::Dependent);
   for (auto *D : E->decls()) {
 if (D->getDeclContext()->isDependentContext() ||
 isa(D))
Index: clang/include/clang/AST/DependenceFlags.h
===
--- clang/include/clang/AST/DependenceFlags.h
+++ clang/include/clang/AST/DependenceFlags.h
@@ -83,29 +83,126 @@
 LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
 #undef LLVM_COMMON_DEPENDENCE
 
+// A combined space of all dependence concepts for all node types.
+// Used when aggregating dependence of nodes of different types.
+class Dependence {
+public:
+  enum Bits : uint8_t {
+None = 0,
+
+// Contains a template parameter pack that wasn't expanded.
+UnexpandedPack = 1,
+// Uses a template parameter, even if it doesn't affect the result.
+// Validity depends on the template parameter.
+Instantiation = 2,
+// Expression type depends on template context.
+// Value and Instantiation should also be set.
+Type = 4,
+// Expression value depends on template context.
+// Instantiation should also be set.
+Value = 8,
+// Depends on template context.
+// The type/value distinction is only meaningful for expressions.
+Dependent = Type | Value,
+// Includes an error, and depends on how it is resolved.
+Error = 16,
+// Type depends on a runtime value (variable-length array).
+VariablyModified = 32,
+
+LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
+  };
+
+  Dependence() : V(None) {}
+
+  Dependence(TypeDependence D)
+  : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TypeDependence::Instantiation, Instantiation) |
+ translate(D, TypeDependence::Dependent, Dependent) |
+ translate(D, TypeDependence::VariablyModified, VariablyModified)) {
+  }
+
+  Dependence(ExprDependence D)
+  : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, ExprDependence::Instantiation, Instantiation) |
+ translate(D, ExprDependence::Type, Type) |
+ translate(D, ExprDependence::Value, Value) |
+ translate(D, ExprDependence::Error, Error)) {}
+
+  Dependence(NestedNameSpecifierDependence D) :
+V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
+translate(D, NNSDependence::Instantiation, Instantiation) |
+translate(D, NNSDependence::Dependent, Dependent)){}
+
+  Dependence(TemplateArgumentDependence D)
+  : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TADependence::Instantiation, Instantiation) |
+ translate(D, TADependence::Dependent, Dependent)) {}
+
+  Dependence(TemplateNameDependence D)
+  : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TNDependence::Instantiation, Instantiation) |
+ translate(D, TNDependence::Dependent, Dependent)) {}
+
+  TypeDependence type() const {
+return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
+   translate(V, Instantiation, TypeDependence::Instantiation) |
+   translate(V, Dependent, 

[PATCH] D76939: [AST] Add a Dependence bitmask to use for calculations with multiple node types.

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 3 inline comments as done.
sammccall added inline comments.



Comment at: clang/include/clang/AST/DependenceFlags.h:120
+
+  Dependence(Bits V) : V(V) {}
+

hokein wrote:
> nit: this seems to be unused?
Removed. (It'll be back in the next patch, though)



Comment at: clang/include/clang/AST/DependenceFlags.h:152
+  TypeDependence type() const {
+return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
+   translate(V, Instantiation, TypeDependence::Instantiation) |

hokein wrote:
> maybe make `Bits` as scoped enum? I find `translate(V, Bits::UnexpandedPack, 
> TypeDependence::UnexpandedPack)` is clearer.
The main users will be outside this file, e.g. in ComputeDependence

```
Dependence D;
if (whatever)
  D.add(Dependence::Instantiation);
```

I think these read a lot better without another qualifier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76939



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


[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:245
+  auto  = Inputs.AST->getSourceManager();
+  auto TB = Inputs.AST->getTokens();
+  // Determine the length of the qualifier under the cursor, then remove it.

sammccall wrote:
> yikes, this copies the tokenbuffer, I didn't think that was even possible!
> auto&
Copy constructor deleted in 94938d7d41cd11c4539ff93b801fe53cb4fddba2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76432



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


[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253245.
oontvoo added a comment.

Updated tests and get it to pass


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/dummy_pragma_once.h
  clang/test/Modules/Inputs/dummy_textual_header.h
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/import-pragma-once.c

Index: clang/test/Modules/import-pragma-once.c
===
--- /dev/null
+++ clang/test/Modules/import-pragma-once.c
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fimplicit-module-maps -I%S/Inputs -verify -x c %s
+#include "dummy_pragma_once.h"
+#include "dummy_textual_header.h"
+
+void *p = 
+void *q = 
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -282,6 +282,11 @@
   header "dummy.h"
 }
 
+module dummy_pragma_once {
+  header "dummy_pragma_once.h"
+  textual header "dummy_textual_header.h"
+}
+
 module builtin {
   header "builtin.h"
   explicit module sub {
Index: clang/test/Modules/Inputs/dummy_textual_header.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_textual_header.h
@@ -0,0 +1,2 @@
+#pragma once
+int y = 6;
Index: clang/test/Modules/Inputs/dummy_pragma_once.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_pragma_once.h
@@ -0,0 +1,3 @@
+#include "dummy_textual_header.h"
+
+int x = 5;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1621,7 +1621,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1678,6 +1678,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1705,7 +1708,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1783,8 +1786,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1801,8 +1803,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2636,6 +2643,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to 

[clang] d68c09a - [AST] Add a Dependence bitmask to use for calculations with multiple node types.

2020-03-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-28T00:15:50+01:00
New Revision: d68c09ac87959694fbb4895ff49443afc2b582f9

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

LOG: [AST] Add a Dependence bitmask to use for calculations with multiple node 
types.

Summary:
This makes it easier/safer to add bits (error) to other node types without
worrying about bit layout all the time.

For now, just use to implement the ad-hoc conversion functions.
Next: remove these functions and use this directly.

Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/lib/AST/ComputeDependence.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index c92b0c65..75c9aa1656b8 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -83,29 +83,126 @@ LLVM_COMMON_DEPENDENCE(TemplateNameDependence)
 LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
 #undef LLVM_COMMON_DEPENDENCE
 
+// A combined space of all dependence concepts for all node types.
+// Used when aggregating dependence of nodes of 
diff erent types.
+class Dependence {
+public:
+  enum Bits : uint8_t {
+None = 0,
+
+// Contains a template parameter pack that wasn't expanded.
+UnexpandedPack = 1,
+// Uses a template parameter, even if it doesn't affect the result.
+// Validity depends on the template parameter.
+Instantiation = 2,
+// Expression type depends on template context.
+// Value and Instantiation should also be set.
+Type = 4,
+// Expression value depends on template context.
+// Instantiation should also be set.
+Value = 8,
+// Depends on template context.
+// The type/value distinction is only meaningful for expressions.
+Dependent = Type | Value,
+// Includes an error, and depends on how it is resolved.
+Error = 16,
+// Type depends on a runtime value (variable-length array).
+VariablyModified = 32,
+
+LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
+  };
+
+  Dependence() : V(None) {}
+
+  Dependence(TypeDependence D)
+  : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TypeDependence::Instantiation, Instantiation) |
+ translate(D, TypeDependence::Dependent, Dependent) |
+ translate(D, TypeDependence::VariablyModified, VariablyModified)) 
{
+  }
+
+  Dependence(ExprDependence D)
+  : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, ExprDependence::Instantiation, Instantiation) |
+ translate(D, ExprDependence::Type, Type) |
+ translate(D, ExprDependence::Value, Value) |
+ translate(D, ExprDependence::Error, Error)) {}
+
+  Dependence(NestedNameSpecifierDependence D) :
+V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
+translate(D, NNSDependence::Instantiation, Instantiation) |
+translate(D, NNSDependence::Dependent, Dependent)){}
+
+  Dependence(TemplateArgumentDependence D)
+  : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TADependence::Instantiation, Instantiation) |
+ translate(D, TADependence::Dependent, Dependent)) {}
+
+  Dependence(TemplateNameDependence D)
+  : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TNDependence::Instantiation, Instantiation) |
+ translate(D, TNDependence::Dependent, Dependent)) {}
+
+  TypeDependence type() const {
+return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
+   translate(V, Instantiation, TypeDependence::Instantiation) |
+   translate(V, Dependent, TypeDependence::Dependent) |
+   translate(V, VariablyModified, TypeDependence::VariablyModified);
+  }
+
+  ExprDependence expr() const {
+return translate(V, UnexpandedPack, ExprDependence::UnexpandedPack) |
+   translate(V, Instantiation, ExprDependence::Instantiation) |
+   translate(V, Type, ExprDependence::Type) |
+   translate(V, Value, ExprDependence::Value) |
+   translate(V, Error, ExprDependence::Error);
+  }
+
+  NestedNameSpecifierDependence nestedNameSpecifier() const {
+return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
+   translate(V, Instantiation, NNSDependence::Instantiation) |
+   translate(V, Dependent, NNSDependence::Dependent);
+  }
+
+  TemplateArgumentDependence templateArgument() const {
+return translate(V, UnexpandedPack, 

[clang] 94938d7 - [Syntax] Prevent (accidentally) copying TokenBuffer

2020-03-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-28T00:09:09+01:00
New Revision: 94938d7d41cd11c4539ff93b801fe53cb4fddba2

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

LOG: [Syntax] Prevent (accidentally) copying TokenBuffer

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tokens.h

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tokens.h 
b/clang/include/clang/Tooling/Syntax/Tokens.h
index 2ee840074810..e9918eac7845 100644
--- a/clang/include/clang/Tooling/Syntax/Tokens.h
+++ b/clang/include/clang/Tooling/Syntax/Tokens.h
@@ -176,6 +176,12 @@ llvm::raw_ostream <<(llvm::raw_ostream , const 
Token );
 class TokenBuffer {
 public:
   TokenBuffer(const SourceManager ) : SourceMgr() {}
+
+  TokenBuffer(TokenBuffer &&) = default;
+  TokenBuffer(const TokenBuffer &) = delete;
+  TokenBuffer =(TokenBuffer &&) = default;
+  TokenBuffer =(const TokenBuffer &) = delete;
+
   /// All tokens produced by the preprocessor after all macro replacements,
   /// directives, etc. Source locations found in the clang AST will always
   /// point to one of these tokens.



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


Re: [PATCH] D75791: [clang-format] Added new option IndentExternBlock

2020-03-27 Thread Marcus Johnson via cfe-commits
I’m wondering if theres a way to tell if an option has been set in the 
clang-format config file.

If IndentExternBlock is not set, we should default to the old behavior.

As for your suggestion of setting IndentExternBlock to 
BraceWrapping.AfterExternBlock or negating it, neither way works with the tests.

> On Mar 26, 2020, at 10:33 AM, MyDeveloperDay via Phabricator 
>  wrote:
> 
> MyDeveloperDay added a comment.
> 
> Could the default be `Style.IndentExternBlock = 
> Style.BraceWrapping.AfterExternBlock`
> 
> Then it would match the prior behaviour off AddLevel being `true` when 
> AfterExternBlock is `true`
> 
>  extern "C" {
>  int a;
>  }
> 
>  extern "C" 
>  {
>int a;
>  }
> 
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D75791/new/
> 
> https://reviews.llvm.org/D75791
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

2020-03-27 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.

LG, thanks! Let me know if/when I should land this for you.




Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:105
+// argument.
+bool isInMacroNotArg(const SourceManager , const SourceLocation Loc) {
+  return Loc.isMacroID() && !SM.isMacroArgExpansion(Loc);

This is just SourceManager::isMacroBodyExpansion(), I think.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:163
+  if (isInMacroNotArg(SM, QualifierToRemove.getBeginLoc()) ||
+  isInMacroNotArg(SM, QualifierToRemove.getEndLoc())) {
+return false;

I think the endloc check should rather be SM.isWrittenInSameFile - it's no good 
if e.g. they're both macro arg expansions, but different ones.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:171
+// The insertion point might be a little awkward if the decl we're anchoring to
+// has a comment in an unfortunate place (e.g. directly above using, or
+// immediately following "namespace {". We should add some helpers for dealing

nit: you've mentioned the two cases I don't think we should bother fixing, but 
not the crucial one: we're anchoring to a regular decl, and we're going to 
insert in between the decl and its doc comment.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:245
+  auto  = Inputs.AST->getSourceManager();
+  auto TB = Inputs.AST->getTokens();
+  // Determine the length of the qualifier under the cursor, then remove it.

yikes, this copies the tokenbuffer, I didn't think that was even possible!
auto&



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:44
+  // SourceLocation if the "using" statement already exists.
+  llvm::Expected
+  findInsertionPoint(const Selection );

adamcz wrote:
> sammccall wrote:
> > this doesn't use any state - make it static or a free function?
> It uses Name and NNSL . Would you prefer this as free function, with both 
> passed as arguments. My initial thought was that, since prepare() and apply() 
> already share these via class members this was fine, but I'm certainly not 
> against making this a free function.
Oops, right. I think since this is the complicated part and it has a fairly 
simple interface, making its inputs/outputs explicit is nice hygiene.

(prepare and apply do communicate through class state, which feels a bit hacky 
to me. We didn't come up with anything nicer but still flexible+simple when 
designing this. It is conventional and documented at least)



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:71
+  return true;
+}
+if (D->getDeclContext()->Encloses(SelectionDeclContext)) {

adamcz wrote:
> sammccall wrote:
> > nit: we conventionally leave out the {} on one-line if bodies etc.
> Uhh...is that a hard rule? I personally hate that, it's just asking for Apple 
> SSL-style bugs
> https://www.imperialviolet.org/2014/02/22/applebug.html
There's no hard rule, but we do use that style consistently and consistency has 
value too.

The clang-tidy check `readability-misleading-indentation` catches that bug. Can 
I suggest:
 - (for us) adding it to `.clang-tidy` in `llvm-project`? This will affect 
clangd and the phabricator linter
 - (for the world) we could start a list of on-by-default clang-tidy checks for 
clangd users with no `.clang-tidy` config, and include this check



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:89
+
+  // If we're looking at a type or NestedNameSpecifier, walk up the tree until
+  // we find the "main" node we care about, which would be ElaboratedTypeLoc or

adamcz wrote:
> sammccall wrote:
> > I like the idea here, but I'm not sure it quite works. e.g. any typeloc has 
> > a directly enclosing typeloc, the inner one can't be targeted. So what 
> > about `x::S*`? (pointertypeloc > elaboratedtypeloc > recordtypeloc)?
> > 
> > - looping up from NNS until you get to something else makes sense
> > - unwrapping typeloc -> elaboratedtypeloc makes sense, but I don't think 
> > you ever want to unwrap multiple levels?
> > - i don't think these cases overlap at all, you want one or the other
> > 
> > Am I missing something?
> If you have a class foo::bar::cc and a struct st inside it, and then do:
> foo::bar::c^c::st *p;
> you end up with:
> PointerTypeLoc -> ElaboratedTypeLoc ->NestedNameSpecifierLoc -> RecordTypeLoc
> in which case you need to go up from type to NNSL and then up again, from 
> NNSL to something that's not NNSL.
> 
> You have a good point with the PointerTypeLoc, that's a bug. We should stop 
> going up the tree as soon as we find ElaboratedTypeLoc. I added a test for 
> that.
> foo::bar::c^c::st *p;

But this isn't a case we 

[PATCH] D76496: [clang-tidy] StringFindStartswith should ignore 3-arg find()

2020-03-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D76496#1947059 , @niko wrote:

> In D76496#1935127 , @njames93 wrote:
>
> > I'm not hugely familiar with the abseil library, but from what I can see 
> > `absl::StartsWith` takes `absl::string_view` as args. Therefore surely it 
> > makes sense to handle the 3rd arg for `str::find` by explicitly 
> > constructing the `absl::string_view` from the pointer and size.
>
>
> I am mainly worried that the 3-arg find is rarely used, and using 
> absl::string_view requires another option to be specified for the header 
> file. If you think that's still a good tradeoff i'll change it to construct a 
> string_view.


The `absl/strings/match` header includes the `absl/strings/string_view` header 
so you wouldn't need to include another header file. Well that's as long as the 
user hasn't done something funky with header files, but arguably the shouldn't 
be using Fix-Its if they have done something like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76496



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


[PATCH] D76957: HIP: Merge builtin library handling

2020-03-27 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: yaxunl, gregrodgers.
Herald added subscribers: kerbowa, Anastasia, nhaehnle, wdng, jvesely.
arsenm added parent revisions: D76862: HIP: Ensure new denormal mode attributes 
are set, D76950: HIP: Link correct denormal mode library, D59321: AMDGPU: Teach 
toolchain to link rocm device libs.

Merge with the new --rocm-path handling used for OpenCL. This looks
for a usable set of device libraries upfront, rather than giving a
generic "no such file or directory error". If any of the required
bitcode libraries are missing, this will now produce a "cannot find
ROCm installation." error. This differs from the existing hip specific
flags by pointing to a rocm root install instead of a single directory
with bitcode files.

  

This tries to maintain compatibility with the existing the
--hip-device-lib and --hip-device-lib-path flags, as well as the
HIP_DEVICE_LIB_PATH environment variable, or at least the range of
uses with testcases. The existing range of uses and behavior doesn't
entirely make sense to me, so some of the untested edge cases change
 behavior. Currently the two path forms seem to have the double purpose
of a search path for an arbitrary --hip-device-lib, and for finding
he stock set of libraries. Since the stock set of libraries This also
changes the behavior when multiple paths are specified, and only takes
the last one (and the environment variable only handles a single
path).

  

If --hip-device-lib is used, it now only treats --hip-device-lib-path
as the search path for it, and does not attempt to find the rocm
installation. If not, --hip-device-lib-path and the environment
variable are used as the directory to search instead of the rocm root
based path.

  

This should also automatically fix handling of the options to use
wave64.


https://reviews.llvm.org/D76957

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-device-libs.hip
  clang/test/Driver/rocm-device-libs.cl

Index: clang/test/Driver/rocm-device-libs.cl
===
--- clang/test/Driver/rocm-device-libs.cl
+++ clang/test/Driver/rocm-device-libs.cl
@@ -120,6 +120,21 @@
 
 
 
+// Test --hip-device-lib-path format
+// RUN: %clang -### -target amdgcn-amd-amdhsa \
+// RUN:   -x cl -mcpu=gfx900 \
+// RUN:   --hip-device-lib-path=%S/Inputs/rocm-device-libs/lib \
+// RUN:   %S/opencl.cl \
+// RUN: 2>&1 | FileCheck -dump-input-on-failure --check-prefixes=COMMON,COMMON-DEFAULT,GFX900-DEFAULT,GFX900,WAVE64 %s
+
+// Test environment variable HIP_DEVICE_LIB_PATH
+// RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/rocm-device-libs/lib %clang -### -target amdgcn-amd-amdhsa \
+// RUN:   -x cl -mcpu=gfx900 \
+// RUN:   %S/opencl.cl \
+// RUN: 2>&1 | FileCheck -dump-input-on-failure --check-prefixes=COMMON,COMMON-DEFAULT,GFX900-DEFAULT,GFX900,WAVE64 %s
+
+
+
 // COMMON: "-triple" "amdgcn-amd-amdhsa"
 // COMMON-SAME: "-mlink-builtin-bitcode" "{{.*}}/lib/opencl.amdgcn.bc"
 // COMMON-SAME: "-mlink-builtin-bitcode" "{{.*}}/lib/ocml.amdgcn.bc"
Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -7,16 +7,16 @@
 
 // Test subtarget with flushing on by default.
 // RUN: %clang -### -target x86_64-linux-gnu \
-// RUN:   --cuda-gpu-arch=gfx803 \
-// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib   \
+// RUN:  --cuda-gpu-arch=gfx803 \
+// RUN:  --rocm-path=%S/Inputs/rocm-device-libs   \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
 
 
 // Test subtarget with flushing off by ddefault.
 // RUN: %clang -### -target x86_64-linux-gnu \
-// RUN:   --cuda-gpu-arch=gfx900 \
-// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:  --cuda-gpu-arch=gfx900 \
+// RUN:  --rocm-path=%S/Inputs/rocm-device-libs \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
 
@@ -25,7 +25,7 @@
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -fcuda-flush-denormals-to-zero \
-// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   --rocm-path=%S/Inputs/rocm-device-libs \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
 
@@ -34,7 +34,7 @@
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx803 \
 // RUN:   -fno-cuda-flush-denormals-to-zero \
-// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   --rocm-path=%S/Inputs/rocm-device-libs \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
 
@@ -43,7 +43,7 @@
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D76365#1946938 , @hliao wrote:

> The new revision is accepted, right? Just want to confirm as it seems you 
> accept it before I posted the new change.


The approval was for the old version. I didn't undo it when I reopened the 
review. The diff looks OK, though the last variant still leaves open the 
question of what's the meaning of these attributes and what are the 
restrictions on their use.

So what's the reasonable thing to do if I write something like this:

  __attribute__((device_builtin_surface_type)) int foo; // Ignore? Warn? Error? 
Do something sensible?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[PATCH] D76939: [AST] Add a Dependence bitmask to use for calculations with multiple node types.

2020-03-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

nice, thanks!




Comment at: clang/include/clang/AST/DependenceFlags.h:120
+
+  Dependence(Bits V) : V(V) {}
+

nit: this seems to be unused?



Comment at: clang/include/clang/AST/DependenceFlags.h:152
+  TypeDependence type() const {
+return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
+   translate(V, Instantiation, TypeDependence::Instantiation) |

maybe make `Bits` as scoped enum? I find `translate(V, Bits::UnexpandedPack, 
TypeDependence::UnexpandedPack)` is clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76939



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


[PATCH] D76916: [Darwin] Respect -fno-unroll-loops during LTO.

2020-03-27 Thread Florian Hahn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ce198d6ed37: [Darwin] Respect -fno-unroll-loops during LTO. 
(authored by fhahn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76916

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll

Index: llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
===
--- /dev/null
+++ llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
@@ -0,0 +1,34 @@
+; REQUIRES: asserts
+
+; RUN: llvm-as < %s > %t1.bc
+
+; Build with unrolling disabled (-lto-no-unroll-loops).
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o -lto-no-unroll-loops --exported-symbol=foo -save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck --check-prefix=NOUNROLL %s
+
+; NOUNROLL: br label %loop
+; NOUNROLL: br i1 %ec, label %exit, label %loop
+
+; Build with unrolling enabled (by not passing -lto-no-unroll-loops). All
+; branches should be gone.
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o --exported-symbol=foo -save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck --check-prefix=UNROLL %s
+
+; UNROLL-NOT: br
+
+define void @foo(i32* %ptr) {
+
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+  %iv.ptr = getelementptr i32, i32* %ptr, i32 %iv
+  store i32 %iv, i32* %iv.ptr
+  %iv.next = add i32 %iv, 1
+  %ec = icmp eq i32 %iv.next, 10
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  ret void
+}
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -109,6 +109,10 @@
 cl::Hidden);
 }
 
+cl::opt LTONoUnrollLoops("lto-no-unroll-loops",
+   cl::desc("Disable unrolling during LTO."),
+   cl::Hidden, cl::init(false));
+
 LTOCodeGenerator::LTOCodeGenerator(LLVMContext )
 : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
   TheLinker(new Linker(*MergedModule)) {
@@ -570,6 +574,7 @@
 
   Triple TargetTriple(TargetMach->getTargetTriple());
   PassManagerBuilder PMB;
+  PMB.DisableUnrollLoops = LTONoUnrollLoops;
   PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
   PMB.LoopVectorize = !DisableVectorization;
   PMB.SLPVectorize = !DisableVectorization;
Index: clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
===
--- /dev/null
+++ clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
@@ -0,0 +1,17 @@
+// REQUIRES: system-darwin
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/lib
+// RUN: touch %t/lib/libLTO.dylib
+
+// Check that ld gets "-lto-no-unroll-loops" when -fno-unroll-loops is passed.
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -fno-unroll-loops -flto=full -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=NOUNROLL %s
+
+// NOUNROLL:  "-mllvm" "-lto-no-unroll-loops"
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=UNROLL %s
+
+// UNROLL-NOT:  -lto-no-unroll-loops
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -543,6 +543,12 @@
 CmdArgs.push_back(Args.MakeArgString("-lto-stats-file=" + StatsFile.str()));
   }
 
+  // Forward -fno-unroll-loops to the linker in LTO.
+  if (Args.hasArg(options::OPT_fno_unroll_loops)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-lto-no-unroll-loops"));
+  }
+
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as expected.
   Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76496: [clang-tidy] StringFindStartswith should ignore 3-arg find()

2020-03-27 Thread Niko Weh via Phabricator via cfe-commits
niko added a comment.

In D76496#1935127 , @njames93 wrote:

> I'm not hugely familiar with the abseil library, but from what I can see 
> `absl::StartsWith` takes `absl::string_view` as args. Therefore surely it 
> makes sense to handle the 3rd arg for `str::find` by explicitly constructing 
> the `absl::string_view` from the pointer and size.


I am mainly worried that the 3-arg find is rarely used, and using 
absl::string_view requires another option to be specified for the header file. 
If you think that's still a good tradeoff i'll change it to construct a 
string_view.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76496



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


[clang] 9ce198d - [Darwin] Respect -fno-unroll-loops during LTO.

2020-03-27 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2020-03-27T22:19:03Z
New Revision: 9ce198d6ed371399e9bd9ba8b48fbab0f4e60240

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

LOG: [Darwin] Respect -fno-unroll-loops during LTO.

Currently -fno-unroll-loops is ignored when doing LTO on Darwin. This
patch adds a new -lto-no-unroll-loops option to the LTO code generator
and forwards it to the linker if -fno-unroll-loops is passed.

Reviewers: thegameg, steven_wu

Reviewed By: thegameg

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

Added: 
clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll

Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 451d0d206d07..951c71bff00e 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -543,6 +543,12 @@ void darwin::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Args.MakeArgString("-lto-stats-file=" + 
StatsFile.str()));
   }
 
+  // Forward -fno-unroll-loops to the linker in LTO.
+  if (Args.hasArg(options::OPT_fno_unroll_loops)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-lto-no-unroll-loops"));
+  }
+
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as 
expected.
   Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, 
options::OPT_t,

diff  --git a/clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c 
b/clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
new file mode 100644
index ..b248898a89f5
--- /dev/null
+++ b/clang/test/Driver/darwin-ld-lto-fno-unroll-loops.c
@@ -0,0 +1,17 @@
+// REQUIRES: system-darwin
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/lib
+// RUN: touch %t/lib/libLTO.dylib
+
+// Check that ld gets "-lto-no-unroll-loops" when -fno-unroll-loops is passed.
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -fno-unroll-loops -flto=full 
-### 2>&1 | \
+// RUN:   FileCheck --check-prefix=NOUNROLL %s
+
+// NOUNROLL:  "-mllvm" "-lto-no-unroll-loops"
+//
+// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=UNROLL %s
+
+// UNROLL-NOT:  -lto-no-unroll-loops

diff  --git a/llvm/lib/LTO/LTOCodeGenerator.cpp 
b/llvm/lib/LTO/LTOCodeGenerator.cpp
index a8a7877f66da..d2ae956b7823 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -109,6 +109,10 @@ cl::opt LTOStatsFile(
 cl::Hidden);
 }
 
+cl::opt LTONoUnrollLoops("lto-no-unroll-loops",
+   cl::desc("Disable unrolling during LTO."),
+   cl::Hidden, cl::init(false));
+
 LTOCodeGenerator::LTOCodeGenerator(LLVMContext )
 : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
   TheLinker(new Linker(*MergedModule)) {
@@ -570,6 +574,7 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool 
DisableInline,
 
   Triple TargetTriple(TargetMach->getTargetTriple());
   PassManagerBuilder PMB;
+  PMB.DisableUnrollLoops = LTONoUnrollLoops;
   PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
   PMB.LoopVectorize = !DisableVectorization;
   PMB.SLPVectorize = !DisableVectorization;

diff  --git a/llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll 
b/llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
new file mode 100644
index ..3ac4c285ffe7
--- /dev/null
+++ b/llvm/test/tools/llvm-lto/fno-unroll-loops-option.ll
@@ -0,0 +1,34 @@
+; REQUIRES: asserts
+
+; RUN: llvm-as < %s > %t1.bc
+
+; Build with unrolling disabled (-lto-no-unroll-loops).
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o -lto-no-unroll-loops 
--exported-symbol=foo -save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck 
--check-prefix=NOUNROLL %s
+
+; NOUNROLL: br label %loop
+; NOUNROLL: br i1 %ec, label %exit, label %loop
+
+; Build with unrolling enabled (by not passing -lto-no-unroll-loops). All
+; branches should be gone.
+; RUN: llvm-lto %t1.bc -o %t.nounroll.o --exported-symbol=foo 
-save-merged-module
+; RUN: llvm-dis  -o - %t.nounroll.o.merged.bc | FileCheck 
--check-prefix=UNROLL %s
+
+; UNROLL-NOT: br
+
+define void @foo(i32* %ptr) {
+
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+  %iv.ptr = getelementptr i32, i32* %ptr, i32 %iv
+  store i32 %iv, i32* %iv.ptr
+  %iv.next = add i32 %iv, 1
+  %ec = icmp eq i32 %iv.next, 10
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  ret void
+}



___
cfe-commits mailing 

[clang] 0fca766 - [OPENMP50]Fix PR45117: Orphaned task reduction should be allowed.

2020-03-27 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-27T17:47:30-04:00
New Revision: 0fca766458da04bbc6d33b3f9ecd57e615c556c1

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

LOG: [OPENMP50]Fix PR45117: Orphaned task reduction should be allowed.

Add support for orpahned task reductions.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/master_taskloop_in_reduction_messages.cpp
clang/test/OpenMP/master_taskloop_simd_in_reduction_messages.cpp
clang/test/OpenMP/task_ast_print.cpp
clang/test/OpenMP/task_in_reduction_codegen.cpp
clang/test/OpenMP/task_in_reduction_message.cpp
clang/test/OpenMP/taskloop_in_reduction_messages.cpp
clang/test/OpenMP/taskloop_simd_in_reduction_messages.cpp
openmp/runtime/test/tasking/omp_task_red_taskloop.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c642c2ba36c8..d2aa2902bb2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9844,8 +9844,6 @@ def err_omp_reduction_in_task : Error<
   "reduction variables may not be accessed in an explicit task">;
 def err_omp_reduction_id_not_compatible : Error<
   "list item of type %0 is not valid for specified reduction operation: unable 
to provide default initialization value">;
-def err_omp_in_reduction_not_task_reduction : Error<
-  "in_reduction variable must appear in a task_reduction clause">;
 def err_omp_reduction_identifier_mismatch : Error<
   "in_reduction variable must have the same reduction operation as in a 
task_reduction clause">;
 def note_omp_previous_reduction_identifier : Note<

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index bef36bf4693b..af7056a10f00 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/PrettyStackTrace.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/Support/AtomicOrdering.h"
 using namespace clang;
@@ -3535,9 +3536,13 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
 // initializer/combiner/finalizer.
 CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, 
S.getBeginLoc(),
RedCG, Cnt);
-llvm::Value *ReductionsPtr =
-CGF.EmitLoadOfScalar(CGF.EmitLValue(TaskgroupDescriptors[Cnt]),
- TaskgroupDescriptors[Cnt]->getExprLoc());
+llvm::Value *ReductionsPtr;
+if (const Expr *TRExpr = TaskgroupDescriptors[Cnt]) {
+  ReductionsPtr = CGF.EmitLoadOfScalar(CGF.EmitLValue(TRExpr),
+   TRExpr->getExprLoc());
+} else {
+  ReductionsPtr = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
+}
 Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem(
 CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
 Replacement = Address(

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 97cfb1cc8f1d..14aa446cc6ef 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14837,8 +14837,8 @@ static bool actOnOMPReductionKindClause(
 if (ClauseKind == OMPC_in_reduction) {
   SourceRange ParentSR;
   BinaryOperatorKind ParentBOK;
-  const Expr *ParentReductionOp;
-  Expr *ParentBOKTD, *ParentReductionOpTD;
+  const Expr *ParentReductionOp = nullptr;
+  Expr *ParentBOKTD = nullptr, *ParentReductionOpTD = nullptr;
   DSAStackTy::DSAVarData ParentBOKDSA =
   Stack->getTopMostTaskgroupReductionData(D, ParentSR, ParentBOK,
   ParentBOKTD);
@@ -14847,13 +14847,9 @@ static bool actOnOMPReductionKindClause(
   D, ParentSR, ParentReductionOp, ParentReductionOpTD);
   bool IsParentBOK = ParentBOKDSA.DKind != OMPD_unknown;
   bool IsParentReductionOp = ParentReductionOpDSA.DKind != OMPD_unknown;
-  if (!IsParentBOK && !IsParentReductionOp) {
-S.Diag(ELoc, diag::err_omp_in_reduction_not_task_reduction);
-continue;
-  }
   if ((DeclareReductionRef.isUnset() && IsParentReductionOp) ||
-  (DeclareReductionRef.isUsable() && IsParentBOK) || BOK != ParentBOK 
||
-  IsParentReductionOp) {
+  (DeclareReductionRef.isUsable() && IsParentBOK) ||
+  (IsParentBOK && BOK != ParentBOK) || IsParentReductionOp) {
 

[PATCH] D76942: Add BitWidth trait to BitmaskEnum, and use for clang DependenceFlags. NFC

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b3bedec999a: Add BitWidth trait to BitmaskEnum, and use for 
clang DependenceFlags. NFC (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76942

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/Type.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  llvm/include/llvm/ADT/BitmaskEnum.h

Index: llvm/include/llvm/ADT/BitmaskEnum.h
===
--- llvm/include/llvm/ADT/BitmaskEnum.h
+++ llvm/include/llvm/ADT/BitmaskEnum.h
@@ -94,6 +94,10 @@
   return U;
 }
 
+constexpr unsigned bitWidth(uint64_t Value) {
+  return Value ? 1 + bitWidth(Value >> 1) : 0;
+}
+
 template ::value>>
 E operator~(E Val) {
   return static_cast(~Underlying(Val) & Mask());
@@ -139,6 +143,10 @@
 
 // Enable bitmask enums in namespace ::llvm and all nested namespaces.
 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+template ::value>>
+constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(uint64_t{
+static_cast>(
+E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
 
 } // namespace llvm
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -50,6 +50,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTRecordReader.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -107,7 +108,7 @@
 /// The number of record fields required for the Expr class
 /// itself.
 static const unsigned NumExprFields =
-NumStmtFields + ExprDependenceBits + 3;
+NumStmtFields + llvm::BitWidth + 3;
 
 /// Read and initialize a ExplicitTemplateArgumentList structure.
 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo ,
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1467,7 +1467,7 @@
 unsigned TC : 8;
 
 /// Store information on the type dependency.
-/*TypeDependence*/ unsigned Dependence : TypeDependenceBits;
+unsigned Dependence : llvm::BitWidth;
 
 /// True if the cache (i.e. the bitfields here starting with
 /// 'Cache') is valid.
@@ -1496,7 +1496,7 @@
   return CachedLocalOrUnnamed;
 }
   };
-  enum { NumTypeBits = 8 + TypeDependenceBits + 6 };
+  enum { NumTypeBits = 8 + llvm::BitWidth + 6 };
 
 protected:
   // These classes allow subclasses to somewhat cleanly pack bitfields
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
@@ -310,9 +311,9 @@
 
 unsigned ValueKind : 2;
 unsigned ObjectKind : 3;
-unsigned /*ExprDependence*/ Dependent : ExprDependenceBits;
+unsigned /*ExprDependence*/ Dependent : llvm::BitWidth;
   };
-  enum { NumExprBits = NumStmtBits + 5 + ExprDependenceBits };
+  enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth };
 
   class ConstantExprBitfields {
 friend class ASTStmtReader;
Index: clang/include/clang/AST/DependenceFlags.h
===
--- clang/include/clang/AST/DependenceFlags.h
+++ clang/include/clang/AST/DependenceFlags.h
@@ -36,7 +36,6 @@
   };
 };
 using ExprDependence = ExprDependenceScope::ExprDependence;
-static constexpr unsigned ExprDependenceBits = 5;
 
 struct TypeDependenceScope {
   enum TypeDependence : uint8_t {
@@ -62,7 +61,6 @@
   };
 };
 using TypeDependence = TypeDependenceScope::TypeDependence;
-static constexpr unsigned TypeDependenceBits = 4;
 
 #define LLVM_COMMON_DEPENDENCE(NAME)   \
   struct NAME##Scope { \
@@ -78,8 +76,7 @@
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Dependent)\
 }; \
   };   \
-  using NAME = NAME##Scope::NAME;  \
-  static constexpr unsigned NAME##Bits = 3;
+  using NAME = NAME##Scope::NAME;
 
 LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
 LLVM_COMMON_DEPENDENCE(TemplateNameDependence)

[PATCH] D76385: Allow remapping Clang module include paths

2020-03-27 Thread Adrian Prantl via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22d5bd0e3b32: Allow remapping Clang module include paths 
(authored by aprantl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76385

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/Modules/debug-info-moduleimport.m


Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2483,6 +2483,17 @@
 assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
"clang module without ASTFile must be specified by -fmodule-name");
 
+  // Return a StringRef to the remapped Path.
+  auto RemapPath = [this](StringRef Path) -> std::string {
+std::string Remapped = remapDIPath(Path);
+StringRef Relative(Remapped);
+StringRef CompDir = TheCU->getDirectory();
+if (Relative.consume_front(CompDir))
+  Relative.consume_front(llvm::sys::path::get_separator());
+
+return Relative.str();
+  };
+
   if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
 // PCH files don't have a signature field in the control block,
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
@@ -2496,16 +2507,12 @@
 if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
   PCM = Mod.getPath();
 llvm::sys::path::append(PCM, Mod.getASTFile());
-std::string RemappedPCM = remapDIPath(PCM);
-StringRef RelativePCM(RemappedPCM);
-StringRef CompDir = TheCU->getDirectory();
-if (RelativePCM.consume_front(CompDir))
-  RelativePCM.consume_front(llvm::sys::path::get_separator());
-DIB.createCompileUnit(TheCU->getSourceLanguage(),
-  // TODO: Support "Source" from external AST 
providers?
-  DIB.createFile(Mod.getModuleName(), CompDir),
-  TheCU->getProducer(), false, StringRef(), 0, 
RelativePCM,
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(
+TheCU->getSourceLanguage(),
+// TODO: Support "Source" from external AST providers?
+DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
+TheCU->getProducer(), false, StringRef(), 0, RemapPath(PCM),
+llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }
 
@@ -2513,9 +2520,10 @@
   IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
   CreateSkeletonCU);
+  std::string IncludePath = Mod.getPath().str();
   llvm::DIModule *DIMod =
   DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
-Mod.getPath());
+RemapPath(IncludePath));
   ModuleCache[M].reset(DIMod);
   return DIMod;
 }


Index: clang/test/Modules/debug-info-moduleimport.m
===
--- clang/test/Modules/debug-info-moduleimport.m
+++ clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ 

[PATCH] D76385: Allow remapping Clang module include paths

2020-03-27 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

LLDB didn't apply DW_AT_comp_dir to DW_AT_LLVM_include_path. I fixed that now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76385



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


[PATCH] D68115: Zero initialize padding in unions

2020-03-27 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In D68115#1946757 , @rsmith wrote:

> In D68115#1946668 , 
> @hubert.reinterpretcast wrote:
>
> > It sounds like we are looking for `-fzero-union-padding`. That's been where 
> > the discussion has left off twice for months.
>
>
> I believe the state of Clang prior to this patch is actually wrong.


That's my understanding as well. I'd like it if this patch (or a follow-up) got 
us back to standard behavior. In either case, I'd like the proposed behavior to 
bee on-by-default when doing initialization of stack variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


[PATCH] D75561: Remove const qualifier from Modules returned by ExternalASTSource. (NFC)

2020-03-27 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Pinging @teemperor


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

https://reviews.llvm.org/D75561



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


[PATCH] D76953: [AST] Fix a crash on invalid bitwidth exprs when preserving the recoveryexprs.

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/ASTContext.cpp:2165
+if (ObjCI->getDecl()->isInvalidDecl()) {
+  // FIXME: are the numbers correct?
+  Width = 8;

these numbers are arbitrary AFAICT, this seems fine.



Comment at: clang/test/Sema/invalid-bitwidth-expr.mm:1
+// RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
+// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s

you might consider merging both tests into this file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76953



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


[clang] 6b3bede - Add BitWidth trait to BitmaskEnum, and use for clang DependenceFlags. NFC

2020-03-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-27T22:40:21+01:00
New Revision: 6b3bedec999a57015339fa5eed276710e87cbb0f

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

LOG: Add BitWidth trait to BitmaskEnum, and use for clang DependenceFlags. NFC

Reviewers: hokein

Subscribers: dexonsmith, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/DependenceFlags.h
clang/include/clang/AST/Stmt.h
clang/include/clang/AST/Type.h
clang/lib/Serialization/ASTReaderStmt.cpp
llvm/include/llvm/ADT/BitmaskEnum.h

Removed: 




diff  --git a/clang/include/clang/AST/DependenceFlags.h 
b/clang/include/clang/AST/DependenceFlags.h
index 788227156c4d..c92b0c65 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -36,7 +36,6 @@ struct ExprDependenceScope {
   };
 };
 using ExprDependence = ExprDependenceScope::ExprDependence;
-static constexpr unsigned ExprDependenceBits = 5;
 
 struct TypeDependenceScope {
   enum TypeDependence : uint8_t {
@@ -62,7 +61,6 @@ struct TypeDependenceScope {
   };
 };
 using TypeDependence = TypeDependenceScope::TypeDependence;
-static constexpr unsigned TypeDependenceBits = 4;
 
 #define LLVM_COMMON_DEPENDENCE(NAME)   
\
   struct NAME##Scope { 
\
@@ -78,8 +76,7 @@ static constexpr unsigned TypeDependenceBits = 4;
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Dependent)
\
 }; 
\
   };   
\
-  using NAME = NAME##Scope::NAME;  
\
-  static constexpr unsigned NAME##Bits = 3;
+  using NAME = NAME##Scope::NAME;
 
 LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
 LLVM_COMMON_DEPENDENCE(TemplateNameDependence)

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 87e1d7f26a16..8c7f0ecad3ef 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
@@ -310,9 +311,9 @@ class alignas(void *) Stmt {
 
 unsigned ValueKind : 2;
 unsigned ObjectKind : 3;
-unsigned /*ExprDependence*/ Dependent : ExprDependenceBits;
+unsigned /*ExprDependence*/ Dependent : llvm::BitWidth;
   };
-  enum { NumExprBits = NumStmtBits + 5 + ExprDependenceBits };
+  enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth };
 
   class ConstantExprBitfields {
 friend class ASTStmtReader;

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 6b46fc5ad312..248fbcfba98e 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1467,7 +1467,7 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 unsigned TC : 8;
 
 /// Store information on the type dependency.
-/*TypeDependence*/ unsigned Dependence : TypeDependenceBits;
+unsigned Dependence : llvm::BitWidth;
 
 /// True if the cache (i.e. the bitfields here starting with
 /// 'Cache') is valid.
@@ -1496,7 +1496,7 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   return CachedLocalOrUnnamed;
 }
   };
-  enum { NumTypeBits = 8 + TypeDependenceBits + 6 };
+  enum { NumTypeBits = 8 + llvm::BitWidth + 6 };
 
 protected:
   // These classes allow subclasses to somewhat cleanly pack bitfields

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 5d9033e37977..3f56968a51dc 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -50,6 +50,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTRecordReader.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -107,7 +108,7 @@ namespace clang {
 /// The number of record fields required for the Expr class
 /// itself.
 static const unsigned NumExprFields =
-NumStmtFields + ExprDependenceBits + 3;
+NumStmtFields + llvm::BitWidth + 3;
 
 /// Read and initialize a ExplicitTemplateArgumentList structure.
 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo ,

diff  --git a/llvm/include/llvm/ADT/BitmaskEnum.h 
b/llvm/include/llvm/ADT/BitmaskEnum.h
index 

[clang] 22d5bd0 - Allow remapping Clang module include paths

2020-03-27 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2020-03-27T14:23:30-07:00
New Revision: 22d5bd0e3b32530785bc7b5c0f32b32a1f907342

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

LOG: Allow remapping Clang module include paths

in the debug info with -fdebug-prefix-map.

rdar://problem/55685132

This reapplies an earlier attempt to commit this without
modifications.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/Modules/debug-info-moduleimport.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index da6cb458982b..49c57e9860a6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2483,6 +2483,17 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
 assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
"clang module without ASTFile must be specified by -fmodule-name");
 
+  // Return a StringRef to the remapped Path.
+  auto RemapPath = [this](StringRef Path) -> std::string {
+std::string Remapped = remapDIPath(Path);
+StringRef Relative(Remapped);
+StringRef CompDir = TheCU->getDirectory();
+if (Relative.consume_front(CompDir))
+  Relative.consume_front(llvm::sys::path::get_separator());
+
+return Relative.str();
+  };
+
   if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
 // PCH files don't have a signature field in the control block,
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
@@ -2496,16 +2507,12 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
 if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
   PCM = Mod.getPath();
 llvm::sys::path::append(PCM, Mod.getASTFile());
-std::string RemappedPCM = remapDIPath(PCM);
-StringRef RelativePCM(RemappedPCM);
-StringRef CompDir = TheCU->getDirectory();
-if (RelativePCM.consume_front(CompDir))
-  RelativePCM.consume_front(llvm::sys::path::get_separator());
-DIB.createCompileUnit(TheCU->getSourceLanguage(),
-  // TODO: Support "Source" from external AST 
providers?
-  DIB.createFile(Mod.getModuleName(), CompDir),
-  TheCU->getProducer(), false, StringRef(), 0, 
RelativePCM,
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(
+TheCU->getSourceLanguage(),
+// TODO: Support "Source" from external AST providers?
+DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
+TheCU->getProducer(), false, StringRef(), 0, RemapPath(PCM),
+llvm::DICompileUnit::FullDebug, Signature);
 DIB.finalize();
   }
 
@@ -2513,9 +2520,10 @@ llvm::DIModule 
*CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
   IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
   CreateSkeletonCU);
+  std::string IncludePath = Mod.getPath().str();
   llvm::DIModule *DIMod =
   DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
-Mod.getPath());
+RemapPath(IncludePath));
   ModuleCache[M].reset(DIMod);
   return DIMod;
 }

diff  --git a/clang/test/Modules/debug-info-moduleimport.m 
b/clang/test/Modules/debug-info-moduleimport.m
index 9dee9964b538..5787ffe22751 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -34,9 +34,11 @@
 
 // RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
 // RUN:   -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
+// RUN:   -fdebug-prefix-map=%S=/SRCDIR \
 // RUN:   -fmodule-format=obj -dwarf-ext-refs \
 // RUN:   %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
 // RUN: | FileCheck %s --check-prefix=SKEL-CHECK
+// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
 // SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
 // SKEL-CHECK: distinct !DICompileUnit({{.*}}file: 
![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5be9b8cbe2b2: [cuda][hip] Add CUDA builtin surface/texture 
reference support. (authored by hliao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/attr-declspec.cu
  clang/test/SemaCUDA/attributes-on-non-cuda.cu
  clang/test/SemaCUDA/bad-attributes.cu
  llvm/include/llvm/IR/Operator.h

Index: llvm/include/llvm/IR/Operator.h
===
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -599,6 +599,25 @@
   }
 };
 
+class AddrSpaceCastOperator
+: public ConcreteOperator {
+  friend class AddrSpaceCastInst;
+  friend class ConstantExpr;
+
+public:
+  Value *getPointerOperand() { return getOperand(0); }
+
+  const Value *getPointerOperand() const { return getOperand(0); }
+
+  unsigned getSrcAddressSpace() const {
+return getPointerOperand()->getType()->getPointerAddressSpace();
+  }
+
+  unsigned getDestAddressSpace() const {
+return getType()->getPointerAddressSpace();
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_OPERATOR_H
Index: clang/test/SemaCUDA/bad-attributes.cu
===
--- clang/test/SemaCUDA/bad-attributes.cu
+++ clang/test/SemaCUDA/bad-attributes.cu
@@ -70,3 +70,27 @@
 __device__ void device_fn() {
   __constant__ int c; // expected-error {{__constant__ variables must be global}}
 }
+
+typedef __attribute__((device_builtin_surface_type)) unsigned long long s0_ty; // expected-warning {{'device_builtin_surface_type' attribute only applies to classes}}
+typedef __attribute__((device_builtin_texture_type)) unsigned long long t0_ty; // expected-warning {{'device_builtin_texture_type' attribute only applies to classes}}
+
+struct __attribute__((device_builtin_surface_type)) s1_ref {}; // expected-error {{illegal device builtin surface reference type 's1_ref' declared here}}
+// expected-note@-1 {{'s1_ref' needs to be instantiated from a class template with proper template arguments}}
+struct __attribute__((device_builtin_texture_type)) t1_ref {}; // expected-error {{illegal device builtin texture reference type 't1_ref' declared here}}
+// expected-note@-1 {{'t1_ref' needs to be instantiated from a class template with proper template arguments}}
+
+template 
+struct __attribute__((device_builtin_surface_type)) s2_cls_template {}; // expected-error {{illegal device builtin surface reference class template 's2_cls_template' declared here}}
+// expected-note@-1 {{'s2_cls_template' needs to have exactly 2 template parameters}}
+template 
+struct __attribute__((device_builtin_texture_type)) t2_cls_template {}; // expected-error {{illegal device builtin texture reference class template 't2_cls_template' declared here}}
+// expected-note@-1 {{'t2_cls_template' needs to have exactly 3 template parameters}}
+
+template 
+struct __attribute__((device_builtin_surface_type)) s3_cls_template {}; // expected-error {{illegal device builtin surface reference class template 's3_cls_template' declared here}}
+// expected-note@-1 {{the 1st template parameter of 's3_cls_template' needs to be a type}}
+// expected-note@-2 {{the 2nd template parameter of 's3_cls_template' needs to be an integer or enum value}}
+template 
+struct __attribute__((device_builtin_texture_type)) t3_cls_template {}; // expected-error {{illegal device builtin texture reference class template 't3_cls_template' declared here}}
+// expected-note@-1 {{the 1st template parameter of 't3_cls_template' needs to be a type}}
+// expected-note@-2 {{the 3rd template parameter of 't3_cls_template' needs to be an integer or enum value}}
Index: clang/test/SemaCUDA/attributes-on-non-cuda.cu
===
--- clang/test/SemaCUDA/attributes-on-non-cuda.cu
+++ clang/test/SemaCUDA/attributes-on-non-cuda.cu
@@ -7,16 +7,19 @@
 // RUN: %clang_cc1 -DEXPECT_WARNINGS -fsyntax-only -verify -x c %s
 
 #if defined(EXPECT_WARNINGS)
-// expected-warning@+12 {{'device' attribute ignored}}
-// expected-warning@+12 {{'global' attribute ignored}}
-// expected-warning@+12 {{'constant' 

[clang] 5be9b8c - [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via cfe-commits

Author: Michael Liao
Date: 2020-03-27T17:18:49-04:00
New Revision: 5be9b8cbe2b2253f78a09a863bef18e574737465

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

LOG: [cuda][hip] Add CUDA builtin surface/texture reference support.

Summary: - Re-commit after fix Sema checks on partial template specialization.

Reviewers: tra, rjmccall, yaxunl, a.sidorin

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGenCUDA/surface.cu
clang/test/CodeGenCUDA/texture.cu

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCUDARuntime.h
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Headers/__clang_cuda_runtime_wrapper.h
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaCUDA/attr-declspec.cu
clang/test/SemaCUDA/attributes-on-non-cuda.cu
clang/test/SemaCUDA/bad-attributes.cu
llvm/include/llvm/IR/Operator.h

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 3a2411b4ed29..6b46fc5ad312 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2111,6 +2111,11 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// than implicitly __strong.
   bool isObjCARCImplicitlyUnretainedType() const;
 
+  /// Check if the type is the CUDA device builtin surface type.
+  bool isCUDADeviceBuiltinSurfaceType() const;
+  /// Check if the type is the CUDA device builtin texture type.
+  bool isCUDADeviceBuiltinTextureType() const;
+
   /// Return the implicit lifetime for this type, which must not be dependent.
   Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5a90b2be2cbf..96bfdd313f47 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1064,16 +1064,20 @@ def CUDADeviceBuiltin : IgnoredAttr {
   let LangOpts = [CUDA];
 }
 
-def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
+def CUDADeviceBuiltinSurfaceType : InheritableAttr {
   let Spellings = [GNU<"device_builtin_surface_type">,
Declspec<"__device_builtin_surface_type__">];
   let LangOpts = [CUDA];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [CUDADeviceBuiltinSurfaceTypeDocs];
 }
 
-def CUDADeviceBuiltinTextureType : IgnoredAttr {
+def CUDADeviceBuiltinTextureType : InheritableAttr {
   let Spellings = [GNU<"device_builtin_texture_type">,
Declspec<"__device_builtin_texture_type__">];
   let LangOpts = [CUDA];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [CUDADeviceBuiltinTextureTypeDocs];
 }
 
 def CUDAGlobal : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a1cf25ed3929..2c89dc6f4952 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4624,6 +4624,28 @@ the initializer on host side.
   }];
 }
 
+def CUDADeviceBuiltinSurfaceTypeDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+The ``device_builtin_surface_type`` attribute can be applied to a class
+template when declaring the surface reference. A surface reference variable
+could be accessed on the host side and, on the device side, might be translated
+into an internal surface object, which is established through surface bind and
+unbind runtime APIs.
+  }];
+}
+
+def CUDADeviceBuiltinTextureTypeDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+The ``device_builtin_texture_type`` attribute can be applied to a class
+template when declaring the texture reference. A texture reference variable
+could be accessed on the host side and, on the device side, might be translated
+into an internal texture object, which is established through texture bind and
+unbind runtime APIs.
+  }];
+}
+
 def LifetimeOwnerDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 762dd1469236..c642c2ba36c8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7967,6 +7967,22 @@ def err_cuda_ovl_target : Error<
 def 

[PATCH] D76949: Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins

2020-03-27 Thread Cameron McInally via Phabricator via cfe-commits
cameron.mcinally accepted this revision.
cameron.mcinally added a comment.
This revision is now accepted and ready to land.

LGTM, assuming Harbormaster whines are addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76949



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76365#1946925 , @hliao wrote:

> Fix Sema checks on partial template specialization.
>
> - Revise Sema checks on the template class.


The new revision is accepted, right? Just want to confirm as it seems you 
accept it before I posted the new change.

In D76365#1946908 , @tra wrote:

> Reopened for further work





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[PATCH] D76953: [AST] Fix a crash on invalid bitwidth exprs when preserving the recoveryexprs.

2020-03-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

If the bitwith expr contains errors, we mark the field decl invalid.

This patch also tweaks the behavior of ObjCInterfaceDecl to be consistent with
existing RecordDecl -- getObjCLayout method is only called with valid decls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76953

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/invalid-bitwidth-expr.cpp
  clang/test/Sema/invalid-bitwidth-expr.mm


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- /dev/null
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
+// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
+@interface Ivar
+{
+  int Foo : foo(); // expected-error {{use of undeclared identifier}}
+};
+@end
+
+constexpr int s = sizeof(Ivar);
Index: clang/test/Sema/invalid-bitwidth-expr.cpp
===
--- /dev/null
+++ clang/test/Sema/invalid-bitwidth-expr.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -frecovery-ast %s
+// RUN: %clang_cc1 -verify -fsyntax-only -fno-recovery-ast %s
+
+struct X { int Y: foo(); }; // expected-error {{use of undeclared identifier}}
+constexpr int ss = sizeof(X);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16172,6 +16172,10 @@
 IdentifierInfo *FieldName,
 QualType FieldTy, bool IsMsStruct,
 Expr *BitWidth, bool *ZeroWidth) {
+  assert(BitWidth);
+  if (BitWidth->containsErrors())
+return ExprError();
+
   // Default to true; that shouldn't confuse checks for emptiness
   if (ZeroWidth)
 *ZeroWidth = true;
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3222,7 +3222,8 @@
   if (D->hasExternalLexicalStorage() && !D->getDefinition())
 getExternalSource()->CompleteType(const_cast(D));
   D = D->getDefinition();
-  assert(D && D->isThisDeclarationADefinition() && "Invalid interface decl!");
+  assert(D && !D->isInvalidDecl() && D->isThisDeclarationADefinition() &&
+ "Invalid interface decl!");
 
   // Look up this layout, if already laid out, return what we have.
   const ObjCContainerDecl *Key =
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2161,6 +2161,12 @@
 return getTypeInfo(cast(T)->getAdjustedType().getTypePtr());
   case Type::ObjCInterface: {
 const auto *ObjCI = cast(T);
+if (ObjCI->getDecl()->isInvalidDecl()) {
+  // FIXME: are the numbers correct?
+  Width = 8;
+  Align = 8;
+  break;
+}
 const ASTRecordLayout  = 
getASTObjCInterfaceLayout(ObjCI->getDecl());
 Width = toBits(Layout.getSize());
 Align = toBits(Layout.getAlignment());


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- /dev/null
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
+// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
+@interface Ivar
+{
+  int Foo : foo(); // expected-error {{use of undeclared identifier}}
+};
+@end
+
+constexpr int s = sizeof(Ivar);
Index: clang/test/Sema/invalid-bitwidth-expr.cpp
===
--- /dev/null
+++ clang/test/Sema/invalid-bitwidth-expr.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -frecovery-ast %s
+// RUN: %clang_cc1 -verify -fsyntax-only -fno-recovery-ast %s
+
+struct X { int Y: foo(); }; // expected-error {{use of undeclared identifier}}
+constexpr int ss = sizeof(X);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16172,6 +16172,10 @@
 IdentifierInfo *FieldName,
 QualType FieldTy, bool IsMsStruct,
 Expr *BitWidth, bool *ZeroWidth) {
+  assert(BitWidth);
+  if (BitWidth->containsErrors())
+return ExprError();
+
   // Default to true; that shouldn't confuse checks for emptiness
   if (ZeroWidth)
 *ZeroWidth = true;
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ 

[PATCH] D76942: Add BitWidth trait to BitmaskEnum, and use for clang DependenceFlags. NFC

2020-03-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

look nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76942



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


[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 253214.
hliao added a comment.

Fix Sema checks on partial template specialization.

- Revise Sema checks on the template class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/attr-declspec.cu
  clang/test/SemaCUDA/attributes-on-non-cuda.cu
  clang/test/SemaCUDA/bad-attributes.cu
  llvm/include/llvm/IR/Operator.h

Index: llvm/include/llvm/IR/Operator.h
===
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -599,6 +599,25 @@
   }
 };
 
+class AddrSpaceCastOperator
+: public ConcreteOperator {
+  friend class AddrSpaceCastInst;
+  friend class ConstantExpr;
+
+public:
+  Value *getPointerOperand() { return getOperand(0); }
+
+  const Value *getPointerOperand() const { return getOperand(0); }
+
+  unsigned getSrcAddressSpace() const {
+return getPointerOperand()->getType()->getPointerAddressSpace();
+  }
+
+  unsigned getDestAddressSpace() const {
+return getType()->getPointerAddressSpace();
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_OPERATOR_H
Index: clang/test/SemaCUDA/bad-attributes.cu
===
--- clang/test/SemaCUDA/bad-attributes.cu
+++ clang/test/SemaCUDA/bad-attributes.cu
@@ -70,3 +70,27 @@
 __device__ void device_fn() {
   __constant__ int c; // expected-error {{__constant__ variables must be global}}
 }
+
+typedef __attribute__((device_builtin_surface_type)) unsigned long long s0_ty; // expected-warning {{'device_builtin_surface_type' attribute only applies to classes}}
+typedef __attribute__((device_builtin_texture_type)) unsigned long long t0_ty; // expected-warning {{'device_builtin_texture_type' attribute only applies to classes}}
+
+struct __attribute__((device_builtin_surface_type)) s1_ref {}; // expected-error {{illegal device builtin surface reference type 's1_ref' declared here}}
+// expected-note@-1 {{'s1_ref' needs to be instantiated from a class template with proper template arguments}}
+struct __attribute__((device_builtin_texture_type)) t1_ref {}; // expected-error {{illegal device builtin texture reference type 't1_ref' declared here}}
+// expected-note@-1 {{'t1_ref' needs to be instantiated from a class template with proper template arguments}}
+
+template 
+struct __attribute__((device_builtin_surface_type)) s2_cls_template {}; // expected-error {{illegal device builtin surface reference class template 's2_cls_template' declared here}}
+// expected-note@-1 {{'s2_cls_template' needs to have exactly 2 template parameters}}
+template 
+struct __attribute__((device_builtin_texture_type)) t2_cls_template {}; // expected-error {{illegal device builtin texture reference class template 't2_cls_template' declared here}}
+// expected-note@-1 {{'t2_cls_template' needs to have exactly 3 template parameters}}
+
+template 
+struct __attribute__((device_builtin_surface_type)) s3_cls_template {}; // expected-error {{illegal device builtin surface reference class template 's3_cls_template' declared here}}
+// expected-note@-1 {{the 1st template parameter of 's3_cls_template' needs to be a type}}
+// expected-note@-2 {{the 2nd template parameter of 's3_cls_template' needs to be an integer or enum value}}
+template 
+struct __attribute__((device_builtin_texture_type)) t3_cls_template {}; // expected-error {{illegal device builtin texture reference class template 't3_cls_template' declared here}}
+// expected-note@-1 {{the 1st template parameter of 't3_cls_template' needs to be a type}}
+// expected-note@-2 {{the 3rd template parameter of 't3_cls_template' needs to be an integer or enum value}}
Index: clang/test/SemaCUDA/attributes-on-non-cuda.cu
===
--- clang/test/SemaCUDA/attributes-on-non-cuda.cu
+++ clang/test/SemaCUDA/attributes-on-non-cuda.cu
@@ -7,16 +7,19 @@
 // RUN: %clang_cc1 -DEXPECT_WARNINGS -fsyntax-only -verify -x c %s
 
 #if defined(EXPECT_WARNINGS)
-// expected-warning@+12 {{'device' attribute ignored}}
-// expected-warning@+12 {{'global' attribute ignored}}
-// expected-warning@+12 {{'constant' attribute ignored}}
-// 

[PATCH] D76365: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra reopened this revision.
tra added a comment.
This revision is now accepted and ready to land.

Reopened for further work


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76365



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D76948#1946878 , @hliao wrote:

> I tried that before submitting this one. But, as it's in the closed state, I 
> cannot submit that anymore. I will attach the difference against the previous 
> change somewhere.


I've reopened it. Let's move the patch and discussion there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao marked an inline comment as done.
hliao added inline comments.



Comment at: clang/test/SemaCUDA/bad-attributes.cu:74-75
+
+typedef __attribute__((device_builtin_surface_type)) unsigned long long s0_ty; 
// expected-warning {{'device_builtin_surface_type' attribute only applies to 
classes}}
+typedef __attribute__((device_builtin_texture_type)) unsigned long long t0_ty; 
// expected-warning {{'device_builtin_texture_type' attribute only applies to 
classes}}
+

tra wrote:
> Please add few test cases replicating use of these attributes in CUDA headers.
the replication from CUDA headers is added on those codegen tests. These tests 
are illegal ones which sema checks should identify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D68115: Zero initialize padding in unions

2020-03-27 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D68115#1946757 , @rsmith wrote:

> 3. After doing (1), extend `__builtin_bit_cast` support to properly handle 
> padding bits.
> 4. After doing (1) and (2), extend constant aggregate emission to always zero 
> padding when required by the language standard. (If you want, make the flag 
> be three-way: never zero, zero as required by language standard, always zero, 
> maybe: `-fzero-padding=never` / `-fzero-padding=std`, 
> `-fzero-padding=always`.)


Just to make sure I understand correctly. There is no proposal to consider 
non-standard zeroing behaviour in constant expression evaluation; right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76948#1946861 , @tra wrote:

> Would it be possible to update the old review with the new diff? It would 
> make it easier to see the incremental changes you've made. If the old review 
> can be reopened that would be great as it would keep all relevant info in one 
> place, but I'm fine doing the review here, too, if phabricator does not let 
> you do it.


Check this for the new change.

https://gist.github.com/darkbuck/836dbb3112ca2e5fab769cf3cdaecd09


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D76948#1946861 , @tra wrote:

> Would it be possible to update the old review with the new diff? It would 
> make it easier to see the incremental changes you've made. If the old review 
> can be reopened that would be great as it would keep all relevant info in one 
> place, but I'm fine doing the review here, too, if phabricator does not let 
> you do it.


I tried that before submitting this one. But, as it's in the closed state, I 
cannot submit that anymore. I will attach the difference against the previous 
change somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Would it be possible to update the old review with the new diff? It would make 
it easier to see the incremental changes you've made. If the old review can be 
reopened that would be great as it would keep all relevant info in one place, 
but I'm fine doing the review here, too, if phabricator does not let you do it.




Comment at: clang/test/SemaCUDA/bad-attributes.cu:74-75
+
+typedef __attribute__((device_builtin_surface_type)) unsigned long long s0_ty; 
// expected-warning {{'device_builtin_surface_type' attribute only applies to 
classes}}
+typedef __attribute__((device_builtin_texture_type)) unsigned long long t0_ty; 
// expected-warning {{'device_builtin_texture_type' attribute only applies to 
classes}}
+

Please add few test cases replicating use of these attributes in CUDA headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D76943: [clang analysis] Make mutex guard detection more reliable.

2020-03-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2144-2145
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion)
+  E = CE->getSubExpr()->IgnoreParens();

Should we also skip over `CK_UserDefinedConversion` here (for conversion 
functions that return mutex locks, I suppose)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76943



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


[PATCH] D33029: [clang-format] add option for dangling parenthesis

2020-03-27 Thread Bhopesh Bassi via Phabricator via cfe-commits
bbassi added a comment.

I don't think that's quite right. Then you will also have to have a 
`AlignWithDanglingParenthesis` for cases when people still want closing 
parenthesis on new line but want parameters as well as closing parenthesis to 
be aligned with opening parenthesis. I think we need a separate option, 
something like `BreakBeforeClosingBracket`.


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

https://reviews.llvm.org/D33029



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


[PATCH] D76949: Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins

2020-03-27 Thread Andrew J Wock via Phabricator via cfe-commits
ajwock created this revision.
ajwock added reviewers: kpn, cameron.mcinally, spatel, hfinkel.
Herald added subscribers: cfe-commits, steven.zhang, shchenz, kbarton, nemanjai.
Herald added a project: clang.
ajwock added a reviewer: nemanjai.
Herald added a subscriber: wuzish.

This patch adds a test for the PowerPC fma compiler builtins, some variations 
of which negate inputs and outputs.  The code to generate IR for these builtins 
was untested before this patch.

Originally, the code used the outdated method of subtracting floating point 
values from -0.0 as floating point negation.  This patch remedies that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76949

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-fma.c


Index: clang/test/CodeGen/builtins-ppc-fma.c
===
--- clang/test/CodeGen/builtins-ppc-fma.c
+++ clang/test/CodeGen/builtins-ppc-fma.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple powerpc64le-gnu-linux \
+// RUN: -target-feature +altivec -Wall -Wno-unused -Werror -emit-llvm %s -o - 
| FileCheck  \
+// RUN: %s
+
+typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
+typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
+
+volatile vec_double vd;
+volatile vec_float vf;
+
+void test_fma(void) {
+  vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> %{{.*}})
+
+  vd = __builtin_vsx_xvmaddadp(vd, vd, vd);
+  // CHECK: @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x 
double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmaddasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
+  // CHECK: fneg <4 x float> [[RESULT]]
+
+  vd = __builtin_vsx_xvnmaddadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+  // CHECK: fneg <2 x double> [[RESULT]]
+
+  vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] fneg <4 x float> %{{.*}}
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
+
+  vd = __builtin_vsx_xvmsubadp(vd, vd, vd);
+  // CHECK: fneg <2 x double> [[RESULT]]
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <4 x float> @llvm.fma.v2f64(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> [[RESULT]])
+  // CHECK: fneg <4 x float> [[RESULT2]]
+
+  vd = __builtin_vsx_xvnmsubadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <2 x double> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x 
double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> [[RESULT]])
+  // CHECK: fneg <2 x double> [[RESULT2]]
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13083,25 +13083,24 @@
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
 return Builder.CreateCall(F, {X, Y, Z});
+
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFSub(Zero,
-  Builder.CreateCall(F, {X, Y, Z}), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
+
   case PPC::BI__builtin_vsx_xvmsubadp:
   case PPC::BI__builtin_vsx_xvmsubasp:
-return Builder.CreateCall(F,
-  {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
+
   case PPC::BI__builtin_vsx_xvnmsubadp:
   case PPC::BI__builtin_vsx_xvnmsubasp:
-Value *FsubRes =
-  Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
-return Builder.CreateFSub(Zero, FsubRes, "sub");
+return Builder.CreateFNeg(
+Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")}), 
"neg");
 }
 llvm_unreachable("Unknown FMA operation");
 return nullptr; // Suppress no-return warning


Index: clang/test/CodeGen/builtins-ppc-fma.c
===
--- clang/test/CodeGen/builtins-ppc-fma.c
+++ 

[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

This's revised change from https://reviews.llvm.org/D76365 after fixing Sema 
checks on the template partial specialization. With this change, I could 
compile the following sample code using surface reference.

kernel.cu

  #include 
  
  surface surf;
  
  #if defined(__clang__)
  __device__ int
  suld_2d_trap(surface, int, int) 
asm("llvm.nvvm.suld.2d.i32.trap");
  
  template 
  static inline __device__ T
  surf2Dread(surface s, int x, int y) {
// By default, `surf2Dread` uses trap mode.
return suld_2d_trap(s, x, y);
  }
  #endif
  
  __device__ int foo(int x, int y) { return surf2Dread(surf, x, y); }

With NVCC, it generates

`kernel.ptx` after `nvcc --ptx -rdc=true kernel.cu`

  //
  // Generated by NVIDIA NVVM Compiler
  //
  // Compiler Build ID: CL-27506705
  // Cuda compilation tools, release 10.2, V10.2.89
  // Based on LLVM 3.4svn
  //
  
  .version 6.5
  .target sm_30
  .address_size 64
  
  // .globl   _Z3fooii
  .visible .global .surfref surf;
  
  .visible .func  (.param .b32 func_retval0) _Z3fooii(
  .param .b32 _Z3fooii_param_0,
  .param .b32 _Z3fooii_param_1
  )
  {
  .reg .b32   %r<4>;
  .reg .b64   %rd<2>;
  
  
  ld.param.u32%r1, [_Z3fooii_param_0];
  ld.param.u32%r2, [_Z3fooii_param_1];
  suld.b.2d.b32.trap {%r3}, [surf, {%r1, %r2}];
  st.param.b32[func_retval0+0], %r3;
  ret;
  }

With Clang, it generates

`kernel-cuda-nvptx64-nvidia-cuda-sm_30.s` after `clang --cuda-device-only 
--cuda-gpu-arch=sm_30 -O2 -S kernel.cu`

  //
  // Generated by LLVM NVPTX Back-End
  //
  
  .version 6.4
  .target sm_30
  .address_size 64
  
  // .globl   _Z3fooii
  .visible .global .surfref surf;
  
  .visible .func  (.param .b32 func_retval0) _Z3fooii(
  .param .b32 _Z3fooii_param_0,
  .param .b32 _Z3fooii_param_1
  )
  {
  .reg .b32   %r<4>;
  .reg .b64   %rd<2>;
  
  ld.param.u32%r1, [_Z3fooii_param_0];
  ld.param.u32%r2, [_Z3fooii_param_1];
  mov.u64 %rd1, surf;
  suld.b.2d.b32.trap {%r3}, [%rd1, {%r1, %r2}];
  st.param.b32[func_retval0+0], %r3;
  ret;
  
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76948



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


[PATCH] D69585: PerformPendingInstatiations() already in the PCH

2020-03-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D69585#1943222 , @llunak wrote:

> In D69585#1942431 , @rsmith wrote:
>
> > This needs to be done behind a flag. It's an explicit design goal that 
> > compilation behavior using a PCH or precompiled preamble behaves 
> > identically to compilation not using a PCH / precompiled preamble. The 
> > behavior of this patch is also non-conforming: we're only allowed to 
> > perform function template instantiations at their points of instantiation 
> > (essentially, at points of use + at the end of the translation unit).
>
>
> How is that different from -fmodules? Given that AFAICT this makes PCHs work 
> the same way as modules, this should mean -fmodules also both fails the 
> identical behaviour goal and is non-conforming.


Each header module ("header unit" in C++20 terminology) in a modules build is a 
distinct translation unit, so there's a point of instantiation at the end of 
it. It's also not a goal of `-fmodules` nor C++20 modules to produce identical 
output to a non-modules build; the modules language feature is intended to 
change the observable language semantics (unlike PCH, which is intended to 
improve build speed without affecting semantics).

> And to make sure I understand correctly, by behaving identically you mean 
> that all the compiler output should be identical without even benign 
> differences?

If by "benign differences" you mean things like different (but still correct) 
diagnostic output, then yes, that's the goal. I think producing the same 
diagnostics in a different order might be OK, though. For example, in an IDE, 
we can automatically precompile a header or a preamble to make interactive use 
more efficient, without changing the observable behavior of the compiler. We 
don't want a different diagnostic experience for interactive use versus 
standalone compilation.

In addition to the "explicit specialization after instantiation" problem you 
identified, attempting instantiation at the end of a preamble or PCH would also 
break things like this:

  template void f();
  struct X;
  void g() { f(); } // instantiation not performed yet
  
  template void f() { T t; };
  // -- end of preamble or PCH --
  struct X {};

Here, instantiation at the end of TU is valid, but instantiation at the end of 
preamble / PCH would reject this valid code, because we'd instantiate `f` 
while `X` is incomplete.


Repository:
  rC Clang

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

https://reviews.llvm.org/D69585



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


[PATCH] D76948: [cuda][hip] Add CUDA builtin surface/texture reference support.

2020-03-27 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: tra, rjmccall, yaxunl.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hliao added a comment.

This's revised change from https://reviews.llvm.org/D76365 after fixing Sema 
checks on the template partial specialization. With this change, I could 
compile the following sample code using surface reference.

kernel.cu

  #include 
  
  surface surf;
  
  #if defined(__clang__)
  __device__ int
  suld_2d_trap(surface, int, int) 
asm("llvm.nvvm.suld.2d.i32.trap");
  
  template 
  static inline __device__ T
  surf2Dread(surface s, int x, int y) {
// By default, `surf2Dread` uses trap mode.
return suld_2d_trap(s, x, y);
  }
  #endif
  
  __device__ int foo(int x, int y) { return surf2Dread(surf, x, y); }

With NVCC, it generates

`kernel.ptx` after `nvcc --ptx -rdc=true kernel.cu`

  //
  // Generated by NVIDIA NVVM Compiler
  //
  // Compiler Build ID: CL-27506705
  // Cuda compilation tools, release 10.2, V10.2.89
  // Based on LLVM 3.4svn
  //
  
  .version 6.5
  .target sm_30
  .address_size 64
  
  // .globl   _Z3fooii
  .visible .global .surfref surf;
  
  .visible .func  (.param .b32 func_retval0) _Z3fooii(
  .param .b32 _Z3fooii_param_0,
  .param .b32 _Z3fooii_param_1
  )
  {
  .reg .b32   %r<4>;
  .reg .b64   %rd<2>;
  
  
  ld.param.u32%r1, [_Z3fooii_param_0];
  ld.param.u32%r2, [_Z3fooii_param_1];
  suld.b.2d.b32.trap {%r3}, [surf, {%r1, %r2}];
  st.param.b32[func_retval0+0], %r3;
  ret;
  }

With Clang, it generates

`kernel-cuda-nvptx64-nvidia-cuda-sm_30.s` after `clang --cuda-device-only 
--cuda-gpu-arch=sm_30 -O2 -S kernel.cu`

  //
  // Generated by LLVM NVPTX Back-End
  //
  
  .version 6.4
  .target sm_30
  .address_size 64
  
  // .globl   _Z3fooii
  .visible .global .surfref surf;
  
  .visible .func  (.param .b32 func_retval0) _Z3fooii(
  .param .b32 _Z3fooii_param_0,
  .param .b32 _Z3fooii_param_1
  )
  {
  .reg .b32   %r<4>;
  .reg .b64   %rd<2>;
  
  ld.param.u32%r1, [_Z3fooii_param_0];
  ld.param.u32%r2, [_Z3fooii_param_1];
  mov.u64 %rd1, surf;
  suld.b.2d.b32.trap {%r3}, [%rd1, {%r1, %r2}];
  st.param.b32[func_retval0+0], %r3;
  ret;
  
  }


- Re-commit after fix Sema checks on partial template specialization.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76948

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/attr-declspec.cu
  clang/test/SemaCUDA/attributes-on-non-cuda.cu
  clang/test/SemaCUDA/bad-attributes.cu
  llvm/include/llvm/IR/Operator.h

Index: llvm/include/llvm/IR/Operator.h
===
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -599,6 +599,25 @@
   }
 };
 
+class AddrSpaceCastOperator
+: public ConcreteOperator {
+  friend class AddrSpaceCastInst;
+  friend class ConstantExpr;
+
+public:
+  Value *getPointerOperand() { return getOperand(0); }
+
+  const Value *getPointerOperand() const { return getOperand(0); }
+
+  unsigned getSrcAddressSpace() const {
+return getPointerOperand()->getType()->getPointerAddressSpace();
+  }
+
+  unsigned getDestAddressSpace() const {
+return getType()->getPointerAddressSpace();
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_OPERATOR_H
Index: clang/test/SemaCUDA/bad-attributes.cu
===
--- clang/test/SemaCUDA/bad-attributes.cu
+++ clang/test/SemaCUDA/bad-attributes.cu
@@ -70,3 +70,27 @@
 __device__ void device_fn() {
   __constant__ int c; // expected-error {{__constant__ variables must be global}}
 }
+
+typedef __attribute__((device_builtin_surface_type)) unsigned long long s0_ty; // expected-warning {{'device_builtin_surface_type' attribute only applies to classes}}
+typedef __attribute__((device_builtin_texture_type)) unsigned long long t0_ty; // expected-warning {{'device_builtin_texture_type' attribute only applies to classes}}
+
+struct __attribute__((device_builtin_surface_type)) s1_ref {}; // expected-error {{illegal device builtin surface reference 

[PATCH] D76950: HIP: Link correct denormal mode library

2020-03-27 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added a reviewer: yaxunl.
Herald added a subscriber: wdng.
arsenm added parent revisions: D59321: AMDGPU: Teach toolchain to link rocm 
device libs, D76862: HIP: Ensure new denormal mode attributes are set.

This wasn't respecting the flush mode based on the default, and also
wasn't correctly handling the explicit
-fno-cuda-flush-denormals-to-zero overriding the mode.


https://reviews.llvm.org/D76950

Files:
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-device-libs.hip

Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -2,23 +2,94 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// Test flush-denormals-to-zero enabled uses oclc_daz_opt_on
+// Test if if oclc_daz_opt_on or if oclc_daz_opt_off is linked depending on
+// expected denormal mode.
 
+// Test subtarget with flushing on by default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib   \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// Test subtarget with flushing off by ddefault.
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// Test explicit flag, opposite of target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -fcuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
 
-// Test flush-denormals-to-zero disabled uses oclc_daz_opt_off
 
+// Test explicit flag, opposite of target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 \
+// RUN:   -fno-cuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// Test explicit flag, same as target default.
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx900 \
+// RUN:   -fno-cuda-flush-denormals-to-zero \
 // RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
 
+
+// Test explicit flag, same as target default.
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 \
+// RUN:   -fcuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// Test last flag wins, not flushing
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 \
+// RUN:   -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx900 \
+// RUN:   -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib   \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx900 \
+// RUN:   -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib   \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 \
+// RUN:   -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD
+
+
 // Test environment variable HIP_DEVICE_LIB_PATH
 
 // RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/hip_dev_lib \
@@ -33,4 +104,3 @@
 // COM-SAME: "-mlink-builtin-bitcode" "{{.*}}ockl.amdgcn.bc"
 // FLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_on.amdgcn.bc"
 // NOFLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_off.amdgcn.bc"
-
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -285,6 +285,7 @@
   (void) GpuArch;
   

[PATCH] D68115: Zero initialize padding in unions

2020-03-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D68115#1946668 , 
@hubert.reinterpretcast wrote:

> It sounds like we are looking for `-fzero-union-padding`. That's been where 
> the discussion has left off twice for months.


I believe the state of Clang prior to this patch is actually wrong. We reach 
this code regardless of the kind of initialization used for the union, and some 
forms of initialization require zeroing of padding whereas some do not. If we 
want to model this precisely, we'll need to track on `APValue` whether the 
padding bits of the union constant are zeroed or not. For example, given:

  union U { char c; int n; };
  U u = U(); // value-initialization
  U v = U{}; // aggregate initialization

Clang emits `{ i8 0, [3 x i8] undef }` for both `u` and `v`. That's correct for 
`v`, but incorrect for `u`: it should emit `{ i8 0, [3 x i8] zeroinitializer }` 
or perhaps simply `zeroinitializer`, because value-initialization invokes 
zero-initialization, which zeroes the padding.

Fixing this properly is likely not very hard, but it would require more changes 
than are present in this patch. (This patch is conservatively correct, but 
initializes more than we need to initialize.)

We also need to track in `APValue` whether padding bits are zeroed in order to 
correctly support `bit_cast` from structs with padding. Per discussion in 
committee, the intended behavior for `bit_cast` is:

> A bit in the value representation of the result is indeterminate if does not 
> correspond to a bit in the value representation of from or corresponds to a 
> bit of an object that is not within its lifetime or has an indeterminate 
> value ([basic.indet]). For each bit in the value representation of the result 
> that is indeterminate, the smallest object containing that bit has an 
> indeterminate value; the behavior is undefined unless that object is of 
> unsigned ordinary character type or std::byte type. The result does not 
> otherwise contain any indeterminate values.

So in particular:

  struct A { char c; int n; };
  constexpr long n = bit_cast(A()); // ok, 0
  constexpr long m = bit_cast(A{}); // ill-formed, indeterminate value 
due to uninitialized padding between c and n

So I would propose we take the following path:

1. Extend Clang's constant evaluator and `APValue` to track, for a struct or 
union value, whether all padding bits are zeroed. (Should always be `true` for 
a value with no padding bits.)
2. Land this patch behind a flag to zero all padding bits for unions, ideally 
extended to cover struct padding as well as union padding.
3. After doing (1), extend `__builtin_bit_cast` support to properly handle 
padding bits.
4. After doing (1) and (2), extend constant aggregate emission to always zero 
padding when required by the language standard. (If you want, make the flag be 
three-way: never zero, zero as required by language standard, always zero, 
maybe: `-fzero-padding=never` / `-fzero-padding=std`, `-fzero-padding=always`.)

Note that (1) and (2) are independent, so I don't think we need to block this 
patch (2) on the implementation of (1), but we should be aware that we're not 
done here until we do steps (3) and (4).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


LLVM buildmaster will be updated and restarted after 6PM PST today.

2020-03-27 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7PM PST today.

Thanks

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


[PATCH] D59321: AMDGPU: Teach toolchain to link rocm device libs

2020-03-27 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 253194.
arsenm added a comment.

Fix negating backwards logic for default FTZ mode


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

https://reviews.llvm.org/D59321

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
  clang/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
  clang/test/Driver/Inputs/rocm-device-libs/lib/hip.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/ockl.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_correctly_rounded_sqrt_off.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_correctly_rounded_sqrt_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_daz_opt_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_daz_opt_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_finite_only_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_finite_only_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1010.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1011.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_1012.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_803.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_isa_version_900.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_unsafe_math_off.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_unsafe_math_on.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_wavefrontsize64_off.amdgcn.bc
  
clang/test/Driver/Inputs/rocm-device-libs/lib/oclc_wavefrontsize64_on.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/ocml.amdgcn.bc
  clang/test/Driver/Inputs/rocm-device-libs/lib/opencl.amdgcn.bc
  clang/test/Driver/amdgpu-visibility.cl
  clang/test/Driver/rocm-detect.cl
  clang/test/Driver/rocm-device-libs.cl
  clang/test/Driver/rocm-not-found.cl
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -99,9 +99,9 @@
   {{"gfx906"},{"gfx906"},  GK_GFX906,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
   {{"gfx908"},{"gfx908"},  GK_GFX908,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
   {{"gfx909"},{"gfx909"},  GK_GFX909,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
-  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32},
+  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
 };
 
 const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef Table) {
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -151,7 +151,10 @@
 
   // Common features.
   FEATURE_FAST_FMA_F32 = 1 << 4,
-  FEATURE_FAST_DENORMAL_F32 = 1 << 5
+  FEATURE_FAST_DENORMAL_F32 = 1 << 5,
+
+  // Wavefront 32 is available.
+  FEATURE_WAVE32 = 1 << 6
 };
 
 StringRef getArchNameAMDGCN(GPUKind AK);
Index: clang/test/Driver/rocm-not-found.cl
===
--- /dev/null
+++ clang/test/Driver/rocm-not-found.cl
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+
+// Check that we raise an error if we're trying to compile OpenCL for amdhsa code but can't
+// find a ROCm install, unless -nogpulib was passed.
+
+// RUN: %clang -### --sysroot=%s/no-rocm-there -target amdgcn--amdhsa %s 2>&1 | FileCheck %s --check-prefix ERR
+// RUN: %clang -### --rocm-path=%s/no-rocm-there -target amdgcn--amdhsa %s 2>&1 | FileCheck %s --check-prefix ERR
+// ERR: cannot find ROCm installation. Provide its path via --rocm-path, or pass -nogpulib.
+
+// RUN: %clang -### -nogpulib --rocm-path=%s/no-rocm-there %s 2>&1 | FileCheck %s --check-prefix OK
+// OK-NOT: cannot find ROCm installation.
Index: clang/test/Driver/rocm-device-libs.cl
===
--- /dev/null
+++ clang/test/Driver/rocm-device-libs.cl
@@ -0,0 +1,163 @@
+// REQUIRES: clang-driver
+// REQUIRES: amdgpu-registered-target
+
+// Test 

[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:12248
+  ///   SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
+  DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
+

Will this collect notes associated with the diagnostic correctly?



Comment at: clang/lib/Sema/SemaAvailability.cpp:479
+case UnavailableAttr::IR_SYCLForbiddenType:
+  diag_available_here = diag::err_type_unsupported;
+  break;

All of the other cases are setting this to a note, not an error, so I suspect 
this will read wrong.



Comment at: clang/lib/Sema/SemaAvailability.cpp:534
+if (S.getLangOpts().SYCLIsDevice)
+  S.SYCLDiagIfDeviceCode(Loc, diag) << ReferringDecl;
+else

Are you sure you want to be applying this to all of the possible diagnostics 
here, rather than just for SYCLForbiddenType unavailable attributes?



Comment at: clang/lib/Sema/SemaDecl.cpp:18030
+  if (LangOpts.SYCLIsDevice && FD->hasAttr())
+return FunctionEmissionStatus::Emitted;
+

So you want to emit it for the definition in addition to emitting it for 
specific specializations?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7771
+return true;
+  }
+

I wonder if it's reasonable to treat all forbidden types the same here or if we 
want different functions for the ARC and SYCL use cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74387



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


[PATCH] D68115: Zero initialize padding in unions

2020-03-27 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D68115#1946612 , @jfb wrote:

> What's the verdict then?


It sounds like we are looking for `-fzero-union-padding`. That's been where the 
discussion has left off twice for months.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


[clang] ee7510d - Fix a Diag call not to assume option spelling

2020-03-27 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2020-03-27T12:12:44-07:00
New Revision: ee7510dc86656b739881466fddd59253d008139d

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

LOG: Fix a Diag call not to assume option spelling

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 2c0d8d05d7c0..ebeed3803e06 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -440,9 +440,11 @@ void toolchains::PS4CPU::addClangTargetOptions(
   ArgStringList ,
   Action::OffloadKind DeviceOffloadingKind) const {
   // PS4 does not use init arrays.
-  if (DriverArgs.hasArg(clang::driver::options::OPT_fuse_init_array))
+  if (DriverArgs.hasArg(options::OPT_fuse_init_array)) {
+Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array);
 getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target)
-  << "-fuse-init-array" << getTriple().str();
+<< A->getAsString(DriverArgs) << getTriple().str();
+  }
 
   CC1Args.push_back("-fno-use-init-array");
 }



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


[PATCH] D75153: [ThinLTO] Allow usage of all SMT threads in the system

2020-03-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lld/test/ELF/basic.s:252
 
-# RUN: not ld.lld %t --thinlto-jobs=0 2>&1 | FileCheck 
--check-prefix=NOTHREADSTHIN %s
-# RUN: not ld.lld %t --plugin-opt=jobs=0 2>&1 | FileCheck 
--check-prefix=NOTHREADSTHIN %s
-# NOTHREADSTHIN: --thinlto-jobs: number of threads must be > 0
+# RUN: ld.lld %t --thinlto-jobs=0 -verbose 2>&1 | FileCheck 
--check-prefix=THREADSTHIN %s
+# RUN: ld.lld %t --thinlto-jobs=1 -verbose 2>&1 | FileCheck 
--check-prefix=THREADSTHIN %s

This change is not needed. lto/thinlto.ll has already tested the functionally.

basic.s should also be split. I did this in 
34bdddf9a13cfdbbb5506dc89cf8e781be53105f



Comment at: lld/test/ELF/basic.s:253
+# RUN: ld.lld %t --thinlto-jobs=0 -verbose 2>&1 | FileCheck 
--check-prefix=THREADSTHIN %s
+# RUN: ld.lld %t --thinlto-jobs=1 -verbose 2>&1 | FileCheck 
--check-prefix=THREADSTHIN %s
+# RUN: ld.lld %t --thinlto-jobs=2 -verbose 2>&1 | FileCheck 
--check-prefix=THREADSTHIN %s

-verbose is not needed because verbose just prints input filenames, which has 
nothing to do with --thinlto-jobs=0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75153



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


[PATCH] D76943: [clang analysis] Make mutex guard detection more reliable.

2020-03-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added a reviewer: rsmith.
Herald added a project: clang.

-Wthread-safety was failing to detect certain AST patterns it should detect. 
Make the pattern detection a bit more comprehensive.

Due to an unrelated bug involving template instantiation, this showed up as a 
regression in 10.0 vs. 9.0 in the original bug report. The included testcase 
fails on older versions of clang, though.

Fixes https://bugs.llvm.org/show_bug.cgi?id=45323 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76943

Files:
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5648,6 +5648,14 @@
 auto ptr = get();
 return ptr->f();
   }
+  void use_constructor() {
+auto ptr = ReadLockedPtr(nullptr);
+ptr->f();
+auto ptr2 = ReadLockedPtr{nullptr};
+ptr2->f();
+auto ptr3 = (ReadLockedPtr{nullptr});
+ptr3->f();
+  }
 }
 
 namespace PR38640 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,13 @@
 
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
-E = EWC->getSubExpr();
-  if (auto *ICE = dyn_cast(E))
-if (ICE->getCastKind() == CK_NoOp)
-  E = ICE->getSubExpr();
+E = EWC->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion)
+  E = CE->getSubExpr()->IgnoreParens();
   if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr();
+E = BTE->getSubExpr()->IgnoreParens();
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());


Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5648,6 +5648,14 @@
 auto ptr = get();
 return ptr->f();
   }
+  void use_constructor() {
+auto ptr = ReadLockedPtr(nullptr);
+ptr->f();
+auto ptr2 = ReadLockedPtr{nullptr};
+ptr2->f();
+auto ptr3 = (ReadLockedPtr{nullptr});
+ptr3->f();
+  }
 }
 
 namespace PR38640 {
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2139,12 +2139,13 @@
 
   // handle constructors that involve temporaries
   if (auto *EWC = dyn_cast(E))
-E = EWC->getSubExpr();
-  if (auto *ICE = dyn_cast(E))
-if (ICE->getCastKind() == CK_NoOp)
-  E = ICE->getSubExpr();
+E = EWC->getSubExpr()->IgnoreParens();
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_NoOp ||
+CE->getCastKind() == CK_ConstructorConversion)
+  E = CE->getSubExpr()->IgnoreParens();
   if (auto *BTE = dyn_cast(E))
-E = BTE->getSubExpr();
+E = BTE->getSubExpr()->IgnoreParens();
 
   if (const auto *CE = dyn_cast(E)) {
 const auto *CtorD = dyn_cast_or_null(CE->getConstructor());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76942: Add BitWidth trait to BitmaskEnum, and use for clang DependenceFlags. NFC

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76942

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/Type.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  llvm/include/llvm/ADT/BitmaskEnum.h

Index: llvm/include/llvm/ADT/BitmaskEnum.h
===
--- llvm/include/llvm/ADT/BitmaskEnum.h
+++ llvm/include/llvm/ADT/BitmaskEnum.h
@@ -94,6 +94,10 @@
   return U;
 }
 
+constexpr unsigned bitWidth(uint64_t Value) {
+  return Value ? 1 + bitWidth(Value >> 1) : 0;
+}
+
 template ::value>>
 E operator~(E Val) {
   return static_cast(~Underlying(Val) & Mask());
@@ -139,6 +143,10 @@
 
 // Enable bitmask enums in namespace ::llvm and all nested namespaces.
 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+template ::value>>
+constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(uint64_t{
+static_cast>(
+E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
 
 } // namespace llvm
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -50,6 +50,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTRecordReader.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -107,7 +108,7 @@
 /// The number of record fields required for the Expr class
 /// itself.
 static const unsigned NumExprFields =
-NumStmtFields + ExprDependenceBits + 3;
+NumStmtFields + llvm::BitWidth + 3;
 
 /// Read and initialize a ExplicitTemplateArgumentList structure.
 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo ,
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1467,7 +1467,7 @@
 unsigned TC : 8;
 
 /// Store information on the type dependency.
-/*TypeDependence*/ unsigned Dependence : TypeDependenceBits;
+unsigned Dependence : llvm::BitWidth;
 
 /// True if the cache (i.e. the bitfields here starting with
 /// 'Cache') is valid.
@@ -1496,7 +1496,7 @@
   return CachedLocalOrUnnamed;
 }
   };
-  enum { NumTypeBits = 8 + TypeDependenceBits + 6 };
+  enum { NumTypeBits = 8 + llvm::BitWidth + 6 };
 
 protected:
   // These classes allow subclasses to somewhat cleanly pack bitfields
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
@@ -310,9 +311,9 @@
 
 unsigned ValueKind : 2;
 unsigned ObjectKind : 3;
-unsigned /*ExprDependence*/ Dependent : ExprDependenceBits;
+unsigned /*ExprDependence*/ Dependent : llvm::BitWidth;
   };
-  enum { NumExprBits = NumStmtBits + 5 + ExprDependenceBits };
+  enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth };
 
   class ConstantExprBitfields {
 friend class ASTStmtReader;
Index: clang/include/clang/AST/DependenceFlags.h
===
--- clang/include/clang/AST/DependenceFlags.h
+++ clang/include/clang/AST/DependenceFlags.h
@@ -36,7 +36,6 @@
   };
 };
 using ExprDependence = ExprDependenceScope::ExprDependence;
-static constexpr unsigned ExprDependenceBits = 5;
 
 struct TypeDependenceScope {
   enum TypeDependence : uint8_t {
@@ -62,7 +61,6 @@
   };
 };
 using TypeDependence = TypeDependenceScope::TypeDependence;
-static constexpr unsigned TypeDependenceBits = 4;
 
 #define LLVM_COMMON_DEPENDENCE(NAME)   \
   struct NAME##Scope { \
@@ -78,8 +76,7 @@
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Dependent)\
 }; \
   };   \
-  using NAME = NAME##Scope::NAME;  \
-  static constexpr unsigned NAME##Bits = 3;
+  using NAME = NAME##Scope::NAME;
 
 LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
 LLVM_COMMON_DEPENDENCE(TemplateNameDependence)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.

LGTM, thanks!




Comment at: clang/test/Analysis/kmalloc-linux-1.c:1
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux 
-analyzer-checker=unix.Malloc -verify %s
+

Oh, I almost forgot, the `core` package is supposed to be present :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76830



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


[PATCH] D68115: Zero initialize padding in unions

2020-03-27 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

What's the verdict then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115



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


[clang] 018ad3b - [AST] Fix typo on NoInitExpr dependence computation

2020-03-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-27T19:40:25+01:00
New Revision: 018ad3b05ec7c1c217ef203042c652a1535d3588

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

LOG: [AST] Fix typo on NoInitExpr dependence computation

Added: 


Modified: 
clang/lib/AST/ComputeDependence.cpp

Removed: 




diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index a6ccf9aad321..2db3a6e94615 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -172,7 +172,7 @@ ExprDependence clang::computeDependence(VAArgExpr *E) {
 
 ExprDependence clang::computeDependence(NoInitExpr *E) {
   return toExprDependence(E->getType()->getDependence()) &
- (ExprDependence::Instantiation & ExprDependence::Error);
+ (ExprDependence::Instantiation | ExprDependence::Error);
 }
 
 ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {



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


[PATCH] D75951: Keep a list of already-included pragma-once files for mods.

2020-03-27 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 253175.
oontvoo added a comment.

Merge master


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75951

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/dummy_pragma_once.h
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/import-pragma-once.c

Index: clang/test/Modules/import-pragma-once.c
===
--- /dev/null
+++ clang/test/Modules/import-pragma-once.c
@@ -0,0 +1,5 @@
+
+#include "dummy_pragma_once.h"
+#include "dummy_pragma_once.h"  // Re-importing should be fine
+
+void *p = 
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -282,6 +282,10 @@
   header "dummy.h"
 }
 
+module dummy_pragma_once {
+  header "dummy_pragma_once.h"
+}
+
 module builtin {
   header "builtin.h"
   explicit module sub {
Index: clang/test/Modules/Inputs/dummy_pragma_once.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/dummy_pragma_once.h
@@ -0,0 +1,3 @@
+//#pragma once | dont need this
+
+int x = 5;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1621,7 +1621,7 @@
   endian::Writer LE(Out, little);
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
   LE.write(KeyLen);
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 2 + 4 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1678,6 +1678,9 @@
   }
   LE.write(Offset);
 
+  // Write this file UID.
+  LE.write(Data.HFI.UID);
+
   auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
 if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
   uint32_t Value = (ModID << 2) | (unsigned)Role;
@@ -1705,7 +1708,7 @@
 /// Write the header search block for the list of files that
 ///
 /// \param HS The header search structure to save.
-void ASTWriter::WriteHeaderSearch(const HeaderSearch ) {
+void ASTWriter::WriteHeaderSearch(HeaderSearch ) {
   HeaderFileInfoTrait GeneratorTrait(*this);
   llvm::OnDiskChainedHashTableGenerator Generator;
   SmallVector SavedStrings;
@@ -1783,8 +1786,7 @@
 // changed since it was loaded. Also skip it if it's for a modular header
 // from a different module; in that case, we rely on the module(s)
 // containing the header to provide this information.
-const HeaderFileInfo *HFI =
-HS.getExistingFileInfo(File, /*WantExternal*/!Chain);
+HeaderFileInfo *HFI = HS.getExistingFileInfo(File, /*WantExternal*/ !Chain);
 if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
   continue;
 
@@ -1801,8 +1803,13 @@
 HeaderFileInfoTrait::key_type Key = {
   Filename, File->getSize(), getTimestampForOutput(File)
 };
+// Set the UID for this HFI so that its importers could use it
+// when serializing.
+HFI->UID = UID;
 HeaderFileInfoTrait::data_type Data = {
-  *HFI, HS.getModuleMap().findAllModulesForHeader(File), {}
+*HFI,
+HS.getModuleMap().findAllModulesForHeader(File),
+{},
 };
 Generator.insert(Key, Data, GeneratorTrait);
 ++NumHeaderSearchEntries;
@@ -2636,6 +2643,25 @@
   Stream.EmitRecord(SUBMODULE_IMPORTS, Record);
 }
 
+// Emit the imported header's UIDs.
+{
+  auto it = PP->Submodules.find(Mod);
+  if (it != PP->Submodules.end() && !it->second.IncludedFiles.empty()) {
+RecordData Record;
+for (unsigned UID : it->second.IncludedFiles) {
+  // Only save it if the header is actually import/pragma once.
+  // FIXME When we first see a header, it always goes into the mod's
+  // list of included, regardless of whether it was pragma-once or not.
+  // Maybe better to fix that earlier?
+  auto HFI = PP->getHeaderSearchInfo().FileInfo[UID];
+  if (HFI.isImport || HFI.isPragmaOnce) {
+Record.push_back(HFI.UID);
+  }
+}
+Stream.EmitRecord(SUBMODULE_IMPORTED_HEADERS, Record);
+  }
+}
+
 // Emit the exports.
 if (!Mod->Exports.empty()) {
   RecordData Record;
@@ -4722,6 +4748,24 @@
   if (WritingModule)
 WriteSubmodules(WritingModule);
 
+  // Write 

[PATCH] D33029: [clang-format] add option for dangling parenthesis

2020-03-27 Thread Ryan Stringham via Phabricator via cfe-commits
stringham added a comment.

I think that adding `AlwaysBreakWithDanglingParenthesis` as an option to 
`BracketAlignmentStyle` should not impact any of the binpacking settings - they 
should be distinct configuration.


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

https://reviews.llvm.org/D33029



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


[PATCH] D76790: [analyzer] StdLibraryFunctionsChecker: fix bug with arg constraints

2020-03-27 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 253174.
martong added a comment.

- Add tests with a subchecker


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76790

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -3,6 +3,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
 // RUN:   -verify=report
@@ -12,6 +13,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
 // RUN:   -analyzer-output=text \
@@ -85,3 +87,18 @@
 // bugpath-warning{{Function argument constraint is not satisfied}} \
 // bugpath-note{{Function argument constraint is not satisfied}}
 }
+
+int __test_fun_with_2_arg_constraints(int, int);
+void test_multiple_constraints(int x, int y) {
+  // State split should not happen here. I.e. x == 1 should not be evaluated
+  // FALSE.
+  __test_fun_with_2_arg_constraints(x, y);
+  clang_analyzer_eval(x == 1); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+  clang_analyzer_eval(y == 1); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -303,7 +303,11 @@
   void checkPostCall(const CallEvent , CheckerContext ) const;
   bool evalCall(const CallEvent , CheckerContext ) const;
 
-  enum CheckKind { CK_StdCLibraryFunctionArgsChecker, CK_NumCheckKinds };
+  enum CheckKind {
+CK_StdCLibraryFunctionArgsChecker,
+CK_StdCLibraryFunctionsTesterChecker,
+CK_NumCheckKinds
+  };
   DefaultBool ChecksEnabled[CK_NumCheckKinds];
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
@@ -452,23 +456,26 @@
   const Summary  = *FoundSummary;
   ProgramStateRef State = C.getState();
 
+  ProgramStateRef NewState = State;
   for (const ValueConstraintPtr& VC : Summary.ArgConstraints) {
-ProgramStateRef SuccessSt = VC->apply(State, Call, Summary);
-ProgramStateRef FailureSt = VC->negate()->apply(State, Call, Summary);
+ProgramStateRef SuccessSt = VC->apply(NewState, Call, Summary);
+ProgramStateRef FailureSt = VC->negate()->apply(NewState, Call, Summary);
 // The argument constraint is not satisfied.
 if (FailureSt && !SuccessSt) {
-  if (ExplodedNode *N = C.generateErrorNode(State))
+  if (ExplodedNode *N = C.generateErrorNode(NewState))
 reportBug(Call, N, C);
   break;
 } else {
-  // Apply the constraint even if we cannot reason about the argument. This
-  // means both SuccessSt and FailureSt can be true. If we weren't applying
-  // the constraint that would mean that symbolic execution continues on a
-  // code whose behaviour is undefined.
+  // We will apply the constraint even if we cannot reason about the
+  // argument. This means both SuccessSt and FailureSt can be true. If we
+  // weren't applying the constraint that would mean that symbolic
+  // execution continues on a code whose behaviour is undefined.
   assert(SuccessSt);
-  C.addTransition(SuccessSt);
+  NewState = SuccessSt;
 }
   }
+  if (NewState && NewState != State)
+C.addTransition(NewState);
 }
 
 void StdLibraryFunctionsChecker::checkPostCall(const CallEvent ,
@@ -933,6 +940,26 @@
   {"getdelim", Summaries{Getline(IntTy, IntMax), Getline(LongTy, LongMax),
  Getline(LongLongTy, LongLongMax)}},
   };
+
+  // Functions for testing.
+  if (ChecksEnabled[CK_StdCLibraryFunctionsTesterChecker]) {
+llvm::StringMap TestFunctionSummaryMap = {
+{"__test_fun_with_2_arg_constraints",
+ Summaries{
+ Summary(ArgTypes{IntTy, IntTy}, RetType{IntTy}, EvalCallAsPure)
+ .ArgConstraint(
+ ArgumentCondition(0U, WithinRange, SingleValue(1)))
+  

[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-03-27 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

There should be no error for `blockWithParam = genericBlockWithParam;` because 
`blockWithParam` is called with `I *` and it is safe to substitute 
`genericBlockWithParam`. Basically you have

  I *blockArg;
  id genericParam = blockArg;

And for `genericBlockWithParam = blockWithParam;` you have

  id blockArg;
  I *blockParam = blockArg;
  // Or as a concrete example
  // id blockArg_thatHappensToBeNumber = @42;
  // NSString *blockParam = blockArg_thatHappensToBeNumber;

It is not safe to make such assignments, that's why there is an error now.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66831



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


[PATCH] D76774: [cmake] Link libc++ tests against static libc++/libc++abi in CrossWinToARMLinux.cmake

2020-03-27 Thread Vlad Vereschaka via Phabricator via cfe-commits
vvereschaka accepted this revision.
vvereschaka 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/D76774/new/

https://reviews.llvm.org/D76774



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


[clang] 49764dc - [OPENMP50]Add basic support for inscan reduction modifier.

2020-03-27 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-27T13:54:38-04:00
New Revision: 49764dc30c4c14ed546e44b67b591902277819f7

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

LOG: [OPENMP50]Add basic support for inscan reduction modifier.

Added basic support (parsing/sema checks) for the inscan modifier in the
reduction clauses.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/nesting_of_regions.cpp
clang/test/OpenMP/parallel_for_reduction_messages.cpp
clang/test/OpenMP/parallel_reduction_messages.c
clang/test/OpenMP/scan_ast_print.cpp
clang/test/OpenMP/scan_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e26aa91a761..762dd1469236 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10078,6 +10078,19 @@ def err_omp_depobj_single_clause_expected : Error<
   "exactly one of 'depend', 'destroy', or 'update' clauses is expected">;
 def err_omp_scan_single_clause_expected : Error<
   "exactly one of 'inclusive' or 'exclusive' clauses is expected">;
+def err_omp_inclusive_exclusive_not_reduction : Error<
+  "the list item must appear in 'reduction' clause with the 'inscan' modifier "
+  "of the parent directive">;
+def err_omp_reduction_not_inclusive_exclusive : Error<
+  "the inscan reduction list item must appear as a list item in an 'inclusive' 
or"
+  " 'exclusive' clause on an inner 'omp scan' directive">;
+def err_omp_wrong_inscan_reduction : Error<
+  "'inscan' modifier can be used only in 'omp for', 'omp simd', 'omp for 
simd',"
+  " 'omp parallel for', or 'omp parallel for simd' directive">;
+def err_omp_inscan_reduction_expected : Error<
+  "expected 'reduction' clause with the 'inscan' modifier">;
+def note_omp_previous_inscan_reduction : Note<
+  "'reduction' clause with 'inscan' modifier is used here">;
 def err_omp_expected_predefined_allocator : Error<
   "expected one of the predefined allocators for the variables with the static 
"
   "storage: 'omp_default_mem_alloc', 'omp_large_cap_mem_alloc', "

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index bfb41ab105ea..3cf92ead9560 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -1112,6 +1112,7 @@ OPENMP_DEPOBJ_CLAUSE(update)
 
 // Modifiers for 'reduction' clause.
 OPENMP_REDUCTION_MODIFIER(default)
+OPENMP_REDUCTION_MODIFIER(inscan)
 
 #undef OPENMP_REDUCTION_MODIFIER
 #undef OPENMP_SCAN_CLAUSE

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 318b075db8bd..97cfb1cc8f1d 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -62,14 +62,15 @@ class DSAStackTy {
   struct DSAVarData {
 OpenMPDirectiveKind DKind = OMPD_unknown;
 OpenMPClauseKind CKind = OMPC_unknown;
+unsigned Modifier = 0;
 const Expr *RefExpr = nullptr;
 DeclRefExpr *PrivateCopy = nullptr;
 SourceLocation ImplicitDSALoc;
 DSAVarData() = default;
 DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind,
const Expr *RefExpr, DeclRefExpr *PrivateCopy,
-   SourceLocation ImplicitDSALoc)
-: DKind(DKind), CKind(CKind), RefExpr(RefExpr),
+   SourceLocation ImplicitDSALoc, unsigned Modifier)
+: DKind(DKind), CKind(CKind), Modifier(Modifier), RefExpr(RefExpr),
   PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {}
   };
   using OperatorOffsetTy =
@@ -80,6 +81,7 @@ class DSAStackTy {
 private:
   struct DSAInfo {
 OpenMPClauseKind Attributes = OMPC_unknown;
+unsigned Modifier = 0;
 /// Pointer to a reference expression and a flag which shows that the
 /// variable is marked as lastprivate(true) or not (false).
 llvm::PointerIntPair RefExpr;
@@ -164,6 +166,8 @@ class DSAStackTy {
 /// List of globals marked as declare target link in this target region
 /// (isOpenMPTargetExecutionDirective(Directive) == true).
 llvm::SmallVector DeclareTargetLinkVarDecls;
+/// List of decls used in inclusive/exclusive clauses of the scan 
directive.
+llvm::DenseSet> UsedInScanDirective;
 SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
  Scope *CurScope, SourceLocation Loc)
 : Directive(DKind), DirectiveName(Name), CurScope(CurScope),
@@ -469,9 +473,22 @@ class DSAStackTy {
   /// parent directive.
   const ValueDecl *getParentLoopControlVariable(unsigned I) const;
 
+  /// Marks the specified decl \p D as used in scan directive.
+  

[PATCH] D76692: [AST][SVE] Treat built-in SVE types as trivial

2020-03-27 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6824883cc9d: [AST][SVE] Treat built-in SVE types as trivial 
(authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76692

Files:
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -516,6 +516,7 @@
   _Static_assert(!__is_literal(svint8_t), "");
   _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
+  _Static_assert(__is_trivial(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");
   _Static_assert(!__is_floating_point(svint8_t), "");
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2249,6 +2249,9 @@
   if ((*this)->isArrayType())
 return Context.getBaseElementType(*this).isTrivialType(Context);
 
+  if ((*this)->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if ((*this)->isIncompleteType())


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -516,6 +516,7 @@
   _Static_assert(!__is_literal(svint8_t), "");
   _Static_assert(__is_pod(svint8_t), "");
   _Static_assert(!__is_polymorphic(svint8_t), "");
+  _Static_assert(__is_trivial(svint8_t), "");
   _Static_assert(__is_object(svint8_t), "");
   _Static_assert(!__is_arithmetic(svint8_t), "");
   _Static_assert(!__is_floating_point(svint8_t), "");
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2249,6 +2249,9 @@
   if ((*this)->isArrayType())
 return Context.getBaseElementType(*this).isTrivialType(Context);
 
+  if ((*this)->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array
   // types which are expressly allowed by the standard and thus our API.
   if ((*this)->isIncompleteType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76691: [AST][SVE] Treat built-in SVE types as trivially copyable

2020-03-27 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35392660e6d5: [AST][SVE] Treat built-in SVE types as 
trivially copyable (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76691

Files:
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -478,6 +478,7 @@
   (void)typeid(ref_int8);
   (void)typeid(static_int8_ptr);
 
+  _Static_assert(__is_trivially_copyable(svint8_t), "");
   _Static_assert(__is_trivially_destructible(svint8_t), "");
   _Static_assert(!__is_nothrow_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_nothrow_assignable(svint8_t &, svint8_t), "");
@@ -591,9 +592,7 @@
   for (const svint8_t  : wrapper()) { // expected-warning {{loop 
variable 'x' binds to a temporary value produced by a range of type 
'wrapper'}} expected-note {{use non-reference type}}
 (void)x;
   }
-  // This warning is bogus and will be removed by a later patch.
-  // The point is to show that it's being removed for the right reasons.
-  for (const svint8_t x : wrapper()) { // expected-warning 
{{loop variable 'x' creates a copy from type 'const svint8_t'}} expected-note 
{{use reference type}}
+  for (const svint8_t x : wrapper()) {
 (void)x;
   }
 #endif
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2303,6 +2303,9 @@
   if (CanonicalType->isDependentType())
 return false;
 
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array 
types
   // which are expressly allowed by the standard and thus our API.
   if (CanonicalType->isIncompleteType())


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -478,6 +478,7 @@
   (void)typeid(ref_int8);
   (void)typeid(static_int8_ptr);
 
+  _Static_assert(__is_trivially_copyable(svint8_t), "");
   _Static_assert(__is_trivially_destructible(svint8_t), "");
   _Static_assert(!__is_nothrow_assignable(svint8_t, svint8_t), "");
   _Static_assert(__is_nothrow_assignable(svint8_t &, svint8_t), "");
@@ -591,9 +592,7 @@
   for (const svint8_t  : wrapper()) { // expected-warning {{loop variable 'x' binds to a temporary value produced by a range of type 'wrapper'}} expected-note {{use non-reference type}}
 (void)x;
   }
-  // This warning is bogus and will be removed by a later patch.
-  // The point is to show that it's being removed for the right reasons.
-  for (const svint8_t x : wrapper()) { // expected-warning {{loop variable 'x' creates a copy from type 'const svint8_t'}} expected-note {{use reference type}}
+  for (const svint8_t x : wrapper()) {
 (void)x;
   }
 #endif
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2303,6 +2303,9 @@
   if (CanonicalType->isDependentType())
 return false;
 
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
   // Return false for incomplete types after skipping any incomplete array types
   // which are expressly allowed by the standard and thus our API.
   if (CanonicalType->isIncompleteType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76939: [AST] Add a Dependence bitmask to use for calculations with multiple node types.

2020-03-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes it easier/safer to add bits (error) to other node types without
worrying about bit layout all the time.

For now, just use to implement the ad-hoc conversion functions.
Next: remove these functions and use this directly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76939

Files:
  clang/include/clang/AST/DependenceFlags.h
  clang/lib/AST/ComputeDependence.cpp

Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -370,7 +370,8 @@
   auto Deps = ExprDependence::None;
 
   if (auto *NNS = E->getQualifier())
-Deps |= toExprDependence(NNS->getDependence());
+Deps |= toExprDependence(NNS->getDependence() &
+ ~NestedNameSpecifierDependence::Dependent);
 
   if (auto *FirstArg = E->getTemplateArgs()) {
 unsigned NumArgs = E->getNumTemplateArgs();
@@ -590,7 +591,8 @@
 D |= turnTypeToValueDependence(
 toExprDependence(ST->getType()->getDependence()));
   if (auto *Q = E->getQualifier())
-D |= toExprDependence(Q->getDependence());
+D |= toExprDependence(Q->getDependence() &
+  ~NestedNameSpecifierDependence::Dependent);
   return D;
 }
 
@@ -616,7 +618,8 @@
 Deps |= ExprDependence::UnexpandedPack;
   Deps |= getDependenceInExpr(E->getNameInfo());
   if (auto *Q = E->getQualifier())
-Deps |= toExprDependence(Q->getDependence());
+Deps |= toExprDependence(Q->getDependence() &
+ ~NestedNameSpecifierDependence::Dependent);
   for (auto *D : E->decls()) {
 if (D->getDeclContext()->isDependentContext() ||
 isa(D))
Index: clang/include/clang/AST/DependenceFlags.h
===
--- clang/include/clang/AST/DependenceFlags.h
+++ clang/include/clang/AST/DependenceFlags.h
@@ -86,29 +86,128 @@
 LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
 #undef LLVM_COMMON_DEPENDENCE
 
+// A combined space of all dependence concepts for all node types.
+// Used when aggregating dependence of nodes of different types.
+class Dependence {
+public:
+  enum Bits : uint8_t {
+None = 0,
+
+// Contains a template parameter pack that wasn't expanded.
+UnexpandedPack = 1,
+// Uses a template parameter, even if it doesn't affect the result.
+// Validity depends on the template parameter.
+Instantiation = 2,
+// Expression type depends on template context.
+// Value and Instantiation should also be set.
+Type = 4,
+// Expression value depends on template context.
+// Instantiation should also be set.
+Value = 8,
+// Depends on template context.
+// The type/value distinction is only meaningful for expressions.
+Dependent = Type | Value,
+// Includes an error, and depends on how it is resolved.
+Error = 16,
+// Type depends on a runtime value (variable-length array).
+VariablyModified = 32,
+
+LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
+  };
+
+  Dependence() : V(None) {}
+
+  Dependence(Bits V) : V(V) {}
+
+  Dependence(TypeDependence D)
+  : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TypeDependence::Instantiation, Instantiation) |
+ translate(D, TypeDependence::Dependent, Dependent) |
+ translate(D, TypeDependence::VariablyModified, VariablyModified)) {
+  }
+
+  Dependence(ExprDependence D)
+  : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, ExprDependence::Instantiation, Instantiation) |
+ translate(D, ExprDependence::Type, Type) |
+ translate(D, ExprDependence::Value, Value) |
+ translate(D, ExprDependence::Error, Error)) {}
+
+  Dependence(NestedNameSpecifierDependence D) :
+V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
+translate(D, NNSDependence::Instantiation, Instantiation) |
+translate(D, NNSDependence::Dependent, Dependent)){}
+
+  Dependence(TemplateArgumentDependence D)
+  : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TADependence::Instantiation, Instantiation) |
+ translate(D, TADependence::Dependent, Dependent)) {}
+
+  Dependence(TemplateNameDependence D)
+  : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
+ translate(D, TNDependence::Instantiation, Instantiation) |
+ translate(D, TNDependence::Dependent, Dependent)) {}
+
+  TypeDependence type() const {
+return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
+   translate(V, Instantiation, TypeDependence::Instantiation) |
+   translate(V, 

[PATCH] D33029: [clang-format] add option for dangling parenthesis

2020-03-27 Thread Bhopesh Bassi via Phabricator via cfe-commits
bbassi added a comment.

@stringham @MyDeveloperDay I have some questions.

- As some have pointed out DanglingParenthesis might be a confusing name, so 
should we try to call it something like BreakBeforeClosingBracket? When this 
option when is set to true we will always break before closing bracket.



- My use case is slightly different. I want each argument/parameter on it's own 
line and always have a break after opening bracket and before closing bracket. 
In other words, I don't want it to try to bin packing at all. What do you think 
about incorporating that use-case in current one? or if that should be a 
separate change.


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

https://reviews.llvm.org/D33029



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


[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

2020-03-27 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 253165.
adamcz added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76432

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2390,6 +2390,250 @@
 EXPECT_EQ(apply(Case.first), Case.second);
   }
 }
+
+TWEAK_TEST(AddUsing);
+TEST_F(AddUsingTest, Prepare) {
+  const std::string Header = R"cpp(
+#define NS(name) one::two::name
+namespace one {
+void oo() {}
+namespace two {
+enum ee {};
+void ff() {}
+class cc {
+public:
+  struct st {};
+  static void mm() {}
+};
+}
+})cpp";
+
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o^:^:^f^f(); }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^::^o^o(); }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o^:^:^e^e E; }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o:^:^c^c C; }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^m^m(); }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }");
+  EXPECT_UNAVAILABLE(Header + "void fun() { N^S(c^c) inst; }");
+}
+
+TEST_F(AddUsingTest, Apply) {
+  FileName = "test.cpp";
+  struct {
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedSource;
+  } Cases[]{{
+// Function, no other using, namespace.
+R"cpp(
+#include "test.hpp"
+namespace {
+void fun() {
+  ^o^n^e^:^:^t^w^o^:^:^f^f();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+namespace {using one::two::ff;
+
+void fun() {
+  ff();
+}
+})cpp",
+},
+// Type, no other using, namespace.
+{
+R"cpp(
+#include "test.hpp"
+namespace {
+void fun() {
+  ::on^e::t^wo::c^c inst;
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+namespace {using ::one::two::cc;
+
+void fun() {
+  cc inst;
+}
+})cpp",
+},
+// Type, no other using, no namespace.
+{
+R"cpp(
+#include "test.hpp"
+
+void fun() {
+  on^e::t^wo::e^e inst;
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::ee;
+
+void fun() {
+  ee inst;
+})cpp"},
+// Function, other usings.
+{
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+using one::two::ee;
+
+namespace {
+void fun() {
+  one::two::f^f();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+using one::two::ff;using one::two::ee;
+
+namespace {
+void fun() {
+  ff();
+}
+})cpp",
+},
+// Function, other usings inside namespace.
+{
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+namespace {
+
+using one::two::ff;
+
+void fun() {
+  o^ne::o^o();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+namespace {
+
+using one::oo;using one::two::ff;
+
+void fun() {
+  oo();
+}
+})cpp"},
+// Using comes after cursor.
+{
+R"cpp(
+#include "test.hpp"
+
+namespace {
+
+void fun() {
+  one::t^wo::ff();
+}
+
+using one::two::cc;
+
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+namespace {using one::two::ff;
+
+
+void fun() {
+  ff();
+}
+
+using one::two::cc;
+
+})cpp"},
+// Pointer type.
+{R"cpp(
+#include "test.hpp"
+
+void fun() {
+  one::two::c^c *p;
+})cpp",
+ R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+void fun() {
+  cc *p;
+})cpp"},
+// Namespace declared via macro.
+{R"cpp(
+#include "test.hpp"
+#define NS_BEGIN(name) namespace name {
+
+NS_BEGIN(foo)
+
+void fun() {
+  one::two::f^f();
+}
+})cpp",
+ R"cpp(
+#include "test.hpp"
+#define NS_BEGIN(name) namespace name {
+
+using one::two::ff;
+
+NS_BEGIN(foo)
+
+void fun() {
+  ff();
+}
+})cpp"},
+// Inside macro argument.
+{R"cpp(
+#include "test.hpp"
+#define CALL(name) name()
+
+void fun() {
+  CALL(one::t^wo::ff);
+})cpp",
+ R"cpp(
+#include "test.hpp"
+#define CALL(name) name()
+
+using one::two::ff;
+
+void fun() {
+  CALL(ff);
+})cpp"}};
+  llvm::StringMap EditedFiles;
+  for (const auto  : Cases) {
+for (const auto  : expandCases(Case.TestSource)) {
+  ExtraFiles["test.hpp"] = R"cpp(
+namespace one {
+void oo() {}
+namespace two {
+enum ee {};
+void ff() {}
+class cc {
+public:
+  struct st { struct nested {}; };
+  static void mm() {}
+};
+}
+})cpp";
+  

[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

2020-03-27 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 253164.
adamcz marked 22 inline comments as done.
adamcz added a comment.

Addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76432

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2390,6 +2390,251 @@
 EXPECT_EQ(apply(Case.first), Case.second);
   }
 }
+
+TWEAK_TEST(AddUsing);
+TEST_F(AddUsingTest, Prepare) {
+  const std::string Header = R"cpp(
+#define NS(name) one::two::name
+namespace one {
+void oo() {}
+namespace two {
+enum ee {};
+void ff() {}
+class cc {
+public:
+  struct st {};
+  static void mm() {}
+};
+}
+})cpp";
+
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o^:^:^f^f(); }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^::^o^o(); }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o^:^:^e^e E; }");
+  EXPECT_AVAILABLE(Header + "void fun() { o^n^e^:^:^t^w^o:^:^c^c C; }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^m^m(); }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }");
+  EXPECT_UNAVAILABLE(Header +
+ "void fun() { N^S(c^c) inst; }");
+}
+
+TEST_F(AddUsingTest, Apply) {
+  FileName = "test.cpp";
+  struct {
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedSource;
+  } Cases[]{{
+// Function, no other using, namespace.
+R"cpp(
+#include "test.hpp"
+namespace {
+void fun() {
+  ^o^n^e^:^:^t^w^o^:^:^f^f();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+namespace {using one::two::ff;
+
+void fun() {
+  ff();
+}
+})cpp",
+},
+// Type, no other using, namespace.
+{
+R"cpp(
+#include "test.hpp"
+namespace {
+void fun() {
+  ::on^e::t^wo::c^c inst;
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+namespace {using ::one::two::cc;
+
+void fun() {
+  cc inst;
+}
+})cpp",
+},
+// Type, no other using, no namespace.
+{
+R"cpp(
+#include "test.hpp"
+
+void fun() {
+  on^e::t^wo::e^e inst;
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::ee;
+
+void fun() {
+  ee inst;
+})cpp"},
+// Function, other usings.
+{
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+using one::two::ee;
+
+namespace {
+void fun() {
+  one::two::f^f();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+using one::two::ff;using one::two::ee;
+
+namespace {
+void fun() {
+  ff();
+}
+})cpp",
+},
+// Function, other usings inside namespace.
+{
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+namespace {
+
+using one::two::ff;
+
+void fun() {
+  o^ne::o^o();
+}
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+namespace {
+
+using one::oo;using one::two::ff;
+
+void fun() {
+  oo();
+}
+})cpp"},
+// Using comes after cursor.
+{
+R"cpp(
+#include "test.hpp"
+
+namespace {
+
+void fun() {
+  one::t^wo::ff();
+}
+
+using one::two::cc;
+
+})cpp",
+R"cpp(
+#include "test.hpp"
+
+namespace {using one::two::ff;
+
+
+void fun() {
+  ff();
+}
+
+using one::two::cc;
+
+})cpp"},
+// Pointer type.
+{R"cpp(
+#include "test.hpp"
+
+void fun() {
+  one::two::c^c *p;
+})cpp",
+ R"cpp(
+#include "test.hpp"
+
+using one::two::cc;
+
+void fun() {
+  cc *p;
+})cpp"},
+// Namespace declared via macro.
+{R"cpp(
+#include "test.hpp"
+#define NS_BEGIN(name) namespace name {
+
+NS_BEGIN(foo)
+
+void fun() {
+  one::two::f^f();
+}
+})cpp",
+ R"cpp(
+#include "test.hpp"
+#define NS_BEGIN(name) namespace name {
+
+using one::two::ff;
+
+NS_BEGIN(foo)
+
+void fun() {
+  ff();
+}
+})cpp"},
+// Inside macro argument.
+{R"cpp(
+#include "test.hpp"
+#define CALL(name) name()
+
+void fun() {
+  CALL(one::t^wo::ff);
+})cpp",
+ R"cpp(
+#include "test.hpp"
+#define CALL(name) name()
+
+using one::two::ff;
+
+void fun() {
+  CALL(ff);
+})cpp"}};
+  llvm::StringMap EditedFiles;
+  for (const auto  : Cases) {
+for (const auto  : expandCases(Case.TestSource)) {
+  ExtraFiles["test.hpp"] = R"cpp(
+namespace one {
+void oo() {}
+namespace two {
+enum ee {};
+void ff() {}
+class cc {
+public:

[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

2020-03-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 253163.
balazske added a comment.

- Removed test file malloc-linux-1.c
- Prevent warning only if "malloc family" free is done (Do not recognize 
`ZERO_SIZE_PTR` at a `delete` call.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76830

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  clang/test/Analysis/kmalloc-linux.c
  clang/test/Analysis/malloc.cpp

Index: clang/test/Analysis/malloc.cpp
===
--- clang/test/Analysis/malloc.cpp
+++ clang/test/Analysis/malloc.cpp
@@ -164,3 +164,11 @@
   (void)a.getName();
 }
 } // namespace argument_leak
+
+#define ZERO_SIZE_PTR ((void *)16)
+
+void test_delete_ZERO_SIZE_PTR() {
+  int *Ptr = (int *)ZERO_SIZE_PTR;
+  // ZERO_SIZE_PTR is specially handled but only for malloc family
+  delete Ptr; // expected-warning{{Argument to 'delete' is a constant address (16)}}
+}
Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -121,3 +121,17 @@
   if (list == NULL)
 return;
 } // expected-warning{{Potential leak of memory pointed to by 'list'}}
+
+// kmalloc can return a constant value defined in ZERO_SIZE_PTR
+// if a block of size 0 is requested
+#define ZERO_SIZE_PTR ((void *)16)
+
+void test_kfree_ZERO_SIZE_PTR() {
+  void *ptr = ZERO_SIZE_PTR;
+  kfree(ptr); // no warning about freeing this value
+}
+
+void test_kfree_other_constant_value() {
+  void *ptr = (void *)1;
+  kfree(ptr); // expected-warning{{Argument to kfree() is a constant address (1)}}
+}
Index: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -126,9 +126,6 @@
 if (!T.isOneOf(tok::l_paren, tok::r_paren))
   FilteredTokens.push_back(T);
 
-  if (FilteredTokens.size() > 2)
-return llvm::None;
-
   // Parse an integer at the end of the macro definition.
   const Token  = FilteredTokens.back();
   if (!T.isLiteral())
@@ -140,11 +137,10 @@
 return llvm::None;
 
   // Parse an optional minus sign.
-  if (FilteredTokens.size() == 2) {
-if (FilteredTokens.front().is(tok::minus))
+  size_t Size = FilteredTokens.size();
+  if (Size >= 2) {
+if (FilteredTokens[Size - 2].is(tok::minus))
   IntValue = -IntValue;
-else
-  return llvm::None;
   }
 
   return IntValue.getSExtValue();
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -58,6 +58,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
@@ -389,6 +390,13 @@
   // TODO: Remove mutable by moving the initializtaion to the registry function.
   mutable Optional KernelZeroFlagVal;
 
+  using KernelZeroSizePtrValueTy = Optional;
+  /// Store the value of macro called `ZERO_SIZE_PTR`.
+  /// The value is initialized at first use, before first use the outer
+  /// Optional is empty, afterwards it contains another Optional that indicates
+  /// if the macro value could be determined, and if yes the value itself.
+  mutable Optional KernelZeroSizePtrValue;
+
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the constructor.
   void processNewAllocation(const CXXNewExpr *NE, CheckerContext ,
@@ -658,6 +666,10 @@
 CheckerContext );
 
   void reportLeak(SymbolRef Sym, ExplodedNode *N, CheckerContext ) const;
+
+  /// Test if value in ArgVal equals to value in macro `ZERO_SIZE_PTR`.
+  bool isArgZERO_SIZE_PTR(ProgramStateRef State, CheckerContext ,
+  SVal ArgVal) const;
 };
 
 //===--===//
@@ -1677,7 +1689,13 @@
   // Nonlocs can't be freed, of course.
   // Non-region locations (labels and fixed addresses) also shouldn't be freed.
   if (!R) {
-ReportBadFree(C, ArgVal, ArgExpr->getSourceRange(), ParentExpr, Family);
+// Exception:
+// If the macro ZERO_SIZE_PTR is defined, this could be a kernel source
+// code. In that case, the ZERO_SIZE_PTR defines a special value used for a
+

  1   2   >