[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

I've reverted this and the follow-up change to fix the build in 
437d4e01fe4c057509dff30efd560049ad07bc99 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119462: [analyzer][NFCi] Use the correct BugType in CStringChecker.

2022-02-11 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added a comment.

In D119462#3312482 , @steakhal wrote:

> I would recommend not touching the unrelated lines, unless you have a clear 
> motive. Other than that I think its fair to say that this must have been a 
> bug. Ill check the report diff tomorrow, prior accepting this.

Yeah will keep in mind. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119462

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


[clang] 437d4e0 - Revert "try to fix windows build after 73e585e44d" and

2022-02-11 Thread Douglas Yung via cfe-commits

Author: Douglas Yung
Date: 2022-02-11T23:47:53-08:00
New Revision: 437d4e01fe4c057509dff30efd560049ad07bc99

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

LOG: Revert "try to fix windows build after 73e585e44d" and
Revert "Reland "[lld/coff] Make lld-link work in a non-MSVC shell, add 
/winsysroot:""

This reverts commit 0574b5fc657451c9d13d3f6d8fe14ea15c23a681 and 
73e585e44d68cf77e2e3274e98c9615156a7d909.

This change is causing the test Driver/cl-options.c to fail on Windows 
buildbots.
https://lab.llvm.org/staging/#/builders/204/builds/1343

Added: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
lld/COFF/CMakeLists.txt
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/Options.td
lld/COFF/SymbolTable.cpp
lld/docs/ReleaseNotes.rst
llvm/lib/CMakeLists.txt
llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
llvm/utils/gn/secondary/lld/COFF/BUILD.gn

Removed: 
lld/test/COFF/winsysroot.test
llvm/include/llvm/WindowsDriver/MSVCPaths.h
llvm/include/llvm/WindowsDriver/MSVCSetupApi.h
llvm/lib/WindowsDriver/CMakeLists.txt
llvm/lib/WindowsDriver/MSVCPaths.cpp
llvm/utils/gn/secondary/llvm/lib/WindowsDriver/BUILD.gn



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 4a2c28bcf32ae..c7defa9cd88c6 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -285,6 +285,7 @@ clang/lib/Driver/ToolChains/InterfaceStubs.h
 clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
+clang/lib/Driver/ToolChains/MSVCSetupApi.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp
 clang/lib/Driver/ToolChains/PPCFreeBSD.h
 clang/lib/Driver/ToolChains/PPCLinux.h
@@ -5328,8 +5329,6 @@ 
llvm/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
 llvm/include/llvm/Transforms/Utils/UnifyLoopExits.h
 llvm/include/llvm/Transforms/Utils/ValueMapper.h
 llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
-llvm/include/llvm/WindowsDriver/MSVCPaths.h
-llvm/include/llvm/WindowsDriver/MSVCSetupApi.h
 llvm/include/llvm/WindowsManifest/WindowsManifestMerger.h
 llvm/include/llvm/WindowsResource/ResourceScriptToken.h
 llvm/include/llvm/XRay/BlockIndexer.h
@@ -6493,7 +6492,6 @@ llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
 llvm/lib/Transforms/Vectorize/VPlanTransforms.h
 llvm/lib/Transforms/Vectorize/VPlanValue.h
 llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
-llvm/lib/WindowsDriver/MSVCPaths.cpp
 llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
 llvm/lib/XRay/BlockIndexer.cpp
 llvm/lib/XRay/BlockVerifier.cpp

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 00c7a8f893ff4..78e8fd1852841 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
   Option
   ProfileData
   Support
-  WindowsDriver
   )
 
 if(WIN32)

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 03e941389aca4..9f4751167ac12 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -40,12 +40,91 @@
   #include 
 #endif
 
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+#include "MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+#include "llvm/Support/COM.h"
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+#endif
+
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+// Windows SDKs and VC Toolchains group their contents into subdirectories 
based
+// on the target architecture. This function converts an llvm::Triple::ArchType
+// to the corresponding subdirectory name.
+static const char *llvmArchToWindowsSDKArch(llvm::Triple::ArchType Arch) {
+  using ArchType = llvm::Triple::ArchType;
+  switch (Arch) {
+  case ArchType::x86:
+return "x86";
+  case ArchType::x86_64:

[PATCH] D119621: [SanitizerCoverage] Add instrumentation callbacks for FP cmp instructions

2022-02-11 Thread Chaofan Shou via Phabricator via cfe-commits
shouc updated this revision to Diff 408164.

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

https://reviews.llvm.org/D119621

Files:
  clang/docs/SanitizerCoverage.rst
  compiler-rt/lib/dfsan/done_abilist.txt
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_interface.inc
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll

Index: llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
@@ -12,10 +12,16 @@
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp2(i16 zeroext, i16 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp4(i32 zeroext, i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp8(i64, i64)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp2(half, half)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp4(float, float)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp8(double, double)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp1(i8 zeroext, i8 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp2(i16 zeroext, i16 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp4(i32 zeroext, i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp8(i64, i64)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp2(half, half)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp4(float, float)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp8(double, double)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_div4(i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_div8(i64)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_gep(i64)
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -52,10 +52,16 @@
 const char SanCovTraceCmp2[] = "__sanitizer_cov_trace_cmp2";
 const char SanCovTraceCmp4[] = "__sanitizer_cov_trace_cmp4";
 const char SanCovTraceCmp8[] = "__sanitizer_cov_trace_cmp8";
+const char SanCovTraceCmpF2[] = "__sanitizer_cov_trace_cmp_fp2";
+const char SanCovTraceCmpF4[] = "__sanitizer_cov_trace_cmp_fp4";
+const char SanCovTraceCmpF8[] = "__sanitizer_cov_trace_cmp_fp8";
 const char SanCovTraceConstCmp1[] = "__sanitizer_cov_trace_const_cmp1";
 const char SanCovTraceConstCmp2[] = "__sanitizer_cov_trace_const_cmp2";
 const char SanCovTraceConstCmp4[] = "__sanitizer_cov_trace_const_cmp4";
 const char SanCovTraceConstCmp8[] = "__sanitizer_cov_trace_const_cmp8";
+const char SanCovTraceConstCmpF2[] = "__sanitizer_cov_trace_const_cmp_fp2";
+const char SanCovTraceConstCmpF4[] = "__sanitizer_cov_trace_const_cmp_fp4";
+const char SanCovTraceConstCmpF8[] = "__sanitizer_cov_trace_const_cmp_fp8";
 const char SanCovLoad1[] = "__sanitizer_cov_load1";
 const char SanCovLoad2[] = "__sanitizer_cov_load2";
 const char SanCovLoad4[] = "__sanitizer_cov_load4";
@@ -257,8 +263,8 @@
   std::string getSectionEnd(const std::string &Section) const;
   FunctionCallee SanCovTracePCIndir;
   FunctionCallee SanCovTracePC, SanCovTracePCGuard;
-  std::array SanCovTraceCmpFunction;
-  std::array SanCovTraceConstCmpFunction;
+  std::array SanCovTraceCmpFunction;
+  std::array SanCovTraceConstCmpFunction;
   std::array SanCovLoadFunction;
   std::array SanCovStoreFunction;
   std::array SanCovTraceDivFunction;
@@ -267,7 +273,8 @@
   GlobalVariable *SanCovLowestStack;
   Type *Int128PtrTy, *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty,
   *Int32PtrTy, *Int16PtrTy, *Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty,
-  *Int1PtrTy;
+  *Int1PtrTy,
+  *Fp16Ty, *Fp16PtrTy, *Fp32Ty, *Fp32PtrTy, *Fp64Ty, *Fp64PtrTy;
   Module *CurModule;
   std::string CurModuleUniqueId;
   Triple TargetTriple;
@@ -443,11 +450,17 @@
   Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
   Int8PtrTy = PointerType::getUnqual(IRB.getInt8Ty());
   Int1PtrTy = PointerType::getUnqual(IRB.getInt1Ty());
+  Fp16PtrTy = PointerType::getUnqual(IRB.getHalfTy());
+  Fp32PtrTy = PointerType::getUnqual(IRB.getFloatTy());
+  Fp64PtrTy = PointerType::getUnqual(IRB.getDoubleTy());
   Int64Ty = IRB.getInt64Ty();
   Int32Ty = IRB.getInt32Ty();
   Int16Ty = IRB.getInt16Ty();
   Int8Ty = IRB.getInt8Ty();
   Int1Ty = IRB.getInt1Ty();
+  Fp16Ty = IRB.getHalfTy();
+  Fp32Ty = IRB.getFloatTy();
+  Fp64Ty = IRB.getDoubleTy();
 
   SanCovTracePCIndir =
   M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy);
@@ -470,6 +483,9 @@
  

[PATCH] D119364: Refactor nested if else with ternary operator in CGExprScalar.cpp

2022-02-11 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added a comment.

In D119364#3310170 , @rjmccall wrote:

> Sure, LGTM

Hey Thanks, would you please help to land this patch . I don't have commit 
access .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119364

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


[PATCH] D119364: Refactor nested if else with ternary operator in CGExprScalar.cpp

2022-02-11 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added a comment.

In D119364#3310170 , @rjmccall wrote:

> Sure, LGTM

Yeah, will keep in mind. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119364

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


[PATCH] D119621: [SanitizerCoverage] Add instrumentation callbacks for FP cmp instructions

2022-02-11 Thread Chaofan Shou via Phabricator via cfe-commits
shouc created this revision.
shouc added reviewers: morehouse, rnk, vitalybuka.
Herald added subscribers: abrachet, hiraditya.
shouc requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Fuzzers need to add branch instrumentation. Current callbacks only consider 
integer instrumentation (i.e., integer related branches). This commit adds 
similar sancov trace callback funcs for floating point (half, float, and 
double) comparisons:

  +  void __sanitizer_cov_trace_cmp_fp2(half Arg1, half Arg2);
  +  void __sanitizer_cov_trace_cmp_fp4(float Arg1, float Arg2);
  +  void __sanitizer_cov_trace_cmp_fp8(double Arg1, double Arg2);
  +  void __sanitizer_cov_trace_const_cmp_fp2(half Arg1, half Arg2);
  +  void __sanitizer_cov_trace_const_cmp_fp4(float Arg1, float Arg2);
  +  void __sanitizer_cov_trace_const_cmp_fp8(double Arg1, double Arg2);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119621

Files:
  clang/docs/SanitizerCoverage.rst
  compiler-rt/lib/dfsan/done_abilist.txt
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_interface.inc
  compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
  llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll

Index: llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll
@@ -12,10 +12,16 @@
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp2(i16 zeroext, i16 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp4(i32 zeroext, i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp8(i64, i64)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp2(half, half)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp4(float, float)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp_fp8(double, double)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp1(i8 zeroext, i8 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp2(i16 zeroext, i16 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp4(i32 zeroext, i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp8(i64, i64)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp2(half, half)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp4(float, float)
+; CHECK-DAG: declare void @__sanitizer_cov_trace_const_cmp_fp8(double, double)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_div4(i32 zeroext)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_div8(i64)
 ; CHECK-DAG: declare void @__sanitizer_cov_trace_gep(i64)
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -52,10 +52,16 @@
 const char SanCovTraceCmp2[] = "__sanitizer_cov_trace_cmp2";
 const char SanCovTraceCmp4[] = "__sanitizer_cov_trace_cmp4";
 const char SanCovTraceCmp8[] = "__sanitizer_cov_trace_cmp8";
+const char SanCovTraceCmpF2[] = "__sanitizer_cov_trace_cmp_fp2";
+const char SanCovTraceCmpF4[] = "__sanitizer_cov_trace_cmp_fp4";
+const char SanCovTraceCmpF8[] = "__sanitizer_cov_trace_cmp_fp8";
 const char SanCovTraceConstCmp1[] = "__sanitizer_cov_trace_const_cmp1";
 const char SanCovTraceConstCmp2[] = "__sanitizer_cov_trace_const_cmp2";
 const char SanCovTraceConstCmp4[] = "__sanitizer_cov_trace_const_cmp4";
 const char SanCovTraceConstCmp8[] = "__sanitizer_cov_trace_const_cmp8";
+const char SanCovTraceConstCmpF2[] = "__sanitizer_cov_trace_const_cmp_fp2";
+const char SanCovTraceConstCmpF4[] = "__sanitizer_cov_trace_const_cmp_fp4";
+const char SanCovTraceConstCmpF8[] = "__sanitizer_cov_trace_const_cmp_fp8";
 const char SanCovLoad1[] = "__sanitizer_cov_load1";
 const char SanCovLoad2[] = "__sanitizer_cov_load2";
 const char SanCovLoad4[] = "__sanitizer_cov_load4";
@@ -257,8 +263,8 @@
   std::string getSectionEnd(const std::string &Section) const;
   FunctionCallee SanCovTracePCIndir;
   FunctionCallee SanCovTracePC, SanCovTracePCGuard;
-  std::array SanCovTraceCmpFunction;
-  std::array SanCovTraceConstCmpFunction;
+  std::array SanCovTraceCmpFunction;
+  std::array SanCovTraceConstCmpFunction;
   std::array SanCovLoadFunction;
   std::array SanCovStoreFunction;
   std::array SanCovTraceDivFunction;
@@ -267,7 +273,8 @@
   GlobalVariable *SanCovLowestStack;
   Type *Int128PtrTy, *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty,
   *Int32PtrTy, *Int16PtrTy, *Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty,
-  *Int1PtrTy;
+  *Int1PtrTy,
+  *Fp16Ty, *Fp16P

[PATCH] D119615: [CUDA][HIP] Do not promote constexpr var with non-constant initializer

2022-02-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

constexpr var may be initialized with address of non-const variable.
In this case the initializer is not constant in device compilation.
This has been handled for const vars but not for constexpr vars.

This patch makes handling of const var and constexpr var
consistent.


https://reviews.llvm.org/D119615

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/test/SemaCUDA/constexpr-var.cu

Index: clang/test/SemaCUDA/constexpr-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/constexpr-var.cu
@@ -0,0 +1,105 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -fsyntax-only -verify
+// RUN: %clang_cc1 -triple x86_64 -x hip %s \
+// RUN:   -fsyntax-only -verify=host
+
+// host-no-diagnostics
+
+#include "Inputs/cuda.h"
+
+// Test constexpr var initialized with address of a const var.
+// Both are promoted to device side.
+
+namespace Test1 {
+const int a = 1;
+
+struct B {
+static constexpr const int *p = &a;
+__device__ static constexpr const int *const p2 = &a;
+};
+
+// Const variable 'a' is treated as __constant__ on device side,
+// therefore its address can be used as initializer for another
+// device variable.
+
+__device__ void f() {
+  int y = a;
+  constexpr const int *x = B::p;
+  constexpr const int *z = B::p2;
+}
+}
+
+// Test constexpr var initialized with address of a non-cost var.
+// Neither is promoted to device side.
+
+namespace Test2 {
+int a = 1;
+// expected-note@-1{{host variable declared here}}
+
+struct B {
+static constexpr int *const p = &a;
+// expected-note@-1{{const variable cannot be emitted on device side due to dynamic initialization}}
+};
+
+__device__ void f() {
+  int y = a;
+  // expected-error@-1{{reference to __host__ variable 'a' in __device__ function}}
+  const int *const *x = &B::p;
+  // expected-error@-1{{reference to __host__ variable 'p' in __device__ function}}
+  // ToDo: use of non-promotable constexpr variable in device compilation should be treated as
+  // ODR-use and diagnosed.
+  const int *const z = B::p;
+}
+}
+
+// Test constexpr device var initialized with address of a non-const host var, __shared var,
+// __managed__ var, __device__ var, __constant__ var, texture var, surface var.
+
+namespace Test3 {
+struct textureReference {
+  int desc;
+};
+
+enum ReadMode {
+  ElementType = 0,
+  NormalizedFloat = 1
+};
+
+template 
+struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
+};
+
+struct surfaceReference {
+  int desc;
+};
+
+template 
+struct __attribute__((device_builtin_surface_type)) surface : public surfaceReference {
+};
+
+// Partial specialization over `void`.
+template
+struct __attribute__((device_builtin_surface_type)) surface : public surfaceReference {
+};
+
+texture tex;
+surface surf;
+
+int a = 1;
+__shared__ int b;
+__managed__ int c = 1;
+__device__ int d = 1;
+__constant__ int e = 1;
+struct B {
+__device__ static constexpr int *const p1 = &a;
+// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+__device__ static constexpr int *const p2 = &b;
+// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+__device__ static constexpr int *const p3 = &c;
+// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+__device__ static constexpr int *const p4 = &d;
+__device__ static constexpr int *const p5 = &e;
+__device__ static constexpr texture *const p6 = &tex;
+__device__ static constexpr surface *const p7 = &surf;
+};
+}
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -145,9 +145,8 @@
 Sema::CUDAVariableTarget Sema::IdentifyCUDATarget(const VarDecl *Var) {
   if (Var->hasAttr())
 return CVT_Unified;
-  if (Var->isConstexpr() && !hasExplicitAttr(Var))
-return CVT_Both;
-  if (Var->getType().isConstQualified() && Var->hasAttr() &&
+  if ((Var->isConstexpr() || Var->getType().isConstQualified()) &&
+  Var->hasAttr() &&
   !hasExplicitAttr(Var))
 return CVT_Both;
   if (Var->hasAttr() || Var->hasAttr() ||
@@ -718,9 +717,9 @@
   !VD->hasAttr() && !VD->hasAttr() &&
   (VD->isFileVarDecl() || VD->isStaticDataMember()) &&
   !IsDependentVar(VD) &&
-  (VD->isConstexpr() || (VD->getType().isConstQualified() &&
- HasAllowedCUDADeviceStaticInitializer(
- *this, VD, CICK_DeviceOrConstant {
+  ((VD->isConstexpr() || VD->getType().isConstQualified()) &&
+   HasAllowedCUDADeviceStaticInitializer(*this, VD,
+  

[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth

2022-02-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:645-646
 
-  auto ValueToUpdate = C.getSValBuilder().makeNull();
+  auto ValueToUpdate = C.getSValBuilder().makeNullWithType(
+  IC->getCXXThisVal().getType(C.getASTContext()));
   State = State->set(ThisRegion, ValueToUpdate);

I don't think this is the right type. This should be the raw pointer type for 
the corresponding smart pointer, not a pointer //to// the smart pointer.

`Call.getResultType()` should be good. 

Also general advice, do not use `SVal::getType()` when you can obtain the type 
from the AST instead. `SVal::getType()` is speculative and it inevitably loses 
some information (in particular, it doesn't discriminate between lvalues and 
pointers).



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:785
+auto NullVal = C.getSValBuilder().makeNullWithType(
+OtherInnerPtr->getType(C.getASTContext()));
 State = State->set(OtherSmartPtrRegion, NullVal);

Same here.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:812
+const ClassTemplateSpecializationDecl *SpecDecl =
+dyn_cast(
+cast(Call.getDecl())->getParent());

You're using `dyn_cast` but you're unconditionally dereferencing the result 
later. Looking at other copies of similar code, you probably need a null check.

(Does running the static analyzer produce a warning here? We have a checker for 
this!)



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:885
 
-auto NullVal = C.getSValBuilder().makeNull();
+auto NullVal = C.getSValBuilder().makeNullWithType(CallExpr->getType());
 // Explicitly tracking the region as null.

I suspect that this type is going to be `bool` which is probably not what you 
want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119601

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

It fails on this:

  // Validate that the default triple is used when run an empty tools dir is 
specified
  // RUN: %clang_cl -vctoolsdir "" -### -- %s 2>&1 | FileCheck %s 
--check-prefix VCTOOLSDIR
  // VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.20.0"

With this:

  
C:\buildbot-root\llvm-clang-x86_64-sie-win\llvm-project\clang\test\Driver\cl-options.c:761:16:
 error: VCTOOLSDIR: expected string not found in input
  // VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.20.0"
 ^
  :1:1: note: scanning from here
  clang version 15.0.0 (https://github.com/llvm/llvm-project.git 
0574b5fc657451c9d13d3f6d8fe14ea15c23a681)
  ^
  :5:68: note: possible intended match here
   "c:\\buildbot-root\\llvm-clang-x86_64-sie-win\\build\\bin\\clang.exe" "-cc1" 
"-triple" "x86_64-pc-windows-msvc19.29.30137" ...

That test was added in D85998 .

I think this is a true regression. findVCToolChainViaCommandLine() used to 
return true on present-but-empty strings, but 
llvm::findVCToolChainViaCommandLine() uses the empty string as "not set".

The fix is probably to make llvm::findVCToolChainViaCommandLine() take 
Optionals instead, and use the Optional value instead of string 
emptiness.

It's late over here, so I won't get to that myself today. Feel free to revert 
for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119612: [clang] Pass more flags to ld64.lld

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:242
 } else if (D.getLTOMode() == LTOK_Thin)
   // If we are using thin LTO, then create a directory instead.
   TmpPathName = D.GetTemporaryDirectory("thinlto");

lgrey: Do you think this should interact with 
134275d994d5fb38edfeb587ba45c8f495c8bf66 in any way, or should have any other 
interesting side effects?

From what I understand, it tells the linker to put temporary files created for 
LTO in the given directory, but then the clang driver cleans up that directory 
when it exits (potentially after running dsymutil). But most people run 
dsymutil later, separately, so I think there should be no interactions there.


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

https://reviews.llvm.org/D119612

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


[PATCH] D119613: [OpenMP] Add support for CPU offloading in new driver

2022-02-11 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
jhuber6 added projects: OpenMP, clang.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.

This patch adds support for linking CPU offloading applications in the
linker wrapper. We generate the necessary linking job using the host
linker's path and library arguments. This may not be true for more
complex offloading schemes, but this is sufficient for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119613

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -646,6 +646,83 @@
 }
 } // namespace amdgcn
 
+namespace generic {
+
+const char *getLDMOption(const llvm::Triple &T) {
+  switch (T.getArch()) {
+  case llvm::Triple::x86:
+if (T.isOSIAMCU())
+  return "elf_iamcu";
+return "elf_i386";
+  case llvm::Triple::aarch64:
+return "aarch64linux";
+  case llvm::Triple::aarch64_be:
+return "aarch64linuxb";
+  case llvm::Triple::ppc64:
+return "elf64ppc";
+  case llvm::Triple::ppc64le:
+return "elf64lppc";
+  case llvm::Triple::x86_64:
+if (T.isX32())
+  return "elf32_x86_64";
+return "elf_x86_64";
+  case llvm::Triple::ve:
+return "elf64ve";
+  default:
+return nullptr;
+  }
+}
+
+Expected link(ArrayRef InputFiles, Triple TheTriple,
+   StringRef Arch) {
+  // Create a new file to write the linked device image to.
+  SmallString<128> TempFile;
+  if (Error Err = createOutputFile(sys::path::filename(ExecutableName) + "-" +
+   TheTriple.getArchName() + "-" + Arch,
+   "out", TempFile))
+return std::move(Err);
+
+  // Use the host linker to perform generic offloading. Use the same libraries
+  // and paths as the host application does.
+  SmallVector CmdArgs;
+  CmdArgs.push_back(LinkerUserPath);
+  CmdArgs.push_back("-m");
+  CmdArgs.push_back(getLDMOption(TheTriple));
+  CmdArgs.push_back("-shared");
+  for (auto AI = HostLinkerArgs.begin(), AE = HostLinkerArgs.end(); AI != AE;
+   ++AI) {
+StringRef Arg = *AI;
+if (Arg.startswith("-L"))
+  CmdArgs.push_back(Arg);
+else if (Arg.startswith("-l"))
+  CmdArgs.push_back(Arg);
+else if (Arg.startswith("--as-needed"))
+  CmdArgs.push_back(Arg);
+else if (Arg.startswith("--no-as-needed"))
+  CmdArgs.push_back(Arg);
+else if (Arg.startswith("-rpath")) {
+  CmdArgs.push_back(Arg);
+  CmdArgs.push_back(*(AI + 1));
+} else if (Arg.startswith("-dynamic-linker")) {
+  CmdArgs.push_back(Arg);
+  CmdArgs.push_back(*(AI + 1));
+}
+  }
+  CmdArgs.push_back("-Bsymbolic");
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(TempFile);
+
+  // Add extracted input files.
+  for (StringRef Input : InputFiles)
+CmdArgs.push_back(Input);
+
+  if (sys::ExecuteAndWait(LinkerUserPath, CmdArgs))
+return createStringError(inconvertibleErrorCode(), "'linker' failed");
+
+  return static_cast(TempFile);
+}
+} // namespace generic
+
 Expected linkDevice(ArrayRef InputFiles,
  Triple TheTriple, StringRef Arch) {
   switch (TheTriple.getArch()) {
@@ -656,7 +733,11 @@
 return amdgcn::link(InputFiles, TheTriple, Arch);
   case Triple::x86:
   case Triple::x86_64:
-// TODO: x86 linking support.
+  case Triple::aarch64:
+  case Triple::aarch64_be:
+  case Triple::ppc64:
+  case Triple::ppc64le:
+return generic::link(InputFiles, TheTriple, Arch);
   default:
 return createStringError(inconvertibleErrorCode(),
  TheTriple.getArchName() +
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119612: [clang] Pass more flags to ld64.lld

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added subscribers: ormris, steven_wu, hiraditya.
thakis requested review of this revision.

- ld64.lld now completely supports -export_dynamic (D119372 
), so map -rdynamic to -export_dynamic like 
already done for ld64

- ld64.lld has been supporting -object_path_lto for well over a year (D92537 
), so pass it like already done for ld64

- ld64.lld has been doing ICF for a while, so pass -no_deduplicate in -O0 and 
-O1 builds like already done for ld64


https://reviews.llvm.org/D119612

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld-dedup.c
  clang/test/Driver/darwin-ld-lto.c
  clang/test/Driver/darwin-ld.c

Index: clang/test/Driver/darwin-ld.c
===
--- clang/test/Driver/darwin-ld.c
+++ clang/test/Driver/darwin-ld.c
@@ -235,6 +235,8 @@
 
 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
 // RUN:   -fuse-ld= -mlinker-version=137 2> %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
+// RUN:   -fuse-ld=lld -mlinker-version=100 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_EXPORT_DYNAMIC %s < %t.log
 // LINK_EXPORT_DYNAMIC: {{ld(.exe)?"}}
 // LINK_EXPORT_DYNAMIC: "-export_dynamic"
Index: clang/test/Driver/darwin-ld-lto.c
===
--- clang/test/Driver/darwin-ld-lto.c
+++ clang/test/Driver/darwin-ld-lto.c
@@ -20,13 +20,17 @@
 
 
 // Check that -object_lto_path is passed correctly to ld64
-// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \
-// RUN:   FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 %s -flto=full -### \
+// RUN: 2>&1 | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld=lld -target x86_64-apple-darwin10 %s -flto=full -### \
+// RUN: 2>&1 | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
 // FULL_LTO_OBJECT_PATH: {{ld(.exe)?"}}
 // FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto"
 // FULL_LTO_OBJECT_PATH-SAME: {{cc\-[a-zA-Z0-9_]+.o}}"
-// RUN: %clang -target x86_64-apple-darwin10 %s -flto=thin -### 2>&1 | \
-// RUN:   FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 %s -flto=thin -### \
+// RUN: 2>&1 | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld=lld -target x86_64-apple-darwin10 %s -flto=thin -### \
+// RUN: 2>&1 | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
 // THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}}
 // THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto"
 // THIN_LTO_OBJECT_PATH-SAME: {{thinlto\-[a-zA-Z0-9_]+}}
Index: clang/test/Driver/darwin-ld-dedup.c
===
--- clang/test/Driver/darwin-ld-dedup.c
+++ clang/test/Driver/darwin-ld-dedup.c
@@ -1,42 +1,58 @@
 // REQUIRES: system-darwin
 
-// -no_deduplicate is only present from ld64 version 262 and later.
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// -no_deduplicate is only present from ld64 version 262 and later, or lld.
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=261 -O0 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
 
 // Add -no_deduplicate when either -O0 or -O1 is explicitly specified
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O0 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=261 -O0 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O1 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=261 -O1 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
 
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O2 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=262 -O2 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O3 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -Os 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang

[PATCH] D119221: [clang][lexer] Allow u8 character literal prefixes in C2x

2022-02-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3462
 
-  case 'u':   // Identifier (uber) or C11/C++11 UTF-8 or UTF-16 string literal
+  case 'u': // Identifier (uber) or C11/C2x/C++11 UTF-8 or UTF-16 string 
literal
 // Notify MIOpt that we read a non-whitespace/non-comment token.

The comment is slightly misleading both before and after this change. Assuming 
this level of detail is desired, I suggest:
  // Identifer (e.g., uber), or
  // UTF-8 (C2x/C++17) or UTF-16 (C11/C++11) character literal, or
  // UTF-8 or UTF-16 string literal (C11/C++11).
  case 'u':



Comment at: clang/test/Lexer/utf8-char-literal.cpp:23
+char f = u8'ab';// expected-error {{Unicode character literals may 
not contain multiple characters}}
+char g = u8'\x80';  // expected-warning {{implicit conversion from 
'int' to 'char' changes value from 128 to -128}}
 #endif

aaron.ballman wrote:
> One more test I'd like to see added, just to make sure we're covering 
> 6.4.4.4p9 properly:
> ```
> _Static_assert(
>   _Generic(u8'a',
>default: 0,
>unsigned char : 1),
>   "Surprise!");  
> ```
> We expect the type of a u8 character literal to be `unsigned char` at the 
> moment, which is different from a u8 string literal, which uses `char`.
> 
> However, WG14 is also going to be considering 
> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm for C2x at our 
> meeting next week.
Good suggestion. I believe the following update will be needed 
to`Sema::ActOnCharacterConstant()` in `clang/lib/Sema/SemaExpr.cpp`:
  ...
  else if (Literal.isUTF8() && getLangOpts().C2x)
Ty = Context.UnsignedCharTy; // u8'x' -> unsigned char in c2x.
  else if Literal.isUTF8() && getLangOpts().Char8)
Ty = Context.Char8Ty; // u8'x' -> char8_t when it exists.
  ...




Comment at: clang/test/Lexer/utf8-char-literal.cpp:24
+char g = u8'\x80';  // expected-warning {{implicit conversion from 
'int' to 'char' changes value from 128 to -128}}
 #endif

We should also exercise the preprocessor with something like this:
  #if u8'\xff' != 0xff
  #error uh oh
  #endif

Hmm, this currently fails for C++20 for both Clang and gcc unless 
`-funsigned-char` is passed. That seems wrong. https://godbolt.org/z/Tb7z85ToG. 
MSVC gets this wrong too, but I think for a different reason; see the 
implementation impact section of [[ https://wg21.link/p2029 | P2029 ]] if 
curious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119221

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


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2022-02-11 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 408137.
lichray added a comment.

Rerun pre-merge checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Basic/CharInfo.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/cxx2a-nttp-printing.cpp
  clang/test/SemaTemplate/temp_arg_string_printing.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -80,3 +80,34 @@
  varDecl(hasType(qualType().bind("id"))),
  "const f *", Clean));
 }
+
+TEST(TypePrinter, TemplateIdWithNTTP) {
+  constexpr char Code[] = R"cpp(
+template 
+struct Str {
+  constexpr Str(char const (&s)[N]) { __builtin_memcpy(value, s, N); }
+  char value[N];
+};
+template  class ASCII {};
+
+ASCII<"this nontype template argument is too long to print"> x;
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(
+  hasName("ASCII"), has(cxxConstructorDecl(
+isMoveConstructor(),
+has(parmVarDecl(hasType(qualType().bind("id")));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is [...]"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = false;
+  }));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII<{"this nontype template argument is too long to print"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.EntireContentsOfLargeArray = true;
+  }));
+}
Index: clang/test/SemaTemplate/temp_arg_string_printing.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_string_printing.cpp
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-print %s | FileCheck %s
+
+using size_t = __SIZE_TYPE__;
+static_assert(__has_builtin(__make_integer_seq));
+
+template  class idx_seq {};
+template  using make_idx_seq = __make_integer_seq;
+
+template 
+struct Str {
+  constexpr Str(CharT const (&s)[N]) : Str(s, make_idx_seq()) {}
+  CharT value[N];
+
+private:
+  template 
+  constexpr Str(CharT const (&s)[N], idx_seq) : value{s[I]...} {}
+};
+
+template  class ASCII {};
+
+void not_string() {
+  // CHECK{LITERAL}: ASCII<{{9, -1, 42}}>
+  new ASCII<(int[]){9, -1, 42}>;
+  // CHECK{LITERAL}: ASCII<{{3.14e+00, 0.00e+00, 4.20e+01}}>
+  new ASCII<(double[]){3.14, 0., 42.}>;
+}
+
+void narrow() {
+  // CHECK{LITERAL}: ASCII<{""}>
+  new ASCII<"">;
+  // CHECK{LITERAL}: ASCII<{"the quick brown fox jumps"}>
+  new ASCII<"the quick brown fox jumps">;
+  // CHECK{LITERAL}: ASCII<{"OVER THE LAZY DOG 0123456789"}>
+  new ASCII<"OVER THE LAZY DOG 0123456789">;
+  // CHECK{LITERAL}: ASCII<{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
+  new ASCII?/)">;
+  // CHECK{LITERAL}: ASCII<{{101, 115, 99, 97, 112, 101, 0, 0}}>
+  new ASCII<"escape\0">;
+  // CHECK{LITERAL}: ASCII<{"escape\r\n"}>
+  new ASCII<"escape\r\n">;
+  // CHECK{LITERAL}: ASCII<{"escape\\\t\f\v"}>
+  new ASCII<"escape\\\t\f\v">;
+  // CHECK{LITERAL}: ASCII<{"escape\a\bc"}>
+  new ASCII<"escape\a\b\c">;
+  // CHECK{LITERAL}: ASCII<{{110, 111, 116, 17, 0}}>
+  new ASCII<"not\x11">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abc">;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, 0}}>
+  new ASCII<"\x12\x14\x7f\x10\x01 abcd">;
+  // CHECK{LITERAL}: ASCII<{"print more characters as string"}>
+  new ASCII<"print more characters as string">;
+  // CHECK{LITERAL}: ASCII<{"print more characters as string, no uplimit"}>
+  new ASCII<"print more characters as string, no uplimit">;
+}
+
+void wide() {
+  // CHECK{LITERAL}: ASCII<{L""}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"the quick brown fox jumps"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"OVER THE LAZY DOG 0123456789"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
+  new ASCII?/)">;
+  // CHECK{LITERAL}: ASCII<{{101, 115, 99, 97, 112, 101, 0, 0}}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"escape\r\n"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"escape\\\t\f\v"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{L"escape\a\bc"}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{{110, 111, 116, 17, 0}}>
+  new ASCII;
+  // CHECK{LITERAL}: ASCII<{{18, 20, 255, 22909, 136, 32, 97,

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408134.
junaire added a comment.

Add missing blank.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___
cfe-commits mail

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408133.
junaire added a comment.

long double should use `L` as literal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___
cf

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

> I think we should probably have test coverage for `long double` as well, but 
> I also wonder whether it makes sense to add coverage for the small 
> floating-point types (like `_Float16`) as well, or whether we already have 
> coverage for those elsewhere.

Test long double is fine for me. But I'm not really sure if we need to test for 
these half-precision floats, as they are part of clang language extension and 
not supported in all targets. IMHO, maybe we can just simply test these normal 
or standard floats first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408129.
junaire added a comment.

Add tests for long double.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of 
floating-point constant too small for type 'double'; minimum is 
4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of 
floating-point constant too large for type 'double'; maximum is 
1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commit

[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-02-11 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

Mmm... just realized that this check should invalidate any macro
that is used in a conditional compilation expression, because enums
can't be used there.


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

https://reviews.llvm.org/D117522

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


[PATCH] D119609: [Clang][Sema] Don't act on ReturnStmt when parsing the lambda declarator.

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, rsmith.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang will try to act on ReturnStmt when parsing the lambda declarator,
which is not desirable. LambdaScopeInfo is nonnull doesn't the lambda has
been built, we should also check LambdaScopeInfo->Lambda.

Fixes #issue53488(https://github.com/llvm/llvm-project/issues/53488)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119609

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/returnstmt-in-lambda-declarator.cpp


Index: clang/test/Sema/returnstmt-in-lambda-declarator.cpp
===
--- /dev/null
+++ clang/test/Sema/returnstmt-in-lambda-declarator.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+void g() {
+  auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot 
initialize a parameter of type 'char' with an rvalue of type 'void'}} 
expected-note {{passing argument to parameter 'c' here}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3560,6 +3560,10 @@
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+
+  if (CurLambda && !CurLambda->Lambda)
+return StmtError();
+
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 


Index: clang/test/Sema/returnstmt-in-lambda-declarator.cpp
===
--- /dev/null
+++ clang/test/Sema/returnstmt-in-lambda-declarator.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+void g() {
+  auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot initialize a parameter of type 'char' with an rvalue of type 'void'}} expected-note {{passing argument to parameter 'c' here}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3560,6 +3560,10 @@
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+
+  if (CurLambda && !CurLambda->Lambda)
+return StmtError();
+
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 408116.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D119574: [clang] Expose -fprofile-use in clang-cl

2022-02-11 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

Hi,

I think we hit a test failure due to this patch in Fuchsia's Clang canary for 
Windows. We've had a lot of breakages on Windows today, so this was hidden 
until 0574b5fc 
 landed.

The failing test is: Clang :: Driver/cl-options.c

The failing bot can be found here: 
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8822483567668224209/overview


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119574

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


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-02-11 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 408104.
vabridgers added a comment.

Update after makeNull fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/cstring-addrspace.c

Index: clang/test/Analysis/cstring-addrspace.c
===
--- /dev/null
+++ clang/test/Analysis/cstring-addrspace.c
@@ -0,0 +1,64 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
+// RUN: -Wno-incompatible-library-redeclaration
+// REQUIRES: z3
+
+void clang_analyzer_warnIfReached();
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+_Static_assert(sizeof(int *) == 8, "");
+_Static_assert(sizeof(DEVICE int *) == 4, "");
+_Static_assert(sizeof(void *) == 8, "");
+_Static_assert(sizeof(DEVICE void *) == 4, "");
+
+// Copy from host to device memory. Note this is specialized
+// since one of the parameters is assigned an address space such
+// that the sizeof the the pointer is different than the other.
+//
+// Some downstream implementations may have specialized memcpy
+// routines that copy from one address space to another. In cases
+// like that, the address spaces are assumed to not overlap, so the
+// cstring overlap check is not needed. When a static analysis report
+// is generated in as case like this, SMTConv may attempt to create
+// a refutation to Z3 with different bitwidth pointers which lead to
+// a crash. This is not common in directly used upstream compiler builds,
+// but can be seen in specialized downstrean implementations. This case
+// covers those specific instances found and debugged.
+//
+// Since memcpy is a builtin, a specialized builtin instance named like
+// 'memcpy_special' will hit in cstring, triggering this behavior. The
+// best we can do for an upstream test is use the same memcpy function name.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+
+void top1(DEVICE void *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top2(DEVICE int *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top3(DEVICE int *dst, int *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top4() {
+  memcpy((DEVICE void *)1, (const void *)1, 1);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -715,11 +715,35 @@
   llvm_unreachable("Fields not found in parent record's definition");
 }
 
+static bool assertEqualBitWidths(ProgramStateRef State, Loc RhsLoc,
+ Loc LhsLoc) {
+  // Implements a "best effort" check for RhsLoc and LhsLoc bit widths
+  ASTContext &Ctx = State->getStateManager().getContext();
+  uint64_t RhsBitwidth =
+  RhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(RhsLoc.getType(Ctx));
+  uint64_t LhsBitwidth =
+  LhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(LhsLoc.getType(Ctx));
+  if (RhsBitwidth && LhsBitwidth &&
+  (LhsLoc.getSubKind() == RhsLoc.getSubKind())) {
+assert(RhsBitwidth == LhsBitwidth &&
+   "RhsLoc and LhsLoc bitwidth must be same!");
+return RhsBitwidth == LhsBitwidth;
+  }
+  return false;
+}
+
 // FIXME: all this logic will change if/when we have MemRegion::getLocation().
 SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
   BinaryOperator::Opcode op,
   Loc lhs, Loc rhs,
   QualType resultTy) {
+
+  // Assert that bitwidth of lhs and rhs are the same.
+  // This can happen if two different address spaces are used,
+  // and the bitwidths of the address spaces are different.
+  // See LIT case clang/test/Analysis/cstring-checker-addressspace.c
+  assertEqualBitWidths(state, rhs, lhs);
+
   // Only comparisons and subtractions are valid operations on two p

[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-11 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray marked 2 inline comments as done.
lichray added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2396
+def ext_decltype_auto_expr : ExtWarn<
+  "ISO C++23 DIS does not allow functional-style cast to 'decltype(auto)'">,
+  InGroup>;

aaron.ballman wrote:
> Is there a reason this one should be `ExtWarn` instead of `Extension`? (I 
> think we typically only issue this kind of diagnostic when `-pedantic` is 
> specified.)
I took a look at other warnings. It seems that Clang believes that a portable 
program can contain `Extension`s; if `ExtWarn` is issued, the program is not 
likely to be portable.

I asked GCC folks yesterday to see if they want to implement this extension, 
and they are not interested. So I guess `ExtWarn` is suitable for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

I'm not exactly sure why, but this change seems to be causing the 
Driver/cl-options.c test to fail on the PS4 Windows bot:

https://lab.llvm.org/staging/#/builders/204/builds/1343

It was also failing previously after the original commit until it was reverted 
at which point it started to pass again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 408097.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:store i

[PATCH] D119590: exclude openembedded distributions from setting rpath on openmp executables

2022-02-11 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Cross compilers are a hazard here. I'd expect there to be a fairly long list of 
magic flags you need to pass to clang to get it to find the right libraries. 
Can you add fno-openmp-implicit-rpath to that list instead?

A better solution might be a cmake flag to specify where to use for the 
implicit rpath directory instead of deriving it from sys::path::parent_path. 
That would let your target set up a cross compiling toolchain that creates 
binaries that are able to find libomp et al in whatever directory they're 
located, without assuming a whole llvm toolchain installed onto the target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119590

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


[PATCH] D117348: [Preprocessor] Reduce the memory overhead of `#define` directives

2022-02-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Revert:

To github.com:llvm/llvm-project.git

  bdf573652138..3f05192c4c40  main -> main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117348

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


[clang] 3f05192 - Revert "[Preprocessor] Reduce the memory overhead of `#define` directives"

2022-02-11 Thread Alex Lorenz via cfe-commits

Author: Alex Lorenz
Date: 2022-02-11T15:53:16-08:00
New Revision: 3f05192c4c40bc79b1db431a7a36baaa9491eebb

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

LOG: Revert "[Preprocessor] Reduce the memory overhead of `#define` directives"

This reverts commit 0d9b91524ea4db3760791bba15773c386a26d8ec.

This change broke LLDB's build. I will need to recommit after fixing LLDB.

Added: 


Modified: 
clang/include/clang/Lex/MacroInfo.h
clang/lib/Lex/MacroInfo.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/unittests/Lex/CMakeLists.txt

Removed: 
clang/unittests/Lex/PPMemoryAllocationsTest.cpp



diff  --git a/clang/include/clang/Lex/MacroInfo.h 
b/clang/include/clang/Lex/MacroInfo.h
index 1947bc8fc509e..0347a7a37186b 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -54,14 +54,11 @@ class MacroInfo {
   /// macro, this includes the \c __VA_ARGS__ identifier on the list.
   IdentifierInfo **ParameterList = nullptr;
 
-  /// This is the list of tokens that the macro is defined to.
-  const Token *ReplacementTokens = nullptr;
-
   /// \see ParameterList
   unsigned NumParameters = 0;
 
-  /// \see ReplacementTokens
-  unsigned NumReplacementTokens = 0;
+  /// This is the list of tokens that the macro is defined to.
+  SmallVector ReplacementTokens;
 
   /// Length in characters of the macro definition.
   mutable unsigned DefinitionLength;
@@ -233,47 +230,26 @@ class MacroInfo {
   bool isWarnIfUnused() const { return IsWarnIfUnused; }
 
   /// Return the number of tokens that this macro expands to.
-  unsigned getNumTokens() const { return NumReplacementTokens; }
+  unsigned getNumTokens() const { return ReplacementTokens.size(); }
 
   const Token &getReplacementToken(unsigned Tok) const {
-assert(Tok < NumReplacementTokens && "Invalid token #");
+assert(Tok < ReplacementTokens.size() && "Invalid token #");
 return ReplacementTokens[Tok];
   }
 
-  using const_tokens_iterator = const Token *;
+  using tokens_iterator = SmallVectorImpl::const_iterator;
 
-  const_tokens_iterator tokens_begin() const { return ReplacementTokens; }
-  const_tokens_iterator tokens_end() const {
-return ReplacementTokens + NumReplacementTokens;
-  }
-  bool tokens_empty() const { return NumReplacementTokens == 0; }
-  ArrayRef tokens() const {
-return llvm::makeArrayRef(ReplacementTokens, NumReplacementTokens);
-  }
+  tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
+  tokens_iterator tokens_end() const { return ReplacementTokens.end(); }
+  bool tokens_empty() const { return ReplacementTokens.empty(); }
+  ArrayRef tokens() const { return ReplacementTokens; }
 
-  llvm::MutableArrayRef
-  allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator) {
-assert(ReplacementTokens == nullptr && NumReplacementTokens == 0 &&
-   "Token list already allocated!");
-NumReplacementTokens = NumTokens;
-Token *NewReplacementTokens = PPAllocator.Allocate(NumTokens);
-ReplacementTokens = NewReplacementTokens;
-return llvm::makeMutableArrayRef(NewReplacementTokens, NumTokens);
-  }
-
-  void setTokens(ArrayRef Tokens, llvm::BumpPtrAllocator &PPAllocator) {
+  /// Add the specified token to the replacement text for the macro.
+  void AddTokenToBody(const Token &Tok) {
 assert(
 !IsDefinitionLengthCached &&
 "Changing replacement tokens after definition length got calculated");
-assert(ReplacementTokens == nullptr && NumReplacementTokens == 0 &&
-   "Token list already set!");
-if (Tokens.empty())
-  return;
-
-NumReplacementTokens = Tokens.size();
-Token *NewReplacementTokens = PPAllocator.Allocate(Tokens.size());
-std::copy(Tokens.begin(), Tokens.end(), NewReplacementTokens);
-ReplacementTokens = NewReplacementTokens;
+ReplacementTokens.push_back(Tok);
   }
 
   /// Return true if this macro is enabled.

diff  --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp
index f5702130d1819..1ccd140364aeb 100644
--- a/clang/lib/Lex/MacroInfo.cpp
+++ b/clang/lib/Lex/MacroInfo.cpp
@@ -28,25 +28,6 @@
 
 using namespace clang;
 
-namespace {
-
-// MacroInfo is expected to take 40 bytes on platforms with an 8 byte pointer
-// and 4 byte SourceLocation.
-template  class MacroInfoSizeChecker {
-public:
-  constexpr static bool AsExpected = true;
-};
-template <> class MacroInfoSizeChecker<8> {
-public:
-  constexpr static bool AsExpected =
-  sizeof(MacroInfo) == (32 + sizeof(SourceLocation) * 2);
-};
-
-static_assert(MacroInfoSizeChecker::AsExpected,
-  "Unexpected size of MacroInfo");
-
-} // end namespace
-
 MacroInfo::MacroInfo(Sou

[PATCH] D117348: [Preprocessor] Reduce the memory overhead of `#define` directives

2022-02-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Yep, I just noticed. Reverting for now and will fix LLDB before recommitting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117348

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


[PATCH] D117348: [Preprocessor] Reduce the memory overhead of `#define` directives

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Very cool! Looks like it broke lldb builds though: 
http://45.33.8.238/linux/68321/step_4.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117348

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D119051#3315747 , @rjmccall wrote:

> And this should be raised as an Itanium issue.

Ah, looks like this is the existing 
https://github.com/itanium-cxx-abi/cxx-abi/issues/66


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth

2022-02-11 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: NoQ, martong.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Usages of makeNull need to be deprecated in favor of makeNullWithWidth
for architectures where the pointer size should not be assumed. This can
occur when pointer sizes can be of different sizes, depending on address
space for example. See https://reviews.llvm.org/D118050 as an example.

This was uncovered initially in a downstream compiler project, and
tested through those systems tests.

steakhal performed systems testing across a large set of open source
projects.

Co-authored-by: steakhal
Resolves: https://github.com/llvm/llvm-project/issues/53664


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119601

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -61,7 +61,7 @@
 
 DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
   if (Loc::isLocType(type))
-return makeNull();
+return makeNullWithType(type);
 
   if (type->isIntegralOrEnumerationType())
 return makeIntVal(0, type);
@@ -359,7 +359,7 @@
 return makeBoolVal(cast(E));
 
   case Stmt::CXXNullPtrLiteralExprClass:
-return makeNull();
+return makeNullWithType(E->getType());
 
   case Stmt::CStyleCastExprClass:
   case Stmt::CXXFunctionalCastExprClass:
@@ -399,7 +399,7 @@
 
 if (Loc::isLocType(E->getType()))
   if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
-return makeNull();
+return makeNullWithType(E->getType());
 
 return None;
   }
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2410,7 +2410,7 @@
   SVal V;
 
   if (Loc::isLocType(T))
-V = svalBuilder.makeNull();
+V = svalBuilder.makeNullWithType(T);
   else if (T->isIntegralOrEnumerationType())
 V = svalBuilder.makeZeroVal(T);
   else if (T->isStructureOrClassType() || T->isArrayType()) {
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -460,7 +460,8 @@
 continue;
   } else {
 // If the cast fails on a pointer, bind to 0.
-state = state->BindExpr(CastE, LCtx, svalBuilder.makeNull());
+state = state->BindExpr(CastE, LCtx,
+svalBuilder.makeNullWithType(resultType));
   }
 } else {
   // If we don't know if the cast succeeded, conjure a new symbol.
@@ -498,7 +499,7 @@
 continue;
   }
   case CK_NullToPointer: {
-SVal V = svalBuilder.makeNull();
+SVal V = svalBuilder.makeNullWithType(CastE->getType());
 state = state->BindExpr(CastE, LCtx, V);
 Bldr.generateNode(CastE, Pred, state);
 continue;
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -549,8 +549,9 @@
   State->BindExpr(CE, C.getLocationContext(), *StreamVal);
   // Generate state for NULL return value.
   // Stream switches to OpenFailed state.
-  ProgramStateRef StateRetNull = State->BindExpr(CE, C.getLocationContext(),
- C.getSValBuilder().makeNull());
+  ProgramStateRef StateRetNull =
+  State->BindExpr(CE, C.getLocationContext(),
+  C.getSValBuilder().makeNullWithType(CE->getType()));
 
   StateRetNotNull =
   StateRetNotNull->set(StreamSym, StreamState::getOpened(Desc));
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrMod

[PATCH] D118986: [clang][deps] Return the whole TU command line

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

This does require build systems to be able to totally replace a command line 
rather than just add to it, but it seems like that's a requirement unless we 
add a way to modify the command line to Clang. lgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118986

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


[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

2022-02-11 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 408079.
lichray added a comment.

- Rephrase a warning message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113393

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.auto.deduct/p2.cpp
  clang/test/CXX/expr/expr.post/expr.type.conv/p1-2b.cpp
  clang/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
  clang/test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
  clang/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
  clang/test/Parser/cxx2b-auto-x.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1388,6 +1388,11 @@
   https://wg21.link/P2360R0";>P2360R0
   Clang 14
 
+
+  auto(x): decay-copy in the language
+  https://wg21.link/P0849R8";>P0849R8
+  Clang 15
+
 
 
   Attributes on Lambda-Expressions
Index: clang/test/SemaCXX/deduced-return-type-cxx14.cpp
===
--- clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -442,6 +442,15 @@
   B() : decltype(auto)() {} // expected-error {{'decltype(auto)' not allowed here}}
 };
   }
+
+  namespace Cast {
+void foo() {
+  (void)decltype(auto)(0); // cxx14_20-error{{'decltype(auto)' not allowed here}} \
+  cxx2b-warning{{functional-style cast to 'decltype(auto)' is a Clang extension}}
+  (void)decltype(auto){0}; // cxx14_20-error{{'decltype(auto)' not allowed here}} \
+  cxx2b-warning{{functional-style cast to 'decltype(auto)' is a Clang extension}}
+}
+  }
 }
 
 namespace CurrentInstantiation {
Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+void looks_like_decltype_auto() {
+  decltype(auto(42)) b = 42; // cxx20-error {{'auto' not allowed here}} \
+cxx2b-warning {{'auto' as a functional-style cast is incompatible with C++ standards before C++2b}}
+  decltype(long *) a = 42;   // expected-error {{expected '(' for function-style cast or type construction}} \
+expected-error {{expected expression}}
+  decltype(auto *) a = 42;   // expected-error {{expected '(' for function-style cast or type construction}} \
+expected-error {{expected expression}}
+  decltype(auto()) c = 42;   // cxx2b-error {{initializer for functional-style cast to 'auto' is empty}} \
+cxx20-error {{'auto' not allowed here}}
+}
+
+struct looks_like_declaration {
+  int n;
+} a;
+
+using T = looks_like_declaration *;
+void f() { T(&a)->n = 1; }
+// FIXME: They should be deemed expressions without breaking function pointer
+//parameter declarations with trailing return types.
+// void g() { auto(&a)->n = 0; }
+// void h() { auto{&a}->n = 0; }
Index: clang/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
===
--- clang/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
+++ clang/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
@@ -1,11 +1,30 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++17 -pedantic
 
+// [expr.new]p2 ... the invented declaration: T x init ;
+// C++2b [dcl.type.auto.deduct]p2.2
+// For a variable declared with a type that contains a placeholder type, T is the declared type of the variable.
 void f() {
+  // - If the initializer is a parenthesized expression-list, the expression-list shall be a single assignmentexpression and E is the assignment-expression.
   new auto('a');
-  new auto {2};
-  new auto {1, 2}; // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
-  new auto {}; // expected-error{{new expression for type 'auto' requires a constructor argument}}
-  new decltype(auto)({1});
-  new decltype(auto)({1, 2}); // expected-error{{new expression for type 'decltype(auto)' contains multiple constructor arguments}}
+  new decltype(auto)('a');
+  // - If the initializer is a braced-init-list, it shall consist of a single brace-enclosed assi

[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Thanks for chiming in!

In D119051#3315741 , @rjmccall wrote:

> Changing the C++03 POD definition is going to be substantially ABI-breaking 
> at this point.  Any logic to change it needs to be platform-specific.

Even if it's only related to the use of "= default"? Hrm. Got some examples I 
could try out?

Ah, I guess here: https://godbolt.org/z/P6n9xKTnM

  struct t1 {
int i;
char c;
t1() = default;
  };
  struct t2: t1 {
char c;
  };
  #ifdef __clang__
  static_assert(sizeof(t2) == 8, "");
  #else
  static_assert(sizeof(t2) == 12, "");
  #endif

Where would be the right place for the platform specific detection to happen 
then? Can the places I've proposed changing in DeclCXX.cpp be made 
target-specific there, or do we have to compute two different properties there 
and do the target-specific selection between them at some later point/in the 
record layout logic?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119600: Stricter use-after-dtor detection for trivial members.

2022-02-11 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis created this revision.
eugenis added reviewers: vitalybuka, kda.
eugenis requested review of this revision.
Herald added a project: clang.

Poison trivial class members one-by-one in the reverse order of their
construction, instead of all-at-once at the very end.

For example, in the following code access to `x` from `~B` will
produce an undefined value.

struct A {

  struct B b;
  int x;

};


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119600

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
  clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp

Index: clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
===
--- clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
+++ clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
@@ -44,7 +44,9 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T1
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T16StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK: [[GEP:%.+]] = getelementptr i8, {{.*}}, i64 8{{$}}
+// CHECK: call void @__sanitizer_dtor_callback(i8* [[GEP]], i64 13)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
 // CHECK-NEXT:ret void
 
 namespace T2 {
@@ -57,8 +59,11 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T2
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T26StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
+// CHECK: [[GEP1:%.+]] = getelementptr i8, {{.*}}, i64 16{{$}}
+// CHECK: call void @__sanitizer_dtor_callback(i8* [[GEP1]], i64 5)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
+// CHECK: [[GEP2:%.+]] = getelementptr i8, {{.*}}, i64 0{{$}}
+// CHECK: call void @__sanitizer_dtor_callback(i8* [[GEP2]], i64 8)
 // CHECK-NEXT:ret void
 
 namespace T3 {
@@ -71,8 +76,11 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T3
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T36StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
+// CHECK: [[GEP1:%.+]] = getelementptr i8, {{.*}}, i64 20{{$}}
+// CHECK: call void @__sanitizer_dtor_callback(i8* [[GEP1]], i64 1)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
+// CHECK: [[GEP2:%.+]] = getelementptr i8, {{.*}}, i64 0{{$}}
+// CHECK: call void @__sanitizer_dtor_callback(i8* [[GEP2]], i64 12)
 // CHECK-NEXT:ret void
 
 namespace T4 {
@@ -100,6 +108,7 @@
 } // namespace T5
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T56StructD2Ev(
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
 // CHECK-NEXT:ret void
 
 namespace T6 {
@@ -114,6 +123,7 @@
 } // namespace T6
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T66StructD2Ev(
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
 // CHECK-NEXT:ret void
 
 namespace T7 {
@@ -127,8 +137,9 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T7
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T76StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
+// CHECK: call void @_ZN10NonTrivialD1Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
 // CHECK-NEXT:ret void
 
 namespace T8 {
@@ -142,8 +153,8 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T8
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T86StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
 // CHECK-NEXT:ret void
 
 namespace T9 {
@@ -157,8 +168,8 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T9
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T96StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
 // CHECK-NEXT:ret void
 
 namespace T10 {
@@ -172,8 +183,8 @@
 static_assert(sizeof(Struct) == 24);
 } // namespace T10
 // CHECK-LABEL: define {{.*}} @_ZN5empty3T106StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
 // CHECK-NEXT:ret void
 
 namespace T11 {
@@ -202,6 +213,7 @@
 } // namespace T12
 } // namespace empty
 // CHECK-LABEL: 

[PATCH] D119599: Add option to align compound assignments like `+=`

2022-02-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: curdeius, HazardyKnusperkeks.
sstwcw added projects: clang-format, clang-tools-extra.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

About the column limit option in the test AlignConsecutiveDeclarations.
Previously, the test worked when the column limit was set to 0.
However, when the column limit is less than the length of a single line,
the formatter is supposed to give up aligning stuff.  Previously it
aligned things due to a bug.  In the function AlignTokens:

  unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
  
  // If we are restricted by the maximum column width, end the sequence.
  if (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn ||
  CommasBeforeLastMatch != CommasBeforeMatch) {
AlignCurrentSequence();
StartOfSequence = i;
  }

`ChangeMaxColumn` would wrap around 0.  `ChangeMaxColumn < MinColumn`
would fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119599

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16392,6 +16392,23 @@
Alignment));
 }
 
+TEST_F(FormatTest, AlignCompoundAssignments) {
+  FormatStyle Alignment = getLLVMStyle();
+  Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
+  Alignment.AlignCompoundAssignments = true;
+  verifyFormat("aa <= 5;\n"
+   "a   &= 5;\n"
+   "bcd *= 5;\n"
+   "ghtyf   += 5;\n"
+   "dvfvdb  -= 5;\n"
+   "a   /= 5;\n"
+   "vdsvsv  %= 5;\n"
+   "sfdbddfbdfbb^= 5;\n"
+   "dvsdsv  |= 5;\n"
+   "int dsvvdvsdvvv  = 123;",
+   Alignment);
+}
+
 TEST_F(FormatTest, AlignConsecutiveAssignments) {
   FormatStyle Alignment = getLLVMStyle();
   Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive;
@@ -16410,7 +16427,8 @@
   verifyFormat("int a   = method();\n"
"int oneTwoThree = 133;",
Alignment);
-  verifyFormat("a &= 5;\n"
+  verifyFormat("aa <= 5;\n"
+   "a &= 5;\n"
"bcd *= 5;\n"
"ghtyf += 5;\n"
"dvfvdb -= 5;\n"
@@ -16847,9 +16865,11 @@
"double b();",
Alignment);
   unsigned OldColumnLimit = Alignment.ColumnLimit;
-  // We need to set ColumnLimit to zero, in order to stress nested alignments,
-  // otherwise the function parameters will be re-flowed onto a single line.
-  Alignment.ColumnLimit = 0;
+  // We need to set ColumnLimit to a small number, in order to stress
+  // nested alignments, otherwise the function parameters will be
+  // re-flowed onto a single line. It also needs to be wide enough so
+  // that things still get aligned.
+  Alignment.ColumnLimit = 20;
   EXPECT_EQ("inta(int   x,\n"
 " float y);\n"
 "double b(intx,\n"
@@ -19248,12 +19268,13 @@
 TEST_F(FormatTest, ParsesConfigurationBools) {
   FormatStyle Style = {};
   Style.Language = FormatStyle::LK_Cpp;
-  CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
+  CHECK_PARSE_BOOL(AlignCompoundAssignments);
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+  CHECK_PARSE_BOOL(AlignTrailingComments);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -270,7 +270,7 @@
 template 
 static void
 AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
-   unsigned Column, F &&Matches,
+   unsigned Column, unsigned AnchorWidth, F &&Matches,
SmallVector &Changes) {
   bool FoundMatchOnLine = false;
   int Shift = 0;
@@ -329,7 +329,9 @@
 // shifted by the same amount
 if (!FoundMatchOnLine && !SkipMatchCheck && Matches(Changes[i])) {
   FoundMatchOnLine = true;
-  Shift = Column - Changes[i].StartOfTokenColumn;
+  Shift = Column +
+  (AnchorWidth ? AnchorWidth - Changes[i].TokenLength : 0) -
+  Changes[i].StartOfTokenColumn;
   Changes[i].Spaces += Shift;
   // FIXME: This is a workaround that should be remove

[PATCH] D119300: Use-after-dtor detection for trivial base classes.

2022-02-11 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis updated this revision to Diff 408071.
eugenis added a comment.

Fix handling of empty base classes and suppress tail calls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119300

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
  compiler-rt/test/msan/dtor-base-access.cpp

Index: compiler-rt/test/msan/dtor-base-access.cpp
===
--- compiler-rt/test/msan/dtor-base-access.cpp
+++ compiler-rt/test/msan/dtor-base-access.cpp
@@ -9,41 +9,62 @@
 
 class Base {
  public:
-  int *x_ptr;
-  Base(int *y_ptr) {
-// store value of subclass member
-x_ptr = y_ptr;
-  }
-  virtual ~Base();
+   int b;
+   Base() { b = 1; }
+   ~Base();
 };
 
-class Derived : public Base {
- public:
-  int y;
-  Derived():Base(&y) {
-y = 10;
-  }
+class TrivialBaseBefore {
+public:
+  int tb0;
+  TrivialBaseBefore() { tb0 = 1; }
+};
+
+class TrivialBaseAfter {
+public:
+  int tb1;
+  TrivialBaseAfter() { tb1 = 1; }
+};
+
+class Derived : public TrivialBaseBefore, public Base, public TrivialBaseAfter {
+public:
+  int d;
+  Derived() { d = 1; }
   ~Derived();
 };
 
+Derived *g;
+
 Base::~Base() {
-  // ok access its own member
-  assert(__msan_test_shadow(&this->x_ptr, sizeof(this->x_ptr)) == -1);
-  // bad access subclass member
-  assert(__msan_test_shadow(this->x_ptr, sizeof(*this->x_ptr)) != -1);
+  // ok to access its own members and earlier bases
+  assert(__msan_test_shadow(&g->tb0, sizeof(g->tb0)) == -1);
+  assert(__msan_test_shadow(&g->b, sizeof(g->b)) == -1);
+  // not ok to access others
+  assert(__msan_test_shadow(&g->tb1, sizeof(g->tb1)) == 0);
+  assert(__msan_test_shadow(&g->d, sizeof(g->d)) == 0);
 }
 
 Derived::~Derived() {
-  // ok to access its own members
-  assert(__msan_test_shadow(&this->y, sizeof(this->y)) == -1);
-  // ok access base class members
-  assert(__msan_test_shadow(&this->x_ptr, sizeof(this->x_ptr)) == -1);
+  // ok to access everything
+  assert(__msan_test_shadow(&g->tb0, sizeof(g->tb0)) == -1);
+  assert(__msan_test_shadow(&g->b, sizeof(g->b)) == -1);
+  assert(__msan_test_shadow(&g->tb1, sizeof(g->tb1)) == -1);
+  assert(__msan_test_shadow(&g->d, sizeof(g->d)) == -1);
 }
 
 int main() {
-  Derived *d = new Derived();
-  assert(__msan_test_shadow(&d->x_ptr, sizeof(d->x_ptr)) == -1);
-  d->~Derived();
-  assert(__msan_test_shadow(&d->x_ptr, sizeof(d->x_ptr)) != -1);
+  g = new Derived();
+  // ok to access everything
+  assert(__msan_test_shadow(&g->tb0, sizeof(g->tb0)) == -1);
+  assert(__msan_test_shadow(&g->b, sizeof(g->b)) == -1);
+  assert(__msan_test_shadow(&g->tb1, sizeof(g->tb1)) == -1);
+  assert(__msan_test_shadow(&g->d, sizeof(g->d)) == -1);
+
+  g->~Derived();
+  // not ok to access everything
+  assert(__msan_test_shadow(&g->tb0, sizeof(g->tb0)) == 0);
+  assert(__msan_test_shadow(&g->b, sizeof(g->b)) == 0);
+  assert(__msan_test_shadow(&g->tb1, sizeof(g->tb1)) == 0);
+  assert(__msan_test_shadow(&g->d, sizeof(g->d)) == 0);
   return 0;
 }
Index: clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+// Base class has trivial dtor => complete dtor poisons base class memory directly.
+
+class Base {
+ public:
+  int x[4];
+};
+
+class Derived : public Base {
+ public:
+  int y;
+  ~Derived() {
+  }
+};
+
+Derived d;
+
+// Poison members, then poison the trivial base class.
+// CHECK-LABEL: define {{.*}}DerivedD2Ev
+// CHECK: %[[GEP:[0-9a-z]+]] = getelementptr i8, i8* {{.*}}, i64 16
+// CHECK: call void @__sanitizer_dtor_callback{{.*}}%[[GEP]], i64 4
+// CHECK: call void @__sanitizer_dtor_callback{{.*}}, i64 16
+// CHECK: ret void
Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -1666,6 +1666,34 @@
 CGF.EmitNounwindRuntimeCall(Fn, Args);
   }
 
+  /// Poison base class with a trivial destructor.
+  struct SanitizeDtorTrivialBase final : EHScopeStack::Cleanup {
+const CXXRecordDecl *BaseClass;
+bool BaseIsVirtual;
+SanitizeDtorTrivialBase(const CXXRecordDecl *Base, bool BaseIsVirtual)
+: BaseClass(Base), BaseIsVirtual(BaseIsVirtual) {}
+
+void Emit(CodeGenFunction &CGF, Flags flags) override {
+  const CXXRecordDecl *DerivedClass =
+  cast(CGF.CurCodeDecl)->getParent();
+
+  Address Addr = CGF.GetAddressOfDirectBaseInCompleteClass(
+

[PATCH] D117348: [Preprocessor] Reduce the memory overhead of `#define` directives

2022-02-11 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d9b91524ea4: [Preprocessor] Reduce the memory overhead of 
`#define` directives (authored by arphaman).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117348

Files:
  clang/include/clang/Lex/MacroInfo.h
  clang/lib/Lex/MacroInfo.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Index: clang/unittests/Lex/PPMemoryAllocationsTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPMemoryAllocationsTest.cpp
@@ -0,0 +1,97 @@
+//===- unittests/Lex/PPMemoryAllocationsTest.cpp - ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+class PPMemoryAllocationsTest : public ::testing::Test {
+protected:
+  PPMemoryAllocationsTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+TEST_F(PPMemoryAllocationsTest, PPMacroDefinesAllocations) {
+  std::string Source;
+  size_t NumMacros = 100;
+  {
+llvm::raw_string_ostream SourceOS(Source);
+
+// Create a combination of 1 or 3 token macros.
+for (size_t I = 0; I < NumMacros; ++I) {
+  SourceOS << "#define MACRO_ID_" << I << " ";
+  if ((I % 2) == 0)
+SourceOS << "(" << I << ")";
+  else
+SourceOS << I;
+  SourceOS << "\n";
+}
+  }
+
+  std::unique_ptr Buf =
+  llvm::MemoryBuffer::getMemBuffer(Source);
+  SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+  TrivialModuleLoader ModLoader;
+  HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+  Diags, LangOpts, Target.get());
+  Preprocessor PP(std::make_shared(), Diags, LangOpts,
+  SourceMgr, HeaderInfo, ModLoader,
+  /*IILookup =*/nullptr,
+  /*OwnsHeaderSearch =*/false);
+  PP.Initialize(*Target);
+  PP.EnterMainSourceFile();
+
+  while (1) {
+Token tok;
+PP.Lex(tok);
+if (tok.is(tok::eof))
+  break;
+  }
+
+  size_t NumAllocated = PP.getPreprocessorAllocator().getBytesAllocated();
+  float BytesPerDefine = float(NumAllocated) / float(NumMacros);
+  llvm::errs() << "Num preprocessor allocations for " << NumMacros
+   << " #define: " << NumAllocated << "\n";
+  llvm::errs() << "Bytes per #define: " << BytesPerDefine << "\n";
+  // On arm64-apple-macos, we get around 120 bytes per define.
+  // Assume a reasonable upper bound based on that number that we don't want
+  // to exceed when storing information about a macro #define with 1 or 3
+  // tokens.
+  EXPECT_LT(BytesPerDefine, 130.0f);
+}
+
+} // anonymous namespace
Index: clang/unittests/Lex/CMakeLists.txt
===
--- clang/unittests/Lex/CMakeLists.txt
+++ clang/unittests/Lex/CMakeLists.txt
@@ -9,6 +9,7 @@
   LexerTest.cpp
   PPCallbacksTest.cpp
   PPConditionalDirectiveRecordTest.cpp
+  PPMemoryAllocationsTest.cpp
   )
 
 clang_target_link_libraries(LexTests
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2431,6 +2431,7 @@
 AddSourceLocation(MI->getDefinitionEndLoc(), Record);
 Record.push_back(MI->isUsed());
 Record.push_back(MI->isUsedForHeaderGuard());
+Record.push_back(MI->getNumTokens());
 unsig

[clang] 0d9b915 - [Preprocessor] Reduce the memory overhead of `#define` directives

2022-02-11 Thread Alex Lorenz via cfe-commits

Author: Alex Lorenz
Date: 2022-02-11T15:01:10-08:00
New Revision: 0d9b91524ea4db3760791bba15773c386a26d8ec

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

LOG: [Preprocessor] Reduce the memory overhead of `#define` directives

Recently we observed high memory pressure caused by clang during some parallel 
builds.
We discovered that we have several projects that have a large number of #define 
directives
in their TUs (on the order of millions), which caused huge memory consumption 
in clang due
to a lot of allocations for MacroInfo. We would like to reduce the memory 
overhead of
clang for a single #define to reduce the memory overhead for these files, to 
allow us to
reduce the memory pressure on the system during highly parallel builds. This 
change achieves
that by removing the SmallVector in MacroInfo and instead storing the tokens in 
an array
allocated using the bump pointer allocator, after all tokens are lexed.

The added unit test with 100 #define directives illustrates the problem. 
Prior to this
change, on arm64 macOS, clang's PP bump pointer allocator allocated 272007616 
bytes, and
used roughly 272 bytes per #define. After this change, clang's PP bump pointer 
allocator
allocates 120002016 bytes, and uses only roughly 120 bytes per #define.

For an example test file that we have internally with 7.8 million #define 
directives, this
change produces the following improvement on arm64 macOS: Persistent allocation 
footprint for
this test case file as it's being compiled to LLVM IR went down 22% from 5.28 
GB to 4.07 GB
and the total allocations went down 14% from 8.26 GB to 7.05 GB. Furthermore, 
this change
reduced the total number of allocations made by the system for this clang 
invocation from
1454853 to 133663, an order of magnitude improvement.

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

Added: 
clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Modified: 
clang/include/clang/Lex/MacroInfo.h
clang/lib/Lex/MacroInfo.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/unittests/Lex/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Lex/MacroInfo.h 
b/clang/include/clang/Lex/MacroInfo.h
index 0347a7a37186b..1947bc8fc509e 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -54,11 +54,14 @@ class MacroInfo {
   /// macro, this includes the \c __VA_ARGS__ identifier on the list.
   IdentifierInfo **ParameterList = nullptr;
 
+  /// This is the list of tokens that the macro is defined to.
+  const Token *ReplacementTokens = nullptr;
+
   /// \see ParameterList
   unsigned NumParameters = 0;
 
-  /// This is the list of tokens that the macro is defined to.
-  SmallVector ReplacementTokens;
+  /// \see ReplacementTokens
+  unsigned NumReplacementTokens = 0;
 
   /// Length in characters of the macro definition.
   mutable unsigned DefinitionLength;
@@ -230,26 +233,47 @@ class MacroInfo {
   bool isWarnIfUnused() const { return IsWarnIfUnused; }
 
   /// Return the number of tokens that this macro expands to.
-  unsigned getNumTokens() const { return ReplacementTokens.size(); }
+  unsigned getNumTokens() const { return NumReplacementTokens; }
 
   const Token &getReplacementToken(unsigned Tok) const {
-assert(Tok < ReplacementTokens.size() && "Invalid token #");
+assert(Tok < NumReplacementTokens && "Invalid token #");
 return ReplacementTokens[Tok];
   }
 
-  using tokens_iterator = SmallVectorImpl::const_iterator;
+  using const_tokens_iterator = const Token *;
 
-  tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
-  tokens_iterator tokens_end() const { return ReplacementTokens.end(); }
-  bool tokens_empty() const { return ReplacementTokens.empty(); }
-  ArrayRef tokens() const { return ReplacementTokens; }
+  const_tokens_iterator tokens_begin() const { return ReplacementTokens; }
+  const_tokens_iterator tokens_end() const {
+return ReplacementTokens + NumReplacementTokens;
+  }
+  bool tokens_empty() const { return NumReplacementTokens == 0; }
+  ArrayRef tokens() const {
+return llvm::makeArrayRef(ReplacementTokens, NumReplacementTokens);
+  }
 
-  /// Add the specified token to the replacement text for the macro.
-  void AddTokenToBody(const Token &Tok) {
+  llvm::MutableArrayRef
+  allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator) {
+assert(ReplacementTokens == nullptr && NumReplacementTokens == 0 &&
+   "Token list already allocated!");
+NumReplacementTokens = NumTokens;
+Token *NewReplacementTokens = PPAllocator.Allocate(NumTokens);
+ReplacementTokens = NewReplacementTokens;
+return llvm::makeMutableArrayRef(NewR

[PATCH] D119299: [NFC] clang-format one function.

2022-02-11 Thread Evgenii Stepanov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa730b6a41ad7: [NFC] clang-format one function. (authored by 
eugenis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119299

Files:
  clang/lib/CodeGen/CGClass.cpp


Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -1649,22 +1649,22 @@
 }
   };
 
- static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
- CharUnits::QuantityType PoisonSize) {
-   CodeGenFunction::SanitizerScope SanScope(&CGF);
-   // Pass in void pointer and size of region as arguments to runtime
-   // function
-   llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
-  llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
-
-   llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
-
-   llvm::FunctionType *FnType =
-   llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
-   llvm::FunctionCallee Fn =
-   CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
-   CGF.EmitNounwindRuntimeCall(Fn, Args);
- }
+  static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
+CharUnits::QuantityType PoisonSize) {
+CodeGenFunction::SanitizerScope SanScope(&CGF);
+// Pass in void pointer and size of region as arguments to runtime
+// function
+llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
+   llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
+
+llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
+
+llvm::FunctionType *FnType =
+llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
+llvm::FunctionCallee Fn =
+CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
+CGF.EmitNounwindRuntimeCall(Fn, Args);
+  }
 
   class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
 const CXXDestructorDecl *Dtor;


Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -1649,22 +1649,22 @@
 }
   };
 
- static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
- CharUnits::QuantityType PoisonSize) {
-   CodeGenFunction::SanitizerScope SanScope(&CGF);
-   // Pass in void pointer and size of region as arguments to runtime
-   // function
-   llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
-  llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
-
-   llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
-
-   llvm::FunctionType *FnType =
-   llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
-   llvm::FunctionCallee Fn =
-   CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
-   CGF.EmitNounwindRuntimeCall(Fn, Args);
- }
+  static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
+CharUnits::QuantityType PoisonSize) {
+CodeGenFunction::SanitizerScope SanScope(&CGF);
+// Pass in void pointer and size of region as arguments to runtime
+// function
+llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
+   llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
+
+llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
+
+llvm::FunctionType *FnType =
+llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
+llvm::FunctionCallee Fn =
+CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
+CGF.EmitNounwindRuntimeCall(Fn, Args);
+  }
 
   class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
 const CXXDestructorDecl *Dtor;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a730b6a - [NFC] clang-format one function.

2022-02-11 Thread Evgenii Stepanov via cfe-commits

Author: Evgenii Stepanov
Date: 2022-02-11T15:00:29-08:00
New Revision: a730b6a41ad7e57a015c4a310850b14513ecb70c

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

LOG: [NFC] clang-format one function.

fix code formatting

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

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 76b90924750c..b7d6139f720c 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1649,22 +1649,22 @@ namespace {
 }
   };
 
- static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
- CharUnits::QuantityType PoisonSize) {
-   CodeGenFunction::SanitizerScope SanScope(&CGF);
-   // Pass in void pointer and size of region as arguments to runtime
-   // function
-   llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
-  llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
-
-   llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
-
-   llvm::FunctionType *FnType =
-   llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
-   llvm::FunctionCallee Fn =
-   CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
-   CGF.EmitNounwindRuntimeCall(Fn, Args);
- }
+  static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
+CharUnits::QuantityType PoisonSize) {
+CodeGenFunction::SanitizerScope SanScope(&CGF);
+// Pass in void pointer and size of region as arguments to runtime
+// function
+llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
+   llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};
+
+llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};
+
+llvm::FunctionType *FnType =
+llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
+llvm::FunctionCallee Fn =
+CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
+CGF.EmitNounwindRuntimeCall(Fn, Args);
+  }
 
   class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
 const CXXDestructorDecl *Dtor;



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


[PATCH] D119597: [clang-format][NFC] Give State.Stack.back() a meaningful name

2022-02-11 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, owenpan, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without that debugging was a hell for me.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119597

Files:
  clang/lib/Format/ContinuationIndenter.cpp

Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -263,9 +263,10 @@
   if (Style.Language == FormatStyle::LK_TextProto) {
 // We need this in order to deal with the bin packing of text fields at
 // global scope.
-State.Stack.back().AvoidBinPacking = true;
-State.Stack.back().BreakBeforeParameter = true;
-State.Stack.back().AlignColons = false;
+auto &CurrentState = State.Stack.back();
+CurrentState.AvoidBinPacking = true;
+CurrentState.BreakBeforeParameter = true;
+CurrentState.AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
@@ -276,8 +277,9 @@
 bool ContinuationIndenter::canBreak(const LineState &State) {
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
+  const auto &CurrentState = State.Stack.back();
   assert(&Previous == Current.Previous);
-  if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
+  if (!Current.CanBreakBefore && !(CurrentState.BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
   // The opening "{" of a braced list has to be on the same line as the first
@@ -296,7 +298,7 @@
   State.LowestLevelOnLine < State.StartOfLineLevel &&
   State.LowestLevelOnLine < Current.NestingLevel)
 return false;
-  if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
+  if (Current.isMemberAccess() && CurrentState.ContainsUnwrappedBuilder)
 return false;
 
   // Don't create a 'hanging' indent if there are multiple blocks in a single
@@ -316,18 +318,19 @@
   // If binary operators are moved to the next line (including commas for some
   // styles of constructor initializers), that's always ok.
   if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
-  State.Stack.back().NoLineBreakInOperand)
+  CurrentState.NoLineBreakInOperand)
 return false;
 
   if (Previous.is(tok::l_square) && Previous.is(TT_ObjCMethodExpr))
 return false;
 
-  return !State.Stack.back().NoLineBreak;
+  return !CurrentState.NoLineBreak;
 }
 
 bool ContinuationIndenter::mustBreak(const LineState &State) {
   const FormatToken &Current = *State.NextToken;
   const FormatToken &Previous = *Current.Previous;
+  const auto &CurrentState = State.Stack.back();
   if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore &&
   Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) {
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
@@ -335,10 +338,10 @@
   }
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
-  if (State.Stack.back().BreakBeforeClosingBrace &&
+  if (CurrentState.BreakBeforeClosingBrace &&
   Current.closesBlockOrBlockTypeList(Style))
 return true;
-  if (State.Stack.back().BreakBeforeClosingParen && Current.is(tok::r_paren))
+  if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
 return true;
@@ -349,7 +352,7 @@
 return true;
   // Avoid producing inconsistent states by requiring breaks where they are not
   // permitted for C# generic type constraints.
-  if (State.Stack.back().IsCSharpGenericTypeConstraint &&
+  if (CurrentState.IsCSharpGenericTypeConstraint &&
   Previous.isNot(TT_CSharpGenericTypeConstraintComma))
 return false;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
@@ -364,10 +367,10 @@
 Previous.isNot(tok::question)) ||
(!Style.BreakBeforeTernaryOperators &&
 Previous.is(TT_ConditionalExpr))) &&
-  State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
+  CurrentState.BreakBeforeParameter && !Current.isTrailingComment() &&
   !Current.isOneOf(tok::r_paren, tok::r_brace))
 return true;
-  if (State.Stack.back().IsChainedConditional &&
+  if (CurrentState.IsChainedConditional &&
   ((Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) &&
 Current.is(tok::colon)) ||
(!Style.BreakBeforeTernaryOperators && Previous.is(TT_ConditionalExpr) &&
@@ -389,7 +392,7 @@
   if (BreakConstructorInitializersToken.is(TT_CtorInitializerColon) &&
   (State.Column + State.Line->Last->TotalLength -

[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-02-11 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

In D117522#3299423 , @carlosgalvezp 
wrote:

> I'm mostly interested on the warning message, [...]

I'm open to changes in the wording of the warning message.

> I get an error when downloading, do you happen to know what could be wrong?

I haven't used arcanist, I've created the review by uploading the diff from git.

You should be able to download the raw diff and then use `git apply` to apply
the diff to your working tree.

I tested with a clone of [[ 
https://github.com/LegalizeAdulthood/iterated-dynamics | iterated dynamics  
]]from github.
That code originates as multi-decade old C code which I've incrementally 
modernized
and has lots of integral constant macros in it.  That led me to some 
improvements over
the first version of this that I put up for review.

>> This check is more about implementing Enum.1 Prefer enumerations over macros.
>
> Should a `cppcoreguidelines` alias be added in that case?

Yeah, I think I'm going to add that.


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

https://reviews.llvm.org/D117522

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


[PATCH] D97625: fix check-clang-tools tests that fail due to Windows CRLF line endings

2022-02-11 Thread Richard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc5bf040d810: fix check-clang-tools tests that fail due to 
Windows CRLF line endings (authored by poelmanc, committed by 
LegalizeAdulthood).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D97625?vs=326956&id=408055#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97625

Files:
  test/.gitattributes


Index: test/.gitattributes
===
--- /dev/null
+++ test/.gitattributes
@@ -0,0 +1,19 @@
+# CRLF (Windows) line endings take two bytes instead of one, so any tests that
+# rely on or check fixed character -offset, Offset: or FileOffset: locations
+# will fail when run on input files checked out with different line endings.
+
+# Most test input files should use native line endings, to ensure that we run
+# tests against both line ending types.
+* text=auto
+
+# These test input files rely on one-byte Unix (LF) line-endings, as they use
+# fixed -offset, FileOffset:, or Offset: numbers in their tests.
+clang-apply-replacements/ClangRenameClassReplacements.cpp text eol=lf
+clang-apply-replacements/Inputs/basic/basic.h text eol=lf
+clang-apply-replacements/Inputs/format/no.cpp text eol=lf
+clang-apply-replacements/Inputs/format/yes.cpp text eol=lf
+clang-tidy/infrastructure/export-diagnostics.cpp text eol=lf
+
+# These test input files rely on two-byte Windows (CRLF) line endings.
+clang-apply-replacements/Inputs/crlf/crlf.cpp text eol=crlf
+clang-apply-replacements/Inputs/crlf/crlf.cpp.expected text eol=crlf


Index: test/.gitattributes
===
--- /dev/null
+++ test/.gitattributes
@@ -0,0 +1,19 @@
+# CRLF (Windows) line endings take two bytes instead of one, so any tests that
+# rely on or check fixed character -offset, Offset: or FileOffset: locations
+# will fail when run on input files checked out with different line endings.
+
+# Most test input files should use native line endings, to ensure that we run
+# tests against both line ending types.
+* text=auto
+
+# These test input files rely on one-byte Unix (LF) line-endings, as they use
+# fixed -offset, FileOffset:, or Offset: numbers in their tests.
+clang-apply-replacements/ClangRenameClassReplacements.cpp text eol=lf
+clang-apply-replacements/Inputs/basic/basic.h text eol=lf
+clang-apply-replacements/Inputs/format/no.cpp text eol=lf
+clang-apply-replacements/Inputs/format/yes.cpp text eol=lf
+clang-tidy/infrastructure/export-diagnostics.cpp text eol=lf
+
+# These test input files rely on two-byte Windows (CRLF) line endings.
+clang-apply-replacements/Inputs/crlf/crlf.cpp text eol=crlf
+clang-apply-replacements/Inputs/crlf/crlf.cpp.expected text eol=crlf
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

And this should be raised as an Itanium issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Changing the C++03 POD definition is going to be substantially ABI-breaking at 
this point.  Any logic to change it needs to be platform-specific.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Relanded in 73e585e44d68cf77e2e3274e98c9615156a7d909 
, with the 
new files in a new WindowsDriver library.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[clang] 73e585e - Reland "[lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:"

2022-02-11 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-02-11T17:07:33-05:00
New Revision: 73e585e44d68cf77e2e3274e98c9615156a7d909

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

LOG: Reland "[lld/coff] Make lld-link work in a non-MSVC shell, add 
/winsysroot:"

This relands commit b3b2538df100ec, except that the new files in Support
are instead in a new library WindowsDriver.

Added: 
lld/test/COFF/winsysroot.test
llvm/include/llvm/WindowsDriver/MSVCPaths.h
llvm/include/llvm/WindowsDriver/MSVCSetupApi.h
llvm/lib/WindowsDriver/CMakeLists.txt
llvm/lib/WindowsDriver/MSVCPaths.cpp
llvm/utils/gn/secondary/llvm/lib/WindowsDriver/BUILD.gn

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
lld/COFF/CMakeLists.txt
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/Options.td
lld/COFF/SymbolTable.cpp
lld/docs/ReleaseNotes.rst
llvm/lib/CMakeLists.txt
llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
llvm/utils/gn/secondary/lld/COFF/BUILD.gn

Removed: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index c7defa9cd88c6..4a2c28bcf32ae 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -285,7 +285,6 @@ clang/lib/Driver/ToolChains/InterfaceStubs.h
 clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
-clang/lib/Driver/ToolChains/MSVCSetupApi.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp
 clang/lib/Driver/ToolChains/PPCFreeBSD.h
 clang/lib/Driver/ToolChains/PPCLinux.h
@@ -5329,6 +5328,8 @@ 
llvm/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
 llvm/include/llvm/Transforms/Utils/UnifyLoopExits.h
 llvm/include/llvm/Transforms/Utils/ValueMapper.h
 llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
+llvm/include/llvm/WindowsDriver/MSVCPaths.h
+llvm/include/llvm/WindowsDriver/MSVCSetupApi.h
 llvm/include/llvm/WindowsManifest/WindowsManifestMerger.h
 llvm/include/llvm/WindowsResource/ResourceScriptToken.h
 llvm/include/llvm/XRay/BlockIndexer.h
@@ -6492,6 +6493,7 @@ llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
 llvm/lib/Transforms/Vectorize/VPlanTransforms.h
 llvm/lib/Transforms/Vectorize/VPlanValue.h
 llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+llvm/lib/WindowsDriver/MSVCPaths.cpp
 llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
 llvm/lib/XRay/BlockIndexer.cpp
 llvm/lib/XRay/BlockVerifier.cpp

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 78e8fd1852841..00c7a8f893ff4 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
   Option
   ProfileData
   Support
+  WindowsDriver
   )
 
 if(WIN32)

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 9f4751167ac12..03e941389aca4 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -40,91 +40,12 @@
   #include 
 #endif
 
-#ifdef _MSC_VER
-// Don't support SetupApi on MinGW.
-#define USE_MSVC_SETUP_API
-
-// Make sure this comes before MSVCSetupApi.h
-#include 
-
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
-#endif
-#include "MSVCSetupApi.h"
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-#include "llvm/Support/COM.h"
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
-#endif
-
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-// Windows SDKs and VC Toolchains group their contents into subdirectories 
based
-// on the target architecture. This function converts an llvm::Triple::ArchType
-// to the corresponding subdirectory name.
-static const char *llvmArchToWindowsSDKArch(llvm::Triple::ArchType Arch) {
-  using ArchType = llvm::Triple::ArchType;
-  switch (Arch) {
-  case ArchType::x86:
-return "x86";
-  case ArchType::x86_64:
-return "x64";
-  case ArchType::arm:
-return "arm";
-  case ArchType::aarch64:
-return "arm64";
-  default:
-return "";
-  }
-}
-
-// Similar to the above function, but for Visual

[PATCH] D113369: [clang-format] Extend SpaceBeforeParens for requires

2022-02-11 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

A friendly ping.


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

https://reviews.llvm.org/D113369

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


[PATCH] D110663: [Driver] Support Debian multiarch style lib/clang/14.0.0/x86_64-linux-gnu runtime path and include/x86_64-linux-gnu/c++/v1 libc++ path

2022-02-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D110663#3298391 , @MaskRay wrote:

> Ping @phosek

Ping @phosek


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110663

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-11 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D110869#3315135 , @xbolva00 wrote:

> @void It would be cool to mention this new feature in release notes.

Good idea! https://reviews.llvm.org/D119592


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D119592: Insert a blurb about the -fzero-call-used-regs feature

2022-02-11 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added reviewers: nickdesaulniers, kees.
void requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119592

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -47,7 +47,12 @@
 Major New Features
 --
 
--  ...
+- Clang now supports the ``-fzero-call-used-regs`` feature for x86. The purpose
+  of this feature is to limit Return-Oriented Programming (ROP) exploits and
+  information leakage. It works by zeroing out a selected class of registers
+  before function return --- e.g., all GPRs that are used within the function.
+  There is an analogous ``zero_call_used_regs`` attribute to allow for finer
+  control of this feature.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -47,7 +47,12 @@
 Major New Features
 --
 
--  ...
+- Clang now supports the ``-fzero-call-used-regs`` feature for x86. The purpose
+  of this feature is to limit Return-Oriented Programming (ROP) exploits and
+  information leakage. It works by zeroing out a selected class of registers
+  before function return --- e.g., all GPRs that are used within the function.
+  There is an analogous ``zero_call_used_regs`` attribute to allow for finer
+  control of this feature.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D119051#3314138 , @Bhramar.vatsa 
wrote:

> Sorry, but I can only add a bit more confusion: 
> https://godbolt.org/z/fT19KTh34
> There are two cases, only differing in terms of user-defined constructor.
>
> Gcc and clang differs in the two cases. Gcc at least packs the second case 
> (without user defined constructor), but clang (trunk version) doesn't.

Right - but with this proposed patch applied, Clang's answer is consistent with 
GCC's behavior, I believe?

> Uncomment/define macro 'PROPS' to check that the type-traits indicate in both 
> cases that it can be considered POD.

Yes, I believe/understand that both of these types are C++11 POD, but the first 
example is not C++98/03 POD (and the second example isn't valid C++98/03, but 
as an extension, it is supported in C++98/03 and as far as I can tell (see the 
switch example in https://reviews.llvm.org/D119051#3305511 ) GCC deems the 
defaulted constructor to be still be C++98/03 POD, as an extension).

So, I believe your example is consistent with the theory I gave at the start of 
this patch: GCC is using the C++98/03 definition of POD, with an extension for 
defaulted functions, to determine whether to pack/align a member or not, and 
changing Clang's definition of 98/03 POD to match GCC's (by adding an extension 
for defaulted functions) is probably the right thing to do, so far as I can 
gather.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119591: clang-analyzer plugins require LLVM_ENABLE_PLUGINS also

2022-02-11 Thread Jameson Nash via Phabricator via cfe-commits
vtjnash created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware, mgorny.
vtjnash requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The clang-analyzer plugins are not linked to a particular tool, so they
can only be compiled if plugins are broadly supported. We could opt
instead to decide whether to link them to specifically against clang or
with undefined symbols, depending on the value of LLVM_ENABLE_PLUGINS,
but we do not currently expect there to be a use case for that rather
niche configuration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119591

Files:
  clang/examples/AnnotateFunctions/CMakeLists.txt
  clang/examples/Attribute/CMakeLists.txt
  clang/examples/CMakeLists.txt
  clang/examples/CallSuperAttribute/CMakeLists.txt
  clang/examples/PluginsOrder/CMakeLists.txt
  clang/examples/PrintFunctionNames/CMakeLists.txt
  clang/lib/Analysis/plugins/CMakeLists.txt
  clang/test/CMakeLists.txt

Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -145,8 +145,8 @@
   endif()
 endif()
 
-if (CLANG_ENABLE_STATIC_ANALYZER)
-  if (CLANG_PLUGIN_SUPPORT)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+  if(CLANG_PLUGIN_SUPPORT AND LLVM_ENABLE_PLUGINS) # Determine if we built them
 list(APPEND CLANG_TEST_DEPS
   SampleAnalyzerPlugin
   CheckerDependencyHandlingAnalyzerPlugin
Index: clang/lib/Analysis/plugins/CMakeLists.txt
===
--- clang/lib/Analysis/plugins/CMakeLists.txt
+++ clang/lib/Analysis/plugins/CMakeLists.txt
@@ -1,4 +1,7 @@
-if(CLANG_ENABLE_STATIC_ANALYZER AND CLANG_PLUGIN_SUPPORT)
+# Since these do not specify a specific PLUGIN_TOOL (which could be clang or
+# clang-tidy), we cannot compile this unless the platform supports plugins with
+# undefined symbols, and cannot use it unless the user has opted for clang plugins).
+if(CLANG_ENABLE_STATIC_ANALYZER AND CLANG_PLUGIN_SUPPORT AND LLVM_ENABLE_PLUGINS)
   add_subdirectory(SampleAnalyzer)
   add_subdirectory(CheckerDependencyHandling)
   add_subdirectory(CheckerOptionHandling)
Index: clang/examples/PrintFunctionNames/CMakeLists.txt
===
--- clang/examples/PrintFunctionNames/CMakeLists.txt
+++ clang/examples/PrintFunctionNames/CMakeLists.txt
@@ -11,7 +11,7 @@
 
 add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL clang)
 
-if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
+if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS
 Support
   )
Index: clang/examples/PluginsOrder/CMakeLists.txt
===
--- clang/examples/PluginsOrder/CMakeLists.txt
+++ clang/examples/PluginsOrder/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_llvm_library(PluginsOrder MODULE PluginsOrder.cpp PLUGIN_TOOL clang)
 
-if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
+if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS
 Support
   )
Index: clang/examples/CallSuperAttribute/CMakeLists.txt
===
--- clang/examples/CallSuperAttribute/CMakeLists.txt
+++ clang/examples/CallSuperAttribute/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_llvm_library(CallSuperAttr MODULE CallSuperAttrInfo.cpp PLUGIN_TOOL clang)
 
-if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
+if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS
 Support
   )
Index: clang/examples/CMakeLists.txt
===
--- clang/examples/CMakeLists.txt
+++ clang/examples/CMakeLists.txt
@@ -3,8 +3,10 @@
   set(EXCLUDE_FROM_ALL ON)
 endif()
 
-add_subdirectory(PrintFunctionNames)
-add_subdirectory(AnnotateFunctions)
-add_subdirectory(Attribute)
-add_subdirectory(CallSuperAttribute)
-add_subdirectory(PluginsOrder)
+if(CLANG_PLUGIN_SUPPORT)
+  add_subdirectory(PrintFunctionNames)
+  add_subdirectory(AnnotateFunctions)
+  add_subdirectory(Attribute)
+  add_subdirectory(CallSuperAttribute)
+  add_subdirectory(PluginsOrder)
+endif()
Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ clang/examples/Attribute/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
-if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
+if(WIN32 OR CYGWIN)
   target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
Index: clang/examples/AnnotateFunctions/CMakeLists.txt
===
--- clang/examples/AnnotateFunctions/CMakeLists.txt
+++ clang/examples/AnnotateFunctions/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL clang)
 
-if(CLANG

[PATCH] D113319: [clang-format] Improve require and concept handling

2022-02-11 Thread Björn Schäpers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9aab0db13fb6: [clang-format] Improve require and concept 
handling (authored by HazardyKnusperkeks).

Changed prior to commit:
  https://reviews.llvm.org/D113319?vs=406444&id=408039#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113319

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -14,6 +14,14 @@
 
 namespace clang {
 namespace format {
+
+// Not really the equality, but everything we need.
+static bool operator==(const FormatToken &LHS,
+   const FormatToken &RHS) noexcept {
+  return LHS.Tok.getKind() == RHS.Tok.getKind() &&
+ LHS.getType() == RHS.getType();
+}
+
 namespace {
 
 class TokenAnnotatorTest : public ::testing::Test {
@@ -119,6 +127,261 @@
   EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_CastRParen);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
+  auto Tokens = annotate("template \n"
+ "concept C = (Foo && Bar) && (Bar && Baz);");
+
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template \n"
+"concept C = requires(T t) {\n"
+"  { t.foo() };\n"
+"} && Bar && Baz;");
+  ASSERT_EQ(Tokens.size(), 35u) << Tokens;
+  EXPECT_TOKEN(Tokens[23], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[28], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template\n"
+"requires C1 && (C21 || C22 && C2e) && C3\n"
+"struct Foo;");
+  ASSERT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_EQ(Tokens[6]->FakeLParens.size(), 1u);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[16], tok::pipepipe, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[21], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[27], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[31], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[31]->FakeRParens, 1u);
+  EXPECT_TRUE(Tokens[31]->ClosesRequiresClause);
+
+  Tokens =
+  annotate("template\n"
+   "requires (C1 && (C21 || C22 && C2e) && C3)\n"
+   "struct Foo;");
+  ASSERT_EQ(Tokens.size(), 38u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_Unknown);
+  EXPECT_EQ(Tokens[7]->FakeLParens.size(), 1u);
+  EXPECT_TOKEN(Tokens[11], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[17], tok::pipepipe, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[22], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[28], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[32], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[32]->FakeRParens, 1u);
+  EXPECT_TOKEN(Tokens[33], tok::r_paren, TT_Unknown);
+  EXPECT_TRUE(Tokens[33]->ClosesRequiresClause);
+}
+
+TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
+  auto NumberOfAdditionalRequiresClauseTokens = 5u;
+  auto NumberOfTokensBeforeRequires = 5u;
+
+  auto BaseTokens = annotate("template\n"
+ "T Pi = 3.14;");
+  auto ConstrainedTokens = annotate("template\n"
+"  requires Foo\n"
+"T Pi = 3.14;");
+
+  auto NumberOfBaseTokens = 11u;
+
+  ASSERT_EQ(BaseTokens.size(), NumberOfBaseTokens) << BaseTokens;
+  ASSERT_EQ(ConstrainedTokens.size(),
+NumberOfBaseTokens + NumberOfAdditionalRequiresClauseTokens)
+  << ConstrainedTokens;
+
+  for (auto I = 0u; I < NumberOfBaseTokens; ++I)
+if (I < NumberOfTokensBeforeRequires)
+  EXPECT_EQ(*BaseTokens[I], *ConstrainedTokens[I]) << I;
+else
+  EXPECT_EQ(*BaseTokens[I],
+*ConstrainedTokens[I + NumberOfAdditionalRequiresClauseTokens])
+  << I;
+
+  BaseTokens = annotate("template\n"
+"struct Bar;");
+  ConstrainedTokens = annotate("template\n"
+   "  requires Foo\n"
+   "struct Bar;");
+  NumberOfBaseTokens = 9u;
+
+  ASSERT_EQ(BaseTokens.size(), NumberOfBaseTok

[clang] 9aab0db - [clang-format] Improve require and concept handling

2022-02-11 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2022-02-11T22:42:37+01:00
New Revision: 9aab0db13fb6d21d1b70247a9b5e4cf916ee1c3a

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

LOG: [clang-format] Improve require and concept handling

- Added an option where to put the requires clauses.
- Renamed IndentRequires to IndentRequiresClause.
- Changed BreakBeforeConceptDeclaration from bool to an enum.

Fixes https://llvm.org/PR32165, and https://llvm.org/PR52401.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d610c19faf2b6..e89523d0e5676 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1988,17 +1988,33 @@ the configuration (without a prefix: ``Auto``).
 
 
 
-**BreakBeforeConceptDeclarations** (``Boolean``) :versionbadge:`clang-format 
13`
-  If ``true``, concept will be placed on a new line.
+**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) 
:versionbadge:`clang-format 13`
+  The concept declaration style to use.
 
-  .. code-block:: c++
+  Possible values:
+
+  * ``BBCDS_Never`` (in configuration: ``Never``)
+Keep the template declaration line together with ``concept``.
+
+.. code-block:: c++
+
+  template  concept C = ...;
+
+  * ``BBCDS_Allowed`` (in configuration: ``Allowed``)
+Breaking between template declaration and ``concept`` is allowed. The
+actual behavior depends on the content and line breaking rules and
+penalities.
+
+  * ``BBCDS_Always`` (in configuration: ``Always``)
+Always break before ``concept``, putting it in the line after the
+template declaration.
+
+.. code-block:: c++
+
+  template 
+  concept C = ...;
 
-true:
- template
- concept ...
 
-false:
- template concept ...
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7`
   If ``true``, ternary operators will be placed after line breaks.
@@ -2690,8 +2706,9 @@ the configuration (without a prefix: ``Auto``).
 
 
 
-**IndentRequires** (``Boolean``) :versionbadge:`clang-format 13`
-  Indent the requires clause in a template
+**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 13`
+  Indent the requires clause in a template. This only applies when
+  ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
 
   .. code-block:: c++
 
@@ -3474,6 +3491,92 @@ the configuration (without a prefix: ``Auto``).
   }
 }
 
+**RequiresClausePosition** (``RequiresClausePositionStyle``) 
:versionbadge:`clang-format 15`
+  The position of the ``requires`` clause.
+
+  Possible values:
+
+  * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
+Always put the ``requires`` clause on its own line.
+
+.. code-block:: c++
+
+  template 
+  requires C
+  struct Foo {...
+
+  template 
+  requires C
+  void bar(T t) {...
+
+  template 
+  void baz(T t)
+  requires C
+  {...
+
+  * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
+Try to put the clause together with the preceding part of a declaration.
+For class templates: stick to the template declaration.
+For function templates: stick to the template declaration.
+For function declaration followed by a requires clause: stick to the
+parameter list.
+
+.. code-block:: c++
+
+  template  requires C
+  struct Foo {...
+
+  template  requires C
+  void bar(T t) {...
+
+  template 
+  void baz(T t) requires C
+  {...
+
+  * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)
+Try to put the ``requires`` clause together with the class or function
+declaration.
+
+.. code-block:: c++
+
+  template 
+  requires C struct Foo {...
+
+  template 
+  requires C void bar(T t) {...
+
+  template 
+  void baz(T t)
+  requires C {...
+
+  * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)
+Try to put everything in the same line if possible. Otherwise normal
+line breaking rules take over.
+
+.. code-block:: c++
+
+  // Fitting:
+  template  requires C struct Foo {...
+
+  template  requires C void bar(T t) {...
+
+  template  void bar(T t) req

[PATCH] D119138: [clang-format] Further improve support for requires expressions

2022-02-11 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2798-2802
+// This one is really tricky, since most tokens doesn't have a type yet.
+// The & or && can be binary operators, then we have a requires
+// expression. But they also can be r-value overload indicators, then
+// we have a trailing requires clause. We try to detect the latter and
+// default to the expressions.

s/doesn't/don't/
IIUC you're talking about, like, `void member() && requires (` — is that right?
It might help the reader to give an example snippet right here. (OTOH, it might 
be "obvious," I don't know. I'm not in the target audience for this code.)
...Ah, I see you give a snippet on line 2837 that's basically what I mean; I 
just first felt the need for that snippet all the way up //here//.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2835-2841
+  // FIXME: We need an annotation on the paren to really know if it is a
+  // function call:
+  // ... foo() && requires ...
+  // or a declaration:
+  // void foo() && requires ...
+  // there is no distinction possible right now. We go for the latter,
+  // because it's more likely to appear in code.

I think it's weird that your heuristic parses backward rather than forward. I 
would think that the next token //after// the `requires` keyword tells you what 
it is with pretty high probability:
`requires requires` — it's a clause
`requires identifier` — it's a clause
`requires {` — it's an expression
`requires (` — unclear, apply further heuristics

Or are those heuristics already present in trunk, and this PR is just dealing 
with the "unclear" case?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2882
+  if (BeforeLastParenContent->isSimpleTypeSpecifier()) {
+// Definetly function delcaration.
+return false;




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

https://reviews.llvm.org/D119138

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


[PATCH] D119590: exclude openembedded distributions from setting rpath on openmp executables

2022-02-11 Thread Khem Raj via Phabricator via cfe-commits
raj.khem created this revision.
raj.khem added reviewers: jhuber6, JonChesterfield.
Herald added subscribers: guansong, yaxunl.
raj.khem requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

OpenEmbedded based SDKs stage toolchains outsides the target rootfs and
libomp.so is part of the target rootfs and not part of compiler
toolchain install or relative to it. It finds the libraries via
--sysroot during compile. This ensures that -rpath is not added for such
systems, since it is adding cross-compile paths to rpath which is not
correct when the binaries are run on real targets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119590

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -648,6 +648,11 @@
 void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
   const ArgList &Args,
   ArgStringList &CmdArgs) {
+  // OpenEmbedded/Yocto installs libomp.so into /usr/lib
+  // therefore using -rpath is not needed, on the contrary it adds
+  // paths from cross compiler install location which is not correct
+  if (TC.getTriple().getVendor() == llvm::Triple::OpenEmbedded)
+return;
 
   if (Args.hasFlag(options::OPT_fopenmp_implicit_rpath,
options::OPT_fno_openmp_implicit_rpath, true)) {


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -648,6 +648,11 @@
 void tools::addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
   const ArgList &Args,
   ArgStringList &CmdArgs) {
+  // OpenEmbedded/Yocto installs libomp.so into /usr/lib
+  // therefore using -rpath is not needed, on the contrary it adds
+  // paths from cross compiler install location which is not correct
+  if (TC.getTriple().getVendor() == llvm::Triple::OpenEmbedded)
+return;
 
   if (Args.hasFlag(options::OPT_fopenmp_implicit_rpath,
options::OPT_fno_openmp_implicit_rpath, true)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: llvm/include/llvm/Support/MSVCPaths.h:15
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 

aprantl wrote:
> This introduces a cyclic dependency that breaks the `-DLLVM_ENABLE_MODULES=1` 
>  build.
> ```
> /Volumes/Data/llvm-project/llvm/include/llvm/Option/Arg.h:17:10: fatal error: 
> cyclic dependency in module 'LLVM_Utils': LLVM_Utils -> LLVM_Option -> 
> LLVM_Utils
> #include "llvm/ADT/SmallVector.h"
>  ^
> While building module 'LLVM_Utils' imported from 
> /Volumes/Data/llvm-project/llvm/lib/Support/ARMBuildAttrs.cpp:9:
> In file included from :195:
> /Volumes/Data/llvm-project/llvm/include/llvm/Support/MSVCPaths.h:14:10: fatal 
> error: could not build module 'LLVM_Option'
> #include "llvm/Option/ArgList.h"
>  ^~~
> /Volumes/Data/llvm-project/llvm/lib/Support/ARMBuildAttrs.cpp:9:10: fatal 
> error: could not build module 'LLVM_Utils'
> #include "llvm/Support/ARMBuildAttributes.h"
>  ^~~
> 3 errors generated.
> ```
Ah yeah, support can't depend on Option. Maybe the easiest fix is to just move 
this to its own library like maskray suggested. Then this isn't a problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119138: [clang-format] Further improve support for requires expressions

2022-02-11 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 408028.
HazardyKnusperkeks marked 6 inline comments as done.
HazardyKnusperkeks added a comment.

Rebased and updated


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

https://reviews.llvm.org/D119138

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -141,6 +141,9 @@
 "  { t.foo() };\n"
 "} && Bar && Baz;");
   ASSERT_EQ(Tokens.size(), 35u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_RequiresExpressionLParen);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_RequiresExpressionLBrace);
   EXPECT_TOKEN(Tokens[23], tok::ampamp, TT_BinaryOperator);
   EXPECT_TOKEN(Tokens[28], tok::ampamp, TT_BinaryOperator);
 
@@ -148,6 +151,7 @@
 "requires C1 && (C21 || C22 && C2e) && C3\n"
 "struct Foo;");
   ASSERT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
   EXPECT_EQ(Tokens[6]->FakeLParens.size(), 1u);
   EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
@@ -163,6 +167,7 @@
"requires (C1 && (C21 || C22 && C2e) && C3)\n"
"struct Foo;");
   ASSERT_EQ(Tokens.size(), 38u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[7], tok::identifier, TT_Unknown);
   EXPECT_EQ(Tokens[7]->FakeLParens.size(), 1u);
   EXPECT_TOKEN(Tokens[11], tok::ampamp, TT_BinaryOperator);
@@ -173,6 +178,72 @@
   EXPECT_EQ(Tokens[32]->FakeRParens, 1u);
   EXPECT_TOKEN(Tokens[33], tok::r_paren, TT_Unknown);
   EXPECT_TRUE(Tokens[33]->ClosesRequiresClause);
+
+  Tokens = annotate("template \n"
+"void foo(T) noexcept requires Bar;");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("template \n"
+"struct S {\n"
+"  void foo() const requires Bar;\n"
+"  void bar() const & requires Baz;\n"
+"  void bar() && requires Baz2;\n"
+"  void baz() const & noexcept requires Baz;\n"
+"  void baz() && noexcept requires Baz2;\n"
+"};\n"
+"\n"
+"void S::bar() const & requires Baz { }");
+  ASSERT_EQ(Tokens.size(), 85u) << Tokens;
+  EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[25], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[36], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[49], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[61], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[77], tok::kw_requires, TT_RequiresClause);
+}
+
+TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
+  auto Tokens = annotate("bool b = requires(int i) { i + 5; };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
+  EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_RequiresExpressionLBrace);
+
+  Tokens = annotate("if (requires(int i) { i + 5; }) return;");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_RequiresExpressionLParen);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_RequiresExpressionLBrace);
+
+  Tokens = annotate("if (func() && requires(int i) { i + 5; }) return;");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_RequiresExpressionLParen);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_RequiresExpressionLBrace);
+
+  Tokens = annotate("template \n"
+"concept C = requires(T T) {\n"
+"  requires Bar && Foo;\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 28u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_RequiresExpressionLParen);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_RequiresExpressionLBrace);
+  EXPECT_TOKEN(Tokens[14], tok::kw_requires,
+   TT_RequiresClauseInARequiresExpression);
+
+  Tokens = annotate("template \n"
+"concept C = requires(T T) {\n"
+"  { t.func() } -> std::same_as;"
+"  requires Bar && Foo;\n"
+  

[PATCH] D119574: [clang] Expose -fprofile-use in clang-cl

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f1147f825d0: [clang] Expose -fprofile-use in clang-cl 
(authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119574

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -76,7 +76,9 @@
 // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
 
 // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1251,9 +1251,10 @@
 Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect context sensitive 
execution counts into /default.profraw (overridden by 
LLVM_PROFILE_FILE env var)">;
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
-Alias;
+Flags<[CoreOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>, MetaVarName<"">,
+Group, Flags<[NoXarchOption, CoreOption]>,
+MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If 
pathname is a directory, it reads from /default.profdata. Otherwise, 
it reads from file .">;
 def fno_profile_instr_generate : Flag<["-"], "fno-profile-instr-generate">,
 Group, Flags<[CoreOption]>,


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -76,7 +76,9 @@
 // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
 
 // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1251,9 +1251,10 @@
 Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect context sensitive execution counts into /default.profraw (overridden by LLVM_PROFILE_FILE env var)">;
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
-Alias;
+Flags<[CoreOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>, MetaVarName<"">,
+Group, Flags<[NoXarchOption, CoreOption]>,
+MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If pathname is a directory, it reads from /default.profdata. Otherwise, it reads from file .">;
 def fno_profile_instr_generate : Flag<["-"], "fno-profile-instr-generate">,
 Group, Flags<[CoreOption]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6f1147f - [clang] Expose -fprofile-use in clang-cl

2022-02-11 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-02-11T16:16:02-05:00
New Revision: 6f1147f825d087f8486a685024078fe08dba755c

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

LOG: [clang] Expose -fprofile-use in clang-cl

Less typing than `-fprofile-instr-use`, and means the same thing.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6be3aa117220e..cd0d56cecaca1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1251,9 +1251,10 @@ def fcs_profile_generate_EQ : Joined<["-"], 
"fcs-profile-generate=">,
 Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect context sensitive 
execution counts into /default.profraw (overridden by 
LLVM_PROFILE_FILE env var)">;
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
-Alias;
+Flags<[CoreOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>, MetaVarName<"">,
+Group, Flags<[NoXarchOption, CoreOption]>,
+MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If 
pathname is a directory, it reads from /default.profdata. Otherwise, 
it reads from file .">;
 def fno_profile_instr_generate : Flag<["-"], "fno-profile-instr-generate">,
 Group, Flags<[CoreOption]>,

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index ae94d86eb94ca..4a8a1b3c5ac4e 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -76,7 +76,9 @@
 // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
 
 // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 



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


[PATCH] D119479: [clang][extract-api] Add global record support

2022-02-11 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 408027.
zixuw added a comment.

Fix a test failure on Windows where diff doesn't recognize the "-a" option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119479

Files:
  clang/include/clang/AST/RawCommentList.h
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/SymbolGraph/API.h
  clang/include/clang/SymbolGraph/AvailabilityInfo.h
  clang/include/clang/SymbolGraph/DeclarationFragments.h
  clang/include/clang/SymbolGraph/Serialization.h
  clang/lib/AST/RawCommentList.cpp
  clang/lib/CMakeLists.txt
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/ExtractAPIConsumer.cpp
  clang/lib/SymbolGraph/API.cpp
  clang/lib/SymbolGraph/CMakeLists.txt
  clang/lib/SymbolGraph/DeclarationFragments.cpp
  clang/lib/SymbolGraph/Serialization.cpp
  clang/test/Driver/extract-api.c
  clang/test/SymbolGraph/global_record.c

Index: clang/test/SymbolGraph/global_record.c
===
--- /dev/null
+++ clang/test/SymbolGraph/global_record.c
@@ -0,0 +1,363 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.c -o %t/output.json | FileCheck -allow-empty %s
+// RUN: diff %t/reference.output.json %t/output.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.c
+int num;
+
+/**
+ * \brief Add two numbers.
+ * \param [in]  x   A number.
+ * \param [in]  y   Another number.
+ * \param [out] res The result of x + y.
+ */
+void add(const int x, const int y, int *res);
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "clang"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declaration": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Variable",
+"identifier": "c.variable"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/input.c"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  }
+},
+{
+  "declaration": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "add"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "x"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "y"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " *"
+},
+{
+  "kind": "internalParam",
+  "spelling": "res"
+},
+{
+  "kind": "text",
+  "spelling": ")"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+   

[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks for the revert!

Is there any documentation for that LLVM_ENABLE_MODULES build config anywhere?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 408019.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/alloc-fns-alignment.c
  clang/test/CodeGen/assume-aligned-and-alloc-align-attributes.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp

Index: clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -27,10 +27,10 @@
 struct OVERALIGNED A { A(); int n[128]; };
 
 // CHECK-LABEL: define {{.*}} @_Z2a0v()
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a0@@YAPEAXXZ"()
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??2@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef 512, i64 allocalign noundef 32)
 // CHECK-MS: cleanuppad
 // CHECK-MS: call void @"??3@YAXPEAXW4align_val_t@std@@@Z"(i8* noundef %[[ALLOC]], i64 noundef 32)
 void *a0() { return new A; }
@@ -39,13 +39,13 @@
 // The size is known.
 //
 // CHECK-LABEL: define {{.*}} @_Z2a1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1AC1Ev(
 // CHECK: call void @_ZdaPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 32)
 // CHECK-MS-LABEL: define {{.*}} @"?a1@@YAPEAXJ@Z"(
-// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK-MS: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @"??_U@YAPEAX_KW4align_val_t@std@@@Z"(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-MS-NOT: store
 // CHECK-MS: invoke noundef %struct.A* @"??0A@@QEAA@XZ"(
@@ -84,7 +84,7 @@
 void *b0() { return new B; }
 
 // CHECK-LABEL: define {{.*}} @_Z2b1l(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 noundef 32)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 32 i8* @_ZnamSt11align_val_t(i64 noundef %{{.*}}, i64 allocalign noundef 32)
 // No array cookie.
 // CHECK-NOT: store
 // CHECK: invoke void @_ZN1BC1Ev(
@@ -169,7 +169,7 @@
 
 #ifndef UNALIGNED
 // CHECK-LABEL: define {{.*}} @_Z2e0v(
-// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 noundef 4)
+// CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 512, i64 allocalign noundef 4)
 // CHECK: call void @_ZdlPvSt11align_val_t(i8* noundef %[[ALLOC]], i64 noundef 4)
 void *e0() { return new (std::align_val_t(4)) A; }
 
Index: clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
===
--- clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
+++ clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
@@ -47,7 +47,7 @@
 
 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
 extern "C" void test_aligned_alloc() {
-  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
+  // CHECK: call noalias noundef nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 noundef 4, i64 allocalign noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
   // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
   __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
 }
Index: clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
===
--- clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
+++ clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -8,7 +8,7 @@
 // CHECK-NEXT:[[ALIGN_ADDR:%.*]] = a

[PATCH] D119509: [analyzer] Fix a crash in NoStateChangeVisitor with body-farmed stack frames.

2022-02-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 408012.
NoQ added a comment.

Oh, great point. Added tests that were crashing the other way round so that to 
demonstrate that this fix is still justified. But I agree that the visitor can 
totally terminate early so that to make the original tests pass for two reasons!


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

https://reviews.llvm.org/D119509

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/malloc-bodyfarms.c
  clang/test/Analysis/malloc-bodyfarms.cpp


Index: clang/test/Analysis/malloc-bodyfarms.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-bodyfarms.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s
+
+namespace std {
+typedef struct once_flag_s {
+  int _M_once = 0;
+} once_flag;
+
+template 
+void call_once(once_flag &o, Callable&& func, Args&&... args);
+} // namespace std
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void callee() {}
+
+void test_no_state_change_in_body_farm() {
+  std::once_flag flag;
+  call_once(flag, callee); // no-crash
+  malloc(1);
+} // expected-warning{{Potential memory leak}}
+
+void test_no_state_change_in_body_farm_2() {
+  void *p = malloc(1);
+  std::once_flag flag;
+  call_once(flag, callee); // no-crash
+  p = 0;
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
Index: clang/test/Analysis/malloc-bodyfarms.c
===
--- /dev/null
+++ clang/test/Analysis/malloc-bodyfarms.c
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void *calloc(size_t, size_t);
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_sync(dispatch_queue_t, dispatch_block_t);
+
+void test_no_state_change_in_body_farm(dispatch_queue_t queue) {
+  dispatch_sync(queue, ^{}); // no-crash
+  calloc(1, 1);
+} // expected-warning{{Potential memory leak}}
+
+void test_no_state_change_in_body_farm_2(dispatch_queue_t queue) {
+  void *p = calloc(1, 1);
+  dispatch_sync(queue, ^{}); // no-crash
+  p = 0;
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -797,8 +797,16 @@
   bool doesFnIntendToHandleOwnership(const Decl *Callee, ASTContext &ACtx) {
 using namespace clang::ast_matchers;
 const FunctionDecl *FD = dyn_cast(Callee);
-if (!FD)
+
+// Given that the stack frame was entered, the body should always be
+// theoretically obtainable. In case of body farms, the synthesized body
+// is not attached to declaration, thus triggering the '!FD->hasBody()'
+// branch. That said, would a synthesized body ever intend to handle
+// ownership? As of today they don't. And if they did, how would we
+// put notes inside it, given that it doesn't match any source locations?
+if (!FD || !FD->hasBody())
   return false;
+
 // TODO: Operator delete is hardly the only deallocator -- Can we reuse
 // isFreeingCall() or something thats already here?
 auto Deallocations = match(


Index: clang/test/Analysis/malloc-bodyfarms.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-bodyfarms.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s
+
+namespace std {
+typedef struct once_flag_s {
+  int _M_once = 0;
+} once_flag;
+
+template 
+void call_once(once_flag &o, Callable&& func, Args&&... args);
+} // namespace std
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void callee() {}
+
+void test_no_state_change_in_body_farm() {
+  std::once_flag flag;
+  call_once(flag, callee); // no-crash
+  malloc(1);
+} // expected-warning{{Potential memory leak}}
+
+void test_no_state_change_in_body_farm_2() {
+  void *p = malloc(1);
+  std::once_flag flag;
+  call_once(flag, callee); // no-crash
+  p = 0;
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
Index: clang/test/Analysis/malloc-bodyfarms.c
===
--- /dev/null
+++ clang/test/Analysis/malloc-bodyfarms.c
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void *calloc(size_t, size_t);
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_sync(dispatch_queue_t, dispatch_block_t);
+
+void test_no_state_change_in_body_farm(dispatch_queue_t queue) {
+  dispatch_sync(queue, ^{}); // no-crash
+  c

[PATCH] D119574: [clang] Expose -fprofile-use in clang-cl

2022-02-11 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D119574

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


[clang] baac665 - Revert "[lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:"

2022-02-11 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2022-02-11T13:07:23-08:00
New Revision: baac665adf324672802dcc7037a25468e9569c95

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

LOG: Revert "[lld/coff] Make lld-link work in a non-MSVC shell, add 
/winsysroot:"

This reverts commit b3b2538df100ec7f6587b0ee70819a3c8ee2c27e,
it introduced a cycklic module depenency that broke the -DLLVM_ENABLE_MODULES=1 
build.

Added: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/Options.td
lld/COFF/SymbolTable.cpp
lld/docs/ReleaseNotes.rst
llvm/lib/Support/CMakeLists.txt
llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Removed: 
lld/test/COFF/winsysroot.test
llvm/include/llvm/Support/MSVCPaths.h
llvm/include/llvm/Support/MSVCSetupApi.h
llvm/lib/Support/MSVCPaths.cpp



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 5666ad499d791..c7defa9cd88c6 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -285,6 +285,7 @@ clang/lib/Driver/ToolChains/InterfaceStubs.h
 clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
+clang/lib/Driver/ToolChains/MSVCSetupApi.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp
 clang/lib/Driver/ToolChains/PPCFreeBSD.h
 clang/lib/Driver/ToolChains/PPCLinux.h
@@ -5149,8 +5150,6 @@ llvm/include/llvm/Support/MemoryBufferRef.h
 llvm/include/llvm/Support/MSP430AttributeParser.h
 llvm/include/llvm/Support/MSP430Attributes.h
 llvm/include/llvm/Support/MSVCErrorWorkarounds.h
-llvm/include/llvm/Support/MSVCPaths.h
-llvm/include/llvm/Support/MSVCSetupApi.h
 llvm/include/llvm/Support/Parallel.h
 llvm/include/llvm/Support/PGOOptions.h
 llvm/include/llvm/Support/PointerLikeTypeTraits.h
@@ -5841,7 +5840,6 @@ llvm/lib/Support/Memory.cpp
 llvm/lib/Support/MemoryBufferRef.cpp
 llvm/lib/Support/MSP430AttributeParser.cpp
 llvm/lib/Support/MSP430Attributes.cpp
-llvm/lib/Support/MSVCPaths.cpp
 llvm/lib/Support/Optional.cpp
 llvm/lib/Support/Parallel.cpp
 llvm/lib/Support/Program.cpp

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 36e190f69154b..9f4751167ac12 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -25,7 +25,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
-#include "llvm/Support/MSVCPaths.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -41,12 +40,91 @@
   #include 
 #endif
 
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+#include "MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+#include "llvm/Support/COM.h"
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+#endif
+
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+// Windows SDKs and VC Toolchains group their contents into subdirectories 
based
+// on the target architecture. This function converts an llvm::Triple::ArchType
+// to the corresponding subdirectory name.
+static const char *llvmArchToWindowsSDKArch(llvm::Triple::ArchType Arch) {
+  using ArchType = llvm::Triple::ArchType;
+  switch (Arch) {
+  case ArchType::x86:
+return "x86";
+  case ArchType::x86_64:
+return "x64";
+  case ArchType::arm:
+return "arm";
+  case ArchType::aarch64:
+return "arm64";
+  default:
+return "";
+  }
+}
+
+// Similar to the above function, but for Visual Studios before VS2017.
+static const char *llvmArchToLegacyVCArch(llvm::Triple::ArchType Arch) {
+  using ArchType = llvm::Triple::ArchType;
+  switch (Arch) {
+  case ArchType::x86:
+// x86 is default in legacy VC toolchains.
+// e.g. x86 libs are directly in /lib as opposed to /lib/x86.
+return

[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Unfortunately this seems to break the modular build. Would you mind taking a 
look? I'm going to revert the patch to get the bots going again.

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/41306/console




Comment at: llvm/include/llvm/Support/MSVCPaths.h:15
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 

This introduces a cyclic dependency that breaks the `-DLLVM_ENABLE_MODULES=1`  
build.
```
/Volumes/Data/llvm-project/llvm/include/llvm/Option/Arg.h:17:10: fatal error: 
cyclic dependency in module 'LLVM_Utils': LLVM_Utils -> LLVM_Option -> 
LLVM_Utils
#include "llvm/ADT/SmallVector.h"
 ^
While building module 'LLVM_Utils' imported from 
/Volumes/Data/llvm-project/llvm/lib/Support/ARMBuildAttrs.cpp:9:
In file included from :195:
/Volumes/Data/llvm-project/llvm/include/llvm/Support/MSVCPaths.h:14:10: fatal 
error: could not build module 'LLVM_Option'
#include "llvm/Option/ArgList.h"
 ^~~
/Volumes/Data/llvm-project/llvm/lib/Support/ARMBuildAttrs.cpp:9:10: fatal 
error: could not build module 'LLVM_Utils'
#include "llvm/Support/ARMBuildAttributes.h"
 ^~~
3 errors generated.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D119496: [Clang][OpaquePtr] Remove calls to deprecated Address constructor

2022-02-11 Thread Richard Trieu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5c314cdf43a: [Clang][OpaquePtr] Remove deprecated Address 
constructor calls (authored by rtrieu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119496

Files:
  clang/lib/CodeGen/CGExpr.cpp

Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -407,7 +407,7 @@
   GV->getValueType()->getPointerTo(
   CGF.getContext().getTargetAddressSpace(LangAS::Default)));
 // FIXME: Should we put the new global into a COMDAT?
-return Address(C, alignment);
+return Address(C, GV->getValueType(), alignment);
   }
 return CGF.CreateMemTemp(Ty, "ref.tmp", Alloca);
   }
@@ -441,10 +441,10 @@
   ownership != Qualifiers::OCL_ExplicitNone) {
 Address Object = createReferenceTemporary(*this, M, E);
 if (auto *Var = dyn_cast(Object.getPointer())) {
-  Object = Address(llvm::ConstantExpr::getBitCast(Var,
-   ConvertTypeForMem(E->getType())
- ->getPointerTo(Object.getAddressSpace())),
-   Object.getAlignment());
+  llvm::Type *Ty = ConvertTypeForMem(E->getType());
+  Object = Address(llvm::ConstantExpr::getBitCast(
+   Var, Ty->getPointerTo(Object.getAddressSpace())),
+   Ty, Object.getAlignment());
 
   // createReferenceTemporary will promote the temporary to a global with a
   // constant initializer if it can.  It can only do this to a value of
@@ -499,9 +499,11 @@
   Address Object = createReferenceTemporary(*this, M, E, &Alloca);
   if (auto *Var = dyn_cast(
   Object.getPointer()->stripPointerCasts())) {
+llvm::Type *TemporaryType = ConvertTypeForMem(E->getType());
 Object = Address(llvm::ConstantExpr::getBitCast(
  cast(Object.getPointer()),
- ConvertTypeForMem(E->getType())->getPointerTo()),
+ TemporaryType->getPointerTo()),
+ TemporaryType,
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a
 // constant temporary that we promoted to a global, we may have already
@@ -1208,9 +1210,10 @@
 LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E,
   const char *Name) {
   ErrorUnsupported(E, Name);
-  llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
-  return MakeAddrLValue(Address(llvm::UndefValue::get(Ty), CharUnits::One()),
-E->getType());
+  llvm::Type *ElTy = ConvertType(E->getType());
+  llvm::Type *Ty = llvm::PointerType::getUnqual(ElTy);
+  return MakeAddrLValue(
+  Address(llvm::UndefValue::get(Ty), ElTy, CharUnits::One()), E->getType());
 }
 
 bool CodeGenFunction::IsWrappedCXXThis(const Expr *Obj) {
@@ -2741,8 +2744,10 @@
 LValue CapLVal =
 EmitCapturedFieldLValue(*this, CapturedStmtInfo->lookup(VD),
 CapturedStmtInfo->getContextValue());
+Address LValueAddress = CapLVal.getAddress(*this);
 CapLVal = MakeAddrLValue(
-Address(CapLVal.getPointer(*this), getContext().getDeclAlign(VD)),
+Address(LValueAddress.getPointer(), LValueAddress.getElementType(),
+getContext().getDeclAlign(VD)),
 CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl),
 CapLVal.getTBAAInfo());
 // Mark lvalue as nontemporal if the variable is marked as nontemporal
@@ -3431,7 +3436,8 @@
   CfiCheckFailDataTy,
   Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
   0);
-  Address CheckKindAddr(V, getIntAlign());
+
+  Address CheckKindAddr(V, Int8Ty, getIntAlign());
   llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr);
 
   llvm::Value *AllVtables = llvm::MetadataAsValue::get(
@@ -3817,7 +3823,7 @@
 llvm::Value *EltPtr =
 emitArraySubscriptGEP(*this, Addr.getElementType(), Addr.getPointer(),
   ScaledIdx, false, SignedIndices, E->getExprLoc());
-Addr = Address(EltPtr, EltAlign);
+Addr = Address(EltPtr, Addr.getElementType(), EltAlign);
 
 // Cast back.
 Addr = Builder.CreateBitCast(Addr, OrigBaseTy);
@@ -3917,7 +3923,8 @@
 CGF.CGM.getNaturalTypeAlignment(ElTy, &TypeBaseInfo, &TypeTBAAInfo);
 BaseInfo.mergeForCast(TypeBaseInfo);
 TBAAInfo = CGF.CGM.mergeTBAAInfoForCast(TBAAInfo, TypeTBAAInfo);
-return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)), Align);
+return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)),
+ 

[clang] d5c314c - [Clang][OpaquePtr] Remove deprecated Address constructor calls

2022-02-11 Thread via cfe-commits

Author: Weverything
Date: 2022-02-11T13:02:09-08:00
New Revision: d5c314cdf43aeab2e7eda2b8a40afae4d01b030f

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

LOG: [Clang][OpaquePtr] Remove deprecated Address constructor calls

Remove most calls to deprcated Address constructor in CGExpr.cpp

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

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 4565f4343aa34..403c60b31816f 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -407,7 +407,7 @@ static Address createReferenceTemporary(CodeGenFunction 
&CGF,
   GV->getValueType()->getPointerTo(
   CGF.getContext().getTargetAddressSpace(LangAS::Default)));
 // FIXME: Should we put the new global into a COMDAT?
-return Address(C, alignment);
+return Address(C, GV->getValueType(), alignment);
   }
 return CGF.CreateMemTemp(Ty, "ref.tmp", Alloca);
   }
@@ -441,10 +441,10 @@ EmitMaterializeTemporaryExpr(const 
MaterializeTemporaryExpr *M) {
   ownership != Qualifiers::OCL_ExplicitNone) {
 Address Object = createReferenceTemporary(*this, M, E);
 if (auto *Var = dyn_cast(Object.getPointer())) {
-  Object = Address(llvm::ConstantExpr::getBitCast(Var,
-   ConvertTypeForMem(E->getType())
- ->getPointerTo(Object.getAddressSpace())),
-   Object.getAlignment());
+  llvm::Type *Ty = ConvertTypeForMem(E->getType());
+  Object = Address(llvm::ConstantExpr::getBitCast(
+   Var, Ty->getPointerTo(Object.getAddressSpace())),
+   Ty, Object.getAlignment());
 
   // createReferenceTemporary will promote the temporary to a global with a
   // constant initializer if it can.  It can only do this to a value of
@@ -499,9 +499,11 @@ EmitMaterializeTemporaryExpr(const 
MaterializeTemporaryExpr *M) {
   Address Object = createReferenceTemporary(*this, M, E, &Alloca);
   if (auto *Var = dyn_cast(
   Object.getPointer()->stripPointerCasts())) {
+llvm::Type *TemporaryType = ConvertTypeForMem(E->getType());
 Object = Address(llvm::ConstantExpr::getBitCast(
  cast(Object.getPointer()),
- ConvertTypeForMem(E->getType())->getPointerTo()),
+ TemporaryType->getPointerTo()),
+ TemporaryType,
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a
 // constant temporary that we promoted to a global, we may have already
@@ -1208,9 +1210,10 @@ RValue CodeGenFunction::EmitUnsupportedRValue(const Expr 
*E,
 LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E,
   const char *Name) {
   ErrorUnsupported(E, Name);
-  llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
-  return MakeAddrLValue(Address(llvm::UndefValue::get(Ty), CharUnits::One()),
-E->getType());
+  llvm::Type *ElTy = ConvertType(E->getType());
+  llvm::Type *Ty = llvm::PointerType::getUnqual(ElTy);
+  return MakeAddrLValue(
+  Address(llvm::UndefValue::get(Ty), ElTy, CharUnits::One()), 
E->getType());
 }
 
 bool CodeGenFunction::IsWrappedCXXThis(const Expr *Obj) {
@@ -2741,8 +2744,10 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 LValue CapLVal =
 EmitCapturedFieldLValue(*this, CapturedStmtInfo->lookup(VD),
 CapturedStmtInfo->getContextValue());
+Address LValueAddress = CapLVal.getAddress(*this);
 CapLVal = MakeAddrLValue(
-Address(CapLVal.getPointer(*this), getContext().getDeclAlign(VD)),
+Address(LValueAddress.getPointer(), LValueAddress.getElementType(),
+getContext().getDeclAlign(VD)),
 CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl),
 CapLVal.getTBAAInfo());
 // Mark lvalue as nontemporal if the variable is marked as nontemporal
@@ -3431,7 +3436,8 @@ void CodeGenFunction::EmitCfiCheckFail() {
   CfiCheckFailDataTy,
   Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
   0);
-  Address CheckKindAddr(V, getIntAlign());
+
+  Address CheckKindAddr(V, Int8Ty, getIntAlign());
   llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr);
 
   llvm::Value *AllVtables = llvm::MetadataAsValue::get(
@@ -3817,7 +3823,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
 llvm::Value *EltPtr =
 emitArraySubscriptGEP(*th

[PATCH] D117355: [PowerPC] Fix the undef virtual register reading failure for PPC backend trap optimization

2022-02-11 Thread Victor Huang via Phabricator via cfe-commits
NeHuang updated this revision to Diff 407877.
NeHuang marked an inline comment as done.
NeHuang added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117355

Files:
  llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
  llvm/test/CodeGen/PowerPC/mi-peephole-trap-opt-dominated-block.mir

Index: llvm/test/CodeGen/PowerPC/mi-peephole-trap-opt-dominated-block.mir
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/mi-peephole-trap-opt-dominated-block.mir
@@ -0,0 +1,152 @@
+# RUN: llc -mtriple powerpc64le-unknown-linux-gnu -mcpu=pwr8 -x mir < %s \
+# RUN:   -verify-machineinstrs -start-before=ppc-mi-peepholes \
+# RUN:   -stop-after=ppc-mi-peepholes -ppc-opt-conditional-trap \
+# RUN:   | FileCheck --check-prefix=CHECK-MIR %s
+
+# RUN: llc -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr8 -x mir < %s \
+# RUN:   -verify-machineinstrs -start-before=ppc-mi-peepholes \
+# RUN:   -stop-after=ppc-mi-peepholes -ppc-opt-conditional-trap \
+# RUN:   | FileCheck --check-prefix=CHECK-MIR %s
+
+# RUN: llc -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr8 -x mir < %s \
+# RUN:   -verify-machineinstrs -start-before=ppc-mi-peepholes \
+# RUN:   -stop-after=ppc-mi-peepholes -ppc-opt-conditional-trap \
+# RUN:   | FileCheck --check-prefix=CHECK-MIR %s
+
+# RUN: llc -mtriple powerpc64le-unknown-linux-gnu -mcpu=pwr8 -x mir < %s \
+# RUN:   -verify-machineinstrs -start-before=ppc-mi-peepholes \
+# RUN:   -ppc-opt-conditional-trap | FileCheck %s
+
+
+--- |
+  define dso_local signext i32 @callee(i32 signext %ic, i32 signext %id) {
+  entry:
+%add = add nsw i32 %id, %ic
+ret i32 %add
+  }
+  define dso_local signext i32 @test_MBB_dominated(i32 signext %ia, i32 signext %ib) {
+  entry:
+tail call void @llvm.ppc.MBB_dominated(i32 3, i32 3, i32 4)
+%cmp.not = icmp slt i32 %ia, %ib
+br i1 %cmp.not, label %cleanup, label %if.then
+  if.then:  ; preds = %entry
+%add = add nsw i32 %ia, 1
+%call = tail call signext i32 @callee(i32 signext %add, i32 signext %ib)
+%add1 = add nsw i32 %call, 1
+br label %cleanup
+  cleanup:  ; preds = %if.then, %entry
+%retval.0 = phi i32 [ %add1, %if.then ], [ 0, %entry ]
+ret i32 %retval.0
+  }
+  declare void @llvm.ppc.MBB_dominated(i32, i32, i32 immarg) #2
+...
+
+---
+name:callee
+alignment:   16
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+liveins: $x3, $x4
+%1:g8rc = COPY $x4
+%0:g8rc = COPY $x3
+%2:gprc = COPY %0.sub_32
+%3:gprc = COPY %1.sub_32
+%4:gprc = nsw ADD4 killed %3, killed %2
+%5:g8rc = EXTSW_32_64 killed %4
+$x3 = COPY %5
+BLR8 implicit $lr8, implicit $rm, implicit $x3
+
+...
+
+---
+name:test_MBB_dominated
+alignment:   16
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+successors: %bb.2(0x4000), %bb.1(0x4000)
+liveins: $x3, $x4
+%3:g8rc = COPY $x4
+%2:g8rc = COPY $x3
+%5:gprc = COPY %3.sub_32
+%4:gprc_and_gprc_nor0 = COPY %2.sub_32
+%7:gprc = LI 3
+TW 4, %7, %7
+%6:gprc = LI 0
+%8:crrc = CMPW %4, %5
+BCC 12, killed %8, %bb.2
+B %bb.1
+  bb.1.if.then:
+successors: %bb.2(0x8000)
+%9:gprc = nsw ADDI %4, 1
+ADJCALLSTACKDOWN 112, 0, implicit-def dead $r1, implicit $r1
+%10:g8rc = EXTSW_32_64 %5
+%11:g8rc = EXTSW_32_64 killed %9
+$x3 = COPY %11
+$x4 = COPY %10
+BL8 @callee, csr_ppc64_altivec, implicit-def dead $lr8, implicit $rm, implicit $x3, implicit $x4, implicit-def $r1, implicit-def $x3
+ADJCALLSTACKUP 112, 0, implicit-def dead $r1, implicit $r1
+%12:g8rc = COPY $x3
+%13:gprc_and_gprc_nor0 = COPY %12.sub_32
+%0:gprc = nsw ADDI killed %13, 1
+  bb.2.cleanup:
+%1:gprc = PHI %6, %bb.0, %0, %bb.1
+%14:g8rc = EXTSW_32_64 %1
+$x3 = COPY %14
+BLR8 implicit $lr8, implicit $rm, implicit $x3
+...
+# CHECK-MIR-LABEL: test_MBB_dominated
+# CHECK-MIR:   bb.0.entry:
+# CHECK-MIR:   successors: %bb.2(0x4000), %bb.1(0x4000)
+# CHECK-MIR:   liveins: $x3, $x4
+# CHECK-MIR:   %0:g8rc = COPY $x4
+# CHECK-MIR-NEXT:  %1:g8rc = COPY $x3
+# CHECK-MIR-NEXT:  %2:gprc = COPY %0.sub_32
+# CHECK-MIR-NEXT:  %3:gprc_and_gprc_nor0 = COPY %1.sub_32
+# CHECK-MIR-NEXT:  %4:gprc = LI 3
+# CHECK-MIR-NEXT:  %5:gprc = IMPLICIT_DEF
+# CHECK-MIR-NEXT:  %6:crrc = IMPLICIT_DEF
+# CHECK-MIR-NEXT:  TRAP
+
+# CHECK-MIR:   bb.1.if.then:
+# CHECK-MIR-NEXT:  successors: %bb.2(0x8000)
+# CHECK-MIR:   %7:gprc = nsw ADDI %3, 1
+# CHECK-MIR-NEXT:  ADJCALLSTACKDOWN 112, 0, implicit-def dead $r1, implicit $r1
+# CHECK-MIR-NEXT:  %8:g8rc = EXTSW_32_64 %2
+# CHECK-MIR-NEXT:  %9:g8rc = EXTSW_32_64 killed %7
+# CHECK-MIR-NEXT:  $x3 = COPY %

[PATCH] D119271: CGCall: also emit LLVM `allocalign` attribute when handling AllocAlign

2022-02-11 Thread Augie Fackler via Phabricator via cfe-commits
durin42 added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:4605
+  TryEmitAsCallSiteAttribute(const llvm::AttributeList &Attrs) {
+llvm::AttributeList NewAttrs = Attrs;
+if (AA)

jyknight wrote:
> We do need to fallback to an assume for 
> "if(CGF.SanOpts.has(SanitizerKind::Alignment)" however -- and NOT emit an 
> allocalign (nor an align) attribute in that case.
> 
> This is necessary so that clang can emit explicit misalignment checks FIRST 
> (and abort with a message if they fail), before letting LLVM assume the 
> specified alignment. In order for the ubsan alignment check to work properly, 
> we need to not trigger misalignment-UB before the check executes! 
> 
> See 
> clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
>  -- note how in the sanitized mode, it doesn't have an the "align 128" on the 
> call result, but instead emits a bunch of code to test alignment, and branch 
> to an ubsan abort on failure -- followed by the llvm.assume only on the 
> successful branch. Although the test-case is only testing assume_aligned, the 
> same behavior should be applicable to allocalign.
> 
> (Which shows that we clearly need a sanitized allocalign test-case, too)
It sounds like (between this comment and the one below) I should just abandon 
the code-sharing between AllocAlignAttrEmitter and AssumeAlignedAttrEmitter - 
is that right?

Also, should I be making a new test case or adding to an existing one for a 
sanitized allocalign test case? Is that an llvm-level thing or a clang-level 
thing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-11 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp:5
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local 
)?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local 
)?}}constant i32 3,

I don;t think this is correct.  That should still be a linkonce odr, otherwise 
you'll get conflicts with other module implementation units.



Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp:9
 // CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external {{(dso_local 
)?}}global
-// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr 
{{(dso_local )?}}global
+// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = available_externally 
{{(dso_local )?}}global
 // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = available_externally 
{{(dso_local )?}}global i32 0,

Likewise.



Comment at: clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp:5
 // CHECK-DAG: @extern_var_exported = external {{(dso_local )?}}global
-// CHECK-DAG: @inline_var_exported = linkonce_odr {{(dso_local )?}}global
+// CHECK-DAG: @inline_var_exported = available_externally {{(dso_local 
)?}}global
 // CHECK-DAG: @const_var_exported = available_externally {{(dso_local 
)?}}constant i32 3

Likewise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119409

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


[PATCH] D119409: [C++20] [Modules] Remain variable's definition in module interface

2022-02-11 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/test/CodeGenCXX/static-variable-in-module.cpp:2-8
+// RUN: mkdir %t
+// RUN: echo "struct S { S(); };" >> %t/foo.h
+// RUN: echo "static S s = S();" >> %t/foo.h
+// RUN: %clang -std=c++20 -I%t %s -S -emit-llvm -o - | FileCheck %s
+module;
+#include "foo.h"
+export module m;

rather than generate a foo.h file, why not (ab)use the preprocessor with 
internal line directives?

```
module;
# 3 __FILE__ 1 // use the next physical line number here (and below)
struct S { S(); };
static S s = S();
# 6 "" 2
export module m;
...
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119409

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


[PATCH] D119574: [clang] Expose -fprofile-use in clang-cl

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added a subscriber: dang.
thakis requested review of this revision.

Less typing than `-fprofile-instr-use`, and means the same thing.


https://reviews.llvm.org/D119574

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -76,7 +76,9 @@
 // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
 
 // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1251,9 +1251,10 @@
 Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect context sensitive 
execution counts into /default.profraw (overridden by 
LLVM_PROFILE_FILE env var)">;
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
-Alias;
+Flags<[CoreOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>, MetaVarName<"">,
+Group, Flags<[NoXarchOption, CoreOption]>,
+MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If 
pathname is a directory, it reads from /default.profdata. Otherwise, 
it reads from file .">;
 def fno_profile_instr_generate : Flag<["-"], "fno-profile-instr-generate">,
 Group, Flags<[CoreOption]>,


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -76,7 +76,9 @@
 // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
 
 // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
 // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1251,9 +1251,10 @@
 Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect context sensitive execution counts into /default.profraw (overridden by LLVM_PROFILE_FILE env var)">;
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
-Alias;
+Flags<[CoreOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>, MetaVarName<"">,
+Group, Flags<[NoXarchOption, CoreOption]>,
+MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If pathname is a directory, it reads from /default.profdata. Otherwise, it reads from file .">;
 def fno_profile_instr_generate : Flag<["-"], "fno-profile-instr-generate">,
 Group, Flags<[CoreOption]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

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

@void It would be cool to mention this new feature in release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D119226: [clang][lex][minimizer] Avoid treating path separators as comments

2022-02-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Cheers, LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119226

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


[PATCH] D119367: [HWASan] Allow no_sanitize(..) and change metadata passing.

2022-02-11 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

In addition to the .bc support we will also need support for reading/writing 
.ll files.




Comment at: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp:1721
-static DenseSet getExcludedGlobals(Module &M) {
-  NamedMDNode *Globals = M.getNamedMetadata("llvm.asan.globals");
-  if (!Globals)

Looks like you'll need to update 
llvm/test/Instrumentation/HWAddressSanitizer/globals.ll to use the new 
attribute instead (after adding the .ll support).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119367

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


[PATCH] D105169: [Clang/Test]: Rename enable_noundef_analysis to disable-noundef-analysis and turn it off by default

2022-02-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

It may not be worth changing now, but I want to mention: it's more conventional 
to have a `BoolOption` which adds `-[no-]noundef-analysis`. Since both positive 
and negative forms exist. When we make the default switch, existing users don't 
need to change the option. After the option becomes quite stable, we can remove 
the option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105169

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


[PATCH] D119479: [clang][extract-api] Add global record support

2022-02-11 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 407967.
zixuw added a comment.

Fix a test failure on Windows where the ':' delimiter for sed was taken by the 
Windows path convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119479

Files:
  clang/include/clang/AST/RawCommentList.h
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/SymbolGraph/API.h
  clang/include/clang/SymbolGraph/AvailabilityInfo.h
  clang/include/clang/SymbolGraph/DeclarationFragments.h
  clang/include/clang/SymbolGraph/Serialization.h
  clang/lib/AST/RawCommentList.cpp
  clang/lib/CMakeLists.txt
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/ExtractAPIConsumer.cpp
  clang/lib/SymbolGraph/API.cpp
  clang/lib/SymbolGraph/CMakeLists.txt
  clang/lib/SymbolGraph/DeclarationFragments.cpp
  clang/lib/SymbolGraph/Serialization.cpp
  clang/test/Driver/extract-api.c
  clang/test/SymbolGraph/global_record.c

Index: clang/test/SymbolGraph/global_record.c
===
--- /dev/null
+++ clang/test/SymbolGraph/global_record.c
@@ -0,0 +1,363 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.c -o %t/output.json | FileCheck -allow-empty %s
+// RUN: diff -a %t/reference.output.json %t/output.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.c
+int num;
+
+/**
+ * \brief Add two numbers.
+ * \param [in]  x   A number.
+ * \param [in]  y   Another number.
+ * \param [out] res The result of x + y.
+ */
+void add(const int x, const int y, int *res);
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "clang"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declaration": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Variable",
+"identifier": "c.variable"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/input.c"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  }
+},
+{
+  "declaration": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "add"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "x"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "const"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "y"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " *"
+},
+{
+  "kind": "internalParam",
+  "spelling": "res"
+},
+{
+  "kind": "text",
+  "spelling": ")"
+}
+  ],
+  "docComment": {
+"lin

[PATCH] D119165: [clang-tidy] Add processing lambda captures at bugprone-use-after-move check

2022-02-11 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:416
 
+  auto CallMoveMatcherLambda = lambdaExpr(
+  forEachLambdaCapture(lambdaCapture(capturesVar(varDecl(

sammccall wrote:
> sammccall wrote:
> > do we want to bind the lambda itself as `moving-call`?
> we should probably have a comment explaining *why* lambdas get handled 
> specially.
> 
> If I understand right:
> - the normal matcher would already match
> - but either MovingCall or ContainingLambda (which?) point at unhelpful nodes 
> and
> - we end up doing the analysis inside the lambda rather than in the enclosing 
> function
> - so never find the following use
> 
> (I wonder if it's possible to fix this slightly more directly by tweaking the 
> MovingCall or ContainingLambda logic)
> If I understand right:

There are some troubles with the original matcher. The most obvious one is 
correctly described at your comment :
The original matcher
```
callExpr(callee(functionDecl(hasName("::std::move"))),
   ... hasAncestor(lambdaExpr().bind("containing-lambda")),
   ...
```
applied to the code
```
auto []() { // lambda_1
   int a = 0;
   ...
   auto [](aa = std::move(a)) { // lambda_2
   }
}
```
will return *lambda_2* binded to the "containing-lambda" but we expect it to be 
*lambda_1*



> (I wonder if it's possible to fix this slightly more directly by tweaking the 
> MovingCall or ContainingLambda logic)
It would be good to find it if it's possible



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1356
+int lambdaCaptures() {
+  int a = 0;
+  int b = 0;

sammccall wrote:
> It's pretty interesting that use-after-move fires for ints!
> 
> Someone might decide to "fix" that though, so probably best to use A like the 
> other tests.
There is also another case that I want to address as a separate patch.
```
void autoCapture() {
  auto var = [](auto &&res) {
auto f = [blk = std::move(res)]() {};
return std::move(res);
  };
}
```
This one is matched as `UnresolvedLookupExpr` and requires another modified 
matcher


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119165

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I went ahead and landed this for now. It's easy to move the 3 new files to 
their own library later on if we decide it's something we want to do.

Thanks for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

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


[PATCH] D118070: Make lld-link work in a non-MSVC shell

2022-02-11 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3b2538df100: [lld/coff] Make lld-link work in a non-MSVC 
shell, add /winsysroot: (authored by pkasting, committed by thakis).

Changed prior to commit:
  https://reviews.llvm.org/D118070?vs=406570&id=407955#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118070

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MSVCSetupApi.h
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h
  lld/COFF/Options.td
  lld/COFF/SymbolTable.cpp
  lld/docs/ReleaseNotes.rst
  lld/test/COFF/winsysroot.test
  llvm/include/llvm/Support/MSVCPaths.h
  llvm/include/llvm/Support/MSVCSetupApi.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/MSVCPaths.cpp
  llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1310,9 +1310,6 @@
 "lib/Driver/ToolChains/Arch/*.cpp",
 "lib/Driver/ToolChains/Arch/*.h",
 ],
-exclude = [
-"lib/Driver/ToolChains/MSVCSetupApi.h",
-],
 ),
 hdrs = glob([
 "include/clang/Driver/*.h",
Index: llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
@@ -98,6 +98,7 @@
 "MD5.cpp",
 "MSP430AttributeParser.cpp",
 "MSP430Attributes.cpp",
+"MSVCPaths.cpp",
 "ManagedStatic.cpp",
 "MathExtras.cpp",
 "MemAlloc.cpp",
Index: llvm/lib/Support/MSVCPaths.cpp
===
--- /dev/null
+++ llvm/lib/Support/MSVCPaths.cpp
@@ -0,0 +1,709 @@
+//===-- MSVCPaths.cpp - MSVC path-parsing helpers -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/MSVCPaths.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/VersionTuple.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include 
+#endif
+
+#ifdef _MSC_VER
+// Don't support SetupApi on MinGW.
+#define USE_MSVC_SETUP_API
+
+// Make sure this comes before MSVCSetupApi.h
+#include 
+
+#include "llvm/Support/COM.h"
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+#include "llvm/Support/MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
+_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
+_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
+#endif
+
+static std::string
+getHighestNumericTupleInDirectory(llvm::vfs::FileSystem &VFS,
+  llvm::StringRef Directory) {
+  std::string Highest;
+  llvm::VersionTuple HighestTuple;
+
+  std::error_code EC;
+  for (llvm::vfs::directory_iterator DirIt = VFS.dir_begin(Directory, EC),
+ DirEnd;
+   !EC && DirIt != DirEnd; DirIt.increment(EC)) {
+auto Status = VFS.status(DirIt->path());
+if (!Status || !Status->isDirectory())
+  continue;
+llvm::StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+llvm::VersionTuple Tuple;
+if (Tuple.tryParse(CandidateName)) // tryParse() returns true on error.
+  continue;
+if (Tuple > HighestTuple) {
+  HighestTuple = Tuple;
+  Highest = CandidateName.str();
+}
+  }
+
+  return Highest;
+}
+
+static bool getWindows10

[clang] b3b2538 - [lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:

2022-02-11 Thread Nico Weber via cfe-commits

Author: Peter Kasting
Date: 2022-02-11T13:55:18-05:00
New Revision: b3b2538df100ec7f6587b0ee70819a3c8ee2c27e

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

LOG: [lld/coff] Make lld-link work in a non-MSVC shell, add /winsysroot:

Makes lld-link work in a non-MSVC shell by autodetecting MSVC toolchain. Also
adds support for /winsysroot and a few other switches.

All this is done by refactoring to share code with clang-cl's existing support
for the same.

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

Added: 
lld/test/COFF/winsysroot.test
llvm/include/llvm/Support/MSVCPaths.h
llvm/include/llvm/Support/MSVCSetupApi.h
llvm/lib/Support/MSVCPaths.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MSVC.h
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/Options.td
lld/COFF/SymbolTable.cpp
lld/docs/ReleaseNotes.rst
llvm/lib/Support/CMakeLists.txt
llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Removed: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index c7defa9cd88c6..5666ad499d791 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -285,7 +285,6 @@ clang/lib/Driver/ToolChains/InterfaceStubs.h
 clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
-clang/lib/Driver/ToolChains/MSVCSetupApi.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp
 clang/lib/Driver/ToolChains/PPCFreeBSD.h
 clang/lib/Driver/ToolChains/PPCLinux.h
@@ -5150,6 +5149,8 @@ llvm/include/llvm/Support/MemoryBufferRef.h
 llvm/include/llvm/Support/MSP430AttributeParser.h
 llvm/include/llvm/Support/MSP430Attributes.h
 llvm/include/llvm/Support/MSVCErrorWorkarounds.h
+llvm/include/llvm/Support/MSVCPaths.h
+llvm/include/llvm/Support/MSVCSetupApi.h
 llvm/include/llvm/Support/Parallel.h
 llvm/include/llvm/Support/PGOOptions.h
 llvm/include/llvm/Support/PointerLikeTypeTraits.h
@@ -5840,6 +5841,7 @@ llvm/lib/Support/Memory.cpp
 llvm/lib/Support/MemoryBufferRef.cpp
 llvm/lib/Support/MSP430AttributeParser.cpp
 llvm/lib/Support/MSP430Attributes.cpp
+llvm/lib/Support/MSVCPaths.cpp
 llvm/lib/Support/Optional.cpp
 llvm/lib/Support/Parallel.cpp
 llvm/lib/Support/Program.cpp

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 9f4751167ac12..36e190f69154b 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/MSVCPaths.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
@@ -40,91 +41,12 @@
   #include 
 #endif
 
-#ifdef _MSC_VER
-// Don't support SetupApi on MinGW.
-#define USE_MSVC_SETUP_API
-
-// Make sure this comes before MSVCSetupApi.h
-#include 
-
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
-#endif
-#include "MSVCSetupApi.h"
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-#include "llvm/Support/COM.h"
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
-_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-_COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-_COM_SMARTPTR_TYPEDEF(IEnumSetupInstances, __uuidof(IEnumSetupInstances));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance, __uuidof(ISetupInstance));
-_COM_SMARTPTR_TYPEDEF(ISetupInstance2, __uuidof(ISetupInstance2));
-#endif
-
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-// Windows SDKs and VC Toolchains group their contents into subdirectories 
based
-// on the target architecture. This function converts an llvm::Triple::ArchType
-// to the corresponding subdirectory name.
-static const char *llvmArchToWindowsSDKArch(llvm::Triple::ArchType Arch) {
-  using ArchType = llvm::Triple::ArchType;
-  switch (Arch) {
-  case ArchType::x86:
-return "x86";
-  case ArchType::x86_64:
-return "x64";
-  case ArchType::arm:
-return "arm";
-  case ArchType::aarch64:
-return "arm64";
-  default:
-return "";
-  }
-}
-
-// Similar to the above function, but for Visual Studios before VS2017.
-static const char *llvmArchToLegacyVCArch(llvm::Triple::ArchType Arch) {
-  using ArchType = llvm::Triple::ArchType;
-  switch (Arch) {
-  case ArchType::x86:
- 

[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog marked an inline comment as done.
kesyog added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Eugene.Zelenko wrote:
> kesyog wrote:
> > Eugene.Zelenko wrote:
> > > Shouldn't it be just `else:`?
> > There are three cases:
> > 
> > | Argument  | `use_color` | Behavior |
> > | `-use-color` | `True` | `--use-color` is passed to clang-tidy, force 
> > enabling color |
> > | `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
> > force disabling color |
> > | (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy 
> > follows its default coloring behavior |
> > 
> > The case on the highlighted line is the second row of the table, and we 
> > have to check that `use_color` is not `None` to exclude the case of the 
> > third row.
> > 
> > I was trying to avoid the extra nesting of something like below, but maybe 
> > the intent would be clearer?
> > ```
> > if use_color is not None:
> >   if use_color:
> > start.append('--use-color')
> >   else:
> > start.append('--use-color=false')
> > ```
> I think you implementation is incorrect. You should check for not `None` 
> first and than set proper value for `--use-color`.
fixed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D112730: [clang-tidy] Add AUTOSAR module

2022-02-11 Thread Tanya Lattner via Phabricator via cfe-commits
tonic added a comment.

Unfortunately our legal counsel has advised that this patch should not be 
included into LLVM because the exact patent burden is not disclosed. Therefore, 
we can not accept this patch into LLVM. I am very sorry to have to report this 
disappointing news.


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

https://reviews.llvm.org/D112730

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog updated this revision to Diff 407950.
kesyog added a comment.

Refactor tri-state logic for readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,20 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color is not None:
+if use_color:
+  start.append('--use-color')
+else:
+  start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +173,8 @@
  tmpdir, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 
 proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
 output, err = proc.communicate()
@@ -231,6 +237,16 @@
   'after applying fixes')
   parser.add_argument('-style', default='file', help='The style of reformat '
   'code after applying fixes')
+  color_group = parser.add_mutually_exclusive_group()
+  color_group.add_argument('-use-color', action='store_true', dest='use_color',
+   help='Use colors in diagnostics, overriding 
clang-tidy\'s default '
+   'behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  color_group.add_argument('-no-use-color', action='store_false', 
dest='use_color',
+   help='Do not use colors in diagnostics, overriding 
clang-tidy\'s default'
+   ' behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  parser.set_defaults(use_color=None)
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
@@ -258,7 +274,8 @@
  None, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 invocation.append('-list-checks')
 invocation.append('-')
 if args.quiet:


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,20 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color is not None:
+if use_color:
+  start.append('--use-color')
+else:
+  start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +173,8 @@
  tmpdir, build_pat

[clang] 87dd3d3 - [clang][OpaquePtr] Remove call to getPointerElementType() in CodeGenModule::GetAddrOfGlobalTemporary()

2022-02-11 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2022-02-11T10:39:49-08:00
New Revision: 87dd3d350c4ce0115b2cdf91d85ddd05ae2661aa

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

LOG: [clang][OpaquePtr] Remove call to getPointerElementType() in 
CodeGenModule::GetAddrOfGlobalTemporary()

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0d89cb723c76b..772059a436d17 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5670,9 +5670,11 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   getModule(), Type, false, llvm::GlobalVariable::InternalLinkage,
   nullptr);
 }
-return ConstantAddress(
-InsertResult.first->second,
-InsertResult.first->second->getType()->getPointerElementType(), Align);
+return ConstantAddress(InsertResult.first->second,
+   llvm::cast(
+   InsertResult.first->second->stripPointerCasts())
+   ->getValueType(),
+   Align);
   }
 
   // FIXME: If an externally-visible declaration extends multiple temporaries,



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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

kesyog wrote:
> Eugene.Zelenko wrote:
> > Shouldn't it be just `else:`?
> There are three cases:
> 
> | Argument  | `use_color` | Behavior |
> | `-use-color` | `True` | `--use-color` is passed to clang-tidy, force 
> enabling color |
> | `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
> force disabling color |
> | (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy follows 
> its default coloring behavior |
> 
> The case on the highlighted line is the second row of the table, and we have 
> to check that `use_color` is not `None` to exclude the case of the third row.
> 
> I was trying to avoid the extra nesting of something like below, but maybe 
> the intent would be clearer?
> ```
> if use_color is not None:
>   if use_color:
> start.append('--use-color')
>   else:
> start.append('--use-color=false')
> ```
I think you implementation is incorrect. You should check for not `None` first 
and than set proper value for `--use-color`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Eugene.Zelenko wrote:
> Shouldn't it be just `else:`?
There are three cases:

| Argument  | `use_color` | Behavior |
| `-use-color` | `True` | `--use-color` is passed to clang-tidy, force enabling 
color |
| `-no-use-color` | `False` | `--use-color=false` is passed to clang-tidy, 
force disabling color |
| (none provided) | `None` | Nothing passed to clang-tidy. clang-tidy follows 
its default coloring behavior |

The case on the highlighted line is the second row of the table, and we have to 
check that `use_color` is not `None` to exclude the case of the third row.

I was trying to avoid the extra nesting of something like below, but maybe the 
intent would be clearer?
```
if use_color is not None:
  if use_color:
start.append('--use-color')
  else:
start.append('--use-color=false')
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:96
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')

Shouldn't it be just `else:`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119562

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


[PATCH] D119367: [HWASan] Allow no_sanitize(..) and change metadata passing.

2022-02-11 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

You might want to update Bitcode writer/reader as well, otherwise nosanitize 
will be lost after a trip through .bc/.ii.




Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:50
+  f()[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
+  return 0;

did you mean to do it twice?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119367

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


[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

2022-02-11 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D110869#3313443 , @void wrote:

> In D110869#3312360 , @RKSimon wrote:
>
>> @void This buildbot appears to be still broken due to this change: 
>> https://lab.llvm.org/buildbot/#/builders/110/builds/10271
>
> Strange...This is the first time seeing something like this. I'll fix it 
> quickly.

It's fixed now. Sorry about the failure!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869

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


[PATCH] D119562: Provide fine control of color in run-clang-tidy

2022-02-11 Thread Kesavan Yogeswaran via Phabricator via cfe-commits
kesyog created this revision.
Herald added a subscriber: carlosgalvezp.
kesyog requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

D90110  modified the behavior of 
`run-clang-tidy` to always pass the
`--use-color` option to clang-tidy, which enabled colored diagnostics
output regardless of TTY status or .clang-tidy settings. This left the
user with no option to disable the colored output.

This presents an issue when trying to parse the output of run-clang-tidy
programmaticall, as the output is polluted with ANSI escape characters.

This PR fixes this issue in two ways:

1. It restores the default behavior of `run-clang-tidy` to let `clang-tidy` 
decide whether to color output. This allows the user to configure color via the 
`UseColor` option in a .clang-tidy file.
2. It adds mutually exclusive, optional `-use-color` and `-no-use-color` 
argument flags that let the user explicitly set the color option via the 
invocation.

After this change the default behavior of `run-clang-tidy` when no
.clang-tidy file is available is now to show no color, presumably
because `clang-tidy` detects that the output is being piped and defaults
to not showing colored output. This seems like an acceptable tradeoff
to respect .clang-tidy configurations, as users can still use the
`-use-color` option to explicitly enable color.

Fixes #49441 (50097 in Bugzilla)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119562

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -82,15 +82,19 @@
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
 header_filter, allow_enabling_alpha_checkers,
 extra_arg, extra_arg_before, quiet, config,
-line_filter):
+line_filter, use_color):
   """Gets a command line for clang-tidy."""
-  start = [clang_tidy_binary, '--use-color']
+  start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
 start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if line_filter is not None:
 start.append('-line-filter=' + line_filter)
+  if use_color:
+start.append('--use-color')
+  elif use_color is not None:
+start.append('--use-color=false')
   if checks:
 start.append('-checks=' + checks)
   if tmpdir is not None:
@@ -168,7 +172,8 @@
  tmpdir, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 
 proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
 output, err = proc.communicate()
@@ -231,6 +236,16 @@
   'after applying fixes')
   parser.add_argument('-style', default='file', help='The style of reformat '
   'code after applying fixes')
+  color_group = parser.add_mutually_exclusive_group()
+  color_group.add_argument('-use-color', action='store_true', dest='use_color',
+   help='Use colors in diagnostics, overriding 
clang-tidy\'s default '
+   'behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  color_group.add_argument('-no-use-color', action='store_false', 
dest='use_color',
+   help='Do not use colors in diagnostics, overriding 
clang-tidy\'s default'
+   ' behavior. This option overrides the \'UseColor\' 
option in'
+   '.clang-tidy file, if any.')
+  parser.set_defaults(use_color=None)
   parser.add_argument('-p', dest='build_path',
   help='Path used to read a compile command database.')
   parser.add_argument('-extra-arg', dest='extra_arg',
@@ -258,7 +273,8 @@
  None, build_path, args.header_filter,
  args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
- args.quiet, args.config, args.line_filter)
+ args.quiet, args.config, args.line_filter,
+ args.use_color)
 invocation.append('-list-checks')
 invocation.ap

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

And thanks for taking a look, and filing bugs - sorry we can't get to 
everything :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D119537#3314509 , @avogelsgesang 
wrote:

> Should this be added to the Release Notes?

We usually go back over the git log around the time of a release cut.
It started as laziness but I think it's a good system: less work writing notes 
for stuff that doesn't end up landing, and gives us a chance to group and 
summarize related changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


  1   2   >