r314177 - [XRay][Driver] Do not link in XRay runtime in shared libs

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 16:40:33 2017
New Revision: 314177

URL: http://llvm.org/viewvc/llvm-project?rev=314177=rev
Log:
[XRay][Driver] Do not link in XRay runtime in shared libs

Summary:
This change ensures that we don't link in the XRay runtime when building
shared libraries with clang. This doesn't prevent us from building
shared libraris tht have XRay instrumentation sleds, but it does prevent
us from linking in the static XRay runtime into a shared library.

The XRay runtime currently doesn't support dynamic registration of
instrumentation sleds in shared objects, which we'll start enabling in
the future. That work has to happen in the back-end and in the runtime.

Reviewers: rnk, pelikan

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=314177=314176=314177=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Mon Sep 25 16:40:33 2017
@@ -206,6 +206,10 @@ void tools::gcc::Linker::RenderExtraTool
 
 static bool addXRayRuntime(const ToolChain , const ArgList ,
ArgStringList ) {
+  // Do not add the XRay runtime to shared libraries.
+  if (Args.hasArg(options::OPT_shared))
+return false;
+
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
 CmdArgs.push_back("-whole-archive");
@@ -213,6 +217,7 @@ static bool addXRayRuntime(const ToolCha
 CmdArgs.push_back("-no-whole-archive");
 return true;
   }
+
   return false;
 }
 

Added: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314177=auto
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (added)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 16:40:33 2017
@@ -0,0 +1,14 @@
+// RUN: %clangxx -shared -fPIC -o /dev/null -v -fxray-instrument %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=SHARED
+// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
+// RUN: FileCheck %s --check-prefix=STATIC
+// RUN: %clangxx -static -fPIE -o /dev/null -v -fxray-instrument %s 2>&1 \
+// RUN: -DMAIN | FileCheck %s --check-prefix=STATIC
+//
+// SHARED-NOT: {{clang_rt\.xray-}}
+// STATIC: {{clang_rt\.xray-}}
+int foo() { return 42; }
+
+#ifdef MAIN
+int main() { return foo(); }
+#endif


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


[PATCH] D38259: [OpenMP] Fix translation of target args

2017-09-25 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.

ToolChain::TranslateArgs() returns nullptr if no changes are performed.
This would currently mean that OpenMPArgs are lost. Patch fixes this
by falling back to simply using OpenMPArgs in that case.


https://reviews.llvm.org/D38259

Files:
  lib/Driver/Compilation.cpp


Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -57,14 +57,16 @@
 *TranslatedArgs, DeviceOffloadKind, AllocatedArgs);
 if (!OpenMPArgs) {
   Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
+  if (!Entry)
+Entry = TranslatedArgs;
 } else {
   Entry = TC->TranslateArgs(*OpenMPArgs, BoundArch, DeviceOffloadKind);
-  delete OpenMPArgs;
+  if (!Entry)
+Entry = OpenMPArgs;
+  else
+delete OpenMPArgs;
 }
 
-if (!Entry)
-  Entry = TranslatedArgs;
-
 // Add allocated arguments to the final DAL.
 for (auto ArgPtr : AllocatedArgs) {
   Entry->AddSynthesizedArg(ArgPtr);


Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -57,14 +57,16 @@
 *TranslatedArgs, DeviceOffloadKind, AllocatedArgs);
 if (!OpenMPArgs) {
   Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
+  if (!Entry)
+Entry = TranslatedArgs;
 } else {
   Entry = TC->TranslateArgs(*OpenMPArgs, BoundArch, DeviceOffloadKind);
-  delete OpenMPArgs;
+  if (!Entry)
+Entry = OpenMPArgs;
+  else
+delete OpenMPArgs;
 }
 
-if (!Entry)
-  Entry = TranslatedArgs;
-
 // Add allocated arguments to the final DAL.
 for (auto ArgPtr : AllocatedArgs) {
   Entry->AddSynthesizedArg(ArgPtr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37656: [cfi] Set function attributes for __cfi_* functions.

2017-09-25 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis updated this revision to Diff 116618.
eugenis added a comment.

Switched to SetLLVMFunctionAttributes


https://reviews.llvm.org/D37656

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/cfi-check-thumb.c
  llvm/lib/Transforms/IPO/CrossDSOCFI.cpp
  llvm/test/Transforms/CrossDSOCFI/thumb.ll


Index: llvm/test/Transforms/CrossDSOCFI/thumb.ll
===
--- llvm/test/Transforms/CrossDSOCFI/thumb.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: opt -mtriple=armv7-linux-android -S -cross-dso-cfi < %s | FileCheck 
--check-prefix=THUMB %s
-; RUN: opt -mtriple=thumbv7-linux-android -S -cross-dso-cfi < %s | FileCheck 
--check-prefix=THUMB %s
-; RUN: opt -mtriple=i386-linux -S -cross-dso-cfi < %s | FileCheck 
--check-prefix=NOTHUMB %s
-; RUN: opt -mtriple=x86_64-linux -S -cross-dso-cfi < %s | FileCheck 
--check-prefix=NOTHUMB %s
-
-target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
-
-define signext i8 @f() !type !0 !type !1 {
-entry:
-  ret i8 1
-}
-
-!llvm.module.flags = !{!2}
-
-!0 = !{i64 0, !"_ZTSFcvE"}
-!1 = !{i64 0, i64 111}
-!2 = !{i32 4, !"Cross-DSO CFI", i32 1}
-
-; THUMB: define void @__cfi_check({{.*}} #[[A:.*]] align 4096
-; THUMB: attributes #[[A]] = { {{.*}}"target-features"="+thumb-mode"
-
-; NOTHUMB: define void @__cfi_check({{.*}} align 4096
Index: llvm/lib/Transforms/IPO/CrossDSOCFI.cpp
===
--- llvm/lib/Transforms/IPO/CrossDSOCFI.cpp
+++ llvm/lib/Transforms/IPO/CrossDSOCFI.cpp
@@ -117,10 +117,6 @@
   F->deleteBody();
   F->setAlignment(4096);
 
-  Triple T(M.getTargetTriple());
-  if (T.isARM() || T.isThumb())
-F->addFnAttr("target-features", "+thumb-mode");
-
   auto args = F->arg_begin();
   Value  = *(args++);
   CallSiteTypeId.setName("CallSiteTypeId");
Index: clang/test/CodeGen/cfi-check-thumb.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-check-thumb.c
@@ -0,0 +1,18 @@
+// Test that __cfi_check and __cfi_check_fail have common attributes and 
calling convention.
+// Also __cfi_check is always using Thumb encoding.
+// RUN: %clang_cc1 -triple armv7-linux-android -O0 -fsanitize-cfi-cross-dso \
+// RUN: -fsanitize=cfi-vcall \
+// RUN: -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK,CHECK-ARM %s
+//
+// RUN: %clang_cc1 -triple thumbv7-linux-android -O0 -fsanitize-cfi-cross-dso \
+// RUN: -fsanitize=cfi-vcall \
+// RUN: -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK,CHECK-THUMB 
%s
+//
+// REQUIRES: arm-registered-target
+
+// CHECK-ARM: define weak_odr hidden void @__cfi_check_fail(i8*, i8*) 
#[[ARM:.*]] {
+// CHECK-THUMB: define weak_odr hidden void @__cfi_check_fail(i8*, i8*) 
#[[THUMB:.*]] {
+// CHECK: define weak void @__cfi_check(i64, i8*, i8*) #[[THUMB:.*]] {
+
+// CHECK-ARM: attributes #[[ARM]] = {{.*}}"target-features"="{{.*}}-thumb-mode
+// CHECK: attributes #[[THUMB]] = {{.*}}"target-features"="{{.*}}+thumb-mode
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -2928,6 +2928,18 @@
   llvm::CallInst::Create(
   llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
   llvm::ReturnInst::Create(Ctx, nullptr, BB);
+
+  // Set default function attributes, but force thumb encoding if applicable.
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeBuiltinFunctionDeclaration(getContext().VoidTy, 
{});
+  FunctionDecl *FD =
+  FunctionDecl::Create(getContext(), getContext().getTranslationUnitDecl(),
+   {}, {}, {}, getContext().VoidTy, nullptr, 
SC_Extern);
+  const auto  = getTarget().getTriple();
+  if (Triple.isARM() || Triple.isThumb()) {
+FD->addAttr(TargetAttr::CreateImplicit(getContext(), "thumb"));
+  }
+  CGM.SetLLVMFunctionAttributes(FD, FI, F);
 }
 
 // This function is basically a switch over the CFI failure kind, which is
@@ -3011,6 +3023,9 @@
   }
 
   FinishFunction();
+
+  CGM.SetLLVMFunctionAttributes(nullptr, FI, F);
+
   // The only reference to this function will be created during LTO link.
   // Make sure it survives until then.
   CGM.addUsedGlobal(F);


Index: llvm/test/Transforms/CrossDSOCFI/thumb.ll
===
--- llvm/test/Transforms/CrossDSOCFI/thumb.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: opt -mtriple=armv7-linux-android -S -cross-dso-cfi < %s | FileCheck --check-prefix=THUMB %s
-; RUN: opt -mtriple=thumbv7-linux-android -S -cross-dso-cfi < %s | FileCheck --check-prefix=THUMB %s
-; RUN: opt -mtriple=i386-linux -S -cross-dso-cfi < %s | FileCheck --check-prefix=NOTHUMB %s
-; RUN: opt -mtriple=x86_64-linux -S -cross-dso-cfi < %s | FileCheck --check-prefix=NOTHUMB %s
-
-target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
-
-define signext i8 @f() !type !0 !type !1 {
-entry:
-  

r314159 - [x86] make assertions less strict in avx512f test file

2017-09-25 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Mon Sep 25 14:31:08 2017
New Revision: 314159

URL: http://llvm.org/viewvc/llvm-project?rev=314159=rev
Log:
[x86] make assertions less strict in avx512f test file

Missed a line in r314158.

Modified:
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=314159=314158=314159=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Mon Sep 25 14:31:08 2017
@@ -8351,7 +8351,7 @@ __m128d test_mm_maskz_move_sd (__mmask8
   // CHECK-LABEL: @test_mm_maskz_move_sd
   // CHECK:  extractelement <2 x double> %{{.*}}, i32 0
   // CHECK:  phi double [ %{{.*}}, %{{.*}} ], [ 0.00e+00, %{{.*}} ]
-  // CHECK:  insertelement <2 x double> %6, double %cond.i, i32 0
+  // CHECK:  insertelement <2 x double> %{{.*}}, double %{{.*}}, i32 0
   return _mm_maskz_move_sd (__U, __A, __B);
 }
 


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


[PATCH] D37913: [OpenMP] Enable the existing nocudalib flag for OpenMP offloading toolchain.

2017-09-25 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 116621.
gtbercea added a comment.

Split line.


https://reviews.llvm.org/D37913

Files:
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -125,3 +125,13 @@
 // RUN:   | FileCheck -check-prefix=CHK-PTXAS-RELO %s
 
 // CHK-PTXAS-RELO: ptxas{{.*}}" "-c"
+
+/// ###
+
+/// Check that error is not thrown by toolchain when no cuda lib flag is used.
+/// Check that the flag is passed when -fopenmp-relocatable-target is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target -march=sm_60 \
+// RUN:   -nocudalib -fopenmp-relocatable-target -save-temps 
-no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FLAG-NOLIBDEVICE %s
+
+// CHK-FLAG-NOLIBDEVICE-NOT: error:{{.*}}sm_60
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -492,11 +492,11 @@
 if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
options::OPT_fno_cuda_approx_transcendentals, 
false))
   CC1Args.push_back("-fcuda-approx-transcendentals");
-
-if (DriverArgs.hasArg(options::OPT_nocudalib))
-  return;
   }
 
+  if (DriverArgs.hasArg(options::OPT_nocudalib))
+return;
+
   std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
 
   if (LibDeviceFile.empty()) {


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -125,3 +125,13 @@
 // RUN:   | FileCheck -check-prefix=CHK-PTXAS-RELO %s
 
 // CHK-PTXAS-RELO: ptxas{{.*}}" "-c"
+
+/// ###
+
+/// Check that error is not thrown by toolchain when no cuda lib flag is used.
+/// Check that the flag is passed when -fopenmp-relocatable-target is used.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 \
+// RUN:   -nocudalib -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FLAG-NOLIBDEVICE %s
+
+// CHK-FLAG-NOLIBDEVICE-NOT: error:{{.*}}sm_60
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -492,11 +492,11 @@
 if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
options::OPT_fno_cuda_approx_transcendentals, false))
   CC1Args.push_back("-fcuda-approx-transcendentals");
-
-if (DriverArgs.hasArg(options::OPT_nocudalib))
-  return;
   }
 
+  if (DriverArgs.hasArg(options::OPT_nocudalib))
+return;
+
   std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
 
   if (LibDeviceFile.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37914: [OpenMP] Don't throw cudalib not found error if only front-end is required.

2017-09-25 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea reopened this revision.
gtbercea added a comment.
This revision is now accepted and ready to land.

Open.


Repository:
  rL LLVM

https://reviews.llvm.org/D37914



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


[PATCH] D38257: [OpenMP] Fix memory leak when translating arguments

2017-09-25 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.

Parsing the argument after -Xopenmp-target allocates memory that needs
to be freed. Associate it with the final DerivedArgList after we know
which one will be used.


https://reviews.llvm.org/D38257

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/Compilation.cpp
  lib/Driver/ToolChain.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -2,9 +2,6 @@
 /// Perform several driver tests for OpenMP offloading
 ///
 
-// Until this test is stabilized on all local configurations.
-// UNSUPPORTED: linux
-
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
 // REQUIRES: powerpc-registered-target
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -800,9 +800,10 @@
   return VersionTuple();
 }
 
-llvm::opt::DerivedArgList *
-ToolChain::TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList ,
-Action::OffloadKind DeviceOffloadKind) const {
+llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
+const llvm::opt::DerivedArgList ,
+Action::OffloadKind DeviceOffloadKind,
+SmallVector ) const {
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
 const OptTable  = getDriver().getOpts();
@@ -854,6 +855,7 @@
   }
   XOpenMPTargetArg->setBaseArg(A);
   A = XOpenMPTargetArg.release();
+  AllocatedArgs.push_back(A);
   DAL->append(A);
   NewArgAdded = true;
 }
Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -51,9 +51,10 @@
 
   DerivedArgList * = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
   if (!Entry) {
+SmallVector AllocatedArgs;
 // Translate OpenMP toolchain arguments provided via the -Xopenmp-target 
flags.
-DerivedArgList *OpenMPArgs = TC->TranslateOpenMPTargetArgs(*TranslatedArgs,
-DeviceOffloadKind);
+DerivedArgList *OpenMPArgs = TC->TranslateOpenMPTargetArgs(
+*TranslatedArgs, DeviceOffloadKind, AllocatedArgs);
 if (!OpenMPArgs) {
   Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
 } else {
@@ -63,6 +64,11 @@
 
 if (!Entry)
   Entry = TranslatedArgs;
+
+// Add allocated arguments to the final DAL.
+for (auto ArgPtr : AllocatedArgs) {
+  Entry->AddSynthesizedArg(ArgPtr);
+}
   }
 
   return *Entry;
Index: include/clang/Driver/ToolChain.h
===
--- include/clang/Driver/ToolChain.h
+++ include/clang/Driver/ToolChain.h
@@ -249,9 +249,10 @@
   ///
   /// \param DeviceOffloadKind - The device offload kind used for the
   /// translation.
-  virtual llvm::opt::DerivedArgList *
-  TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList ,
-  Action::OffloadKind DeviceOffloadKind) const;
+  virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
+  const llvm::opt::DerivedArgList ,
+  Action::OffloadKind DeviceOffloadKind,
+  SmallVector ) const;
 
   /// Choose a tool to use to handle the action \p JA.
   ///


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -2,9 +2,6 @@
 /// Perform several driver tests for OpenMP offloading
 ///
 
-// Until this test is stabilized on all local configurations.
-// UNSUPPORTED: linux
-
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
 // REQUIRES: powerpc-registered-target
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -800,9 +800,10 @@
   return VersionTuple();
 }
 
-llvm::opt::DerivedArgList *
-ToolChain::TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList ,
-Action::OffloadKind DeviceOffloadKind) const {
+llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
+const llvm::opt::DerivedArgList ,
+Action::OffloadKind DeviceOffloadKind,
+SmallVector ) const {
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
 const OptTable  = getDriver().getOpts();
@@ -854,6 +855,7 @@
   }
   XOpenMPTargetArg->setBaseArg(A);
   A = XOpenMPTargetArg.release();
+  AllocatedArgs.push_back(A);
   DAL->append(A);
   NewArgAdded = true;
 }
Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -51,9 +51,10 @@
 
   DerivedArgList * = TCArgs[{TC, BoundArch, 

[PATCH] D38258: [OpenMP] Fix passing of -m arguments to device toolchain

2017-09-25 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.

AuxTriple is not set if host and device share a toolchain. Also,
removing an argument modifies the DAL which needs to be returned
for future use.
(Move tests back to offload-openmp.c as they are not related to GPUs.)


https://reviews.llvm.org/D38258

Files:
  lib/Driver/ToolChain.cpp
  test/Driver/openmp-offload-gpu.c
  test/Driver/openmp-offload.c

Index: test/Driver/openmp-offload.c
===
--- test/Driver/openmp-offload.c
+++ test/Driver/openmp-offload.c
@@ -39,6 +39,54 @@
 
 /// ###
 
+/// Check -Xopenmp-target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 is passed when compiling for the device.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-EQ-TARGET %s
+
+// CHK-FOPENMP-EQ-TARGET: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
+
+/// ###
+
+/// Check -Xopenmp-target -mcpu=pwr7 is passed when compiling for the device.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -mcpu=pwr7 %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-TARGET %s
+
+// CHK-FOPENMP-TARGET: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
+
+/// ##
+
+/// Check -mcpu=pwr7 is passed to the same triple.
+// RUN:%clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -target powerpc64le-ibm-linux-gnu -mcpu=pwr7 %s 2>&1 \
+// RUN:| FileCheck -check-prefix=CHK-FOPENMP-MCPU-TO-SAME-TRIPLE %s
+
+// CHK-FOPENMP-MCPU-TO-SAME-TRIPLE: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
+
+/// ##
+
+/// Check -march=pwr7 is NOT passed to nvptx64-nvidia-cuda.
+// RUN:%clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -march=pwr7 %s 2>&1 \
+// RUN:| FileCheck -check-prefix=CHK-FOPENMP-MARCH-TO-GPU %s
+
+// CHK-FOPENMP-MARCH-TO-GPU-NOT: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
+
+/// ###
+
+/// Check -Xopenmp-target triggers error when multiple triples are used.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu,powerpc64le-unknown-linux-gnu -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-TARGET-AMBIGUOUS-ERROR %s
+
+// CHK-FOPENMP-TARGET-AMBIGUOUS-ERROR: clang{{.*}} error: cannot deduce implicit triple value for -Xopenmp-target, specify triple using -Xopenmp-target=
+
+/// ###
+
+/// Check -Xopenmp-target triggers error when an option requiring arguments is passed to it.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR %s
+
+// CHK-FOPENMP-TARGET-NESTED-ERROR: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
+
+/// ###
+
 /// Check the phases graph when using a single target, different from the host.
 /// We should have an offload action joining the host compile and device
 /// preprocessor and another one joining the device linking outputs to the host
Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -9,38 +9,6 @@
 
 /// ###
 
-/// Check -Xopenmp-target=powerpc64le-ibm-linux-gnu -march=pwr7 is passed when compiling for the device.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-EQ-TARGET %s
-
-// CHK-FOPENMP-EQ-TARGET: clang{{.*}} "-target-cpu" "pwr7"
-
-/// ###
-
-/// Check -Xopenmp-target -march=pwr7 is passed when compiling for the device.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -mcpu=pwr7 %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHK-FOPENMP-TARGET %s
-
-// CHK-FOPENMP-TARGET: clang{{.*}} "-target-cpu" 

Re: [PATCH] D38208: Add support for remembering origins to ExternalASTMerger

2017-09-25 Thread Sean Callanan via cfe-commits
Updated the diff.  Unfortunately reviews.llvm.org is down, so I'll try 
updating that page in the morning.


Sean

On 9/25/17 5:04 AM, Bruno Cardoso Lopes via Phabricator wrote:

bruno added inline comments.



Comment at: lib/AST/ExternalASTMerger.cpp:79
+  return cast(SearchResultDecl)->getPrimaryContext();
+else
+  return nullptr; // This type of lookup is unsupported

No need for `else` here.



Comment at: lib/AST/ExternalASTMerger.cpp:173
+ASTImporter ::ImporterForOrigin(ASTContext ) {
+  for (const std::unique_ptr  : Importers) {
+if (>getFromContext() == )

No need for curly braces here.



Comment at: lib/AST/ExternalASTMerger.cpp:189
+bool ExternalASTMerger::HasImporterForOrigin(ASTContext ) {
+  for (const std::unique_ptr  : Importers) {
+if (>getFromContext() == )

No need for curly braces here.



Comment at: lib/AST/ExternalASTMerger.cpp:289
+  LookupSameContext(Origin.AST->getTranslationUnitDecl(), ToDC, Reverse);
+  if (!FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC)) {
+if (LoggingEnabled())

You can probably simplify this to something like:


```
bool RecordOrigin = !FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC);

if (RecordOrigin)
   RecordOriginImpl(ToDC, Origin, Importer);
   
if (LoggingEnabled()) {

   logs() << "(ExternalASTMerger*)" << (void*)this
  << " decided";
  
   if (!RecordOrigin)

 logs() << " NOT";
 
   logs() << " to record origin (DeclContext*)" << (void*)Origin.DC

  << ", (ASTContext*)" << (void*)
  << "\n";
}
```



Comment at: lib/AST/ExternalASTMerger.cpp:380
+
+  if (Candidates.empty()) {
+return false;

No need for curly braces here.



Comment at: tools/clang-import-test/clang-import-test.cpp:329
  CG.GetModule()->print(llvm::outs(), nullptr);
-  if (CI->getDiagnosticClient().getNumErrors()) {
+  if (CI.getDiagnosticClient().getNumErrors()) {
  return llvm::make_error(

No need for curly braces here


Repository:
   rL LLVM

https://reviews.llvm.org/D38208





Index: include/clang/AST/ExternalASTMerger.h
===
--- include/clang/AST/ExternalASTMerger.h   (revision 313996)
+++ include/clang/AST/ExternalASTMerger.h   (working copy)
@@ -1,51 +1,176 @@
 //===--- ExternalASTMerger.h - Merging External AST Interface ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
 //
 //  This file declares the ExternalASTMerger, which vends a combination of ASTs
 //  from several different ASTContext/FileManager pairs
 //
 
//===--===//
 #ifndef LLVM_CLANG_AST_EXTERNALASTMERGER_H
 #define LLVM_CLANG_AST_EXTERNALASTMERGER_H
 
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ExternalASTSource.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
+/// ExternalASTSource implementation that merges information from several
+/// ASTContexts.
+///
+/// ExtermalASTMerger maintains a vector of ASTImporters that it uses to import
+/// (potentially incomplete) Decls and DeclContexts from the source ASTContexts
+/// in response to ExternalASTSource API calls.
+///
+/// When lookup occurs in the resulting imported DeclContexts, the original
+/// DeclContexts need to be queried.  Roughly, there are three cases here:
+///
+/// - The DeclContext of origin can be found by simple name lookup.  In this
+///   case, no additional state is required.
+///
+/// - The DeclContext of origin is different from what would be found by name
+///   lookup.  In this case, Origins contains an entry overriding lookup and
+///   specifying the correct pair of DeclContext/ASTContext.
+///
+/// - The DeclContext of origin was determined by another ExterenalASTMerger. 
+///   (This is possible when the source ASTContext for one of the Importers has
+///   its own ExternalASTMerger).  The origin must be properly forwarded in 
this
+///   case.
+///
+/// ExternalASTMerger's job is to maintain the data structures necessary to
+/// allow this.  The data structures themselves can be extracted (read-only) 
and
+/// copied for re-use.
 class ExternalASTMerger : public ExternalASTSource {
 public:
-  struct ImporterPair {
-std::unique_ptr Forward;
-std::unique_ptr Reverse;
+  /// A single origin for a DeclContext.  Unlike Decls, DeclContexts do
+  /// not allow their containing ASTContext to be determined in all cases.
+  struct DCOrigin {
+DeclContext *DC;
+ASTContext *AST;
   };
 
+  typedef std::map OriginMap;
+  typedef 

r314158 - [x86] make assertions less strict in avx512f test file

2017-09-25 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Mon Sep 25 14:27:37 2017
New Revision: 314158

URL: http://llvm.org/viewvc/llvm-project?rev=314158=rev
Log:
[x86] make assertions less strict in avx512f test file

I'm not sure why yet, but there may be differences depending on the host?

Modified:
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=314158=314157=314158=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Mon Sep 25 14:27:37 2017
@@ -8306,52 +8306,52 @@ __m512d test_mm512_setzero_pd()
 __mmask16 test_mm512_int2mask(int __a)
 {
   // CHECK-LABEL: test_mm512_int2mask
-  // CHECK: trunc i32 %1 to i16
+  // CHECK: trunc i32 %{{.*}} to i16
   return _mm512_int2mask(__a);
 }
 
 int test_mm512_mask2int(__mmask16 __a)
 {
   // CHECK-LABEL: test_mm512_mask2int
-  // CHECK: zext i16 %1 to i32
+  // CHECK: zext i16 %{{.*}} to i32
   return _mm512_mask2int(__a);
 }
 
 __m128 test_mm_mask_move_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
   // CHECK-LABEL: @test_mm_mask_move_ss
-  // CHECK: %vecext.i = extractelement <4 x float> %6, i32 0
-  // CHECK: %vecext1.i = extractelement <4 x float> %7, i32 0
-  // CHECK: %cond.i = phi float [ %vecext.i, %cond.true.i ], [ %vecext1.i, 
%cond.false.i ]
-  // CHECK: %vecins.i = insertelement <4 x float> %8, float %cond.i, i32 0
+  // CHECK:  extractelement <4 x float> %{{.*}}, i32 0
+  // CHECK:  extractelement <4 x float> %{{.*}}, i32 0
+  // CHECK:  phi float [ %{{.*}}, %{{.*}} ], [ %{{.*}}, %{{.*}} ]
+  // CHECK:  insertelement <4 x float> %{{.*}}, float %cond.i, i32 0
   return _mm_mask_move_ss ( __W,  __U,  __A,  __B);
 }
 
 __m128 test_mm_maskz_move_ss (__mmask8 __U, __m128 __A, __m128 __B)
 {
   // CHECK-LABEL: @test_mm_maskz_move_ss
-  // CHECK: %vecext.i = extractelement <4 x float> %5, i32 0
-  // CHECK: %cond.i = phi float [ %vecext.i, %cond.true.i ], [ 0.00e+00, 
%cond.false.i ]
-  // CHECK: %vecins.i = insertelement <4 x float> %6, float %cond.i, i32 0
+  // CHECK:  extractelement <4 x float> %{{.*}}, i32 0
+  // CHECK:  phi float [ %{{.*}}, %{{.*}} ], [ 0.00e+00, %{{.*}} ]
+  // CHECK:  insertelement <4 x float> %{{.*}}, float %{{.*}}, i32 0
   return _mm_maskz_move_ss (__U, __A, __B);
 }
 
 __m128d test_mm_mask_move_sd (__m128d __W, __mmask8 __U, __m128d __A, __m128d 
__B)
 {
   // CHECK-LABEL: @test_mm_mask_move_sd
-  // CHECK: %vecext.i = extractelement <2 x double> %6, i32 0
-  // CHECK: %vecext1.i = extractelement <2 x double> %7, i32 0
-  // CHECK: %cond.i = phi double [ %vecext.i, %cond.true.i ], [ %vecext1.i, 
%cond.false.i ]
-  // CHECK: %vecins.i = insertelement <2 x double> %8, double %cond.i, i32 0
+  // CHECK:  extractelement <2 x double> %{{.*}}, i32 0
+  // CHECK:  extractelement <2 x double> %{{.*}}, i32 0
+  // CHECK:  phi double [ %{{.*}}, %{{.*}} ], [ %{{.*}}, %{{.*}} ]
+  // CHECK:  insertelement <2 x double> %{{.*}}, double %{{.*}}, i32 0
   return _mm_mask_move_sd ( __W,  __U,  __A,  __B);
 }
 
 __m128d test_mm_maskz_move_sd (__mmask8 __U, __m128d __A, __m128d __B)
 {
   // CHECK-LABEL: @test_mm_maskz_move_sd
-  // CHECK: %vecext.i = extractelement <2 x double> %5, i32 0
-  // CHECK: %cond.i = phi double [ %vecext.i, %cond.true.i ], [ 0.00e+00, 
%cond.false.i ]
-  // CHECK: %vecins.i = insertelement <2 x double> %6, double %cond.i, i32 0
+  // CHECK:  extractelement <2 x double> %{{.*}}, i32 0
+  // CHECK:  phi double [ %{{.*}}, %{{.*}} ], [ 0.00e+00, %{{.*}} ]
+  // CHECK:  insertelement <2 x double> %6, double %cond.i, i32 0
   return _mm_maskz_move_sd (__U, __A, __B);
 }
 


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


[PATCH] D38209: [Sema] Correct nothrow inherited by noexcept

2017-09-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

In https://reviews.llvm.org/D38209#880553, @STL_MSFT wrote:

> > do you think `__declspec(nothrow)` calling the terminate handler in Clang 
> > is a bug?
>
> It's certainly a behavior difference with potential performance impact, 
> although I don't think it can be viewed as a bug, strictly speaking. MSVC 
> treats `__declspec(nothrow)` as an optimization request, with undefined 
> behavior if it's violated. Termination is definitely one of the possible 
> results of undefined behavior.
>
> We've recently had to slightly rethink our EH strategy in light of C++17's 
> addition of noexcept into the type system, and the removal of dynamic 
> exception specifications (and the change in semantics to throw()). MSVC's 
> /EHsc makes this extra fun. If you're interested, I can put you in contact 
> with the compiler dev who recently made those changes.


That might be helpful. I'm mostly interested in whether `__declspec(nothrow)` 
is intended to be part of the type system in the same way `noexcept` specifiers 
are.

@erichkeane -- can you see whether `__attribute__((nothrow))` is part of the 
type system as far as GCC is concerned (in C++17 mode, assuming GCC has 
implemented that functionality already)?


https://reviews.llvm.org/D38209



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


r314178 - Revert "[XRay][Driver] Do not link in XRay runtime in shared libs"

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 17:41:08 2017
New Revision: 314178

URL: http://llvm.org/viewvc/llvm-project?rev=314178=rev
Log:
Revert "[XRay][Driver] Do not link in XRay runtime in shared libs"

Reverts r314177.

Removed:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=314178=314177=314178=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Mon Sep 25 17:41:08 2017
@@ -206,10 +206,6 @@ void tools::gcc::Linker::RenderExtraTool
 
 static bool addXRayRuntime(const ToolChain , const ArgList ,
ArgStringList ) {
-  // Do not add the XRay runtime to shared libraries.
-  if (Args.hasArg(options::OPT_shared))
-return false;
-
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
 CmdArgs.push_back("-whole-archive");
@@ -217,7 +213,6 @@ static bool addXRayRuntime(const ToolCha
 CmdArgs.push_back("-no-whole-archive");
 return true;
   }
-
   return false;
 }
 

Removed: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314177=auto
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (removed)
@@ -1,14 +0,0 @@
-// RUN: %clangxx -shared -fPIC -o /dev/null -v -fxray-instrument %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=SHARED
-// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
-// RUN: FileCheck %s --check-prefix=STATIC
-// RUN: %clangxx -static -fPIE -o /dev/null -v -fxray-instrument %s 2>&1 \
-// RUN: -DMAIN | FileCheck %s --check-prefix=STATIC
-//
-// SHARED-NOT: {{clang_rt\.xray-}}
-// STATIC: {{clang_rt\.xray-}}
-int foo() { return 42; }
-
-#ifdef MAIN
-int main() { return foo(); }
-#endif


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


r314193 - [XRay] Run command once without piping to FileCheck

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 21:17:37 2017
New Revision: 314193

URL: http://llvm.org/viewvc/llvm-project?rev=314193=rev
Log:
[XRay] Run command once without piping to FileCheck

This allows us to debug the failures that come up from the build bots.

Follow-up to D38226.

Modified:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp

Modified: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314193=314192=314193=diff
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 21:17:37 2017
@@ -1,5 +1,7 @@
+// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s
 // RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SHARED
+// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s -DMAIN
 // RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
 // RUN: FileCheck %s --check-prefix=STATIC
 //


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


r314187 - CodeGenModule: Adapt to LLVM TargetLibraryInfo changes

2017-09-25 Thread Matthias Braun via cfe-commits
Author: matze
Date: Mon Sep 25 19:37:23 2017
New Revision: 314187

URL: http://llvm.org/viewvc/llvm-project?rev=314187=rev
Log:
CodeGenModule: Adapt to LLVM TargetLibraryInfo changes

Adapt to LLVM TargetLibraryInfo changes in r314185.

See also https://reviews.llvm.org/D38106 and https://reviews.llvm.org/D37891

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=314187=314186=314187=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Sep 25 19:37:23 2017
@@ -476,17 +476,11 @@ void CodeGenModule::Release() {
 getModule().addModuleFlag(llvm::Module::Warning, "Debug Info Version",
   llvm::DEBUG_METADATA_VERSION);
 
-  // Width of wchar_t in bytes
-  uint64_t WCharWidth =
-  Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
-  assert((LangOpts.ShortWChar ||
-  llvm::TargetLibraryInfoImpl::getTargetWCharSize(Target.getTriple()) 
==
-  Target.getWCharWidth() / 8) &&
- "LLVM wchar_t size out of sync");
-
   // We need to record the widths of enums and wchar_t, so that we can generate
   // the correct build attributes in the ARM backend. wchar_size is also used 
by
   // TargetLibraryInfo.
+  uint64_t WCharWidth =
+  Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
   getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
 
   llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();


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


r314190 - [XRay] Remove -fPIC from shared build test.

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 21:00:41 2017
New Revision: 314190

URL: http://llvm.org/viewvc/llvm-project?rev=314190=rev
Log:
[XRay] Remove -fPIC from shared build test.

Follow-up to D38226.

Modified:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp

Modified: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314190=314189=314190=diff
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 21:00:41 2017
@@ -1,4 +1,4 @@
-// RUN: %clangxx -shared -fPIC -o /dev/null -v -fxray-instrument %s 2>&1 | \
+// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SHARED
 // RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
 // RUN: FileCheck %s --check-prefix=STATIC


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


r314194 - [XRay] Avoid actual linking when testing the driver

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 21:29:25 2017
New Revision: 314194

URL: http://llvm.org/viewvc/llvm-project?rev=314194=rev
Log:
[XRay] Avoid actual linking when testing the driver

Use -### in the command to see just look for the output of -v.

Follow-up to D38226.

Modified:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp

Modified: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314194=314193=314194=diff
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 21:29:25 2017
@@ -1,9 +1,9 @@
-// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s
-// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s 2>&1 | \
+// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s -###
+// RUN: %clangxx -shared -o /dev/null -v -fxray-instrument %s -### 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SHARED
-// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s -DMAIN
-// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
-// RUN: FileCheck %s --check-prefix=STATIC
+// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s -### -DMAIN
+// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s -### 2>&1 -DMAIN 
\
+// RUN: | FileCheck %s --check-prefix=STATIC
 //
 // SHARED-NOT: {{clang_rt\.xray-}}
 // STATIC: {{clang_rt\.xray-}}


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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D38171#880016, @xazax.hun wrote:

> In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:
>
> > I feel like the current handling of the clang-tidy check aliases needs 
> > adjusting.
> >  If one enables all the checks (`Checks: '*'`), and then disables some of 
> > them
> >  on check-by-check basis, if the disabled check has aliases
> >  (`cppcoreguidelines-pro-type-vararg` vs `hicpp-vararg`, 
> > `hicpp-no-array-decay`
> >  vs `cppcoreguidelines-pro-bounds-array-to-pointer-decay` and so on)
> >  each of the aliases must be explicitly be disabled too.
>
>
> That is somewhat intentional I think. Lets imagined you are interested in 
> cppcoreguidelines but not interested in high integrity cpp. It would be great 
> to be able to use Checks: `'cppcoreguidelines*,-hicpp*'` without having to 
> worry about the aliases.
>
> In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:
>
> > If that is intentional, perhaps there could be a config option to either 
> > disable
> >  creation/registration of the check aliases altogether, or an option to 
> > threat
> >  aliases as a hard link, so anything happening to any of the aliases/base 
> > check
> >  would happen to all of them.
>
>
> I think the source of the problems is that conceptually there are two 
> distinct reasons to disable a check. One reason when the user is not 
> interested in the results regardless what is the category or name of the 
> check. In this case, all aliases should be disabled. The second is when a 
> category of checks (e.g.: a guideline) is not applicable to the code. In this 
> case aliases should not be disabled. So I think a global option would not 
> solve this issue. A better solution might be a per glob notation. So `-` 
> could mean do not disable aliases and `--` could mean disable aliases as well 
> but that is just an example.
>
> All in all, I think this is not related strictly to this issue and I think we 
> should discuss this separately on the mailing list.
>
> In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:
>
> > (Also, if the check has parameters, and one specifies different parameters 
> > for the base check, and the aliases, what happens?)
>
>
> I think this is a very good point, this needs to be documented somewhere.


A mail [0] posted by @JonasToth is about the similar problem, i think we can 
continue there.

I *think* he has a point, a some better way to setup aliases, without actually
creating aliased checks is the solution IMO. This way, there won't be any
need to disable all the aliases when completely disabling the checks, and
there won't be multiple config options for the each alias. The legacy support
is the question though.

[0] (https://lists.llvm.org/pipermail/cfe-dev/2017-September/055589.html)


https://reviews.llvm.org/D38171



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


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-25 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 116548.
Anastasia added a comment.

Addressed comments from Alexey.


https://reviews.llvm.org/D37804

Files:
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGExpr.cpp
  test/CodeGenOpenCL/vectorLoadStore.cl


Index: test/CodeGenOpenCL/vectorLoadStore.cl
===
--- test/CodeGenOpenCL/vectorLoadStore.cl
+++ test/CodeGenOpenCL/vectorLoadStore.cl
@@ -1,9 +1,22 @@
-// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 -triple "spir-unknown-unknown" %s -emit-llvm -O0 -o - | 
FileCheck %s
 
-typedef char char3 __attribute((ext_vector_type(3)));;
+typedef char char2 __attribute((ext_vector_type(2)));
+typedef char char3 __attribute((ext_vector_type(3)));
+typedef char char8 __attribute((ext_vector_type(8)));
+typedef float float4 __attribute((ext_vector_type(4)));
 
 // Check for optimized vec3 load/store which treats vec3 as vec4.
 void foo(char3 *P, char3 *Q) {
   *P = *Q;
   // CHECK: %{{.*}} = shufflevector <4 x i8> %{{.*}}, <4 x i8> undef, <3 x 
i32> 
 }
+
+// CHECK: define spir_func void @alignment()
+void alignment() {
+  __private char2 data_generic[100];
+  __private char8 data_private[100];
+
+  // CHECK: %{{.*}} = load <4 x float>, <4 x float> addrspace(4)* %{{.*}}, 
align 2
+  // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 8
+  ((private float4 *)data_private)[1] = ((float4 *)data_generic)[2];
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -925,6 +925,7 @@
 // Non-converting casts (but not C's implicit conversion from void*).
 case CK_BitCast:
 case CK_NoOp:
+case CK_AddressSpaceConversion:
   if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) {
 if (PtrTy->getPointeeType()->isVoidType())
   break;
@@ -953,8 +954,10 @@
   CodeGenFunction::CFITCK_UnrelatedCast,
   CE->getLocStart());
 }
-
-return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
+return CE->getCastKind() != CK_AddressSpaceConversion
+   ? Builder.CreateBitCast(Addr, ConvertType(E->getType()))
+   : Builder.CreateAddrSpaceCast(Addr,
+ ConvertType(E->getType()));
   }
   break;
 
Index: lib/CodeGen/CGBuilder.h
===
--- lib/CodeGen/CGBuilder.h
+++ lib/CodeGen/CGBuilder.h
@@ -145,6 +145,13 @@
Addr.getAlignment());
   }
 
+  using CGBuilderBaseTy::CreateAddrSpaceCast;
+  Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty,
+  const llvm::Twine  = "") {
+return Address(CreateAddrSpaceCast(Addr.getPointer(), Ty, Name),
+   Addr.getAlignment());
+  }
+
   /// Cast the element type of the given address to a different type,
   /// preserving information like the alignment and address space.
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,


Index: test/CodeGenOpenCL/vectorLoadStore.cl
===
--- test/CodeGenOpenCL/vectorLoadStore.cl
+++ test/CodeGenOpenCL/vectorLoadStore.cl
@@ -1,9 +1,22 @@
-// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 -triple "spir-unknown-unknown" %s -emit-llvm -O0 -o - | FileCheck %s
 
-typedef char char3 __attribute((ext_vector_type(3)));;
+typedef char char2 __attribute((ext_vector_type(2)));
+typedef char char3 __attribute((ext_vector_type(3)));
+typedef char char8 __attribute((ext_vector_type(8)));
+typedef float float4 __attribute((ext_vector_type(4)));
 
 // Check for optimized vec3 load/store which treats vec3 as vec4.
 void foo(char3 *P, char3 *Q) {
   *P = *Q;
   // CHECK: %{{.*}} = shufflevector <4 x i8> %{{.*}}, <4 x i8> undef, <3 x i32> 
 }
+
+// CHECK: define spir_func void @alignment()
+void alignment() {
+  __private char2 data_generic[100];
+  __private char8 data_private[100];
+
+  // CHECK: %{{.*}} = load <4 x float>, <4 x float> addrspace(4)* %{{.*}}, align 2
+  // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 8
+  ((private float4 *)data_private)[1] = ((float4 *)data_generic)[2];
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -925,6 +925,7 @@
 // Non-converting casts (but not C's implicit conversion from void*).
 case CK_BitCast:
 case CK_NoOp:
+case CK_AddressSpaceConversion:
   if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) {
 if (PtrTy->getPointeeType()->isVoidType())
   break;
@@ -953,8 +954,10 @@
   CodeGenFunction::CFITCK_UnrelatedCast,
   

[clang-tools-extra] r314107 - Fix clangd when built with LLVM_LINK_LLVM_DYLIB=ON

2017-09-25 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Mon Sep 25 07:08:35 2017
New Revision: 314107

URL: http://llvm.org/viewvc/llvm-project?rev=314107=rev
Log:
Fix clangd when built with LLVM_LINK_LLVM_DYLIB=ON

Reviewers: malaperle, malaperle-ericsson, bkramer

Reviewed By: bkramer

Subscribers: bkramer, mgorny, ilya-biryukov, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/CMakeLists.txt?rev=314107=314106=314107=diff
==
--- clang-tools-extra/trunk/clangd/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/tool/CMakeLists.txt Mon Sep 25 07:08:35 2017
@@ -6,6 +6,10 @@ add_clang_tool(clangd
 
 install(TARGETS clangd RUNTIME DESTINATION bin)
 
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
 target_link_libraries(clangd
   clangBasic
   clangDaemon
@@ -14,5 +18,4 @@ target_link_libraries(clangd
   clangSema
   clangTooling
   clangToolingCore
-  LLVMSupport
   )


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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:

> On a somewhat related  note, since this is already talking about aliases
>
> I feel like the current handling of the clang-tidy check aliases needs 
> adjusting.
>  If one enables all the checks (`Checks: '*'`), and then disables some of them
>  on check-by-check basis,


Clang-tidy allows doing so, but I doubt this is a use case we want to 
encourage. At least, not for a day-to-day use. Most checks require a certain 
amount of work on the target code and sometimes fine tuning of the check 
options to be useful for any real codebase. Apart from that, there are checks 
that give duplicate warnings (some are aliases and some just cover intersecting 
set of issues), and there are checks that can give conflicting advice. These 
facts don't combine well with the "enable almost all checks" use case and limit 
its area of applicability to stress-testing clang-tidy and maybe to initial 
evaluation of clang-tidy checks on a certain codebase (though going from the 
other direction and determining the set of style rules for the codebase and 
then finding which of those are implemented in clang-tidy is a more fruitful 
approach).

> if the disabled check has aliases
>  (`cppcoreguidelines-pro-type-vararg` vs `hicpp-vararg`, 
> `hicpp-no-array-decay`
>  vs `cppcoreguidelines-pro-bounds-array-to-pointer-decay` and so on)
>  each of the aliases must be explicitly be disabled too.

It seems to be the least confusing of possible options. Gabor made a good point 
why this is useful as it is.

> This is rather inconvenient.
> 
> If that is intentional, perhaps there could be a config option to either 
> disable
>  creation/registration of the check aliases altogether, or an option to threat
>  aliases as a hard link, so anything happening to any of the aliases/base 
> check
>  would happen to all of them.
> 
> (Also, if the check has parameters, and one specifies different parameters 
> for the base check, and the aliases, what happens?)




https://reviews.llvm.org/D38171



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


[PATCH] D37023: [analyzer] Fix bugreporter::getDerefExpr() again.

2017-09-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 116542.
NoQ added a comment.

@dcoughlin: You're right, my reasoning and understanding was not correct, and 
your explanation is much more clear. My code still makes sense to me though, so 
i updated the comments to match. And moved the unusual logic for the 
lvalue-to-rvalue cast unwrap to the bottom of the function.

Essentially, `getDerefExpr()` tries its best to explain where the null pointer 
comes from, on the syntactic level, by unpacking expressions that wrap the 
expression from which the pointer "originates", where "originates" is 
understood in a vague manner defined only by what the callers of this utility 
function expect to see. This leaves us with a few kinds of expressions that we 
need to unwrap, and we shouldn't touch other expressions, leaving 
pattern-matching over them to the caller.

There are other facilities that work on non-syntactic level, like your example 
where we might jump from function expression to return statement within the 
callee if the callee was inlined, or how `getNilReceiver()` function unwraps 
`ObjCMessageExpr` to the `self` pointer *iff* it `self` was `nil` during 
symbolic execution (which implies that the whole message expression is `nil`).

So that's right - lvalue-to-rvalue casts are not "the whole point", but merely 
an example of an expression kind that we do not have a right to unwrap. In 
fact, the callers still expect us to unwrap it once, but immediately stop 
afterwards. This inconsistency should probably be fixed, but `getDerefExpr` is 
used by checkers, and current code in checkers seems clean and concise enough.

I had a look at other cast kinds in `OperationKinds.def`, and all of them 
seemed as if they're worth unwrapping, apart from, of course, 
`CK_LValueToRValue`.

@xazax.hun: So, i guess, if the cast is earlier than we'd expect, then we'd 
just fail to unwrap something. So we won't find where the pointer comes from, 
and give up prematurely on our pattern-matching, while looking at roughly the 
same expression/value, plus-minus offsets. It sounds better than the case when 
the cast is //later// than we'd expect, where we may accidentally unwrap wrong 
stuff and start tracking a completely unrelated value, so i hope it shouldn't 
be a problem. Thanks for sharing the concern - the AST is huge and very few 
people possess really deep understanding of it, so any curious findings about 
it are really nice to share.


https://reviews.llvm.org/D37023

Files:
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  test/Analysis/null-deref-path-notes.m

Index: test/Analysis/null-deref-path-notes.m
===
--- test/Analysis/null-deref-path-notes.m
+++ test/Analysis/null-deref-path-notes.m
@@ -50,6 +50,23 @@
   *p = 1; // expected-warning{{Dereference of null pointer}} expected-note{{Dereference of null pointer}}
 }
 
+@interface WithArrayPtr
+- (void) useArray;
+@end
+
+@implementation WithArrayPtr {
+@public int *p;
+}
+- (void)useArray {
+  p[1] = 2; // expected-warning{{Array access (via ivar 'p') results in a null pointer dereference}}
+// expected-note@-1{{Array access (via ivar 'p') results in a null pointer dereference}}
+}
+@end
+
+void testWithArrayPtr(WithArrayPtr *w) {
+  w->p = 0; // expected-note{{Null pointer value stored to 'p'}}
+  [w useArray]; // expected-note{{Calling 'useArray'}}
+}
 
 // CHECK:  diagnostics
 // CHECK-NEXT:  
@@ -801,4 +818,227 @@
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:path
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line67
+// CHECK-NEXT:   col3
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line67
+// CHECK-NEXT:  col3
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line67
+// CHECK-NEXT:  col10
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  depth0
+// CHECK-NEXT:  extended_message
+// CHECK-NEXT:  Null pointer value stored to p
+// CHECK-NEXT:  message
+// CHECK-NEXT:  Null pointer value stored to p
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line67
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line67
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// 

[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D38171#880025, @xazax.hun wrote:

> In https://reviews.llvm.org/D38171#880022, @lebedev.ri wrote:
>
> > A mail [0] posted by @JonasToth is about the similar problem, i think we 
> > can continue there.
>
>
> Great! Could you summarize your points there as well? Thanks in advance.


Done. 

In https://reviews.llvm.org/D38171#880024, @alexfh wrote:

> In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:
>
> > On a somewhat related  note, since this is already talking about aliases
> >
> > I feel like the current handling of the clang-tidy check aliases needs 
> > adjusting.
> >  If one enables all the checks (`Checks: '*'`), and then disables some of 
> > them
> >  on check-by-check basis,
>
>
> Clang-tidy allows doing so, but I doubt this is a use case we want to 
> encourage.
>  At least, not for a day-to-day use.


It's much like clang's `-Weverything`, which is rather convenient, and is
inconveniently 'missing 
' in gcc, because the 
devs believe that there would
be complains that it results in new warnings each release, 
which is kinda the point of that flag...

> Most checks require a certain amount of work on the target code and sometimes
>  fine tuning of the check options to be useful for any real codebase. Apart 
> from that,
>  there are checks that give duplicate warnings (some are aliases and some 
> just cover
>  intersecting set of issues), and there are checks that can give conflicting 
> advice.
>  These facts don't combine well with the "enable almost all checks" use case 
> and limit
>  its area of applicability to stress-testing clang-tidy and maybe to initial 
> evaluation of
>  clang-tidy checks on a certain codebase (though going from the other 
> direction and
>  determining the set of style rules for the codebase and then finding which 
> of those
>  are implemented in clang-tidy is a more fruitful approach).

Except the disagreeing checks, same could be said about `-Weverything`, 
clang-analyzer,
etc :)   Yes, of course it does not just work, and of course needs some further 
tuning,
and of course the codebase that is being checked needs to be fixed not to warn.

I.e. the use-case is to always have all the warnings enabled, and each time a 
new check
is triggered, analyze whether it should be kept enabled, or disable it.


https://reviews.llvm.org/D38171



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


[PATCH] D38228: Fix clangd when built with LLVM_LINK_LLVM_DYLIB=ON

2017-09-25 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D38228



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


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-25 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM. Thanks!


https://reviews.llvm.org/D37804



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


[PATCH] D38225: [clangd] Fix missing "message" key when responding with unsupported method

2017-09-25 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

This looks good. Do you have commit access?


https://reviews.llvm.org/D38225



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

@leanil : Could you add a test case where the warnings are explicitly disabled 
in the compilation command and also one where only the aliased warning is 
explicitly disabled?

In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:

> I feel like the current handling of the clang-tidy check aliases needs 
> adjusting.
>  If one enables all the checks (`Checks: '*'`), and then disables some of them
>  on check-by-check basis, if the disabled check has aliases
>  (`cppcoreguidelines-pro-type-vararg` vs `hicpp-vararg`, 
> `hicpp-no-array-decay`
>  vs `cppcoreguidelines-pro-bounds-array-to-pointer-decay` and so on)
>  each of the aliases must be explicitly be disabled too.


That is somewhat intentional I think. Lets imagined you are interested in 
cppcoreguidelines but not interested in high integrity cpp. It would be great 
to be able to use Checks: `'cppcoreguidelines*,-hicpp*'` without having to 
worry about the aliases.

In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:

> If that is intentional, perhaps there could be a config option to either 
> disable
>  creation/registration of the check aliases altogether, or an option to threat
>  aliases as a hard link, so anything happening to any of the aliases/base 
> check
>  would happen to all of them.


I think the source of the problems is that conceptually there are two distinct 
reasons to disable a check. One reason when the user is not interested in the 
results regardless what is the category or name of the check. In this case, all 
aliases should be disabled. The second is when a category of checks (e.g.: a 
guideline) is not applicable to the code. In this case aliases should not be 
disabled. So I think a global option would not solve this issue. A better 
solution might be a per glob notation. So `-` could mean do not disable aliases 
and `--` could mean disable aliases as well but that is just an example.

All in all, I think this is not related strictly to this issue and I think we 
should discuss this separately on the mailing list.

In https://reviews.llvm.org/D38171#878814, @lebedev.ri wrote:

> (Also, if the check has parameters, and one specifies different parameters 
> for the base check, and the aliases, what happens?)


I think this is a very good point, this needs to be documented somewhere.


https://reviews.llvm.org/D38171



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


[PATCH] D38209: [Sema] Correct nothrow inherited by noexcept

2017-09-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm not certain we have the semantics of `__declspec(nothrow)` exactly correct 
-- a simple test shows that `__attribute__((nothrow))`, `__declspec(nothrow)`, 
and `noexcept(true)` are subtly different.

When I run this with MSVC 2017, the terminate handler is not called and the 
application continues rather than terminates, but Clang calls the terminate 
handler.

  #include 
  #include 
  
  __declspec(nothrow) void f() { throw 1; }
  
  int main() {
std::set_terminate([]() {
  std::cout << "terminate called" << std::endl;
  std::abort();
});
  
f();
  }

However, in this case terminate is called using GCC 6.3 and Clang.

  #include 
  #include 
   
  __attribute__((nothrow)) void f() { throw 1; }
   
  int main() {
std::set_terminate([]() {
  std::cout << "terminate called" << std::endl;
  std::abort();
});
   
f();
  }

For your test case: GCC accepts (with __attribute__), MSVC accepts (with 
__declspec), and EDG rejects `Derived() noexcept = default` because of 
incompatible exception specs. I think it's probably reasonable for us to accept 
despite the slight semantic differences.

@STL_MSFT -- do you think `__declspec(nothrow)` calling the terminate handler 
in Clang is a bug?




Comment at: lib/Sema/SemaDeclCXX.cpp:170
 
+  if (EST == EST_None && Method->hasAttr()) {
+EST = EST_BasicNoexcept;

Elide the braces.



Comment at: test/SemaCXX/nothrow-as-noexcept-ctor.cpp:3
+
+
+// expected-no-diagnostics

You can remove the spurious newline from the test.


https://reviews.llvm.org/D38209



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D38171#878808, @alexfh wrote:

> András, that's definitely an interesting idea. However, it might be 
> interesting to explore a more principled approach:
>
> 1. Make `clang-diagnostic-*` checks first-class citizens and take full 
> control of all diagnostics, i.e. disable all Clang diagnostics by default, 
> and enable the ones that correspond to the enabled clang-diagnostic checks.


I agree that this is a good idea. I think it could be done in this patch. But 
to be sure, could you elaborate on what do you mean by first-class citizen?

> 2. Make aliases first-class citizens (there was a proposal as well, but we 
> didn't arrive to a consensus at that time). That would include the ability to 
> configure an alias name for any check including clang-diagnostic- and 
> clang-analyzer- checks.

Do you have a link to the proposal? What do you mean by the ability to 
configure? As in having a config file or registering aliases in modules like 
now? If you mean the former, I think that is better addressed in a follow-up 
patch.

> 3. Use aliases to map clang-diagnostic- checks to check names under cert-, 
> hicpp-, etc.
> 
>   I didn't carefully consider all possible implications and there may be 
> issues with any or all of the three parts of this, but I think it's worth 
> exploring.




https://reviews.llvm.org/D38171



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


[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-09-25 Thread William Enright via Phabricator via cfe-commits
Nebiroth added a comment.

In https://reviews.llvm.org/D36150#879194, @ilya-biryukov wrote:

> Looks good.
>  Do you want me to submit this patch for you?


Yes please.


https://reviews.llvm.org/D36150



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


[PATCH] D38231: fixing a bug in mask[z]_set1

2017-09-25 Thread jina via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314102: fixing a bug in mask[z]_set1 intrinsic (authored by 
jina.nahias).

Changed prior to commit:
  https://reviews.llvm.org/D38231?vs=116513=116545#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38231

Files:
  cfe/trunk/lib/Headers/avx512vlintrin.h
  cfe/trunk/test/CodeGen/avx512vl-builtins.c


Index: cfe/trunk/lib/Headers/avx512vlintrin.h
===
--- cfe/trunk/lib/Headers/avx512vlintrin.h
+++ cfe/trunk/lib/Headers/avx512vlintrin.h
@@ -5761,15 +5761,15 @@
 _mm_mask_set1_epi64 (__m128i __O, __mmask8 __M, long long __A)
 {
   return (__m128i) __builtin_ia32_selectq_128(__M,
-  (__v2di) _mm_set1_epi8(__A),
+  (__v2di) _mm_set1_epi64x(__A),
   (__v2di) __O);
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS
 _mm_maskz_set1_epi64 (__mmask8 __M, long long __A)
 {
   return (__m128i) __builtin_ia32_selectq_128(__M,
-  (__v2di) _mm_set1_epi8(__A),
+  (__v2di) _mm_set1_epi64x(__A),
   (__v2di) _mm_setzero_si128());
 }
 
Index: cfe/trunk/test/CodeGen/avx512vl-builtins.c
===
--- cfe/trunk/test/CodeGen/avx512vl-builtins.c
+++ cfe/trunk/test/CodeGen/avx512vl-builtins.c
@@ -4563,45 +4563,17 @@
 #ifdef __x86_64__
 __m128i test_mm_mask_set1_epi64(__m128i __O, __mmask8 __M, long long __A) {
   // CHECK-LABEL: @test_mm_mask_set1_epi64
-  // CHECK: insertelement <16 x i8> undef, i8 %{{.*}}, i32 0
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 1
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 2
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 3
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 4
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 5
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 6
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 7
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 8
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 9
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 10
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 11
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 12
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 13
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 14
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 15
+  // CHECK: insertelement <2 x i64> undef, i64 %{{.*}}, i32 0
+  // CHECK: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, i32 1
   // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <2 x i32> 
   // CHECK: select <2 x i1> %{{.*}}, <2 x i64> %{{.*}}, <2 x i64> %{{.*}}
   return _mm_mask_set1_epi64(__O, __M, __A); 
 }
 
 __m128i test_mm_maskz_set1_epi64(__mmask8 __M, long long __A) {
   // CHECK-LABEL: @test_mm_maskz_set1_epi64
-  // CHECK: insertelement <16 x i8> undef, i8 %{{.*}}, i32 0
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 1
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 2
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 3
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 4
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 5
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 6
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 7
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 8
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 9
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 10
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 11
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 12
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 13
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 14
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 15
+  // CHECK: insertelement <2 x i64> undef, i64 %{{.*}}, i32 0
+  // CHECK: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, i32 1
   // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <2 x i32> 
   // CHECK: select <2 x i1> %{{.*}}, <2 x i64> %{{.*}}, <2 x i64> %{{.*}}
   return _mm_maskz_set1_epi64(__M, __A); 


Index: cfe/trunk/lib/Headers/avx512vlintrin.h
===
--- cfe/trunk/lib/Headers/avx512vlintrin.h
+++ cfe/trunk/lib/Headers/avx512vlintrin.h
@@ -5761,15 +5761,15 @@
 _mm_mask_set1_epi64 (__m128i __O, __mmask8 __M, long long __A)
 {
   return (__m128i) __builtin_ia32_selectq_128(__M,
-  (__v2di) _mm_set1_epi8(__A),
+   

r314102 - fixing a bug in mask[z]_set1 intrinsic

2017-09-25 Thread Jina Nahias via cfe-commits
Author: jina.nahias
Date: Mon Sep 25 06:38:08 2017
New Revision: 314102

URL: http://llvm.org/viewvc/llvm-project?rev=314102=rev
Log:
fixing a bug in mask[z]_set1 intrinsic

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

Change-Id: I80bbff9cbe93e4be54d8a761ef9723edf3f57c57

Modified:
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/lib/Headers/avx512vlintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlintrin.h?rev=314102=314101=314102=diff
==
--- cfe/trunk/lib/Headers/avx512vlintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512vlintrin.h Mon Sep 25 06:38:08 2017
@@ -5761,7 +5761,7 @@ static __inline__ __m128i __DEFAULT_FN_A
 _mm_mask_set1_epi64 (__m128i __O, __mmask8 __M, long long __A)
 {
   return (__m128i) __builtin_ia32_selectq_128(__M,
-  (__v2di) _mm_set1_epi8(__A),
+  (__v2di) _mm_set1_epi64x(__A),
   (__v2di) __O);
 }
 
@@ -5769,7 +5769,7 @@ static __inline__ __m128i __DEFAULT_FN_A
 _mm_maskz_set1_epi64 (__mmask8 __M, long long __A)
 {
   return (__m128i) __builtin_ia32_selectq_128(__M,
-  (__v2di) _mm_set1_epi8(__A),
+  (__v2di) _mm_set1_epi64x(__A),
   (__v2di) _mm_setzero_si128());
 }
 

Modified: cfe/trunk/test/CodeGen/avx512vl-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512vl-builtins.c?rev=314102=314101=314102=diff
==
--- cfe/trunk/test/CodeGen/avx512vl-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512vl-builtins.c Mon Sep 25 06:38:08 2017
@@ -4563,22 +4563,8 @@ __m256i test_mm256_maskz_set1_epi32(__mm
 #ifdef __x86_64__
 __m128i test_mm_mask_set1_epi64(__m128i __O, __mmask8 __M, long long __A) {
   // CHECK-LABEL: @test_mm_mask_set1_epi64
-  // CHECK: insertelement <16 x i8> undef, i8 %{{.*}}, i32 0
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 1
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 2
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 3
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 4
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 5
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 6
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 7
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 8
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 9
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 10
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 11
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 12
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 13
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 14
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 15
+  // CHECK: insertelement <2 x i64> undef, i64 %{{.*}}, i32 0
+  // CHECK: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, i32 1
   // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <2 x i32> 
   // CHECK: select <2 x i1> %{{.*}}, <2 x i64> %{{.*}}, <2 x i64> %{{.*}}
   return _mm_mask_set1_epi64(__O, __M, __A); 
@@ -4586,22 +4572,8 @@ __m128i test_mm_mask_set1_epi64(__m128i
 
 __m128i test_mm_maskz_set1_epi64(__mmask8 __M, long long __A) {
   // CHECK-LABEL: @test_mm_maskz_set1_epi64
-  // CHECK: insertelement <16 x i8> undef, i8 %{{.*}}, i32 0
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 1
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 2
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 3
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 4
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 5
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 6
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 7
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 8
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 9
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 10
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 11
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 12
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 13
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 14
-  // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 15
+  // CHECK: insertelement <2 x i64> undef, i64 %{{.*}}, i32 0
+  // CHECK: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, i32 1
   // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <2 x i32> 
   // CHECK: select <2 x i1> %{{.*}}, <2 x i64> %{{.*}}, <2 x i64> %{{.*}}
   return 

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

2017-09-25 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 116559.
Nebiroth added a comment.

Fixed inverted compile_commands check logic that made tests fail.
More readable command arg checks.


https://reviews.llvm.org/D37150

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

Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -11,16 +11,23 @@
 #include "JSONRPCDispatcher.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-
 #include 
 #include 
 #include 
 #include 
+#include 
 
 using namespace clang;
 using namespace clang::clangd;
 
+static llvm::cl::opt CompileCommandsDir(
+"compile-commands-dir",
+llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
+   "is invalid, clangd will look in the current directory and "
+   "parent paths of each source file."));
+
 static llvm::cl::opt
 WorkerThreadsCount("j",
llvm::cl::desc("Number of async workers used by clangd"),
@@ -56,18 +63,40 @@
   if (RunSynchronously)
 WorkerThreadsCount = 0;
 
+  /// Validate command line arguments.
   llvm::raw_ostream  = llvm::outs();
   llvm::raw_ostream  = llvm::errs();
   JSONOutput Out(Outs, Logs);
 
-  // Change stdin to binary to not lose \r\n on windows.
-  llvm::sys::ChangeStdinToBinary();
+  // If --compile-commands-dir arg was invoked, check value and override default
+  // path.
+  namespace path = llvm::sys::path;
+  llvm::Optional CompileCommandsDirPath;
+
+  if (CompileCommandsDir.empty())
+CompileCommandsDirPath = llvm::None;
+  else if (!llvm::sys::path::is_absolute(CompileCommandsDir)) {
+llvm::errs()
+<< "Path specified by --compile-commands-dir must be an absolute "
+   "path. The argument will be ignored.\n";
+CompileCommandsDirPath = llvm::None;
+  } else if (!llvm::sys::fs::exists(CompileCommandsDir)) {
+llvm::errs() << "Path specified by --compile-commands-dir does not exist. "
+"The argument will be "
+"ignored.\n";
+CompileCommandsDirPath = llvm::None;
+  } else
+CompileCommandsDirPath = CompileCommandsDir;
 
   llvm::Optional ResourceDirRef = None;
   if (!ResourceDir.empty())
 ResourceDirRef = ResourceDir;
 
+  /// Change stdin to binary to not lose \r\n on windows.
+  llvm::sys::ChangeStdinToBinary();
+
+  /// Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(Out, WorkerThreadsCount, EnableSnippets,
-ResourceDirRef);
+ResourceDirRef, CompileCommandsDirPath);
   LSPServer.run(std::cin);
 }
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -47,15 +47,17 @@
 class DirectoryBasedGlobalCompilationDatabase
 : public GlobalCompilationDatabase {
 public:
-  DirectoryBasedGlobalCompilationDatabase(clangd::Logger );
+  DirectoryBasedGlobalCompilationDatabase(
+  clangd::Logger , llvm::Optional NewCompileCommandsDir);
 
   std::vector
   getCompileCommands(PathRef File) override;
 
   void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
 
 private:
   tooling::CompilationDatabase *getCompilationDatabase(PathRef File);
+  tooling::CompilationDatabase *tryLoadDatabaseFromPath(PathRef File);
 
   std::mutex Mutex;
   /// Caches compilation databases loaded from directories(keys are
@@ -67,6 +69,9 @@
   llvm::StringMap ExtraFlagsForFile;
   /// Used for logging.
   clangd::Logger 
+  /// Used for command argument pointing to folder where compile_commands.json
+  /// is located.
+  llvm::Optional CompileCommandsDir;
 };
 } // namespace clangd
 } // namespace clang
Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -38,8 +38,9 @@
 }
 
 DirectoryBasedGlobalCompilationDatabase::
-DirectoryBasedGlobalCompilationDatabase(clangd::Logger )
-: Logger(Logger) {}
+DirectoryBasedGlobalCompilationDatabase(
+clangd::Logger , llvm::Optional NewCompileCommandsDir)
+: Logger(Logger), CompileCommandsDir(NewCompileCommandsDir) {}
 
 std::vector
 DirectoryBasedGlobalCompilationDatabase::getCompileCommands(PathRef File) {
@@ -67,34 +68,48 @@
 }
 
 tooling::CompilationDatabase *
-DirectoryBasedGlobalCompilationDatabase::getCompilationDatabase(PathRef File) {
-  std::lock_guard Lock(Mutex);
+DirectoryBasedGlobalCompilationDatabase::tryLoadDatabaseFromPath(PathRef File) {
 
   namespace path = llvm::sys::path;
+  auto CachedIt = 

[PATCH] D38171: Implement clang-tidy check aliases.

2017-09-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D38171#880022, @lebedev.ri wrote:

> A mail [0] posted by @JonasToth is about the similar problem, i think we can 
> continue there.


Great! Could you summarize your points there as well? Thanks in advance.


https://reviews.llvm.org/D38171



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


r314104 - [Clang] Adding missing feature to goldmont

2017-09-25 Thread Michael Zuckerman via cfe-commits
Author: mzuckerm
Date: Mon Sep 25 06:49:32 2017
New Revision: 314104

URL: http://llvm.org/viewvc/llvm-project?rev=314104=rev
Log:
[Clang] Adding missing feature to goldmont

Change-Id: I6c22478d16b8e02ce60dae2f8c80d43bc5ab3a9c

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp
cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=314104=314103=314104=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Mon Sep 25 06:49:32 2017
@@ -215,6 +215,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "xsaves", true);
 setFeatureEnabledImpl(Features, "clflushopt", true);
 setFeatureEnabledImpl(Features, "mpx", true);
+setFeatureEnabledImpl(Features, "fsgsbase", true);
 LLVM_FALLTHROUGH;
   case CK_Silvermont:
 setFeatureEnabledImpl(Features, "aes", true);

Modified: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-arch-macros.c?rev=314104=314103=314104=diff
==
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c Mon Sep 25 06:49:32 
2017
@@ -991,6 +991,7 @@
 // RUN:   | FileCheck %s -check-prefix=CHECK_GLM_M32
 // CHECK_GLM_M32: #define __AES__ 1
 // CHECK_GLM_M32: #define __CLFLUSHOPT__ 1
+// CHECK_GLM_M32: #define __FSGSBASE__ 1
 // CHECK_GLM_M32: #define __FXSR__ 1
 // CHECK_GLM_M32: #define __MMX__ 1
 // CHECK_GLM_M32: #define __MPX__ 1
@@ -1030,6 +1031,7 @@
 // RUN:   | FileCheck %s -check-prefix=CHECK_GLM_M64
 // CHECK_GLM_M64: #define __AES__ 1
 // CHECK_GLM_M64: #define __CLFLUSHOPT__ 1
+// CHECK_GLM_M64: #define __FSGSBASE__ 1
 // CHECK_GLM_M64: #define __FXSR__ 1
 // CHECK_GLM_M64: #define __MMX__ 1
 // CHECK_GLM_M64: #define __MPX__ 1


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


[PATCH] D38134: [OpenCL] Emit enqueued block as kernel

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

I think we should add a test case when the same block is both called and 
enqueued.




Comment at: lib/CodeGen/CGOpenCLRuntime.cpp:113
+
+llvm::Value *CGOpenCLRuntime::emitOpenCLEnqueuedBlock(CodeGenFunction ,
+  const Expr *E) {

yaxunl wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > I am not particularly in favour of duplicating CodeGen functionality as 
> > > > it typically has so many special cases that are hard to catch. Is this 
> > > > logic needed in order to pass to block literal information  that the 
> > > > block is enqueued?
> > > This code is needed to emit separate functions for a block which is 
> > > directly called and also enqueued as a kernel. Since the kernel needs to 
> > > have proper calling convention and ABI, it cannot be emitted as the same 
> > > function as when the block is called directly. Since it is OpenCL 
> > > specific code, I found it is cleaner to separate this code as member of 
> > > CGOpenCLRuntime instead of fitting it into CGF.EmitBlockLiteral.
> > This part is replacing standard `EmitScalarExpr` call which is doing 
> > several things before calling into block generation. That's why I am a bit 
> > worried we are covering all the corner cases here.
> > 
> > So if we transform all blocks into kernels unconditionally we won't need 
> > this special handling then?
> > 
> > Do we generate two versions of the blocks now: one for enqueue and one for 
> > call?
> If we transform all blocks into kernels, we could simplify the logic. 
> Probably will not need this special handling.
> 
> However, when the block is called directly, the first argument is a private 
> pointer, when it is executed as a kernel, the first argument is a global 
> pointer or a struct (for amdgpu target), therefore the emitted functions 
> cannot be the same.
Would using generic address space for this first argument not work?



Comment at: test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl:3
+
+// CHECK: %[[S1:struct.__amdgpu_block_arg_t.*]] = type { [3 x i64], [1 x i8] }
+// CHECK: %[[S2:struct.__amdgpu_block_arg_t.*]] = type { [5 x i64], [1 x i8] }

yaxunl wrote:
> Anastasia wrote:
> > This struct is not identical to block literal struct?
> The LLVM type of the first argument of block invoke function is created 
> directly with sorting and rearrangement. There is no AST type corresponding 
> to it. However, the function codegen requires AST type of this argument. I 
> feel it is unnecessary to create the corresponding AST type. For simplicity, 
> just create an AST type with the same size and alignment as the LLVM type. In 
> the function code, it will be bitcasted to the correct LLVM struct type and 
> get the captured variables.
So `void ptr` won't be possible here? Since it is cast to a right struct inside 
the block anyway. Once again a block is a special type object with known 
semantic to compiler and runtime in contract to kernels that can be written 
with any arbitrary type of arguments.

I just don't like the idea of duplicating the block invoke function in case 
it's being both called and enqueued. Also the login in blocks code generation 
becomes difficult to understand. So I am wondering if we could perhaps create a 
separate kernel function (as a wrapper) for enqueue_kernel which would call a 
block instead. What do you think about it? I think the kernel prototype would 
be fairly generic as it would just have a block call inside and pass the 
arguments into it... We won't need to modify block generation then at all. 


https://reviews.llvm.org/D38134



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


[PATCH] D36973: [libclang] Add support for querying cursor availability

2017-09-25 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added inline comments.



Comment at: bindings/python/tests/cindex/test_cursor.py:407
+# AvailabilityKind.DEPRECATED
+tu = get_tu('#include \n void test(char* s) { std::gets(s); }', 
lang='cpp')
+cursor = get_cursor(tu, 'gets')

It might be better to use a user-defined function that is explicitly deprecated 
rather than relying on 3rd party standard includes deprecating things for you.


https://reviews.llvm.org/D36973



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


[PATCH] D38226: [XRay][Driver] Do not link in XRay runtime in shared libs

2017-09-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good


https://reviews.llvm.org/D38226



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


[libclc] r314111 - prepare_builtins: Fix compile breakage with older LLVM

2017-09-25 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Mon Sep 25 09:04:37 2017
New Revision: 314111

URL: http://llvm.org/viewvc/llvm-project?rev=314111=rev
Log:
prepare_builtins: Fix compile breakage with older LLVM

Fixes r314050

reviewer: Tom Stellard

Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/utils/prepare-builtins.cpp

Modified: libclc/trunk/utils/prepare-builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/utils/prepare-builtins.cpp?rev=314111=314110=314111=diff
==
--- libclc/trunk/utils/prepare-builtins.cpp (original)
+++ libclc/trunk/utils/prepare-builtins.cpp Mon Sep 25 09:04:37 2017
@@ -84,8 +84,13 @@ int main(int argc, char **argv) {
   }
 
   std::error_code EC;
+#if HAVE_LLVM >= 0x0600
   std::unique_ptr Out(
   new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
+#else
+  std::unique_ptr Out(
+  new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+#endif
   if (EC) {
 errs() << EC.message() << '\n';
 exit(1);


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


[libclc] r314112 - Rework atomic ops to use clang builtins rather than llvm asm

2017-09-25 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Mon Sep 25 09:07:34 2017
New Revision: 314112

URL: http://llvm.org/viewvc/llvm-project?rev=314112=rev
Log:
Rework atomic ops to use clang builtins rather than llvm asm

reviewer: Aaron Watry

Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/lib/atomic/atomic_add.cl
libclc/trunk/generic/lib/atomic/atomic_and.cl
libclc/trunk/generic/lib/atomic/atomic_cmpxchg.cl
libclc/trunk/generic/lib/atomic/atomic_max.cl
libclc/trunk/generic/lib/atomic/atomic_min.cl
libclc/trunk/generic/lib/atomic/atomic_or.cl
libclc/trunk/generic/lib/atomic/atomic_sub.cl
libclc/trunk/generic/lib/atomic/atomic_xor.cl
Removed:
libclc/trunk/amdgpu/lib/atomic/atomic.cl
libclc/trunk/generic/lib/atomic/atomic_impl.ll
Modified:
libclc/trunk/amdgpu/lib/SOURCES
libclc/trunk/generic/lib/SOURCES
libclc/trunk/generic/lib/atomic/atomic_xchg.cl

Modified: libclc/trunk/amdgpu/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/SOURCES?rev=314112=314111=314112=diff
==
--- libclc/trunk/amdgpu/lib/SOURCES (original)
+++ libclc/trunk/amdgpu/lib/SOURCES Mon Sep 25 09:07:34 2017
@@ -1,4 +1,3 @@
-atomic/atomic.cl
 math/nextafter.cl
 math/sqrt.cl
 image/get_image_width.cl

Removed: libclc/trunk/amdgpu/lib/atomic/atomic.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/atomic/atomic.cl?rev=314111=auto
==
--- libclc/trunk/amdgpu/lib/atomic/atomic.cl (original)
+++ libclc/trunk/amdgpu/lib/atomic/atomic.cl (removed)
@@ -1,65 +0,0 @@
-#include 
-
-#define ATOMIC_FUNC_DEFINE(RET_SIGN, ARG_SIGN, TYPE, CL_FUNCTION, 
CLC_FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
-_CLC_OVERLOAD _CLC_DEF RET_SIGN TYPE CL_FUNCTION (volatile CL_ADDRSPACE 
RET_SIGN TYPE *p, RET_SIGN TYPE val) { \
-   return (RET_SIGN 
TYPE)__clc_##CLC_FUNCTION##_addr##LLVM_ADDRSPACE((volatile CL_ADDRSPACE 
ARG_SIGN TYPE*)p, (ARG_SIGN TYPE)val); \
-}
-
-/* For atomic functions that don't need different bitcode dependending on 
argument signedness */
-#define ATOMIC_FUNC_SIGN(TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
-   _CLC_DECL signed TYPE __clc_##FUNCTION##_addr##LLVM_ADDRSPACE(volatile 
CL_ADDRSPACE signed TYPE*, signed TYPE); \
-   ATOMIC_FUNC_DEFINE(signed, signed, TYPE, FUNCTION, FUNCTION, 
CL_ADDRSPACE, LLVM_ADDRSPACE) \
-   ATOMIC_FUNC_DEFINE(unsigned, signed, TYPE, FUNCTION, FUNCTION, 
CL_ADDRSPACE, LLVM_ADDRSPACE)
-
-#define ATOMIC_FUNC_ADDRSPACE(TYPE, FUNCTION) \
-   ATOMIC_FUNC_SIGN(TYPE, FUNCTION, global, 1) \
-   ATOMIC_FUNC_SIGN(TYPE, FUNCTION, local, 3)
-
-#define ATOMIC_FUNC(FUNCTION) \
-   ATOMIC_FUNC_ADDRSPACE(int, FUNCTION)
-
-#define ATOMIC_FUNC_DEFINE_3_ARG(RET_SIGN, ARG_SIGN, TYPE, CL_FUNCTION, 
CLC_FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
-_CLC_OVERLOAD _CLC_DEF RET_SIGN TYPE CL_FUNCTION (volatile CL_ADDRSPACE 
RET_SIGN TYPE *p, RET_SIGN TYPE cmp, RET_SIGN TYPE val) { \
-   return (RET_SIGN 
TYPE)__clc_##CLC_FUNCTION##_addr##LLVM_ADDRSPACE((volatile CL_ADDRSPACE 
ARG_SIGN TYPE*)p, (ARG_SIGN TYPE)cmp, (ARG_SIGN TYPE)val); \
-}
-
-/* For atomic functions that don't need different bitcode dependending on 
argument signedness */
-#define ATOMIC_FUNC_SIGN_3_ARG(TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
-   _CLC_DECL signed TYPE __clc_##FUNCTION##_addr##LLVM_ADDRSPACE(volatile 
CL_ADDRSPACE signed TYPE*, signed TYPE, signed TYPE); \
-   ATOMIC_FUNC_DEFINE_3_ARG(signed, signed, TYPE, FUNCTION, FUNCTION, 
CL_ADDRSPACE, LLVM_ADDRSPACE) \
-   ATOMIC_FUNC_DEFINE_3_ARG(unsigned, signed, TYPE, FUNCTION, FUNCTION, 
CL_ADDRSPACE, LLVM_ADDRSPACE)
-
-#define ATOMIC_FUNC_ADDRSPACE_3_ARG(TYPE, FUNCTION) \
-   ATOMIC_FUNC_SIGN_3_ARG(TYPE, FUNCTION, global, 1) \
-   ATOMIC_FUNC_SIGN_3_ARG(TYPE, FUNCTION, local, 3)
-
-#define ATOMIC_FUNC_3_ARG(FUNCTION) \
-   ATOMIC_FUNC_ADDRSPACE_3_ARG(int, FUNCTION)
-
-ATOMIC_FUNC(atomic_add)
-ATOMIC_FUNC(atomic_and)
-ATOMIC_FUNC(atomic_or)
-ATOMIC_FUNC(atomic_sub)
-ATOMIC_FUNC(atomic_xchg)
-ATOMIC_FUNC(atomic_xor)
-ATOMIC_FUNC_3_ARG(atomic_cmpxchg)
-
-_CLC_DECL signed int __clc_atomic_max_addr1(volatile global signed int*, 
signed int);
-_CLC_DECL signed int __clc_atomic_max_addr3(volatile local signed int*, signed 
int);
-_CLC_DECL uint __clc_atomic_umax_addr1(volatile global uint*, uint);
-_CLC_DECL uint __clc_atomic_umax_addr3(volatile local uint*, uint);
-
-ATOMIC_FUNC_DEFINE(signed, signed, int, atomic_max, atomic_max, global, 1)
-ATOMIC_FUNC_DEFINE(signed, signed, int, atomic_max, atomic_max, local, 3)
-ATOMIC_FUNC_DEFINE(unsigned, unsigned, int, atomic_max, atomic_umax, global, 1)
-ATOMIC_FUNC_DEFINE(unsigned, unsigned, int, atomic_max, atomic_umax, local, 3)
-
-_CLC_DECL signed int __clc_atomic_min_addr1(volatile global signed int*, 
signed int);
-_CLC_DECL signed int 

Re: r314079 - Fix implicit-fallthrough warning by adding missing break

2017-09-25 Thread David Blaikie via cfe-commits
Is there also missing test coverage here?

On Sun, Sep 24, 2017 at 8:19 AM Simon Pilgrim via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rksimon
> Date: Sun Sep 24 08:17:46 2017
> New Revision: 314079
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314079=rev
> Log:
> Fix implicit-fallthrough warning by adding missing break
>
> Modified:
> cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
>
> Modified: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp?rev=314079=314078=314079=diff
>
> ==
> --- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp (original)
> +++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp Sun Sep 24 08:17:46 2017
> @@ -185,6 +185,7 @@ void CrossTranslationUnitContext::emitCr
>case index_error_code::invalid_index_format:
>  Context.getDiagnostics().Report(diag::err_fnmap_parsing)
>  << IE.getFileName() << IE.getLineNum();
> +break;
>case index_error_code::multiple_definitions:
>  Context.getDiagnostics().Report(diag::err_multiple_def_index)
>  << IE.getLineNum();
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37822: [OpenCL] Clean up and add missing fields for block struct

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



Comment at: lib/CodeGen/CGBlocks.cpp:311
+// The header is basically 'struct { int; int; generic void *;
+// custom_fields; }'. Assert that that struct is packed.
+auto GenPtrAlign = CharUnits::fromQuantity(

remove one "that".



Comment at: lib/CodeGen/CGBlocks.cpp:312
+// custom_fields; }'. Assert that that struct is packed.
+auto GenPtrAlign = CharUnits::fromQuantity(
+CGM.getTarget().getPointerAlign(LangAS::opencl_generic) / 8);

I think the alignment might not be computed correctly now if there will be 
custom fields that might have a bigger size than a pointer? Also what happens 
if we have captures as well?



Comment at: lib/CodeGen/CGBlocks.cpp:850
+   CGM.getDataLayout().getTypeAllocSize(I->getType())),
+   "block.custom");
+  }

do we need to add numeration to each item name?



Comment at: lib/CodeGen/CGBlocks.cpp:1250
   // Function
   fields.add(blockFn);
 

If we reorder fields and put this on top we can merge the if statements above 
and below this point.


https://reviews.llvm.org/D37822



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-09-25 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[clang-tools-extra] r314119 - [clangd] Fix missing "message" key when responding with unsupported method

2017-09-25 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Sep 25 10:16:47 2017
New Revision: 314119

URL: http://llvm.org/viewvc/llvm-project?rev=314119=rev
Log:
[clangd] Fix missing "message" key when responding with unsupported method

The language server protocol dictates that a ResponseError should have a
[message string][1] describing the error. This adds a simple message to the
error and a simple test.

[1]: 
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#response-message

Patch by Raoul Wols!

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

Added:
clang-tools-extra/trunk/test/clangd/unsupported-method.test
Modified:
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=314119=314118=314119=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Mon Sep 25 10:16:47 
2017
@@ -42,7 +42,7 @@ void Handler::handleMethod(llvm::yaml::M
   // Return that this method is unsupported.
   writeMessage(
   R"({"jsonrpc":"2.0","id":)" + ID +
-  R"(,"error":{"code":-32601}})");
+  R"(,"error":{"code":-32601,"message":"method not found"}})");
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {

Added: clang-tools-extra/trunk/test/clangd/unsupported-method.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/unsupported-method.test?rev=314119=auto
==
--- clang-tools-extra/trunk/test/clangd/unsupported-method.test (added)
+++ clang-tools-extra/trunk/test/clangd/unsupported-method.test Mon Sep 25 
10:16:47 2017
@@ -0,0 +1,19 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 143
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":""}}}
+
+Content-Length: 92
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/jumpInTheAirLikeYouJustDontCare","params":{}}
+# CHECK: {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"method not 
found"}}
+
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}


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


[PATCH] D38225: [clangd] Fix missing "message" key when responding with unsupported method

2017-09-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314119: [clangd] Fix missing "message" key when responding 
with unsupported method (authored by d0k).

Repository:
  rL LLVM

https://reviews.llvm.org/D38225

Files:
  clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
  clang-tools-extra/trunk/test/clangd/unsupported-method.test


Index: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
===
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
@@ -42,7 +42,7 @@
   // Return that this method is unsupported.
   writeMessage(
   R"({"jsonrpc":"2.0","id":)" + ID +
-  R"(,"error":{"code":-32601}})");
+  R"(,"error":{"code":-32601,"message":"method not found"}})");
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
Index: clang-tools-extra/trunk/test/clangd/unsupported-method.test
===
--- clang-tools-extra/trunk/test/clangd/unsupported-method.test
+++ clang-tools-extra/trunk/test/clangd/unsupported-method.test
@@ -0,0 +1,19 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 143
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":""}}}
+
+Content-Length: 92
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/jumpInTheAirLikeYouJustDontCare","params":{}}
+# CHECK: {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"method not 
found"}}
+
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}


Index: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
===
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
@@ -42,7 +42,7 @@
   // Return that this method is unsupported.
   writeMessage(
   R"({"jsonrpc":"2.0","id":)" + ID +
-  R"(,"error":{"code":-32601}})");
+  R"(,"error":{"code":-32601,"message":"method not found"}})");
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
Index: clang-tools-extra/trunk/test/clangd/unsupported-method.test
===
--- clang-tools-extra/trunk/test/clangd/unsupported-method.test
+++ clang-tools-extra/trunk/test/clangd/unsupported-method.test
@@ -0,0 +1,19 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 143
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":""}}}
+
+Content-Length: 92
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/jumpInTheAirLikeYouJustDontCare","params":{}}
+# CHECK: {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"method not found"}}
+
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314124 - [Sema] Null check in BuildDeclarationNameExpr

2017-09-25 Thread Yi Kong via cfe-commits
Author: kongyi
Date: Mon Sep 25 10:36:54 2017
New Revision: 314124

URL: http://llvm.org/viewvc/llvm-project?rev=314124=rev
Log:
[Sema] Null check in BuildDeclarationNameExpr

Qualtype may point to null if we cannot infer its type yet.

Fixes PR33843

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

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/typo-correction-crash.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=314124=314123=314124=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 25 10:36:54 2017
@@ -2803,6 +2803,8 @@ ExprResult Sema::BuildDeclarationNameExp
 
   {
 QualType type = VD->getType();
+if (type.isNull())
+  return ExprError();
 if (auto *FPT = type->getAs()) {
   // C++ [except.spec]p17:
   //   An exception-specification is considered to be needed when:

Modified: cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-crash.cpp?rev=314124=314123=314124=diff
==
--- cfe/trunk/test/SemaCXX/typo-correction-crash.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-crash.cpp Mon Sep 25 10:36:54 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
 auto check1() {
   return 1;
   return s; // expected-error {{use of undeclared identifier 's'}}
@@ -19,3 +19,5 @@ struct FooRecord { };
 FooRecord::NestedNamespace::type x; // expected-error {{no member named 
'NestedNamespace' in 'FooRecord'; did you mean 
'BarNamespace::NestedNamespace'?}}
 
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared 
identifier 'n'}}
+
+void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error 
{{undeclared identifier '_test_'}}


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


[PATCH] D38158: [Sema] Null check in BuildDeclarationNameExpr

2017-09-25 Thread Yi Kong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314124: [Sema] Null check in BuildDeclarationNameExpr 
(authored by kongyi).

Changed prior to commit:
  https://reviews.llvm.org/D38158?vs=116279=116571#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38158

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaCXX/typo-correction-crash.cpp


Index: cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
===
--- cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
+++ cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
 auto check1() {
   return 1;
   return s; // expected-error {{use of undeclared identifier 's'}}
@@ -19,3 +19,5 @@
 FooRecord::NestedNamespace::type x; // expected-error {{no member named 
'NestedNamespace' in 'FooRecord'; did you mean 
'BarNamespace::NestedNamespace'?}}
 
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared 
identifier 'n'}}
+
+void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error 
{{undeclared identifier '_test_'}}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -2803,6 +2803,8 @@
 
   {
 QualType type = VD->getType();
+if (type.isNull())
+  return ExprError();
 if (auto *FPT = type->getAs()) {
   // C++ [except.spec]p17:
   //   An exception-specification is considered to be needed when:


Index: cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
===
--- cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
+++ cfe/trunk/test/SemaCXX/typo-correction-crash.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
 auto check1() {
   return 1;
   return s; // expected-error {{use of undeclared identifier 's'}}
@@ -19,3 +19,5 @@
 FooRecord::NestedNamespace::type x; // expected-error {{no member named 'NestedNamespace' in 'FooRecord'; did you mean 'BarNamespace::NestedNamespace'?}}
 
 void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared identifier 'n'}}
+
+void bind() { for (const auto& [test,_] : _test_) { }; } // expected-error {{undeclared identifier '_test_'}}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -2803,6 +2803,8 @@
 
   {
 QualType type = VD->getType();
+if (type.isNull())
+  return ExprError();
 if (auto *FPT = type->getAs()) {
   // C++ [except.spec]p17:
   //   An exception-specification is considered to be needed when:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38243: [clang-format] Add ext/ to google include categories

2017-09-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This adds an ext/ header include category for google style.


https://reviews.llvm.org/D38243

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314129 - [CUDA] Fix names of __nvvm_vote* intrinsics.

2017-09-25 Thread Artem Belevich via cfe-commits
Author: tra
Date: Mon Sep 25 10:55:26 2017
New Revision: 314129

URL: http://llvm.org/viewvc/llvm-project?rev=314129=rev
Log:
[CUDA] Fix names of __nvvm_vote* intrinsics.

Also fixed a syntax error in activemask().

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

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

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=314129=314128=314129=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Mon Sep 25 10:55:26 2017
@@ -170,22 +170,22 @@ inline __device__ void __barrier_sync_co
 }
 
 inline __device__ int __all_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_all(mask, pred);
+  return __nvvm_vote_all_sync(mask, pred);
 }
 
 inline __device__ int __any_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_any(mask, pred);
+  return __nvvm_vote_any_sync(mask, pred);
 }
 
 inline __device__ int __uni_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_uni(mask, pred);
+  return __nvvm_vote_uni_sync(mask, pred);
 }
 
 inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_ballot(mask, pred);
+  return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ activemask() { return __nvvm_vote.ballot(1); }
+inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
 #endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
// __CUDA_ARCH__ >= 300)


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


[PATCH] D38188: [CUDA] Fix names of __nvvm_vote* intrinsics.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D38188#880318, @jlebar wrote:

> Should we add tests to the test-suite?  Or, are these already caught by the 
> existing tests we have?


That's the plan. Once clang can compile CUDA headers, I'll add CUDA-9 specific 
tests to the testsuite and update the buildbot to compile/run tests with CUDA-9.


https://reviews.llvm.org/D38188



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


[PATCH] D38225: [clangd] Fix missing "message" key when responding with unsupported method

2017-09-25 Thread Raoul Wols via Phabricator via cfe-commits
rwols added a comment.

No, I don't have commit access. Feel free to merge.


https://reviews.llvm.org/D38225



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


[PATCH] D38188: [CUDA] Fix names of __nvvm_vote* intrinsics.

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

Should we add tests to the test-suite?  Or, are these already caught by the 
existing tests we have?


https://reviews.llvm.org/D38188



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


[PATCH] D38158: [Sema] Null check in BuildDeclarationNameExpr

2017-09-25 Thread Yi Kong via Phabricator via cfe-commits
kongyi added a comment.

ping...


Repository:
  rL LLVM

https://reviews.llvm.org/D38158



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


[PATCH] D38158: [Sema] Null check in BuildDeclarationNameExpr

2017-09-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D38158



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


[PATCH] D38188: [CUDA] Fix names of __nvvm_vote* intrinsics.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314129: [CUDA] Fix names of __nvvm_vote* intrinsics. 
(authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D38188?vs=116400=116576#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38188

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


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -170,22 +170,22 @@
 }
 
 inline __device__ int __all_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_all(mask, pred);
+  return __nvvm_vote_all_sync(mask, pred);
 }
 
 inline __device__ int __any_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_any(mask, pred);
+  return __nvvm_vote_any_sync(mask, pred);
 }
 
 inline __device__ int __uni_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_uni(mask, pred);
+  return __nvvm_vote_uni_sync(mask, pred);
 }
 
 inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_ballot(mask, pred);
+  return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ activemask() { return __nvvm_vote.ballot(1); }
+inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
 #endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
// __CUDA_ARCH__ >= 300)


Index: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
@@ -170,22 +170,22 @@
 }
 
 inline __device__ int __all_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_all(mask, pred);
+  return __nvvm_vote_all_sync(mask, pred);
 }
 
 inline __device__ int __any_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_any(mask, pred);
+  return __nvvm_vote_any_sync(mask, pred);
 }
 
 inline __device__ int __uni_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_uni(mask, pred);
+  return __nvvm_vote_uni_sync(mask, pred);
 }
 
 inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_ballot(mask, pred);
+  return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ activemask() { return __nvvm_vote.ballot(1); }
+inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
 #endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
// __CUDA_ARCH__ >= 300)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38191: [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9603
+Value *Pred = Builder.CreateSExt(Builder.CreateExtractValue(ResultPair, 1),
+ PredOutPtr.getElementType());
+Builder.CreateStore(Pred, PredOutPtr);

jlebar wrote:
> Doing sext i1 -> i32 is going to cause us to store 0 or -1 in the pred 
> (right?).  The CUDA docs say
> 
> > Predicate pred is set to true if all threads in mask have the same value of 
> > value; otherwise the predicate is set to false.
> 
> I'd guess that "true" probably means 1 (i.e. uext i1 -> i32) rather than -1, 
> although, I guess we have to check.
Right. It should've been ZExt. In similar places CUDA headers use "selp %r1, 1, 
0, %p".


https://reviews.llvm.org/D38191



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


[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-25 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

ping.


https://reviews.llvm.org/D35743



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


[PATCH] D38191: [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314135: [NVPTX] added match.{any,all}.sync instructions, 
intrinsics & builtins. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D38191?vs=116578=116584#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38191

Files:
  cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
  cfe/trunk/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/trunk/include/llvm/IR/IntrinsicsNVVM.td
  llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
  llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
  llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/trunk/test/CodeGen/NVPTX/match.ll

Index: llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
+++ llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
@@ -714,6 +714,9 @@
 return false;
   case Intrinsic::nvvm_texsurf_handle_internal:
 SelectTexSurfHandle(N);
+  case Intrinsic::nvvm_match_all_sync_i32p:
+  case Intrinsic::nvvm_match_all_sync_i64p:
+SelectMatchAll(N);
 return true;
   }
 }
@@ -726,6 +729,36 @@
 MVT::i64, GlobalVal));
 }
 
+void NVPTXDAGToDAGISel::SelectMatchAll(SDNode *N) {
+  SDLoc DL(N);
+  enum { IS_I64 = 4, HAS_CONST_VALUE = 2, HAS_CONST_MASK = 1 };
+  unsigned IID = cast(N->getOperand(0))->getZExtValue();
+  unsigned OpcodeIndex =
+  (IID == Intrinsic::nvvm_match_all_sync_i64p) ? IS_I64 : 0;
+  SDValue MaskOp = N->getOperand(1);
+  SDValue ValueOp = N->getOperand(2);
+  if (ConstantSDNode *ValueConst = dyn_cast(ValueOp)) {
+OpcodeIndex |= HAS_CONST_VALUE;
+ValueOp = CurDAG->getTargetConstant(ValueConst->getZExtValue(), DL,
+ValueConst->getValueType(0));
+  }
+  if (ConstantSDNode *MaskConst = dyn_cast(MaskOp)) {
+OpcodeIndex |= HAS_CONST_MASK;
+MaskOp = CurDAG->getTargetConstant(MaskConst->getZExtValue(), DL,
+   MaskConst->getValueType(0));
+  }
+  // Maps {IS_I64, HAS_CONST_VALUE, HAS_CONST_MASK} -> opcode
+  unsigned Opcodes[8] = {
+  NVPTX::MATCH_ALLP_SYNC_32rr, NVPTX::MATCH_ALLP_SYNC_32ri,
+  NVPTX::MATCH_ALLP_SYNC_32ir, NVPTX::MATCH_ALLP_SYNC_32ii,
+  NVPTX::MATCH_ALLP_SYNC_64rr, NVPTX::MATCH_ALLP_SYNC_64ri,
+  NVPTX::MATCH_ALLP_SYNC_64ir, NVPTX::MATCH_ALLP_SYNC_64ii};
+  SDNode *NewNode = CurDAG->getMachineNode(Opcodes[OpcodeIndex], DL,
+   {ValueOp->getValueType(0), MVT::i1},
+   {MaskOp, ValueOp});
+  ReplaceNode(N, NewNode);
+}
+
 void NVPTXDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
   SDValue Src = N->getOperand(0);
   AddrSpaceCastSDNode *CastN = cast(N);
Index: llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.td
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -158,6 +158,7 @@
 def hasPTX60 : Predicate<"Subtarget->getPTXVersion() >= 60">;
 
 def hasSM30 : Predicate<"Subtarget->getSmVersion() >= 30">;
+def hasSM70 : Predicate<"Subtarget->getSmVersion() >= 70">;
 
 def useFP16Math: Predicate<"Subtarget->allowFP16Math()">;
 
Index: llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
+++ llvm/trunk/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
@@ -58,6 +58,7 @@
   bool tryIntrinsicNoChain(SDNode *N);
   bool tryIntrinsicChain(SDNode *N);
   void SelectTexSurfHandle(SDNode *N);
+  void SelectMatchAll(SDNode *N);
   bool tryLoad(SDNode *N);
   bool tryLoadVector(SDNode *N);
   bool tryLDGLDU(SDNode *N);
Index: llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/trunk/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -247,6 +247,63 @@
 defm VOTE_SYNC_UNI : VOTE_SYNC;
 defm VOTE_SYNC_BALLOT : VOTE_SYNC;
 
+multiclass MATCH_ANY_SYNC {
+  def ii : NVPTXInst<(outs regclass:$dest), (ins i32imm:$mask, ImmOp:$value),
+  "match.any.sync." # ptxtype # " \t$dest, $value, $mask;",
+  [(set regclass:$dest, (IntOp imm:$mask, imm:$value))]>,
+   Requires<[hasPTX60, hasSM70]>;
+  def ir : NVPTXInst<(outs regclass:$dest), (ins Int32Regs:$mask, ImmOp:$value),
+  "match.any.sync." # ptxtype # " \t$dest, $value, $mask;",
+  [(set regclass:$dest, (IntOp Int32Regs:$mask, imm:$value))]>,
+   Requires<[hasPTX60, hasSM70]>;
+  def ri : NVPTXInst<(outs regclass:$dest), (ins i32imm:$mask, 

[PATCH] D37695: [clang-format] Break non-trailing comments, try 2

2017-09-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

ping


https://reviews.llvm.org/D37695



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


[PATCH] D38191: [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

2017-09-25 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:419
+TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", "ptx60")
+// These return a pair {value, predicate} which requires custom lowering.
+TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", "ptx60")

Nit, non-restrictive "which" should get a comma.  :)



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:9603
+Value *Pred = Builder.CreateSExt(Builder.CreateExtractValue(ResultPair, 1),
+ PredOutPtr.getElementType());
+Builder.CreateStore(Pred, PredOutPtr);

Doing sext i1 -> i32 is going to cause us to store 0 or -1 in the pred 
(right?).  The CUDA docs say

> Predicate pred is set to true if all threads in mask have the same value of 
> value; otherwise the predicate is set to false.

I'd guess that "true" probably means 1 (i.e. uext i1 -> i32) rather than -1, 
although, I guess we have to check.


https://reviews.llvm.org/D38191



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


[PATCH] D38191: [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 116578.
tra marked an inline comment as done.
tra added a comment.

Addressed Justin's comments.


https://reviews.llvm.org/D38191

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/__clang_cuda_intrinsics.h
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/match.ll

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -0,0 +1,117 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
+
+declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
+declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+
+; CHECK-LABEL: .func{{.*}}match.any.sync.i32
+define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i32_param_0];
+  ; CHECK: ld.param.u32 	[[VALUE:%r[0-9]+]], [match.any.sync.i32_param_1];
+
+  ; CHECK:  match.any.sync.b32  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i32(i32 %mask, i32 %value)
+  ; CHECK:  match.any.sync.b32  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i32(i32 1, i32 %value)
+  ; CHECK:  match.any.sync.b32  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i32(i32 %mask, i32 2)
+  ; CHECK:  match.any.sync.b32  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i32(i32 3, i32 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
+}
+
+; CHECK-LABEL: .func{{.*}}match.any.sync.i64
+define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
+  ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
+
+  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
+  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
+  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
+  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i64 %v0, %v1
+  %sum2 = add i64 %v2, %v3
+  %sum3 = add i64 %sum1, %sum2
+  ret i64 %sum3;
+}
+
+declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
+declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+
+; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
+define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i32p_param_0];
+  ; CHECK: ld.param.u32 	[[VALUE:%r[0-9]+]], [match.all.sync.i32p_param_1];
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 %mask, i32 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 %mask, i32 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 2, i32 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, 4, 3;
+  %r4 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 3, i32 4)
+  %v4 = extractvalue {i32, i1} %r4, 0
+  %p4 = extractvalue {i32, i1} %r4, 1
+
+  %vsum1 = add i32 %v1, %v2
+  %vsum2 = add i32 %v3, %v4
+  %vsum3 = add i32 %vsum1, %vsum2
+  %psum1 = add i1 %p1, %p2
+  %psum2 = add i1 %p3, %p4
+  %psum3 = add i1 %psum1, %psum2
+  %ret0 = insertvalue {i32, i1} undef, i32 %vsum3, 0
+  %ret1 = insertvalue {i32, i1} %ret0, i1 %psum3, 1
+  ret {i32, i1} %ret1;
+}
+
+; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
+define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
+  ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
+
+  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i64, i1} %r1, 0
+  %p1 = extractvalue {i64, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = 

r314135 - [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

2017-09-25 Thread Artem Belevich via cfe-commits
Author: tra
Date: Mon Sep 25 11:53:57 2017
New Revision: 314135

URL: http://llvm.org/viewvc/llvm-project?rev=314135=rev
Log:
[NVPTX] added match.{any,all}.sync instructions, intrinsics & builtins.

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
cfe/trunk/test/CodeGen/builtins-nvptx-ptx60.cu

Modified: cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def?rev=314135=314134=314135=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def Mon Sep 25 11:53:57 2017
@@ -413,6 +413,13 @@ TARGET_BUILTIN(__nvvm_vote_any_sync, "bU
 TARGET_BUILTIN(__nvvm_vote_uni_sync, "bUib", "", "ptx60")
 TARGET_BUILTIN(__nvvm_vote_ballot_sync, "UiUib", "", "ptx60")
 
+// Match
+TARGET_BUILTIN(__nvvm_match_any_sync_i32, "UiUiUi", "", "ptx60")
+TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", "ptx60")
+// These return a pair {value, predicate}, which requires custom lowering.
+TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", "ptx60")
+TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "WiUiWii*", "", "ptx60")
+
 // Membar
 
 BUILTIN(__nvvm_membar_cta, "v", "")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=314135=314134=314135=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Sep 25 11:53:57 2017
@@ -9589,6 +9589,21 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 {Ptr->getType()->getPointerElementType(), Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
+  case NVPTX::BI__nvvm_match_all_sync_i32p:
+  case NVPTX::BI__nvvm_match_all_sync_i64p: {
+Value *Mask = EmitScalarExpr(E->getArg(0));
+Value *Val = EmitScalarExpr(E->getArg(1));
+Address PredOutPtr = EmitPointerWithAlignment(E->getArg(2));
+Value *ResultPair = Builder.CreateCall(
+CGM.getIntrinsic(BuiltinID == NVPTX::BI__nvvm_match_all_sync_i32p
+ ? Intrinsic::nvvm_match_all_sync_i32p
+ : Intrinsic::nvvm_match_all_sync_i64p),
+{Mask, Val});
+Value *Pred = Builder.CreateZExt(Builder.CreateExtractValue(ResultPair, 1),
+ PredOutPtr.getElementType());
+Builder.CreateStore(Pred, PredOutPtr);
+return Builder.CreateExtractValue(ResultPair, 0);
+  }
   default:
 return nullptr;
   }

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=314135=314134=314135=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Mon Sep 25 11:53:57 2017
@@ -92,8 +92,9 @@ __MAKE_SHUFFLES(__shfl_xor, __nvvm_shfl_
 
 #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
 
+#if CUDA_VERSION >= 9000
+#if (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300)
 // __shfl_sync_* variants available in CUDA-9
-#if CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300)
 #pragma push_macro("__MAKE_SYNC_SHUFFLES")
 #define __MAKE_SYNC_SHUFFLES(__FnName, __IntIntrinsic, __FloatIntrinsic,   
\
  __Mask)   
\
@@ -187,8 +188,33 @@ inline __device__ unsigned int __ballot_
 
 inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
-#endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
-   // __CUDA_ARCH__ >= 300)
+#endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
+
+// Define __match* builtins CUDA-9 headers expect to see.
+#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700
+inline __device__ unsigned int __match32_any_sync(unsigned int mask,
+  unsigned int value) {
+  return __nvvm_match_any_sync_i32(mask, value);
+}
+
+inline __device__ unsigned long long
+__match64_any_sync(unsigned int mask, unsigned long long value) {
+  return __nvvm_match_any_sync_i64(mask, value);
+}
+
+inline __device__ unsigned int
+__match32_all_sync(unsigned int mask, unsigned int value, int *pred) {
+  return __nvvm_match_all_sync_i32p(mask, value, pred);
+}
+
+inline __device__ unsigned long long
+__match64_all_sync(unsigned int mask, unsigned long long value, int *pred) {
+  return __nvvm_match_all_sync_i64p(mask, value, pred);
+}
+#include "crt/sm_70_rt.hpp"
+
+#endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700
+#endif 

[PATCH] D36487: Emit section information for extern variables.

2017-09-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 116581.
eandrews added a comment.

I've modified the patch to emit a warning for re-declarations only. I also 
removed the isUsed check.


https://reviews.llvm.org/D36487

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/extern-section-attribute.cpp
  test/Sema/attr-section.c


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning 
{{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error 
{{'section' attribute only applies to functions, methods, properties, and 
global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = 
+extern int a __attribute__((section("foo,zed"))); // expected-warning 
{{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck 
%s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,16 @@
 }
   }
 
+  // This redeclaration adds a section attribute.
+  if (New->hasAttr() && !Old->hasAttr()) {
+if (auto *VD = dyn_cast(New)) {
+  if (VD->isThisDeclarationADefinition() != VarDecl::Definition) {
+Diag(New->getLocation(), 
diag::warn_attribute_section_on_redeclaration);
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }
+}
+  }
+
   if (!Old->hasAttrs())
 return;
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2436,6 +2436,12 @@
   EmitGlobalVarDefinition(D);
 }
 
+// Emit section information for extern variables.
+if (D->hasExternalStorage()) {
+  if (const SectionAttr *SA = D->getAttr())
+GV->setSection(SA->getName());
+}
+
 // Handle XCore specific ABI requirements.
 if (getTriple().getArch() == llvm::Triple::xcore &&
 D->getLanguageLinkage() == CLanguageLinkage &&
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2620,6 +2620,8 @@
   "argument to 'section' attribute is not valid for this target: %0">;
 def warn_mismatched_section : Warning<
   "section does not match previous declaration">, InGroup;
+def warn_attribute_section_on_redeclaration : Warning<
+  "section attribute is specified on redeclared variable">, InGroup;
 
 def err_anonymous_property: Error<
   "anonymous property is not supported">;


Index: test/Sema/attr-section.c
===
--- test/Sema/attr-section.c
+++ test/Sema/attr-section.c
@@ -19,3 +19,7 @@
 void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}
 
 enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}
+
+extern int a; // expected-note {{previous declaration is here}}
+int *b = 
+extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}}
Index: test/CodeGenCXX/extern-section-attribute.cpp
===
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck %s
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2607,6 +2607,16 @@
 }
   }
 
+  // This redeclaration adds a section attribute.
+  if (New->hasAttr() && !Old->hasAttr()) {
+if (auto *VD = dyn_cast(New)) {
+  if 

r314188 - [XRay][Driver] Do not link in XRay runtime in shared libs

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 20:18:11 2017
New Revision: 314188

URL: http://llvm.org/viewvc/llvm-project?rev=314188=rev
Log:
[XRay][Driver] Do not link in XRay runtime in shared libs

Summary:
This change ensures that we don't link in the XRay runtime when building
shared libraries with clang. This doesn't prevent us from building
shared libraris tht have XRay instrumentation sleds, but it does prevent
us from linking in the static XRay runtime into a shared library.

The XRay runtime currently doesn't support dynamic registration of
instrumentation sleds in shared objects, which we'll start enabling in
the future. That work has to happen in the back-end and in the runtime.

Reviewers: rnk, pelikan

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/XRay/lit.local.cfg

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=314188=314187=314188=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Mon Sep 25 20:18:11 2017
@@ -206,6 +206,10 @@ void tools::gcc::Linker::RenderExtraTool
 
 static bool addXRayRuntime(const ToolChain , const ArgList ,
ArgStringList ) {
+  // Do not add the XRay runtime to shared libraries.
+  if (Args.hasArg(options::OPT_shared))
+return false;
+
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
 CmdArgs.push_back("-whole-archive");
@@ -213,6 +217,7 @@ static bool addXRayRuntime(const ToolCha
 CmdArgs.push_back("-no-whole-archive");
 return true;
   }
+
   return false;
 }
 

Modified: cfe/trunk/test/Driver/XRay/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/lit.local.cfg?rev=314188=314187=314188=diff
==
--- cfe/trunk/test/Driver/XRay/lit.local.cfg (original)
+++ cfe/trunk/test/Driver/XRay/lit.local.cfg Mon Sep 25 20:18:11 2017
@@ -1,2 +1,21 @@
 target_triple_components = config.target_triple.split('-')
 config.available_features.update(target_triple_components)
+
+# Only run the tests in platforms where XRay instrumentation is supported.
+supported_targets = [
+'amd64', 'x86_64', 'x86_64h', 'arm', 'aarch64', 'arm64', 'powerpc64le',
+'mips', 'mipsel', 'mips64', 'mips64el'
+]
+
+# Only on platforms we support.
+supported_oses = [
+'linux'
+]
+
+triple_set = set(target_triple_components)
+if len(triple_set.intersection(supported_targets)) == 0:
+  config.unsupported = True
+
+# Do not run for 'android' despite being linux.
+if len(triple_set.intersection(supported_oses)) == 0 or 'android' in 
triple_set:
+  config.unsupported = True

Added: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314188=auto
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (added)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 20:18:11 2017
@@ -0,0 +1,16 @@
+// RUN: %clangxx -shared -fPIC -o /dev/null -v -fxray-instrument %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=SHARED
+// RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
+// RUN: FileCheck %s --check-prefix=STATIC
+// RUN: %clangxx -static -fPIE -o /dev/null -v -fxray-instrument %s 2>&1 \
+// RUN: -DMAIN | FileCheck %s --check-prefix=STATIC
+//
+// SHARED-NOT: {{clang_rt\.xray-}}
+// STATIC: {{clang_rt\.xray-}}
+//
+// REQUIRES: linux
+int foo() { return 42; }
+
+#ifdef MAIN
+int main() { return foo(); }
+#endif


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


r314189 - [XRay] Stop running tests for 'amd64', and remove -fPIE from tests.

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 20:45:37 2017
New Revision: 314189

URL: http://llvm.org/viewvc/llvm-project?rev=314189=rev
Log:
[XRay] Stop running tests for 'amd64', and remove -fPIE from tests.

Follow-up to D38226.

Modified:
cfe/trunk/test/Driver/XRay/lit.local.cfg
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp

Modified: cfe/trunk/test/Driver/XRay/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/lit.local.cfg?rev=314189=314188=314189=diff
==
--- cfe/trunk/test/Driver/XRay/lit.local.cfg (original)
+++ cfe/trunk/test/Driver/XRay/lit.local.cfg Mon Sep 25 20:45:37 2017
@@ -3,8 +3,8 @@ config.available_features.update(target_
 
 # Only run the tests in platforms where XRay instrumentation is supported.
 supported_targets = [
-'amd64', 'x86_64', 'x86_64h', 'arm', 'aarch64', 'arm64', 'powerpc64le',
-'mips', 'mipsel', 'mips64', 'mips64el'
+'x86_64', 'x86_64h', 'arm', 'aarch64', 'arm64', 'powerpc64le', 'mips',
+'mipsel', 'mips64', 'mips64el'
 ]
 
 # Only on platforms we support.

Modified: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314189=314188=314189=diff
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 20:45:37 2017
@@ -2,8 +2,6 @@
 // RUN: FileCheck %s --check-prefix=SHARED
 // RUN: %clangxx -static -o /dev/null -v -fxray-instrument %s 2>&1 -DMAIN | \
 // RUN: FileCheck %s --check-prefix=STATIC
-// RUN: %clangxx -static -fPIE -o /dev/null -v -fxray-instrument %s 2>&1 \
-// RUN: -DMAIN | FileCheck %s --check-prefix=STATIC
 //
 // SHARED-NOT: {{clang_rt\.xray-}}
 // STATIC: {{clang_rt\.xray-}}


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


r314191 - [XRay] Only run shared tests when 'enable_shared' is true

2017-09-25 Thread Dean Michael Berris via cfe-commits
Author: dberris
Date: Mon Sep 25 21:07:45 2017
New Revision: 314191

URL: http://llvm.org/viewvc/llvm-project?rev=314191=rev
Log:
[XRay] Only run shared tests when 'enable_shared' is true

Follow-up to D38226.

Modified:
cfe/trunk/test/Driver/XRay/lit.local.cfg
cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp

Modified: cfe/trunk/test/Driver/XRay/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/lit.local.cfg?rev=314191=314190=314191=diff
==
--- cfe/trunk/test/Driver/XRay/lit.local.cfg (original)
+++ cfe/trunk/test/Driver/XRay/lit.local.cfg Mon Sep 25 21:07:45 2017
@@ -19,3 +19,6 @@ if len(triple_set.intersection(supported
 # Do not run for 'android' despite being linux.
 if len(triple_set.intersection(supported_oses)) == 0 or 'android' in 
triple_set:
   config.unsupported = True
+
+if config.enable_shared:
+  config.available_features.update(['enable_shared'])

Modified: cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp?rev=314191=314190=314191=diff
==
--- cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp (original)
+++ cfe/trunk/test/Driver/XRay/xray-shared-noxray.cpp Mon Sep 25 21:07:45 2017
@@ -6,7 +6,7 @@
 // SHARED-NOT: {{clang_rt\.xray-}}
 // STATIC: {{clang_rt\.xray-}}
 //
-// REQUIRES: linux
+// REQUIRES: linux, enable_shared
 int foo() { return 42; }
 
 #ifdef MAIN


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


r314138 - [MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked

2017-09-25 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Mon Sep 25 12:24:45 2017
New Revision: 314138

URL: http://llvm.org/viewvc/llvm-project?rev=314138=rev
Log:
[MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked

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

Added:
cfe/trunk/test/Driver/mingw-msvcrt.c
Modified:
cfe/trunk/lib/Driver/ToolChains/MinGW.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MinGW.cpp?rev=314138=314137=314138=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp Mon Sep 25 12:24:45 2017
@@ -82,6 +82,9 @@ void tools::MinGW::Linker::AddLibGCC(con
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
+  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase")
+  return;
   CmdArgs.push_back("-lmsvcrt");
 }
 

Added: cfe/trunk/test/Driver/mingw-msvcrt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mingw-msvcrt.c?rev=314138=auto
==
--- cfe/trunk/test/Driver/mingw-msvcrt.c (added)
+++ cfe/trunk/test/Driver/mingw-msvcrt.c Mon Sep 25 12:24:45 2017
@@ -0,0 +1,5 @@
+// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_DEFAULT %s
+// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | 
FileCheck -check-prefix=CHECK_MSVCR120 %s
+
+// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
+// CHECK_MSVCR120: "-lmingwex" "-ladvapi32"


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


[PATCH] D37530: [MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked

2017-09-25 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314138: [MinGW] Don't link -lmsvcrt if a different msvcrt 
version is to be linked (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D37530?vs=114429=116587#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37530

Files:
  cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
  cfe/trunk/test/Driver/mingw-msvcrt.c


Index: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
@@ -82,6 +82,9 @@
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
+  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase")
+  return;
   CmdArgs.push_back("-lmsvcrt");
 }
 
Index: cfe/trunk/test/Driver/mingw-msvcrt.c
===
--- cfe/trunk/test/Driver/mingw-msvcrt.c
+++ cfe/trunk/test/Driver/mingw-msvcrt.c
@@ -0,0 +1,5 @@
+// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_DEFAULT %s
+// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | 
FileCheck -check-prefix=CHECK_MSVCR120 %s
+
+// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
+// CHECK_MSVCR120: "-lmingwex" "-ladvapi32"


Index: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
@@ -82,6 +82,9 @@
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
+  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase")
+  return;
   CmdArgs.push_back("-lmsvcrt");
 }
 
Index: cfe/trunk/test/Driver/mingw-msvcrt.c
===
--- cfe/trunk/test/Driver/mingw-msvcrt.c
+++ cfe/trunk/test/Driver/mingw-msvcrt.c
@@ -0,0 +1,5 @@
+// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s
+// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s
+
+// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
+// CHECK_MSVCR120: "-lmingwex" "-ladvapi32"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38214: [analyzer] Fix crash on modeling of pointer arithmetic

2017-09-25 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314141: [analyzer] Fix crash on modeling of pointer 
arithmetic (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D38214?vs=116455=116590#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38214

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  cfe/trunk/test/Analysis/ptr-arith.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -726,9 +726,11 @@
 if (Optional rInt = rhs.getAs()) {
   // If one of the operands is a symbol and the other is a constant,
   // build an expression for use by the constraint manager.
-  if (SymbolRef lSym = lhs.getAsLocSymbol(true))
-return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
-
+  if (SymbolRef lSym = lhs.getAsLocSymbol(true)) {
+if (BinaryOperator::isComparisonOp(op))
+  return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
+return UnknownVal();
+  }
   // Special case comparisons to NULL.
   // This must come after the test if the LHS is a symbol, which is used to
   // build constraints. The address of any non-symbolic region is 
guaranteed
Index: cfe/trunk/test/Analysis/ptr-arith.cpp
===
--- cfe/trunk/test/Analysis/ptr-arith.cpp
+++ cfe/trunk/test/Analysis/ptr-arith.cpp
@@ -111,3 +111,9 @@
   __UINTPTR_TYPE__ y = (__UINTPTR_TYPE__)p - 1;
   return y == x;
 }
+
+// Bug 34374
+bool integerAsPtrSubtractionNoCrash(char *p, __UINTPTR_TYPE__ m) {
+  auto n = p - reinterpret_cast((__UINTPTR_TYPE__)1);
+  return n == m;
+}


Index: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -726,9 +726,11 @@
 if (Optional rInt = rhs.getAs()) {
   // If one of the operands is a symbol and the other is a constant,
   // build an expression for use by the constraint manager.
-  if (SymbolRef lSym = lhs.getAsLocSymbol(true))
-return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
-
+  if (SymbolRef lSym = lhs.getAsLocSymbol(true)) {
+if (BinaryOperator::isComparisonOp(op))
+  return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
+return UnknownVal();
+  }
   // Special case comparisons to NULL.
   // This must come after the test if the LHS is a symbol, which is used to
   // build constraints. The address of any non-symbolic region is guaranteed
Index: cfe/trunk/test/Analysis/ptr-arith.cpp
===
--- cfe/trunk/test/Analysis/ptr-arith.cpp
+++ cfe/trunk/test/Analysis/ptr-arith.cpp
@@ -111,3 +111,9 @@
   __UINTPTR_TYPE__ y = (__UINTPTR_TYPE__)p - 1;
   return y == x;
 }
+
+// Bug 34374
+bool integerAsPtrSubtractionNoCrash(char *p, __UINTPTR_TYPE__ m) {
+  auto n = p - reinterpret_cast((__UINTPTR_TYPE__)1);
+  return n == m;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314141 - [analyzer] Fix crash on modeling of pointer arithmetic

2017-09-25 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Mon Sep 25 12:32:33 2017
New Revision: 314141

URL: http://llvm.org/viewvc/llvm-project?rev=314141=rev
Log:
[analyzer] Fix crash on modeling of pointer arithmetic

This patch fixes analyzer's crash on the newly added test case 
(see also https://bugs.llvm.org/show_bug.cgi?id=34374).
Pointers subtraction appears to be modeled incorrectly 
in the following example:
  char* p;
  auto n = p - reinterpret_cast((unsigned long)1);
In this case the analyzer (built without this patch) 
tries to create a symbolic value for the difference 
treating reinterpret_cast((unsigned long)1) 
as an integer, that is not correct.

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

Test plan: make check-all

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/trunk/test/Analysis/ptr-arith.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=314141=314140=314141=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Mon Sep 25 12:32:33 
2017
@@ -726,9 +726,11 @@ SVal SimpleSValBuilder::evalBinOpLL(Prog
 if (Optional rInt = rhs.getAs()) {
   // If one of the operands is a symbol and the other is a constant,
   // build an expression for use by the constraint manager.
-  if (SymbolRef lSym = lhs.getAsLocSymbol(true))
-return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
-
+  if (SymbolRef lSym = lhs.getAsLocSymbol(true)) {
+if (BinaryOperator::isComparisonOp(op))
+  return MakeSymIntVal(lSym, op, rInt->getValue(), resultTy);
+return UnknownVal();
+  }
   // Special case comparisons to NULL.
   // This must come after the test if the LHS is a symbol, which is used to
   // build constraints. The address of any non-symbolic region is 
guaranteed

Modified: cfe/trunk/test/Analysis/ptr-arith.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ptr-arith.cpp?rev=314141=314140=314141=diff
==
--- cfe/trunk/test/Analysis/ptr-arith.cpp (original)
+++ cfe/trunk/test/Analysis/ptr-arith.cpp Mon Sep 25 12:32:33 2017
@@ -111,3 +111,9 @@ bool ptrAsIntegerSubtractionNoCrash(__UI
   __UINTPTR_TYPE__ y = (__UINTPTR_TYPE__)p - 1;
   return y == x;
 }
+
+// Bug 34374
+bool integerAsPtrSubtractionNoCrash(char *p, __UINTPTR_TYPE__ m) {
+  auto n = p - reinterpret_cast((__UINTPTR_TYPE__)1);
+  return n == m;
+}


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


r314142 - Revert "[NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.", rL314135.

2017-09-25 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Mon Sep 25 12:41:56 2017
New Revision: 314142

URL: http://llvm.org/viewvc/llvm-project?rev=314142=rev
Log:
Revert "[NVPTX] added match.{any,all}.sync instructions, intrinsics & 
builtins.", rL314135.

Causing assertion failures on macos:

> Assertion failed: (Num < NumOperands && "Invalid child # of SDNode!"),
> function getOperand, file
> /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/include/llvm/CodeGen/SelectionDAGNodes.h,
> line 835.

http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/42739/testReport/LLVM/CodeGen_NVPTX/surf_read_cuda_ll/

Modified:
cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
cfe/trunk/test/CodeGen/builtins-nvptx-ptx60.cu

Modified: cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def?rev=314142=314141=314142=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsNVPTX.def Mon Sep 25 12:41:56 2017
@@ -413,13 +413,6 @@ TARGET_BUILTIN(__nvvm_vote_any_sync, "bU
 TARGET_BUILTIN(__nvvm_vote_uni_sync, "bUib", "", "ptx60")
 TARGET_BUILTIN(__nvvm_vote_ballot_sync, "UiUib", "", "ptx60")
 
-// Match
-TARGET_BUILTIN(__nvvm_match_any_sync_i32, "UiUiUi", "", "ptx60")
-TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", "ptx60")
-// These return a pair {value, predicate}, which requires custom lowering.
-TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", "ptx60")
-TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "WiUiWii*", "", "ptx60")
-
 // Membar
 
 BUILTIN(__nvvm_membar_cta, "v", "")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=314142=314141=314142=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Sep 25 12:41:56 2017
@@ -9589,21 +9589,6 @@ Value *CodeGenFunction::EmitNVPTXBuiltin
 {Ptr->getType()->getPointerElementType(), Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
-  case NVPTX::BI__nvvm_match_all_sync_i32p:
-  case NVPTX::BI__nvvm_match_all_sync_i64p: {
-Value *Mask = EmitScalarExpr(E->getArg(0));
-Value *Val = EmitScalarExpr(E->getArg(1));
-Address PredOutPtr = EmitPointerWithAlignment(E->getArg(2));
-Value *ResultPair = Builder.CreateCall(
-CGM.getIntrinsic(BuiltinID == NVPTX::BI__nvvm_match_all_sync_i32p
- ? Intrinsic::nvvm_match_all_sync_i32p
- : Intrinsic::nvvm_match_all_sync_i64p),
-{Mask, Val});
-Value *Pred = Builder.CreateZExt(Builder.CreateExtractValue(ResultPair, 1),
- PredOutPtr.getElementType());
-Builder.CreateStore(Pred, PredOutPtr);
-return Builder.CreateExtractValue(ResultPair, 0);
-  }
   default:
 return nullptr;
   }

Modified: cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h?rev=314142=314141=314142=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_intrinsics.h Mon Sep 25 12:41:56 2017
@@ -92,9 +92,8 @@ __MAKE_SHUFFLES(__shfl_xor, __nvvm_shfl_
 
 #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
 
-#if CUDA_VERSION >= 9000
-#if (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300)
 // __shfl_sync_* variants available in CUDA-9
+#if CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300)
 #pragma push_macro("__MAKE_SYNC_SHUFFLES")
 #define __MAKE_SYNC_SHUFFLES(__FnName, __IntIntrinsic, __FloatIntrinsic,   
\
  __Mask)   
\
@@ -188,33 +187,8 @@ inline __device__ unsigned int __ballot_
 
 inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
-#endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
-
-// Define __match* builtins CUDA-9 headers expect to see.
-#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700
-inline __device__ unsigned int __match32_any_sync(unsigned int mask,
-  unsigned int value) {
-  return __nvvm_match_any_sync_i32(mask, value);
-}
-
-inline __device__ unsigned long long
-__match64_any_sync(unsigned int mask, unsigned long long value) {
-  return __nvvm_match_any_sync_i64(mask, value);
-}
-
-inline __device__ unsigned int
-__match32_all_sync(unsigned int mask, unsigned int value, int *pred) {
-  return __nvvm_match_all_sync_i32p(mask, value, pred);
-}
-

[PATCH] D38247: [libunwind] Correct data types in the _Unwind_FunctionContext struct

2017-09-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.

This makes it match the definition used within llvm and in libgcc, we 
previously got the wrong layout on 64 bit.


https://reviews.llvm.org/D38247

Files:
  src/Unwind-sjlj.c


Index: src/Unwind-sjlj.c
===
--- src/Unwind-sjlj.c
+++ src/Unwind-sjlj.c
@@ -39,10 +39,10 @@
   struct _Unwind_FunctionContext *prev;
 
   // set by calling function before registering to be the landing pad
-  uintptr_t   resumeLocation;
+  uint32_tresumeLocation;
 
   // set by personality handler to be parameters passed to landing pad function
-  uintptr_t   resumeParameters[4];
+  uint32_tresumeParameters[4];
 
   // set by calling function before registering
   __personality_routine   personality; // arm offset=24


Index: src/Unwind-sjlj.c
===
--- src/Unwind-sjlj.c
+++ src/Unwind-sjlj.c
@@ -39,10 +39,10 @@
   struct _Unwind_FunctionContext *prev;
 
   // set by calling function before registering to be the landing pad
-  uintptr_t   resumeLocation;
+  uint32_tresumeLocation;
 
   // set by personality handler to be parameters passed to landing pad function
-  uintptr_t   resumeParameters[4];
+  uint32_tresumeParameters[4];
 
   // set by calling function before registering
   __personality_routine   personality; // arm offset=24
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-09-25 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Sorry for the wait!


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-09-25 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:134
+else if (I->isUnsigned())
+  OS << I->getZExtValue() << ", which is";
+else

Please print single quotes around the value.



Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:138
+
+OS << " larger or equal with the width of type '"
+   << B->getLHS()->getType().getAsString() << "'.";

"equal with the width" -> "equal to the width"


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D38249: [libunwind] Skip building unused parts when targeting SJLJ

2017-09-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
Herald added subscribers: kristof.beyls, aemerson.

When SJLJ exceptions are used, those functions aren't used.

This fixes build failures on ARM with SJLJ enabled, such as armv7/iOS.


https://reviews.llvm.org/D38249

Files:
  src/UnwindLevel1.c
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/libunwind.cpp


Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -24,6 +24,7 @@
 #include 
 
 
+#ifndef __USING_SJLJ_EXCEPTIONS__
 #include "AddressSpace.hpp"
 #include "UnwindCursor.hpp"
 
@@ -341,6 +342,7 @@
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
 
 
 
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -289,7 +289,7 @@
   movx0, #0   // return UNW_ESUCCESS
   ret
 
-#elif defined(__arm__) && !defined(__APPLE__)
+#elif defined(__arm__) && !(defined(__APPLE__) || 
defined(__USING_SJLJ_EXCEPTIONS__))
 
 #if !defined(__ARM_ARCH_ISA_ARM)
   .thumb
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -308,7 +308,7 @@
   ldpx0, x1,  [x0, #0x000]  // restore x0,x1
   retx30// jump to pc
 
-#elif defined(__arm__) && !defined(__APPLE__)
+#elif defined(__arm__) && !(defined(__APPLE__) || 
defined(__USING_SJLJ_EXCEPTIONS__))
 
 #if !defined(__ARM_ARCH_ISA_ARM)
   .thumb
Index: src/UnwindLevel1.c
===
--- src/UnwindLevel1.c
+++ src/UnwindLevel1.c
@@ -30,7 +30,7 @@
 #include "unwind.h"
 #include "config.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
 
 static _Unwind_Reason_Code
 unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception 
*exception_object) {
@@ -503,4 +503,4 @@
   unw_set_reg(cursor, UNW_REG_IP, value);
 }
 
-#endif // !defined(_LIBUNWIND_ARM_EHABI)
+#endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)


Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -24,6 +24,7 @@
 #include 
 
 
+#ifndef __USING_SJLJ_EXCEPTIONS__
 #include "AddressSpace.hpp"
 #include "UnwindCursor.hpp"
 
@@ -341,6 +342,7 @@
   DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
 
 
 
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -289,7 +289,7 @@
   movx0, #0   // return UNW_ESUCCESS
   ret
 
-#elif defined(__arm__) && !defined(__APPLE__)
+#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__))
 
 #if !defined(__ARM_ARCH_ISA_ARM)
   .thumb
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -308,7 +308,7 @@
   ldpx0, x1,  [x0, #0x000]  // restore x0,x1
   retx30// jump to pc
 
-#elif defined(__arm__) && !defined(__APPLE__)
+#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__))
 
 #if !defined(__ARM_ARCH_ISA_ARM)
   .thumb
Index: src/UnwindLevel1.c
===
--- src/UnwindLevel1.c
+++ src/UnwindLevel1.c
@@ -30,7 +30,7 @@
 #include "unwind.h"
 #include "config.h"
 
-#if !defined(_LIBUNWIND_ARM_EHABI)
+#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
 
 static _Unwind_Reason_Code
 unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
@@ -503,4 +503,4 @@
   unw_set_reg(cursor, UNW_REG_IP, value);
 }
 
-#endif // !defined(_LIBUNWIND_ARM_EHABI)
+#endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36737: [analyzer] Store design discussions in docs/analyzer for future use.

2017-09-25 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Thanks!


https://reviews.llvm.org/D36737



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


[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable

2017-09-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.

When targeting apple platforms, these functions are implemented in
Unwind_AppleExtras.cpp, but there's previously no implementation for
other platforms.

Does `__thread` have any specific runtime requirements on e.g. windows?


https://reviews.llvm.org/D38250

Files:
  src/Unwind-sjlj.c


Index: src/Unwind-sjlj.c
===
--- src/Unwind-sjlj.c
+++ src/Unwind-sjlj.c
@@ -465,4 +465,18 @@
   return 0;
 }
 
+#ifndef __APPLE__
+__thread struct _Unwind_FunctionContext *stack = NULL;
+
+_LIBUNWIND_HIDDEN
+struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+  return stack;
+}
+
+_LIBUNWIND_HIDDEN
+void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
+  stack = fc;
+}
+#endif // !defined(__APPLE__)
+
 #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS)


Index: src/Unwind-sjlj.c
===
--- src/Unwind-sjlj.c
+++ src/Unwind-sjlj.c
@@ -465,4 +465,18 @@
   return 0;
 }
 
+#ifndef __APPLE__
+__thread struct _Unwind_FunctionContext *stack = NULL;
+
+_LIBUNWIND_HIDDEN
+struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+  return stack;
+}
+
+_LIBUNWIND_HIDDEN
+void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
+  stack = fc;
+}
+#endif // !defined(__APPLE__)
+
 #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314145 - Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr" after fixing PR31620.

2017-09-25 Thread Wei Mi via cfe-commits
Author: wmi
Date: Mon Sep 25 12:57:59 2017
New Revision: 314145

URL: http://llvm.org/viewvc/llvm-project?rev=314145=rev
Log:
Reinstall the patch "Use EmitPointerWithAlignment to get alignment information 
of the pointer used in atomic expr" after fixing PR31620.

This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it 
and
will generate libcall instead of atomic op. The patch uses 
EmitPointerWithAlignment
to get the precise alignment information.

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

Added:
cfe/trunk/test/CodeGenCXX/atomic-align.cpp
Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=314145=314144=314145=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Mon Sep 25 12:57:59 2017
@@ -745,19 +745,19 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  CharUnits sizeChars, alignChars;
-  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
-  uint64_t Size = sizeChars.getQuantity();
-  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = (sizeChars != alignChars ||
- getContext().toBits(sizeChars) > MaxInlineWidthInBits);
-
   llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
 
   Address Val1 = Address::invalid();
   Address Val2 = Address::invalid();
   Address Dest = Address::invalid();
-  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+  Address Ptr = EmitPointerWithAlignment(E->getPtr());
+
+  CharUnits sizeChars, alignChars;
+  std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
+  uint64_t Size = sizeChars.getQuantity();
+  unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
+  bool UseLibcall = ((Ptr.getAlignment() % sizeChars) != 0 ||
+ getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {

Added: cfe/trunk/test/CodeGenCXX/atomic-align.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomic-align.cpp?rev=314145=auto
==
--- cfe/trunk/test/CodeGenCXX/atomic-align.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/atomic-align.cpp Mon Sep 25 12:57:59 2017
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
+
+struct AM {
+  int f1, f2;
+};
+alignas(8) AM m;
+AM load1() {
+  AM am;
+  // m is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load1v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}
+
+struct BM {
+  int f1;
+  alignas(8) AM f2;
+};
+BM bm;
+AM load2() {
+  AM am;
+  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
+  // of libcall.
+  // CHECK-LABEL: @_Z5load2v
+  // CHECK: load atomic {{.*}} monotonic
+  __atomic_load(, , 0);
+  return am;
+}


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


[PATCH] D36806: Switch to cantFail(), since it does the same assertion.

2017-09-25 Thread Stephen Hines via Phabricator via cfe-commits
srhines added a comment.

Ping.


https://reviews.llvm.org/D36806



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


r314171 - Allow specifying sanitizers in blacklists

2017-09-25 Thread Vlad Tsyrklevich via cfe-commits
Author: vlad.tsyrklevich
Date: Mon Sep 25 15:11:12 2017
New Revision: 314171

URL: http://llvm.org/viewvc/llvm-project?rev=314171=rev
Log:
Allow specifying sanitizers in blacklists

Summary:
This is the follow-up patch to D37924.

This change refactors clang to use the the newly added section headers
in SpecialCaseList to specify which sanitizers blacklists entries
should apply to, like so:

  [cfi-vcall]
  fun:*bad_vcall*
  [cfi-derived-cast|cfi-unrelated-cast]
  fun:*bad_cast*

The SanitizerSpecialCaseList class has been added to allow querying by
SanitizerMask, and SanitizerBlacklist and its downstream users have been
updated to provide that information. Old blacklists not using sections
will continue to function identically since the blacklist entries will
be placed into a '[*]' section by default matching against all
sanitizers.

Reviewers: pcc, kcc, eugenis, vsk

Reviewed By: eugenis

Subscribers: dberris, cfe-commits, mgorny

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

Added:
cfe/trunk/include/clang/Basic/SanitizerSpecialCaseList.h
cfe/trunk/lib/Basic/SanitizerSpecialCaseList.cpp
cfe/trunk/test/CodeGen/Inputs/sanitizer-special-case-list.sanitized.txt
cfe/trunk/test/CodeGen/Inputs/sanitizer-special-case-list.unsanitized1.txt
cfe/trunk/test/CodeGen/Inputs/sanitizer-special-case-list.unsanitized2.txt
cfe/trunk/test/CodeGen/Inputs/sanitizer-special-case-list.unsanitized3.txt
cfe/trunk/test/CodeGen/Inputs/sanitizer-special-case-list.unsanitized4.txt
cfe/trunk/test/CodeGen/sanitizer-special-case-list.c
Modified:
cfe/trunk/docs/ControlFlowIntegrity.rst
cfe/trunk/docs/SanitizerSpecialCaseList.rst
cfe/trunk/include/clang/Basic/SanitizerBlacklist.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Basic/CMakeLists.txt
cfe/trunk/lib/Basic/SanitizerBlacklist.cpp
cfe/trunk/lib/Basic/XRayLists.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGenCXX/cfi-blacklist.cpp

Modified: cfe/trunk/docs/ControlFlowIntegrity.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ControlFlowIntegrity.rst?rev=314171=314170=314171=diff
==
--- cfe/trunk/docs/ControlFlowIntegrity.rst (original)
+++ cfe/trunk/docs/ControlFlowIntegrity.rst Mon Sep 25 15:11:12 2017
@@ -243,17 +243,25 @@ Blacklist
 
 A :doc:`SanitizerSpecialCaseList` can be used to relax CFI checks for certain
 source files, functions and types using the ``src``, ``fun`` and ``type``
-entity types.
+entity types. Specific CFI modes can be be specified using ``[section]``
+headers.
 
 .. code-block:: bash
 
-# Suppress checking for code in a file.
+# Suppress all CFI checking for code in a file.
 src:bad_file.cpp
 src:bad_header.h
 # Ignore all functions with names containing MyFooBar.
 fun:*MyFooBar*
 # Ignore all types in the standard library.
 type:std::*
+# Disable only unrelated cast checks for this function
+[cfi-unrelated-cast]
+fun:*UnrelatedCast*
+# Disable CFI call checks for this function without affecting cast checks
+[cfi-vcall|cfi-nvcall|cfi-icall]
+fun:*BadCall*
+
 
 .. _cfi-cross-dso:
 

Modified: cfe/trunk/docs/SanitizerSpecialCaseList.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerSpecialCaseList.rst?rev=314171=314170=314171=diff
==
--- cfe/trunk/docs/SanitizerSpecialCaseList.rst (original)
+++ cfe/trunk/docs/SanitizerSpecialCaseList.rst Mon Sep 25 15:11:12 2017
@@ -51,14 +51,23 @@ Example
 Format
 ==
 
-Each line contains an entity type, followed by a colon and a regular
-expression, specifying the names of the entities, optionally followed by
-an equals sign and a tool-specific category. Empty lines and lines starting
-with "#" are ignored. The meanining of ``*`` in regular expression for entity
-names is different - it is treated as in shell wildcarding. Two generic
-entity types are ``src`` and ``fun``, which allow user to add, respectively,
-source files and functions to special case list. Some sanitizer tools may
-introduce custom entity types - refer to tool-specific docs.
+Blacklists consist of entries, optionally grouped into sections. Empty lines 
and
+lines starting with "#" are ignored.
+
+Section names are regular expressions written in square brackets that denote
+which sanitizer the following entries apply to. For example, ``[address]``
+specifies AddressSanitizer while ``[cfi-vcall|cfi-icall]`` specifies Control
+Flow Integrity virtual and indirect call checking. Entries without a section
+will be placed under the ``[*]`` section applying to all enabled sanitizers.
+
+Entries contain an entity type, followed by a 

[PATCH] D38209: [Sema] Correct nothrow inherited by noexcept

2017-09-25 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT added a comment.

> do you think `__declspec(nothrow)` calling the terminate handler in Clang is 
> a bug?

It's certainly a behavior difference with potential performance impact, 
although I don't think it can be viewed as a bug, strictly speaking. MSVC 
treats `__declspec(nothrow)` as an optimization request, with undefined 
behavior if it's violated. Termination is definitely one of the possible 
results of undefined behavior.

We've recently had to slightly rethink our EH strategy in light of C++17's 
addition of noexcept into the type system, and the removal of dynamic exception 
specifications (and the change in semantics to throw()). MSVC's /EHsc makes 
this extra fun. If you're interested, I can put you in contact with the 
compiler dev who recently made those changes.


https://reviews.llvm.org/D38209



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


[PATCH] D37903: Fix assume-filename handling in clang-format.el

2017-09-25 Thread Micah Werbitt via Phabricator via cfe-commits
werbitt reclaimed this revision.
werbitt added a comment.
This revision is now accepted and ready to land.

It looks like I just uploaded a diff against a bad branch, and I can't figure 
out how to undo it. Sorry about that.


https://reviews.llvm.org/D37903



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


[PATCH] D37903: Fix assume-filename handling in clang-format.el

2017-09-25 Thread Micah Werbitt via Phabricator via cfe-commits
werbitt updated this revision to Diff 116605.
werbitt added a comment.

Cleanup Docs

- The first line of of an emacs docstring should be a complete sentence.

-Specify that "-assume-filname" is a clang-format option


https://reviews.llvm.org/D37903

Files:
  tools/clang-format/clang-format.el


Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -119,12 +119,10 @@
   (byte-to-position (1+ byte)
 
 ;;;###autoload
-(defun clang-format-region (start end  style assume-file-name)
-  "Use clang-format to format the code between START and END according to STYLE
-using ASSUME-FILE-NAME to locate a style config file. If called interactively
-uses the region or the current statement if there is no active region. If no
-style is given uses `clang-format-style'. If no assume-file-name is given uses
-`buffer-file-name'."
+(defun clang-format-region (start end  style)
+  "Use clang-format to format the code between START and END according to 
STYLE.
+If called interactively uses the region or the current statement if there
+is no active region.  If no style is given uses `clang-format-style'."
   (interactive
(if (use-region-p)
(list (region-beginning) (region-end))
@@ -133,9 +131,6 @@
   (unless style
 (setq style clang-format-style))
 
-  (unless assume-file-name
-(setq assume-file-name buffer-file-name))
-
   (let ((file-start (clang-format--bufferpos-to-filepos start 'approximate
 'utf-8-unix))
 (file-end (clang-format--bufferpos-to-filepos end 'approximate
@@ -149,20 +144,16 @@
 ;; always use ‘utf-8-unix’ and ignore the buffer coding system.
 (default-process-coding-system '(utf-8-unix . utf-8-unix)))
 (unwind-protect
-(let ((status (apply #'call-process-region
- nil nil clang-format-executable
- nil `(,temp-buffer ,temp-file) nil
- `("-output-replacements-xml"
-   ;; Gaurd against a nil assume-file-name.
-   ;; If -assume-filename is given a blank string
-   ;; it will crash as per the following bug report
-   ;; https://bugs.llvm.org/show_bug.cgi?id=34667
-   ,@(and assume-file-name
-  (list "-assume-filename" 
assume-file-name))
-   "-style" ,style
-   "-offset" ,(number-to-string file-start)
-   "-length" ,(number-to-string (- file-end 
file-start))
-   "-cursor" ,(number-to-string cursor
+(let ((status (call-process-region
+   nil nil clang-format-executable
+   nil `(,temp-buffer ,temp-file) nil
+
+   "-output-replacements-xml"
+   "-assume-filename" (or (buffer-file-name) "")
+   "-style" style
+   "-offset" (number-to-string file-start)
+   "-length" (number-to-string (- file-end file-start))
+   "-cursor" (number-to-string cursor)))
   (stderr (with-temp-buffer
 (unless (zerop (cadr (insert-file-contents temp-file)))
   (insert ": "))
@@ -190,12 +181,10 @@
   (when (buffer-name temp-buffer) (kill-buffer temp-buffer)
 
 ;;;###autoload
-(defun clang-format-buffer ( style assume-file-name)
-  "Use clang-format to format the current buffer according to STYLE using
-ASSUME-FILE-NAME to locate a style config file. If no style is given uses
-`clang-format-style'. If no assume-file-name is given uses `buffer-file-name'."
+(defun clang-format-buffer ( style)
+  "Use clang-format to format the current buffer according to STYLE."
   (interactive)
-  (clang-format-region (point-min) (point-max) style assume-file-name))
+  (clang-format-region (point-min) (point-max) style))
 
 ;;;###autoload
 (defalias 'clang-format 'clang-format-region)


Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -119,12 +119,10 @@
   (byte-to-position (1+ byte)
 
 ;;;###autoload
-(defun clang-format-region (start end  style assume-file-name)
-  "Use clang-format to format the code between START and END according to STYLE
-using ASSUME-FILE-NAME to locate a style config file. If called interactively
-uses the region or the current statement if there is no active region. If no
-style is given uses `clang-format-style'. If no assume-file-name is given uses
-`buffer-file-name'."
+(defun clang-format-region (start end  style)
+  "Use 

r314172 - clang-format/java: Always put space after `assert` keyword.

2017-09-25 Thread Nico Weber via cfe-commits
Author: nico
Date: Mon Sep 25 15:42:49 2017
New Revision: 314172

URL: http://llvm.org/viewvc/llvm-project?rev=314172=rev
Log:
clang-format/java: Always put space after `assert` keyword.

Previously, it was missing if the expression after the assert started with a (.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=314172=314171=314172=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Sep 25 15:42:49 2017
@@ -2185,6 +2185,8 @@ bool TokenAnnotator::spaceRequiredBetwee
   const FormatToken ) {
   if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
 return true;
+  if (Left.is(Keywords.kw_assert) && Style.Language == FormatStyle::LK_Java)
+return true;
   if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
   Left.Tok.getObjCKeywordID() == tok::objc_property)
 return true;

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=314172=314171=314172=diff
==
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Mon Sep 25 15:42:49 2017
@@ -412,6 +412,7 @@ TEST_F(FormatTestJava, SynchronizedKeywo
 
 TEST_F(FormatTestJava, AssertKeyword) {
   verifyFormat("assert a && b;");
+  verifyFormat("assert (a && b);");
 }
 
 TEST_F(FormatTestJava, PackageDeclarations) {


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


[PATCH] D38188: [CUDA] Fix names of __nvvm_vote* intrinsics.

2017-09-25 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added a subscriber: sanjoy.

Also fixed a syntax error in activemask().


https://reviews.llvm.org/D38188

Files:
  clang/lib/Headers/__clang_cuda_intrinsics.h


Index: clang/lib/Headers/__clang_cuda_intrinsics.h
===
--- clang/lib/Headers/__clang_cuda_intrinsics.h
+++ clang/lib/Headers/__clang_cuda_intrinsics.h
@@ -170,22 +170,22 @@
 }
 
 inline __device__ int __all_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_all(mask, pred);
+  return __nvvm_vote_all_sync(mask, pred);
 }
 
 inline __device__ int __any_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_any(mask, pred);
+  return __nvvm_vote_any_sync(mask, pred);
 }
 
 inline __device__ int __uni_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_uni(mask, pred);
+  return __nvvm_vote_uni_sync(mask, pred);
 }
 
 inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_ballot(mask, pred);
+  return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ activemask() { return __nvvm_vote.ballot(1); }
+inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
 #endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
// __CUDA_ARCH__ >= 300)


Index: clang/lib/Headers/__clang_cuda_intrinsics.h
===
--- clang/lib/Headers/__clang_cuda_intrinsics.h
+++ clang/lib/Headers/__clang_cuda_intrinsics.h
@@ -170,22 +170,22 @@
 }
 
 inline __device__ int __all_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_all(mask, pred);
+  return __nvvm_vote_all_sync(mask, pred);
 }
 
 inline __device__ int __any_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_any(mask, pred);
+  return __nvvm_vote_any_sync(mask, pred);
 }
 
 inline __device__ int __uni_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_uni(mask, pred);
+  return __nvvm_vote_uni_sync(mask, pred);
 }
 
 inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
-  return __nvvm_vote_sync_ballot(mask, pred);
+  return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ activemask() { return __nvvm_vote.ballot(1); }
+inline __device__ unsigned int activemask() { return __nvvm_vote_ballot(1); }
 
 #endif // __CUDA_VERSION >= 9000 && (!defined(__CUDA_ARCH__) ||
// __CUDA_ARCH__ >= 300)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36589: Add support for remembering origins to ExternalASTMerger

2017-09-25 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 116405.
spyffe marked 18 inline comments as done.
spyffe added a subscriber: cfe-commits.
spyffe added a comment.

Updated to reflect Bruno's suggestions.

- Commented `ExternalASTMerger.h` extensively.
- Refactored the log into a pluggable `raw_ostream` that defaults to 
`llvm::nulls()`.
- Added comments per Bruno's requests
- Fixed some indentation
- Fixed some variable names and auto [*&] s
- Removed some commented-out code
- Cleaned up some curly braces


https://reviews.llvm.org/D36589

Files:
  include/clang/AST/ExternalASTMerger.h
  lib/AST/ExternalASTMerger.cpp
  lib/Sema/SemaType.cpp
  test/Import/extern-c-function/Inputs/F.cpp
  test/Import/extern-c-function/test.cpp
  test/Import/forward-declared-objc-class/Inputs/S1.m
  test/Import/forward-declared-objc-class/Inputs/S2.m
  test/Import/forward-declared-objc-class/Inputs/S3.m
  test/Import/forward-declared-objc-class/test.m
  test/Import/forward-declared-struct/Inputs/S3.c
  test/Import/forward-declared-struct/test.c
  test/Import/local-struct-use-origins/Inputs/Callee.cpp
  test/Import/local-struct-use-origins/test.cpp
  test/Import/local-struct/test.cpp
  test/Import/objc-definitions-in-expression/Inputs/S.m
  test/Import/objc-definitions-in-expression/test.m
  test/Import/struct-and-var/Inputs/S1.cpp
  test/Import/struct-and-var/Inputs/S2.cpp
  test/Import/struct-and-var/test.cpp
  test/Import/template/Inputs/T.cpp
  test/Import/template/test.cpp
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ tools/clang-import-test/clang-import-test.cpp
@@ -48,8 +48,12 @@
 
 static llvm::cl::opt
 Direct("direct", llvm::cl::Optional,
- llvm::cl::desc("Use the parsed declarations without indirection"));
+   llvm::cl::desc("Use the parsed declarations without indirection"));
 
+static llvm::cl::opt
+UseOrigins("use-origins", llvm::cl::Optional,
+   llvm::cl::desc("Use DeclContext origin information for more accurate lookups"));  
+
 static llvm::cl::list
 ClangArgs("Xcc", llvm::cl::ZeroOrMore,
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
@@ -60,13 +64,11 @@
   llvm::cl::desc("The language to parse (default: c++)"),
   llvm::cl::init("c++"));
 
-static llvm::cl::opt
-DumpAST("dump-ast", llvm::cl::init(false),
-llvm::cl::desc("Dump combined AST"));
+static llvm::cl::opt DumpAST("dump-ast", llvm::cl::init(false),
+   llvm::cl::desc("Dump combined AST"));
 
-static llvm::cl::opt
-DumpIR("dump-ir", llvm::cl::init(false),
-llvm::cl::desc("Dump IR from final parse"));
+static llvm::cl::opt DumpIR("dump-ir", llvm::cl::init(false),
+  llvm::cl::desc("Dump IR from final parse"));
 
 namespace init_convenience {
 class TestDiagnosticConsumer : public DiagnosticConsumer {
@@ -154,8 +156,7 @@
   }
 };
 
-std::unique_ptr
-BuildCompilerInstance() {
+std::unique_ptr BuildCompilerInstance() {
   auto Ins = llvm::make_unique();
   auto DC = llvm::make_unique();
   const bool ShouldOwnClient = true;
@@ -227,29 +228,48 @@
 } // end namespace
 
 namespace {
- 
-void AddExternalSource(
-CompilerInstance ,
-llvm::ArrayRef Imports) {
-  ExternalASTMerger::ImporterEndpoint Target({CI.getASTContext(), CI.getFileManager()});
-  llvm::SmallVector Sources;
-  for (const std::unique_ptr  : Imports) {
-Sources.push_back({CI->getASTContext(), CI->getFileManager()});
+
+struct CIAndOrigins {
+  using OriginMap = clang::ExternalASTMerger::OriginMap;
+  std::unique_ptr CI;
+
+  ASTContext () { return CI->getASTContext(); }
+  FileManager () { return CI->getFileManager(); }
+  const OriginMap () {
+static const OriginMap EmptyOriginMap;
+if (ExternalASTSource *Source = CI->getASTContext().getExternalSource())
+  return static_cast(Source)->GetOrigins();
+else
+  return EmptyOriginMap;
   }
+  DiagnosticConsumer () {
+return CI->getDiagnosticClient();
+  }
+  CompilerInstance () { return *CI; }
+};
+
+void AddExternalSource(CIAndOrigins ,
+   llvm::MutableArrayRef Imports) {
+  ExternalASTMerger::ImporterTarget Target(
+  {CI.getASTContext(), CI.getFileManager()});
+  llvm::SmallVector Sources;
+  for (CIAndOrigins  : Imports) {
+Sources.push_back(
+{Import.getASTContext(), Import.getFileManager(), Import.getOriginMap()});
+  }
   auto ES = llvm::make_unique(Target, Sources);
   CI.getASTContext().setExternalSource(ES.release());
   CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();
 }
 
-std::unique_ptr BuildIndirect(std::unique_ptr ) {
-  std::unique_ptr IndirectCI =
-  init_convenience::BuildCompilerInstance();
+CIAndOrigins 

[PATCH] D36150: [clangd] LSP extension to switch between source/header file

2017-09-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

Looks good.
Do you want me to submit this patch for you?


https://reviews.llvm.org/D36150



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


[PATCH] D38191: [NVPTX] added match.{any, all}.sync instructions, intrinsics & builtins.

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

https://reviews.llvm.org/D38191

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/__clang_cuda_intrinsics.h
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/match.ll

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -0,0 +1,117 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
+
+declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
+declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+
+; CHECK-LABEL: .func{{.*}}match.any.sync.i32
+define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i32_param_0];
+  ; CHECK: ld.param.u32 	[[VALUE:%r[0-9]+]], [match.any.sync.i32_param_1];
+
+  ; CHECK:  match.any.sync.b32  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i32(i32 %mask, i32 %value)
+  ; CHECK:  match.any.sync.b32  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i32(i32 1, i32 %value)
+  ; CHECK:  match.any.sync.b32  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i32(i32 %mask, i32 2)
+  ; CHECK:  match.any.sync.b32  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i32(i32 3, i32 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
+}
+
+; CHECK-LABEL: .func{{.*}}match.any.sync.i64
+define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
+  ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
+
+  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
+  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
+  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
+  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i64 %v0, %v1
+  %sum2 = add i64 %v2, %v3
+  %sum3 = add i64 %sum1, %sum2
+  ret i64 %sum3;
+}
+
+declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
+declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+
+; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
+define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i32p_param_0];
+  ; CHECK: ld.param.u32 	[[VALUE:%r[0-9]+]], [match.all.sync.i32p_param_1];
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 %mask, i32 %value)
+  %v1 = extractvalue {i32, i1} %r1, 0
+  %p1 = extractvalue {i32, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 %mask, i32 1)
+  %v2 = extractvalue {i32, i1} %r2, 0
+  %p2 = extractvalue {i32, i1} %r2, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, [[VALUE]], 2;
+  %r3 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 2, i32 %value)
+  %v3 = extractvalue {i32, i1} %r3, 0
+  %p3 = extractvalue {i32, i1} %r3, 1
+
+  ; CHECK:  match.all.sync.b32 {{%r[0-9]+\|%p[0-9]+}}, 4, 3;
+  %r4 = call {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32 3, i32 4)
+  %v4 = extractvalue {i32, i1} %r4, 0
+  %p4 = extractvalue {i32, i1} %r4, 1
+
+  %vsum1 = add i32 %v1, %v2
+  %vsum2 = add i32 %v3, %v4
+  %vsum3 = add i32 %vsum1, %vsum2
+  %psum1 = add i1 %p1, %p2
+  %psum2 = add i1 %p3, %p4
+  %psum3 = add i1 %psum1, %psum2
+  %ret0 = insertvalue {i32, i1} undef, i32 %vsum3, 0
+  %ret1 = insertvalue {i32, i1} %ret0, i1 %psum3, 1
+  ret {i32, i1} %ret1;
+}
+
+; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
+define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+  ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
+  ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.all.sync.i64p_param_1];
+
+  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, [[VALUE]], [[MASK]];
+  %r1 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 %value)
+  %v1 = extractvalue {i64, i1} %r1, 0
+  %p1 = extractvalue {i64, i1} %r1, 1
+
+  ; CHECK:  match.all.sync.b64 {{%rd[0-9]+\|%p[0-9]+}}, 1, [[MASK]];
+  %r2 = call {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32 %mask, i64 1)
+  %v2 = extractvalue {i64, i1} %r2, 0
+  %p2 = extractvalue 

[PATCH] D38113: OpenCL: Assume functions are convergent

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

Do we need an option to disable this? In case it causes regression in some 
applications and users want to disable it. At least for debugging.




Comment at: test/CodeGenOpenCL/convergent.cl:73
 // CHECK:  %[[tobool_pr:.+]] = phi i1 [ true, %[[if_then]] ], [ false, %{{.+}} 
]
-// CHECK:  tail call spir_func void @convfun() #[[attr5:.+]]
+// CHECK:  tail call spir_func void @convfun() #[[attr4:.+]]
 // CHECK:  br i1 %[[tobool_pr]], label %[[if_then2:.+]], label %[[if_end3:.+]]

check the attribute has convergent



Comment at: test/CodeGenOpenCL/convergent.cl:95
+// CHECK-LABEL: define spir_func void @test_unroll() local_unnamed_addr #1
+// CHECK:  tail call spir_func void @convfun() #[[attr4:[0-9]+]]
+// CHECK:  tail call spir_func void @convfun() #[[attr4]]

need to check the attribute is convergent



Comment at: test/CodeGenOpenCL/convergent.cl:118
 // CHECK: [[for_body]]:
-// CHECK:  tail call spir_func void @nodupfun() #[[attr6:[0-9]+]]
+// CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()

need to check the attribute has noduplicate



Comment at: test/CodeGenOpenCL/convergent.cl:127
 
 // CHECK: declare spir_func void @nodupfun(){{[^#]*}} #[[attr3:[0-9]+]]
 

check the attribute has noduplicate


https://reviews.llvm.org/D38113



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


[PATCH] D38040: [OpenMP] Add an additional test for D34888

2017-09-25 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In https://reviews.llvm.org/D38040#878799, @Hahnfeld wrote:

> In https://reviews.llvm.org/D38040#878441, @gtbercea wrote:
>
> > The test is verifying whether the parameter is passed to the kernel 
> > correctly. I believe it was not passed as a reference before the patch.
>
>
> Ah, right: This isn't checked anywhere before. Maybe add a comment about 
> what's tested here?
>  Do we want to check the rest of the codegen with a focus that the variable 
> is passed as a reference?
>
> > In addition to that, something that was in my previous patch is related to 
> > this code:
> > 
> >   DSAStack->checkMappableExprComponentListsForDeclAtLevel(
> >   D, Level, 
> > [&](OMPClauseMappableExprCommon::MappableExprComponentListRef
> > 
> > 
> > In particular with the Level variable. Should the Level variable actually 
> > be Level + 1 in this case?
>
> I'm not sure, the current public `clang-ykt` has `Level`:  
> https://github.com/clang-ykt/clang/blob/d181aed/lib/Sema/SemaOpenMP.cpp#L1361


You're right!


Repository:
  rL LLVM

https://reviews.llvm.org/D38040



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


[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I wonder whether this feature really pulls its weight compared to using `@file` 
and prepending `-fmodule-file=` to each line.

The big difference between this patch and an `@file` seems to be the filtering 
by prefix / storing this information as a subset of the data in a file. Can you 
say a bit more about how you're envisioning this integrating into build 
systems, such that that would be a natural way to model this mapping?


https://reviews.llvm.org/D37299



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


[PATCH] D38202: Add Documentation to attribute-nothrow. Additionally, limit to functions.

2017-09-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
Herald added a subscriber: javed.absar.

Attribute nothrow is only allowed on functions, so I added that.  Additionally,
it lacks any documentation, so I added some.  Please wordsmith!


https://reviews.llvm.org/D38202

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  test/Misc/pragma-attribute-supported-attributes-list.test


Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 64 attributes:
+// CHECK: #pragma clang attribute supports 65 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -39,6 +39,7 @@
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, 
SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSplitStack (SubjectMatchRule_function)
+// CHECK-NEXT: NoThrow (SubjectMatchRule_function)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: ObjCBoxable (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2686,6 +2686,17 @@
   }];
 }
 
+def NoThrowDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the GNU style ``__attribute__((nothrow))`` attribute as an
+equivilent of `noexcept` on function declarations. This attribute informs the
+compiler that the annotated function does cannot throw an exception. This
+prevents exception-unwinding. This attribute is particularly useful on 
functions
+in the C Standard Library that are guaranteed to not throw an exception.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1431,7 +1431,8 @@
 
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
-  let Documentation = [Undocumented];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoThrowDocs];
 }
 
 def NvWeak : IgnoredAttr {


Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 64 attributes:
+// CHECK: #pragma clang attribute supports 65 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -39,6 +39,7 @@
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSplitStack (SubjectMatchRule_function)
+// CHECK-NEXT: NoThrow (SubjectMatchRule_function)
 // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
 // CHECK-NEXT: ObjCBoxable (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2686,6 +2686,17 @@
   }];
 }
 
+def NoThrowDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the GNU style ``__attribute__((nothrow))`` attribute as an
+equivilent of `noexcept` on function declarations. This attribute informs the
+compiler that the annotated function does cannot throw an exception. This
+prevents exception-unwinding. This attribute is particularly useful on functions
+in the C Standard Library that are guaranteed to not throw an exception.
+}];
+}
+
 def InternalLinkageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1431,7 +1431,8 @@
 
 def NoThrow : InheritableAttr {
   let Spellings = 

[PATCH] D38203: [Sema] Corrected the warn-on-throw-from-noexcept behavior to include nothrow

2017-09-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

Discovered that 'nothrow' (which is supposed to be an alias for noexcept)
was not warning with a throw inside of it.  This patch corrects the behavior
previously created to add 'nothrow' to this list.


https://reviews.llvm.org/D38203

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -14,6 +14,12 @@
   ~R_ShouldDiag() { // expected-note  {{destructor has a implicit non-throwing 
exception specification}}
 throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
   }
+  __attribute__((nothrow)) R_ShouldDiag() {// expected-note {{function 
declared non-throwing here}}
+throw 1;// expected-warning {{has a non-throwing exception specification 
but}}
+  }
+  void __attribute__((nothrow)) SomeThrow() {// expected-note {{function 
declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+  }
 };
 
 struct M_ShouldNotDiag {
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -426,7 +426,7 @@
 
 static bool isNoexcept(const FunctionDecl *FD) {
   const auto *FPT = FD->getType()->castAs();
-  if (FPT->isNothrow(FD->getASTContext()))
+  if (FPT->isNothrow(FD->getASTContext()) || FD->hasAttr())
 return true;
   return false;
 }


Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -14,6 +14,12 @@
   ~R_ShouldDiag() { // expected-note  {{destructor has a implicit non-throwing exception specification}}
 throw 1; // expected-warning {{has a non-throwing exception specification but}}
   }
+  __attribute__((nothrow)) R_ShouldDiag() {// expected-note {{function declared non-throwing here}}
+throw 1;// expected-warning {{has a non-throwing exception specification but}}
+  }
+  void __attribute__((nothrow)) SomeThrow() {// expected-note {{function declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
 };
 
 struct M_ShouldNotDiag {
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -426,7 +426,7 @@
 
 static bool isNoexcept(const FunctionDecl *FD) {
   const auto *FPT = FD->getType()->castAs();
-  if (FPT->isNothrow(FD->getASTContext()))
+  if (FPT->isNothrow(FD->getASTContext()) || FD->hasAttr())
 return true;
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38205: [Sema] Warn on attribute nothrow conflicting with language specifiers

2017-09-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

I discovered it was possible to create a 'nothrow' noexcept(false)
function, which is both non-sensical as well as seemingly breaking.

This patch warns if attribute nothrow is used with anything besides "noexcept".

"noexcept(true)" isn't possible, because the noexcept decl isn't parsed until
later.


https://reviews.llvm.org/D38205

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp


Index: test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify 
-std=c++14
+
+struct S {
+  __attribute__((nothrow)) S() noexcept(true); 
+  __attribute__((nothrow)) void Func1() noexcept(false);
+  __attribute__((nothrow)) void Func2() throws();
+  __attribute__((nothrow)) void Func3() noexcept;
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1969,6 +1969,25 @@
   attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNoThrowAttr(Sema , Decl *D, const AttributeList ) {
+  assert(isa(D) && "attribute nothrow only valid on functions");
+
+  auto *FD = cast(D);
+  const auto *FPT = FD->getType()->getAs();
+
+  if (FPT && FPT->hasExceptionSpec() &&
+  FPT->getExceptionSpecType() != EST_BasicNoexcept) {
+S.Diag(attr.getLoc(),
+   diag::warn_nothrow_attr_disagrees_with_exception_specification);
+S.Diag(FD->getExceptionSpecSourceRange().getBegin(),
+   diag::note_previous_decl)
+<< "exception specification";
+  }
+
+  D->addAttr(::new (S.Context) NoThrowAttr(
+  attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
+}
+
 static void handleNoCallerSavedRegsAttr(Sema , Decl *D,
 const AttributeList ) {
   if (S.CheckNoCallerSavedRegsAttr(Attr))
@@ -6192,7 +6211,7 @@
 handleNoReturnAttr(S, D, Attr);
 break;
   case AttributeList::AT_NoThrow:
-handleSimpleAttribute(S, D, Attr);
+handleNoThrowAttr(S, D, Attr);
 break;
   case AttributeList::AT_CUDAShared:
 handleSharedAttr(S, D, Attr);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1407,6 +1407,10 @@
   "argument to noexcept specifier must be a constant expression">;
 def err_exception_spec_not_parsed : Error<
   "exception specification is not available until end of class definition">;
+def warn_nothrow_attr_disagrees_with_exception_specification
+: ExtWarn<"Attribute nothrow ignored, it disagrees with language specified 
"
+  "exception specification">,
+  InGroup;
 
 // C++ access checking
 def err_class_redeclared_with_different_access : Error<


Index: test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++14
+
+struct S {
+  __attribute__((nothrow)) S() noexcept(true); 
+  __attribute__((nothrow)) void Func1() noexcept(false);
+  __attribute__((nothrow)) void Func2() throws();
+  __attribute__((nothrow)) void Func3() noexcept;
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1969,6 +1969,25 @@
   attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNoThrowAttr(Sema , Decl *D, const AttributeList ) {
+  assert(isa(D) && "attribute nothrow only valid on functions");
+
+  auto *FD = cast(D);
+  const auto *FPT = FD->getType()->getAs();
+
+  if (FPT && FPT->hasExceptionSpec() &&
+  FPT->getExceptionSpecType() != EST_BasicNoexcept) {
+S.Diag(attr.getLoc(),
+   diag::warn_nothrow_attr_disagrees_with_exception_specification);
+S.Diag(FD->getExceptionSpecSourceRange().getBegin(),
+   diag::note_previous_decl)
+<< "exception specification";
+  }
+
+  D->addAttr(::new (S.Context) NoThrowAttr(
+  attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
+}
+
 static void handleNoCallerSavedRegsAttr(Sema , Decl *D,
 const AttributeList ) {
   if (S.CheckNoCallerSavedRegsAttr(Attr))
@@ -6192,7 +6211,7 @@
 handleNoReturnAttr(S, D, Attr);
 break;
   case AttributeList::AT_NoThrow:
-handleSimpleAttribute(S, D, Attr);
+handleNoThrowAttr(S, D, Attr);
 

[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-25 Thread Boris Kolpackov via Phabricator via cfe-commits
boris added a comment.

Yes, the main "feature" of this approach compared to @file is the ability to 
reuse an already existing file to store this information. Most build systems 
that support C/C++ compilation have to store auxiliary dependency information 
at least for the extracted header dependencies (those .d files generated by the 
-M option family, for example) but some also store hashes of options, compiler 
version/signature, etc. So instead of creating a yet another file (per 
translation unit), the idea is to reuse the already existing one by storing the 
mapping with some "distinguishing" prefix. As a concrete example, a make-based 
build system could append it to the .d file (which is a makefile fragment)  as 
comments. How exactly this information is extracted is still an open question 
but I think this approach is generic enough to accommodate a wide range of 
possibilities (for example, -M could produce this information or the build 
system could append it itself after the -M is done).


https://reviews.llvm.org/D37299



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


[PATCH] D36589: Add support for remembering origins to ExternalASTMerger

2017-09-25 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Thanks for the additional docs! More comments below.




Comment at: lib/AST/ExternalASTMerger.cpp:116
+if (auto *ToDC = dyn_cast(To)) {
+  logs() << "(ExternalASTMerger*)" << (void*)
+ << " imported (DeclContext*)" << (void*)ToDC

Can you conditionalize the logging?



Comment at: lib/AST/ExternalASTMerger.cpp:126
+  Parent.HasImporterForOrigin(*FromOrigins.at(FromDC).AST)) {
+logs() << "(ExternalASTMerger*)" << (void*)
+   << " forced origin (DeclContext*)"

Same here.



Comment at: lib/AST/ExternalASTMerger.cpp:134
+  } else {
+logs() << "(ExternalASTMerger*)" << (void*)
+   << " maybe recording origin (DeclContext*)" << (void*)FromDC

Same here.



Comment at: lib/AST/ExternalASTMerger.cpp:213
+if (!DidCallback)
+  logs() << "(ExternalASTMerger*)" << (void*)this
+ << " asserting for (DeclContext*)" << (void*)DC

Same here.



Comment at: lib/AST/ExternalASTMerger.cpp:286
+  if (!FoundFromDC || !IsSameDC(FoundFromDC.get(), Origin.DC)) {
+logs() << "(ExternalASTMerger*)" << (void*)this
+   << " decided to record origin (DeclContext*)" << (void*)Origin.DC

Ditto



Comment at: lib/AST/ExternalASTMerger.cpp:292
+  } else {
+logs() << "(ExternalASTMerger*)" << (void*)this
+   << " decided NOT to record origin (DeclContext*)" << 
(void*)Origin.DC

Ditto



Comment at: tools/clang-import-test/clang-import-test.cpp:232
+
+struct CIAndOrigins {
+  using OriginMap = clang::ExternalASTMerger::OriginMap;

Can you also add a brief documentation for this one? 



Comment at: tools/clang-import-test/clang-import-test.cpp:242
+  return static_cast(Source)->GetOrigins();
+else
+  return EmptyOriginMap;

No need for the `else` here.



Comment at: tools/clang-import-test/clang-import-test.cpp:256
+  llvm::SmallVector Sources;
+  for (CIAndOrigins  : Imports) {
+Sources.push_back(

No need for curly braces here.



Comment at: tools/clang-import-test/clang-import-test.cpp:326
 "Errors occured while parsing the expression.", std::error_code());
   } else {
 return std::move(CI);

No need for the `else` here.



Comment at: tools/clang-import-test/clang-import-test.cpp:333
+  llvm::SmallVector Sources;
+  for (CIAndOrigins  : Imports) {
+Sources.push_back(

No need for curly braces here.



Comment at: tools/clang-import-test/clang-import-test.cpp:354
   exit(-1);
 } else {
   ImportCIs.push_back(std::move(*ImportCI));

No need for the `else` here.



Comment at: tools/clang-import-test/clang-import-test.cpp:365
   }
-  llvm::Expected ExpressionCI =
-  Parse(Expression, Direct ? ImportCIs : IndirectCIs, DumpAST, DumpIR);
+  if (UseOrigins) {
+for (auto  : ImportCIs) {

No need for braces in this entire block



Comment at: tools/clang-import-test/clang-import-test.cpp:376
 exit(-1);
   } else {
+Forget(*ExpressionCI, (Direct && !UseOrigins) ? ImportCIs : IndirectCIs);

No need for the `else` here.


https://reviews.llvm.org/D36589



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


[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-25 Thread Boris Kolpackov via Phabricator via cfe-commits
boris updated this revision to Diff 116438.
boris marked an inline comment as done.
boris added a comment.

New revision this time with the tests (which got dropped from the earlier 
revision diff for some reason).


https://reviews.llvm.org/D37299

Files:
  docs/Modules.rst
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CXX/modules-ts/basic/basic.search/module-import.cpp

Index: test/CXX/modules-ts/basic/basic.search/module-import.cpp
===
--- test/CXX/modules-ts/basic/basic.search/module-import.cpp
+++ test/CXX/modules-ts/basic/basic.search/module-import.cpp
@@ -5,6 +5,8 @@
 // RUN: echo 'export module x; int a, b;' > %t/x.cppm
 // RUN: echo 'export module y; import x; int c;' > %t/y.cppm
 // RUN: echo 'export module z; import y; int d;' > %t/z.cppm
+// RUN: echo 'x=%t/x.pcm'  > %t/modmap
+// RUN: echo 'y=%t/y.pcm' >> %t/modmap
 //
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/y.cppm -o %t/y.pcm
@@ -19,7 +21,17 @@
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=y=%t/y.pcm -verify %s \
 // RUN:-DMODULE_NAME=y
 //
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=x
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=y
+//
 // RUN: mv %t/x.pcm %t/a.pcm
+// RUN: echo 'foo.o: foo.cxx'   > %t/modmap
+// RUN: echo '# Mmodule name to file mapping:' >> %t/modmap
+// RUN: echo '#@z=%t/z.pcm'>> %t/modmap
+// RUN: echo '#@ y=%t/y.pcm'   >> %t/modmap
+// RUN: echo '#@x=%t/a.pcm '   >> %t/modmap
 //
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=x=%t/a.pcm -verify %s \
 // RUN:-DMODULE_NAME=x
@@ -33,7 +45,15 @@
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=z=%t/z.pcm -fmodule-file=y=%t/y.pcm -fmodule-file=x=%t/a.pcm -verify %s \
 // RUN:-DMODULE_NAME=z
 //
+//
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=x
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=y
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=z
+//

 import MODULE_NAME;

 // expected-no-diagnostics
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1528,8 +1528,80 @@
   return P.str();
 }

+// Read the mapping of module names to precompiled module files from a file.
+// The argument can include an optional line prefix ([]=), in
+// which case only lines that start with the prefix are considered (with the
+// prefix and the following whitespaces, if any, ignored).
+//
+// Each mapping entry should be in the same form as the -fmodule-file option
+// value (=) with leading/trailing whitespaces ignored.
+//
+static void LoadModuleFileMap(HeaderSearchOptions ,
+  DiagnosticsEngine , FileManager ,
+  StringRef Val, const std::string ) {
+  // See if we have the prefix.
+  StringRef File;
+  StringRef Prefix;
+  if (Val.find('=') != StringRef::npos) {
+auto Pair = Val.split('=');
+Prefix = Pair.first;
+File = Pair.second;
+if (Prefix.empty()) {
+  Diags.Report(diag::err_drv_invalid_value) << Arg << Val;
+  return;
+}
+  } else
+File = Val;
+
+  if (File.empty()) {
+Diags.Report(diag::err_drv_invalid_value) << Arg << Val;
+return;
+  }
+
+  auto *Buf = FileMgr.getBufferForFile(File);
+  if (!Buf) {
+Diags.Report(diag::err_cannot_open_file)
+<< File << Buf.getError().message();
+return;
+  }
+
+  // Read the file line by line.
+  StringRef Str = Buf.get()->getBuffer();
+  for (size_t B = 0, E = 0; B < Str.size(); B = E + 1) {
+E = Str.find_first_of(StringRef("\n\0", 2), B);
+
+if (E == StringRef::npos)
+  E = Str.size();
+else if (Str[E] == '\0')
+  break; // The file (or the rest of it) is binary, bail out.
+
+// [B, E) is our line. Compare and skip the prefix, if any.
+StringRef Line = Str.substr(B, E - B);
+if (!Prefix.empty()) {
+  if (!Line.startswith(Prefix))
+continue;
+
+  Line = Line.substr(Prefix.size());
+}
+
+// Skip leading and trailing whitespaces and ignore blanks (even if they
+// had prefix; think make comments).
+Line = Line.trim();
+if (Line.empty())
+  continue;
+
+if (Line.find('=') == 

[PATCH] D38208: Add support for remembering origins to ExternalASTMerger

2017-09-25 Thread Sean Callanan via Phabricator via cfe-commits
spyffe created this revision.
spyffe added a project: clang.

At @bruno 's request, recreating this with cfe-commits as a subscriber.  The 
original is https://reviews.llvm.org/D36589

`ExternalASTMerger` has hitherto relied on being able to look up any Decl 
through its named `DeclContext` chain.  This works for many cases, but causes 
problems for function-local structs, which cannot be looked up in their 
containing `FunctionDecl`.  An example case is

  void f() {
{ struct S { int a; }; }
{ struct S { bool b; }; }
  }

It is not possible to lookup either of the two `S`es individually (or even to 
provide enough information to disambiguate) after parsing is over; and there is 
typically no need to, since they are invisible to the outside world.

However, ExternalASTMerger needs to be able to complete either S on demand.  
This led to an `XFAIL` on test/Import/local-struct, which this patch removes.  
The way the patch works is:

- It defines a new data structure, `ExternalASTMerger::OriginMap`, which 
clients are expected to maintain (default-constructing if the origin does not 
have an `ExternalASTMerger` servicing it)
- As `DeclContext`s are imported, if they cannot be looked up by name they are 
placed in the `OriginMap`.  This allows `ExternalASTMerger` to complete them 
later if necessary.
- As `DeclContext`s are imported from an origin that already has its own 
`OriginMap`, the origins are forwarded – but only for those `DeclContext`s that 
are actually used.  This keeps the amount of stored data minimal.


Repository:
  rL LLVM

https://reviews.llvm.org/D38208

Files:
  include/clang/AST/ExternalASTMerger.h
  lib/AST/ExternalASTMerger.cpp
  lib/Sema/SemaType.cpp
  test/Import/extern-c-function/Inputs/F.cpp
  test/Import/extern-c-function/test.cpp
  test/Import/forward-declared-objc-class/Inputs/S1.m
  test/Import/forward-declared-objc-class/Inputs/S2.m
  test/Import/forward-declared-objc-class/Inputs/S3.m
  test/Import/forward-declared-objc-class/test.m
  test/Import/forward-declared-struct/Inputs/S3.c
  test/Import/forward-declared-struct/test.c
  test/Import/local-struct-use-origins/Inputs/Callee.cpp
  test/Import/local-struct-use-origins/test.cpp
  test/Import/local-struct/test.cpp
  test/Import/objc-definitions-in-expression/Inputs/S.m
  test/Import/objc-definitions-in-expression/test.m
  test/Import/struct-and-var/Inputs/S1.cpp
  test/Import/struct-and-var/Inputs/S2.cpp
  test/Import/struct-and-var/test.cpp
  test/Import/template/Inputs/T.cpp
  test/Import/template/test.cpp
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ tools/clang-import-test/clang-import-test.cpp
@@ -48,8 +48,12 @@
 
 static llvm::cl::opt
 Direct("direct", llvm::cl::Optional,
- llvm::cl::desc("Use the parsed declarations without indirection"));
+   llvm::cl::desc("Use the parsed declarations without indirection"));
 
+static llvm::cl::opt
+UseOrigins("use-origins", llvm::cl::Optional,
+   llvm::cl::desc("Use DeclContext origin information for more accurate lookups"));  
+
 static llvm::cl::list
 ClangArgs("Xcc", llvm::cl::ZeroOrMore,
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
@@ -60,13 +64,11 @@
   llvm::cl::desc("The language to parse (default: c++)"),
   llvm::cl::init("c++"));
 
-static llvm::cl::opt
-DumpAST("dump-ast", llvm::cl::init(false),
-llvm::cl::desc("Dump combined AST"));
+static llvm::cl::opt DumpAST("dump-ast", llvm::cl::init(false),
+   llvm::cl::desc("Dump combined AST"));
 
-static llvm::cl::opt
-DumpIR("dump-ir", llvm::cl::init(false),
-llvm::cl::desc("Dump IR from final parse"));
+static llvm::cl::opt DumpIR("dump-ir", llvm::cl::init(false),
+  llvm::cl::desc("Dump IR from final parse"));
 
 namespace init_convenience {
 class TestDiagnosticConsumer : public DiagnosticConsumer {
@@ -154,8 +156,7 @@
   }
 };
 
-std::unique_ptr
-BuildCompilerInstance() {
+std::unique_ptr BuildCompilerInstance() {
   auto Ins = llvm::make_unique();
   auto DC = llvm::make_unique();
   const bool ShouldOwnClient = true;
@@ -227,29 +228,54 @@
 } // end namespace
 
 namespace {
- 
-void AddExternalSource(
-CompilerInstance ,
-llvm::ArrayRef Imports) {
-  ExternalASTMerger::ImporterEndpoint Target({CI.getASTContext(), CI.getFileManager()});
-  llvm::SmallVector Sources;
-  for (const std::unique_ptr  : Imports) {
-Sources.push_back({CI->getASTContext(), CI->getFileManager()});
+
+/// A container for a CompilerInstance (possibly with an ExternalASTMerger
+/// attached to its ASTContext).
+///
+/// Provides an accessor for the DeclContext origins associated with the
+/// ExternalASTMerger (or an empty list of 

[PATCH] D36589: Add support for remembering origins to ExternalASTMerger

2017-09-25 Thread Sean Callanan via Phabricator via cfe-commits
spyffe abandoned this revision.
spyffe marked 13 inline comments as done.
spyffe added a comment.

At @bruno 's request, abandoning this revision in favor of the updated 
https://reviews.llvm.org/D38208.
That revision has all the changes requested.


https://reviews.llvm.org/D36589



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


[PATCH] D38205: [Sema] Warn on attribute nothrow conflicting with language specifiers

2017-09-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 116433.
erichkeane added a comment.

Woops, didn't commit my correct tests!


https://reviews.llvm.org/D38205

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp


Index: test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify 
-std=c++14
+
+struct S {
+  //expected-warning@+2 {{Attribute nothrow ignored, it disagrees with}}
+  ///expected-note@+1 {{exception specification declared here}}
+  __attribute__((nothrow)) S() noexcept(true);
+  //expected-warning@+2 {{Attribute nothrow ignored, it disagrees with}}
+  ///expected-note@+1 {{exception specification declared here}}
+  __attribute__((nothrow)) void Func1() noexcept(false);
+  __attribute__((nothrow)) void Func3() noexcept;
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1969,6 +1969,25 @@
   attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNoThrowAttr(Sema , Decl *D, const AttributeList ) {
+  assert(isa(D) && "attribute nothrow only valid on functions");
+
+  auto *FD = cast(D);
+  const auto *FPT = FD->getType()->getAs();
+
+  if (FPT && FPT->hasExceptionSpec() &&
+  FPT->getExceptionSpecType() != EST_BasicNoexcept) {
+S.Diag(attr.getLoc(),
+   diag::warn_nothrow_attr_disagrees_with_exception_specification);
+S.Diag(FD->getExceptionSpecSourceRange().getBegin(),
+   diag::note_previous_decl)
+<< "exception specification";
+  }
+
+  D->addAttr(::new (S.Context) NoThrowAttr(
+  attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
+}
+
 static void handleNoCallerSavedRegsAttr(Sema , Decl *D,
 const AttributeList ) {
   if (S.CheckNoCallerSavedRegsAttr(Attr))
@@ -6192,7 +6211,7 @@
 handleNoReturnAttr(S, D, Attr);
 break;
   case AttributeList::AT_NoThrow:
-handleSimpleAttribute(S, D, Attr);
+handleNoThrowAttr(S, D, Attr);
 break;
   case AttributeList::AT_CUDAShared:
 handleSharedAttr(S, D, Attr);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1407,6 +1407,10 @@
   "argument to noexcept specifier must be a constant expression">;
 def err_exception_spec_not_parsed : Error<
   "exception specification is not available until end of class definition">;
+def warn_nothrow_attr_disagrees_with_exception_specification
+: ExtWarn<"Attribute nothrow ignored, it disagrees with language specified 
"
+  "exception specification">,
+  InGroup;
 
 // C++ access checking
 def err_class_redeclared_with_different_access : Error<


Index: test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++14
+
+struct S {
+  //expected-warning@+2 {{Attribute nothrow ignored, it disagrees with}}
+  ///expected-note@+1 {{exception specification declared here}}
+  __attribute__((nothrow)) S() noexcept(true);
+  //expected-warning@+2 {{Attribute nothrow ignored, it disagrees with}}
+  ///expected-note@+1 {{exception specification declared here}}
+  __attribute__((nothrow)) void Func1() noexcept(false);
+  __attribute__((nothrow)) void Func3() noexcept;
+};
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1969,6 +1969,25 @@
   attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNoThrowAttr(Sema , Decl *D, const AttributeList ) {
+  assert(isa(D) && "attribute nothrow only valid on functions");
+
+  auto *FD = cast(D);
+  const auto *FPT = FD->getType()->getAs();
+
+  if (FPT && FPT->hasExceptionSpec() &&
+  FPT->getExceptionSpecType() != EST_BasicNoexcept) {
+S.Diag(attr.getLoc(),
+   diag::warn_nothrow_attr_disagrees_with_exception_specification);
+S.Diag(FD->getExceptionSpecSourceRange().getBegin(),
+   diag::note_previous_decl)
+<< "exception specification";
+  }
+
+  D->addAttr(::new (S.Context) NoThrowAttr(
+  attr.getRange(), S.Context, attr.getAttributeSpellingListIndex()));
+}
+
 static void handleNoCallerSavedRegsAttr(Sema , Decl *D,
 const AttributeList ) 

[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-09-25 Thread Boris Kolpackov via Phabricator via cfe-commits
boris updated this revision to Diff 116442.
boris added a comment.

Another attempt to upload a clean diff (also rebased on latest HEAD).


https://reviews.llvm.org/D37299

Files:
  docs/Modules.rst
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CXX/modules-ts/basic/basic.search/module-import.cpp

Index: test/CXX/modules-ts/basic/basic.search/module-import.cpp
===
--- test/CXX/modules-ts/basic/basic.search/module-import.cpp
+++ test/CXX/modules-ts/basic/basic.search/module-import.cpp
@@ -5,6 +5,8 @@
 // RUN: echo 'export module x; int a, b;' > %t/x.cppm
 // RUN: echo 'export module y; import x; int c;' > %t/y.cppm
 // RUN: echo 'export module z; import y; int d;' > %t/z.cppm
+// RUN: echo 'x=%t/x.pcm'  > %t/modmap
+// RUN: echo 'y=%t/y.pcm' >> %t/modmap
 //
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %t/x.cppm -o %t/x.pcm
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface -fmodule-file=%t/x.pcm %t/y.cppm -o %t/y.pcm
@@ -19,7 +21,17 @@
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=y=%t/y.pcm -verify %s \
 // RUN:-DMODULE_NAME=y
 //
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=x
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=y
+//
 // RUN: mv %t/x.pcm %t/a.pcm
+// RUN: echo 'foo.o: foo.cxx'   > %t/modmap
+// RUN: echo '# Mmodule name to file mapping:' >> %t/modmap
+// RUN: echo '#@z=%t/z.pcm'>> %t/modmap
+// RUN: echo '#@ y=%t/y.pcm'   >> %t/modmap
+// RUN: echo '#@x=%t/a.pcm '   >> %t/modmap
 //
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=x=%t/a.pcm -verify %s \
 // RUN:-DMODULE_NAME=x
@@ -33,6 +45,14 @@
 // RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file=z=%t/z.pcm -fmodule-file=y=%t/y.pcm -fmodule-file=x=%t/a.pcm -verify %s \
 // RUN:-DMODULE_NAME=z
 //
+//
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=x
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=y
+// RUN: %clang_cc1 -std=c++1z -fmodules-ts -I%t -fmodule-file-map=#@=%t/modmap -verify %s \
+// RUN:-DMODULE_NAME=z
+//
 
 import MODULE_NAME;
 
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1531,8 +1531,80 @@
   return P.str();
 }
 
+// Read the mapping of module names to precompiled module files from a file.
+// The argument can include an optional line prefix ([]=), in
+// which case only lines that start with the prefix are considered (with the
+// prefix and the following whitespaces, if any, ignored).
+//
+// Each mapping entry should be in the same form as the -fmodule-file option
+// value (=) with leading/trailing whitespaces ignored.
+//
+static void LoadModuleFileMap(HeaderSearchOptions ,
+  DiagnosticsEngine , FileManager ,
+  StringRef Val, const std::string ) {
+  // See if we have the prefix.
+  StringRef File;
+  StringRef Prefix;
+  if (Val.find('=') != StringRef::npos) {
+auto Pair = Val.split('=');
+Prefix = Pair.first;
+File = Pair.second;
+if (Prefix.empty()) {
+  Diags.Report(diag::err_drv_invalid_value) << Arg << Val;
+  return;
+}
+  } else
+File = Val;
+
+  if (File.empty()) {
+Diags.Report(diag::err_drv_invalid_value) << Arg << Val;
+return;
+  }
+
+  auto *Buf = FileMgr.getBufferForFile(File);
+  if (!Buf) {
+Diags.Report(diag::err_cannot_open_file)
+<< File << Buf.getError().message();
+return;
+  }
+
+  // Read the file line by line.
+  StringRef Str = Buf.get()->getBuffer();
+  for (size_t B = 0, E = 0; B < Str.size(); B = E + 1) {
+E = Str.find_first_of(StringRef("\n\0", 2), B);
+
+if (E == StringRef::npos)
+  E = Str.size();
+else if (Str[E] == '\0')
+  break; // The file (or the rest of it) is binary, bail out.
+
+// [B, E) is our line. Compare and skip the prefix, if any.
+StringRef Line = Str.substr(B, E - B);
+if (!Prefix.empty()) {
+  if (!Line.startswith(Prefix))
+continue;
+
+  Line = Line.substr(Prefix.size());
+}
+
+// Skip leading and trailing whitespaces and ignore blanks (even if they
+// had prefix; think make comments).
+Line = Line.trim();
+if (Line.empty())
+  continue;
+
+if (Line.find('=') == StringRef::npos) {
+  Diags.Report(diag::err_drv_invalid_module_file_map) << Line;
+  

  1   2   >